KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > artifact > deployer > DefaultArtifactDeployer


1 package org.apache.maven.artifact.deployer;
2
3 /*
4  * Copyright 2001-2005 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import org.apache.maven.artifact.Artifact;
20 import org.apache.maven.artifact.manager.WagonManager;
21 import org.apache.maven.artifact.metadata.ArtifactMetadata;
22 import org.apache.maven.artifact.repository.ArtifactRepository;
23 import org.apache.maven.artifact.repository.metadata.RepositoryMetadataDeploymentException;
24 import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
25 import org.apache.maven.artifact.transform.ArtifactTransformationManager;
26 import org.apache.maven.wagon.TransferFailedException;
27 import org.codehaus.plexus.logging.AbstractLogEnabled;
28 import org.codehaus.plexus.util.FileUtils;
29
30 import java.io.File JavaDoc;
31 import java.io.IOException JavaDoc;
32 import java.util.Iterator JavaDoc;
33
34 public class DefaultArtifactDeployer
35     extends AbstractLogEnabled
36     implements ArtifactDeployer
37 {
38     private WagonManager wagonManager;
39
40     private ArtifactTransformationManager transformationManager;
41
42     private RepositoryMetadataManager repositoryMetadataManager;
43
44     /**
45      * @deprecated we want to use the artifact method only, and ensure artifact.file is set correctly.
46      */

47     public void deploy( String JavaDoc basedir, String JavaDoc finalName, Artifact artifact, ArtifactRepository deploymentRepository,
48                         ArtifactRepository localRepository )
49         throws ArtifactDeploymentException
50     {
51         String JavaDoc extension = artifact.getArtifactHandler().getExtension();
52         File JavaDoc source = new File JavaDoc( basedir, finalName + "." + extension );
53         deploy( source, artifact, deploymentRepository, localRepository );
54     }
55
56     public void deploy( File JavaDoc source, Artifact artifact, ArtifactRepository deploymentRepository,
57                         ArtifactRepository localRepository )
58         throws ArtifactDeploymentException
59     {
60         if ( !wagonManager.isOnline() )
61         {
62             // deployment shouldn't silently fail when offline
63
throw new ArtifactDeploymentException( "System is offline. Cannot deploy artifact: " + artifact + "." );
64         }
65
66         try
67         {
68             transformationManager.transformForDeployment( artifact, deploymentRepository, localRepository );
69
70             // Copy the original file to the new one if it was transformed
71
File JavaDoc artifactFile = new File JavaDoc( localRepository.getBasedir(), localRepository.pathOf( artifact ) );
72             if ( !artifactFile.equals( source ) )
73             {
74                 FileUtils.copyFile( source, artifactFile );
75             }
76
77             wagonManager.putArtifact( source, artifact, deploymentRepository );
78
79             // must be after the artifact is installed
80
for ( Iterator JavaDoc i = artifact.getMetadataList().iterator(); i.hasNext(); )
81             {
82                 ArtifactMetadata metadata = (ArtifactMetadata) i.next();
83                 repositoryMetadataManager.deploy( metadata, localRepository, deploymentRepository );
84             }
85             // TODO: would like to flush this, but the plugin metadata is added in advance, not as an install/deploy transformation
86
// This would avoid the need to merge and clear out the state during deployment
87
// artifact.getMetadataList().clear();
88
}
89         catch ( TransferFailedException e )
90         {
91             throw new ArtifactDeploymentException( "Error deploying artifact: " + e.getMessage(), e );
92         }
93         catch ( IOException JavaDoc e )
94         {
95             throw new ArtifactDeploymentException( "Error deploying artifact: " + e.getMessage(), e );
96         }
97         catch ( RepositoryMetadataDeploymentException e )
98         {
99             throw new ArtifactDeploymentException( "Error installing artifact's metadata: " + e.getMessage(), e );
100         }
101     }
102 }
103
Popular Tags