1 package org.apache.maven.project;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.List;
24
25 import org.apache.maven.artifact.Artifact;
26 import org.apache.maven.artifact.handler.ArtifactHandler;
27 import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
28 import org.apache.maven.model.Resource;
29 import org.apache.maven.project.artifact.AttachedArtifact;
30 import org.codehaus.plexus.component.annotations.Component;
31 import org.codehaus.plexus.component.annotations.Requirement;
32 import org.codehaus.plexus.logging.AbstractLogEnabled;
33
34 @SuppressWarnings( "deprecation" )
35 @Component( role = MavenProjectHelper.class )
36 public class DefaultMavenProjectHelper
37 extends AbstractLogEnabled
38 implements MavenProjectHelper
39 {
40 @Requirement
41 private ArtifactHandlerManager artifactHandlerManager;
42
43 public void attachArtifact( MavenProject project, String artifactType, String artifactClassifier, File artifactFile )
44 {
45 String type = artifactType;
46
47 ArtifactHandler handler = null;
48
49 if ( type != null )
50 {
51 handler = artifactHandlerManager.getArtifactHandler( artifactType );
52 }
53
54 if ( handler == null )
55 {
56 handler = artifactHandlerManager.getArtifactHandler( "jar" );
57 }
58
59 Artifact artifact = new AttachedArtifact( project.getArtifact(), artifactType, artifactClassifier, handler );
60
61 artifact.setFile( artifactFile );
62 artifact.setResolved( true );
63
64 attachArtifact( project, artifact );
65 }
66
67 public void attachArtifact( MavenProject project, String artifactType, File artifactFile )
68 {
69 ArtifactHandler handler = artifactHandlerManager.getArtifactHandler( artifactType );
70
71 Artifact artifact = new AttachedArtifact( project.getArtifact(), artifactType, handler );
72
73 artifact.setFile( artifactFile );
74 artifact.setResolved( true );
75
76 attachArtifact( project, artifact );
77 }
78
79 public void attachArtifact( MavenProject project, File artifactFile, String artifactClassifier )
80 {
81 Artifact projectArtifact = project.getArtifact();
82
83 Artifact artifact =
84 new AttachedArtifact( projectArtifact, projectArtifact.getType(), artifactClassifier,
85 projectArtifact.getArtifactHandler() );
86
87 artifact.setFile( artifactFile );
88 artifact.setResolved( true );
89
90 attachArtifact( project, artifact );
91 }
92
93
94
95
96
97
98
99
100 public void attachArtifact( MavenProject project, Artifact artifact )
101 {
102 project.addAttachedArtifact( artifact );
103 }
104
105 public void addResource( MavenProject project, String resourceDirectory, List<String> includes,
106 List<String> excludes )
107 {
108 Resource resource = new Resource();
109 resource.setDirectory( resourceDirectory );
110 resource.setIncludes( includes );
111 resource.setExcludes( excludes );
112
113 project.addResource( resource );
114 }
115
116 public void addTestResource( MavenProject project, String resourceDirectory, List<String> includes,
117 List<String> excludes )
118 {
119 Resource resource = new Resource();
120 resource.setDirectory( resourceDirectory );
121 resource.setIncludes( includes );
122 resource.setExcludes( excludes );
123
124 project.addTestResource( resource );
125 }
126
127 }