You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2019/01/18 10:26:26 UTC
[maven-jmod-plugin] branch master updated: [MJMOD-20] set jmod
--main-class argument if it is set.
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-jmod-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 0a2af83 [MJMOD-20] set jmod --main-class argument if it is set.
0a2af83 is described below
commit 0a2af837d99ad230a5cc20204abb773b989ebf04
Author: André Tadeu de Carvalho <an...@gmail.com>
AuthorDate: Fri Jan 18 08:26:22 2019 -0200
[MJMOD-20] set jmod --main-class argument if it is set.
---
src/it/mjmod-20-set-main-class/greetings/pom.xml | 95 +++++++++++++++++++++
.../greetings/src/main/java/module-info.java | 22 +++++
.../src/main/java/myproject/greetings/Main.java | 29 +++++++
src/it/mjmod-20-set-main-class/invoker.properties | 18 ++++
src/it/mjmod-20-set-main-class/pom.xml | 74 ++++++++++++++++
src/it/mjmod-20-set-main-class/verify.groovy | 98 ++++++++++++++++++++++
src/it/mjmod-20-set-main-class/world/pom.xml | 85 +++++++++++++++++++
.../world/src/main/java/module-info.java | 22 +++++
.../world/src/main/java/myproject/world/World.java | 26 ++++++
.../apache/maven/plugins/jmod/JModCreateMojo.java | 6 ++
10 files changed, 475 insertions(+)
diff --git a/src/it/mjmod-20-set-main-class/greetings/pom.xml b/src/it/mjmod-20-set-main-class/greetings/pom.xml
new file mode 100644
index 0000000..4046bd6
--- /dev/null
+++ b/src/it/mjmod-20-set-main-class/greetings/pom.xml
@@ -0,0 +1,95 @@
+<?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">
+ <parent>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jmod-plugin-mjmod-20</artifactId>
+ <version>99.0</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>myproject.greetings</artifactId>
+ <packaging>jmod</packaging>
+
+ <name>myproject.greetings</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>myproject.world</artifactId>
+ <type>jmod</type>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifest>
+ <addClasspath>true</addClasspath>
+ <mainClass>myproject.greetings.Main</mainClass>
+ </manifest>
+ </archive>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ <configuration>
+ <classifier>client</classifier>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jmod-plugin</artifactId>
+ <configuration>
+ <mainClass>myproject.greetings.Main</mainClass>
+ <modulePath>target/jmods</modulePath>
+ <moduleVersion>${project.version}</moduleVersion>
+ </configuration>
+ <executions>
+ <execution>
+ <id>list</id>
+ <goals>
+ <goal>list</goal>
+ </goals>
+ <phase>verify</phase>
+ </execution>
+ <execution>
+ <id>describe</id>
+ <goals>
+ <goal>describe</goal>
+ </goals>
+ <phase>verify</phase>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/src/it/mjmod-20-set-main-class/greetings/src/main/java/module-info.java b/src/it/mjmod-20-set-main-class/greetings/src/main/java/module-info.java
new file mode 100644
index 0000000..f7a143b
--- /dev/null
+++ b/src/it/mjmod-20-set-main-class/greetings/src/main/java/module-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+
+module myproject.greetings {
+ requires myproject.world;
+}
\ No newline at end of file
diff --git a/src/it/mjmod-20-set-main-class/greetings/src/main/java/myproject/greetings/Main.java b/src/it/mjmod-20-set-main-class/greetings/src/main/java/myproject/greetings/Main.java
new file mode 100644
index 0000000..4a0e709
--- /dev/null
+++ b/src/it/mjmod-20-set-main-class/greetings/src/main/java/myproject/greetings/Main.java
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+package myproject.greetings;
+
+import myproject.world.World;
+
+public class Main {
+ public static void main(String[] args) {
+ System.out.format("Greetings %s!%n", World.name());
+ }
+}
+
diff --git a/src/it/mjmod-20-set-main-class/invoker.properties b/src/it/mjmod-20-set-main-class/invoker.properties
new file mode 100644
index 0000000..eb94c3e
--- /dev/null
+++ b/src/it/mjmod-20-set-main-class/invoker.properties
@@ -0,0 +1,18 @@
+# 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.
+invoker.java.version = 9+
+invoker.goals = package
diff --git a/src/it/mjmod-20-set-main-class/pom.xml b/src/it/mjmod-20-set-main-class/pom.xml
new file mode 100644
index 0000000..6a52afe
--- /dev/null
+++ b/src/it/mjmod-20-set-main-class/pom.xml
@@ -0,0 +1,74 @@
+<?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>
+
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jmod-plugin-mjmod-20</artifactId>
+ <version>99.0</version>
+ <packaging>pom</packaging>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>myproject.world</artifactId>
+ <version>${project.version}</version>
+ <type>jmod</type>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <build>
+ <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.8.0</version>
+ <configuration>
+ <release>9</release>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jmod-plugin</artifactId>
+ <version>@project.version@</version>
+ <extensions>true</extensions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <modules>
+ <module>world</module>
+ <module>greetings</module>
+ </modules>
+
+</project>
\ No newline at end of file
diff --git a/src/it/mjmod-20-set-main-class/verify.groovy b/src/it/mjmod-20-set-main-class/verify.groovy
new file mode 100644
index 0000000..1b74c30
--- /dev/null
+++ b/src/it/mjmod-20-set-main-class/verify.groovy
@@ -0,0 +1,98 @@
+/*
+ * 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.util.jar.JarEntry
+import java.util.jar.JarFile
+
+def validateArtifact( String module, List<String> artifactNames )
+{
+ println( "Checking if ${basedir}/${module}/target exists." )
+ File target = new File( basedir, "/${module}/target" )
+ assert target.isDirectory()
+
+ File artifact = new File( target, "/jmods/myproject.${module}.jmod" )
+ assert artifact.isFile()
+
+ Set contents = new HashSet()
+
+ JarFile jar = new JarFile( artifact )
+ Enumeration jarEntries = jar.entries()
+ while ( jarEntries.hasMoreElements() )
+ {
+ JarEntry entry = (JarEntry) jarEntries.nextElement()
+ println( "Current entry: ${entry}" )
+ if ( !entry.isDirectory() )
+ {
+ // Only compare files
+ contents.add( entry.getName() )
+ }
+ }
+
+ assert artifactNames.size() == contents.size()
+
+ artifactNames.each{ artifactName ->
+ assert contents.contains( artifactName )
+ }
+}
+
+validateArtifact( "world", [ "classes/module-info.class", "classes/myproject/world/World.class" ] )
+validateArtifact( "greetings", [ "classes/module-info.class", "classes/myproject/greetings/Main.class" ] )
+
+def sout = new StringBuilder(), serr = new StringBuilder()
+def proc = "jmod describe ${basedir}/greetings/target/jmods/myproject.greetings.jmod".execute()
+proc.consumeProcessOutput( sout, serr )
+proc.waitForOrKill( 1000 )
+if ( ! sout.toString().trim().isEmpty() && serr.toString().trim().isEmpty() )
+{
+ Set<String> expectedLines = new HashSet(
+ Arrays.asList(
+ "myproject.greetings@99.0",
+ "requires java.base mandated",
+ "requires myproject.world",
+ "contains myproject.greetings",
+ "main-class myproject.greetings.Main" ) )
+ String[] lines = sout.toString().split("\n")
+ for ( String line : lines )
+ {
+ if ( ! line.trim().isEmpty() && !expectedLines.contains(line) )
+ {
+ System.err.println( "This line was not returned from jmod: ${line}" )
+ return false
+ }
+ else
+ {
+ expectedLines.remove(line)
+ }
+ }
+ if (!expectedLines.isEmpty()) {
+ System.err.println( "This module does not the following items:" )
+ for ( String line : expectedLines )
+ {
+ System.err.println( line )
+ }
+ return false
+ }
+}
+else
+{
+ System.err.println( "Some error happened while trying to run 'jmod describe "
+ + "${target}/jmods/myproject.greetings.jmod'" )
+ System.err.println( serr )
+ return false
+}
\ No newline at end of file
diff --git a/src/it/mjmod-20-set-main-class/world/pom.xml b/src/it/mjmod-20-set-main-class/world/pom.xml
new file mode 100644
index 0000000..e5a0bb6
--- /dev/null
+++ b/src/it/mjmod-20-set-main-class/world/pom.xml
@@ -0,0 +1,85 @@
+<?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">
+ <parent>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jmod-plugin-mjmod-20</artifactId>
+ <version>99.0</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>myproject.world</artifactId>
+ <packaging>jmod</packaging>
+
+ <name>myproject.world</name>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifest>
+ <addClasspath>true</addClasspath>
+ </manifest>
+ </archive>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ <configuration>
+ <classifier>client</classifier>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jmod-plugin</artifactId>
+ <configuration>
+ <modulePath>target/jmods</modulePath>
+ <moduleVersion>${project.version}</moduleVersion>
+ </configuration>
+ <executions>
+ <execution>
+ <id>list</id>
+ <goals>
+ <goal>list</goal>
+ </goals>
+ <phase>verify</phase>
+ </execution>
+ <execution>
+ <id>describe</id>
+ <goals>
+ <goal>describe</goal>
+ </goals>
+ <phase>verify</phase>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/src/it/mjmod-20-set-main-class/world/src/main/java/module-info.java b/src/it/mjmod-20-set-main-class/world/src/main/java/module-info.java
new file mode 100644
index 0000000..3077609
--- /dev/null
+++ b/src/it/mjmod-20-set-main-class/world/src/main/java/module-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+
+module myproject.world {
+ exports myproject.world;
+}
\ No newline at end of file
diff --git a/src/it/mjmod-20-set-main-class/world/src/main/java/myproject/world/World.java b/src/it/mjmod-20-set-main-class/world/src/main/java/myproject/world/World.java
new file mode 100644
index 0000000..6509579
--- /dev/null
+++ b/src/it/mjmod-20-set-main-class/world/src/main/java/myproject/world/World.java
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+package myproject.world;
+
+public class World {
+ public static String name() {
+ return "world";
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/jmod/JModCreateMojo.java b/src/main/java/org/apache/maven/plugins/jmod/JModCreateMojo.java
index b268372..24589a0 100644
--- a/src/main/java/org/apache/maven/plugins/jmod/JModCreateMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jmod/JModCreateMojo.java
@@ -587,6 +587,12 @@ public class JModCreateMojo
argsFile.println( getPlatformSeparatedList( configList ) );
}
+ if ( StringUtils.isNotBlank( mainClass ) )
+ {
+ argsFile.println( "--main-class" );
+ argsFile.println( mainClass );
+ }
+
List<String> cmdsList = handleConfigurationListWithDefault( cmds, DEFAULT_CMD_DIRECTORY );
if ( !cmdsList.isEmpty() )
{