diff options
author | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-10-13 15:33:22 +0400 |
---|---|---|
committer | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-10-13 15:37:38 +0400 |
commit | 4e549769e27bf9dcb08aeb52d8b407a8f414a396 (patch) | |
tree | 39065552168b35be40710dec589576e4543f88f4 | |
parent | 049d0b5e982916a4b345df1736dce368129dc9af (diff) | |
download | sonarqube-4e549769e27bf9dcb08aeb52d8b407a8f414a396.tar.gz sonarqube-4e549769e27bf9dcb08aeb52d8b407a8f414a396.zip |
SONAR-2681 Provide meaningful error message when unable to determine Maven project structure
This occurs because of usage of Advanced Reactor Options.
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/MavenProjectConverter.java | 15 | ||||
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/MavenProjectConverterTest.java | 40 |
2 files changed, 39 insertions, 16 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/MavenProjectConverter.java b/sonar-batch/src/main/java/org/sonar/batch/MavenProjectConverter.java index c9c56384afe..bd5dceb6444 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/MavenProjectConverter.java +++ b/sonar-batch/src/main/java/org/sonar/batch/MavenProjectConverter.java @@ -32,9 +32,8 @@ import com.google.common.collect.Maps; public final class MavenProjectConverter { - private MavenProjectConverter() { - // only static methods - } + private static final String UNABLE_TO_DETERMINE_PROJECT_STRUCTURE_EXCEPTION_MESSAGE = "Unable to determine structure of project." + + " Probably you use Maven Advanced Reactor Options, which is not supported by Sonar and should not be used."; public static ProjectDefinition convert(List<MavenProject> poms, MavenProject root) { Map<String, MavenProject> paths = Maps.newHashMap(); // projects by canonical path to pom.xml @@ -59,10 +58,10 @@ public final class MavenProjectConverter { ProjectDefinition parentProject = defs.get(pom); ProjectDefinition subProject = defs.get(module); if (parentProject == null) { - throw new IllegalStateException(); + throw new IllegalStateException(UNABLE_TO_DETERMINE_PROJECT_STRUCTURE_EXCEPTION_MESSAGE); } if (subProject == null) { - throw new IllegalStateException(); + throw new IllegalStateException(UNABLE_TO_DETERMINE_PROJECT_STRUCTURE_EXCEPTION_MESSAGE); } parentProject.addSubProject(subProject); } @@ -73,7 +72,7 @@ public final class MavenProjectConverter { ProjectDefinition rootProject = defs.get(root); if (rootProject == null) { - throw new IllegalStateException(); + throw new IllegalStateException(UNABLE_TO_DETERMINE_PROJECT_STRUCTURE_EXCEPTION_MESSAGE); } return rootProject; @@ -115,4 +114,8 @@ public final class MavenProjectConverter { } return file; } + + private MavenProjectConverter() { + // only static methods + } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/MavenProjectConverterTest.java b/sonar-batch/src/test/java/org/sonar/batch/MavenProjectConverterTest.java index 872de93fed8..e220ecf12d7 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/MavenProjectConverterTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/MavenProjectConverterTest.java @@ -19,6 +19,19 @@ */ package org.sonar.batch; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; + +import java.io.File; +import java.io.IOException; +import java.io.StringReader; +import java.net.URISyntaxException; +import java.util.Arrays; +import java.util.Properties; + import org.apache.commons.io.FileUtils; import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; @@ -29,18 +42,25 @@ import org.junit.Test; import org.sonar.api.CoreProperties; import org.sonar.api.batch.bootstrap.ProjectDefinition; -import java.io.File; -import java.io.IOException; -import java.io.StringReader; -import java.net.URISyntaxException; -import java.util.Arrays; -import java.util.Properties; +public class MavenProjectConverterTest { -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; + /** + * See SONAR-2681 + */ + public void shouldThrowExceptionWhenUnableToDetermineProjectStructure() { + MavenProject root = new MavenProject(); + root.setFile(new File("/foo/pom.xml")); + root.getBuild().setDirectory("target"); + root.getModules().add("module/pom.xml"); + + try { + MavenProjectConverter.convert(Arrays.asList(root), root); + fail(); + } catch (IllegalStateException e) { + assertThat(e.getMessage(), containsString("Advanced Reactor Options")); + } + } -public class MavenProjectConverterTest { @Test public void shouldConvertModules() { MavenProject root = new MavenProject(); |