From: Evgeny Mandrikov Date: Tue, 1 Feb 2011 22:58:56 +0000 (+0300) Subject: Improve ProjectDefinition X-Git-Tag: 2.6~64 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c449685c7fc56d15daab8eec3df557ed6a8ec938;p=sonarqube.git Improve ProjectDefinition * Replace properties "sonar.projectBinaries" and "sonar.projectLibraries" by explicit fields in ProjectDefinition --- diff --git a/sonar-batch/src/main/java/org/sonar/batch/InMemoryPomCreator.java b/sonar-batch/src/main/java/org/sonar/batch/InMemoryPomCreator.java index 04c6e32aa74..1f1f1a3be9d 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/InMemoryPomCreator.java +++ b/sonar-batch/src/main/java/org/sonar/batch/InMemoryPomCreator.java @@ -28,7 +28,10 @@ import org.sonar.api.utils.SonarException; import org.sonar.batch.bootstrapper.ProjectDefinition; import java.io.File; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Properties; /** * This is a dirty hack for for non-Maven environments, @@ -46,8 +49,10 @@ public class InMemoryPomCreator { File workDir = project.getWorkDir(); String buildDirectory = workDir.getAbsolutePath() + "/target"; Properties properties = project.getProperties(); - final String binaries = properties.getProperty("sonar.projectBinaries", buildDirectory + "/classes"); - final String[] libraries = StringUtils.split(properties.getProperty("sonar.projectLibraries", ""), ','); + + if (project.getBinaries().size() == 0) { + project.addBinaryDir(buildDirectory + "/classes"); + } final MavenProject pom = new MavenProject() { /** @@ -64,8 +69,8 @@ public class InMemoryPomCreator { @Override public List getCompileClasspathElements() throws DependencyResolutionRequiredException { List cp = new ArrayList(); - cp.add(binaries); - cp.addAll(Arrays.asList(libraries)); + cp.addAll(project.getBinaries()); + cp.addAll(project.getLibraries()); return cp; } }; @@ -85,7 +90,7 @@ public class InMemoryPomCreator { // Configure fake directories pom.getBuild().setDirectory(buildDirectory); - pom.getBuild().setOutputDirectory(binaries); + pom.getBuild().setOutputDirectory(project.getBinaries().get(0)); Reporting reporting = new Reporting(); String reportingOutputDirectory = buildDirectory + "/site"; reporting.setOutputDirectory(reportingOutputDirectory); diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/ProjectDefinition.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/ProjectDefinition.java index 10ede5a1100..54ea3b5f5e3 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/ProjectDefinition.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/ProjectDefinition.java @@ -39,6 +39,8 @@ public class ProjectDefinition { private Properties properties; private List sourceDirs = Lists.newArrayList(); private List testDirs = Lists.newArrayList(); + private List binaries = Lists.newArrayList(); + private List libraries = Lists.newArrayList(); /** * @param baseDir project base directory @@ -85,4 +87,29 @@ public class ProjectDefinition { public void addTestDir(String path) { testDirs.add(path); } + + public List getBinaries() { + return binaries; + } + + /** + * @param path path to directory with compiled source. In case of Java this is directory with class files. + * It can be absolute or relative to project directory. + * @TODO currently Sonar supports only one such directory due to dependency on MavenProject + */ + public void addBinaryDir(String path) { + binaries.add(path); + } + + public List getLibraries() { + return libraries; + } + + /** + * @param path path to file with third-party library. In case of Java this is path to jar file. + * It can be absolute or relative to project directory. + */ + public void addLibrary(String path) { + libraries.add(path); + } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/InMemoryPomCreatorTest.java b/sonar-batch/src/test/java/org/sonar/batch/InMemoryPomCreatorTest.java index 9893598add2..7ddb33cfef7 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/InMemoryPomCreatorTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/InMemoryPomCreatorTest.java @@ -81,7 +81,6 @@ public class InMemoryPomCreatorTest { @Test public void sourceDirectories() { createRequiredProperties(); - properties.setProperty("sonar.projectBinaries", "junit.jar"); project.addSourceDir("src"); project.addTestDir("test"); @@ -97,8 +96,8 @@ public class InMemoryPomCreatorTest { @Test public void classpath() throws Exception { createRequiredProperties(); - properties.setProperty("sonar.projectBinaries", "/classes"); - properties.setProperty("sonar.projectLibraries", "junit.jar"); + project.addBinaryDir("/classes"); + project.addLibrary("junit.jar"); MavenProject pom = create();