1 | |
package org.apache.maven.artifact.ant; |
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.installer.ArtifactInstaller; |
25 | |
import org.apache.maven.artifact.metadata.ArtifactMetadata; |
26 | |
import org.apache.maven.artifact.repository.ArtifactRepository; |
27 | |
import org.apache.maven.project.artifact.ProjectArtifactMetadata; |
28 | |
import org.apache.tools.ant.BuildException; |
29 | |
|
30 | |
import java.util.Iterator; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | 0 | public class InstallTask |
40 | |
extends InstallDeployTaskSupport |
41 | |
{ |
42 | |
protected void doExecute() |
43 | |
{ |
44 | 0 | ArtifactRepository localRepo = createLocalArtifactRepository(); |
45 | |
|
46 | 0 | Pom pom = buildPom( localRepo ); |
47 | |
|
48 | 0 | if ( pom == null ) |
49 | |
{ |
50 | 0 | throw new BuildException( "A POM element is required to install to the local repository" ); |
51 | |
} |
52 | |
|
53 | 0 | Artifact artifact = pom.getArtifact(); |
54 | |
|
55 | 0 | boolean isPomArtifact = "pom".equals( pom.getPackaging() ); |
56 | 0 | if ( !isPomArtifact ) |
57 | |
{ |
58 | 0 | ArtifactMetadata metadata = new ProjectArtifactMetadata( artifact, pom.getFile() ); |
59 | 0 | artifact.addMetadata( metadata ); |
60 | |
} |
61 | |
|
62 | 0 | ArtifactInstaller installer = (ArtifactInstaller) lookup( ArtifactInstaller.ROLE ); |
63 | |
try |
64 | |
{ |
65 | 0 | if ( !isPomArtifact ) |
66 | |
{ |
67 | 0 | if ( file == null ) |
68 | |
{ |
69 | 0 | throw new BuildException( "You must specify a file to install to the local repository." ); |
70 | |
} |
71 | |
|
72 | 0 | installer.install( file, artifact, localRepo ); |
73 | |
} |
74 | |
else |
75 | |
{ |
76 | 0 | installer.install( pom.getFile(), artifact, localRepo ); |
77 | |
} |
78 | |
|
79 | |
|
80 | 0 | if ( attachedArtifacts != null ) |
81 | |
{ |
82 | 0 | Iterator iter = pom.getAttachedArtifacts().iterator(); |
83 | |
|
84 | 0 | while ( iter.hasNext() ) |
85 | |
{ |
86 | 0 | Artifact attachedArtifact = (Artifact) iter.next(); |
87 | 0 | installer.install( attachedArtifact.getFile(), attachedArtifact, localRepo ); |
88 | 0 | } |
89 | |
} |
90 | |
} |
91 | 0 | catch ( ArtifactInstallationException e ) |
92 | |
{ |
93 | 0 | throw new BuildException( |
94 | |
"Error installing artifact '" + artifact.getDependencyConflictId() + "': " + e.getMessage(), e ); |
95 | 0 | } |
96 | 0 | } |
97 | |
} |