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