aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionDictionnary.java5
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/phases/SensorsExecutor.java27
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java11
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java9
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileIndex.java21
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java17
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/batch/SquidUtils.java (renamed from sonar-plugin-api/src/main/java/org/sonar/api/batch/SquidUtils.java)3
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/resources/JavaFile.java (renamed from sonar-plugin-api/src/main/java/org/sonar/api/resources/JavaFile.java)2
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/resources/JavaPackage.java (renamed from sonar-plugin-api/src/main/java/org/sonar/api/resources/JavaPackage.java)0
-rw-r--r--sonar-deprecated/src/test/java/org/sonar/api/batch/SquidUtilsTest.java (renamed from sonar-plugin-api/src/test/java/org/sonar/api/batch/SquidUtilsTest.java)0
-rw-r--r--sonar-deprecated/src/test/java/org/sonar/api/resources/JavaFileTest.java (renamed from sonar-plugin-api/src/test/java/org/sonar/api/resources/JavaFileTest.java)9
-rw-r--r--sonar-deprecated/src/test/java/org/sonar/api/resources/JavaPackageTest.java (renamed from sonar-plugin-api/src/test/java/org/sonar/api/resources/JavaPackageTest.java)10
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/Directory.java3
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/Resource.java17
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/InputDir.java70
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/ModuleFileSystem.java7
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/internal/DefaultInputDir.java131
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/checks/NoSonarFilterTest.java6
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/measures/AverageFormulaTest.java20
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/measures/SumChildDistributionFormulaTest.java21
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceUtilsTest.java61
21 files changed, 77 insertions, 373 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionDictionnary.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionDictionnary.java
index 3779471971c..6e246f19f0f 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionDictionnary.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionDictionnary.java
@@ -23,7 +23,6 @@ import com.google.common.collect.Lists;
import org.apache.commons.lang.ClassUtils;
import org.sonar.api.BatchExtension;
import org.sonar.api.batch.CheckProject;
-import org.sonar.api.batch.Sensor;
import org.sonar.api.platform.ComponentContainer;
import org.sonar.api.resources.Project;
@@ -59,9 +58,7 @@ public class BatchExtensionDictionnary extends org.sonar.api.batch.BatchExtensio
private boolean shouldKeep(Class type, Object extension, Project project, ExtensionMatcher matcher) {
boolean keep = ClassUtils.isAssignable(extension.getClass(), type) && (matcher == null || matcher.accept(extension));
- // For Sensors we no longer filter on shouldExecuteOnProject
- if (keep && project != null && ClassUtils.isAssignable(extension.getClass(), CheckProject.class)
- && !ClassUtils.isAssignable(extension.getClass(), Sensor.class)) {
+ if (keep && project != null && ClassUtils.isAssignable(extension.getClass(), CheckProject.class)) {
keep = ((CheckProject) extension).shouldExecuteOnProject(project);
}
return keep;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/SensorsExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/phases/SensorsExecutor.java
index 249a492a19a..1fb8949841e 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/phases/SensorsExecutor.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/phases/SensorsExecutor.java
@@ -23,19 +23,16 @@ import com.google.common.collect.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.BatchComponent;
-import org.sonar.api.CoreProperties;
import org.sonar.api.batch.Sensor;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.batch.maven.DependsUponMavenPlugin;
import org.sonar.api.batch.maven.MavenPluginHandler;
import org.sonar.api.database.DatabaseSession;
-import org.sonar.api.resources.Language;
import org.sonar.api.resources.Project;
import org.sonar.api.utils.TimeProfiler;
import org.sonar.batch.bootstrap.BatchExtensionDictionnary;
import org.sonar.batch.events.EventBus;
import org.sonar.batch.scan.filesystem.DefaultModuleFileSystem;
-import org.sonar.batch.scan.language.DefaultModuleLanguages;
import org.sonar.batch.scan.maven.MavenPluginExecutor;
import java.util.Collection;
@@ -50,10 +47,9 @@ public class SensorsExecutor implements BatchComponent {
private BatchExtensionDictionnary selector;
private final DatabaseSession session;
private final SensorMatcher sensorMatcher;
- private final DefaultModuleLanguages moduleLanguages;
public SensorsExecutor(BatchExtensionDictionnary selector, Project project, DefaultModuleFileSystem fs, MavenPluginExecutor mavenExecutor, EventBus eventBus,
- DatabaseSession session, SensorMatcher sensorMatcher, DefaultModuleLanguages moduleLanguages) {
+ DatabaseSession session, SensorMatcher sensorMatcher) {
this.selector = selector;
this.mavenExecutor = mavenExecutor;
this.eventBus = eventBus;
@@ -61,7 +57,6 @@ public class SensorsExecutor implements BatchComponent {
this.fs = fs;
this.session = session;
this.sensorMatcher = sensorMatcher;
- this.moduleLanguages = moduleLanguages;
}
public void execute(SensorContext context) {
@@ -72,25 +67,7 @@ public class SensorsExecutor implements BatchComponent {
// SONAR-2965 In case the sensor takes too much time we close the session to not face a timeout
session.commitAndClose();
- if (sensor.shouldExecuteOnProject(module)) {
- executeSensor(context, sensor);
- } else {
- // For backward compatibility try to execute Sensor for each language until it is executed once (or never)
- String oldLanguageKey = module.getLanguageKey();
- Language oldLanguage = module.getLanguage();
- for (Language language : moduleLanguages.languages()) {
- module.setLanguage(language);
- module.getConfiguration().setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, language.getKey());
- if (sensor.shouldExecuteOnProject(module)) {
- LOG.warn("Sensor {} should be updated to not depends on deprecated Project::getLanguage or Project::getLanguageKey", sensor);
- executeSensor(context, sensor);
- break;
- }
- }
- // Restore module language
- module.setLanguage(oldLanguage);
- module.getConfiguration().setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, oldLanguageKey);
- }
+ executeSensor(context, sensor);
}
eventBus.fireEvent(new SensorsPhaseEvent(Lists.newArrayList(sensors), false));
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java
index 8070a0a0574..bf8696b057e 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java
@@ -27,8 +27,6 @@ import org.sonar.api.CoreProperties;
import org.sonar.api.batch.SonarIndex;
import org.sonar.api.config.Settings;
import org.sonar.api.resources.File;
-import org.sonar.api.resources.Java;
-import org.sonar.api.resources.JavaFile;
import org.sonar.api.resources.Languages;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
@@ -74,15 +72,14 @@ public class ComponentIndexer implements BatchComponent {
for (InputFile inputFile : inputFiles) {
String languageKey = inputFile.attribute(InputFile.ATTRIBUTE_LANGUAGE);
boolean unitTest = InputFile.TYPE_TEST.equals(inputFile.attribute(InputFile.ATTRIBUTE_TYPE));
- Resource sonarFile;
String pathFromSourceDir = inputFile.attribute(DefaultInputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH);
if (pathFromSourceDir == null) {
pathFromSourceDir = inputFile.path();
}
- if (Java.KEY.equals(languageKey)) {
- sonarFile = JavaFile.create(inputFile.path(), pathFromSourceDir, unitTest);
- } else {
- sonarFile = File.create(inputFile.path(), pathFromSourceDir, languages.get(languageKey), unitTest);
+ Resource sonarFile = File.create(inputFile.path(), pathFromSourceDir, languages.get(languageKey), unitTest);
+ String deprecatedKey = inputFile.attribute(DefaultInputFile.ATTRIBUTE_COMPONENT_DEPRECATED_KEY);
+ if (deprecatedKey != null) {
+ sonarFile.setDeprecatedKey(deprecatedKey);
}
if (sonarFile != null) {
moduleLanguages.addLanguage(languageKey);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java
index f4e10352caf..d27c313175b 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java
@@ -29,7 +29,6 @@ import org.sonar.api.CoreProperties;
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.InputDir;
import org.sonar.api.scan.filesystem.InputFile;
import org.sonar.api.scan.filesystem.ModuleFileSystem;
import org.sonar.api.scan.filesystem.internal.InputFiles;
@@ -191,14 +190,6 @@ public class DefaultModuleFileSystem implements ModuleFileSystem {
}
@Override
- public InputDir inputDir(File ioFile) {
- if (!ioFile.isDirectory()) {
- throw new SonarException(ioFile.getAbsolutePath() + "is not a directory");
- }
- return index.inputDir(this, ioFile);
- }
-
- @Override
public List<File> files(FileQuery query) {
return InputFiles.toFiles(inputFiles(query));
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileIndex.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileIndex.java
index 4c037133b8f..226f84a198d 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileIndex.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileIndex.java
@@ -20,7 +20,6 @@
package org.sonar.batch.scan.filesystem;
import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.filefilter.FileFilterUtils;
import org.apache.commons.io.filefilter.HiddenFileFilter;
import org.apache.commons.io.filefilter.IOFileFilter;
@@ -28,12 +27,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.BatchComponent;
import org.sonar.api.resources.Project;
-import org.sonar.api.scan.filesystem.InputDir;
import org.sonar.api.scan.filesystem.InputFile;
-import org.sonar.api.scan.filesystem.PathResolver;
-import org.sonar.api.scan.filesystem.internal.DefaultInputDir;
import org.sonar.api.scan.filesystem.InputFileFilter;
-import org.sonar.api.utils.PathUtils;
+import org.sonar.api.scan.filesystem.PathResolver;
import org.sonar.api.utils.SonarException;
import java.io.File;
@@ -81,7 +77,7 @@ public class FileIndex implements BatchComponent {
private final InputFileBuilderFactory inputFileBuilderFactory;
public FileIndex(List<InputFileFilter> filters, ExclusionFilters exclusionFilters, InputFileBuilderFactory inputFileBuilderFactory,
- InputFileCache cache, PathResolver pathResolver, Project project) {
+ InputFileCache cache, PathResolver pathResolver, Project project) {
this.filters = filters;
this.exclusionFilters = exclusionFilters;
this.inputFileBuilderFactory = inputFileBuilderFactory;
@@ -127,7 +123,7 @@ public class FileIndex implements BatchComponent {
if (path == null) {
LoggerFactory.getLogger(getClass()).warn(String.format(
"File '%s' is not declared in module basedir %s", sourceFile.getAbsoluteFile(), fileSystem.baseDir()
- ));
+ ));
} else {
if (exclusionFilters.accept(sourceFile, path, type)) {
indexFile(inputFileBuilder, fileSystem, progress, sourceFile, path, type);
@@ -145,14 +141,6 @@ public class FileIndex implements BatchComponent {
return fileCache.byPath(fileSystem.moduleKey(), path);
}
- InputDir inputDir(DefaultModuleFileSystem fileSystem, File ioFile) {
- String path = computeFilePath(fileSystem, ioFile);
- DefaultInputDir inputDir = new DefaultInputDir(FilenameUtils.normalize(ioFile.getAbsolutePath(), true), path);
- String resourceKey = PathUtils.sanitize(path);
- inputDir.setKey(module.getEffectiveKey() + ":" + resourceKey);
- return inputDir;
- }
-
private void indexDirectory(InputFileBuilder inputFileBuilder, DefaultModuleFileSystem fileSystem, Progress status, File dirToIndex) {
Collection<File> files = FileUtils.listFiles(dirToIndex, FILE_FILTER, DIR_FILTER);
for (File sourceFile : files) {
@@ -160,7 +148,7 @@ public class FileIndex implements BatchComponent {
if (path == null) {
LoggerFactory.getLogger(getClass()).warn(String.format(
"File '%s' is not declared in module basedir %s", sourceFile.getAbsoluteFile(), fileSystem.baseDir()
- ));
+ ));
} else {
if (exclusionFilters.accept(sourceFile, path, InputFile.TYPE_MAIN)) {
indexFile(inputFileBuilder, fileSystem, status, sourceFile, path, InputFile.TYPE_MAIN);
@@ -184,7 +172,6 @@ public class FileIndex implements BatchComponent {
return pathResolver.relativePath(fileSystem.baseDir(), file);
}
-
private boolean accept(InputFile inputFile) {
// InputFileFilter extensions
for (InputFileFilter filter : filters) {
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java
index 919b3b3e74e..5ca14958749 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java
@@ -33,7 +33,6 @@ import org.sonar.api.batch.SonarIndex;
import org.sonar.api.config.Settings;
import org.sonar.api.resources.AbstractLanguage;
import org.sonar.api.resources.Java;
-import org.sonar.api.resources.JavaFile;
import org.sonar.api.resources.Languages;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Qualifiers;
@@ -101,13 +100,13 @@ public class ComponentIndexerTest {
mock(ResourceDao.class), mock(InputFileCache.class));
indexer.execute(fs);
- verify(sonarIndex).index(JavaFile.create("src/main/java/foo/bar/Foo.java", "foo/bar/Foo.java", false));
- verify(sonarIndex).index(JavaFile.create("src/main/java2/foo/bar/Foo.java", "foo/bar/Foo.java", false));
- verify(sonarIndex).index(argThat(new ArgumentMatcher<JavaFile>() {
+ verify(sonarIndex).index(org.sonar.api.resources.File.create("src/main/java/foo/bar/Foo.java", "foo/bar/Foo.java", Java.INSTANCE, false));
+ verify(sonarIndex).index(org.sonar.api.resources.File.create("src/main/java2/foo/bar/Foo.java", "foo/bar/Foo.java", Java.INSTANCE, false));
+ verify(sonarIndex).index(argThat(new ArgumentMatcher<org.sonar.api.resources.File>() {
@Override
public boolean matches(Object arg0) {
- JavaFile javaFile = (JavaFile) arg0;
- return javaFile.getKey().equals("src/test/java/foo/bar/FooTest.java") && javaFile.getDeprecatedKey().equals("foo.bar.FooTest")
+ org.sonar.api.resources.File javaFile = (org.sonar.api.resources.File) arg0;
+ return javaFile.getKey().equals("src/test/java/foo/bar/FooTest.java")
&& javaFile.getPath().equals("src/test/java/foo/bar/FooTest.java")
&& javaFile.getQualifier().equals(Qualifiers.UNIT_TEST_FILE);
}
@@ -142,7 +141,7 @@ public class ComponentIndexerTest {
mock(ResourceDao.class), mock(InputFileCache.class));
indexer.execute(fs);
- Resource sonarFile = JavaFile.create("src/main/java/foo/bar/Foo.java", "foo/bar/Foo.java", false);
+ Resource sonarFile = org.sonar.api.resources.File.create("src/main/java/foo/bar/Foo.java", "foo/bar/Foo.java", Java.INSTANCE, false);
verify(sonarIndex).index(sonarFile);
verify(sonarIndex).setSource(sonarFile, "sample code");
}
@@ -184,7 +183,7 @@ public class ComponentIndexerTest {
mock(ResourceDao.class), mock(InputFileCache.class));
indexer.execute(fs);
- Resource sonarFile = JavaFile.create("src/main/java/foo/bar/Foo.java", "foo/bar/Foo.java", false);
+ Resource sonarFile = org.sonar.api.resources.File.create("src/main/java/foo/bar/Foo.java", "foo/bar/Foo.java", Java.INSTANCE, false);
verify(sonarIndex).setSource(eq(sonarFile), argThat(new ArgumentMatcher<String>() {
@Override
@@ -212,7 +211,7 @@ public class ComponentIndexerTest {
mock(ResourceDao.class), mock(InputFileCache.class));
indexer.execute(fs);
- Resource sonarFile = JavaFile.create("/src/main/java/foo/bar/Foo.java", "foo/bar/Foo.java", false);
+ Resource sonarFile = org.sonar.api.resources.File.create("/src/main/java/foo/bar/Foo.java", "foo/bar/Foo.java", Java.INSTANCE, false);
verify(sonarIndex).setSource(eq(sonarFile), argThat(new ArgumentMatcher<String>() {
@Override
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SquidUtils.java b/sonar-deprecated/src/main/java/org/sonar/api/batch/SquidUtils.java
index 3a280e2b792..b8381af2819 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SquidUtils.java
+++ b/sonar-deprecated/src/main/java/org/sonar/api/batch/SquidUtils.java
@@ -21,7 +21,6 @@ package org.sonar.api.batch;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.StringUtils;
-import org.sonar.api.resources.Directory;
import org.sonar.api.resources.JavaFile;
import org.sonar.api.resources.JavaPackage;
@@ -58,7 +57,7 @@ public final class SquidUtils {
*/
@Deprecated
public static JavaPackage convertJavaPackageKeyFromSquidFormat(String key) {
- return new Directory(key);
+ return new JavaPackage(key);
}
public static String convertToSquidKeyFormat(JavaFile file) {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/JavaFile.java b/sonar-deprecated/src/main/java/org/sonar/api/resources/JavaFile.java
index ecc675b5a6b..4bb59509364 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/JavaFile.java
+++ b/sonar-deprecated/src/main/java/org/sonar/api/resources/JavaFile.java
@@ -211,7 +211,7 @@ public class JavaFile extends Resource {
String normalizedPath = normalize(relativePathFromBasedir);
javaFile.setKey(normalizedPath);
javaFile.setPath(normalizedPath);
- javaFile.parent = new Directory();
+ javaFile.parent = new JavaPackage();
String directoryPath;
if (normalizedPath.contains(Directory.SEPARATOR)) {
directoryPath = StringUtils.substringBeforeLast(normalizedPath, Directory.SEPARATOR);
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/JavaPackage.java b/sonar-deprecated/src/main/java/org/sonar/api/resources/JavaPackage.java
index 356cf58a14e..356cf58a14e 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/JavaPackage.java
+++ b/sonar-deprecated/src/main/java/org/sonar/api/resources/JavaPackage.java
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/SquidUtilsTest.java b/sonar-deprecated/src/test/java/org/sonar/api/batch/SquidUtilsTest.java
index 7313c4ca330..7313c4ca330 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/SquidUtilsTest.java
+++ b/sonar-deprecated/src/test/java/org/sonar/api/batch/SquidUtilsTest.java
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/JavaFileTest.java b/sonar-deprecated/src/test/java/org/sonar/api/resources/JavaFileTest.java
index f61bdba8e31..619dfff794d 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/JavaFileTest.java
+++ b/sonar-deprecated/src/test/java/org/sonar/api/resources/JavaFileTest.java
@@ -157,15 +157,6 @@ public class JavaFileTest {
}
@Test
- public void javaFilesAreEquivalentToFiles() {
- JavaFile javaFile = new JavaFile("foo");
- javaFile.setKey("someKey");
- org.sonar.api.resources.File file = new org.sonar.api.resources.File("bar");
- file.setKey("someKey");
- assertThat(javaFile).isEqualTo(file);
- }
-
- @Test
public void oneLevelPackage() {
JavaFile clazz = new JavaFile("onelevel.MyFile");
assertEquals("onelevel.MyFile", clazz.getDeprecatedKey());
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/JavaPackageTest.java b/sonar-deprecated/src/test/java/org/sonar/api/resources/JavaPackageTest.java
index f74b95d330b..9210a95ce5c 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/JavaPackageTest.java
+++ b/sonar-deprecated/src/test/java/org/sonar/api/resources/JavaPackageTest.java
@@ -21,7 +21,6 @@ package org.sonar.api.resources;
import org.junit.Test;
-import static org.fest.assertions.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -56,13 +55,4 @@ public class JavaPackageTest {
assertFalse(pac.matchFilePattern("**"));
}
- @Test
- public void packagesAreEquivalentToDirectories() {
- JavaPackage pac = new JavaPackage();
- pac.setKey("someKey");
- Directory dir = new Directory();
- dir.setKey("someKey");
- assertThat(pac).isEqualTo(dir);
- }
-
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Directory.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Directory.java
index d916dcec556..d9c2eb06d61 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Directory.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Directory.java
@@ -29,9 +29,8 @@ import javax.annotation.CheckForNull;
/**
* @since 1.10
- * Extends JavaPackage to allow smooth migration from JavaPackage to Directory
*/
-public class Directory extends JavaPackage {
+public class Directory extends Resource {
public static final String SEPARATOR = "/";
public static final String ROOT = "[root]";
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Resource.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Resource.java
index 958f2246ce9..871fcb60a56 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Resource.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Resource.java
@@ -285,10 +285,7 @@ public abstract class Resource implements Serializable {
if (o == null) {
return false;
}
- if (getClass() != o.getClass()
- // JavaPackage and Directory are considered equivalent since 4.2
- // JavaFile and File are considered equivalent since 4.2
- && !isEquivalentTo(o)) {
+ if (getClass() != o.getClass()) {
return false;
}
@@ -300,18 +297,6 @@ public abstract class Resource implements Serializable {
}
}
- private boolean isPackageOrDirectory(Object o) {
- return o instanceof JavaPackage;
- }
-
- private boolean isJavaFileOrFile(Object o) {
- return o instanceof JavaFile || o instanceof File;
- }
-
- private boolean isEquivalentTo(Object o) {
- return isPackageOrDirectory(this) && isPackageOrDirectory(o) || isJavaFileOrFile(this) && isJavaFileOrFile(o);
- }
-
@Override
public int hashCode() {
return key != null ? key.hashCode() : deprecatedKey.hashCode();
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/InputDir.java b/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/InputDir.java
deleted file mode 100644
index ae755fc7ab0..00000000000
--- a/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/InputDir.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.api.scan.filesystem;
-
-import javax.annotation.CheckForNull;
-
-import java.io.File;
-import java.io.Serializable;
-import java.util.Map;
-
-/**
- * @since 4.2
- */
-public interface InputDir extends Serializable {
-
- /**
- * Path is relative from module base directory. Path is unique and identifies file
- * within given <code>{@link org.sonar.api.scan.filesystem.ModuleFileSystem}</code>.
- * File separator is the forward slash ('/'), even on MSWindows.
- * <p/>
- * Returns <code>src/main/java/com</code> if module base dir is
- * <code>/absolute/path/to/module</code> and if directory is
- * <code>/absolute/path/to/module/src/main/java/com</code>.
- * <p/>
- * Returned path is never null.
- */
- String path();
-
- /**
- * Not-null canonical path. File separator is forward slash ('/'), even on MSWindows.
- */
- String absolutePath();
-
- File file();
-
- /**
- * Not-null directory name
- */
- String name();
-
- /**
- * Does the given attribute have the given value ?
- */
- boolean has(String attribute, String value);
-
- /**
- * See list of attribute keys in constants starting with ATTRIBUTE_.
- */
- @CheckForNull
- String attribute(String key);
-
- Map<String, String> attributes();
-}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/ModuleFileSystem.java b/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/ModuleFileSystem.java
index 9ab95321f14..9ea6ec091e9 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/ModuleFileSystem.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/ModuleFileSystem.java
@@ -94,13 +94,6 @@ public interface ModuleFileSystem extends BatchComponent {
InputFile inputFile(File ioFile);
/**
- * Search for input directory corresponding to the given java.io.File.
- * @since 4.2
- */
- @CheckForNull
- InputDir inputDir(File ioFile);
-
- /**
* Default charset for files of the module. If it's not defined, then
* return the platform default charset. When trying to read an input file it is better to rely on
* {@link InputFile#encoding()} as encoding may be different for each file.
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/internal/DefaultInputDir.java b/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/internal/DefaultInputDir.java
deleted file mode 100644
index 3789f0c5759..00000000000
--- a/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/internal/DefaultInputDir.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.api.scan.filesystem.internal;
-
-import com.google.common.collect.Maps;
-import org.apache.commons.io.FilenameUtils;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.scan.filesystem.InputDir;
-import org.sonar.api.utils.PathUtils;
-
-import javax.annotation.CheckForNull;
-
-import java.io.File;
-import java.util.Map;
-
-/**
- * PLUGINS MUST NOT USE THIS CLASS, EVEN FOR UNIT TESTING.
- *
- * @since 4.2
- */
-public class DefaultInputDir implements InputDir {
-
- /**
- * We're not sure that this is the correct way, so not in API yet.
- */
- public static final String ATTRIBUTE_COMPONENT_KEY = "CMP_KEY";
-
- private final String absolutePath;
- private final String path;
- private final Map<String, String> attributes;
-
- private DefaultInputDir(File file, String path, Map<String, String> attributes) {
- this.absolutePath = PathUtils.canonicalPath(file);
- this.path = FilenameUtils.separatorsToUnix(path);
- this.attributes = attributes;
- }
-
- public DefaultInputDir(String absolutePath, String path) {
- this.absolutePath = absolutePath;
- this.path = path;
- this.attributes = Maps.newHashMap();
- }
-
- /**
- * Plugins must not build their own instances of {@link InputDir}.
- * {@link org.sonar.api.scan.filesystem.ModuleFileSystem} must be used to search for inputDir.
- */
- public static DefaultInputDir create(File file, String path, Map<String, String> attributes) {
- return new DefaultInputDir(file, path, attributes);
- }
-
- @Override
- public String path() {
- return path;
- }
-
- @Override
- public String absolutePath() {
- return absolutePath;
- }
-
- @Override
- public File file() {
- return new File(absolutePath);
- }
-
- @Override
- public String name() {
- return path();
- }
-
- @Override
- public boolean has(String attribute, String value) {
- return StringUtils.equals(attributes.get(attribute), value);
- }
-
- @Override
- @CheckForNull
- public String attribute(String key) {
- return attributes.get(key);
- }
-
- @Override
- public Map<String, String> attributes() {
- return attributes;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- DefaultInputDir other = (DefaultInputDir) o;
- return absolutePath.equals(other.absolutePath);
- }
-
- @Override
- public int hashCode() {
- return absolutePath.hashCode();
- }
-
- @Override
- public String toString() {
- return String.format("[%s]", path);
- }
-
- public DefaultInputDir setKey(String s) {
- attributes.put(ATTRIBUTE_COMPONENT_KEY, s);
- return this;
- }
-}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/checks/NoSonarFilterTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/checks/NoSonarFilterTest.java
index 70a25607d94..e0be4e3ee80 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/checks/NoSonarFilterTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/checks/NoSonarFilterTest.java
@@ -22,7 +22,7 @@ package org.sonar.api.checks;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.batch.SensorContext;
-import org.sonar.api.resources.JavaFile;
+import org.sonar.api.resources.File;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.Violation;
@@ -37,11 +37,11 @@ public class NoSonarFilterTest {
private SensorContext sensorContext = mock(SensorContext.class);
NoSonarFilter filter = new NoSonarFilter(sensorContext);
- private JavaFile javaFile;
+ private File javaFile;
@Before
public void prepare() {
- javaFile = new JavaFile("org.foo.Bar");
+ javaFile = new File("org.foo.Bar");
when(sensorContext.getResource(javaFile)).thenReturn(javaFile);
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/measures/AverageFormulaTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/measures/AverageFormulaTest.java
index ea973af889e..0637eee5e38 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/measures/AverageFormulaTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/measures/AverageFormulaTest.java
@@ -21,7 +21,7 @@ package org.sonar.api.measures;
import org.junit.Before;
import org.junit.Test;
-import org.sonar.api.resources.JavaFile;
+import org.sonar.api.resources.File;
import java.util.List;
@@ -139,7 +139,7 @@ public class AverageFormulaTest {
public void test_calculation_for_file() {
when(data.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 60.0));
when(data.getMeasure(CoreMetrics.FUNCTIONS)).thenReturn(new Measure(CoreMetrics.FUNCTIONS, 20.0));
- when(context.getResource()).thenReturn(new JavaFile("foo"));
+ when(context.getResource()).thenReturn(new File("foo"));
Measure measure = AverageFormula.create(CoreMetrics.COMPLEXITY, CoreMetrics.FUNCTIONS).calculate(data, context);
assertThat(measure.getValue()).isEqualTo(3.0);
@@ -150,11 +150,11 @@ public class AverageFormulaTest {
when(data.getMeasure(CoreMetrics.COMPLEXITY_IN_FUNCTIONS)).thenReturn(null);
when(data.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 60.0));
when(data.getMeasure(CoreMetrics.FUNCTIONS)).thenReturn(new Measure(CoreMetrics.FUNCTIONS, 20.0));
- when(context.getResource()).thenReturn(new JavaFile("foo"));
+ when(context.getResource()).thenReturn(new File("foo"));
Measure measure = AverageFormula.create(CoreMetrics.COMPLEXITY_IN_FUNCTIONS, CoreMetrics.FUNCTIONS)
- .setFallbackForMainMetric(CoreMetrics.COMPLEXITY)
- .calculate(data, context);
+ .setFallbackForMainMetric(CoreMetrics.COMPLEXITY)
+ .calculate(data, context);
assertThat(measure.getValue()).isEqualTo(3.0);
}
@@ -163,11 +163,11 @@ public class AverageFormulaTest {
when(data.getMeasure(CoreMetrics.COMPLEXITY_IN_FUNCTIONS)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 60.0));
when(data.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 42.0));
when(data.getMeasure(CoreMetrics.FUNCTIONS)).thenReturn(new Measure(CoreMetrics.FUNCTIONS, 20.0));
- when(context.getResource()).thenReturn(new JavaFile("foo"));
+ when(context.getResource()).thenReturn(new File("foo"));
Measure measure = AverageFormula.create(CoreMetrics.COMPLEXITY_IN_FUNCTIONS, CoreMetrics.FUNCTIONS)
- .setFallbackForMainMetric(CoreMetrics.COMPLEXITY)
- .calculate(data, context);
+ .setFallbackForMainMetric(CoreMetrics.COMPLEXITY)
+ .calculate(data, context);
assertThat(measure.getValue()).isEqualTo(3.0);
}
@@ -183,8 +183,8 @@ public class AverageFormulaTest {
when(data.getChildren()).thenReturn(childrenData);
Measure measure = AverageFormula.create(CoreMetrics.COMPLEXITY_IN_FUNCTIONS, CoreMetrics.FUNCTIONS)
- .setFallbackForMainMetric(CoreMetrics.COMPLEXITY)
- .calculate(data, context);
+ .setFallbackForMainMetric(CoreMetrics.COMPLEXITY)
+ .calculate(data, context);
assertThat(measure.getValue()).isEqualTo(2.5);
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/measures/SumChildDistributionFormulaTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/measures/SumChildDistributionFormulaTest.java
index 938a3232e4e..35907e2946c 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/measures/SumChildDistributionFormulaTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/measures/SumChildDistributionFormulaTest.java
@@ -22,9 +22,8 @@ package org.sonar.api.measures;
import com.google.common.collect.Lists;
import org.junit.Before;
import org.junit.Test;
+import org.sonar.api.resources.Directory;
import org.sonar.api.resources.File;
-import org.sonar.api.resources.JavaFile;
-import org.sonar.api.resources.JavaPackage;
import org.sonar.api.resources.Scopes;
import java.util.Collections;
@@ -60,7 +59,7 @@ public class SumChildDistributionFormulaTest {
@Test
public void testWhenGetChildrenReturnsEmpty() {
when(context.getTargetMetric()).thenReturn(new Metric("foo"));
- when(data.getChildrenMeasures(new Metric("foo"))).thenReturn(Collections.<Measure> emptyList());
+ when(data.getChildrenMeasures(new Metric("foo"))).thenReturn(Collections.<Measure>emptyList());
assertNull(formula.calculate(data, context));
}
@@ -72,7 +71,7 @@ public class SumChildDistributionFormulaTest {
List<Measure> list = Lists.newArrayList(
new Measure(m, "1=0;2=2;5=0;10=10;20=2"),
new Measure(m, "1=0;2=2;5=0;10=10;30=3")
- );
+ );
when(data.getChildrenMeasures(new Metric("foo"))).thenReturn(list);
assertThat(formula.calculate(data, context), nullValue());
}
@@ -85,7 +84,7 @@ public class SumChildDistributionFormulaTest {
List<Measure> list = Lists.newArrayList(
new Measure(m, "1=0;2=2;5=0;10=10;20=2"),
new Measure(m, "1=3;2=2;5=3;10=12;20=0")
- );
+ );
when(data.getChildrenMeasures(new Metric("foo"))).thenReturn(list);
assertThat(formula.calculate(data, context).getData(), is("1=3;2=4;5=3;10=22;20=2"));
}
@@ -98,7 +97,7 @@ public class SumChildDistributionFormulaTest {
@Test
public void shouldNotPersistWhenScopeLowerThanMinimun() throws Exception {
- when(context.getResource()).thenReturn(JavaFile.fromRelativePath("org/Foo.java", false));
+ when(context.getResource()).thenReturn(new File("org/Foo.java"));
initContextWithChildren();
formula.setMinimumScopeToPersist(Scopes.DIRECTORY);
@@ -109,7 +108,7 @@ public class SumChildDistributionFormulaTest {
@Test
public void shouldPersistWhenScopeEqualsMinimun() throws Exception {
- when(context.getResource()).thenReturn(JavaFile.fromRelativePath("org/Foo.java", false));
+ when(context.getResource()).thenReturn(new File("org/Foo.java"));
initContextWithChildren();
formula.setMinimumScopeToPersist(Scopes.FILE);
@@ -120,7 +119,7 @@ public class SumChildDistributionFormulaTest {
@Test
public void shouldPersistWhenScopeHigherThanMinimun() throws Exception {
- when(context.getResource()).thenReturn(new JavaPackage("org.foo"));
+ when(context.getResource()).thenReturn(new Directory("org/foo"));
initContextWithChildren();
formula.setMinimumScopeToPersist(Scopes.FILE);
@@ -133,9 +132,9 @@ public class SumChildDistributionFormulaTest {
Metric m = new Metric("foo", Metric.ValueType.DATA);
when(context.getTargetMetric()).thenReturn(m);
List<Measure> list = Lists.newArrayList(
- new Measure(m, "0.5=0;2.5=2"),
- new Measure(m, "0.5=3;2.5=4")
- );
+ new Measure(m, "0.5=0;2.5=2"),
+ new Measure(m, "0.5=3;2.5=4")
+ );
when(data.getChildrenMeasures(new Metric("foo"))).thenReturn(list);
}
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceUtilsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceUtilsTest.java
index cf2e1e3b0c8..1619b93880f 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceUtilsTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceUtilsTest.java
@@ -29,42 +29,43 @@ import static org.mockito.Mockito.when;
public class ResourceUtilsTest {
@Test
- public void checkJavaClass() {
- JavaFile clazz = new JavaFile("hello.Foo");
- assertThat(ResourceUtils.isClass(clazz), is(true));
- assertThat(ResourceUtils.isPackage(clazz), is(false));
- assertThat(ResourceUtils.isModuleProject(clazz), is(false));
- assertThat(ResourceUtils.isSpace(clazz), is(false));
- assertThat(ResourceUtils.isEntity(clazz), is(true));
- assertThat(ResourceUtils.isSet(clazz), is(false));
- assertThat(ResourceUtils.isRootProject(clazz), is(false));
- assertThat(ResourceUtils.isUnitTestClass(clazz), is(false));
+ public void checkFile() {
+ File file = new File("hello.Foo");
+ assertThat(ResourceUtils.isClass(file), is(true));
+ assertThat(ResourceUtils.isPackage(file), is(false));
+ assertThat(ResourceUtils.isModuleProject(file), is(false));
+ assertThat(ResourceUtils.isSpace(file), is(false));
+ assertThat(ResourceUtils.isEntity(file), is(true));
+ assertThat(ResourceUtils.isSet(file), is(false));
+ assertThat(ResourceUtils.isRootProject(file), is(false));
+ assertThat(ResourceUtils.isUnitTestClass(file), is(false));
}
@Test
- public void checkJavaUnitTest() {
- JavaFile clazz = new JavaFile("hello.Foo", true);
- assertThat(ResourceUtils.isClass(clazz), is(false));
- assertThat(ResourceUtils.isPackage(clazz), is(false));
- assertThat(ResourceUtils.isModuleProject(clazz), is(false));
- assertThat(ResourceUtils.isSpace(clazz), is(false));
- assertThat(ResourceUtils.isEntity(clazz), is(true));
- assertThat(ResourceUtils.isSet(clazz), is(false));
- assertThat(ResourceUtils.isRootProject(clazz), is(false));
- assertThat(ResourceUtils.isUnitTestClass(clazz), is(true));
+ public void checkUnitTest() {
+ File utFile = new File("hello.Foo");
+ utFile.setQualifier(Qualifiers.UNIT_TEST_FILE);
+ assertThat(ResourceUtils.isClass(utFile), is(false));
+ assertThat(ResourceUtils.isPackage(utFile), is(false));
+ assertThat(ResourceUtils.isModuleProject(utFile), is(false));
+ assertThat(ResourceUtils.isSpace(utFile), is(false));
+ assertThat(ResourceUtils.isEntity(utFile), is(true));
+ assertThat(ResourceUtils.isSet(utFile), is(false));
+ assertThat(ResourceUtils.isRootProject(utFile), is(false));
+ assertThat(ResourceUtils.isUnitTestClass(utFile), is(true));
}
@Test
- public void checkJavaPackage() {
- JavaPackage pack = new JavaPackage("hello");
- assertThat(ResourceUtils.isClass(pack), is(false));
- assertThat(ResourceUtils.isPackage(pack), is(true));
- assertThat(ResourceUtils.isModuleProject(pack), is(false));
- assertThat(ResourceUtils.isSpace(pack), is(true));
- assertThat(ResourceUtils.isEntity(pack), is(false));
- assertThat(ResourceUtils.isSet(pack), is(false));
- assertThat(ResourceUtils.isRootProject(pack), is(false));
- assertThat(ResourceUtils.isUnitTestClass(pack), is(false));
+ public void checkDirectory() {
+ Directory dir = new Directory("hello");
+ assertThat(ResourceUtils.isClass(dir), is(false));
+ assertThat(ResourceUtils.isPackage(dir), is(true));
+ assertThat(ResourceUtils.isModuleProject(dir), is(false));
+ assertThat(ResourceUtils.isSpace(dir), is(true));
+ assertThat(ResourceUtils.isEntity(dir), is(false));
+ assertThat(ResourceUtils.isSet(dir), is(false));
+ assertThat(ResourceUtils.isRootProject(dir), is(false));
+ assertThat(ResourceUtils.isUnitTestClass(dir), is(false));
}
@Test