1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.resources;
20
21 import java.nio.file.Path;
22 import java.util.List;
23 import java.util.stream.Collectors;
24
25 import org.apache.maven.api.ProjectScope;
26 import org.apache.maven.api.plugin.MojoException;
27 import org.apache.maven.api.plugin.annotations.Mojo;
28 import org.apache.maven.api.plugin.annotations.Parameter;
29 import org.apache.maven.api.services.ProjectManager;
30 import org.apache.maven.shared.filtering.Resource;
31
32
33
34
35
36
37
38
39 @Mojo(name = "testResources", defaultPhase = "process-test-resources", projectRequired = true)
40 public class TestResourcesMojo extends ResourcesMojo {
41
42
43
44 @Parameter(defaultValue = "${project.build.testOutputDirectory}", required = true)
45 private Path outputDirectory;
46
47
48
49
50 @Parameter
51 private List<Resource> resources;
52
53
54
55
56
57
58 @Parameter(property = "maven.test.skip", defaultValue = "false")
59 private boolean skip;
60
61
62
63
64 public void execute() throws MojoException {
65 if (skip) {
66 getLog().info("Not copying test resources");
67 return;
68 }
69
70 if (resources == null) {
71 resources = session.getService(ProjectManager.class).getResources(project, ProjectScope.TEST).stream()
72 .map(ResourceUtils::newResource)
73 .collect(Collectors.toList());
74 }
75
76 super.doExecute();
77 }
78
79
80 public Path getOutputDirectory() {
81 return outputDirectory;
82 }
83
84
85 public void setOutputDirectory(Path outputDirectory) {
86 this.outputDirectory = outputDirectory;
87 }
88
89
90 public List<Resource> getResources() {
91 return resources;
92 }
93
94
95 public void setResources(List<Resource> resources) {
96 this.resources = resources;
97 }
98 }