You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kh...@apache.org on 2017/09/02 23:05:55 UTC

svn commit: r1807104 - in /maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod: AbstractJModMojo.java JModCreateMojo.java JModDescribeMojo.java JModListMojo.java

Author: khmarbaise
Date: Sat Sep  2 23:05:54 2017
New Revision: 1807104

URL: http://svn.apache.org/viewvc?rev=1807104&view=rev
Log:
Added list and describe goal.

Added:
    maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod/JModDescribeMojo.java
Modified:
    maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod/AbstractJModMojo.java
    maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod/JModCreateMojo.java
    maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod/JModListMojo.java

Modified: maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod/AbstractJModMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod/AbstractJModMojo.java?rev=1807104&r1=1807103&r2=1807104&view=diff
==============================================================================
--- maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod/AbstractJModMojo.java (original)
+++ maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod/AbstractJModMojo.java Sat Sep  2 23:05:54 2017
@@ -39,9 +39,9 @@ import org.codehaus.plexus.util.cli.Comm
 import org.codehaus.plexus.util.cli.Commandline;
 
 /**
- * This contains the code to handle toolchains and execute command which is similar to code in
- * maven-jlink-plugin (maven-jdeps-plugin?).
- * Later we need to think to combine that code to reduce duplication.
+ * This contains the code to handle toolchains and execute command which is similar to code in maven-jlink-plugin
+ * (maven-jdeps-plugin?). Later we need to think to combine that code to reduce duplication.
+ * 
  * @author Karl Heinz Marbaise <a href="mailto:khmarbaise@apache.org">khmarbaise@apache.org</a>
  */
 public abstract class AbstractJModMojo
@@ -57,7 +57,7 @@ public abstract class AbstractJModMojo
     @Component
     private ToolchainManager toolchainManager;
 
-    //TODO: Check how to prevent code duplication in maven-jlink, maven-jmod and maven-jdeps plugin? 
+    // TODO: Check how to prevent code duplication in maven-jlink, maven-jmod and maven-jdeps plugin?
     protected String getJModExecutable()
         throws IOException
     {
@@ -182,7 +182,11 @@ public abstract class AbstractJModMojo
 
             if ( StringUtils.isNotEmpty( output ) )
             {
-                getLog().info( output );
+                String[] splitLines = StringUtils.split( output, "\n" );
+                for ( String outputLine : splitLines )
+                {
+                    getLog().info( outputLine );
+                }
             }
         }
         catch ( CommandLineException e )
@@ -193,7 +197,8 @@ public abstract class AbstractJModMojo
     }
 
     /**
-     * Convert a list into a 
+     * Convert a list into a
+     * 
      * @param modules The list of modules.
      * @return The string with the module list which is separated by {@code ,}.
      */

Modified: maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod/JModCreateMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod/JModCreateMojo.java?rev=1807104&r1=1807103&r2=1807104&view=diff
==============================================================================
--- maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod/JModCreateMojo.java (original)
+++ maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod/JModCreateMojo.java Sat Sep  2 23:05:54 2017
@@ -37,7 +37,7 @@ import org.codehaus.plexus.util.cli.Comm
 /**
  * The <code>create</code> goal is intended to create <code>jmod</code> files which can be used for later linking via
  * <code>maven-jlink-plugin</code>. The JMod files can not be used as usual dependencies on the classpath only in
- * relationship with maven-jlink-plugin. JMOD files can be used at compile time and link time, but not at run time.
+ * relationship with maven-jlink-plugin. 
  * 
  * @author Karl Heinz Marbaise <a href="mailto:khmarbaise@apache.org">khmarbaise@apache.org</a>
  */
