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