1   package org.apache.maven.plugins.jmod;
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  import java.io.File;
23  import java.io.IOException;
24  import java.io.PrintStream;
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.codehaus.plexus.util.cli.Commandline;
33  
34  
35  
36  
37  
38  
39  @Mojo( name = "describe", requiresDependencyResolution = ResolutionScope.NONE, defaultPhase = LifecyclePhase.NONE )
40  public class JModDescribeMojo
41      extends AbstractJModMojo
42  {
43  
44      @Parameter( defaultValue = "${project.build.directory}", required = true, readonly = true )
45      private File outputDirectory;
46  
47      
48  
49  
50      
51      @Parameter( 
52          defaultValue = "${project.build.directory}/jmods/${project.artifactId}.jmod", 
53          property = "jmodfile", 
54          required = true 
55      )
56      
57      private File jmodFile;
58  
59      public void execute()
60          throws MojoExecutionException, MojoFailureException
61      {
62  
63          String jModExecutable;
64          try
65          {
66              jModExecutable = getJModExecutable();
67          }
68          catch ( IOException e )
69          {
70              throw new MojoFailureException( "Unable to find jmod command: " + e.getMessage(), e );
71          }
72  
73          getLog().info( "Toolchain in maven-jmod-plugin: jmod [ " + jModExecutable + " ]" );
74  
75          if ( !jmodFile.exists() || !jmodFile.isFile() )
76          {
77              throw new MojoFailureException( "Unable to find " + jmodFile.getAbsolutePath() );
78          }
79  
80          Commandline cmd;
81          try
82          {
83              cmd = createJModDescribeCommandLine( jmodFile );
84          }
85          catch ( IOException e )
86          {
87              throw new MojoExecutionException( e.getMessage() );
88          }
89          cmd.setExecutable( jModExecutable );
90  
91          getLog().info( "The following information is contained in the module file " + jmodFile.getAbsolutePath() );
92          executeCommand( cmd, outputDirectory );
93  
94      }
95  
96      private Commandline createJModDescribeCommandLine( File resultingJModFile )
97          throws IOException
98      {
99          File file = new File( outputDirectory, "jmodDescribeArgs" );
100         if ( !getLog().isDebugEnabled() )
101         {
102             file.deleteOnExit();
103         }
104         file.getParentFile().mkdirs();
105         file.createNewFile();
106 
107         PrintStream argsFile = new PrintStream( file );
108 
109         argsFile.println( "describe" );
110 
111         argsFile.println( resultingJModFile.getAbsolutePath() );
112         argsFile.close();
113 
114         Commandline cmd = new Commandline();
115         cmd.createArg().setValue( '@' + file.getAbsolutePath() );
116 
117         return cmd;
118     }
119 
120 }