KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > project > DefaultMavenProjectHelper


1 package org.apache.maven.project;
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.handler.ArtifactHandler;
21 import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
22 import org.apache.maven.model.Resource;
23 import org.apache.maven.project.artifact.AttachedArtifact;
24
25 import java.io.File JavaDoc;
26 import java.util.List JavaDoc;
27
28 public class DefaultMavenProjectHelper
29     implements MavenProjectHelper
30 {
31     
32     private ArtifactHandlerManager artifactHandlerManager;
33
34     public void attachArtifact( MavenProject project, String JavaDoc artifactType, String JavaDoc artifactClassifier, File JavaDoc artifactFile )
35     {
36         String JavaDoc type = artifactType;
37         
38         ArtifactHandler handler = null;
39         
40         if ( type != null )
41         {
42             handler = artifactHandlerManager.getArtifactHandler( artifactType );
43         }
44         
45         if ( handler == null )
46         {
47             handler = artifactHandlerManager.getArtifactHandler( "jar" );
48         }
49         
50         Artifact artifact = new AttachedArtifact( project.getArtifact(), artifactType, artifactClassifier, handler );
51         
52         artifact.setFile( artifactFile );
53         artifact.setResolved( true );
54         
55         project.addAttachedArtifact( artifact );
56     }
57
58     public void attachArtifact( MavenProject project, String JavaDoc artifactType, File JavaDoc artifactFile )
59     {
60         ArtifactHandler handler = artifactHandlerManager.getArtifactHandler( artifactType );
61         
62         Artifact artifact = new AttachedArtifact( project.getArtifact(), artifactType, handler );
63         
64         artifact.setFile( artifactFile );
65         artifact.setResolved( true );
66         
67         project.addAttachedArtifact( artifact );
68     }
69
70     public void attachArtifact( MavenProject project, File JavaDoc artifactFile, String JavaDoc artifactClassifier )
71     {
72         Artifact projectArtifact = project.getArtifact();
73         
74         Artifact artifact = new AttachedArtifact( projectArtifact, projectArtifact.getType(), artifactClassifier, projectArtifact.getArtifactHandler() );
75         
76         artifact.setFile( artifactFile );
77         artifact.setResolved( true );
78         
79         project.addAttachedArtifact( artifact );
80     }
81
82     public void addResource( MavenProject project, String JavaDoc resourceDirectory, List JavaDoc includes, List JavaDoc excludes )
83     {
84         Resource resource = new Resource();
85         resource.setDirectory( resourceDirectory );
86         resource.setIncludes( includes );
87         resource.setExcludes( excludes );
88
89         project.addResource( resource );
90     }
91
92     public void addTestResource( MavenProject project, String JavaDoc resourceDirectory, List JavaDoc includes, List JavaDoc excludes )
93     {
94         Resource resource = new Resource();
95         resource.setDirectory( resourceDirectory );
96         resource.setIncludes( includes );
97         resource.setExcludes( excludes );
98
99         project.addTestResource( resource );
100     }
101
102 }
103
Popular Tags