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