Skip to content

Commit 899e27f

Browse files
committed
Add type to freeze
1 parent d6891a3 commit 899e27f

File tree

5 files changed

+79
-4
lines changed

5 files changed

+79
-4
lines changed

maven_plugin/src/main/java/io/github/chains_project/maven_lockfile/FreezeDependencyMojo.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ private Dependency toMavenDependency(DependencyNode dep) {
160160
if (dep.getClassifier() != null) {
161161
mavenDep.setClassifier(dep.getClassifier().getValue());
162162
}
163+
if (dep.getType() != null) {
164+
mavenDep.setType(dep.getType().getValue());
165+
}
163166
mavenDep.setScope(dep.getScope().getValue());
164167
return mavenDep;
165168
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package io.github.chains_project.maven_lockfile.data;
2+
3+
import com.google.common.base.Strings;
4+
import java.util.Objects;
5+
6+
/**
7+
* A Maven artifact type specifies the packaging type of the artifact (e.g., jar, pom, war).
8+
* The default type is "jar", so we return null for "jar" or null/empty input to avoid redundant data.
9+
*/
10+
public class ArtifactType implements Comparable<ArtifactType> {
11+
public static ArtifactType of(String type) {
12+
if (Strings.isNullOrEmpty(type) || "jar".equals(type)) {
13+
return null;
14+
}
15+
return new ArtifactType(type);
16+
}
17+
18+
private final String value;
19+
20+
private ArtifactType(String type) {
21+
this.value = Objects.requireNonNull(type, "type is marked non-null but is null");
22+
}
23+
24+
public String getValue() {
25+
return value;
26+
}
27+
28+
@Override
29+
public String toString() {
30+
return "{" + " ArtifactType='" + getValue() + "'" + "}";
31+
}
32+
33+
@Override
34+
public boolean equals(Object o) {
35+
if (o == this) return true;
36+
if (!(o instanceof ArtifactType)) {
37+
return false;
38+
}
39+
ArtifactType artifactType = (ArtifactType) o;
40+
return Objects.equals(value, artifactType.value);
41+
}
42+
43+
@Override
44+
public int hashCode() {
45+
return Objects.hashCode(value);
46+
}
47+
48+
@Override
49+
public int compareTo(ArtifactType o) {
50+
return this.value.compareTo(o.value);
51+
}
52+
}

maven_plugin/src/main/java/io/github/chains_project/maven_lockfile/graph/DependencyGraph.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import io.github.chains_project.maven_lockfile.checksum.AbstractChecksumCalculator;
66
import io.github.chains_project.maven_lockfile.checksum.RepositoryInformation;
77
import io.github.chains_project.maven_lockfile.data.ArtifactId;
8+
import io.github.chains_project.maven_lockfile.data.ArtifactType;
89
import io.github.chains_project.maven_lockfile.data.Classifier;
910
import io.github.chains_project.maven_lockfile.data.GroupId;
1011
import io.github.chains_project.maven_lockfile.data.MavenScope;
@@ -87,6 +88,7 @@ private static Optional<DependencyNode> createDependencyNode(
8788
var artifactId = ArtifactId.of(node.getArtifact().getArtifactId());
8889
var version = VersionNumber.of(node.getArtifact().getVersion());
8990
var classifier = Classifier.of(node.getArtifact().getClassifier());
91+
var type = ArtifactType.of(node.getArtifact().getType());
9092
PluginLogManager.getLog().debug(String.format("Calculating checksum for %s", node.toNodeString()));
9193
var checksum = isRoot ? "" : calc.calculateArtifactChecksum(node.getArtifact());
9294
var scope = MavenScope.fromString(node.getArtifact().getScope());
@@ -105,6 +107,7 @@ private static Optional<DependencyNode> createDependencyNode(
105107
groupId,
106108
version,
107109
classifier,
110+
type,
108111
scope,
109112
repositoryInformation.getResolvedUrl(),
110113
repositoryInformation.getRepositoryId(),

maven_plugin/src/main/java/io/github/chains_project/maven_lockfile/graph/DependencyNode.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.google.gson.annotations.Expose;
44
import io.github.chains_project.maven_lockfile.data.ArtifactId;
5+
import io.github.chains_project.maven_lockfile.data.ArtifactType;
56
import io.github.chains_project.maven_lockfile.data.Classifier;
67
import io.github.chains_project.maven_lockfile.data.GroupId;
78
import io.github.chains_project.maven_lockfile.data.MavenScope;
@@ -20,6 +21,7 @@ public class DependencyNode implements Comparable<DependencyNode> {
2021
private final ArtifactId artifactId;
2122
private final VersionNumber version;
2223
private final Classifier classifier;
24+
private final ArtifactType type;
2325
private final String checksumAlgorithm;
2426
private final String checksum;
2527
private final MavenScope scope;
@@ -42,6 +44,7 @@ public class DependencyNode implements Comparable<DependencyNode> {
4244
GroupId groupId,
4345
VersionNumber version,
4446
Classifier classifier,
47+
ArtifactType type,
4548
MavenScope scope,
4649
ResolvedUrl resolved,
4750
RepositoryId repositoryId,
@@ -51,6 +54,7 @@ public class DependencyNode implements Comparable<DependencyNode> {
5154
this.groupId = groupId;
5255
this.version = version;
5356
this.classifier = classifier;
57+
this.type = type;
5458
this.checksumAlgorithm = checksumAlgorithm;
5559
this.checksum = checksum;
5660
this.children = new TreeSet<>(Comparator.comparing(DependencyNode::getComparatorString));
@@ -89,6 +93,12 @@ public VersionNumber getVersion() {
8993
public Classifier getClassifier() {
9094
return classifier;
9195
}
96+
/**
97+
* @return the artifact type or null if default (jar)
98+
*/
99+
public ArtifactType getType() {
100+
return type;
101+
}
92102
/**
93103
* @return the scope
94104
*/
@@ -173,6 +183,7 @@ public int hashCode() {
173183
artifactId,
174184
version,
175185
classifier,
186+
type,
176187
checksumAlgorithm,
177188
checksum,
178189
scope,
@@ -195,6 +206,7 @@ public boolean equals(Object obj) {
195206
&& Objects.equals(artifactId, other.artifactId)
196207
&& Objects.equals(version, other.version)
197208
&& Objects.equals(classifier, other.classifier)
209+
&& Objects.equals(type, other.type)
198210
&& Objects.equals(checksumAlgorithm, other.checksumAlgorithm)
199211
&& Objects.equals(checksum, other.checksum)
200212
&& Objects.equals(scope, other.scope)
@@ -233,10 +245,10 @@ public int compareTo(DependencyNode o) {
233245
@Override
234246
public String toString() {
235247
return "DependencyNode [groupId=" + groupId + ", artifactId=" + artifactId + ", version=" + version
236-
+ ", classifier=" + classifier + ", checksumAlgorithm=" + checksumAlgorithm + ", checksum=" + checksum
237-
+ ", scope=" + scope + ", resolved=" + resolved + ", repositoryId=" + repositoryId
238-
+ ", selectedVersion=" + selectedVersion + ", id=" + id + ", parent=" + parent + ", children="
239-
+ children + "]";
248+
+ ", classifier=" + classifier + ", type=" + type + ", checksumAlgorithm=" + checksumAlgorithm
249+
+ ", checksum=" + checksum + ", scope=" + scope + ", resolved=" + resolved + ", repositoryId="
250+
+ repositoryId + ", selectedVersion=" + selectedVersion + ", id=" + id + ", parent=" + parent
251+
+ ", children=" + children + "]";
240252
}
241253

242254
public String getComparatorString() {

maven_plugin/src/test/java/io/github/chains_project/maven_lockfile/graph/LockfileTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import io.github.chains_project.maven_lockfile.checksum.ChecksumModes;
66
import io.github.chains_project.maven_lockfile.data.ArtifactId;
7+
import io.github.chains_project.maven_lockfile.data.ArtifactType;
78
import io.github.chains_project.maven_lockfile.data.Config;
89
import io.github.chains_project.maven_lockfile.data.Environment;
910
import io.github.chains_project.maven_lockfile.data.GroupId;
@@ -65,6 +66,7 @@ private DependencyNode dependencyNodeA(DependencyNode child1, DependencyNode chi
6566
GroupId.of("Ag"),
6667
VersionNumber.of("1"),
6768
null,
69+
ArtifactType.of("pom"),
6870
MavenScope.RUNTIME,
6971
ResolvedUrl.Unresolved(),
7072
RepositoryId.None(),
@@ -82,6 +84,7 @@ private DependencyNode dependencyNodeB() {
8284
GroupId.of("Bg"),
8385
VersionNumber.of("1"),
8486
null,
87+
ArtifactType.of("jar"),
8588
MavenScope.RUNTIME,
8689
ResolvedUrl.Unresolved(),
8790
RepositoryId.None(),
@@ -95,6 +98,7 @@ private DependencyNode dependencyNodeAChild1() {
9598
GroupId.of("Ag1"),
9699
VersionNumber.of("1"),
97100
null,
101+
ArtifactType.of("war"),
98102
MavenScope.RUNTIME,
99103
ResolvedUrl.Unresolved(),
100104
RepositoryId.None(),
@@ -108,6 +112,7 @@ private DependencyNode dependencyNodeAChild2() {
108112
GroupId.of("Ag2"),
109113
VersionNumber.of("1"),
110114
null,
115+
ArtifactType.of("jar"),
111116
MavenScope.RUNTIME,
112117
ResolvedUrl.Unresolved(),
113118
RepositoryId.None(),

0 commit comments

Comments
 (0)