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