30
30
import org .apache .maven .model .PluginExecution ;
31
31
import org .apache .maven .plugin .AbstractMojo ;
32
32
import org .apache .maven .plugin .MojoExecutionException ;
33
- import org .apache .maven .plugin .MojoFailureException ;
34
33
import org .apache .maven .plugin .descriptor .PluginDescriptor ;
35
34
import org .apache .maven .plugins .annotations .Component ;
36
35
import org .apache .maven .plugins .annotations .LifecyclePhase ;
37
36
import org .apache .maven .plugins .annotations .Mojo ;
38
37
import org .apache .maven .plugins .annotations .Parameter ;
39
38
import org .apache .maven .project .MavenProject ;
40
39
import org .apache .maven .project .artifact .ProjectArtifact ;
41
- import org .apache .maven .project .artifact .ProjectArtifactMetadata ;
42
40
import org .eclipse .aether .RepositorySystem ;
43
- import org .eclipse .aether .artifact .Artifact ;
44
41
import org .eclipse .aether .installation .InstallRequest ;
45
42
import org .eclipse .aether .installation .InstallationException ;
46
- import org .eclipse .aether .util .artifact .SubArtifact ;
47
43
48
44
/**
49
45
* Installs the project's main artifact, and any other artifacts attached by other plugins in the lifecycle, to the
50
46
* local repository.
51
- *
47
+ *
52
48
* @author <a href="mailto:[email protected] ">Emmanuel Venisse</a>
53
49
*/
54
50
@ Mojo ( name = "install" , defaultPhase = LifecyclePhase .INSTALL , threadSafe = true )
@@ -74,7 +70,7 @@ public class InstallMojo
74
70
* Whether every project should be installed during its own install-phase or at the end of the multimodule build. If
75
71
* set to {@code true} and the build fails, none of the reactor projects is installed.
76
72
* <strong>(experimental)</strong>
77
- *
73
+ *
78
74
* @since 2.5
79
75
*/
80
76
@ Parameter ( defaultValue = "false" , property = "installAtEnd" )
@@ -83,7 +79,7 @@ public class InstallMojo
83
79
/**
84
80
* Set this to <code>true</code> to bypass artifact installation. Use this for artifacts that do not need to be
85
81
* installed in the local repository.
86
- *
82
+ *
87
83
* @since 2.4
88
84
*/
89
85
@ Parameter ( property = "maven.install.skip" , defaultValue = "false" )
@@ -115,7 +111,7 @@ private boolean hasState( MavenProject project )
115
111
116
112
@ Override
117
113
public void execute ()
118
- throws MojoExecutionException , MojoFailureException
114
+ throws MojoExecutionException
119
115
{
120
116
if ( skip )
121
117
{
@@ -194,16 +190,12 @@ private boolean hasExecution( Plugin plugin )
194
190
return false ;
195
191
}
196
192
197
- private void installProject ( MavenProject project ) throws MojoExecutionException , MojoFailureException
193
+ private void installProject ( MavenProject project ) throws MojoExecutionException
198
194
{
199
195
try
200
196
{
201
197
repositorySystem .install ( session .getRepositorySession (), processProject ( project ) );
202
198
}
203
- catch ( IllegalArgumentException e )
204
- {
205
- throw new MojoFailureException ( e .getMessage (), e );
206
- }
207
199
catch ( InstallationException e )
208
200
{
209
201
throw new MojoExecutionException ( e .getMessage (), e );
@@ -213,63 +205,40 @@ private void installProject( MavenProject project ) throws MojoExecutionExceptio
213
205
/**
214
206
* Processes passed in {@link MavenProject} and produces {@link InstallRequest} out of it.
215
207
*
216
- * @throws IllegalArgumentException if project is badly set up.
208
+ * @throws MojoExecutionException if project is badly set up.
217
209
*/
218
- private InstallRequest processProject ( MavenProject project )
210
+ private InstallRequest processProject ( MavenProject project ) throws MojoExecutionException
219
211
{
220
212
InstallRequest request = new InstallRequest ();
221
- org .apache .maven .artifact .Artifact mavenMainArtifact = project .getArtifact ();
222
- String packaging = project .getPackaging ();
223
- File pomFile = project .getFile ();
224
- boolean isPomArtifact = "pom" .equals ( packaging );
225
- boolean pomArtifactAttached = false ;
226
213
227
- if ( pomFile != null )
214
+ if ( isFile ( project . getFile () ) )
228
215
{
229
216
request .addArtifact ( RepositoryUtils .toArtifact ( new ProjectArtifact ( project ) ) );
230
- pomArtifactAttached = true ;
217
+ }
218
+ else
219
+ {
220
+ throw new MojoExecutionException ( "The project POM could not be attached" );
231
221
}
232
222
233
- if ( !isPomArtifact )
223
+ if ( !"pom" . equals ( project . getPackaging () ) )
234
224
{
235
- File file = mavenMainArtifact . getFile ();
236
- if ( file != null && file . isFile ( ) )
225
+ org . apache . maven . artifact . Artifact mavenMainArtifact = project . getArtifact ();
226
+ if ( isFile ( mavenMainArtifact . getFile () ) )
237
227
{
238
- Artifact mainArtifact = RepositoryUtils .toArtifact ( mavenMainArtifact );
239
- request .addArtifact ( mainArtifact );
240
-
241
- if ( !pomArtifactAttached )
242
- {
243
- for ( Object metadata : mavenMainArtifact .getMetadataList () )
244
- {
245
- if ( metadata instanceof ProjectArtifactMetadata )
246
- {
247
- request .addArtifact ( new SubArtifact (
248
- mainArtifact ,
249
- "" ,
250
- "pom"
251
- ).setFile ( ( (ProjectArtifactMetadata ) metadata ).getFile () ) );
252
- pomArtifactAttached = true ;
253
- }
254
- }
255
- }
228
+ request .addArtifact ( RepositoryUtils .toArtifact ( mavenMainArtifact ) );
256
229
}
257
230
else if ( !project .getAttachedArtifacts ().isEmpty () )
258
231
{
259
- throw new IllegalArgumentException ( "The packaging plugin for this project did not assign "
232
+ throw new MojoExecutionException ( "The packaging plugin for this project did not assign "
260
233
+ "a main file to the project but it has attachments. Change packaging to 'pom'." );
261
234
}
262
235
else
263
236
{
264
- throw new IllegalArgumentException ( "The packaging for this project did not assign "
237
+ throw new MojoExecutionException ( "The packaging for this project did not assign "
265
238
+ "a file to the build artifact" );
266
239
}
267
240
}
268
241
269
- if ( !pomArtifactAttached )
270
- {
271
- throw new IllegalArgumentException ( "The POM could not be attached" );
272
- }
273
242
274
243
for ( org .apache .maven .artifact .Artifact attached : project .getAttachedArtifacts () )
275
244
{
@@ -280,4 +249,8 @@ else if ( !project.getAttachedArtifacts().isEmpty() )
280
249
return request ;
281
250
}
282
251
252
+ private boolean isFile ( File file )
253
+ {
254
+ return file != null && file .isFile ();
255
+ }
283
256
}
0 commit comments