1 | |
package org.apache.maven.artifact.installer; |
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.metadata.ArtifactMetadata; |
24 | |
import org.apache.maven.artifact.repository.ArtifactRepository; |
25 | |
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataInstallationException; |
26 | |
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager; |
27 | |
import org.apache.maven.artifact.transform.ArtifactTransformationManager; |
28 | |
import org.codehaus.plexus.logging.AbstractLogEnabled; |
29 | |
import org.codehaus.plexus.util.FileUtils; |
30 | |
|
31 | |
import java.io.File; |
32 | |
import java.io.IOException; |
33 | |
import java.util.Iterator; |
34 | |
|
35 | 1 | public class DefaultArtifactInstaller |
36 | |
extends AbstractLogEnabled |
37 | |
implements ArtifactInstaller |
38 | |
{ |
39 | |
private ArtifactTransformationManager transformationManager; |
40 | |
|
41 | |
private RepositoryMetadataManager repositoryMetadataManager; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
public void install( String basedir, String finalName, Artifact artifact, ArtifactRepository localRepository ) |
47 | |
throws ArtifactInstallationException |
48 | |
{ |
49 | 0 | String extension = artifact.getArtifactHandler().getExtension(); |
50 | 0 | File source = new File( basedir, finalName + "." + extension ); |
51 | |
|
52 | 0 | install( source, artifact, localRepository ); |
53 | 0 | } |
54 | |
|
55 | |
public void install( File source, Artifact artifact, ArtifactRepository localRepository ) |
56 | |
throws ArtifactInstallationException |
57 | |
{ |
58 | |
try |
59 | |
{ |
60 | 1 | transformationManager.transformForInstall( artifact, localRepository ); |
61 | |
|
62 | 1 | String localPath = localRepository.pathOf( artifact ); |
63 | |
|
64 | |
|
65 | 1 | File destination = new File( localRepository.getBasedir(), localPath ); |
66 | 1 | if ( !destination.getParentFile().exists() ) |
67 | |
{ |
68 | 0 | destination.getParentFile().mkdirs(); |
69 | |
} |
70 | |
|
71 | 1 | getLogger().info( "Installing " + source.getPath() + " to " + destination ); |
72 | |
|
73 | 1 | FileUtils.copyFile( source, destination ); |
74 | |
|
75 | |
|
76 | 1 | for ( Iterator i = artifact.getMetadataList().iterator(); i.hasNext(); ) |
77 | |
{ |
78 | 1 | ArtifactMetadata metadata = (ArtifactMetadata) i.next(); |
79 | 1 | repositoryMetadataManager.install( metadata, localRepository ); |
80 | 1 | } |
81 | |
|
82 | |
|
83 | |
|
84 | |
} |
85 | 0 | catch ( IOException e ) |
86 | |
{ |
87 | 0 | throw new ArtifactInstallationException( "Error installing artifact: " + e.getMessage(), e ); |
88 | |
} |
89 | 0 | catch ( RepositoryMetadataInstallationException e ) |
90 | |
{ |
91 | 0 | throw new ArtifactInstallationException( "Error installing artifact's metadata: " + e.getMessage(), e ); |
92 | 1 | } |
93 | 1 | } |
94 | |
} |