Skip to content

Commit

Permalink
Merge pull request #125 from janezkranjc/master
Browse files Browse the repository at this point in the history
added support for the classifier coordinate
  • Loading branch information
xhanin committed Nov 30, 2014
2 parents 6378fa6 + c3f30b7 commit 1a48982
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 10 deletions.
23 changes: 18 additions & 5 deletions restx-build/src/main/java/restx/build/GAV.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,39 @@
public class GAV {
public static GAV parse(String gav) {
String[] parts = gav.split(":");
if (parts.length < 3 || parts.length > 4) {
if (parts.length < 3 || parts.length > 5) {
throw new IllegalArgumentException("can't parse '" + gav + "' as a module coordinates (GAV). " +
"It must have at least 3 parts separated by columns. (4th is optional and correspond to artifact type)");
"It must have at least 3 parts separated by columns. (4th and 5th are optional and correspond to artifact type and classifier)");
}
if(parts.length == 3) {
return new GAV(parts[0], parts[1], parts[2]);
}
return new GAV(parts[0], parts[1], parts[2], parts[3]);
if(parts.length == 4) {
return new GAV(parts[0], parts[1], parts[2], parts[3]);
}
return new GAV(parts[0], parts[1], parts[2], parts[3], parts[4]);
}

private final String groupId;
private final String artifactId;
private final String version;
private final String type;
private final String classifier;

public GAV(String groupId, String artifactId, String version) {
this(groupId, artifactId, version, null);
this(groupId, artifactId, version, null, null);
}

public GAV(final String groupId, final String artifactId, final String version, final String type) {
public GAV(String groupId, String artifactId, String version, String type) {
this(groupId, artifactId, version, type, null);
}

public GAV(final String groupId, final String artifactId, final String version, final String type, final String classifier) {
this.groupId = groupId;
this.artifactId = artifactId;
this.version = version;
this.type = type;
this.classifier = classifier;
}

public String getGroupId() {
Expand All @@ -50,6 +59,10 @@ public String getType() {
return type;
}

public String getClassifier() {
return classifier;
}

@Override
public String toString() {
if (type == null){
Expand Down
19 changes: 15 additions & 4 deletions restx-build/src/main/java/restx/build/IvySupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ public class IvySupport implements RestxBuild.Generator {
private String eaVersion = "0.9";

public void generate(ModuleDescriptor md, Writer w) throws IOException {
w.write("<ivy-module version=\"2.0\" xmlns:ea=\"http://www.easyant.org\">\n");

if (md.hasClassifier()) {
w.write("<ivy-module version=\"2.0\" xmlns:ea=\"http://www.easyant.org\" xmlns:e=\"http://ant.apache.org/ivy/extra\">\n");
} else {
w.write("<ivy-module version=\"2.0\" xmlns:ea=\"http://www.easyant.org\">\n");
}

w.write(" <info organisation=\"" + md.getGav().getGroupId() +
"\" module=\"" + md.getGav().getArtifactId() +
Expand Down Expand Up @@ -56,10 +59,18 @@ public void generate(ModuleDescriptor md, Writer w) throws IOException {
if (expandedVersion.endsWith("-SNAPSHOT")) {
expandedVersion = "latest.integration";
}
w.write(String.format(" <dependency org=\"%s\" name=\"%s\" rev=\"%s\" conf=\"%s\" />\n",
if (dependency.getGav().getClassifier() == null) {
w.write(String.format(" <dependency org=\"%s\" name=\"%s\" rev=\"%s\" conf=\"%s\" />\n",
groupId, dependency.getGav().getArtifactId(),
expandedVersion,
"compile".equals(scope) ? "default" : scope +"->default"));
} else {
w.write(String.format(" <dependency org=\"%s\" name=\"%s\" rev=\"%s\" conf=\"%s\">\n <artifact name=\"%s\" e:classifier=\"%s\" />\n </dependency>\n",
groupId, dependency.getGav().getArtifactId(),
expandedVersion,
"compile".equals(scope) ? "default" : scope +"->default"));
"compile".equals(scope) ? "default" : scope +"->default",
dependency.getGav().getArtifactId(), dependency.getGav().getClassifier()));
}
}
}
w.write(" </dependencies>\n");
Expand Down
3 changes: 3 additions & 0 deletions restx-build/src/main/java/restx/build/MavenSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ private void toMavenGAV(GAV gav, String indent, Writer w) throws IOException {
if(gav.getType() != null) {
writeXmlTag(w, indent, "type", gav.getType());
}
if(gav.getClassifier() != null) {
writeXmlTag(w, indent, "classifier", gav.getClassifier());
}
}

private void writeXmlTag(Writer w, String indent, String tag, String val) throws IOException {
Expand Down
11 changes: 11 additions & 0 deletions restx-build/src/main/java/restx/build/ModuleDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,15 @@ public ModuleDescriptor concatDependency(String scope, ModuleDependency dep) {

return new ModuleDescriptor(parent, gav, packaging, properties, fragments, newDeps);
}

public boolean hasClassifier() {
for (String scope : this.getDependencyScopes()) {
for (ModuleDependency dependency : this.getDependencies(scope)) {
if (dependency.getGav().getClassifier()!=null) {
return true;
}
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void run(RestxShell shell) throws Exception {
ivy.retrieve(resolveReport.getModuleDescriptor().getModuleRevisionId(),
new RetrieveOptions()
.setDestArtifactPattern(
shell.currentLocation().toAbsolutePath() + "/target/dependency/[artifact]-[revision].[ext]")
shell.currentLocation().toAbsolutePath() + "/target/dependency/[artifact]-[revision](-[classifier]).[ext]")
.setSync(true)
);

Expand Down

0 comments on commit 1a48982

Please sign in to comment.