1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.nuxeo.build.ant.artifact;
20
21 import java.io.File;
22
23 import org.apache.maven.artifact.Artifact;
24 import org.apache.maven.project.MavenProject;
25 import org.apache.maven.project.MavenProjectHelper;
26 import org.apache.tools.ant.BuildException;
27 import org.apache.tools.ant.Project;
28 import org.apache.tools.ant.Task;
29 import org.nuxeo.build.maven.AntBuildMojo;
30
31
32
33
34
35
36 public class AttachArtifactTask extends Task {
37
38 private File file;
39
40 private String classifier;
41
42 private String type;
43
44
45
46
47 public void setFile(File file) {
48 this.file = file;
49 }
50
51
52
53
54
55 public void setClassifier(String classifier) {
56 this.classifier = "".equals(classifier) ? null : classifier;
57 }
58
59
60
61
62
63
64 @Deprecated
65 public void setTarget(String artifactKey) {
66 log("The target parameter is deprecated and ignored. The attach task now only applies to the current project.",
67 Project.MSG_WARN);
68 }
69
70
71
72
73
74 public void setType(String type) {
75 this.type = type;
76 }
77
78 @Override
79 public void execute() throws BuildException {
80 MavenProject pom = AntBuildMojo.getInstance().getProject();
81 log("Attaching " + file + " to " + pom, Project.MSG_INFO);
82 if (type == null) {
83 type = getExtension(file.getName());
84 log("Unspecified type, using: " + type, Project.MSG_WARN);
85 }
86 Artifact pomArtifact = pom.getArtifact();
87 if (classifier != null || !type.equals(pomArtifact.getType())) {
88 AntBuildMojo.getInstance().getProjectHelper().attachArtifact(pom,
89 type, classifier, file);
90 } else {
91 pomArtifact.setFile(file);
92 pomArtifact.setResolved(true);
93 }
94 }
95
96
97
98
99
100 private String getExtension(String name) {
101 int idx = name.lastIndexOf('.');
102 return name.substring(idx + 1);
103 }
104 }