1 | |
package org.apache.maven.plugin.install; |
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.artifact.Artifact; |
23 | |
import org.apache.maven.artifact.installer.ArtifactInstallationException; |
24 | |
import org.apache.maven.artifact.metadata.ArtifactMetadata; |
25 | |
import org.apache.maven.plugin.MojoExecutionException; |
26 | |
import org.apache.maven.project.artifact.ProjectArtifactMetadata; |
27 | |
|
28 | |
import java.io.File; |
29 | |
import java.util.Iterator; |
30 | |
import java.util.List; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | 7 | public class InstallMojo |
41 | |
extends AbstractInstallMojo |
42 | |
{ |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
protected String packaging; |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
private File pomFile; |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
private Artifact artifact; |
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
private List attachedArtifacts; |
70 | |
|
71 | |
public void execute() |
72 | |
throws MojoExecutionException |
73 | |
{ |
74 | |
|
75 | 6 | boolean isPomArtifact = "pom".equals( packaging ); |
76 | |
|
77 | 6 | ArtifactMetadata metadata = null; |
78 | |
|
79 | 6 | if ( updateReleaseInfo ) |
80 | |
{ |
81 | 1 | artifact.setRelease( true ); |
82 | |
} |
83 | |
|
84 | |
try |
85 | |
{ |
86 | 6 | if ( isPomArtifact ) |
87 | |
{ |
88 | 1 | installer.install( pomFile, artifact, localRepository ); |
89 | 1 | installChecksums( artifact ); |
90 | |
} |
91 | |
else |
92 | |
{ |
93 | 5 | metadata = new ProjectArtifactMetadata( artifact, pomFile ); |
94 | 5 | artifact.addMetadata( metadata ); |
95 | |
|
96 | 5 | File file = artifact.getFile(); |
97 | |
|
98 | |
|
99 | |
|
100 | 5 | if ( file != null && file.isFile() ) |
101 | |
{ |
102 | 3 | installer.install( file, artifact, localRepository ); |
103 | 3 | installChecksums( artifact ); |
104 | |
} |
105 | 2 | else if ( !attachedArtifacts.isEmpty() ) |
106 | |
{ |
107 | 1 | getLog().info( "No primary artifact to install, installing attached artifacts instead." ); |
108 | |
|
109 | 1 | Artifact pomArtifact = |
110 | |
artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), |
111 | |
artifact.getBaseVersion() ); |
112 | 1 | pomArtifact.setFile( pomFile ); |
113 | 1 | if ( updateReleaseInfo ) |
114 | |
{ |
115 | 0 | pomArtifact.setRelease( true ); |
116 | |
} |
117 | |
|
118 | 1 | installer.install( pomFile, pomArtifact, localRepository ); |
119 | 1 | installChecksums( pomArtifact ); |
120 | |
} |
121 | |
else |
122 | |
{ |
123 | 1 | throw new MojoExecutionException( |
124 | |
"The packaging for this project did not assign a file to the build artifact" ); |
125 | |
} |
126 | |
} |
127 | |
|
128 | 5 | for ( Iterator i = attachedArtifacts.iterator(); i.hasNext(); ) |
129 | |
{ |
130 | 2 | Artifact attached = (Artifact) i.next(); |
131 | |
|
132 | 2 | installer.install( attached.getFile(), attached, localRepository ); |
133 | 2 | installChecksums( attached ); |
134 | |
} |
135 | |
} |
136 | 0 | catch ( ArtifactInstallationException e ) |
137 | |
{ |
138 | 0 | throw new MojoExecutionException( e.getMessage(), e ); |
139 | 5 | } |
140 | 5 | } |
141 | |
} |