1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.nuxeo.build.ant.artifact;
18
19 import java.io.IOException;
20
21 import org.apache.tools.ant.BuildException;
22 import org.apache.tools.ant.taskdefs.Sequential;
23 import org.eclipse.aether.artifact.Artifact;
24
25
26
27
28
29
30
31
32
33 public class ArtifactForeach extends Sequential {
34
35 public String property;
36
37 public ArtifactSet artifactSet;
38
39 public String getProperty() {
40 return property;
41 }
42
43 public void setProperty(String property) {
44 this.property = property;
45 }
46
47 public ArtifactSet getArtifactSet() {
48 return artifactSet;
49 }
50
51 public void setSetref(String setref) {
52 artifactSet = (ArtifactSet) getProject().getReference(setref);
53
54 }
55
56 @Override
57 public void execute() throws BuildException {
58 for (Artifact artifact : artifactSet.getArtifacts()) {
59 String canonicalPath = null;
60 try {
61 canonicalPath = artifact.getFile().getCanonicalPath();
62 } catch (IOException e) {
63 throw new BuildException(
64 "Failed to artifact file canonical path for "
65 + artifact, e);
66 }
67 getProject().setProperty(property + ".file.path", canonicalPath);
68 getProject().setProperty(property + ".archetypeId",
69 artifact.getArtifactId());
70 getProject().setProperty(property + ".groupId",
71 artifact.getGroupId());
72 getProject().setProperty(property + ".version",
73 artifact.getBaseVersion());
74 try {
75 super.execute();
76 } catch (BuildException e) {
77 throw new BuildException(
78 "Couldn't execute the task for artifact " + artifact, e);
79 }
80 }
81
82 }
83 }