1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package io.wcm.devops.conga.tooling.maven.plugin;
21
22 import java.io.File;
23 import java.io.FileOutputStream;
24 import java.io.IOException;
25 import java.io.OutputStream;
26 import java.nio.file.Files;
27 import java.util.Properties;
28
29 import org.apache.maven.plugin.AbstractMojo;
30 import org.apache.maven.plugin.MojoExecutionException;
31 import org.apache.maven.plugin.MojoFailureException;
32 import org.apache.maven.plugins.annotations.LifecyclePhase;
33 import org.apache.maven.plugins.annotations.Mojo;
34 import org.apache.maven.plugins.annotations.Parameter;
35 import org.apache.maven.project.MavenProject;
36
37 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
38 import io.wcm.devops.conga.generator.GeneratorOptions;
39 import io.wcm.devops.conga.generator.util.FileUtil;
40 import io.wcm.devops.conga.tooling.maven.plugin.util.VersionInfoUtil;
41
42
43
44
45
46 @Mojo(name = "generate-version-info", defaultPhase = LifecyclePhase.GENERATE_RESOURCES, requiresProject = true, threadSafe = true)
47 public class GenerateVersionInfoMojo extends AbstractMojo {
48
49
50
51
52 @Parameter(defaultValue = "${project.build.directory}/definitions")
53 private String definitionTarget;
54
55 @Parameter(property = "project", required = true, readonly = true)
56 private MavenProject project;
57
58 @Override
59 @SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE")
60 public void execute() throws MojoExecutionException, MojoFailureException {
61 File outputDir = new File(definitionTarget, GeneratorOptions.CLASSPATH_PREFIX);
62 if (!outputDir.exists()) {
63 outputDir.mkdirs();
64 }
65
66 File propsFile = new File(outputDir, BuildConstants.FILE_VERSION_INFO);
67 if (propsFile.exists()) {
68 try {
69 Files.delete(propsFile.toPath());
70 }
71 catch (IOException ex) {
72 throw new MojoExecutionException("Unable to delete file: " + FileUtil.getCanonicalPath(propsFile), ex);
73 }
74 }
75 Properties versionInfo = VersionInfoUtil.getVersionInfoProperties(project);
76 try (OutputStream os = new FileOutputStream(propsFile)) {
77 versionInfo.store(os, "CONGA Version Info");
78 }
79 catch (IOException ex) {
80 throw new MojoExecutionException("Error generating version info to "
81 + FileUtil.getCanonicalPath(propsFile) + ": " + ex.getMessage(), ex);
82 }
83 }
84
85 }