@@ -381,7 +381,7 @@ public class JModCreateMojo
     private Commandline createJModCreateCommandLine( File resultingJModFile )
         throws IOException
     {
-        File file = new File( outputDirectory, "jmodArgs" );
+        File file = new File( outputDirectory, "jmodCreateArgs" );
         if ( !getLog().isDebugEnabled() )
         {
             file.deleteOnExit();

Added: maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod/JModDescribeMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod/JModDescribeMojo.java?rev=1807104&view=auto
==============================================================================
--- maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod/JModDescribeMojo.java (added)
+++ maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod/JModDescribeMojo.java Sat Sep  2 23:05:54 2017
@@ -0,0 +1,121 @@
+package org.apache.maven.plugins.jmod;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintStream;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.plugins.annotations.ResolutionScope;
+import org.codehaus.plexus.util.cli.Commandline;
+
+/**
+ * This goal is to support the usage of <code>jmod describe</code>.
+ * 
+ * @author Karl Heinz Marbaise <a href="mailto:khmarbaise@apache.org">khmarbaise@apache.org</a>
+ */
+@Mojo( name = "describe", requiresDependencyResolution = ResolutionScope.NONE, defaultPhase = LifecyclePhase.NONE )
+public class JModDescribeMojo
+    extends AbstractJModMojo
+{
+
+    /**
+     * Do not change this. (TODO!)
+     */
+    @Parameter( defaultValue = "${project.build.directory}", required = true, readonly = true )
+    private File outputDirectory;
+
+    /**
+     * The moduleName. The default is to use the <code>artifactId</code>.
+     */
+    @Parameter( defaultValue = "${project.artifactId}", required = true )
+    private String moduleName;
+
+    public void execute()
+        throws MojoExecutionException, MojoFailureException
+    {
+
+        String jModExecutable;
+        try
+        {
+            jModExecutable = getJModExecutable();
+        }
+        catch ( IOException e )
+        {
+            throw new MojoFailureException( "Unable to find jmod command: " + e.getMessage(), e );
+        }
+
+        getLog().info( "Toolchain in maven-jmod-plugin: jmod [ " + jModExecutable + " ]" );
+
+        // We need to put the resulting x.jmod files into jmods folder otherwise is
+        // seemed to be not working.
+        // Check why?
+        File modsFolder = new File( outputDirectory, "jmods" );
+        File resultingJModFile = new File( modsFolder, moduleName + ".jmod" );
+
+        // create the jmods folder...
+        modsFolder.mkdirs();
+
+        Commandline cmd;
+        try
+        {
+            cmd = createJModDescribeCommandLine( resultingJModFile );
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( e.getMessage() );
+        }
+        cmd.setExecutable( jModExecutable );
+
+        getLog().info( "The following information is contained in the module file " + resultingJModFile.getAbsolutePath() );
+        executeCommand( cmd, outputDirectory );
+
+    }
+
+    private Commandline createJModDescribeCommandLine( File resultingJModFile )
+        throws IOException
+    {
+        File file = new File( outputDirectory, "jmodDescribeArgs" );
+        if ( !getLog().isDebugEnabled() )
+        {
+            file.deleteOnExit();
+        }
+        file.getParentFile().mkdirs();
+        file.createNewFile();
+
+        PrintStream argsFile = new PrintStream( file );
+
+        argsFile.println( "describe" );
+
+        argsFile.println( resultingJModFile.getAbsolutePath() );
+        argsFile.close();
+
+        Commandline cmd = new Commandline();
+        cmd.createArg().setValue( '@' + file.getAbsolutePath() );
+
+        return cmd;
+    }
+
+}

Modified: maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod/JModListMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod/JModListMojo.java?rev=1807104&r1=1807103&r2=1807104&view=diff
==============================================================================
--- maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod/JModListMojo.java (original)
+++ maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod/JModListMojo.java Sat Sep  2 23:05:54 2017
@@ -19,30 +19,44 @@ package org.apache.maven.plugins.jmod;
  * under the License.
  */
 
+import java.io.File;
 import java.io.IOException;
+import java.io.PrintStream;
 
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugins.annotations.LifecyclePhase;
 import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.plugins.annotations.ResolutionScope;
+import org.codehaus.plexus.util.cli.Commandline;
 
 /**
- * <pre>
- * jmod list...
- * </pre>
+ * This goal is to support the usage of <code>jmod list</code>.
  * 
  * @author Karl Heinz Marbaise <a href="mailto:khmarbaise@apache.org">khmarbaise@apache.org</a>
  */
-@Mojo( name = "list", requiresDependencyResolution = ResolutionScope.COMPILE, defaultPhase = LifecyclePhase.PACKAGE )
+@Mojo( name = "list", requiresDependencyResolution = ResolutionScope.NONE, defaultPhase = LifecyclePhase.NONE )
 public class JModListMojo
     extends AbstractJModMojo
 {
+    
+    /**
+     * Do not change this. (TODO!)
+     */
+    @Parameter( defaultValue = "${project.build.directory}", required = true, readonly = true )
+    private File outputDirectory;
+
+    /**
+     * The moduleName. The default is to use the <code>artifactId</code>.
+     */
+    @Parameter( defaultValue = "${project.artifactId}", required = true )
+    private String moduleName;
+    
     public void execute()
         throws MojoExecutionException, MojoFailureException
     {
 
-        
         String jModExecutable;
         try
         {
@@ -53,13 +67,55 @@ public class JModListMojo
             throw new MojoFailureException( "Unable to find jmod command: " + e.getMessage(), e );
         }
 
-//        // Synopsis
-//        // Usage: jmod ...
-//        Commandline cmd = createJModCommandLine();
-//        cmd.setExecutable( jModExecutable );
-//
-//        executeCommand( cmd, outputDirectory );
-        
+        getLog().info( "Toolchain in maven-jmod-plugin: jmod [ " + jModExecutable + " ]" );
+
+        // We need to put the resulting x.jmod files into jmods folder otherwise is
+        // seemed to be not working.
+        // Check why?
+        File modsFolder = new File( outputDirectory, "jmods" );
+        File resultingJModFile = new File( modsFolder, moduleName + ".jmod" );
+
+        // create the jmods folder...
+        modsFolder.mkdirs();
+
+        Commandline cmd;
+        try
+        {
+            cmd = createJModListCommandLine( resultingJModFile );
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( e.getMessage() );
+        }
+        cmd.setExecutable( jModExecutable );
+
+        getLog().info( "The following files are contained in the module file " + resultingJModFile.getAbsolutePath() );
+        executeCommand( cmd, outputDirectory );
+
+    }
+
+    private Commandline createJModListCommandLine( File resultingJModFile )
+        throws IOException
+    {
+        File file = new File( outputDirectory, "jmodListArgs" );
+        if ( !getLog().isDebugEnabled() )
+        {
+            file.deleteOnExit();
+        }
+        file.getParentFile().mkdirs();
+        file.createNewFile();
+
+        PrintStream argsFile = new PrintStream( file );
+
+        argsFile.println( "list" );
+
+        argsFile.println( resultingJModFile.getAbsolutePath() );
+        argsFile.close();
+
+        Commandline cmd = new Commandline();
+        cmd.createArg().setValue( '@' + file.getAbsolutePath() );
+
+        return cmd;
     }
 
 }