This is an automated email from the ASF dual-hosted git repository. rfscholte pushed a commit to branch MJMOD-8 in repository https://gitbox.apache.org/repos/asf/maven-jmod-plugin.git
commit ec2a619b953fbdf5836f536c4c7f9b2329c87085 Author: Andre Tadeu de Carvalho <[email protected]> AuthorDate: Fri Jan 18 14:33:07 2019 -0200 Preliminar version of 'NPE on create'. --- .../about-cli-app/pom.xml | 44 +++++++++++++ .../about-cli-app/src/main/java/module-info.java | 24 +++++++ .../src/main/java/mymodule/about/cli/Main.java | 51 +++++++++++++++ .../about-cli-distribution-jmod/pom.xml | 74 ++++++++++++++++++++++ .../src/main/cmds/about | 23 +++++++ .../src/main/configs/about.yaml | 18 ++++++ .../invoker.properties | 18 ++++++ .../mjmod-8-generate-jmod-in-other-project/pom.xml | 69 ++++++++++++++++++++ .../verify.groovy | 64 +++++++++++++++++++ .../apache/maven/plugins/jmod/JModCreateMojo.java | 70 ++++++++++++++++---- 10 files changed, 443 insertions(+), 12 deletions(-) diff --git a/src/it/mjmod-8-generate-jmod-in-other-project/about-cli-app/pom.xml b/src/it/mjmod-8-generate-jmod-in-other-project/about-cli-app/pom.xml new file mode 100644 index 0000000..3c55696 --- /dev/null +++ b/src/it/mjmod-8-generate-jmod-in-other-project/about-cli-app/pom.xml @@ -0,0 +1,44 @@ +<?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-jmod-plugin-mjmod-8</artifactId> + <version>99.0</version> + </parent> + + <artifactId>about-cli-app</artifactId> + <packaging>jar</packaging> + + <dependencies> + <dependency> + <groupId>info.picocli</groupId> + <artifactId>picocli</artifactId> + <version>2.0.0</version> + <type>jar</type> + </dependency> + </dependencies> + +</project> diff --git a/src/it/mjmod-8-generate-jmod-in-other-project/about-cli-app/src/main/java/module-info.java b/src/it/mjmod-8-generate-jmod-in-other-project/about-cli-app/src/main/java/module-info.java new file mode 100644 index 0000000..f836de9 --- /dev/null +++ b/src/it/mjmod-8-generate-jmod-in-other-project/about-cli-app/src/main/java/module-info.java @@ -0,0 +1,24 @@ +/* + * 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 mymodule.about.cli { + requires java.base; + requires static info.picocli; + exports mymodule.about.cli; +} diff --git a/src/it/mjmod-8-generate-jmod-in-other-project/about-cli-app/src/main/java/mymodule/about/cli/Main.java b/src/it/mjmod-8-generate-jmod-in-other-project/about-cli-app/src/main/java/mymodule/about/cli/Main.java new file mode 100644 index 0000000..e7de64b --- /dev/null +++ b/src/it/mjmod-8-generate-jmod-in-other-project/about-cli-app/src/main/java/mymodule/about/cli/Main.java @@ -0,0 +1,51 @@ +/* + * 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 mymodule.about.cli; + +import picocli.CommandLine; + +import static picocli.CommandLine.*; + +@Command( + name = "Main", + description = "Demonstrating picocli", + headerHeading = "Demonstration Usage:%n%n") +public class Main { + + @Option(names = {"-v", "--verbose"}, description = "Verbose output?") + private boolean verbose; + + @Option(names = {"-f", "--file"}, description = "Path and name of file", required = true) + private String fileName; + + @Option(names = {"-h", "--help"}, description = "Display help/usage.", help = true) + boolean help; + + public static void main(String[] arguments) { + + final Main main = CommandLine.populateCommand(new Main(), arguments); + + if (main.help) { + CommandLine.usage(main, System.out, CommandLine.Help.Ansi.AUTO); + } else { + System.out.println("The provided file path and name is " + main.fileName + " and verbosity is set to " + main.verbose); + } + } +} diff --git a/src/it/mjmod-8-generate-jmod-in-other-project/about-cli-distribution-jmod/pom.xml b/src/it/mjmod-8-generate-jmod-in-other-project/about-cli-distribution-jmod/pom.xml new file mode 100644 index 0000000..438a5ad --- /dev/null +++ b/src/it/mjmod-8-generate-jmod-in-other-project/about-cli-distribution-jmod/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> + + <parent> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jmod-plugin-mjmod-8</artifactId> + <version>99.0</version> + </parent> + + <artifactId>about-cli-distribution-jmod</artifactId> + <packaging>jmod</packaging> + + <dependencies> + <dependency> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>about-cli-app</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jmod-plugin</artifactId> + <extensions>true</extensions> + <!-- <configuration> + <classPath> + ${project.parent.basedir}/about-cli-app/target/about-cli-app-${project.version}.jar + </classPath> + </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-8-generate-jmod-in-other-project/about-cli-distribution-jmod/src/main/cmds/about b/src/it/mjmod-8-generate-jmod-in-other-project/about-cli-distribution-jmod/src/main/cmds/about new file mode 100755 index 0000000..f265741 --- /dev/null +++ b/src/it/mjmod-8-generate-jmod-in-other-project/about-cli-distribution-jmod/src/main/cmds/about @@ -0,0 +1,23 @@ +#!/bin/sh + +# 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. + +JLINK_VM_OPTIONS= +DIR=`dirname $0` +$DIR/java $JLINK_VM_OPTIONS -m mymodule.about.cli.jar/mymodule.about.cli.Main $@ + diff --git a/src/it/mjmod-8-generate-jmod-in-other-project/about-cli-distribution-jmod/src/main/configs/about.yaml b/src/it/mjmod-8-generate-jmod-in-other-project/about-cli-distribution-jmod/src/main/configs/about.yaml new file mode 100644 index 0000000..b5e8780 --- /dev/null +++ b/src/it/mjmod-8-generate-jmod-in-other-project/about-cli-distribution-jmod/src/main/configs/about.yaml @@ -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. + +Test diff --git a/src/it/mjmod-8-generate-jmod-in-other-project/invoker.properties b/src/it/mjmod-8-generate-jmod-in-other-project/invoker.properties new file mode 100644 index 0000000..eb94c3e --- /dev/null +++ b/src/it/mjmod-8-generate-jmod-in-other-project/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-8-generate-jmod-in-other-project/pom.xml b/src/it/mjmod-8-generate-jmod-in-other-project/pom.xml new file mode 100644 index 0000000..49725f8 --- /dev/null +++ b/src/it/mjmod-8-generate-jmod-in-other-project/pom.xml @@ -0,0 +1,69 @@ +<?xml version="1.0"?> +<!-- + 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-8</artifactId> + <version>99.0</version> + <packaging>pom</packaging> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> + </properties> + + <modules> + <module>about-cli-app</module> + <module>about-cli-distribution-jmod</module> + </modules> + + <build> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.8.0</version> + <configuration> + <release>9</release> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jmod-plugin</artifactId> + <version>@project.version@</version> + </plugin> + </plugins> + </pluginManagement> + + </build> + + <pluginRepositories> + <pluginRepository> + <id>apache.snapshots</id> + <url>http://repository.apache.org/snapshots/</url> + </pluginRepository> + </pluginRepositories> + +</project> diff --git a/src/it/mjmod-8-generate-jmod-in-other-project/verify.groovy b/src/it/mjmod-8-generate-jmod-in-other-project/verify.groovy new file mode 100644 index 0000000..7ca4e3d --- /dev/null +++ b/src/it/mjmod-8-generate-jmod-in-other-project/verify.groovy @@ -0,0 +1,64 @@ +/* + * 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 + + +println( "Checking if ${basedir}/about-cli-app/target exists." ) +File target = new File( basedir, "/about-cli-app/target" ) +assert target.isDirectory() + +File artifact = new File( basedir, "/about-cli-distribution-jmod/target/jmods/about-cli-distribution-jmod.jmod" ) +assert artifact.isFile() + +String[] artifactNames = [ + "classes/module-info.class", + "classes/META-INF/MANIFEST.MF", + "classes/mymodule/about/cli/Main.class", + "classes/META-INF/maven/org.apache.maven.plugins/about-cli-app/pom.xml", + "classes/META-INF/maven/org.apache.maven.plugins/about-cli-app/pom.properties", + "conf/about.yaml", + "bin/about" +] + +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() ) + } +} + +println( "Comparing the expected number of files with the actual number of files" ) +assert artifactNames.length == contents.size() + +artifactNames.each{ artifactName -> + println( "Does ${artifactName} exist in content." ) + assert contents.contains( artifactName ) +} + +return true \ No newline at end of file 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 24589a0..37a5fdd 100644 --- a/src/main/java/org/apache/maven/plugins/jmod/JModCreateMojo.java +++ b/src/main/java/org/apache/maven/plugins/jmod/JModCreateMojo.java @@ -30,6 +30,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import org.apache.commons.lang3.SystemUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -283,6 +284,15 @@ public class JModCreateMojo private List<String> modulePaths; + /** + * Define the value for the parameter <code>--class-path <path></code>, which is used when generating + * a jmod file from a JAR. + * + * Example: <code>jmod create --class-path <JAR location> <full jmod destination path></code> + */ + // @Parameter + private String classPath = ""; + public void execute() throws MojoExecutionException, MojoFailureException { @@ -321,21 +331,52 @@ public class JModCreateMojo modsFolder.mkdirs(); this.modulePaths = new ArrayList<>(); - for ( Entry<String, JavaModuleDescriptor> item : pathElements.entrySet() ) + + if ( pathElements != null && !pathElements.isEmpty() ) { - // Isn't there a better solution? - if ( item.getValue() == null ) + for ( Entry<String, JavaModuleDescriptor> item : pathElements.entrySet() ) { - String message = "The given dependency " + item.getKey() - + " does not have a module-info.java file. So it can't be linked."; - getLog().error( message ); - throw new MojoFailureException( message ); + // Isn't there a better solution? + if ( item.getValue() == null ) + { + String message = "The given dependency " + item.getKey() + + " does not have a module-info.java file. So it can't be linked."; + getLog().error( message ); + throw new MojoFailureException( message ); + } + getLog().debug( "pathElements Item:" + item.getKey() + " v:" + item.getValue().name() ); + getLog().info( " -> module: " + item.getValue().name() + " ( " + item.getKey() + " )" ); + // We use the real module name and not the artifact Id... + this.modulePaths.add( item.getKey() ); + } + } + /* else if ( classPath == null || classPath.trim().isEmpty() ) + { + throw new MojoExecutionException( "You must either have a module in your project or the " + + "'classPath' configuration set in 'maven-jmod-plugin' configuration section." ); + } */ + else + { + // TODO: can I improve this? + if ( getProject().getDependencyArtifacts().isEmpty() ) + { + throw new MojoExecutionException( "You must either have a module in your project or at " + + "least one JAR/JMOD in the dependency's list." ); } - getLog().debug( "pathElements Item:" + item.getKey() + " v:" + item.getValue().name() ); - getLog().info( " -> module: " + item.getValue().name() + " ( " + item.getKey() + " )" ); - // We use the real module name and not the artifact Id... - this.modulePaths.add( item.getKey() ); + String separator = SystemUtils.IS_OS_WINDOWS ? ";" : ":"; + StringBuilder builder = new StringBuilder(); + int i = 0; + for ( Artifact artifact : getProject().getDependencyArtifacts() ) + { + builder.append( artifact.getFile().getAbsolutePath() ); + if ( ++i < getProject().getDependencyArtifacts().size() ) + { + builder.append( separator ); + } + } + classPath = builder.toString(); } + // The jmods directory of the JDK this.modulePaths.add( jmodsFolderJDK.getAbsolutePath() ); @@ -559,7 +600,12 @@ public class JModCreateMojo argsFile.println( moduleVersion ); } - if ( !pathElements.isEmpty() ) + if ( classPath != null && !classPath.trim().isEmpty() ) + { + argsFile.println( "--class-path" ); + argsFile.println( classPath ); + } + else if ( !pathElements.isEmpty() ) { argsFile.println( "--class-path" ); //TODO: Can't this be achieved in a more elegant way?
