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,
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() {
/**
@Override
public List<String> getCompileClasspathElements() throws DependencyResolutionRequiredException {
List<String> cp = new ArrayList<String>();
- cp.add(binaries);
- cp.addAll(Arrays.asList(libraries));
+ cp.addAll(project.getBinaries());
+ cp.addAll(project.getLibraries());
return cp;
}
};
// 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);
private Properties properties;
private List<String> sourceDirs = Lists.newArrayList();
private List<String> testDirs = Lists.newArrayList();
+ private List<String> binaries = Lists.newArrayList();
+ private List<String> libraries = Lists.newArrayList();
/**
* @param baseDir project base directory
public void addTestDir(String path) {
testDirs.add(path);
}
+
+ public List<String> 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<String> 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);
+ }
}
@Test
public void sourceDirectories() {
createRequiredProperties();
- properties.setProperty("sonar.projectBinaries", "junit.jar");
project.addSourceDir("src");
project.addTestDir("test");
@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();