1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package io.wcm.caravan.maven.plugins.haldocs;
21
22 import java.io.File;
23 import java.net.MalformedURLException;
24 import java.net.URL;
25
26 import org.apache.maven.artifact.DependencyResolutionRequiredException;
27 import org.apache.maven.model.Build;
28 import org.apache.maven.model.Resource;
29 import org.apache.maven.plugin.AbstractMojo;
30 import org.apache.maven.plugins.annotations.Parameter;
31 import org.apache.maven.project.MavenProject;
32
33
34
35
36 abstract class AbstractBaseMojo extends AbstractMojo {
37
38 @Parameter(property = "project", required = true, readonly = true)
39 protected MavenProject project;
40
41 private File generatedResourcesFolder;
42
43
44
45
46
47
48 protected URL[] getCompileClasspathElementURLs() throws DependencyResolutionRequiredException {
49
50 return project.getCompileClasspathElements().stream()
51 .map(path -> {
52 try {
53 return new File(path).toURI().toURL();
54 }
55 catch (MalformedURLException ex) {
56 throw new RuntimeException(ex);
57 }
58 })
59 .toArray(size -> new URL[size]);
60 }
61
62
63
64
65
66
67 protected void addResource(String sourceDirectory, String targetPath) {
68
69
70 Resource resource = new Resource();
71 resource.setDirectory(sourceDirectory);
72 resource.setTargetPath(targetPath);
73
74
75 Build build = this.project.getBuild();
76 build.addResource(resource);
77 getLog().debug("Added resource: " + resource.getDirectory() + " -> " + resource.getTargetPath());
78 }
79
80
81
82
83
84 protected File getGeneratedResourcesDirectory() {
85 if (generatedResourcesFolder == null) {
86 String generatedResourcesFolderAbsolutePath = this.project.getBuild().getDirectory() + "/" + getGeneratedResourcesDirectoryPath();
87 generatedResourcesFolder = new File(generatedResourcesFolderAbsolutePath);
88 if (!generatedResourcesFolder.exists()) {
89 generatedResourcesFolder.mkdirs();
90 }
91 }
92 return generatedResourcesFolder;
93 }
94
95
96
97
98 protected abstract String getGeneratedResourcesDirectoryPath();
99
100 }