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
35
36
37 @SuppressWarnings( "deprecation" )
38 @Component( role = MavenProjectHelper.class )
39 public class DefaultMavenProjectHelper
40 extends AbstractLogEnabled
41 implements MavenProjectHelper
42 {
43 @Requirement
44 private ArtifactHandlerManager artifactHandlerManager;
45
46 public void attachArtifact( MavenProject project, String artifactType, String artifactClassifier,
47 File artifactFile )
48 {
49 String type = artifactType;
50
51 ArtifactHandler handler = null;
52
53 if ( type != null )
54 {
55 handler = artifactHandlerManager.getArtifactHandler( artifactType );
56 }
57
58 if ( handler == null )
59 {
60 handler = artifactHandlerManager.getArtifactHandler( "jar" );
61 }
62
63 Artifact artifact = new AttachedArtifact( project.getArtifact(), artifactType, artifactClassifier, handler );
64
65 artifact.setFile( artifactFile );
66 artifact.setResolved( true );
67
68 attachArtifact( project, artifact );
69 }
70
71 public void attachArtifact( MavenProject project, String artifactType, File artifactFile )
72 {
73 ArtifactHandler handler = artifactHandlerManager.getArtifactHandler( artifactType );
74
75 Artifact artifact = new AttachedArtifact( project.getArtifact(), artifactType, handler );
76
77 artifact.setFile( artifactFile );
78 artifact.setResolved( true );
79
80 attachArtifact( project, artifact );
81 }
82
83 public void attachArtifact( MavenProject project, File artifactFile, String artifactClassifier )
84 {
85 Artifact projectArtifact = project.getArtifact();
86
87 Artifact artifact =
88 new AttachedArtifact( projectArtifact, projectArtifact.getType(), artifactClassifier,
89 projectArtifact.getArtifactHandler() );
90
91 artifact.setFile( artifactFile );
92 artifact.setResolved( true );
93
94 attachArtifact( project, artifact );
95 }
96
97
98
99
100
101
102
103
104 public void attachArtifact( MavenProject project, Artifact artifact )
105 {
106 project.addAttachedArtifact( artifact );
107 }
108
109 public void addResource( MavenProject project, String resourceDirectory, List<String> includes,
110 List<String> excludes )
111 {
112 Resource resource = new Resource();
113 resource.setDirectory( resourceDirectory );
114 resource.setIncludes( includes );
115 resource.setExcludes( excludes );
116
117 project.addResource( resource );
118 }
119
120 public void addTestResource( MavenProject project, String resourceDirectory, List<String> includes,
121 List<String> excludes )
122 {
123 Resource resource = new Resource();
124 resource.setDirectory( resourceDirectory );
125 resource.setIncludes( includes );
126 resource.setExcludes( excludes );
127
128 project.addTestResource( resource );
129 }
130
131 }