Permalink
Browse files

Merge pull request #125 from janezkranjc/master

added support for the classifier coordinate
  • Loading branch information...
xhanin committed Nov 30, 2014
2 parents 6378fa6 + c3f30b7 commit 1a4898215f3213d8b8bd34379f88d9aaf1459557
@@ -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() {
@@ -50,6 +59,10 @@ public String getType() {
return type;
}
public String getClassifier() {
return classifier;
}
@Override
public String toString() {
if (type == null){
@@ -13,8 +13,11 @@
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() +
@@ -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");
@@ -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 {
@@ -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;
}
}
@@ -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)
);

0 comments on commit 1a48982

Please sign in to comment.