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 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 }