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 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 String extension = artifact.getArtifactHandler().getExtension();
55 File source = new File( basedir, finalName + "." + extension );
56 deploy( source, artifact, deploymentRepository, localRepository );
57 }
58
59 public void deploy( File source, Artifact artifact, ArtifactRepository deploymentRepository,
60 ArtifactRepository localRepository )
61 throws ArtifactDeploymentException
62 {
63 if ( !wagonManager.isOnline() )
64 {
65
66 throw new ArtifactDeploymentException( "System is offline. Cannot deploy artifact: " + artifact + "." );
67 }
68
69
70
71
72
73
74
75
76 boolean useArtifactFile = false;
77 File oldArtifactFile = artifact.getFile();
78 if ( "pom".equals( artifact.getType() ) )
79 {
80 artifact.setFile( source );
81 useArtifactFile = true;
82 }
83
84 try
85 {
86 transformationManager.transformForDeployment( artifact, deploymentRepository, localRepository );
87
88
89
90
91 if ( useArtifactFile )
92 {
93 source = artifact.getFile();
94 artifact.setFile( oldArtifactFile );
95 }
96
97
98
99
100
101 File artifactFile = new File( localRepository.getBasedir(), localRepository.pathOf( artifact ) );
102 if ( !artifactFile.equals( source ) )
103 {
104 FileUtils.copyFile( source, artifactFile );
105 }
106
107 wagonManager.putArtifact( source, artifact, deploymentRepository );
108
109
110 for ( Iterator i = artifact.getMetadataList().iterator(); i.hasNext(); )
111 {
112 ArtifactMetadata metadata = (ArtifactMetadata) i.next();
113 repositoryMetadataManager.deploy( metadata, localRepository, deploymentRepository );
114 }
115
116
117
118 }
119 catch ( TransferFailedException e )
120 {
121 throw new ArtifactDeploymentException( "Error deploying artifact: " + e.getMessage(), e );
122 }
123 catch ( IOException e )
124 {
125 throw new ArtifactDeploymentException( "Error deploying artifact: " + e.getMessage(), e );
126 }
127 catch ( RepositoryMetadataDeploymentException e )
128 {
129 throw new ArtifactDeploymentException( "Error installing artifact's metadata: " + e.getMessage(), e );
130 }
131 }
132 }