Skip to content

Commit

Permalink
Fix NullPointerException when using PluginDependencies since version
Browse files Browse the repository at this point in the history
1.6.0

Fixes #76
A regression was introduced with the following change:
exec mojo can run executableDependency instead of executable (7684096)
  • Loading branch information
jonasrutishauser authored and slawekjaranowski committed Jul 12, 2022
1 parent a4d0207 commit b595f69
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 8 deletions.
29 changes: 29 additions & 0 deletions src/it/projects/project6/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<project>
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.codehaus.mojo.exec.it</groupId>
<artifactId>parent</artifactId>
<version>0.1</version>
</parent>

<groupId>org.codehaus.mojo.exec.project5</groupId>
<artifactId>project5</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>Exec Plugin Example Project 5 Parent</name>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
</dependency>
</dependencies>
</dependencyManagement>
<modules>
<module>project5exec</module>
<module>project5lib</module>
<module>project5libB</module>
</modules>
</project>
71 changes: 71 additions & 0 deletions src/it/projects/project6/project5exec/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<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/maven-v4_0_0.xsd">
<parent>
<groupId>org.codehaus.mojo.exec.project5</groupId>
<artifactId>project5</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>project5exec</artifactId>
<packaging>jar</packaging>
<name>Exec Plugin Example Project 5 Exec</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>@pom.version@</version>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<systemProperties>
<systemProperty>
<key>propkey</key>
<value>propvalue</value>
</systemProperty>
</systemProperties>
<mainClass>
org.codehaus.mojo.exec.project5libB.App
</mainClass>
<arguments>
<argument>argument1</argument>
<argument>argument2</argument>
</arguments>
<includeProjectDependencies>false</includeProjectDependencies>
<includePluginDependencies>true</includePluginDependencies>
<executableDependency>
<groupId>org.codehaus.mojo.exec.project5</groupId>
<artifactId>project5libB</artifactId>
</executableDependency>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo.exec.project5</groupId>
<artifactId>project5libB</artifactId>
<version>${project.version}</version>
</dependency>
<!--junit dependency is an intentional extraneous dependency-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.0.4</version>
</dependency>
</dependencies>
</project>
22 changes: 22 additions & 0 deletions src/it/projects/project6/project5lib/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<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/maven-v4_0_0.xsd">
<parent>
<groupId>org.codehaus.mojo.exec.project5</groupId>
<artifactId>project5</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>project5lib</artifactId>
<packaging>jar</packaging>
<name>Exec Plugin Example Project 5 Lib</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.1</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.codehaus.mojo.exec.project5lib;

/**
* Used for manual integrationtest of the java goal.
*
*/
public class ExampleLibrary
{
public ExampleLibrary() {
}
public boolean isAGoodDay() {
return true;
}
}
21 changes: 21 additions & 0 deletions src/it/projects/project6/project5libB/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<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/maven-v4_0_0.xsd">
<parent>
<groupId>org.codehaus.mojo.exec.project5</groupId>
<artifactId>project5</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>project5libB</artifactId>
<packaging>jar</packaging>
<name>Exec Plugin Example Project 5 Lib B</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo.exec.project5</groupId>
<artifactId>project5lib</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.codehaus.mojo.exec.project5libB;

/**
* Used for manual integrationtest of the java goal.
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println("I was started. So obviously I found the main class");

App app = new App();

try
{
Class fileUtils = app.getClass().getClassLoader().loadClass( "org.codehaus.mojo.exec.project5lib.ExampleLibrary" );
if ( null != fileUtils )
{
System.out.println( "Found the ExampleLibrary" );
}
}

catch ( Exception e )
{
System.out.println( "Did not find the ExampleLibrary" );
}

try
{
Class fileUtils = app.getClass().getClassLoader().loadClass( "org.apache.commons.io.FileUtils" );
if ( null != fileUtils )
{
System.out.println( "Found the runtime dependency" );
}
}
catch ( Exception e )
{
System.out.println( "Did not find the runtime dependency" );
}


String value = System.getProperty("propkey");
if (null != value)
{
System.out.println("Found the system property passed");
}
}
}
24 changes: 24 additions & 0 deletions src/it/projects/project6/verify.groovy
Original file line number Diff line number Diff line change
@@ -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.
*/
File log = new File(basedir, 'build.log')
assert log.exists()
assert log.getText().contains("I was started. So obviously I found the main class")
assert log.getText().contains("Found the ExampleLibrary")
assert log.getText().contains("Found the runtime dependency")
assert log.getText().contains("Found the system property passed")
5 changes: 5 additions & 0 deletions src/main/java/org/codehaus/mojo/exec/AbstractExecMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ protected final MavenSession getSession()
return session;
}

protected final List<Artifact> getPluginDependencies()
{
return pluginDependencies;
}

/**
* Examine the plugin dependencies to find the executable artifact.
*
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/org/codehaus/mojo/exec/ExecJavaMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilder;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.shared.artifact.filter.resolve.AndFilter;
import org.apache.maven.shared.artifact.filter.resolve.TransformableFilter;
import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResult;
import org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver;

Expand All @@ -53,12 +55,6 @@ public class ExecJavaMojo
@Component
private ProjectBuilder projectBuilder;

/**
* @since 1.1-beta-1
*/
@Parameter( readonly = true, defaultValue = "${plugin.artifacts}" )
private List<Artifact> pluginDependencies;

/**
* The main class to execute.<br>
* With Java 9 and above you can prefix it with the modulename, e.g. <code>com.greetings/com.greetings.Main</code>
Expand Down Expand Up @@ -679,7 +675,7 @@ private Set<Artifact> determineRelevantPluginDependencies()
if ( this.executableDependency == null )
{
getLog().debug( "All Plugin Dependencies will be included." );
relevantDependencies = new HashSet<Artifact>( this.pluginDependencies );
relevantDependencies = new HashSet<Artifact>( this.getPluginDependencies() );
}
else
{
Expand Down Expand Up @@ -715,7 +711,9 @@ private Set<Artifact> resolveExecutableDependencies( Artifact executablePomArtif
MavenProject executableProject =
this.projectBuilder.build( executablePomArtifact, buildingRequest ).getProject();

for ( ArtifactResult artifactResult : dependencyResolver.resolveDependencies( buildingRequest, executableProject.getModel(), null ) )
for ( ArtifactResult artifactResult : dependencyResolver.resolveDependencies( buildingRequest,
executableProject.getModel(),
new AndFilter( Collections.<TransformableFilter>emptyList() ) ) )
{
executableDependencies.add( artifactResult.getArtifact() );
}
Expand Down

0 comments on commit b595f69

Please sign in to comment.