Skip to content

Commit bb59b67

Browse files
authored
Introduce publication (#254)
1 parent 2549a40 commit bb59b67

File tree

4 files changed

+138
-3
lines changed

4 files changed

+138
-3
lines changed

interface-test/src/test/java/coursierapi/test/FetchTests.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package coursierapi.test;
22

33
import coursierapi.Dependency;
4+
import coursierapi.Publication;
45
import coursierapi.Fetch;
56
import coursierapi.FetchResult;
67
import coursierapi.error.CoursierError;
@@ -44,4 +45,28 @@ public void simple() {
4445

4546
}
4647

48+
49+
@Test
50+
public void withPublication() {
51+
Dependency dep = Dependency.of("com.google.protobuf", "protoc", "3.18.2")
52+
.withPublication(new Publication("protoc", "jar", "exe", "windows-x86_32"));
53+
54+
Fetch fetch = Fetch.create().addDependencies(dep);
55+
56+
FetchResult result;
57+
try {
58+
result = fetch.fetchResult();
59+
} catch (CoursierError e) {
60+
throw new RuntimeException(e);
61+
}
62+
63+
Set<String> fileNames = new HashSet<>();
64+
for (File f : result.getFiles()) {
65+
fileNames.add(f.getName());
66+
}
67+
68+
Set<String> expectedFileNames = new HashSet<>(Arrays.asList("protoc-3.18.2-windows-x86_32.exe"));
69+
assertEquals(expectedFileNames, fileNames);
70+
}
71+
4772
}

