1 | |
package org.apache.maven.artifact.deployer; |
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.manager.WagonManager; |
24 | |
import org.apache.maven.artifact.metadata.ArtifactMetadata; |
25 | |
import org.apache.maven.artifact.repository.ArtifactRepository; |
26 | |
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataDeploymentException; |
27 | |
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager; |
28 | |
import org.apache.maven.artifact.transform.ArtifactTransformationManager; |
29 | |
import org.apache.maven.wagon.TransferFailedException; |
30 | |
import org.codehaus.plexus.logging.AbstractLogEnabled; |
31 | |
import org.codehaus.plexus.util.FileUtils; |
32 | |
|
33 | |
import java.io.File; |
34 | |
import java.io.IOException; |
35 | |
import java.util.Iterator; |
36 | |
|
37 | 1 | public class DefaultArtifactDeployer |
38 | |
extends AbstractLogEnabled |
39 | |
implements ArtifactDeployer |
40 | |
{ |
41 | |
private WagonManager wagonManager; |
42 | |
|
43 | |
private ArtifactTransformationManager transformationManager; |
44 | |
|
45 | |
private RepositoryMetadataManager repositoryMetadataManager; |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
public void deploy( String basedir, String finalName, Artifact artifact, ArtifactRepository deploymentRepository, |
51 | |
ArtifactRepository localRepository ) |
52 | |
throws ArtifactDeploymentException |
53 | |
{ |
54 | 0 | String extension = artifact.getArtifactHandler().getExtension(); |
55 | 0 | File source = new File( basedir, finalName + "." + extension ); |
56 | 0 | deploy( source, artifact, deploymentRepository, localRepository ); |
57 | 0 | } |
58 | |
|
59 | |
public void deploy( File source, Artifact artifact, ArtifactRepository deploymentRepository, |
60 | |
ArtifactRepository localRepository ) |
61 | |
throws ArtifactDeploymentException |
62 | |
{ |
63 | 1 | if ( !wagonManager.isOnline() ) |
64 | |
{ |
65 | |
|
66 | 0 | throw new ArtifactDeploymentException( "System is offline. Cannot deploy artifact: " + artifact + "." ); |
67 | |
} |
68 | |
|
69 | |
try |
70 | |
{ |
71 | 1 | transformationManager.transformForDeployment( artifact, deploymentRepository, localRepository ); |
72 | |
|
73 | |
|
74 | 1 | File artifactFile = new File( localRepository.getBasedir(), localRepository.pathOf( artifact ) ); |
75 | 1 | if ( !artifactFile.equals( source ) ) |
76 | |
{ |
77 | 1 | FileUtils.copyFile( source, artifactFile ); |
78 | |
} |
79 | |
|
80 | 1 | wagonManager.putArtifact( source, artifact, deploymentRepository ); |
81 | |
|
82 | |
|
83 | 1 | for ( Iterator i = artifact.getMetadataList().iterator(); i.hasNext(); ) |
84 | |
{ |
85 | 1 | ArtifactMetadata metadata = (ArtifactMetadata) i.next(); |
86 | 1 | repositoryMetadataManager.deploy( metadata, localRepository, deploymentRepository ); |
87 | 1 | } |
88 | |
|
89 | |
|
90 | |
|
91 | |
} |
92 | 0 | catch ( TransferFailedException e ) |
93 | |
{ |
94 | 0 | throw new ArtifactDeploymentException( "Error deploying artifact: " + e.getMessage(), e ); |
95 | |
} |
96 | 0 | catch ( IOException e ) |
97 | |
{ |
98 | 0 | throw new ArtifactDeploymentException( "Error deploying artifact: " + e.getMessage(), e ); |
99 | |
} |
100 | 0 | catch ( RepositoryMetadataDeploymentException e ) |
101 | |
{ |
102 | 0 | throw new ArtifactDeploymentException( "Error installing artifact's metadata: " + e.getMessage(), e ); |
103 | 1 | } |
104 | 1 | } |
105 | |
} |