1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.jmod;
20
21 import javax.inject.Inject;
22
23 import java.io.File;
24 import java.io.IOException;
25
26 import org.apache.maven.plugin.MojoExecutionException;
27 import org.apache.maven.plugin.MojoFailureException;
28 import org.apache.maven.plugins.annotations.LifecyclePhase;
29 import org.apache.maven.plugins.annotations.Mojo;
30 import org.apache.maven.plugins.annotations.Parameter;
31 import org.apache.maven.plugins.annotations.ResolutionScope;
32 import org.apache.maven.shared.utils.cli.Commandline;
33 import org.apache.maven.toolchain.ToolchainManager;
34
35
36
37
38
39
40 @Mojo(name = "list", requiresDependencyResolution = ResolutionScope.NONE, defaultPhase = LifecyclePhase.NONE)
41 public class JModListMojo extends AbstractJModMojo {
42
43 @Parameter(defaultValue = "${project.build.directory}", required = true, readonly = true)
44 private File outputDirectory;
45
46
47
48
49
50 @Parameter(
51 defaultValue = "${project.build.directory}/jmods/${project.artifactId}.jmod",
52 property = "jmodfile",
53 required = true)
54
55 private File jmodFile;
56
57 @Inject
58 public JModListMojo(ToolchainManager toolchainManager) {
59 super(toolchainManager);
60 }
61
62 public void execute() throws MojoExecutionException, MojoFailureException {
63 try {
64 String jModExecutable = getJModExecutable();
65 getLog().debug("Toolchain in maven-jmod-plugin: jmod [ " + jModExecutable + " ]");
66
67 Commandline cmd = createJModListCommandLine();
68 cmd.setExecutable(jModExecutable);
69
70 getLog().info("The following files are contained in the module file " + jmodFile.getAbsolutePath());
71 executeCommand(cmd, outputDirectory);
72 } catch (IOException e) {
73 throw new MojoFailureException("Unable to find jmod command: " + e.getMessage(), e);
74 }
75 }
76
77 private Commandline createJModListCommandLine() throws MojoFailureException {
78 if (!jmodFile.exists() || !jmodFile.isFile()) {
79 throw new MojoFailureException("Unable to find " + jmodFile.getAbsolutePath());
80 }
81
82 Commandline commandLine = new Commandline();
83 commandLine.createArg().setValue("list");
84 commandLine.createArg().setValue(jmodFile.getAbsolutePath());
85 return commandLine;
86 }
87 }