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 2016/10/09 12:02:05 UTC
svn commit: r1763963 - in /maven/plugins/trunk/maven-jmod-plugin: ./ src/
src/main/ src/main/filtered-resources/ src/main/filtered-resources/META-INF/
src/main/filtered-resources/META-INF/plexus/ src/main/java/
src/main/java/org/ src/main/java/org/apac...
Author: khmarbaise
Date: Sun Oct 9 12:02:05 2016
New Revision: 1763963
URL: http://svn.apache.org/viewvc?rev=1763963&view=rev
Log:
First prototype of maven-jmod-plugin.
Added:
maven/plugins/trunk/maven-jmod-plugin/ (with props)
maven/plugins/trunk/maven-jmod-plugin/pom.xml
maven/plugins/trunk/maven-jmod-plugin/src/
maven/plugins/trunk/maven-jmod-plugin/src/main/
maven/plugins/trunk/maven-jmod-plugin/src/main/filtered-resources/
maven/plugins/trunk/maven-jmod-plugin/src/main/filtered-resources/META-INF/
maven/plugins/trunk/maven-jmod-plugin/src/main/filtered-resources/META-INF/plexus/
maven/plugins/trunk/maven-jmod-plugin/src/main/filtered-resources/META-INF/plexus/components.xml
maven/plugins/trunk/maven-jmod-plugin/src/main/java/
maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/
maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/
maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/
maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/
maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod/
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/JModHashMojo.java
maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod/JModListMojo.java
Propchange: maven/plugins/trunk/maven-jmod-plugin/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sun Oct 9 12:02:05 2016
@@ -0,0 +1,13 @@
+cobertura.ser
+*~
+*.log
+.classpath
+.project
+*.ipr
+*.iws
+*.iml
+.idea
+target
+.wtpmodules
+.settings
+bin
Added: maven/plugins/trunk/maven-jmod-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jmod-plugin/pom.xml?rev=1763963&view=auto
==============================================================================
--- maven/plugins/trunk/maven-jmod-plugin/pom.xml (added)
+++ maven/plugins/trunk/maven-jmod-plugin/pom.xml Sun Oct 9 12:02:05 2016
@@ -0,0 +1,100 @@
+<?xml version='1.0' encoding='UTF-8'?>
+
+<!--
+ 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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-plugins</artifactId>
+ <version>30</version>
+ <relativePath>../maven-plugins/pom.xml</relativePath>
+ </parent>
+
+ <artifactId>maven-jmod-plugin</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ <packaging>maven-plugin</packaging>
+
+ <name>Apache Maven JMod Plugin</name>
+ <description>http://openjdk.java.net/jeps/261</description>
+ <inceptionYear>2016</inceptionYear>
+
+ <prerequisites>
+ <maven>${mavenVersion}</maven>
+ </prerequisites>
+
+ <scm>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/maven/plugins/trunk/maven-jmod-plugin/</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/maven/plugins/trunk/maven-jmod-plugin/
+ </developerConnection>
+ <url>http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jmod-plugin/</url>
+ </scm>
+ <issueManagement>
+ <system>jira</system>
+ <url>https://issues.apache.org/jira/browse/MJMOD</url>
+ </issueManagement>
+ <distributionManagement>
+ <site>
+ <id>apache.website</id>
+ <url>scm:svn:https://svn.apache.org/repos/infra/websites/production/maven/components/${maven.site.path}</url>
+ </site>
+ </distributionManagement>
+
+ <properties>
+ <mavenVersion>3.0</mavenVersion>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-annotations</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <!-- Maven -->
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>${mavenVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>${mavenVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.4</version>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>src/main/filtered-resources</directory>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
+ </build>
+
+</project>
Added: maven/plugins/trunk/maven-jmod-plugin/src/main/filtered-resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jmod-plugin/src/main/filtered-resources/META-INF/plexus/components.xml?rev=1763963&view=auto
==============================================================================
--- maven/plugins/trunk/maven-jmod-plugin/src/main/filtered-resources/META-INF/plexus/components.xml (added)
+++ maven/plugins/trunk/maven-jmod-plugin/src/main/filtered-resources/META-INF/plexus/components.xml Sun Oct 9 12:02:05 2016
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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.
+-->
+
+<component-set>
+ <components>
+ <!--
+ | JMODS
+ |-->
+ <component>
+ <role>org.apache.maven.artifact.handler.ArtifactHandler</role>
+ <role-hint>jmod</role-hint>
+ <implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
+ <configuration>
+ <type>jmod</type>
+ <includesDependencies>true</includesDependencies>
+ <language>java</language>
+ <addedToClasspath>false</addedToClasspath>
+ </configuration>
+ </component>
+
+ <!--
+ | Defining the phases with their appropriate plugins
+ ! and versions which will be executed during the 'default'
+ ! life cycle.
+ -->
+ <!--
+ | JLINK
+ |-->
+ <component>
+ <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
+ <role-hint>jmod</role-hint>
+ <implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
+ <configuration>
+ <lifecycles>
+ <lifecycle>
+ <id>default</id>
+ <!-- START SNIPPET: jmod-lifecycle -->
+ <phases>
+ <process-resources>
+ org.apache.maven.plugins:maven-resources-plugin:3.0.1:resources
+ </process-resources>
+ <compile>
+ org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile
+ </compile>
+ <process-test-resources>
+ org.apache.maven.plugins:maven-resources-plugin:3.0.1:testResources
+ </process-test-resources>
+ <test-compile>
+ org.apache.maven.plugins:maven-compiler-plugin:3.5.1:testCompile
+ </test-compile>
+ <test>
+ org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test
+ </test>
+ <package>
+ org.apache.maven.plugins:maven-jmod-plugin:${project.version}:create
+ </package>
+ <install>
+ org.apache.maven.plugins:maven-install-plugin:2.5.2:install
+ </install>
+ <deploy>
+ org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy
+ </deploy>
+ </phases>
+ <!-- END SNIPPET: jmods-lifecycle -->
+ </lifecycle>
+ </lifecycles>
+ </configuration>
+ </component>
+
+ </components>
+</component-set>
Added: 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=1763963&view=auto
==============================================================================
--- maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod/AbstractJModMojo.java (added)
+++ maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod/AbstractJModMojo.java Sun Oct 9 12:02:05 2016
@@ -0,0 +1,219 @@
+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.util.Properties;
+
+import org.apache.commons.lang.SystemUtils;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.toolchain.Toolchain;
+import org.apache.maven.toolchain.ToolchainManager;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.cli.CommandLineException;
+import org.codehaus.plexus.util.cli.CommandLineUtils;
+import org.codehaus.plexus.util.cli.Commandline;
+
+/**
+ *
+ * @author Karl Heinz Marbaise <a href="mailto:khmarbaise@apache.org">khmarbaise@apache.org</a>
+ *
+ */
+public abstract class AbstractJModMojo
+ extends AbstractMojo
+{
+
+ @Parameter( defaultValue = "${project}", readonly = true, required = true )
+ private MavenProject project;
+
+ @Parameter( defaultValue = "${session}", readonly = true, required = true )
+ private MavenSession session;
+
+ @Component
+ private ToolchainManager toolchainManager;
+
+ protected String getJModExecutable() throws IOException
+ {
+ Toolchain tc = getToolchain();
+
+ String jLinkExecutable = null;
+ if ( tc != null )
+ {
+ jLinkExecutable = tc.findTool( "jmod" );
+ }
+
+ String jLinkCommand = "jmod" + ( SystemUtils.IS_OS_WINDOWS ? ".exe" : "" );
+
+ File jLinkExe;
+
+ if ( StringUtils.isNotEmpty( jLinkExecutable ) )
+ {
+ jLinkExe = new File( jLinkExecutable );
+
+ if ( jLinkExe.isDirectory() )
+ {
+ jLinkExe = new File( jLinkExe, jLinkCommand );
+ }
+
+ if ( SystemUtils.IS_OS_WINDOWS && jLinkExe.getName().indexOf( '.' ) < 0 )
+ {
+ jLinkExe = new File( jLinkExe.getPath() + ".exe" );
+ }
+
+ if ( !jLinkExe.isFile() )
+ {
+ throw new IOException( "The jlink executable '" + jLinkExe
+ + "' doesn't exist or is not a file." );
+ }
+ return jLinkExe.getAbsolutePath();
+ }
+
+ // ----------------------------------------------------------------------
+ // Try to find jlink from System.getProperty( "java.home" )
+ // By default, System.getProperty( "java.home" ) = JRE_HOME and JRE_HOME
+ // should be in the JDK_HOME
+ // ----------------------------------------------------------------------
+ // For IBM's JDK 1.2
+ // Really ?
+ if ( SystemUtils.IS_OS_AIX )
+ {
+ jLinkExe =
+ new File( SystemUtils.getJavaHome() + File.separator + ".." + File.separator + "sh", jLinkCommand );
+ }
+ // For Apple's JDK 1.6.x (and older?) on Mac OSX
+ // CHECKSTYLE_OFF: MagicNumber
+ else if ( SystemUtils.IS_OS_MAC_OSX && SystemUtils.JAVA_VERSION_FLOAT < 1.7f )
+ // CHECKSTYLE_ON: MagicNumber
+ {
+ jLinkExe = new File( SystemUtils.getJavaHome() + File.separator + "bin", jLinkCommand );
+ }
+ else
+ {
+ jLinkExe =
+ new File( SystemUtils.getJavaHome() + File.separator + ".." + File.separator + "bin", jLinkCommand );
+ }
+
+ // ----------------------------------------------------------------------
+ // Try to find jlink from JAVA_HOME environment variable
+ // ----------------------------------------------------------------------
+ if ( !jLinkExe.exists() || !jLinkExe.isFile() )
+ {
+ Properties env = CommandLineUtils.getSystemEnvVars();
+ String javaHome = env.getProperty( "JAVA_HOME" );
+ if ( StringUtils.isEmpty( javaHome ) )
+ {
+ throw new IOException( "The environment variable JAVA_HOME is not correctly set." );
+ }
+ if ( ( !new File( javaHome ).getCanonicalFile().exists() )
+ || ( new File( javaHome ).getCanonicalFile().isFile() ) )
+ {
+ throw new IOException( "The environment variable JAVA_HOME=" + javaHome
+ + " doesn't exist or is not a valid directory." );
+ }
+
+ jLinkExe = new File( javaHome + File.separator + "bin", jLinkCommand );
+ }
+
+ if ( !jLinkExe.getCanonicalFile().exists() || !jLinkExe.getCanonicalFile().isFile() )
+ {
+ throw new IOException( "The jlink executable '" + jLinkExe
+ + "' doesn't exist or is not a file. Verify the JAVA_HOME environment variable." );
+ }
+
+ return jLinkExe.getAbsolutePath();
+ }
+
+ protected void executeCommand ( Commandline cmd, File outputDirectory ) throws MojoExecutionException
+ {
+ if ( getLog().isDebugEnabled() )
+ {
+ // no quoted arguments ???
+ getLog().debug( CommandLineUtils.toString( cmd.getCommandline() ).replaceAll( "'", "" ) );
+ }
+
+ CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
+ CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();
+ try
+ {
+ int exitCode = CommandLineUtils.executeCommandLine( cmd, out, err );
+
+ String output = ( StringUtils.isEmpty( out.getOutput() ) ? null : '\n' + out.getOutput().trim() );
+
+ if ( exitCode != 0 )
+ {
+ if ( StringUtils.isNotEmpty( output ) )
+ {
+ //Reconsider to use WARN / ERROR ?
+ getLog().info( output );
+ }
+
+ StringBuilder msg = new StringBuilder( "\nExit code: " );
+ msg.append( exitCode );
+ if ( StringUtils.isNotEmpty( err.getOutput() ) )
+ {
+ msg.append( " - " ).append( err.getOutput() );
+ }
+ msg.append( '\n' );
+ msg.append( "Command line was: " ).append( cmd ).append( '\n' ).append( '\n' );
+
+ throw new MojoExecutionException( msg.toString() );
+ }
+
+ if ( StringUtils.isNotEmpty( output ) )
+ {
+ getLog().info( output );
+ }
+ }
+ catch ( CommandLineException e )
+ {
+ throw new MojoExecutionException( "Unable to execute jmod command: " + e.getMessage(), e );
+ }
+
+ }
+
+ private Toolchain getToolchain()
+ {
+ Toolchain tc = null;
+ if ( toolchainManager != null )
+ {
+ tc = toolchainManager.getToolchainFromBuildContext( "jdk", session );
+ }
+
+ return tc;
+ }
+
+ public MavenProject getProject()
+ {
+ return project;
+ }
+
+ public MavenSession getSession()
+ {
+ return session;
+ }
+
+
+}
Added: 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=1763963&view=auto
==============================================================================
--- maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod/JModCreateMojo.java (added)
+++ maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod/JModCreateMojo.java Sun Oct 9 12:02:05 2016
@@ -0,0 +1,261 @@
+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.util.List;
+
+import org.apache.commons.lang.SystemUtils;
+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.FileUtils;
+import org.codehaus.plexus.util.cli.Commandline;
+
+/**
+ * <pre>
+ * jmod create ...
+ * </pre>
+ *
+ * @author Karl Heinz Marbaise <a href="mailto:khmarbaise@apache.org">khmarbaise@apache.org</a>
+ */
+// TODO: Reconsider resolution scope, phase ?
+// CHECKSTYLE_OFF: LineLength
+@Mojo( name = "create", requiresDependencyResolution = ResolutionScope.COMPILE, defaultPhase = LifecyclePhase.PREPARE_PACKAGE, requiresProject = true )
+// CHECKSTYLE_ON: LineLength
+public class JModCreateMojo
+ extends AbstractJModMojo
+{
+
+ /**
+ * <code>--class-path <path></code> Application jar files|dir containing classes.
+ */
+ @Parameter( defaultValue = "${project.build.outputDirectory}" )
+ private List<String> classPath;
+
+ /**
+ * <code>--class-path <path></code> Application jar files|dir containing classes.
+ */
+ @Parameter
+ private List<String> cmds;
+
+ /**
+ * <code>--config <path></code> Location of user-editable config files.
+ */
+ @Parameter
+ private File config;
+
+ @Parameter
+ private List<String> excludes;
+
+ @Parameter
+ private String mainClass;
+
+ @Parameter
+ private List<File> libs;
+
+ @Parameter( defaultValue = "${project.version}" )
+ private String moduleVersion;
+
+ /**
+ * <code>--os-arch <os-arch></code> Operating system architecture.
+ */
+ @Parameter
+ private String osArch;
+
+ /**
+ * <code>--os-name <os-name></code> Operating system name.
+ */
+ @Parameter
+ private String osName;
+
+ /**
+ * <code>--os-version <os-version></code> Operating system version.
+ */
+ @Parameter
+ private String osVersion;
+
+ /**
+ * Define the modulepath for the <code>jmod</code> call. <code>--module-path <path></code>
+ */
+ // TODO: check if this target/classes folder?
+ @Parameter( defaultValue = "${project.build.outputDirectory}", required = true )
+ private File modulePath;
+
+ @Parameter( defaultValue = "${project.artifactId}", required = true )
+ private String moduleName;
+
+ @Parameter( defaultValue = "${project.build.directory}" )
+ private File outputDirectory;
+
+ public void execute()
+ throws MojoExecutionException, MojoFailureException
+ {
+
+ failIfParametersAreNotInTheirValidValueRanges();
+
+ 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.
+ // Check why?
+ File modsFolder = new File( outputDirectory, "jmods" );
+ File resultingJModFile = new File( modsFolder, moduleName + ".jmod" );
+
+ deleteOutputIfAlreadyExists( resultingJModFile );
+
+ // create the jmods folder...
+ modsFolder.mkdirs();
+
+ Commandline cmd = createJModCreateCommandLine( resultingJModFile );
+ cmd.setExecutable( jModExecutable );
+
+ executeCommand( cmd, outputDirectory );
+
+ }
+
+ private void deleteOutputIfAlreadyExists( File resultingJModFile )
+ throws MojoFailureException
+ {
+ if ( resultingJModFile.exists() && resultingJModFile.isFile() )
+ {
+ try
+ {
+ getLog().debug( "Deleting the existing " + resultingJModFile.getAbsolutePath() + " file." );
+ FileUtils.forceDelete( resultingJModFile );
+ }
+ catch ( IOException e )
+ {
+ String message = "Failure during deleting of file " + resultingJModFile.getAbsolutePath();
+ getLog().error( message );
+ throw new MojoFailureException( message );
+ }
+ }
+ }
+
+ private void failIfParametersAreNotInTheirValidValueRanges()
+ throws MojoFailureException
+ {
+ if ( modulePath != null && !modulePath.isDirectory() )
+ {
+ String message = "The given module-path parameter " + modulePath.getAbsolutePath() + " is not a directory.";
+ getLog().error( message );
+ throw new MojoFailureException( message );
+ }
+
+ if ( moduleName != null && moduleName.trim().isEmpty() )
+ {
+ String message = "A moduleName must be given.";
+ getLog().error( message );
+ throw new MojoFailureException( message );
+ }
+ }
+
+ private Commandline createJModCreateCommandLine( File resultingJModFile )
+ {
+ Commandline cmd = new Commandline();
+
+ cmd.createArg().setValue( "create" );
+
+ if ( moduleVersion != null )
+ {
+ cmd.createArg().setValue( "--module-version" );
+ cmd.createArg().setValue( moduleVersion );
+ }
+
+ cmd.createArg().setValue( "--os-arch" );
+ if ( osArch != null )
+ {
+ cmd.createArg().setValue( osArch );
+ }
+ else
+ {
+ cmd.createArg().setValue( SystemUtils.OS_ARCH );
+ }
+
+ cmd.createArg().setValue( "--os-name" );
+ if ( osName != null )
+ {
+ cmd.createArg().setValue( osName );
+ }
+ else
+ {
+ cmd.createArg().setValue( SystemUtils.OS_NAME );
+ }
+
+ cmd.createArg().setValue( "--os-version" );
+ if ( osVersion != null )
+ {
+ cmd.createArg().setValue( osVersion );
+ }
+ else
+ {
+ cmd.createArg().setValue( SystemUtils.OS_VERSION );
+ }
+
+ if ( classPath != null )
+ {
+ cmd.createArg().setValue( "--class-path" );
+ StringBuilder sb = getColonSeparateList( classPath );
+ cmd.createArg().setValue( sb.toString() );
+ }
+
+ // Can not be overwritten...
+ // TODO: Good idea?
+ cmd.createArg().setFile( resultingJModFile );
+ return cmd;
+ }
+
+ private StringBuilder getColonSeparateList( List<String> paths )
+ {
+ StringBuilder sb = new StringBuilder();
+ for ( String module : paths )
+ {
+ if ( sb.length() > 0 )
+ {
+ // FIXME: Check this ?
+ if ( SystemUtils.IS_OS_WINDOWS )
+ {
+ sb.append( ';' );
+ }
+ else
+ {
+ sb.append( ':' );
+ }
+ }
+ sb.append( module );
+ }
+ return sb;
+ }
+
+}
Added: maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod/JModHashMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod/JModHashMojo.java?rev=1763963&view=auto
==============================================================================
--- maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod/JModHashMojo.java (added)
+++ maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod/JModHashMojo.java Sun Oct 9 12:02:05 2016
@@ -0,0 +1,160 @@
+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;
+
+/*
+ * 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.IOException;
+import java.util.List;
+
+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 create ...
+ * </pre>
+ *
+ * @author Karl Heinz Marbaise <a href="mailto:khmarbaise@apache.org">khmarbaise@apache.org</a>
+ */
+// TODO: Reconsider resolution scope, phase ?
+@Mojo( name = "hash", requiresDependencyResolution = ResolutionScope.COMPILE, defaultPhase = LifecyclePhase.PACKAGE )
+public class JModHashMojo
+ extends AbstractJModMojo
+{
+
+ /**
+ * <code>--class-path <path></code> Application jar files|dir containing classes.
+ */
+ @Parameter
+ private List<String> classPath;
+
+ /**
+ * <code>--class-path <path></code> Application jar files|dir containing classes.
+ */
+ @Parameter
+ private List<String> cmds;
+
+ /**
+ * <code>--config <path></code> Location of user-editable config files.
+ */
+ @Parameter
+ private File config;
+
+ @Parameter
+ private boolean dryRun;
+
+ @Parameter
+ private List<String> excludes;
+
+ @Parameter
+ private String mainClass;
+
+ @Parameter
+ private List<File> libs;
+
+ @Parameter
+ private String moduleVersion;
+
+ /**
+ * <code>--os-arch <os-arch></code> Operating system architecture.
+ */
+ @Parameter
+ private String osArch;
+
+ /**
+ * <code>--os-name <os-name></code> Operating system name.
+ */
+ @Parameter
+ private String osName;
+
+ /**
+ * <code>--os-version <os-version></code> Operating system version.
+ */
+ @Parameter
+ private String osVersion;
+
+ /**
+ * Define the modulepath for the <code>jmod</code> call. <code>--module-path <path></code>
+ * Must be a directory.
+ */
+ @Parameter( required = true )
+ private File modulePath;
+
+ 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 );
+ }
+
+ Commandline cmd = createJModHashCommandLine();
+ cmd.setExecutable( jModExecutable );
+
+ // executeCommand( cmd, outputDirectory );
+
+ }
+
+ private Commandline createJModHashCommandLine()
+ {
+ Commandline cmd = new Commandline();
+
+ cmd.createArg().setValue( "hash" );
+
+ if ( dryRun )
+ {
+ cmd.createArg().setValue( "--dry-run" );
+ }
+
+ return cmd;
+ }
+
+}
Added: 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=1763963&view=auto
==============================================================================
--- maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod/JModListMojo.java (added)
+++ maven/plugins/trunk/maven-jmod-plugin/src/main/java/org/apache/maven/plugins/jmod/JModListMojo.java Sun Oct 9 12:02:05 2016
@@ -0,0 +1,65 @@
+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.IOException;
+
+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.ResolutionScope;
+
+/**
+ * <pre>
+ * jmod list...
+ * </pre>
+ *
+ * @author Karl Heinz Marbaise <a href="mailto:khmarbaise@apache.org">khmarbaise@apache.org</a>
+ */
+@Mojo( name = "list", requiresDependencyResolution = ResolutionScope.COMPILE, defaultPhase = LifecyclePhase.PACKAGE )
+public class JModListMojo
+ extends AbstractJModMojo
+{
+ 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 );
+ }
+
+// // Synopsis
+// // Usage: jmod ...
+// Commandline cmd = createJModCommandLine();
+// cmd.setExecutable( jModExecutable );
+//
+// executeCommand( cmd, outputDirectory );
+
+ }
+
+}