@@ -1,3 +1,4 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2016 SonarSource SA | |||
@@ -17,13 +18,12 @@ | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
import java.io.File; | |||
import org.sonar.api.batch.bootstrap.ProjectBuilder; | |||
import org.sonar.api.batch.bootstrap.ProjectDefinition; | |||
import org.sonar.api.batch.bootstrap.ProjectReactor; | |||
import org.sonar.api.config.Settings; | |||
import java.io.File; | |||
/** | |||
* This plugin relates to projects/project-builder sample | |||
*/ | |||
@@ -58,7 +58,7 @@ public final class CreateSubProjects extends ProjectBuilder { | |||
subProject.setKey("com.sonarsource.it.projects.batch:project-builder-module-a"); | |||
subProject.setVersion(root.getVersion()); | |||
subProject.setName("Module A"); | |||
subProject.setSourceDirs("src"); | |||
subProject.addSources("src"); | |||
root.addSubProject(subProject); | |||
return subProject; | |||
} | |||
@@ -70,7 +70,7 @@ public final class CreateSubProjects extends ProjectBuilder { | |||
subProject.setKey("com.sonarsource.it.projects.batch:project-builder-module-b"); | |||
subProject.setVersion(root.getVersion()); | |||
subProject.setName("Module B"); | |||
subProject.addSourceFiles("src/HelloB.java"); | |||
subProject.addSources("src/HelloB.java"); | |||
root.addSubProject(subProject); | |||
return subProject; | |||
} |
@@ -41,38 +41,9 @@ import org.sonar.api.CoreProperties; | |||
public class ProjectDefinition { | |||
public static final String SOURCES_PROPERTY = "sonar.sources"; | |||
/** | |||
* @deprecated since 4.5 use {@link #SOURCES_PROPERTY} | |||
*/ | |||
@Deprecated | |||
public static final String SOURCE_DIRS_PROPERTY = SOURCES_PROPERTY; | |||
/** | |||
* @deprecated since 4.5 use {@link #SOURCES_PROPERTY} | |||
*/ | |||
@Deprecated | |||
public static final String SOURCE_FILES_PROPERTY = "sonar.sourceFiles"; | |||
public static final String TESTS_PROPERTY = "sonar.tests"; | |||
/** | |||
* @deprecated since 4.5 use {@link #TESTS_PROPERTY} | |||
*/ | |||
@Deprecated | |||
public static final String TEST_DIRS_PROPERTY = TESTS_PROPERTY; | |||
/** | |||
* @deprecated since 4.5 use {@link #TESTS_PROPERTY} | |||
*/ | |||
@Deprecated | |||
public static final String TEST_FILES_PROPERTY = "sonar.testFiles"; | |||
/** | |||
* @deprecated since 4.5.1 use SonarQube Java specific API | |||
*/ | |||
@Deprecated | |||
public static final String BINARIES_PROPERTY = "sonar.binaries"; | |||
/** | |||
* @deprecated since 4.5.1 use SonarQube Java specific API | |||
*/ | |||
@Deprecated | |||
public static final String LIBRARIES_PROPERTY = "sonar.libraries"; | |||
public static final String BUILD_DIR_PROPERTY = "sonar.buildDir"; | |||
private static final char SEPARATOR = ','; | |||
@@ -90,17 +61,6 @@ public class ProjectDefinition { | |||
} | |||
} | |||
/** | |||
* @deprecated in 2.12, because it uses external object to represent internal state. | |||
* To ensure backward-compatibility with Ant task this method cannot clone properties, | |||
* so other callers must explicitly make clone of properties before passing into this method. | |||
* Thus better to use {@link #create()} with combination of other methods like {@link #setProperties(Properties)} and {@link #setProperty(String, String)}. | |||
*/ | |||
@Deprecated | |||
public static ProjectDefinition create(Properties properties) { | |||
return new ProjectDefinition(properties); | |||
} | |||
public static ProjectDefinition create() { | |||
return new ProjectDefinition(new Properties()); | |||
} | |||
@@ -252,14 +212,6 @@ public class ProjectDefinition { | |||
return trim(StringUtils.split(sources, SEPARATOR)); | |||
} | |||
/** | |||
* @deprecated since 4.5 use {@link #sources()} | |||
*/ | |||
@Deprecated | |||
public List<String> getSourceDirs() { | |||
return sources(); | |||
} | |||
/** | |||
* @param paths paths to file or directory with main sources. | |||
* They can be absolute or relative to project base directory. | |||
@@ -271,14 +223,6 @@ public class ProjectDefinition { | |||
return this; | |||
} | |||
/** | |||
* @deprecated since 4.5 use {@link #addSources(String...)} | |||
*/ | |||
@Deprecated | |||
public ProjectDefinition addSourceDirs(String... paths) { | |||
return addSources(paths); | |||
} | |||
public ProjectDefinition addSources(File... fileOrDirs) { | |||
for (File fileOrDir : fileOrDirs) { | |||
addSources(fileOrDir.getAbsolutePath()); | |||
@@ -286,40 +230,16 @@ public class ProjectDefinition { | |||
return this; | |||
} | |||
/** | |||
* @deprecated since 4.5 use {@link #addSources(File...)} | |||
*/ | |||
@Deprecated | |||
public ProjectDefinition addSourceDirs(File... dirs) { | |||
return addSources(dirs); | |||
} | |||
public ProjectDefinition resetSources() { | |||
properties.remove(SOURCES_PROPERTY); | |||
return this; | |||
} | |||
/** | |||
* @deprecated since 4.5 use {@link #resetSources()} | |||
*/ | |||
@Deprecated | |||
public ProjectDefinition resetSourceDirs() { | |||
return resetSources(); | |||
} | |||
public ProjectDefinition setSources(String... paths) { | |||
resetSources(); | |||
return addSources(paths); | |||
} | |||
/** | |||
* @deprecated since 4.5 use {@link #setSources(String...)} | |||
*/ | |||
@Deprecated | |||
public ProjectDefinition setSourceDirs(String... paths) { | |||
return setSources(paths); | |||
} | |||
public ProjectDefinition setSources(File... filesOrDirs) { | |||
resetSources(); | |||
for (File fileOrDir : filesOrDirs) { | |||
@@ -328,65 +248,11 @@ public class ProjectDefinition { | |||
return this; | |||
} | |||
/** | |||
* @deprecated since 4.5 use {@link #setSources(File...)} | |||
*/ | |||
@Deprecated | |||
public ProjectDefinition setSourceDirs(File... dirs) { | |||
resetSourceDirs(); | |||
for (File dir : dirs) { | |||
addSourceDirs(dir.getAbsolutePath()); | |||
} | |||
return this; | |||
} | |||
/** | |||
* @deprecated since 4.5 use {@link #addSources(File...)} | |||
*/ | |||
@Deprecated | |||
public ProjectDefinition addSourceFiles(String... paths) { | |||
// Hack for visual studio project builder that used to add baseDir first as source dir | |||
List<String> sourceDirs = getSourceDirs(); | |||
if (sourceDirs.size() == 1 && isDirectory(sourceDirs.get(0))) { | |||
resetSources(); | |||
} | |||
return addSources(paths); | |||
} | |||
/** | |||
* @deprecated since 4.5 use {@link #addSources(File...)} | |||
*/ | |||
@Deprecated | |||
public ProjectDefinition addSourceFiles(File... files) { | |||
// Hack for visual studio project builder that used to add baseDir first as source dir | |||
List<String> sourceDirs = getSourceDirs(); | |||
if (sourceDirs.size() == 1 && isDirectory(sourceDirs.get(0))) { | |||
resetSources(); | |||
} | |||
return addSources(files); | |||
} | |||
/** | |||
* @deprecated since 4.5 use {@link #sources()} | |||
*/ | |||
@Deprecated | |||
public List<String> getSourceFiles() { | |||
return sources(); | |||
} | |||
public List<String> tests() { | |||
String sources = (String) ObjectUtils.defaultIfNull(properties.get(TESTS_PROPERTY), ""); | |||
return trim(StringUtils.split(sources, SEPARATOR)); | |||
} | |||
/** | |||
* @deprecated since 4.5 use {@link #tests()} | |||
*/ | |||
@Deprecated | |||
public List<String> getTestDirs() { | |||
return tests(); | |||
} | |||
/** | |||
* @param paths path to files or directories with test sources. | |||
* It can be absolute or relative to project directory. | |||
@@ -398,14 +264,6 @@ public class ProjectDefinition { | |||
return this; | |||
} | |||
/** | |||
* @deprecated since 4.5 use {@link #addTests(String...)} | |||
*/ | |||
@Deprecated | |||
public ProjectDefinition addTestDirs(String... paths) { | |||
return addTests(paths); | |||
} | |||
public ProjectDefinition addTests(File... fileOrDirs) { | |||
for (File fileOrDir : fileOrDirs) { | |||
addTests(fileOrDir.getAbsolutePath()); | |||
@@ -413,27 +271,11 @@ public class ProjectDefinition { | |||
return this; | |||
} | |||
/** | |||
* @deprecated since 4.5 use {@link #addTests(File...)} | |||
*/ | |||
@Deprecated | |||
public ProjectDefinition addTestDirs(File... dirs) { | |||
return addTests(dirs); | |||
} | |||
public ProjectDefinition setTests(String... paths) { | |||
resetTests(); | |||
return addTests(paths); | |||
} | |||
/** | |||
* @deprecated since 4.5 use {@link #setTests(String...)} | |||
*/ | |||
@Deprecated | |||
public ProjectDefinition setTestDirs(String... paths) { | |||
return setTests(paths); | |||
} | |||
public ProjectDefinition setTests(File... fileOrDirs) { | |||
resetTests(); | |||
for (File dir : fileOrDirs) { | |||
@@ -442,116 +284,11 @@ public class ProjectDefinition { | |||
return this; | |||
} | |||
/** | |||
* @deprecated since 4.5 use {@link #setTests(File...)} | |||
*/ | |||
@Deprecated | |||
public ProjectDefinition setTestDirs(File... dirs) { | |||
return setTests(dirs); | |||
} | |||
public ProjectDefinition resetTests() { | |||
properties.remove(TESTS_PROPERTY); | |||
return this; | |||
} | |||
/** | |||
* @deprecated since 4.5 use {@link #resetTests()} | |||
*/ | |||
@Deprecated | |||
public ProjectDefinition resetTestDirs() { | |||
return resetTests(); | |||
} | |||
/** | |||
* @deprecated since 4.5 use {@link #addTests(String...)} | |||
*/ | |||
@Deprecated | |||
public ProjectDefinition addTestFiles(String... paths) { | |||
// Hack for visual studio project builder that used to add baseDir first as test dir | |||
List<String> testDirs = getTestDirs(); | |||
if (testDirs.size() == 1 && isDirectory(testDirs.get(0))) { | |||
resetTests(); | |||
} | |||
return addTests(paths); | |||
} | |||
private boolean isDirectory(String relativeOrAbsoluteDir) { | |||
File file = new File(relativeOrAbsoluteDir); | |||
if (!file.isAbsolute()) { | |||
file = new File(baseDir, relativeOrAbsoluteDir); | |||
} | |||
return file.isDirectory(); | |||
} | |||
/** | |||
* @deprecated since 4.5 use {@link #addTests(File...)} | |||
*/ | |||
@Deprecated | |||
public ProjectDefinition addTestFiles(File... files) { | |||
// Hack for visual studio project builder that used to add baseDir first as test dir | |||
List<String> testDirs = getTestDirs(); | |||
if (testDirs.size() == 1 && isDirectory(testDirs.get(0))) { | |||
resetTests(); | |||
} | |||
return addTests(files); | |||
} | |||
/** | |||
* @deprecated since 4.5 use {@link #tests()} | |||
*/ | |||
@Deprecated | |||
public List<String> getTestFiles() { | |||
return tests(); | |||
} | |||
/** | |||
* @deprecated since 4.5.1 use SonarQube Java specific API | |||
*/ | |||
@Deprecated | |||
public List<String> getBinaries() { | |||
String sources = (String) ObjectUtils.defaultIfNull(properties.get(BINARIES_PROPERTY), ""); | |||
return trim(StringUtils.split(sources, SEPARATOR)); | |||
} | |||
/** | |||
* @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. | |||
* @deprecated since 4.5.1 use SonarQube Java specific API | |||
*/ | |||
@Deprecated | |||
public ProjectDefinition addBinaryDir(String path) { | |||
appendProperty(BINARIES_PROPERTY, path); | |||
return this; | |||
} | |||
/** | |||
* @deprecated since 4.5.1 use SonarQube Java specific API | |||
*/ | |||
@Deprecated | |||
public ProjectDefinition addBinaryDir(File f) { | |||
return addBinaryDir(f.getAbsolutePath()); | |||
} | |||
/** | |||
* @deprecated since 4.5.1 use SonarQube Java specific API | |||
*/ | |||
@Deprecated | |||
public List<String> getLibraries() { | |||
String sources = (String) ObjectUtils.defaultIfNull(properties.get(LIBRARIES_PROPERTY), ""); | |||
return trim(StringUtils.split(sources, SEPARATOR)); | |||
} | |||
/** | |||
* @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. | |||
* @deprecated since 4.5.1 use SonarQube Java specific API | |||
*/ | |||
@Deprecated | |||
public void addLibrary(String path) { | |||
appendProperty(LIBRARIES_PROPERTY, path); | |||
} | |||
/** | |||
* @since 2.8 | |||
*/ |
@@ -23,6 +23,8 @@ import org.junit.Test; | |||
import org.sonar.api.batch.bootstrap.internal.ProjectBuilderContext; | |||
import org.sonar.api.config.Settings; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import java.io.File; | |||
import static org.hamcrest.core.Is.is; | |||
@@ -43,7 +45,7 @@ public class ProjectBuilderTest { | |||
ProjectDefinition root = projectReactor.getRoot(); | |||
assertThat(root.getName(), is("Name changed by plugin")); | |||
assertThat(root.getSubProjects().size(), is(1)); | |||
assertThat(root.getSubProjects().get(0).getSourceDirs(), hasItem("src")); | |||
assertThat(root.getSubProjects().get(0).sources()).contains("src"); | |||
} | |||
final static class ProjectBuilderSample extends ProjectBuilder { | |||
@@ -68,7 +70,7 @@ public class ProjectBuilderTest { | |||
subProject.setKey("groupId:parentProjectId"); | |||
subProject.setVersion(root.getVersion()); | |||
subProject.setName("Sub Project"); | |||
subProject.setSourceDirs("src"); | |||
subProject.setSources("src"); | |||
root.addSubProject(subProject); | |||
} | |||
} |
@@ -30,9 +30,6 @@ import java.util.List; | |||
import java.util.Properties; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.hamcrest.Matchers.is; | |||
import static org.hamcrest.Matchers.nullValue; | |||
import static org.junit.Assert.assertThat; | |||
public class ProjectDefinitionTest { | |||
@@ -43,14 +40,14 @@ public class ProjectDefinitionTest { | |||
public void shouldSetKey() { | |||
ProjectDefinition def = ProjectDefinition.create(); | |||
def.setKey("mykey"); | |||
assertThat(def.getKey(), is("mykey")); | |||
assertThat(def.getKey()).isEqualTo("mykey"); | |||
} | |||
@Test | |||
public void shouldSetVersion() { | |||
ProjectDefinition def = ProjectDefinition.create(); | |||
def.setVersion("2.0-SNAPSHOT"); | |||
assertThat(def.getVersion(), is("2.0-SNAPSHOT")); | |||
assertThat(def.getVersion()).isEqualTo("2.0-SNAPSHOT"); | |||
} | |||
@Test | |||
@@ -58,15 +55,15 @@ public class ProjectDefinitionTest { | |||
ProjectDefinition def = ProjectDefinition.create(); | |||
def.setName("myname"); | |||
def.setDescription("desc"); | |||
assertThat(def.getName(), is("myname")); | |||
assertThat(def.getDescription(), is("desc")); | |||
assertThat(def.getName()).isEqualTo("myname"); | |||
assertThat(def.getDescription()).isEqualTo("desc"); | |||
} | |||
@Test | |||
public void shouldSupportDefaultName() { | |||
ProjectDefinition def = ProjectDefinition.create(); | |||
def.setKey("myKey"); | |||
assertThat(def.getName(), is("Unnamed - myKey")); | |||
assertThat(def.getName()).isEqualTo("Unnamed - myKey"); | |||
} | |||
@Test | |||
@@ -75,16 +72,14 @@ public class ProjectDefinitionTest { | |||
props.setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "foo"); | |||
ProjectDefinition def = ProjectDefinition.create(); | |||
def.setProperties(props); | |||
assertThat(def.getKey(), is("foo")); | |||
assertThat(def.getKey()).isEqualTo("foo"); | |||
} | |||
@Test | |||
public void testDefaultValues() { | |||
ProjectDefinition def = ProjectDefinition.create(); | |||
assertThat(def.getSourceDirs().size(), is(0)); | |||
assertThat(def.getTestDirs().size(), is(0)); | |||
assertThat(def.getBinaries().size(), is(0)); | |||
assertThat(def.getLibraries().size(), is(0)); | |||
assertThat(def.sources()).isEmpty(); | |||
assertThat(def.tests()).isEmpty(); | |||
} | |||
/** | |||
@@ -93,54 +88,11 @@ public class ProjectDefinitionTest { | |||
@Test | |||
public void shouldTrimPaths() { | |||
ProjectDefinition def = ProjectDefinition.create(); | |||
def.setProperty(ProjectDefinition.SOURCE_DIRS_PROPERTY, "src1, src2 , with whitespace"); | |||
def.setProperty(ProjectDefinition.TEST_DIRS_PROPERTY, "test1, test2 , with whitespace"); | |||
def.setProperty(ProjectDefinition.BINARIES_PROPERTY, "bin1, bin2 , with whitespace"); | |||
def.setProperty(ProjectDefinition.LIBRARIES_PROPERTY, "lib1, lib2 , with whitespace"); | |||
assertFiles(def.getSourceDirs(), "src1", "src2", "with whitespace"); | |||
assertFiles(def.getTestDirs(), "test1", "test2", "with whitespace"); | |||
assertFiles(def.getBinaries(), "bin1", "bin2", "with whitespace"); | |||
assertFiles(def.getLibraries(), "lib1", "lib2", "with whitespace"); | |||
} | |||
@Test | |||
public void shouldAddDirectoriesAsPath() { | |||
ProjectDefinition def = ProjectDefinition.create(); | |||
def.addSourceDirs("src/main/java", "src/main/java2"); | |||
def.addTestDirs("src/test/java"); | |||
def.addTestDirs("src/test/java2"); | |||
def.addBinaryDir("target/classes"); | |||
def.addBinaryDir("target/classes2"); | |||
def.addLibrary("junit.jar"); | |||
def.addLibrary("mockito.jar"); | |||
assertFiles(def.getSourceDirs(), "src/main/java", "src/main/java2"); | |||
assertFiles(def.getTestDirs(), "src/test/java", "src/test/java2"); | |||
assertFiles(def.getBinaries(), "target/classes", "target/classes2"); | |||
assertFiles(def.getLibraries(), "junit.jar", "mockito.jar"); | |||
} | |||
@Test | |||
public void shouldAddDirectories() { | |||
ProjectDefinition def = ProjectDefinition.create(); | |||
def.addSourceDirs(new File("src/main/java"), new File("src/main/java2")); | |||
def.addTestDirs(new File("src/test/java"), new File("src/test/java2")); | |||
def.addBinaryDir(new File("target/classes")); | |||
assertThat(def.getSourceDirs().size(), is(2)); | |||
assertThat(def.getTestDirs().size(), is(2)); | |||
assertThat(def.getBinaries().size(), is(1)); | |||
} | |||
@Test | |||
public void shouldAddFiles() { | |||
ProjectDefinition def = ProjectDefinition.create(); | |||
def.addSourceFiles("src/main/java/foo/Bar.java", "src/main/java/hello/World.java"); | |||
def.addTestFiles("src/test/java/foo/BarTest.java", "src/test/java/hello/WorldTest.java"); | |||
def.setSources("src1", " src2 ", " with whitespace"); | |||
def.setTests("test1"," test2 "," with whitespace"); | |||
assertFiles(def.getSourceFiles(), "src/main/java/foo/Bar.java", "src/main/java/hello/World.java"); | |||
assertFiles(def.getTestFiles(), "src/test/java/foo/BarTest.java", "src/test/java/hello/WorldTest.java"); | |||
assertThat(def.sources()).containsOnly("src1", "src2", "with whitespace"); | |||
assertThat(def.tests()).containsOnly("test1", "test2", "with whitespace"); | |||
} | |||
@Test | |||
@@ -149,91 +101,32 @@ public class ProjectDefinitionTest { | |||
ProjectDefinition child = ProjectDefinition.create(); | |||
root.addSubProject(child); | |||
assertThat(root.getSubProjects().size(), is(1)); | |||
assertThat(child.getSubProjects().size(), is(0)); | |||
assertThat(root.getSubProjects()).hasSize(1); | |||
assertThat(child.getSubProjects()).isEmpty(); | |||
assertThat(root.getParent(), nullValue()); | |||
assertThat(child.getParent(), is(root)); | |||
assertThat(root.getParent()).isNull(); | |||
assertThat(child.getParent()).isEqualTo(root); | |||
} | |||
@Test | |||
public void shouldResetSourceDirs() { | |||
ProjectDefinition root = ProjectDefinition.create(); | |||
root.addSourceDirs("src", "src2/main"); | |||
assertThat(root.getSourceDirs().size(), is(2)); | |||
root.addSources("src", "src2/main"); | |||
assertThat(root.sources()).hasSize(2); | |||
root.resetSourceDirs(); | |||
assertThat(root.getSourceDirs().size(), is(0)); | |||
root.resetSources(); | |||
assertThat(root.sources()).isEmpty(); | |||
} | |||
@Test | |||
public void shouldResetTestDirs() { | |||
ProjectDefinition root = ProjectDefinition.create(); | |||
root.addTestDirs("src", "src2/test"); | |||
assertThat(root.getTestDirs().size(), is(2)); | |||
root.addTests("src", "src2/test"); | |||
assertThat(root.tests()).hasSize(2); | |||
root.resetTestDirs(); | |||
assertThat(root.getTestDirs().size(), is(0)); | |||
root.resetTests(); | |||
assertThat(root.tests()).isEmpty(); | |||
} | |||
@Test | |||
public void shouldResetSourceDirsWhenUsindDeprecatedMethod() throws IOException { | |||
File baseDir = temp.newFolder(); | |||
ProjectDefinition root = ProjectDefinition.create().setBaseDir(baseDir); | |||
File src = new File(baseDir, "src"); | |||
src.mkdir(); | |||
root.addSourceDirs("src"); | |||
assertThat(root.getSourceDirs()).containsOnly("src"); | |||
root.addSourceFiles("foo.java"); | |||
assertThat(root.getSourceDirs()).containsOnly("foo.java"); | |||
} | |||
@Test | |||
public void shouldResetTestDirsWhenUsindDeprecatedMethod() throws IOException { | |||
File baseDir = temp.newFolder(); | |||
ProjectDefinition root = ProjectDefinition.create().setBaseDir(baseDir); | |||
File test = new File(baseDir, "test"); | |||
test.mkdir(); | |||
root.addTestDirs("test"); | |||
assertThat(root.getTestDirs()).containsOnly("test"); | |||
root.addTestFiles("fooTest.java"); | |||
assertThat(root.getTestDirs()).containsOnly("fooTest.java"); | |||
} | |||
@Test | |||
public void shouldResetSourceDirsWhenUsindDeprecatedFileMethod() throws IOException { | |||
File baseDir = temp.newFolder(); | |||
ProjectDefinition root = ProjectDefinition.create().setBaseDir(baseDir); | |||
File src = new File(baseDir, "src"); | |||
src.mkdir(); | |||
root.addSourceDirs("src"); | |||
assertThat(root.getSourceDirs()).containsOnly("src"); | |||
File file = new File(src, "foo.java"); | |||
root.addSourceFiles(file); | |||
assertThat(root.getSourceDirs()).containsOnly(file.getAbsolutePath()); | |||
} | |||
@Test | |||
public void shouldResetTestDirsWhenUsindDeprecatedFileMethod() throws IOException { | |||
File baseDir = temp.newFolder(); | |||
ProjectDefinition root = ProjectDefinition.create().setBaseDir(baseDir); | |||
File test = new File(baseDir, "test"); | |||
test.mkdir(); | |||
root.addTestDirs("test"); | |||
assertThat(root.getTestDirs()).containsOnly("test"); | |||
File file = new File(test, "fooTest.java"); | |||
root.addTestFiles(file); | |||
assertThat(root.getTestDirs()).containsOnly(file.getAbsolutePath()); | |||
} | |||
private static void assertFiles(List<String> paths, String... values) { | |||
assertThat(paths.size(), is(values.length)); | |||
for (int i = 0; i < values.length; i++) { | |||
assertThat(paths.get(i), is(values[i])); | |||
} | |||
} | |||
} |
@@ -333,9 +333,9 @@ public class DefaultIndex extends SonarIndex { | |||
List<String> dirs; | |||
ProjectDefinition projectDef = projectTree.getProjectDefinition(getProject()); | |||
if (isTest) { | |||
dirs = projectDef.getTestDirs(); | |||
dirs = projectDef.tests(); | |||
} else { | |||
dirs = projectDef.getSourceDirs(); | |||
dirs = projectDef.sources(); | |||
} | |||
for (String src : dirs) { | |||
java.io.File dirOrFile = pathResolver.relativeFile(projectDef.getBaseDir(), src); |
@@ -19,34 +19,31 @@ | |||
*/ | |||
package org.sonar.batch.scan.filesystem; | |||
import org.sonar.api.batch.fs.InputFile.Status; | |||
import org.sonar.batch.analysis.DefaultAnalysisMode; | |||
import com.google.common.annotations.VisibleForTesting; | |||
import com.google.common.base.Function; | |||
import com.google.common.collect.Collections2; | |||
import com.google.common.collect.ImmutableList; | |||
import com.google.common.collect.Lists; | |||
import java.io.File; | |||
import java.nio.charset.Charset; | |||
import java.util.ArrayList; | |||
import java.util.Collection; | |||
import java.util.Collections; | |||
import java.util.List; | |||
import java.util.Map; | |||
import javax.annotation.CheckForNull; | |||
import javax.annotation.Nullable; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.sonar.api.CoreProperties; | |||
import org.sonar.api.batch.fs.FilePredicate; | |||
import org.sonar.api.batch.fs.InputFile.Status; | |||
import org.sonar.api.batch.fs.internal.DefaultFileSystem; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.resources.Project; | |||
import org.sonar.api.scan.filesystem.FileQuery; | |||
import org.sonar.api.scan.filesystem.ModuleFileSystem; | |||
import org.sonar.api.utils.MessageException; | |||
import org.sonar.batch.analysis.DefaultAnalysisMode; | |||
/** | |||
* @since 3.5 | |||
@@ -60,7 +57,6 @@ public class DefaultModuleFileSystem extends DefaultFileSystem implements Module | |||
private File buildDir; | |||
private List<File> sourceDirsOrFiles = Lists.newArrayList(); | |||
private List<File> testDirsOrFiles = Lists.newArrayList(); | |||
private List<File> binaryDirs = Lists.newArrayList(); | |||
private ComponentIndexer componentIndexer; | |||
private boolean initialized; | |||
@@ -87,7 +83,6 @@ public class DefaultModuleFileSystem extends DefaultFileSystem implements Module | |||
this.buildDir = initializer.buildDir(); | |||
this.sourceDirsOrFiles = initializer.sources(); | |||
this.testDirsOrFiles = initializer.tests(); | |||
this.binaryDirs = initializer.binaryDirs(); | |||
// filter the files sensors have access to | |||
if (!mode.scanAllFiles()) { | |||
@@ -139,7 +134,7 @@ public class DefaultModuleFileSystem extends DefaultFileSystem implements Module | |||
@Override | |||
public List<File> binaryDirs() { | |||
return binaryDirs; | |||
return Collections.emptyList(); | |||
} | |||
@Override |
@@ -50,7 +50,6 @@ public class FileSystemLogger { | |||
logDir(logger, "Working dir: ", fs.workDir()); | |||
logPaths(logger, "Source paths: ", fs.baseDir(), fs.sources()); | |||
logPaths(logger, "Test paths: ", fs.baseDir(), fs.tests()); | |||
logPaths(logger, "Binary dirs: ", fs.baseDir(), fs.binaryDirs()); | |||
logEncoding(logger, fs.encoding()); | |||
} | |||
@@ -42,13 +42,11 @@ public class ModuleFileSystemInitializer { | |||
private File buildDir; | |||
private List<File> sourceDirsOrFiles = Lists.newArrayList(); | |||
private List<File> testDirsOrFiles = Lists.newArrayList(); | |||
private List<File> binaryDirs = Lists.newArrayList(); | |||
public ModuleFileSystemInitializer(ProjectDefinition module, TempFolder tempUtils, PathResolver pathResolver) { | |||
baseDir = module.getBaseDir(); | |||
buildDir = module.getBuildDir(); | |||
initWorkingDir(module, tempUtils); | |||
initBinaryDirs(module, pathResolver); | |||
initSources(module, pathResolver); | |||
initTests(module, pathResolver); | |||
} | |||
@@ -84,13 +82,6 @@ public class ModuleFileSystemInitializer { | |||
} | |||
} | |||
private void initBinaryDirs(ProjectDefinition module, PathResolver pathResolver) { | |||
for (String path : module.getBinaries()) { | |||
File dir = pathResolver.relativeFile(module.getBaseDir(), path); | |||
binaryDirs.add(dir); | |||
} | |||
} | |||
File baseDir() { | |||
return baseDir; | |||
} | |||
@@ -112,11 +103,4 @@ public class ModuleFileSystemInitializer { | |||
return testDirsOrFiles; | |||
} | |||
/** | |||
* @deprecated since 4.5.1 use SonarQube Java specific API | |||
*/ | |||
@Deprecated | |||
List<File> binaryDirs() { | |||
return binaryDirs; | |||
} | |||
} |
@@ -58,7 +58,7 @@ public class ProjectReactorBuilderTest { | |||
assertThat(projectDefinition.getName()).isEqualTo("Foo Project"); | |||
assertThat(projectDefinition.getVersion()).isEqualTo("1.0-SNAPSHOT"); | |||
assertThat(projectDefinition.getDescription()).isEqualTo("Description of Foo Project"); | |||
assertThat(projectDefinition.getSourceDirs()).contains("sources"); | |||
assertThat(projectDefinition.sources()).contains("sources"); | |||
} | |||
@Test | |||
@@ -125,8 +125,8 @@ public class ProjectReactorBuilderTest { | |||
assertThat(rootProject.getVersion()).isEqualTo("1.0-SNAPSHOT"); | |||
assertThat(rootProject.getDescription()).isEqualTo("Description of Foo Project"); | |||
// root project must not contain some properties - even if they are defined in the root properties file | |||
assertThat(rootProject.getSourceDirs().contains("sources")).isFalse(); | |||
assertThat(rootProject.getTestDirs().contains("tests")).isFalse(); | |||
assertThat(rootProject.sources().contains("sources")).isFalse(); | |||
assertThat(rootProject.tests().contains("tests")).isFalse(); | |||
// and module properties must have been cleaned | |||
assertThat(rootProject.properties().get("module1.sonar.projectKey")).isNull(); | |||
assertThat(rootProject.properties().get("module2.sonar.projectKey")).isNull(); | |||
@@ -148,9 +148,8 @@ public class ProjectReactorBuilderTest { | |||
assertThat(module1.getVersion()).isEqualTo("1.0-SNAPSHOT"); | |||
// Description should not be inherited from parent if not set | |||
assertThat(module1.getDescription()).isNull(); | |||
assertThat(module1.getSourceDirs()).contains("sources"); | |||
assertThat(module1.getTestDirs()).contains("tests"); | |||
assertThat(module1.getBinaries()).contains("target/classes"); | |||
assertThat(module1.sources()).contains("sources"); | |||
assertThat(module1.tests()).contains("tests"); | |||
// and module properties must have been cleaned | |||
assertThat(module1.properties().get("module1.sonar.projectKey")).isNull(); | |||
assertThat(module1.properties().get("module2.sonar.projectKey")).isNull(); | |||
@@ -167,9 +166,8 @@ public class ProjectReactorBuilderTest { | |||
assertThat(module2.getName()).isEqualTo("Foo Module 2"); | |||
assertThat(module2.getVersion()).isEqualTo("1.0-SNAPSHOT"); | |||
assertThat(module2.getDescription()).isEqualTo("Description of Module 2"); | |||
assertThat(module2.getSourceDirs()).contains("src"); | |||
assertThat(module2.getTestDirs()).contains("tests"); | |||
assertThat(module2.getBinaries()).contains("target/classes"); | |||
assertThat(module2.sources()).contains("src"); | |||
assertThat(module2.tests()).contains("tests"); | |||
// and module properties must have been cleaned | |||
assertThat(module2.properties().get("module1.sonar.projectKey")).isNull(); | |||
assertThat(module2.properties().get("module2.sonar.projectKey")).isNull(); | |||
@@ -216,7 +214,7 @@ public class ProjectReactorBuilderTest { | |||
// Module 1 | |||
ProjectDefinition module1 = modules.get(0); | |||
assertThat(module1.getBaseDir().getCanonicalFile()).isEqualTo(getResource(this.getClass(), "multi-language-definitions-all-in-root")); | |||
assertThat(module1.getSourceDirs()).contains("src/main/java"); | |||
assertThat(module1.sources()).contains("src/main/java"); | |||
// and module properties must have been cleaned | |||
assertThat(module1.getWorkDir().getCanonicalFile()) | |||
.isEqualTo(new File(getResource(this.getClass(), "multi-language-definitions-all-in-root"), ".sonar/example_java-module")); | |||
@@ -224,7 +222,7 @@ public class ProjectReactorBuilderTest { | |||
// Module 2 | |||
ProjectDefinition module2 = modules.get(1); | |||
assertThat(module2.getBaseDir().getCanonicalFile()).isEqualTo(getResource(this.getClass(), "multi-language-definitions-all-in-root")); | |||
assertThat(module2.getSourceDirs()).contains("src/main/groovy"); | |||
assertThat(module2.sources()).contains("src/main/groovy"); | |||
// and module properties must have been cleaned | |||
assertThat(module2.getWorkDir().getCanonicalFile()) | |||
.isEqualTo(new File(getResource(this.getClass(), "multi-language-definitions-all-in-root"), ".sonar/example_groovy-module")); | |||
@@ -559,8 +557,8 @@ public class ProjectReactorBuilderTest { | |||
assertThat(rootProject.getVersion()).isEqualTo("1.0-SNAPSHOT"); | |||
assertThat(rootProject.getDescription()).isEqualTo("Description of Foo Project"); | |||
// root project must not contain some properties - even if they are defined in the root properties file | |||
assertThat(rootProject.getSourceDirs().contains("sources")).isFalse(); | |||
assertThat(rootProject.getTestDirs().contains("tests")).isFalse(); | |||
assertThat(rootProject.sources().contains("sources")).isFalse(); | |||
assertThat(rootProject.tests().contains("tests")).isFalse(); | |||
// and module properties must have been cleaned | |||
assertThat(rootProject.properties().get("module1.sonar.projectKey")).isNull(); | |||
assertThat(rootProject.properties().get("module2.sonar.projectKey")).isNull(); | |||
@@ -582,9 +580,8 @@ public class ProjectReactorBuilderTest { | |||
assertThat(module1.getVersion()).isEqualTo("1.0-SNAPSHOT"); | |||
// Description should not be inherited from parent if not set | |||
assertThat(module1.getDescription()).isNull(); | |||
assertThat(module1.getSourceDirs()).contains("sources"); | |||
assertThat(module1.getTestDirs()).contains("tests"); | |||
assertThat(module1.getBinaries()).contains("target/classes"); | |||
assertThat(module1.sources()).contains("sources"); | |||
assertThat(module1.tests()).contains("tests"); | |||
// and module properties must have been cleaned | |||
assertThat(module1.properties().get("module1.sonar.projectKey")).isNull(); | |||
assertThat(module1.properties().get("module2.sonar.projectKey")).isNull(); | |||
@@ -601,9 +598,8 @@ public class ProjectReactorBuilderTest { | |||
assertThat(module1Feature.getName()).isEqualTo("Foo Module 1 Feature"); | |||
assertThat(module1Feature.getVersion()).isEqualTo("1.0-SNAPSHOT"); | |||
assertThat(module1Feature.getDescription()).isEqualTo("Description of Module 1 Feature"); | |||
assertThat(module1Feature.getSourceDirs()).contains("src"); | |||
assertThat(module1Feature.getTestDirs()).contains("tests"); | |||
assertThat(module1Feature.getBinaries()).contains("target/classes"); | |||
assertThat(module1Feature.sources()).contains("src"); | |||
assertThat(module1Feature.tests()).contains("tests"); | |||
// and module properties must have been cleaned | |||
assertThat(module1Feature.properties().get("module1.sonar.projectKey")).isNull(); | |||
assertThat(module1Feature.properties().get("module2.sonar.projectKey")).isNull(); |
@@ -19,11 +19,12 @@ | |||
*/ | |||
package org.sonar.batch.scan.filesystem; | |||
import org.sonar.api.batch.fs.InputFile.Status; | |||
import org.junit.Before; | |||
import org.sonar.batch.analysis.DefaultAnalysisMode; | |||
import com.google.common.collect.Lists; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import java.nio.charset.Charset; | |||
import java.util.Arrays; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
@@ -31,14 +32,11 @@ import org.junit.rules.TemporaryFolder; | |||
import org.mockito.Mockito; | |||
import org.sonar.api.CoreProperties; | |||
import org.sonar.api.batch.fs.InputFile; | |||
import org.sonar.api.batch.fs.InputFile.Status; | |||
import org.sonar.api.batch.fs.internal.DefaultInputFile; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.resources.Project; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import java.nio.charset.Charset; | |||
import java.util.Arrays; | |||
import org.sonar.batch.analysis.DefaultAnalysisMode; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.mockito.Mockito.mock; | |||
@@ -146,7 +144,6 @@ public class DefaultModuleFileSystemTest { | |||
when(initializer.baseDir()).thenReturn(basedir); | |||
when(initializer.buildDir()).thenReturn(buildDir); | |||
when(initializer.workingDir()).thenReturn(workingDir); | |||
when(initializer.binaryDirs()).thenReturn(Arrays.asList(new File(basedir, "target/classes"))); | |||
File javaSrc = new File(basedir, "src/main/java"); | |||
javaSrc.mkdirs(); | |||
File groovySrc = new File(basedir, "src/main/groovy"); | |||
@@ -164,7 +161,6 @@ public class DefaultModuleFileSystemTest { | |||
assertThat(fs.buildDir().getCanonicalPath()).isEqualTo(buildDir.getCanonicalPath()); | |||
assertThat(fs.sourceDirs()).hasSize(2); | |||
assertThat(fs.testDirs()).hasSize(1); | |||
assertThat(fs.binaryDirs()).hasSize(1); | |||
} | |||
@Test |
@@ -69,9 +69,8 @@ public class ModuleFileSystemInitializerTest { | |||
ProjectDefinition project = ProjectDefinition.create() | |||
.setBaseDir(baseDir) | |||
.setBuildDir(buildDir) | |||
.addSourceDirs("src/main/java", "src/main/unknown") | |||
.addTestDirs("src/test/java", "src/test/unknown") | |||
.addBinaryDir("target/classes"); | |||
.addSources("src/main/java", "src/main/unknown") | |||
.addTests("src/test/java", "src/test/unknown"); | |||
ModuleFileSystemInitializer initializer = new ModuleFileSystemInitializer(project, mock(TempFolder.class), pathResolver); | |||
@@ -81,8 +80,6 @@ public class ModuleFileSystemInitializerTest { | |||
assertThat(path(initializer.sources().get(0))).endsWith("src/main/java"); | |||
assertThat(initializer.tests()).hasSize(1); | |||
assertThat(path(initializer.tests().get(0))).endsWith("src/test/java"); | |||
assertThat(initializer.binaryDirs()).hasSize(1); | |||
assertThat(path(initializer.binaryDirs().get(0))).endsWith("target/classes"); | |||
} | |||
private String path(File f) throws IOException { |