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