Skip to content

Commit 1a48982

Browse files
committed
Merge pull request #125 from janezkranjc/master
added support for the classifier coordinate
2 parents 6378fa6 + c3f30b7 commit 1a48982

5 files changed

Lines changed: 48 additions & 10 deletions

File tree

restx-build/src/main/java/restx/build/GAV.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,39 @@
88
public class GAV {
99
public static GAV parse(String gav) {
1010
String[] parts = gav.split(":");
11-
if (parts.length < 3 || parts.length > 4) {
11+
if (parts.length < 3 || parts.length > 5) {
1212
throw new IllegalArgumentException("can't parse '" + gav + "' as a module coordinates (GAV). " +
13-
"It must have at least 3 parts separated by columns. (4th is optional and correspond to artifact type)");
13+
"It must have at least 3 parts separated by columns. (4th and 5th are optional and correspond to artifact type and classifier)");
1414
}
1515
if(parts.length == 3) {
1616
return new GAV(parts[0], parts[1], parts[2]);
1717
}
18-
return new GAV(parts[0], parts[1], parts[2], parts[3]);
18+
if(parts.length == 4) {
19+
return new GAV(parts[0], parts[1], parts[2], parts[3]);
20+
}
21+
return new GAV(parts[0], parts[1], parts[2], parts[3], parts[4]);
1922
}
2023

2124
private final String groupId;
2225
private final String artifactId;
2326
private final String version;
2427
private final String type;
28+
private final String classifier;
2529

2630
public GAV(String groupId, String artifactId, String version) {
27-
this(groupId, artifactId, version, null);
31+
this(groupId, artifactId, version, null, null);
2832
}
2933

30-
public GAV(final String groupId, final String artifactId, final String version, final String type) {
34+
public GAV(String groupId, String artifactId, String version, String type) {
35+
this(groupId, artifactId, version, type, null);
36+
}
37+
38+
public GAV(final String groupId, final String artifactId, final String version, final String type, final String classifier) {
3139
this.groupId = groupId;
3240
this.artifactId = artifactId;
3341
this.version = version;
3442
this.type = type;
43+
this.classifier = classifier;
3544
}
3645

3746
public String getGroupId() {
@@ -50,6 +59,10 @@ public String getType() {
5059
return type;
5160
}
5261

62+
public String getClassifier() {
63+
return classifier;
64+
}
65+
5366
@Override
5467
public String toString() {
5568
if (type == null){

restx-build/src/main/java/restx/build/IvySupport.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ public class IvySupport implements RestxBuild.Generator {
1313
private String eaVersion = "0.9";
1414

1515
public void generate(ModuleDescriptor md, Writer w) throws IOException {
16-
w.write("<ivy-module version=\"2.0\" xmlns:ea=\"http://www.easyant.org\">\n");
17-
16+
if (md.hasClassifier()) {
17+
w.write("<ivy-module version=\"2.0\" xmlns:ea=\"http://www.easyant.org\" xmlns:e=\"http://ant.apache.org/ivy/extra\">\n");
18+
} else {
19+
w.write("<ivy-module version=\"2.0\" xmlns:ea=\"http://www.easyant.org\">\n");
20+
}
1821

1922
w.write(" <info organisation=\"" + md.getGav().getGroupId() +
2023
"\" module=\"" + md.getGav().getArtifactId() +
@@ -56,10 +59,18 @@ public void generate(ModuleDescriptor md, Writer w) throws IOException {
5659
if (expandedVersion.endsWith("-SNAPSHOT")) {
5760
expandedVersion = "latest.integration";
5861
}
59-
w.write(String.format(" <dependency org=\"%s\" name=\"%s\" rev=\"%s\" conf=\"%s\" />\n",
62+
if (dependency.getGav().getClassifier() == null) {
63+
w.write(String.format(" <dependency org=\"%s\" name=\"%s\" rev=\"%s\" conf=\"%s\" />\n",
64+
groupId, dependency.getGav().getArtifactId(),
65+
expandedVersion,
66+
"compile".equals(scope) ? "default" : scope +"->default"));
67+
} else {
68+
w.write(String.format(" <dependency org=\"%s\" name=\"%s\" rev=\"%s\" conf=\"%s\">\n <artifact name=\"%s\" e:classifier=\"%s\" />\n </dependency>\n",
6069
groupId, dependency.getGav().getArtifactId(),
6170
expandedVersion,
62-
"compile".equals(scope) ? "default" : scope +"->default"));
71+
"compile".equals(scope) ? "default" : scope +"->default",
72+
dependency.getGav().getArtifactId(), dependency.getGav().getClassifier()));
73+
}
6374
}
6475
}
6576
w.write(" </dependencies>\n");

restx-build/src/main/java/restx/build/MavenSupport.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ private void toMavenGAV(GAV gav, String indent, Writer w) throws IOException {
167167
if(gav.getType() != null) {
168168
writeXmlTag(w, indent, "type", gav.getType());
169169
}
170+
if(gav.getClassifier() != null) {
171+
writeXmlTag(w, indent, "classifier", gav.getClassifier());
172+
}
170173
}
171174

172175
private void writeXmlTag(Writer w, String indent, String tag, String val) throws IOException {

restx-build/src/main/java/restx/build/ModuleDescriptor.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,15 @@ public ModuleDescriptor concatDependency(String scope, ModuleDependency dep) {
6767

6868
return new ModuleDescriptor(parent, gav, packaging, properties, fragments, newDeps);
6969
}
70+
71+
public boolean hasClassifier() {
72+
for (String scope : this.getDependencyScopes()) {
73+
for (ModuleDependency dependency : this.getDependencies(scope)) {
74+
if (dependency.getGav().getClassifier()!=null) {
75+
return true;
76+
}
77+
}
78+
}
79+
return false;
80+
}
7081
}

restx-core-shell/src/main/java/restx/core/shell/DepsShellCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void run(RestxShell shell) throws Exception {
9292
ivy.retrieve(resolveReport.getModuleDescriptor().getModuleRevisionId(),
9393
new RetrieveOptions()
9494
.setDestArtifactPattern(
95-
shell.currentLocation().toAbsolutePath() + "/target/dependency/[artifact]-[revision].[ext]")
95+
shell.currentLocation().toAbsolutePath() + "/target/dependency/[artifact]-[revision](-[classifier]).[ext]")
9696
.setSync(true)
9797
);
9898

0 commit comments

Comments
 (0)