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 12:21:45 UTC
[maven-jmod-plugin] 03/06: Add integration test.
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch JMOD-20
in repository https://gitbox.apache.org/repos/asf/maven-jmod-plugin.git
commit c274a7ce47aae857a121cb80a0d6987bf5de9f93
Author: Andre Tadeu de Carvalho <an...@gmail.com>
AuthorDate: Sat Dec 15 23:37:26 2018 -0200
Add integration test.
---
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 | 99 ++++++++++++++
src/it/mjmod-20-set-main-class/verify.groovy | 152 +++++++++++++++++++++
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 ++++
9 files changed, 548 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..8948d9b
--- /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 = 1.9+
+invoker.goals = clean 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..c56f561
--- /dev/null
+++ b/src/it/mjmod-20-set-main-class/pom.xml
@@ -0,0 +1,99 @@
+<?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>
+ <maven.compiler.source>1.9</maven.compiler.source>
+ <maven.compiler.target>1.9</maven.compiler.target>
+ </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>
+ <artifactId>maven-clean-plugin</artifactId>
+ <version>3.0.0</version>
+ </plugin>
+ <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
+ <plugin>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>3.0.2</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.8.0</version>
+ <configuration>
+ <target>1.9</target>
+ <source>1.9</source>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>3.0.2</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-install-plugin</artifactId>
+ <version>2.5.2</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <version>2.8.2</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jmod-plugin</artifactId>
+ <!--<version>@project.version@</version> -->
+ <version>3.0.0-alpha-2-SNAPSHOT</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..1b72b80
--- /dev/null
+++ b/src/it/mjmod-20-set-main-class/verify.groovy
@@ -0,0 +1,152 @@
+/*
+ * 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
+
+
+try {
+ println("Checking if ${basedir}/world/target exists.")
+ File target = new File( basedir, "/world/target" )
+ if ( !target.exists() || !target.isDirectory() ) {
+ System.err.println( "${target.getAbsolutePath()} folder is missing or not a directory." )
+ return false
+ }
+
+ File artifact = new File( target, "/jmods/myproject.world.jmod" )
+ if ( !artifact.exists() || artifact.isDirectory() ) {
+ System.err.println( "${artifact.getAbsolutePath()} file is missing or a directory." )
+ return false
+ }
+
+ String[] artifactNames = [
+ "classes/module-info.class",
+ "classes/myproject/world/World.class"
+ ]
+
+ 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() )
+ }
+ }
+
+ if ( artifactNames.length != contents.size() ) {
+ System.err.println( "jar content size is different from the expected content size" )
+ return false
+ }
+ artifactNames.each{ artifactName ->
+ if ( !contents.contains( artifactName ) ) {
+ System.err.println( "Artifact[" + artifactName + "] not found in jar archive" )
+ return false
+ }
+ }
+} catch ( Throwable e ) {
+ e.printStackTrace()
+ return false
+}
+
+try {
+ println("Checking if ${basedir}/greetings/target exists.")
+ File target = new File( basedir, "/greetings/target" )
+ if ( !target.exists() || !target.isDirectory() ) {
+ System.err.println( "${target.getAbsolutePath()} folder is missing or not a directory." )
+ return false
+ }
+
+ File artifact = new File( target, "/jmods/myproject.greetings.jmod" )
+ if ( !artifact.exists() || artifact.isDirectory() ) {
+ System.err.println( "${artifact.getAbsolutePath()} file is missing or a directory." )
+ return false
+ }
+
+ String[] artifactNames = [
+ "classes/module-info.class",
+ "classes/myproject/greetings/Main.class"
+ ]
+
+ 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() )
+ }
+ }
+
+ if ( artifactNames.length != contents.size() ) {
+ System.err.println( "jar content size is different from the expected content size" )
+ return false
+ }
+ artifactNames.each{ artifactName ->
+ if ( !contents.contains( artifactName ) ) {
+ System.err.println( "Artifact[" + artifactName + "] not found in jar archive" )
+ return false
+ }
+ }
+
+ def sout = new StringBuilder(), serr = new StringBuilder()
+ def proc = "jmod describe ${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
+ }
+ return true
+ } else {
+ System.err.println( "Some error happened while trying to run 'jmod describe "
+ + "${target}/jmods/myproject.greetings.jmod'" )
+ System.err.println(serr)
+ return false
+ }
+} catch ( Throwable e ) {
+ e.printStackTrace()
+ return false
+}
+
+return true
\ 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";
+ }
+}