View Javadoc

1   package org.apache.maven.project;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.artifact.Artifact;
23  import org.apache.maven.artifact.handler.ArtifactHandler;
24  import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
25  import org.apache.maven.model.Resource;
26  import org.apache.maven.project.artifact.AttachedArtifact;
27  
28  import java.io.File;
29  import java.util.List;
30  
31  public class DefaultMavenProjectHelper
32      implements MavenProjectHelper
33  {
34      
35      private ArtifactHandlerManager artifactHandlerManager;
36  
37      public void attachArtifact( MavenProject project, String artifactType, String artifactClassifier, File artifactFile )
38      {
39          String type = artifactType;
40          
41          ArtifactHandler handler = null;
42          
43          if ( type != null )
44          {
45              handler = artifactHandlerManager.getArtifactHandler( artifactType );
46          }
47          
48          if ( handler == null )
49          {
50              handler = artifactHandlerManager.getArtifactHandler( "jar" );
51          }
52  
53          Artifact artifact = new AttachedArtifact( project.getArtifact(), artifactType, artifactClassifier, handler );
54          
55          artifact.setFile( artifactFile );
56          artifact.setResolved( true );
57          
58          project.addAttachedArtifact( artifact );
59      }
60  
61      public void attachArtifact( MavenProject project, String artifactType, File artifactFile )
62      {
63          ArtifactHandler handler = artifactHandlerManager.getArtifactHandler( artifactType );
64          
65          Artifact artifact = new AttachedArtifact( project.getArtifact(), artifactType, handler );
66          
67          artifact.setFile( artifactFile );
68          artifact.setResolved( true );
69          
70          project.addAttachedArtifact( artifact );
71      }
72  
73      public void attachArtifact( MavenProject project, File artifactFile, String artifactClassifier )
74      {
75          Artifact projectArtifact = project.getArtifact();
76          
77          Artifact artifact = new AttachedArtifact( projectArtifact, projectArtifact.getType(), artifactClassifier, projectArtifact.getArtifactHandler() );
78          
79          artifact.setFile( artifactFile );
80          artifact.setResolved( true );
81          
82          project.addAttachedArtifact( artifact );
83      }
84  
85      public void addResource( MavenProject project, String resourceDirectory, List includes, List excludes )
86      {
87          Resource resource = new Resource();
88          resource.setDirectory( resourceDirectory );
89          resource.setIncludes( includes );
90          resource.setExcludes( excludes );
91  
92          project.addResource( resource );
93      }
94  
95      public void addTestResource( MavenProject project, String resourceDirectory, List includes, List excludes )
96      {
97          Resource resource = new Resource();
98          resource.setDirectory( resourceDirectory );
99          resource.setIncludes( includes );
100         resource.setExcludes( excludes );
101 
102         project.addTestResource( resource );
103     }
104 
105 }