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 | 0 | 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 | 0 | String type = artifactType; |
40 | |
|
41 | 0 | ArtifactHandler handler = null; |
42 | |
|
43 | 0 | if ( type != null ) |
44 | |
{ |
45 | 0 | handler = artifactHandlerManager.getArtifactHandler( artifactType ); |
46 | |
} |
47 | |
|
48 | 0 | if ( handler == null ) |
49 | |
{ |
50 | 0 | handler = artifactHandlerManager.getArtifactHandler( "jar" ); |
51 | |
} |
52 | |
|
53 | 0 | Artifact artifact = new AttachedArtifact( project.getArtifact(), artifactType, artifactClassifier, handler ); |
54 | |
|
55 | 0 | artifact.setFile( artifactFile ); |
56 | 0 | artifact.setResolved( true ); |
57 | |
|
58 | 0 | project.addAttachedArtifact( artifact ); |
59 | 0 | } |
60 | |
|
61 | |
public void attachArtifact( MavenProject project, String artifactType, File artifactFile ) |
62 | |
{ |
63 | 0 | ArtifactHandler handler = artifactHandlerManager.getArtifactHandler( artifactType ); |
64 | |
|
65 | 0 | Artifact artifact = new AttachedArtifact( project.getArtifact(), artifactType, handler ); |
66 | |
|
67 | 0 | artifact.setFile( artifactFile ); |
68 | 0 | artifact.setResolved( true ); |
69 | |
|
70 | 0 | project.addAttachedArtifact( artifact ); |
71 | 0 | } |
72 | |
|
73 | |
public void attachArtifact( MavenProject project, File artifactFile, String artifactClassifier ) |
74 | |
{ |
75 | 0 | Artifact projectArtifact = project.getArtifact(); |
76 | |
|
77 | 0 | Artifact artifact = new AttachedArtifact( projectArtifact, projectArtifact.getType(), artifactClassifier, projectArtifact.getArtifactHandler() ); |
78 | |
|
79 | 0 | artifact.setFile( artifactFile ); |
80 | 0 | artifact.setResolved( true ); |
81 | |
|
82 | 0 | project.addAttachedArtifact( artifact ); |
83 | 0 | } |
84 | |
|
85 | |
public void addResource( MavenProject project, String resourceDirectory, List includes, List excludes ) |
86 | |
{ |
87 | 0 | Resource resource = new Resource(); |
88 | 0 | resource.setDirectory( resourceDirectory ); |
89 | 0 | resource.setIncludes( includes ); |
90 | 0 | resource.setExcludes( excludes ); |
91 | |
|
92 | 0 | project.addResource( resource ); |
93 | 0 | } |
94 | |
|
95 | |
public void addTestResource( MavenProject project, String resourceDirectory, List includes, List excludes ) |
96 | |
{ |
97 | 0 | Resource resource = new Resource(); |
98 | 0 | resource.setDirectory( resourceDirectory ); |
99 | 0 | resource.setIncludes( includes ); |
100 | 0 | resource.setExcludes( excludes ); |
101 | |
|
102 | 0 | project.addTestResource( resource ); |
103 | 0 | } |
104 | |
|
105 | |
} |