From bef7fac6e3495dae57a44e6a5902afd89c74b196 Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Tue, 20 May 2014 20:26:27 -0400 Subject: [PATCH] [MNG-5613] fix NullPointerException when error occur during project dependency graph creation Submitted by: Sebastian Le Merdy From: https://github.com/apache/maven/pull/13 --- .../java/org/apache/maven/DefaultMaven.java | 4 +- .../org/apache/maven/DefaultMavenTest.java | 45 +++++++++++++++++++ .../cyclic-reference/module-a/pom.xml | 19 ++++++++ .../cyclic-reference/module-b/pom.xml | 19 ++++++++ .../default-maven/cyclic-reference/pom.xml | 14 ++++++ 5 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 maven-core/src/test/java/org/apache/maven/DefaultMavenTest.java create mode 100644 maven-core/src/test/projects/default-maven/cyclic-reference/module-a/pom.xml create mode 100644 maven-core/src/test/projects/default-maven/cyclic-reference/module-b/pom.xml create mode 100644 maven-core/src/test/projects/default-maven/cyclic-reference/pom.xml diff --git a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java index 6328819168..ab47efd00f 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -267,13 +267,13 @@ public class DefaultMaven // ProjectDependencyGraph projectDependencyGraph = createProjectDependencyGraph( projects, request, result, true ); - session.setProjects( projectDependencyGraph.getSortedProjects() ); - if ( result.hasExceptions() ) { return result; } + session.setProjects( projectDependencyGraph.getSortedProjects() ); + try { session.setProjectMap( getProjectMap( session.getProjects() ) ); diff --git a/maven-core/src/test/java/org/apache/maven/DefaultMavenTest.java b/maven-core/src/test/java/org/apache/maven/DefaultMavenTest.java new file mode 100644 index 0000000000..ab073a6324 --- /dev/null +++ b/maven-core/src/test/java/org/apache/maven/DefaultMavenTest.java @@ -0,0 +1,45 @@ +package org.apache.maven; + +import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.execution.MavenExecutionResult; + +import static java.util.Arrays.asList; + +/* + * 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. + */ +public class DefaultMavenTest extends AbstractCoreMavenComponentTestCase{ + + public void testThatErrorDuringProjectDependencyGraphCreationAreStored() + throws Exception + { + Maven maven = getContainer().lookup( Maven.class ); + MavenExecutionRequest request = createMavenExecutionRequest( getProject( "cyclic-reference" ) ).setGoals( asList("validate") ); + + MavenExecutionResult result = maven.execute( request ); + + assertEquals( ProjectCycleException.class, result.getExceptions().get( 0 ).getClass() ); + } + + @Override + protected String getProjectsDirectory() + { + return "src/test/projects/default-maven"; + } + +} diff --git a/maven-core/src/test/projects/default-maven/cyclic-reference/module-a/pom.xml b/maven-core/src/test/projects/default-maven/cyclic-reference/module-a/pom.xml new file mode 100644 index 0000000000..56ec3412c7 --- /dev/null +++ b/maven-core/src/test/projects/default-maven/cyclic-reference/module-a/pom.xml @@ -0,0 +1,19 @@ + + 4.0.0 + + + cyclic-reference + parent + 1.0-SNAPSHOT + + module-a + + + + cyclic-reference + module-b + 1.0-SNAPSHOT + + + diff --git a/maven-core/src/test/projects/default-maven/cyclic-reference/module-b/pom.xml b/maven-core/src/test/projects/default-maven/cyclic-reference/module-b/pom.xml new file mode 100644 index 0000000000..ffa4f34704 --- /dev/null +++ b/maven-core/src/test/projects/default-maven/cyclic-reference/module-b/pom.xml @@ -0,0 +1,19 @@ + + 4.0.0 + + + cyclic-reference + parent + 1.0-SNAPSHOT + + module-b + + + + cyclic-reference + module-a + 1.0-SNAPSHOT + + + diff --git a/maven-core/src/test/projects/default-maven/cyclic-reference/pom.xml b/maven-core/src/test/projects/default-maven/cyclic-reference/pom.xml new file mode 100644 index 0000000000..e266619053 --- /dev/null +++ b/maven-core/src/test/projects/default-maven/cyclic-reference/pom.xml @@ -0,0 +1,14 @@ + + 4.0.0 + + cyclic-reference + parent + 1.0-SNAPSHOT + pom + + + module-a + module-b + +