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
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);
}
ProjectDefinition rootProject = defs.get(root);
if (rootProject == null) {
- throw new IllegalStateException();
+ throw new IllegalStateException(UNABLE_TO_DETERMINE_PROJECT_STRUCTURE_EXCEPTION_MESSAGE);
}
return rootProject;
}
return file;
}
+
+ private MavenProjectConverter() {
+ // only static methods
+ }
}
*/
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;
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();