interface/src/main/java/coursierapi/Dependency.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public final class Dependency implements Serializable {
1313
private String configuration;
1414
private String type;
1515
private String classifier;
16+
private Publication publication;
1617
private boolean transitive;
1718

1819

@@ -23,6 +24,7 @@ private Dependency(Module module, String version) {
2324
this.configuration = "";
2425
this.type = "";
2526
this.classifier = "";
27+
this.publication = null;
2628
this.transitive = true;
2729
}
2830

@@ -38,6 +40,7 @@ public static Dependency of(Dependency dependency) {
3840
.withConfiguration(dependency.getConfiguration())
3941
.withType(dependency.getType())
4042
.withClassifier(dependency.getClassifier())
43+
.withPublication(dependency.getPublication())
4144
.withTransitive(dependency.isTransitive());
4245
}
4346

@@ -82,6 +85,11 @@ public Dependency withClassifier(String classifier) {
8285
return this;
8386
}
8487

88+
public Dependency withPublication(Publication publication) {
89+
this.publication = publication;
90+
return this;
91+
}
92+
8593
public Dependency withTransitive(boolean transitive) {
8694
this.transitive = transitive;
8795
return this;
@@ -99,14 +107,15 @@ public boolean equals(Object obj) {
99107
this.configuration.equals(other.configuration) &&
100108
this.type.equals(other.type) &&
101109
this.classifier.equals(other.classifier) &&
110+
Objects.equals(this.publication, other.publication) &&
102111
this.transitive == other.transitive;
103112
}
104113
return false;
105114
}
106115

107116
@Override
108117
public int hashCode() {
109-
return 37 * (37 * (37 * (37 * (37 * (37 * (17 + module.hashCode()) + version.hashCode()) + exclusions.hashCode()) + configuration.hashCode()) + type.hashCode()) + classifier.hashCode()) + Boolean.hashCode(transitive);
118+
return 37 * (37 * (37 * (37 * (37 * (37 * (37 * (17 + module.hashCode()) + version.hashCode()) + exclusions.hashCode()) + configuration.hashCode()) + type.hashCode()) + classifier.hashCode()) + Objects.hashCode(publication)) + Boolean.hashCode(transitive);
110119
}
111120

112121
@Override
@@ -135,6 +144,10 @@ public String toString() {
135144
b.append(", classifier=");
136145
b.append(classifier);
137146
}
147+
if (publication != null) {
148+
b.append(", publication=");
149+
b.append(publication);
150+
}
138151
if (!transitive) {
139152
b.append(", intransitive");
140153
}
@@ -167,6 +180,10 @@ public String getClassifier() {
167180
return classifier;
168181
}
169182

183+
public Publication getPublication() {
184+
return publication;
185+
}
186+
170187
public boolean isTransitive() {
171188
return transitive;
172189
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package coursierapi;
2+
3+
import java.io.Serializable;
4+
5+
public final class Publication implements Serializable {
6+
7+
private final String name;
8+
private final String type;
9+
private final String extension;
10+
private final String classifier;
11+
12+
public Publication(String name, String type, String extension, String classifier) {
13+
this.name = name;
14+
this.type = type;
15+
this.extension = extension;
16+
this.classifier = classifier;
17+
}
18+
19+
public Publication(String name) {
20+
this(name, "", "", "");
21+
}
22+
23+
public Publication(String name, String type) {
24+
this(name, type, "", "");
25+
}
26+
27+
public Publication(String name, String type, String extension) {
28+
this(name, type, extension, "");
29+
}
30+
31+
public String getName() {
32+
return name;
33+
}
34+
35+
public String getType() {
36+
return type;
37+
}
38+
39+
public String getExtension() {
40+
return extension;
41+
}
42+
43+
public String getClassifier() {
44+
return classifier;
45+
}
46+
47+
@Override
48+
public boolean equals(Object o) {
49+
if (this == o)
50+
return true;
51+
if (o instanceof Publication) {
52+
Publication other = (Publication) o;
53+
return name.equals(other.name) &&
54+
type.equals(other.type) &&
55+
extension.equals(other.extension) &&
56+
classifier.equals(other.classifier);
57+
}
58+
return false;
59+
}
60+
61+
@Override
62+
public int hashCode() {
63+
return 37 * (37 * (37 * (37 * (17 + extension.hashCode()) + classifier.hashCode()) + type.hashCode()) + name.hashCode());
64+
}
65+
66+
@Override
67+
public String toString() {
68+
StringBuilder b = new StringBuilder("Publication(");
69+
b.append(name);
70+
b.append(", ");
71+
if (!type.isEmpty()) {
72+
b.append(", type=");
73+
b.append(type);
74+
}
75+
if (!classifier.isEmpty()) {
76+
b.append(", classifier=");
77+
b.append(classifier);
78+
}
79+
if (extension != null) {
80+
b.append(", extension=");
81+
b.append(extension);
82+
}
83+
b.append(")");
84+
return b.toString();
85+
}
86+
}

interface/src/main/scala/coursier/internal/api/ApiHelper.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import coursier._
88
import coursierapi.{Credentials, Logger, SimpleLogger}
99
import coursier.cache.loggers.RefreshLogger
1010
import coursier.cache.{ArchiveCache, CacheDefaults, CacheLogger, FileCache, UnArchiver}
11-
import coursier.core.{Authentication, Configuration, Version}
11+
import coursier.core.{Authentication, Configuration, Extension, Publication, Version}
1212
import coursier.error.{CoursierError, FetchError, ResolutionError}
1313
import coursier.ivy.IvyRepository
1414
import coursier.jvm.{JavaHome, JvmCache}
@@ -117,11 +117,18 @@ object ApiHelper {
117117
val tpe = Type(dep.getType)
118118
val classifier = Classifier(dep.getClassifier)
119119

120-
Dependency(module0, dep.getVersion)
120+
val dep0 = Dependency(module0, dep.getVersion)
121121
.withExclusions(exclusions)
122122
.withConfiguration(configuration)
123123
.withAttributes(Attributes(tpe, classifier))
124124
.withTransitive(dep.isTransitive)
125+
126+
Option(dep.getPublication)
127+
.map { p =>
128+
val p0 = Publication(p.getName, Type(p.getType), Extension(p.getExtension), Classifier(p.getClassifier))
129+
dep0.withPublication(p0)
130+
}
131+
.getOrElse(dep0)
125132
}
126133

127134
def dependency(dep: Dependency): coursierapi.Dependency =

0 commit comments

Comments
 (0)