KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > artifact > installer > DefaultArtifactInstaller


1 package org.apache.maven.artifact.installer;
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.metadata.ArtifactMetadata;
21 import org.apache.maven.artifact.repository.ArtifactRepository;
22 import org.apache.maven.artifact.repository.metadata.RepositoryMetadataInstallationException;
23 import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
24 import org.apache.maven.artifact.transform.ArtifactTransformationManager;
25 import org.codehaus.plexus.logging.AbstractLogEnabled;
26 import org.codehaus.plexus.util.FileUtils;
27
28 import java.io.File JavaDoc;
29 import java.io.IOException JavaDoc;
30 import java.util.Iterator JavaDoc;
31
32 public class DefaultArtifactInstaller
33     extends AbstractLogEnabled
34     implements ArtifactInstaller
35 {
36     private ArtifactTransformationManager transformationManager;
37
38     private RepositoryMetadataManager repositoryMetadataManager;
39
40     /**
41      * @deprecated we want to use the artifact method only, and ensure artifact.file is set correctly.
42      */

43     public void install( String JavaDoc basedir, String JavaDoc finalName, Artifact artifact, ArtifactRepository localRepository )
44         throws ArtifactInstallationException
45     {
46         String JavaDoc extension = artifact.getArtifactHandler().getExtension();
47         File JavaDoc source = new File JavaDoc( basedir, finalName + "." + extension );
48
49         install( source, artifact, localRepository );
50     }
51
52     public void install( File JavaDoc source, Artifact artifact, ArtifactRepository localRepository )
53         throws ArtifactInstallationException
54     {
55         try
56         {
57             transformationManager.transformForInstall( artifact, localRepository );
58
59             String JavaDoc localPath = localRepository.pathOf( artifact );
60
61             // TODO: use a file: wagon and the wagon manager?
62
File JavaDoc destination = new File JavaDoc( localRepository.getBasedir(), localPath );
63             if ( !destination.getParentFile().exists() )
64             {
65                 destination.getParentFile().mkdirs();
66             }
67
68             getLogger().info( "Installing " + source.getPath() + " to " + destination );
69
70             FileUtils.copyFile( source, destination );
71
72             // must be after the artifact is installed
73
for ( Iterator JavaDoc i = artifact.getMetadataList().iterator(); i.hasNext(); )
74             {
75                 ArtifactMetadata metadata = (ArtifactMetadata) i.next();
76                 repositoryMetadataManager.install( metadata, localRepository );
77             }
78             // TODO: would like to flush this, but the plugin metadata is added in advance, not as an install/deploy transformation
79
// This would avoid the need to merge and clear out the state during deployment
80
// artifact.getMetadataList().clear();
81
}
82         catch ( IOException JavaDoc e )
83         {
84             throw new ArtifactInstallationException( "Error installing artifact: " + e.getMessage(), e );
85         }
86         catch ( RepositoryMetadataInstallationException e )
87         {
88             throw new ArtifactInstallationException( "Error installing artifact's metadata: " + e.getMessage(), e );
89         }
90     }
91 }
Popular Tags