Skip to content

Commit 717bc2c

Browse files
committed
fix: sort members
1 parent db99b3c commit 717bc2c

17 files changed

Lines changed: 851 additions & 888 deletions

src/main/java/org/apache/commons/release/plugin/internal/ArtifactUtils.java

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,27 @@ public final class ArtifactUtils {
6161
IN_TOTO_DIGEST_NAMES = Collections.unmodifiableMap(m);
6262
}
6363

64-
/** No instances. */
65-
private ArtifactUtils() {
66-
// prevent instantiation
67-
}
68-
6964
/**
70-
* Gets the filename of an artifact in the default Maven repository layout.
65+
* Gets a map of checksum algorithm names to hex-encoded digest values for the given artifact file.
7166
*
7267
* @param artifact A Maven artifact.
73-
* @return A filename.
68+
* @param algorithms JSSE names of algorithms to use
69+
* @return A map of checksum algorithm names to hex-encoded digest values.
70+
* @throws IOException If an I/O error occurs reading the artifact file.
71+
* @throws IllegalArgumentException If any of the algorithms is not supported.
7472
*/
75-
public static String getFileName(final Artifact artifact) {
76-
return getFileName(artifact, artifact.getArtifactHandler().getExtension());
73+
private static Map<String, String> getChecksums(final Artifact artifact, final String... algorithms) throws IOException {
74+
final Map<String, String> checksums = new HashMap<>();
75+
for (final String algorithm : algorithms) {
76+
final String key = IN_TOTO_DIGEST_NAMES.get(algorithm);
77+
if (key == null) {
78+
throw new IllegalArgumentException("Invalid algorithm name for in-toto attestation: " + algorithm);
79+
}
80+
final DigestUtils digest = new DigestUtils(DigestUtils.getDigest(algorithm));
81+
final String checksum = digest.digestAsHex(artifact.getFile());
82+
checksums.put(key, checksum);
83+
}
84+
return checksums;
7785
}
7886

7987
/**
@@ -93,6 +101,16 @@ public static String getFileName(final Artifact artifact, final String extension
93101
return fileName.toString();
94102
}
95103

104+
/**
105+
* Gets the filename of an artifact in the default Maven repository layout.
106+
*
107+
* @param artifact A Maven artifact.
108+
* @return A filename.
109+
*/
110+
public static String getFileName(final Artifact artifact) {
111+
return getFileName(artifact, artifact.getArtifactHandler().getExtension());
112+
}
113+
96114
/**
97115
* Gets the Package URL corresponding to this artifact.
98116
*
@@ -111,29 +129,6 @@ public static String getPackageUrl(final Artifact artifact) {
111129
return sb.toString();
112130
}
113131

114-
/**
115-
* Gets a map of checksum algorithm names to hex-encoded digest values for the given artifact file.
116-
*
117-
* @param artifact A Maven artifact.
118-
* @param algorithms JSSE names of algorithms to use
119-
* @return A map of checksum algorithm names to hex-encoded digest values.
120-
* @throws IOException If an I/O error occurs reading the artifact file.
121-
* @throws IllegalArgumentException If any of the algorithms is not supported.
122-
*/
123-
private static Map<String, String> getChecksums(final Artifact artifact, final String... algorithms) throws IOException {
124-
final Map<String, String> checksums = new HashMap<>();
125-
for (final String algorithm : algorithms) {
126-
final String key = IN_TOTO_DIGEST_NAMES.get(algorithm);
127-
if (key == null) {
128-
throw new IllegalArgumentException("Invalid algorithm name for in-toto attestation: " + algorithm);
129-
}
130-
final DigestUtils digest = new DigestUtils(DigestUtils.getDigest(algorithm));
131-
final String checksum = digest.digestAsHex(artifact.getFile());
132-
checksums.put(key, checksum);
133-
}
134-
return checksums;
135-
}
136-
137132
/**
138133
* Converts a Maven artifact to a SLSA {@link ResourceDescriptor}.
139134
*
@@ -155,4 +150,9 @@ public static ResourceDescriptor toResourceDescriptor(final Artifact artifact, f
155150
}
156151
return descriptor;
157152
}
153+
154+
/** No instances. */
155+
private ArtifactUtils() {
156+
// prevent instantiation
157+
}
158158
}

