Skip to content

Commit f2308c6

Browse files
committed
fix: missing Javadoc
1 parent e617f28 commit f2308c6

4 files changed

Lines changed: 87 additions & 91 deletions

File tree

src/main/java/org/apache/commons/build/BuildAttestationMojo.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ public class BuildAttestationMojo extends AbstractMojo {
124124
*/
125125
private final MavenProjectHelper mavenProjectHelper;
126126

127+
/**
128+
* Creates a new instance with the given dependencies.
129+
*
130+
* @param project A Maven project.
131+
* @param scmManager A SCM manager.
132+
* @param runtimeInformation Maven runtime information.
133+
* @param session A Maven session.
134+
* @param mavenProjectHelper A helper to attach artifacts to the project.
135+
*/
127136
@Inject
128137
public BuildAttestationMojo(MavenProject project, ScmManager scmManager, RuntimeInformation runtimeInformation, MavenSession session,
129138
MavenProjectHelper mavenProjectHelper) {
@@ -138,10 +147,20 @@ void setOutputDirectory(File outputDirectory) {
138147
this.outputDirectory = outputDirectory;
139148
}
140149

150+
/**
151+
* Returns the SCM directory.
152+
*
153+
* @return The SCM directory.
154+
*/
141155
public File getScmDirectory() {
142156
return scmDirectory;
143157
}
144158

159+
/**
160+
* Sets the SCM directory.
161+
*
162+
* @param scmDirectory The SCM directory.
163+
*/
145164
public void setScmDirectory(File scmDirectory) {
146165
this.scmDirectory = scmDirectory;
147166
}

src/main/java/org/apache/commons/build/internal/ArtifactUtils.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,32 @@
2525
import org.apache.maven.artifact.Artifact;
2626
import org.apache.maven.plugin.MojoExecutionException;
2727

28+
/**
29+
* Utilities to convert {@link Artifact} from and to other types.
30+
*/
2831
public final class ArtifactUtils {
2932

3033
private ArtifactUtils() {
3134
// prevent instantiation
3235
}
3336

37+
/**
38+
* Returns the conventional filename for the given artifact.
39+
*
40+
* @param artifact A Maven artifact.
41+
* @return A filename.
42+
*/
3443
public static String getFileName(Artifact artifact) {
3544
return getFileName(artifact, artifact.getArtifactHandler().getExtension());
3645
}
3746

47+
/**
48+
* Returns the filename for the given artifact with a changed extension.
49+
*
50+
* @param artifact A Maven artifact.
51+
* @param extension The file name extension.
52+
* @return A filename.
53+
*/
3854
public static String getFileName(Artifact artifact, String extension) {
3955
StringBuilder fileName = new StringBuilder();
4056
fileName.append(artifact.getArtifactId()).append("-").append(artifact.getVersion());
@@ -45,6 +61,12 @@ public static String getFileName(Artifact artifact, String extension) {
4561
return fileName.toString();
4662
}
4763

64+
/**
65+
* Returns the Package URL corresponding to this artifact.
66+
*
67+
* @param artifact A maven artifact.
68+
* @return A PURL for the given artifact.
69+
*/
4870
public static String getPackageUrl(Artifact artifact) {
4971
StringBuilder sb = new StringBuilder();
5072
sb.append("pkg:maven/").append(artifact.getGroupId()).append("/").append(artifact.getArtifactId()).append("@").append(artifact.getVersion())
@@ -57,14 +79,21 @@ public static String getPackageUrl(Artifact artifact) {
5779
return sb.toString();
5880
}
5981

60-
public static Map<String, String> getChecksums(Artifact artifact) throws IOException {
82+
private static Map<String, String> getChecksums(Artifact artifact) throws IOException {
6183
Map<String, String> checksums = new HashMap<>();
6284
DigestUtils digest = new DigestUtils(DigestUtils.getSha256Digest());
6385
String sha256sum = digest.digestAsHex(artifact.getFile());
6486
checksums.put("sha256", sha256sum);
6587
return checksums;
6688
}
6789

90+
/**
91+
* Converts a Maven artifact to a SLSA {@link ResourceDescriptor}.
92+
*
93+
* @param artifact A Maven artifact.
94+
* @return A SLSA resource descriptor.
95+
* @throws MojoExecutionException If an I/O error occurs retrieving the artifact.
96+
*/
6897
public static ResourceDescriptor toResourceDescriptor(Artifact artifact) throws MojoExecutionException {
6998
ResourceDescriptor descriptor = new ResourceDescriptor();
7099
descriptor.setName(getFileName(artifact));

src/main/java/org/apache/commons/build/internal/GitUtils.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,18 @@
2626
import java.nio.file.Paths;
2727
import java.security.MessageDigest;
2828

29+
/**
30+
* Utilities for Git operations.
31+
*/
2932
public final class GitUtils {
3033

34+
/**
35+
* Returns the Git tree hash for the given directory.
36+
*
37+
* @param path A directory path.
38+
* @return A hex-encoded SHA-1 tree hash.
39+
* @throws IOException If the path is not a directory or an I/O error occurs.
40+
*/
3141
public static String gitTree(Path path) throws IOException {
3242
if (!Files.isDirectory(path)) {
3343
throw new IOException("Path is not a directory: " + path);
@@ -36,6 +46,13 @@ public static String gitTree(Path path) throws IOException {
3646
return Hex.encodeHexString(DigestUtils.gitTree(digest, path));
3747
}
3848

49+
/**
50+
* Returns the Git blob hash for the given file.
51+
*
52+
* @param path A regular file path.
53+
* @return A hex-encoded SHA-1 blob hash.
54+
* @throws IOException If the path is not a regular file or an I/O error occurs.
55+
*/
3956
public static String gitBlob(Path path) throws IOException {
4057
if (!Files.isRegularFile(path)) {
4158
throw new IOException("Path is not a regular file: " + path);
@@ -44,6 +61,14 @@ public static String gitBlob(Path path) throws IOException {
4461
return Hex.encodeHexString(DigestUtils.gitBlob(digest, path));
4562
}
4663

64+
/**
65+
* Converts an SCM URI to a download URI suffixed with the current branch name.
66+
*
67+
* @param scmUri A Maven SCM URI starting with {@code scm:git}.
68+
* @param repositoryPath A path inside the Git repository.
69+
* @return A download URI of the form {@code git+<url>@<branch>}.
70+
* @throws IOException If the current branch cannot be determined.
71+
*/
4772
public static String scmToDownloadUri(String scmUri, Path repositoryPath) throws IOException {
4873
if (!scmUri.startsWith("scm:git")) {
4974
throw new IllegalArgumentException("Invalid scmUri: " + scmUri);
@@ -52,6 +77,15 @@ public static String scmToDownloadUri(String scmUri, Path repositoryPath) throws
5277
return "git+" + scmUri.substring(8) + "@" + currentBranch;
5378
}
5479

80+
/**
81+
* Returns the current branch name for the given repository path.
82+
*
83+
* <p>Returns the commit SHA if the repository is in a detached HEAD state.
84+
*
85+
* @param repositoryPath A path inside the Git repository.
86+
* @return The current branch name, or the commit SHA for a detached HEAD.
87+
* @throws IOException If the {@code .git} directory cannot be found or read.
88+
*/
5589
public static String getCurrentBranch(Path repositoryPath) throws IOException {
5690
Path gitDir = findGitDir(repositoryPath);
5791
String head = new String(Files.readAllBytes(gitDir.resolve("HEAD")), StandardCharsets.UTF_8).trim();

src/main/java/org/apache/commons/build/models/slsa/v1_2/package-info.java

Lines changed: 4 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -18,99 +18,13 @@
1818
/**
1919
* SLSA 1.2 Build Attestation Models.
2020
*
21-
* <p>This package provides Jackson-annotated model classes that implement the <a
22-
* href="https://slsa.dev/spec/v1.2">Supply-chain Levels for Software Artifacts (SLSA) v1.2
23-
* specification</a>.
21+
* <p>This package provides Jackson-annotated model classes that implement the <a href="https://slsa.dev/spec/v1.2">Supply-chain Levels for Software Artifacts
22+
* (SLSA) v1.2 specification</a>.</p>
2423
*
2524
* <h2>Overview</h2>
2625
*
27-
* <p>SLSA is a framework for evaluating and improving the security posture of build systems. SLSA
28-
* v1.2 defines a standard for recording build provenance - information about how software
29-
* artifacts were produced.
30-
*
31-
* <h2>Core Models</h2>
32-
*
33-
* <ul>
34-
* <li><b>{@link org.apache.commons.build.models.slsa.v1_2.Provenance}</b> - Root object
35-
* describing the build provenance. Contains BuildDefinition and RunDetails.
36-
* <li><b>{@link org.apache.commons.build.models.slsa.v1_2.BuildDefinition}</b> - Specifies
37-
* the inputs that define the build, including build type, configuration, external
38-
* parameters, and resolved dependencies.
39-
* <li><b>{@link org.apache.commons.build.models.slsa.v1_2.RunDetails}</b> - Specifies the
40-
* details about the build invocation and environment, including the builder identity and
41-
* build metadata.
42-
* </ul>
43-
*
44-
* <h2>Supporting Models</h2>
45-
*
46-
* <ul>
47-
* <li><b>{@link org.apache.commons.build.models.slsa.v1_2.Builder}</b> - Identifies the
48-
* entity that executed the build.
49-
* <li><b>{@link org.apache.commons.build.models.slsa.v1_2.BuildMetadata}</b> - Contains
50-
* metadata about the build invocation, including timing information.
51-
* <li><b>{@link org.apache.commons.build.models.slsa.v1_2.ResourceDescriptor}</b> - Describes
52-
* an artifact or resource referenced in the build by URI and cryptographic digest.
53-
* </ul>
54-
*
55-
* <h2>Usage Example</h2>
56-
*
57-
* <pre>
58-
* // Create a builder
59-
* Builder builder = new Builder();
60-
* builder.setId("https://github.com/actions");
61-
* builder.setVersion("1.0");
62-
*
63-
* // Create build metadata
64-
* BuildMetadata buildMetadata = new BuildMetadata();
65-
* buildMetadata.setInvocationId("build-12345");
66-
* buildMetadata.setStartedOn(OffsetDateTime.now(ZoneOffset.UTC));
67-
* buildMetadata.setFinishedOn(OffsetDateTime.now(ZoneOffset.UTC));
68-
*
69-
* // Create run details
70-
* RunDetails runDetails = new RunDetails();
71-
* runDetails.setBuilder(builder);
72-
* runDetails.setMetadata(buildMetadata);
73-
*
74-
* // Create build definition
75-
* BuildDefinition buildDefinition = new BuildDefinition();
76-
* buildDefinition.setBuildType("https://github.com/actions");
77-
* buildDefinition.setExternalParameters(new HashMap<>());
78-
*
79-
* // Create provenance
80-
* Provenance provenance = new Provenance();
81-
* provenance.setBuildDefinition(buildDefinition);
82-
* provenance.setRunDetails(runDetails);
83-
*
84-
* // Serialize with Jackson
85-
* ObjectMapper mapper = new ObjectMapper();
86-
* String json = mapper.writeValueAsString(provenance);
87-
* </pre>
88-
*
89-
* <h2>Jackson Integration</h2>
90-
*
91-
* <p>All models use Jackson annotations for JSON serialization/deserialization:
92-
*
93-
* <ul>
94-
* <li>{@code @JsonProperty} - Maps field names to JSON properties
95-
* <li>{@code @JsonInclude} - Controls inclusion of null/empty values in serialization
96-
* <li>{@code @JsonFormat} - Specifies date/time formatting
97-
* </ul>
98-
*
99-
* <p>The models are compatible with Jackson's ObjectMapper and support both serialization to
100-
* JSON and deserialization from JSON.
101-
*
102-
* <h2>Validation</h2>
103-
*
104-
* <p>Some models include Jakarta Validation annotations:
105-
*
106-
* <ul>
107-
* <li>{@code @NotBlank} - Ensures required string fields are not empty
108-
* </ul>
109-
*
110-
* <p>Users can enable validation using a Jakarta Validation provider to ensure provenance
111-
* integrity.
112-
*
113-
* <h2>Reference</h2>
26+
* <p>SLSA is a framework for evaluating and improving the security posture of build systems. SLSA v1.2 defines a standard for recording build provenance:
27+
* information about how software artifacts were produced.</p>
11428
*
11529
* @see <a href="https://slsa.dev/spec/v1.2">SLSA v1.2 Specification</a>
11630
* @see <a href="https://github.com/in-toto/attestation">In-toto Attestation Framework</a>

0 commit comments

Comments
 (0)