1 package org.apache.maven.ant.tasks;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.plugins.antrun.AntRunMojo;
23 import org.apache.maven.plugins.antrun.MavenAntRunProject;
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.codehaus.plexus.util.FileUtils;
30
31 import java.io.File;
32
33
34
35
36 public class AttachArtifactTask
37 extends Task
38 {
39
40
41
42
43 private String mavenProjectRefId = AntRunMojo.DEFAULT_MAVEN_PROJECT_REF_REFID;
44
45
46
47
48 @SuppressWarnings( "FieldCanBeLocal" )
49 private String mavenProjectHelperRefId = AntRunMojo.DEFAULT_MAVEN_PROJECT_HELPER_REFID;
50
51
52
53
54 private File file;
55
56
57
58
59 private String classifier;
60
61
62
63
64 private String type;
65
66
67 @Override
68 public void execute()
69 {
70 if ( file == null )
71 {
72 throw new BuildException( "File is a required parameter." );
73 }
74
75 if ( !file.exists() )
76 {
77 throw new BuildException( "File does not exist: " + file );
78 }
79
80 if ( this.getProject().getReference( mavenProjectRefId ) == null )
81 {
82 throw new BuildException( "Maven project reference not found: " + mavenProjectRefId );
83 }
84
85 if ( type == null )
86 {
87 type = FileUtils.getExtension( file.getName() );
88 }
89
90 MavenProject mavenProject =
91 ( (MavenAntRunProject) this.getProject().getReference( mavenProjectRefId ) ).getMavenProject();
92
93 if ( this.getProject().getReference( mavenProjectHelperRefId ) == null )
94 {
95 throw new BuildException( "Maven project helper reference not found: " + mavenProjectHelperRefId );
96 }
97
98 log( "Attaching " + file + " as an attached artifact", Project.MSG_VERBOSE );
99 MavenProjectHelper projectHelper = getProject().getReference( mavenProjectHelperRefId );
100 projectHelper.attachArtifact( mavenProject, type, classifier, file );
101 }
102
103
104
105
106 public File getFile()
107 {
108 return file;
109 }
110
111
112
113
114 public void setFile( File file )
115 {
116 this.file = file;
117 }
118
119
120
121
122 public String getMavenProjectRefId()
123 {
124 return mavenProjectRefId;
125 }
126
127
128
129
130 public void setMavenProjectRefId( String mavenProjectRefId )
131 {
132 this.mavenProjectRefId = mavenProjectRefId;
133 }
134
135
136
137
138 public String getClassifier()
139 {
140 return classifier;
141 }
142
143
144
145
146 public void setClassifier( String classifier )
147 {
148 this.classifier = classifier;
149 }
150
151
152
153
154 public String getType()
155 {
156 return type;
157 }
158
159
160
161
162 public void setType( String type )
163 {
164 this.type = type;
165 }
166 }