src/main/java/org/apache/commons/release/plugin/internal/BuildDefinitions.java

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,44 @@
3636
public final class BuildDefinitions {
3737

3838
/**
39-
* No instances.
39+
* Reconstructs the Maven command line string from the given execution request.
40+
*
41+
* @param request the Maven execution request
42+
* @return a string representation of the Maven command line
4043
*/
41-
private BuildDefinitions() {
44+
static String commandLine(final MavenExecutionRequest request) {
45+
final List<String> args = new ArrayList<>(request.getGoals());
46+
final String profiles = String.join(",", request.getActiveProfiles());
47+
if (!profiles.isEmpty()) {
48+
args.add("-P" + profiles);
49+
}
50+
request.getUserProperties().forEach((key, value) -> args.add("-D" + key + "=" + value));
51+
return String.join(" ", args);
52+
}
53+
54+
/**
55+
* Returns a map of external build parameters captured from the current JVM and Maven session.
56+
*
57+
* @param session the current Maven session
58+
* @return a map of parameter names to values
59+
*/
60+
public static Map<String, Object> externalParameters(final MavenSession session) {
61+
final Map<String, Object> params = new HashMap<>();
62+
params.put("jvm.args", ManagementFactory.getRuntimeMXBean().getInputArguments());
63+
final MavenExecutionRequest request = session.getRequest();
64+
params.put("maven.goals", request.getGoals());
65+
params.put("maven.profiles", request.getActiveProfiles());
66+
params.put("maven.user.properties", request.getUserProperties());
67+
params.put("maven.cmdline", commandLine(request));
68+
final Map<String, Object> env = new HashMap<>();
69+
params.put("env", env);
70+
for (final Map.Entry<String, String> entry : System.getenv().entrySet()) {
71+
final String key = entry.getKey();
72+
if ("TZ".equals(key) || "LANG".equals(key) || key.startsWith("LC_")) {
73+
env.put(key, entry.getValue());
74+
}
75+
}
76+
return params;
4277
}
4378

4479
/**
@@ -106,43 +141,8 @@ public static ResourceDescriptor maven(final String version, final Path mavenHom
106141
}
107142

108143
/**
109-
* Returns a map of external build parameters captured from the current JVM and Maven session.
110-
*
111-
* @param session the current Maven session
112-
* @return a map of parameter names to values
113-
*/
114-
public static Map<String, Object> externalParameters(final MavenSession session) {
115-
final Map<String, Object> params = new HashMap<>();
116-
params.put("jvm.args", ManagementFactory.getRuntimeMXBean().getInputArguments());
117-
final MavenExecutionRequest request = session.getRequest();
118-
params.put("maven.goals", request.getGoals());
119-
params.put("maven.profiles", request.getActiveProfiles());
120-
params.put("maven.user.properties", request.getUserProperties());
121-
params.put("maven.cmdline", commandLine(request));
122-
final Map<String, Object> env = new HashMap<>();
123-
params.put("env", env);
124-
for (final Map.Entry<String, String> entry : System.getenv().entrySet()) {
125-
final String key = entry.getKey();
126-
if ("TZ".equals(key) || "LANG".equals(key) || key.startsWith("LC_")) {
127-
env.put(key, entry.getValue());
128-
}
129-
}
130-
return params;
131-
}
132-
133-
/**
134-
* Reconstructs the Maven command line string from the given execution request.
135-
*
136-
* @param request the Maven execution request
137-
* @return a string representation of the Maven command line
144+
* No instances.
138145
*/
139-
static String commandLine(final MavenExecutionRequest request) {
140-
final List<String> args = new ArrayList<>(request.getGoals());
141-
final String profiles = String.join(",", request.getActiveProfiles());
142-
if (!profiles.isEmpty()) {
143-
args.add("-P" + profiles);
144-
}
145-
request.getUserProperties().forEach((key, value) -> args.add("-D" + key + "=" + value));
146-
return String.join(" ", args);
146+
private BuildDefinitions() {
147147
}
148148
}

src/main/java/org/apache/commons/release/plugin/internal/DsseUtils.java

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@
4747
*/
4848
public final class DsseUtils {
4949

50-
/**
51-
* Not instantiable.
52-
*/
53-
private DsseUtils() {
54-
}
55-
5650
/**
5751
* Creates and prepares a {@link GpgSigner} from the given configuration.
5852
*
@@ -79,6 +73,56 @@ public static AbstractGpgSigner createGpgSigner(final String executable, final b
7973
return signer;
8074
}
8175

76+
/**
77+
* Extracts the key identifier from a binary OpenPGP Signature Packet.
78+
*
79+
* @param sigBytes raw binary OpenPGP Signature Packet bytes
80+
* @return uppercase hex-encoded fingerprint or key ID string
81+
* @throws MojoExecutionException if {@code sigBytes} cannot be parsed as an OpenPGP signature
82+
*/
83+
public static String getKeyId(final byte[] sigBytes) throws MojoExecutionException {
84+
try {
85+
final PGPSignatureList sigList = (PGPSignatureList) new BcPGPObjectFactory(sigBytes).nextObject();
86+
final PGPSignature sig = sigList.get(0);
87+
final PGPSignatureSubpacketVector hashed = sig.getHashedSubPackets();
88+
if (hashed != null) {
89+
final IssuerFingerprint fp = hashed.getIssuerFingerprint();
90+
if (fp != null) {
91+
return Hex.encodeHexString(fp.getFingerprint());
92+
}
93+
}
94+
return Long.toHexString(sig.getKeyID()).toUpperCase(Locale.ROOT);
95+
} catch (final IOException e) {
96+
throw new MojoExecutionException("Failed to extract key ID from signature", e);
97+
}
98+
}
99+
100+
/**
101+
* Signs {@code paeFile} and returns the raw OpenPGP signature bytes.
102+
*
103+
* <p>The signer must already have {@link AbstractGpgSigner#prepare()} called before this method is invoked.</p>
104+
*
105+
* @param signer the configured, prepared signer
106+
* @param path path to the file to sign
107+
* @return raw binary PGP signature bytes
108+
* @throws MojoExecutionException if signing or signature decoding fails
109+
*/
110+
public static byte[] signFile(final AbstractGpgSigner signer, final Path path) throws MojoExecutionException {
111+
final Path signaturePath = signer.generateSignatureForArtifact(path.toFile()).toPath();
112+
final byte[] signatureBytes;
113+
try (InputStream in = Files.newInputStream(signaturePath); ArmoredInputStream armoredIn = new ArmoredInputStream(in)) {
114+
signatureBytes = IOUtils.toByteArray(armoredIn);
115+
} catch (final IOException e) {
116+
throw new MojoExecutionException("Failed to read signature file: " + signaturePath, e);
117+
}
118+
try {
119+
Files.delete(signaturePath);
120+
} catch (final IOException e) {
121+
throw new MojoExecutionException("Failed to delete signature file: " + signaturePath, e);
122+
}
123+
return signatureBytes;
124+
}
125+
82126
/**
83127
* Serializes {@code statement} to JSON using the DSSE Pre-Authentication Encoding (PAE).
84128
*
@@ -127,52 +171,8 @@ public static Path writePaeFile(final byte[] statementBytes, final Path buildDir
127171
}
128172

129173
/**
130-
* Signs {@code paeFile} and returns the raw OpenPGP signature bytes.
131-
*
132-
* <p>The signer must already have {@link AbstractGpgSigner#prepare()} called before this method is invoked.</p>
133-
*
134-
* @param signer the configured, prepared signer
135-
* @param path path to the file to sign
136-
* @return raw binary PGP signature bytes
137-
* @throws MojoExecutionException if signing or signature decoding fails
138-
*/
139-
public static byte[] signFile(final AbstractGpgSigner signer, final Path path) throws MojoExecutionException {
140-
final Path signaturePath = signer.generateSignatureForArtifact(path.toFile()).toPath();
141-
final byte[] signatureBytes;
142-
try (InputStream in = Files.newInputStream(signaturePath); ArmoredInputStream armoredIn = new ArmoredInputStream(in)) {
143-
signatureBytes = IOUtils.toByteArray(armoredIn);
144-
} catch (final IOException e) {
145-
throw new MojoExecutionException("Failed to read signature file: " + signaturePath, e);
146-
}
147-
try {
148-
Files.delete(signaturePath);
149-
} catch (final IOException e) {
150-
throw new MojoExecutionException("Failed to delete signature file: " + signaturePath, e);
151-
}
152-
return signatureBytes;
153-
}
154-
155-
/**
156-
* Extracts the key identifier from a binary OpenPGP Signature Packet.
157-
*
158-
* @param sigBytes raw binary OpenPGP Signature Packet bytes
159-
* @return uppercase hex-encoded fingerprint or key ID string
160-
* @throws MojoExecutionException if {@code sigBytes} cannot be parsed as an OpenPGP signature
174+
* Not instantiable.
161175
*/
162-
public static String getKeyId(final byte[] sigBytes) throws MojoExecutionException {
163-
try {
164-
final PGPSignatureList sigList = (PGPSignatureList) new BcPGPObjectFactory(sigBytes).nextObject();
165-
final PGPSignature sig = sigList.get(0);
166-
final PGPSignatureSubpacketVector hashed = sig.getHashedSubPackets();
167-
if (hashed != null) {
168-
final IssuerFingerprint fp = hashed.getIssuerFingerprint();
169-
if (fp != null) {
170-
return Hex.encodeHexString(fp.getFingerprint());
171-
}
172-
}
173-
return Long.toHexString(sig.getKeyID()).toUpperCase(Locale.ROOT);
174-
} catch (final IOException e) {
175-
throw new MojoExecutionException("Failed to extract key ID from signature", e);
176-
}
176+
private DsseUtils() {
177177
}
178178
}

0 commit comments

Comments
 (0)