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,
44 File artifactFile )
45 {
46 String type = artifactType;
47
48 ArtifactHandler handler = null;
49
50 if ( type != null )
51 {
52 handler = artifactHandlerManager.getArtifactHandler( artifactType );
53 }
54
55 if ( handler == null )
56 {
57 handler = artifactHandlerManager.getArtifactHandler( "jar" );
58 }
59
60 Artifact artifact = new AttachedArtifact( project.getArtifact(), artifactType, artifactClassifier, handler );
61
62 artifact.setFile( artifactFile );
63 artifact.setResolved( true );
64
65 attachArtifact( project, artifact );
66 }
67
68 public void attachArtifact( MavenProject project, String artifactType, File artifactFile )
69 {
70 ArtifactHandler handler = artifactHandlerManager.getArtifactHandler( artifactType );
71
72 Artifact artifact = new AttachedArtifact( project.getArtifact(), artifactType, handler );
73
74 artifact.setFile( artifactFile );
75 artifact.setResolved( true );
76
77 attachArtifact( project, artifact );
78 }
79
80 public void attachArtifact( MavenProject project, File artifactFile, String artifactClassifier )
81 {
82 Artifact projectArtifact = project.getArtifact();
83
84 Artifact artifact = 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 public void attachArtifact( MavenProject project, Artifact artifact )
94 {
95 try
96 {
97 project.addAttachedArtifact( artifact );
98 }
99 catch ( DuplicateArtifactAttachmentException dae )
100 {
101 getLogger().warn( dae.getMessage() );
102
103
104
105 throw dae;
106 }
107 }
108
109 public void addResource( MavenProject project, String resourceDirectory, List includes, List excludes )
110 {
111 Resource resource = new Resource();
112 resource.setDirectory( resourceDirectory );
113 resource.setIncludes( includes );
114 resource.setExcludes( excludes );
115
116 project.addResource( resource );
117 }
118
119 public void addTestResource( MavenProject project, String resourceDirectory, List includes, List excludes )
120 {
121 Resource resource = new Resource();
122 resource.setDirectory( resourceDirectory );
123 resource.setIncludes( includes );
124 resource.setExcludes( excludes );
125
126 project.addTestResource( resource );
127 }
128
129 }