diff options
73 files changed, 985 insertions, 657 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/ignore/scanner/SourceScanner.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/ignore/scanner/SourceScanner.java index 4bd4a6fd985..4a5d87eb5d6 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/ignore/scanner/SourceScanner.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/ignore/scanner/SourceScanner.java @@ -23,21 +23,16 @@ package org.sonar.plugins.core.issue.ignore.scanner; import org.sonar.api.batch.Phase; import org.sonar.api.batch.Sensor; import org.sonar.api.batch.SensorContext; -import org.sonar.api.resources.Java; -import org.sonar.api.resources.JavaFile; import org.sonar.api.resources.Project; -import org.sonar.api.resources.Resource; import org.sonar.api.scan.filesystem.FileQuery; -import org.sonar.api.scan.filesystem.ModuleFileSystem; -import org.sonar.api.scan.filesystem.PathResolver; +import org.sonar.api.scan.filesystem.internal.DefaultInputFile; +import org.sonar.api.scan.filesystem.internal.InputFile; import org.sonar.api.utils.SonarException; -import org.sonar.core.component.ComponentKeys; +import org.sonar.batch.scan.filesystem.DefaultModuleFileSystem; import org.sonar.plugins.core.issue.ignore.pattern.ExclusionPatternInitializer; import org.sonar.plugins.core.issue.ignore.pattern.InclusionPatternInitializer; -import java.io.File; import java.nio.charset.Charset; -import java.util.List; @Phase(name = Phase.Name.PRE) public final class SourceScanner implements Sensor { @@ -45,16 +40,14 @@ public final class SourceScanner implements Sensor { private final RegexpScanner regexpScanner; private final ExclusionPatternInitializer exclusionPatternInitializer; private final InclusionPatternInitializer inclusionPatternInitializer; - private final ModuleFileSystem fileSystem; - private final PathResolver pathResolver; + private final DefaultModuleFileSystem fileSystem; public SourceScanner(RegexpScanner regexpScanner, ExclusionPatternInitializer exclusionPatternInitializer, InclusionPatternInitializer inclusionPatternInitializer, - ModuleFileSystem fileSystem) { + DefaultModuleFileSystem fileSystem) { this.regexpScanner = regexpScanner; this.exclusionPatternInitializer = exclusionPatternInitializer; this.inclusionPatternInitializer = inclusionPatternInitializer; this.fileSystem = fileSystem; - this.pathResolver = new PathResolver(); } public boolean shouldExecuteOnProject(Project project) { @@ -73,57 +66,31 @@ public final class SourceScanner implements Sensor { protected void parseDirs(Project project, boolean isTest) { Charset sourcesEncoding = fileSystem.sourceCharset(); - // TODO use InputFile - List<File> files; - List<File> dirs; + Iterable<InputFile> files; if (isTest) { - files = fileSystem.files(FileQuery.onTest().onLanguage(project.getLanguageKey())); - dirs = fileSystem.testDirs(); + files = fileSystem.inputFiles(FileQuery.onTest().onLanguage(project.getLanguageKey())); } else { - files = fileSystem.files(FileQuery.onSource().onLanguage(project.getLanguageKey())); - dirs = fileSystem.sourceDirs(); + files = fileSystem.inputFiles(FileQuery.onSource().onLanguage(project.getLanguageKey())); } - for (File inputFile : files) { + for (InputFile inputFile : files) { try { - // TODO reuse InputFile.attribute(DefaultInputFile.COMPONENT_KEY ? - String componentKey = resolveComponent(inputFile, dirs, project, isTest); - if (componentKey != null) { - - String relativePath = pathResolver.relativePath(dirs, inputFile).path(); - inclusionPatternInitializer.initializePatternsForPath(relativePath, componentKey); - exclusionPatternInitializer.initializePatternsForPath(relativePath, componentKey); + String componentEffectiveKey = inputFile.attribute(DefaultInputFile.ATTRIBUTE_COMPONENT_KEY); + if (componentEffectiveKey != null) { + String relativePathFromSource = inputFile.attribute(InputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH); + inclusionPatternInitializer.initializePatternsForPath(relativePathFromSource, componentEffectiveKey); + exclusionPatternInitializer.initializePatternsForPath(relativePathFromSource, componentEffectiveKey); if (exclusionPatternInitializer.hasFileContentPattern()) { - regexpScanner.scan(componentKey, inputFile, sourcesEncoding); + regexpScanner.scan(componentEffectiveKey, inputFile.file(), sourcesEncoding); } } } catch (Exception e) { - throw new SonarException("Unable to read the source file : '" + inputFile.getAbsolutePath() + "' with the charset : '" + throw new SonarException("Unable to read the source file : '" + inputFile.absolutePath() + "' with the charset : '" + sourcesEncoding.name() + "'.", e); } } } - /* - * This method is necessary because Java resources are not treated as every other resource... - */ - private String resolveComponent(File inputFile, List<File> sourceDirs, Project project, boolean isTest) { - Resource resource; - - if (Java.KEY.equals(project.getLanguageKey()) && Java.isJavaFile(inputFile)) { - - resource = JavaFile.fromIOFile(inputFile, sourceDirs, isTest); - } else { - resource = new org.sonar.api.resources.File(pathResolver.relativePath(sourceDirs, inputFile).path()); - } - - if (resource == null) { - return null; - } else { - return ComponentKeys.createKey(project, resource); - } - } - @Override public String toString() { return "Issues Exclusions - Source Scanner"; diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/ignore/scanner/SourceScannerTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/ignore/scanner/SourceScannerTest.java index 02a169b7f67..39d80f75112 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/ignore/scanner/SourceScannerTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/ignore/scanner/SourceScannerTest.java @@ -20,7 +20,7 @@ package org.sonar.plugins.core.issue.ignore.scanner; -import com.google.common.collect.ImmutableList; +import com.google.common.base.Charsets; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -29,10 +29,14 @@ import org.junit.rules.TemporaryFolder; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.sonar.api.resources.Java; import org.sonar.api.resources.Project; import org.sonar.api.scan.filesystem.FileQuery; -import org.sonar.api.scan.filesystem.ModuleFileSystem; +import org.sonar.api.scan.filesystem.internal.DefaultInputFile; +import org.sonar.api.scan.filesystem.internal.InputFile; +import org.sonar.api.scan.filesystem.internal.InputFileBuilder; import org.sonar.api.utils.SonarException; +import org.sonar.batch.scan.filesystem.DefaultModuleFileSystem; import org.sonar.plugins.core.issue.ignore.pattern.ExclusionPatternInitializer; import org.sonar.plugins.core.issue.ignore.pattern.InclusionPatternInitializer; import org.sonar.plugins.core.issue.ignore.pattern.PatternMatcher; @@ -40,15 +44,11 @@ import org.sonar.plugins.core.issue.ignore.pattern.PatternMatcher; import java.io.File; import java.io.IOException; import java.util.Arrays; -import java.util.Collections; -import java.util.List; import static com.google.common.base.Charsets.UTF_8; import static org.fest.assertions.Assertions.assertThat; import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; @@ -65,7 +65,7 @@ public class SourceScannerTest { @Mock private PatternMatcher patternMatcher; @Mock - private ModuleFileSystem fileSystem; + private DefaultModuleFileSystem fs; private Project project; @@ -75,16 +75,19 @@ public class SourceScannerTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); + private File baseDir; + @Before - public void init() { + public void init() throws IOException { + baseDir = temp.newFolder(); MockitoAnnotations.initMocks(this); Project realProject = new Project("polop"); project = Mockito.spy(realProject); Mockito.doReturn("java").when(project).getLanguageKey(); - when(fileSystem.sourceCharset()).thenReturn(UTF_8); + when(fs.sourceCharset()).thenReturn(UTF_8); - scanner = new SourceScanner(regexpScanner, exclusionPatternInitializer, inclusionPatternInitializer, fileSystem); + scanner = new SourceScanner(regexpScanner, exclusionPatternInitializer, inclusionPatternInitializer, fs); } @Test @@ -114,121 +117,105 @@ public class SourceScannerTest { @Test public void shouldAnalyseJavaProject() throws IOException { - File sourceFile = new File("src/main/java/Foo.java"); - File testFile = new File("src/test/java/FooTest.java"); - - when(project.getLanguageKey()).thenReturn("java"); - when(fileSystem.files(Mockito.isA(FileQuery.class))) - .thenReturn(Arrays.asList(sourceFile)) - .thenReturn(Arrays.asList(testFile)); - when(fileSystem.sourceDirs()).thenReturn(Arrays.asList(new File("src/main/java"))); - when(fileSystem.testDirs()).thenReturn(Arrays.asList(new File("src/test/java"))); + File javaFile1 = new File(baseDir, "src/main/java/Foo.java"); + when(fs.inputFiles(FileQuery.onSource().onLanguage(Java.KEY))).thenReturn((Iterable) Arrays.asList( + new InputFileBuilder(javaFile1, Charsets.UTF_8, "src/main/java/Foo.java") + .attribute(InputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH, "Foo.java") + .attribute(DefaultInputFile.ATTRIBUTE_COMPONENT_KEY, "polop:/src/main/java/Foo.java") + .build())); + File javaTestFile1 = new File(baseDir, "src/test/java/FooTest.java"); + when(fs.inputFiles(FileQuery.onTest().onLanguage(Java.KEY))).thenReturn( + (Iterable) Arrays.asList( + new InputFileBuilder(javaTestFile1, Charsets.UTF_8, "src/test/java/FooTest.java") + .attribute(InputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH, "FooTest.java") + .attribute(DefaultInputFile.ATTRIBUTE_COMPONENT_KEY, "polop:/src/test/java/FooTest.java") + .build())); + when(project.getLanguageKey()).thenReturn(Java.KEY); + when(exclusionPatternInitializer.hasFileContentPattern()).thenReturn(true); scanner.analyse(project, null); - verify(inclusionPatternInitializer).initializePatternsForPath("Foo.java", "polop:[default].Foo"); - verify(inclusionPatternInitializer).initializePatternsForPath("FooTest.java", "polop:[default].FooTest"); - verify(exclusionPatternInitializer).initializePatternsForPath("Foo.java", "polop:[default].Foo"); - verify(exclusionPatternInitializer).initializePatternsForPath("FooTest.java", "polop:[default].FooTest"); - verify(regexpScanner).scan("polop:[default].Foo", sourceFile, UTF_8); - verify(regexpScanner).scan("polop:[default].FooTest", testFile, UTF_8); + verify(inclusionPatternInitializer).initializePatternsForPath("Foo.java", "polop:/src/main/java/Foo.java"); + verify(inclusionPatternInitializer).initializePatternsForPath("FooTest.java", "polop:/src/test/java/FooTest.java"); + verify(exclusionPatternInitializer).initializePatternsForPath("Foo.java", "polop:/src/main/java/Foo.java"); + verify(exclusionPatternInitializer).initializePatternsForPath("FooTest.java", "polop:/src/test/java/FooTest.java"); + verify(regexpScanner).scan("polop:/src/main/java/Foo.java", javaFile1, UTF_8); + verify(regexpScanner).scan("polop:/src/test/java/FooTest.java", javaTestFile1, UTF_8); } @Test public void shouldAnalyseFilesOnlyWhenRegexConfigured() throws IOException { - File sourceFile = new File("src/main/java/Foo.java"); - File testFile = new File("src/test/java/FooTest.java"); - - when(project.getLanguageKey()).thenReturn("java"); - when(fileSystem.files(Mockito.isA(FileQuery.class))) - .thenReturn(Arrays.asList(sourceFile)) - .thenReturn(Arrays.asList(testFile)); - when(fileSystem.sourceDirs()).thenReturn(Arrays.asList(new File("src/main/java"))); - when(fileSystem.testDirs()).thenReturn(Arrays.asList(new File("src/test/java"))); + File javaFile1 = new File(baseDir, "src/main/java/Foo.java"); + when(fs.inputFiles(FileQuery.onSource().onLanguage(Java.KEY))).thenReturn((Iterable) Arrays.asList( + new InputFileBuilder(javaFile1, Charsets.UTF_8, "src/main/java/Foo.java") + .attribute(InputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH, "Foo.java") + .attribute(DefaultInputFile.ATTRIBUTE_COMPONENT_KEY, "polop:/src/main/java/Foo.java") + .build())); + File javaTestFile1 = new File(baseDir, "src/test/java/FooTest.java"); + when(fs.inputFiles(FileQuery.onTest().onLanguage(Java.KEY))).thenReturn( + (Iterable) Arrays.asList( + new InputFileBuilder(javaTestFile1, Charsets.UTF_8, "src/test/java/FooTest.java") + .attribute(InputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH, "FooTest.java") + .attribute(DefaultInputFile.ATTRIBUTE_COMPONENT_KEY, "polop:/src/test/java/FooTest.java") + .build())); + when(project.getLanguageKey()).thenReturn(Java.KEY); + when(exclusionPatternInitializer.hasFileContentPattern()).thenReturn(false); scanner.analyse(project, null); - verify(inclusionPatternInitializer).initializePatternsForPath("Foo.java", "polop:[default].Foo"); - verify(inclusionPatternInitializer).initializePatternsForPath("FooTest.java", "polop:[default].FooTest"); - verify(exclusionPatternInitializer).initializePatternsForPath("Foo.java", "polop:[default].Foo"); - verify(exclusionPatternInitializer).initializePatternsForPath("FooTest.java", "polop:[default].FooTest"); + verify(inclusionPatternInitializer).initializePatternsForPath("Foo.java", "polop:/src/main/java/Foo.java"); + verify(inclusionPatternInitializer).initializePatternsForPath("FooTest.java", "polop:/src/test/java/FooTest.java"); + verify(exclusionPatternInitializer).initializePatternsForPath("Foo.java", "polop:/src/main/java/Foo.java"); + verify(exclusionPatternInitializer).initializePatternsForPath("FooTest.java", "polop:/src/test/java/FooTest.java"); verifyZeroInteractions(regexpScanner); } @Test public void shouldAnalyseOtherProject() throws Exception { - File rootDir = temp.newFolder(); - File sourceFile = new File(rootDir, "Foo.php"); - File testFile = new File(rootDir, "FooTest.php"); + File phpFile1 = new File(baseDir, "src/Foo.php"); + when(fs.inputFiles(FileQuery.onSource().onLanguage("php"))).thenReturn((Iterable) Arrays.asList( + new InputFileBuilder(phpFile1, Charsets.UTF_8, "src/Foo.php") + .attribute(InputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH, "Foo.php") + .attribute(DefaultInputFile.ATTRIBUTE_COMPONENT_KEY, "polop:/src/Foo.php") + .build())); + File phpTestFile1 = new File(baseDir, "src/test/FooTest.php"); + when(fs.inputFiles(FileQuery.onTest().onLanguage("php"))).thenReturn( + (Iterable) Arrays.asList( + new InputFileBuilder(phpTestFile1, Charsets.UTF_8, "src/test/FooTest.php") + .attribute(InputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH, "FooTest.php") + .attribute(DefaultInputFile.ATTRIBUTE_COMPONENT_KEY, "polop:/src/test/FooTest.php") + .build())); when(project.getLanguageKey()).thenReturn("php"); - when(fileSystem.files(Mockito.isA(FileQuery.class))) - .thenReturn(Arrays.asList(sourceFile)) - .thenReturn(Arrays.asList(testFile)); - when(fileSystem.sourceDirs()).thenReturn(ImmutableList.of(rootDir)); - when(fileSystem.testDirs()).thenReturn(ImmutableList.of(rootDir)); - when(exclusionPatternInitializer.hasFileContentPattern()).thenReturn(true); - scanner.analyse(project, null); - - verify(inclusionPatternInitializer).initializePatternsForPath("Foo.php", "polop:Foo.php"); - verify(inclusionPatternInitializer).initializePatternsForPath("FooTest.php", "polop:FooTest.php"); - verify(exclusionPatternInitializer).initializePatternsForPath("Foo.php", "polop:Foo.php"); - verify(exclusionPatternInitializer).initializePatternsForPath("FooTest.php", "polop:FooTest.php"); - verify(regexpScanner).scan("polop:Foo.php", sourceFile, UTF_8); - verify(regexpScanner).scan("polop:FooTest.php", testFile, UTF_8); - } - - @Test - public void shouldAnalyseJavaProjectWithNonJavaFile() throws IOException { - File rootDir = temp.newFolder(); - File sourceFile = new File(rootDir, "src/main/java/Foo.java"); - File otherFile = new File(rootDir, "other.js"); - - when(project.getLanguageKey()).thenReturn("java"); - List<File> empty = Collections.emptyList(); - when(fileSystem.files(Mockito.isA(FileQuery.class))) - .thenReturn(Arrays.asList(sourceFile, otherFile)) - .thenReturn(empty); - when(fileSystem.sourceDirs()).thenReturn(ImmutableList.of(new File(rootDir, "src/main/java"), rootDir)); - when(fileSystem.testDirs()).thenReturn(ImmutableList.of(new File(rootDir, "src/test/java"))); when(exclusionPatternInitializer.hasFileContentPattern()).thenReturn(true); scanner.analyse(project, null); - verify(inclusionPatternInitializer).initializePatternsForPath("Foo.java", "polop:[default].Foo"); - verify(exclusionPatternInitializer).initializePatternsForPath("Foo.java", "polop:[default].Foo"); - verify(regexpScanner).scan("polop:[default].Foo", sourceFile, UTF_8); - verify(regexpScanner, never()).scan("other.js", otherFile, UTF_8); - } - - @Test - public void shouldIgnoreInvalidFile() throws IOException { - File sourceFile = new File("invalid.java"); - - when(project.getLanguageKey()).thenReturn("java"); - List<File> empty = Collections.emptyList(); - when(fileSystem.files(Mockito.isA(FileQuery.class))) - .thenReturn(Arrays.asList(sourceFile)) - .thenReturn(empty); - when(fileSystem.sourceDirs()).thenReturn(Arrays.asList(new File("src/main/java"))); - when(fileSystem.testDirs()).thenReturn(Arrays.asList(new File("src/test/java"))); - when(exclusionPatternInitializer.hasFileContentPattern()).thenReturn(true); - - scanner.analyse(project, null); - - verifyNoMoreInteractions(regexpScanner); + verify(inclusionPatternInitializer).initializePatternsForPath("Foo.php", "polop:/src/Foo.php"); + verify(inclusionPatternInitializer).initializePatternsForPath("FooTest.php", "polop:/src/test/FooTest.php"); + verify(exclusionPatternInitializer).initializePatternsForPath("Foo.php", "polop:/src/Foo.php"); + verify(exclusionPatternInitializer).initializePatternsForPath("FooTest.php", "polop:/src/test/FooTest.php"); + verify(regexpScanner).scan("polop:/src/Foo.php", phpFile1, UTF_8); + verify(regexpScanner).scan("polop:/src/test/FooTest.php", phpTestFile1, UTF_8); } @Test public void shouldReportFailure() throws IOException { - File sourceFile = new File("Foo.php"); + File phpFile1 = new File(baseDir, "src/Foo.php"); + when(fs.inputFiles(FileQuery.onSource().onLanguage("php"))).thenReturn((Iterable) Arrays.asList( + new InputFileBuilder(phpFile1, Charsets.UTF_8, "src/Foo.php") + .attribute(InputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH, "Foo.php") + .attribute(DefaultInputFile.ATTRIBUTE_COMPONENT_KEY, "polop:/src/Foo.php") + .build())); + when(fs.inputFiles(FileQuery.onTest().onLanguage("php"))).thenReturn( + (Iterable) Arrays.asList()); when(project.getLanguageKey()).thenReturn("php"); - when(fileSystem.files(Mockito.isA(FileQuery.class))).thenReturn(Arrays.asList(sourceFile)); - doThrow(new IOException("BUG")).when(regexpScanner).scan("polop:Foo.php", sourceFile, UTF_8); + when(exclusionPatternInitializer.hasFileContentPattern()).thenReturn(true); + doThrow(new IOException("BUG")).when(regexpScanner).scan("polop:/src/Foo.php", phpFile1, UTF_8); thrown.expect(SonarException.class); thrown.expectMessage("Unable to read the source file"); diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CoverageMeasurementFilterTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CoverageMeasurementFilterTest.java index 3642681de8f..9e193af9677 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CoverageMeasurementFilterTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CoverageMeasurementFilterTest.java @@ -53,24 +53,23 @@ public class CoverageMeasurementFilterTest { @Test public void shouldFilterFileBasedOnPattern() { - Resource resource = new File("org/polop/File.php"); + Resource resource = File.create("src/org/polop/File.php", "org/polop/File.php", null, false); Measure coverageMeasure = mock(Measure.class); when(coverageMeasure.getMetric()).thenReturn(CoreMetrics.LINES_TO_COVER); - settings.setProperty(CoverageMeasurementFilter.PROPERTY_COVERAGE_EXCLUSIONS, "org/polop/*"); + settings.setProperty(CoverageMeasurementFilter.PROPERTY_COVERAGE_EXCLUSIONS, "src/org/polop/*"); filter.initPatterns(); assertThat(filter.accept(resource, coverageMeasure)).isFalse(); } @Test public void shouldNotFilterFileBasedOnPattern() { - Resource resource = new File("org/polop/File.php"); + Resource resource = File.create("src/org/polop/File.php", "org/polop/File.php", null, false); Measure coverageMeasure = mock(Measure.class); when(coverageMeasure.getMetric()).thenReturn(CoreMetrics.COVERAGE); - settings.setProperty(CoverageMeasurementFilter.PROPERTY_COVERAGE_EXCLUSIONS, "org/other/*"); + settings.setProperty(CoverageMeasurementFilter.PROPERTY_COVERAGE_EXCLUSIONS, "src/org/other/*"); filter.initPatterns(); assertThat(filter.accept(resource, coverageMeasure)).isTrue(); } } - diff --git a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarEngine.java b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarEngine.java index 48ff0147243..d92157f3e11 100644 --- a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarEngine.java +++ b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarEngine.java @@ -32,7 +32,11 @@ import org.sonar.api.database.model.ResourceModel; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Measure; import org.sonar.api.measures.PersistenceMode; -import org.sonar.api.resources.*; +import org.sonar.api.resources.Java; +import org.sonar.api.resources.JavaFile; +import org.sonar.api.resources.Language; +import org.sonar.api.resources.Project; +import org.sonar.api.resources.Resource; import org.sonar.api.scan.filesystem.FileQuery; import org.sonar.api.scan.filesystem.ModuleFileSystem; import org.sonar.api.scan.filesystem.PathResolver; @@ -54,12 +58,20 @@ import org.sonar.plugins.cpd.index.SonarDuplicationsIndex; import javax.annotation.Nullable; import java.io.File; -import java.io.*; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStreamReader; +import java.io.Reader; import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.concurrent.*; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; public class SonarEngine extends CpdEngine { @@ -91,10 +103,10 @@ public class SonarEngine extends CpdEngine { static String getFullKey(Project project, Resource resource) { return new StringBuilder(ResourceModel.KEY_SIZE) - .append(project.getKey()) - .append(':') - .append(resource.getKey()) - .toString(); + .append(project.getKey()) + .append(':') + .append(resource.getKey()) + .toString(); } @Override @@ -128,7 +140,7 @@ public class SonarEngine extends CpdEngine { reader = new InputStreamReader(new FileInputStream(file), fileSystem.sourceCharset()); statements = statementChunker.chunk(tokenChunker.chunk(reader)); } catch (FileNotFoundException e) { - throw new SonarException("Cannot find file "+ file, e); + throw new SonarException("Cannot find file " + file, e); } finally { IOUtils.closeQuietly(reader); } @@ -157,9 +169,9 @@ public class SonarEngine extends CpdEngine { clones = null; LOG.warn("Timeout during detection of duplications for " + file, e); } catch (InterruptedException e) { - throw new SonarException("Fail during detection of duplication for "+ file, e); + throw new SonarException("Fail during detection of duplication for " + file, e); } catch (ExecutionException e) { - throw new SonarException("Fail during detection of duplication for "+ file, e); + throw new SonarException("Fail during detection of duplication for " + file, e); } save(context, resource, clones); @@ -184,8 +196,8 @@ public class SonarEngine extends CpdEngine { } protected Resource getResource(File file) { - String relativePath = pathResolver.relativePath(fileSystem.sourceDirs(), file).path(); - return JavaFile.fromRelativePath(relativePath, false); + String relativePathFromBaseDir = pathResolver.relativePath(fileSystem.baseDir(), file); + return JavaFile.create(relativePathFromBaseDir, "unused", false); } static void save(SensorContext context, Resource resource, @Nullable Iterable<CloneGroup> duplications) { @@ -212,7 +224,7 @@ public class SonarEngine extends CpdEngine { context.saveMeasure(resource, CoreMetrics.DUPLICATED_BLOCKS, duplicatedBlocks); Measure data = new Measure(CoreMetrics.DUPLICATIONS_DATA, toXml(duplications)) - .setPersistenceMode(PersistenceMode.DATABASE); + .setPersistenceMode(PersistenceMode.DATABASE); context.saveMeasure(resource, data); } @@ -223,9 +235,9 @@ public class SonarEngine extends CpdEngine { xml.append("<g>"); for (ClonePart part : duplication.getCloneParts()) { xml.append("<b s=\"").append(part.getStartLine()) - .append("\" l=\"").append(part.getLines()) - .append("\" r=\"").append(StringEscapeUtils.escapeXml(part.getResourceId())) - .append("\"/>"); + .append("\" l=\"").append(part.getLines()) + .append("\" r=\"").append(StringEscapeUtils.escapeXml(part.getResourceId())) + .append("\"/>"); } xml.append("</g>"); } diff --git a/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/SonarEngineTest.java b/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/SonarEngineTest.java index 3b4b2a30572..c2346fe86fb 100644 --- a/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/SonarEngineTest.java +++ b/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/SonarEngineTest.java @@ -28,7 +28,6 @@ import org.sonar.api.resources.JavaFile; import org.sonar.api.resources.Resource; import org.sonar.api.scan.filesystem.ModuleFileSystem; import org.sonar.api.scan.filesystem.PathResolver; -import org.sonar.api.scan.filesystem.PathResolver.RelativePath; import org.sonar.api.test.IsMeasure; import org.sonar.duplications.index.CloneGroup; import org.sonar.duplications.index.ClonePart; @@ -39,7 +38,6 @@ import java.util.List; import static org.fest.assertions.Assertions.assertThat; import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyCollection; import static org.mockito.Matchers.argThat; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; @@ -58,18 +56,16 @@ public class SonarEngineTest { resource = new JavaFile("key1"); } - @SuppressWarnings("unchecked") @Test public void testGetResource() { PathResolver pathResolver = mock(PathResolver.class); ModuleFileSystem fileSystem = mock(ModuleFileSystem.class); - RelativePath relativePath = new RelativePath(null, "com/foo/Bar.java"); - when(pathResolver.relativePath(anyCollection(), any(java.io.File.class))).thenReturn(relativePath); + when(pathResolver.relativePath(any(java.io.File.class), any(java.io.File.class))).thenReturn("src/main/java/com/foo/Bar.java"); SonarEngine engine = new SonarEngine(null, fileSystem, pathResolver, null); Resource resource = engine.getResource(new java.io.File("")); - assertThat(resource.getKey()).isEqualTo("com.foo.Bar"); + assertThat(resource.getKey()).isEqualTo("/src/main/java/com/foo/Bar.java"); assertThat(resource).isInstanceOf(JavaFile.class); } @@ -91,11 +87,11 @@ public class SonarEngineTest { verify(context).saveMeasure(resource, CoreMetrics.DUPLICATED_BLOCKS, 1d); verify(context).saveMeasure(resource, CoreMetrics.DUPLICATED_LINES, 200d); verify(context).saveMeasure( - eq(resource), - argThat(new IsMeasure(CoreMetrics.DUPLICATIONS_DATA, "<duplications><g>" - + "<b s=\"5\" l=\"200\" r=\"key1\"/>" - + "<b s=\"15\" l=\"200\" r=\"key2\"/>" - + "</g></duplications>"))); + eq(resource), + argThat(new IsMeasure(CoreMetrics.DUPLICATIONS_DATA, "<duplications><g>" + + "<b s=\"5\" l=\"200\" r=\"key1\"/>" + + "<b s=\"15\" l=\"200\" r=\"key2\"/>" + + "</g></duplications>"))); } @Test @@ -107,11 +103,11 @@ public class SonarEngineTest { verify(context).saveMeasure(resource, CoreMetrics.DUPLICATED_LINES, 400d); verify(context).saveMeasure(resource, CoreMetrics.DUPLICATED_BLOCKS, 2d); verify(context).saveMeasure( - eq(resource), - argThat(new IsMeasure(CoreMetrics.DUPLICATIONS_DATA, "<duplications><g>" - + "<b s=\"5\" l=\"200\" r=\"key1\"/>" - + "<b s=\"215\" l=\"200\" r=\"key1\"/>" - + "</g></duplications>"))); + eq(resource), + argThat(new IsMeasure(CoreMetrics.DUPLICATIONS_DATA, "<duplications><g>" + + "<b s=\"5\" l=\"200\" r=\"key1\"/>" + + "<b s=\"215\" l=\"200\" r=\"key1\"/>" + + "</g></duplications>"))); } @Test @@ -123,52 +119,52 @@ public class SonarEngineTest { verify(context).saveMeasure(resource, CoreMetrics.DUPLICATED_BLOCKS, 1d); verify(context).saveMeasure(resource, CoreMetrics.DUPLICATED_LINES, 200d); verify(context).saveMeasure( - eq(resource), - argThat(new IsMeasure(CoreMetrics.DUPLICATIONS_DATA, "<duplications><g>" - + "<b s=\"5\" l=\"200\" r=\"key1\"/>" - + "<b s=\"15\" l=\"200\" r=\"key2\"/>" - + "<b s=\"25\" l=\"200\" r=\"key3\"/>" - + "</g></duplications>"))); + eq(resource), + argThat(new IsMeasure(CoreMetrics.DUPLICATIONS_DATA, "<duplications><g>" + + "<b s=\"5\" l=\"200\" r=\"key1\"/>" + + "<b s=\"15\" l=\"200\" r=\"key2\"/>" + + "<b s=\"25\" l=\"200\" r=\"key3\"/>" + + "</g></duplications>"))); } @Test public void testTwoDuplicatedGroupsInvolvingThreeFiles() throws Exception { List<CloneGroup> groups = Arrays.asList( - newCloneGroup(new ClonePart("key1", 0, 5, 204), new ClonePart("key2", 0, 15, 214)), - newCloneGroup(new ClonePart("key1", 0, 15, 214), new ClonePart("key3", 0, 15, 214))); + newCloneGroup(new ClonePart("key1", 0, 5, 204), new ClonePart("key2", 0, 15, 214)), + newCloneGroup(new ClonePart("key1", 0, 15, 214), new ClonePart("key3", 0, 15, 214))); SonarEngine.save(context, resource, groups); verify(context).saveMeasure(resource, CoreMetrics.DUPLICATED_FILES, 1d); verify(context).saveMeasure(resource, CoreMetrics.DUPLICATED_BLOCKS, 2d); verify(context).saveMeasure(resource, CoreMetrics.DUPLICATED_LINES, 210d); verify(context).saveMeasure( - eq(resource), - argThat(new IsMeasure(CoreMetrics.DUPLICATIONS_DATA, "<duplications>" - + "<g>" - + "<b s=\"5\" l=\"200\" r=\"key1\"/>" - + "<b s=\"15\" l=\"200\" r=\"key2\"/>" - + "</g>" - + "<g>" - + "<b s=\"15\" l=\"200\" r=\"key1\"/>" - + "<b s=\"15\" l=\"200\" r=\"key3\"/>" - + "</g>" - + "</duplications>"))); + eq(resource), + argThat(new IsMeasure(CoreMetrics.DUPLICATIONS_DATA, "<duplications>" + + "<g>" + + "<b s=\"5\" l=\"200\" r=\"key1\"/>" + + "<b s=\"15\" l=\"200\" r=\"key2\"/>" + + "</g>" + + "<g>" + + "<b s=\"15\" l=\"200\" r=\"key1\"/>" + + "<b s=\"15\" l=\"200\" r=\"key3\"/>" + + "</g>" + + "</duplications>"))); } @Test public void shouldEscapeXmlEntities() { File csharpFile = new File("Loads/File Loads/Subs & Reds/SubsRedsDelivery.cs"); List<CloneGroup> groups = Arrays.asList(newCloneGroup( - new ClonePart("Loads/File Loads/Subs & Reds/SubsRedsDelivery.cs", 0, 5, 204), - new ClonePart("Loads/File Loads/Subs & Reds/SubsRedsDelivery2.cs", 0, 15, 214))); + new ClonePart("Loads/File Loads/Subs & Reds/SubsRedsDelivery.cs", 0, 5, 204), + new ClonePart("Loads/File Loads/Subs & Reds/SubsRedsDelivery2.cs", 0, 15, 214))); SonarEngine.save(context, csharpFile, groups); verify(context).saveMeasure( - eq(csharpFile), - argThat(new IsMeasure(CoreMetrics.DUPLICATIONS_DATA, "<duplications><g>" - + "<b s=\"5\" l=\"200\" r=\"Loads/File Loads/Subs & Reds/SubsRedsDelivery.cs\"/>" - + "<b s=\"15\" l=\"200\" r=\"Loads/File Loads/Subs & Reds/SubsRedsDelivery2.cs\"/>" - + "</g></duplications>"))); + eq(csharpFile), + argThat(new IsMeasure(CoreMetrics.DUPLICATIONS_DATA, "<duplications><g>" + + "<b s=\"5\" l=\"200\" r=\"Loads/File Loads/Subs & Reds/SubsRedsDelivery.cs\"/>" + + "<b s=\"15\" l=\"200\" r=\"Loads/File Loads/Subs & Reds/SubsRedsDelivery2.cs\"/>" + + "</g></duplications>"))); } private CloneGroup newCloneGroup(ClonePart... parts) { diff --git a/sonar-batch/src/main/java/org/sonar/batch/DefaultFileLinesContextFactory.java b/sonar-batch/src/main/java/org/sonar/batch/DefaultFileLinesContextFactory.java index 8c956ec9117..13d53e1ba9a 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/DefaultFileLinesContextFactory.java +++ b/sonar-batch/src/main/java/org/sonar/batch/DefaultFileLinesContextFactory.java @@ -33,6 +33,8 @@ public class DefaultFileLinesContextFactory implements FileLinesContextFactory { } public FileLinesContext createFor(Resource resource) { + // Reload resource in case it use deprecated key + resource = index.getResource(resource); return new DefaultFileLinesContext(index, resource); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java index b0ef29a709e..fa665e608b9 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java @@ -28,6 +28,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.batch.Event; import org.sonar.api.batch.SonarIndex; +import org.sonar.api.batch.SquidUtils; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.database.model.Snapshot; import org.sonar.api.design.Dependency; @@ -36,6 +37,10 @@ import org.sonar.api.measures.MeasuresFilter; import org.sonar.api.measures.MeasuresFilters; import org.sonar.api.measures.Metric; import org.sonar.api.measures.MetricFinder; +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.Project; import org.sonar.api.resources.ProjectLink; import org.sonar.api.resources.Qualifiers; @@ -202,7 +207,7 @@ public class DefaultIndex extends SonarIndex { bucket.addMeasure(measure); if (measure.getPersistenceMode().useDatabase()) { - persistence.saveMeasure(resource, measure); + persistence.saveMeasure(bucket.getResource(), measure); } } return measure; @@ -465,7 +470,7 @@ public class DefaultIndex extends SonarIndex { @Override public <R extends Resource> R getResource(R reference) { - Bucket bucket = buckets.get(reference); + Bucket bucket = getBucket(reference); if (bucket != null) { return (R) bucket.getResource(); } @@ -525,7 +530,7 @@ public class DefaultIndex extends SonarIndex { } private Bucket doIndex(Resource resource, Resource parentReference) { - Bucket bucket = buckets.get(resource); + Bucket bucket = getBucket(resource); if (bucket != null) { return bucket; } @@ -545,6 +550,7 @@ public class DefaultIndex extends SonarIndex { } resource.setEffectiveKey(ComponentKeys.createKey(currentProject, resource)); + resource.setDeprecatedEffectiveKey(ComponentKeys.createDeprecatedKey(currentProject, resource)); bucket = new Bucket(resource).setParent(parentBucket); buckets.put(resource, bucket); @@ -598,11 +604,45 @@ public class DefaultIndex extends SonarIndex { private Bucket getBucket(Resource resource, boolean acceptExcluded) { Bucket bucket = null; if (resource != null) { - bucket = buckets.get(resource); + bucket = getBucket(resource); if (!acceptExcluded && bucket != null && bucket.isExcluded()) { bucket = null; } } return bucket; } + + /** + * Should support 3 situations + * 1) key = new key and deprecatedKey = old key : this is the standard use case in a perfect world + * 2) key = old key and deprecatedKey = null : this is to support backard compatibility for plugins using + * {@link SquidUtils#convertJavaFileKeyFromSquidFormat(String)} or {@link SquidUtils#convertJavaPackageKeyFromSquidFormat(String)} + * 3) key = null and deprecatedKey = oldKey : this is for plugins that are using deprecated constructors of {@link JavaFile}, {@link JavaPackage}, {@link File}, {@link Directory} + * @param res + * @return + */ + private Bucket getBucket(Resource res) { + if (StringUtils.isNotBlank(res.getKey()) && StringUtils.isNotBlank(res.getDeprecatedKey())) { + return buckets.get(res); + } + // Squid compatibility fix (case 2) + if (StringUtils.isBlank(res.getDeprecatedKey())) { + res.setDeprecatedKey(res.getKey()); + } + if (StringUtils.isNotBlank(res.getDeprecatedKey())) { + // Fallback to use deprecated key + for (Map.Entry<Resource, Bucket> entry : buckets.entrySet()) { + Resource indexedResource = entry.getKey(); + if (res.getClass() == indexedResource.getClass() && res.getDeprecatedKey().equals(indexedResource.getDeprecatedKey())) { + LOG.warn("Resource was found using deprecated key. Please update your plugin."); + // Fix resource key + Bucket bucket = entry.getValue(); + res.setKey(bucket.getResource().getKey()); + return bucket; + } + } + } + return null; + } + } diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java index abe1e4915ef..cbf24c5e6be 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java @@ -255,12 +255,15 @@ public final class DefaultResourcePersister implements ResourcePersister { private ResourceModel findOrCreateModel(@Nullable Integer rootModuleId, Resource resource) { ResourceModel model; try { - if (rootModuleId != null && StringUtils.isNotBlank(resource.getPath())) { - model = session.getSingleResult(ResourceModel.class, "rootId", rootModuleId, "path", resource.getPath()); - } else { - model = session.getSingleResult(ResourceModel.class, "key", resource.getEffectiveKey()); + model = session.getSingleResult(ResourceModel.class, "key", resource.getEffectiveKey()); + if (model == null) { + // Fallback on deprecated key when resource has not already been migrated + model = session.getSingleResult(ResourceModel.class, "key", resource.getDeprecatedEffectiveKey(), "deprecatedKey", null); } if (model == null) { + if (StringUtils.isBlank(resource.getEffectiveKey())) { + throw new SonarException("Unable to persist resource " + resource.toString() + ". Resource effective key is blank. This may be caused by an outdated plugin."); + } model = createModel(resource); } else { @@ -278,6 +281,8 @@ public final class DefaultResourcePersister implements ResourcePersister { model.setEnabled(Boolean.TRUE); model.setDescription(resource.getDescription()); model.setKey(resource.getEffectiveKey()); + String deprecatedEffectiveKey = resource.getDeprecatedEffectiveKey(); + model.setDeprecatedKey(StringUtils.isNotBlank(deprecatedEffectiveKey) ? deprecatedEffectiveKey : resource.getEffectiveKey()); model.setPath(resource.getPath()); if (resource.getLanguage() != null) { model.setLanguageKey(resource.getLanguage().getKey()); @@ -295,6 +300,13 @@ public final class DefaultResourcePersister implements ResourcePersister { static void mergeModel(ResourceModel model, Resource resource) { model.setEnabled(true); + model.setKey(resource.getEffectiveKey()); + if (StringUtils.isNotBlank(resource.getDeprecatedEffectiveKey())) { + model.setDeprecatedKey(resource.getDeprecatedEffectiveKey()); + } else if (StringUtils.isBlank(model.getDeprecatedKey())) { + // By default deprecated key is the same as previous key + model.setDeprecatedKey(model.getKey()); + } if (StringUtils.isNotBlank(resource.getName())) { model.setName(resource.getName()); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/FileIndexer.java b/sonar-batch/src/main/java/org/sonar/batch/phases/FileIndexer.java index 025f1effc45..408557f9c2b 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/FileIndexer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/phases/FileIndexer.java @@ -31,7 +31,6 @@ 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; import org.sonar.api.resources.Resource; import org.sonar.api.scan.filesystem.FileQuery; import org.sonar.api.scan.filesystem.internal.InputFile; @@ -72,16 +71,11 @@ public class FileIndexer implements BatchComponent { for (InputFile inputFile : files) { Resource sonarFile; if (Java.KEY.equals(languageKey)) { - sonarFile = JavaFile.fromRelativePath(inputFile.attribute(InputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH), unitTest); + sonarFile = JavaFile.create(inputFile.path(), inputFile.attribute(InputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH), unitTest); } else { - File newFile = new File(languages.get(languageKey), inputFile.attribute(InputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH)); - if (newFile != null && unitTest) { - newFile.setQualifier(Qualifiers.UNIT_TEST_FILE); - } - sonarFile = newFile; + sonarFile = File.create(inputFile.path(), inputFile.attribute(InputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH), languages.get(languageKey), unitTest); } if (sonarFile != null) { - sonarFile.setPath(inputFile.path()); sonarIndex.index(sonarFile); try { if (importSource) { 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 19826e193b7..6ccd2fd5c95 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 @@ -175,12 +175,16 @@ public class FileIndex implements BatchComponent { String sourceRelativePath = pathResolver.relativePath(sourceDir, file); set(attributes, InputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH, sourceRelativePath); + String resourceKey = PathUtils.sanitize(path); + if (!StringUtils.startsWith(resourceKey, "/")) { + resourceKey = "/" + resourceKey; + } + set(attributes, DefaultInputFile.ATTRIBUTE_COMPONENT_KEY, project.getEffectiveKey() + ":" + resourceKey); if (Java.KEY.equals(lang)) { - set(attributes, DefaultInputFile.ATTRIBUTE_COMPONENT_KEY, project.getEffectiveKey() + ":" + JavaFile.fromRelativePath(sourceRelativePath, false).getKey()); + set(attributes, DefaultInputFile.ATTRIBUTE_COMPONENT_DEPRECATED_KEY, project.getEffectiveKey() + ":" + JavaFile.fromRelativePath(sourceRelativePath, false).getKey()); } else { - set(attributes, DefaultInputFile.ATTRIBUTE_COMPONENT_KEY, project.getEffectiveKey() + ":" + sourceRelativePath); + set(attributes, DefaultInputFile.ATTRIBUTE_COMPONENT_DEPRECATED_KEY, project.getEffectiveKey() + ":" + sourceRelativePath); } - // hash + status initStatus(file, fileSystem.sourceCharset(), path, attributes); diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ComponentSelector.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/ComponentSelector.java index 8542eb6476e..ba4a29ac6f8 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ComponentSelector.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/ComponentSelector.java @@ -31,4 +31,6 @@ abstract class ComponentSelector { abstract Set<String> componentKeys(); + abstract String getDeprecatedKey(String componentKey); + } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ComponentSelectorFactory.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/ComponentSelectorFactory.java index b384130468c..6fd9bb07c76 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ComponentSelectorFactory.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/ComponentSelectorFactory.java @@ -37,6 +37,6 @@ public class ComponentSelectorFactory implements BatchComponent { if (mode.isIncremental()) { return new IncrementalComponentSelector(fileCache); } - return new DefaultComponentSelector(); + return new DefaultComponentSelector(fileCache); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/DefaultComponentSelector.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/DefaultComponentSelector.java index ce65bb715df..a90b4df7bf4 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/DefaultComponentSelector.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/DefaultComponentSelector.java @@ -19,28 +19,50 @@ */ package org.sonar.batch.scan.report; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; import org.sonar.api.issue.Issue; +import org.sonar.api.scan.filesystem.internal.DefaultInputFile; +import org.sonar.api.scan.filesystem.internal.InputFile; +import org.sonar.batch.scan.filesystem.InputFileCache; +import java.util.Map; import java.util.Set; -import static com.google.common.collect.Sets.newHashSet; +class DefaultComponentSelector extends ComponentSelector { -class DefaultComponentSelector extends ComponentSelector{ + private final InputFileCache cache; + private final Map<String, String> componentKeys = Maps.newHashMap(); + private final Set<String> componentKeysWithIssue = Sets.newHashSet(); - private final Set<String> componentKeys = newHashSet(); + DefaultComponentSelector(InputFileCache cache) { + this.cache = cache; + } @Override void init() { + for (InputFile inputFile : cache.all()) { + String componentKey = inputFile.attribute(DefaultInputFile.ATTRIBUTE_COMPONENT_KEY); + String componentDeprecatedKey = inputFile.attribute(DefaultInputFile.ATTRIBUTE_COMPONENT_DEPRECATED_KEY); + if (componentKey != null) { + componentKeys.put(componentKey, componentDeprecatedKey); + } + } } @Override boolean register(Issue issue) { - componentKeys.add(issue.componentKey()); + componentKeysWithIssue.add(issue.componentKey()); return true; } @Override Set<String> componentKeys() { - return componentKeys; + return componentKeysWithIssue; + } + + @Override + String getDeprecatedKey(String componentKey) { + return componentKeys.get(componentKey); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/IncrementalComponentSelector.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/IncrementalComponentSelector.java index 85b648fb035..0c54d1bbfa3 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/IncrementalComponentSelector.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/IncrementalComponentSelector.java @@ -19,19 +19,19 @@ */ package org.sonar.batch.scan.report; +import com.google.common.collect.Maps; import org.sonar.api.issue.Issue; -import org.sonar.api.scan.filesystem.internal.InputFile; import org.sonar.api.scan.filesystem.internal.DefaultInputFile; +import org.sonar.api.scan.filesystem.internal.InputFile; import org.sonar.batch.scan.filesystem.InputFileCache; +import java.util.Map; import java.util.Set; -import static com.google.common.collect.Sets.newHashSet; - class IncrementalComponentSelector extends ComponentSelector { private final InputFileCache cache; - private final Set<String> componentKeys = newHashSet(); + private final Map<String, String> componentKeys = Maps.newHashMap(); IncrementalComponentSelector(InputFileCache cache) { this.cache = cache; @@ -43,8 +43,9 @@ class IncrementalComponentSelector extends ComponentSelector { String status = inputFile.attribute(InputFile.ATTRIBUTE_STATUS); if (status != null && !InputFile.STATUS_SAME.equals(status)) { String componentKey = inputFile.attribute(DefaultInputFile.ATTRIBUTE_COMPONENT_KEY); + String componentDeprecatedKey = inputFile.attribute(DefaultInputFile.ATTRIBUTE_COMPONENT_DEPRECATED_KEY); if (componentKey != null) { - componentKeys.add(componentKey); + componentKeys.put(componentKey, componentDeprecatedKey); } } } @@ -52,11 +53,16 @@ class IncrementalComponentSelector extends ComponentSelector { @Override boolean register(Issue issue) { - return componentKeys.contains(issue.componentKey()); + return componentKeys.keySet().contains(issue.componentKey()); } @Override Set<String> componentKeys() { - return componentKeys; + return componentKeys.keySet(); + } + + @Override + String getDeprecatedKey(String componentKey) { + return componentKeys.get(componentKey); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/JsonReport.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/JsonReport.java index cca87185e97..b0d46450130 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/JsonReport.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/JsonReport.java @@ -41,7 +41,11 @@ import org.sonar.batch.events.BatchStepEvent; import org.sonar.batch.events.EventBus; import org.sonar.batch.issue.IssueCache; -import java.io.*; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -66,13 +70,13 @@ public class JsonReport implements BatchComponent { private UserFinder userFinder; public JsonReport(Settings settings, ModuleFileSystem fileSystem, Server server, RuleFinder ruleFinder, IssueCache issueCache, - EventBus eventBus, ComponentSelectorFactory componentSelectorFactory, AnalysisMode mode, UserFinder userFinder) { + EventBus eventBus, ComponentSelectorFactory componentSelectorFactory, AnalysisMode mode, UserFinder userFinder) { this(settings, fileSystem, server, ruleFinder, issueCache, eventBus, componentSelectorFactory.create(), mode, userFinder); } @VisibleForTesting JsonReport(Settings settings, ModuleFileSystem fileSystem, Server server, RuleFinder ruleFinder, IssueCache issueCache, - EventBus eventBus, ComponentSelector componentSelector, AnalysisMode analysisMode, UserFinder userFinder) { + EventBus eventBus, ComponentSelector componentSelector, AnalysisMode analysisMode, UserFinder userFinder) { this.settings = settings; this.fileSystem = fileSystem; this.server = server; @@ -141,7 +145,7 @@ public class JsonReport implements BatchComponent { json .beginObject() .name("key").value(issue.key()) - .name("component").value(issue.componentKey()) + .name("component").value(componentSelector.getDeprecatedKey(issue.componentKey())) .name("line").value(issue.line()) .name("message").value(issue.message()) .name("severity").value(issue.severity()) @@ -179,7 +183,7 @@ public class JsonReport implements BatchComponent { for (String componentKey : componentSelector.componentKeys()) { json .beginObject() - .name("key").value(componentKey) + .name("key").value(componentSelector.getDeprecatedKey(componentKey)) .endObject(); } json.endArray(); diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java index 2b31f72d2a8..2f6158496b9 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java @@ -114,10 +114,10 @@ public class DefaultIndexTest { @Test public void shouldIndexParentOfDeprecatedFiles() { - File file = new File("org/foo/Bar.java"); + File file = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false); assertThat(index.index(file)).isTrue(); - Directory reference = new Directory("org/foo"); + Directory reference = Directory.create("src/org/foo", "org/foo"); assertThat(index.getResource(reference).getName()).isEqualTo("org/foo"); assertThat(index.isIndexed(reference, true)).isTrue(); assertThat(index.isExcluded(reference)).isFalse(); @@ -127,15 +127,15 @@ public class DefaultIndexTest { @Test public void shouldIndexTreeOfResources() { - Directory directory = new Directory("org/foo"); - File file = new File("org/foo/Bar.java"); - file.setLanguage(Java.INSTANCE); + Directory directory = Directory.create("src/org/foo", "org/foo"); + File file = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", Java.INSTANCE, false); assertThat(index.index(directory)).isTrue(); assertThat(index.index(file, directory)).isTrue(); - File fileRef = new File("org/foo/Bar.java"); - assertThat(index.getResource(fileRef).getKey()).isEqualTo("org/foo/Bar.java"); + File fileRef = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false); + assertThat(index.getResource(fileRef).getKey()).isEqualTo("/src/org/foo/Bar.java"); + assertThat(index.getResource(fileRef).getDeprecatedKey()).isEqualTo("org/foo/Bar.java"); assertThat(index.getResource(fileRef).getLanguage().getKey()).isEqualTo("java"); assertThat(index.isIndexed(fileRef, true)).isTrue(); assertThat(index.isExcluded(fileRef)).isFalse(); @@ -156,12 +156,12 @@ public class DefaultIndexTest { @Test public void shouldNotIndexResourceIfParentNotIndexed() { - Directory directory = new Directory("org/other"); - File file = new File("org/foo/Bar.java"); + Directory directory = Directory.create("src/org/other", "org/other"); + File file = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false); assertThat(index.index(file, directory)).isFalse(); - File fileRef = new File("org/foo/Bar.java"); + File fileRef = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false); assertThat(index.isIndexed(directory, true)).isFalse(); assertThat(index.isIndexed(fileRef, true)).isFalse(); assertThat(index.isExcluded(fileRef)).isFalse(); @@ -176,7 +176,7 @@ public class DefaultIndexTest { public void shouldIndexEvenIfLocked() { lock.lock(); - Directory dir = new Directory("org/foo"); + Directory dir = Directory.create("src/org/foo", "org/foo"); assertThat(index.index(dir)).isTrue(); assertThat(index.isIndexed(dir, true)).isTrue(); } @@ -186,13 +186,13 @@ public class DefaultIndexTest { lock.setFailWhenLocked(true); lock.lock(); - Directory dir = new Directory("org/foo"); + Directory dir = Directory.create("src/org/foo", "org/foo"); index.index(dir); } @Test public void shouldBeExcluded() { - File file = new File("org/foo/ExcludedBar.java"); + File file = File.create("src/org/foo/ExcludedBar.java", "org/foo/ExcludedBar.java", null, false); assertThat(index.index(file)).isFalse(); assertThat(index.isIndexed(file, true)).isTrue(); assertThat(index.isIndexed(file, false)).isFalse(); @@ -201,7 +201,7 @@ public class DefaultIndexTest { @Test public void shouldIndexResourceWhenAddingMeasure() { - Resource dir = new Directory("org/foo"); + Resource dir = Directory.create("src/org/foo", "org/foo"); index.addMeasure(dir, new Measure("ncloc").setValue(50.0)); assertThat(index.isIndexed(dir, true)).isTrue(); @@ -213,7 +213,7 @@ public class DefaultIndexTest { */ @Test public void shouldNotFailWhenSavingViolationOnNullRule() { - File file = new File("org/foo/Bar.java"); + File file = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false); Violation violation = Violation.create((Rule) null, file); index.addViolation(violation); @@ -227,7 +227,7 @@ public class DefaultIndexTest { public void should_ignore_violation_on_unknown_rules() { Rule ruleWithoutID = Rule.create("repoKey", "ruleKey", "Rule"); - File file = new File("org/foo/Bar.java"); + File file = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false); Violation violation = Violation.create(ruleWithoutID, file); index.addViolation(violation); @@ -237,7 +237,7 @@ public class DefaultIndexTest { @Test public void should_get_violation() { Rule rule = Rule.create("repoKey", "ruleKey", "Rule"); - File file = new File("org/foo/Bar.java"); + File file = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false); Violation violation = Violation.create(rule, file); when(deprecatedViolations.get(anyString())).thenReturn(newArrayList(violation)); @@ -249,7 +249,7 @@ public class DefaultIndexTest { @Test public void should_get_filtered_violation_with_off_switch_mode() { Rule rule = Rule.create("repoKey", "ruleKey", "Rule"); - File file = new File("org/foo/Bar.java"); + File file = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false); Violation violation = Violation.create(rule, file).setSwitchedOff(true); when(deprecatedViolations.get(anyString())).thenReturn(newArrayList(violation)); @@ -262,7 +262,7 @@ public class DefaultIndexTest { @Test public void should_get_filtered_violation_with_on_switch_mode() { Rule rule = Rule.create("repoKey", "ruleKey", "Rule"); - File file = new File("org/foo/Bar.java"); + File file = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false); Violation violation = Violation.create(rule, file).setSwitchedOff(false); when(deprecatedViolations.get(anyString())).thenReturn(newArrayList(violation)); diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java index 6bf3829f442..4c0d954e695 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java @@ -25,6 +25,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.api.database.model.ResourceModel; +import org.sonar.api.resources.Directory; import org.sonar.api.resources.JavaFile; import org.sonar.api.resources.JavaPackage; import org.sonar.api.resources.Library; @@ -144,19 +145,8 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase { ResourcePersister persister = new DefaultResourcePersister(getSession(), mock(ResourcePermissions.class), snapshotCache, resourceCache); persister.saveProject(singleProject, null); - persister.saveResource(singleProject, new JavaPackage("org.foo").setEffectiveKey("foo:org.foo").setPath("/src/main/java/org/foo")); - - // check that the directory is attached to the project - checkTables("shouldSaveNewDirectory", new String[] {"build_date", "created_at"}, "projects", "snapshots"); - } - - @Test - public void shouldSaveNewDirectoryAndNormalizePath() { - setupData("shared"); - - ResourcePersister persister = new DefaultResourcePersister(getSession(), mock(ResourcePermissions.class), snapshotCache, resourceCache); - persister.saveProject(singleProject, null); - persister.saveResource(singleProject, new JavaPackage("org.foo").setEffectiveKey("foo:org.foo").setPath("src/main/java/org/foo/")); + persister.saveResource(singleProject, + Directory.create("src/main/java/org/foo", "org.foo").setEffectiveKey("foo:/src/main/java/org/foo").setDeprecatedEffectiveKey("foo:org.foo")); // check that the directory is attached to the project checkTables("shouldSaveNewDirectory", new String[] {"build_date", "created_at"}, "projects", "snapshots"); diff --git a/sonar-batch/src/test/java/org/sonar/batch/phases/DecoratorsExecutorTest.java b/sonar-batch/src/test/java/org/sonar/batch/phases/DecoratorsExecutorTest.java index 6330c25c828..7c9a9f762b8 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/phases/DecoratorsExecutorTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/phases/DecoratorsExecutorTest.java @@ -19,8 +19,6 @@ */ package org.sonar.batch.phases; -import org.sonar.core.measure.MeasurementFilters; - import org.junit.Test; import org.sonar.api.batch.BatchExtensionDictionnary; import org.sonar.api.batch.Decorator; @@ -32,6 +30,8 @@ import org.sonar.api.resources.Resource; import org.sonar.api.utils.SonarException; import org.sonar.batch.DefaultDecoratorContext; import org.sonar.batch.events.EventBus; +import org.sonar.core.measure.MeasurementFilters; + import static org.hamcrest.number.OrderingComparisons.greaterThanOrEqualTo; import static org.hamcrest.number.OrderingComparisons.lessThan; import static org.junit.Assert.assertThat; @@ -67,13 +67,13 @@ public class DecoratorsExecutorTest { doThrow(new SonarException()).when(decorator).decorate(any(Resource.class), any(DecoratorContext.class)); DecoratorsExecutor executor = new DecoratorsExecutor(mock(BatchExtensionDictionnary.class), new Project("key"), mock(SonarIndex.class), - mock(EventBus.class), mock(MeasurementFilters.class)); + mock(EventBus.class), mock(MeasurementFilters.class)); try { - executor.executeDecorator(decorator, mock(DefaultDecoratorContext.class), new File("org/foo/Bar.java")); + executor.executeDecorator(decorator, mock(DefaultDecoratorContext.class), File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false)); fail("Exception has not been thrown"); } catch (SonarException e) { - assertThat(e.getMessage(), containsString("org/foo/Bar.java")); + assertThat(e.getMessage(), containsString("/src/org/foo/Bar.java")); } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/phases/FileIndexerTest.java b/sonar-batch/src/test/java/org/sonar/batch/phases/FileIndexerTest.java index d961d85f856..0ee7ce9b638 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/phases/FileIndexerTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/phases/FileIndexerTest.java @@ -103,13 +103,14 @@ public class FileIndexerTest { FileIndexer indexer = new FileIndexer(project, fs, new Languages(Java.INSTANCE), sonarIndex, settings); indexer.execute(); - verify(sonarIndex).index(new JavaFile("foo.bar.Foo", false).setPath("/src/main/java/foo/bar/Foo.java")); - verify(sonarIndex).index(new JavaFile("foo.bar.Foo", false).setPath("/src/main/java2/foo/bar/Foo.java")); + 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>() { @Override public boolean matches(Object arg0) { JavaFile javaFile = (JavaFile) arg0; - return javaFile.getKey().equals("foo.bar.FooTest") && javaFile.getPath().equals("/src/test/java/foo/bar/FooTest.java") + return javaFile.getKey().equals("/src/test/java/foo/bar/FooTest.java") && javaFile.getDeprecatedKey().equals("foo.bar.FooTest") + && javaFile.getPath().equals("/src/test/java/foo/bar/FooTest.java") && javaFile.getQualifier().equals(Qualifiers.UNIT_TEST_FILE); } })); @@ -130,9 +131,9 @@ public class FileIndexerTest { FileIndexer indexer = new FileIndexer(project, fs, new Languages(cobolLanguage), sonarIndex, settings); indexer.execute(); - verify(sonarIndex).index(new org.sonar.api.resources.File("foo/bar/Foo.cbl").setPath("/src/foo/bar/Foo.cbl")); - verify(sonarIndex).index(new org.sonar.api.resources.File("foo/bar/Foo.cbl").setPath("/src2/foo/bar/Foo.cbl")); - verify(sonarIndex).index(new org.sonar.api.resources.File("foo/bar/FooTest.cbl").setPath("/src/test/foo/bar/FooTest.cbl")); + verify(sonarIndex).index(org.sonar.api.resources.File.create("/src/foo/bar/Foo.cbl", "foo/bar/Foo.cbl", cobolLanguage, false)); + verify(sonarIndex).index(org.sonar.api.resources.File.create("/src2/foo/bar/Foo.cbl", "foo/bar/Foo.cbl", cobolLanguage, false)); + verify(sonarIndex).index(org.sonar.api.resources.File.create("/src/test/foo/bar/FooTest.cbl", "foo/bar/FooTest.cbl", cobolLanguage, true)); } @Test @@ -149,13 +150,13 @@ public class FileIndexerTest { FileIndexer indexer = new FileIndexer(project, fs, new Languages(Java.INSTANCE), sonarIndex, settings); indexer.execute(); - Resource sonarFile = new JavaFile("foo.bar.Foo", false).setPath("/src/main/java/foo/bar/Foo.java"); + Resource sonarFile = JavaFile.create("src/main/java/foo/bar/Foo.java", "foo/bar/Foo.java", false); verify(sonarIndex).index(sonarFile); verify(sonarIndex).setSource(sonarFile, "sample code"); } @Test - public void should_use_mac_roman_charset_forR_reading_source_files() throws Exception { + public void should_use_mac_roman_charset_for_reading_source_files() throws Exception { String encoding = "MacRoman"; String testFile = "MacRomanEncoding.java"; fileEncodingTest(encoding, testFile); @@ -189,7 +190,7 @@ public class FileIndexerTest { FileIndexer indexer = new FileIndexer(project, fs, new Languages(Java.INSTANCE), sonarIndex, settings); indexer.execute(); - Resource sonarFile = new JavaFile("foo.bar.Foo", false).setPath("/src/main/java/foo/bar/Foo.java"); + Resource sonarFile = JavaFile.create("src/main/java/foo/bar/Foo.java", "foo/bar/Foo.java", false); verify(sonarIndex).setSource(eq(sonarFile), argThat(new ArgumentMatcher<String>() { @Override @@ -216,7 +217,7 @@ public class FileIndexerTest { FileIndexer indexer = new FileIndexer(project, fs, new Languages(Java.INSTANCE), sonarIndex, settings); indexer.execute(); - Resource sonarFile = new JavaFile("foo.bar.Foo", false).setPath("/src/main/java/foo/bar/Foo.java"); + Resource sonarFile = JavaFile.create("/src/main/java/foo/bar/Foo.java", "foo/bar/Foo.java", false); verify(sonarIndex).setSource(eq(sonarFile), argThat(new ArgumentMatcher<String>() { @Override diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ExclusionFiltersTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ExclusionFiltersTest.java index 8c913d24b79..62f844b7aa6 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ExclusionFiltersTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ExclusionFiltersTest.java @@ -144,8 +144,8 @@ public class ExclusionFiltersTest { settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "**/*Dao.c"); ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings)); - assertThat(filter.isIgnored(new File("org/sonar", "FooDao.c"))).isFalse(); - assertThat(filter.isIgnored(new File("org/sonar", "Foo.c"))).isTrue(); + assertThat(filter.isIgnored(File.create("src/org/sonar/FooDao.c", "org/sonar/FooDao.c", null, false))).isFalse(); + assertThat(filter.isIgnored(File.create("src/org/sonar/Foo.c", "org/sonar/Foo.c", null, false))).isTrue(); } @Test @@ -154,8 +154,8 @@ public class ExclusionFiltersTest { settings.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "**/*Dao.c"); ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings)); - assertThat(filter.isIgnored(new File("org/sonar", "FooDao.c"))).isTrue(); - assertThat(filter.isIgnored(new File("org/sonar", "Foo.c"))).isFalse(); + assertThat(filter.isIgnored(File.create("src/org/sonar/FooDao.c", "org/sonar/FooDao.c", null, false))).isTrue(); + assertThat(filter.isIgnored(File.create("src/org/sonar/Foo.c", "org/sonar/Foo.c", null, false))).isFalse(); } @Test @@ -164,8 +164,8 @@ public class ExclusionFiltersTest { settings.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "file:**/*Dao.c"); ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings)); - assertThat(filter.isIgnored(new File("org/sonar", "FooDao.c"))).isFalse(); - assertThat(filter.isIgnored(new File("org/sonar", "Foo.c"))).isFalse(); + assertThat(filter.isIgnored(File.create("src/org/sonar/FooDao.c", "org/sonar/FooDao.c", null, false))).isFalse(); + assertThat(filter.isIgnored(File.create("src/org/sonar/Foo.c", "org/sonar/Foo.c", null, false))).isFalse(); } @Test @@ -174,8 +174,8 @@ public class ExclusionFiltersTest { settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "file:**/*Dao.c"); ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings)); - assertThat(filter.isIgnored(new File("org/sonar", "FooDao.c"))).isFalse(); - assertThat(filter.isIgnored(new File("org/sonar", "Foo.c"))).isFalse(); + assertThat(filter.isIgnored(File.create("src/org/sonar/FooDao.c", "org/sonar/FooDao.c", null, false))).isFalse(); + assertThat(filter.isIgnored(File.create("src/org/sonar/Foo.c", "org/sonar/Foo.c", null, false))).isFalse(); } /** @@ -187,8 +187,8 @@ public class ExclusionFiltersTest { settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "**/*Dao.java"); ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings)); - assertThat(filter.isIgnored(new JavaFile("org.sonar", "FooDao"))).isFalse(); - assertThat(filter.isIgnored(new JavaFile("org.sonar", "Foo"))).isTrue(); + assertThat(filter.isIgnored(JavaFile.create("src/org/sonar/FooDao.java", "org/sonar/FooDao.java", false))).isFalse(); + assertThat(filter.isIgnored(JavaFile.create("src/org/sonar/Foo.java", "org/sonar/Foo.java", false))).isTrue(); } /** @@ -200,8 +200,8 @@ public class ExclusionFiltersTest { settings.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "**/*Dao.java"); ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings)); - assertThat(filter.isIgnored(new JavaFile("org.sonar", "FooDao"))).isTrue(); - assertThat(filter.isIgnored(new JavaFile("org.sonar", "Foo"))).isFalse(); + assertThat(filter.isIgnored(JavaFile.create("src/org/sonar/FooDao.java", "org/sonar/FooDao.java", false))).isTrue(); + assertThat(filter.isIgnored(JavaFile.create("src/org/sonar/Foo.java", "org/sonar/Foo.java", false))).isFalse(); } @Test diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/report/JsonReportTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/report/JsonReportTest.java index 0b0ce6bd1a1..5a09dfdbff4 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/report/JsonReportTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/report/JsonReportTest.java @@ -34,11 +34,14 @@ import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleFinder; import org.sonar.api.scan.filesystem.ModuleFileSystem; +import org.sonar.api.scan.filesystem.internal.DefaultInputFile; +import org.sonar.api.scan.filesystem.internal.InputFile; import org.sonar.api.user.User; import org.sonar.api.user.UserFinder; import org.sonar.batch.bootstrap.AnalysisMode; import org.sonar.batch.events.EventBus; import org.sonar.batch.issue.IssueCache; +import org.sonar.batch.scan.filesystem.InputFileCache; import org.sonar.core.user.DefaultUser; import org.sonar.test.TestUtils; @@ -82,14 +85,19 @@ public class JsonReportTest { mode = mock(AnalysisMode.class); when(mode.isPreview()).thenReturn(true); userFinder = mock(UserFinder.class); - jsonReport = new JsonReport(settings, fileSystem, server, ruleFinder, issueCache, mock(EventBus.class), new DefaultComponentSelector(), mode, userFinder); + InputFileCache inputFileCache = mock(InputFileCache.class); + InputFile inputFile = mock(InputFile.class); + when(inputFile.attribute(DefaultInputFile.ATTRIBUTE_COMPONENT_KEY)).thenReturn("struts:/src/main/java/org/apache/struts/Action.java"); + when(inputFile.attribute(DefaultInputFile.ATTRIBUTE_COMPONENT_DEPRECATED_KEY)).thenReturn("struts:org.apache.struts.Action"); + when(inputFileCache.all()).thenReturn(Arrays.asList(inputFile)); + jsonReport = new JsonReport(settings, fileSystem, server, ruleFinder, issueCache, mock(EventBus.class), new DefaultComponentSelector(inputFileCache), mode, userFinder); } @Test public void should_write_json() throws Exception { DefaultIssue issue = new DefaultIssue() .setKey("200") - .setComponentKey("struts:org.apache.struts.Action") + .setComponentKey("struts:/src/main/java/org/apache/struts/Action.java") .setRuleKey(RuleKey.of("squid", "AvoidCycles")) .setMessage("There are 2 cycles") .setSeverity("MINOR") @@ -120,7 +128,7 @@ public class JsonReportTest { RuleKey ruleKey = RuleKey.of("squid", "AvoidCycles"); DefaultIssue issue = new DefaultIssue() .setKey("200") - .setComponentKey("struts:org.apache.struts.Action") + .setComponentKey("struts:/src/main/java/org/apache/struts/Action.java") .setRuleKey(ruleKey) .setStatus(Issue.STATUS_CLOSED) .setResolution(Issue.RESOLUTION_FIXED) diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shared.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shared.xml index 2c2a08fa2d0..e2327ea28c9 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shared.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shared.xml @@ -3,7 +3,7 @@ <!-- other project --> <projects id="1000" scope="PRJ" qualifier="TRK" kee="my:key" root_id="[null]" name="Other project" long_name="Other" description="[null]" - enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="my:key"/> <snapshots purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="3000" project_id="1000" parent_snapshot_id="[null]" root_project_id="1000" root_snapshot_id="[null]" scope="PRJ" qualifier="TRK" created_at="2008-11-01 13:58:00.00" build_date="2008-11-01 13:58:00.00" version="[null]" path="" diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject-result.xml index 36c622aec03..daadbb905fd 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject-result.xml @@ -2,7 +2,7 @@ <projects id="1001" scope="PRJ" qualifier="TRK" kee="foo" root_id="[null]" name="Foo" long_name="Foo" description="some description" - enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="foo"/> <!-- old snapshot --> <snapshots purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="3001" project_id="1001" parent_snapshot_id="[null]" root_project_id="1001" root_snapshot_id="[null]" diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject.xml index 1f6a485baa5..7ddc14c2e1b 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject.xml @@ -3,7 +3,7 @@ <!-- This project has a root_id which should be set to NULL (SONAR-1700) --> <projects id="1001" scope="PRJ" qualifier="TRK" kee="foo" root_id="12345" name="name" long_name="long name" description="description" - enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="foo"/> <snapshots purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="3001" project_id="1001" parent_snapshot_id="[null]" root_project_id="1001" root_snapshot_id="[null]" scope="PRJ" qualifier="TRK" created_at="2010-12-23 00:00:00.00" build_date="2010-12-23 00:00:00.00" version="[null]" path="" diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveCopyProject-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveCopyProject-result.xml index c4cc6d2ff4a..4726d31facb 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveCopyProject-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveCopyProject-result.xml @@ -3,7 +3,7 @@ <!-- other project --> <projects id="1000" scope="PRJ" qualifier="TRK" kee="my:key" root_id="[null]" name="Other project" long_name="Other" description="[null]" - enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" /> + enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="my:key" /> <snapshots purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="3000" project_id="1000" parent_snapshot_id="[null]" root_project_id="1000" root_snapshot_id="[null]" scope="PRJ" qualifier="TRK" created_at="2008-11-01 13:58:00.00" build_date="2008-11-01 13:58:00.00" version="[null]" path="" @@ -13,7 +13,7 @@ <!-- new project --> <projects id="1001" scope="PRJ" qualifier="TRK" kee="foo" root_id="[null]" name="Foo" long_name="Foo" description="some description" - enabled="true" language="java" copy_resource_id="10" person_id="[null]" path="[null]" /> + enabled="true" language="java" copy_resource_id="10" person_id="[null]" path="[null]" deprecated_kee="foo" /> <snapshots purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="3001" project_id="1001" parent_snapshot_id="[null]" root_project_id="1001" root_snapshot_id="[null]" scope="PRJ" qualifier="TRK" created_at="2010-12-25 00:00:00.00" build_date="2010-12-25 00:00:00.00" version="[null]" path="" diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewDirectory-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewDirectory-result.xml index 9fc216c25c0..09cc4144e78 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewDirectory-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewDirectory-result.xml @@ -3,7 +3,7 @@ <!-- other project --> <projects id="1000" scope="PRJ" qualifier="TRK" kee="my:key" root_id="[null]" name="Other project" long_name="Other" description="[null]" - enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" /> + enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="my:key" /> <snapshots purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="3000" project_id="1000" parent_snapshot_id="[null]" root_project_id="1000" root_snapshot_id="[null]" scope="PRJ" qualifier="TRK" created_at="2008-11-01 13:58:00.00" build_date="2008-11-01 13:58:00.00" version="[null]" path="" @@ -13,18 +13,18 @@ <!-- new project --> <projects id="1001" scope="PRJ" qualifier="TRK" kee="foo" root_id="[null]" name="Foo" long_name="Foo" description="some description" - enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" /> + enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="foo" /> - <projects id="1002" scope="DIR" qualifier="PAC" kee="foo:org.foo" root_id="1001" + <projects id="1002" scope="DIR" qualifier="DIR" kee="foo:/src/main/java/org/foo" root_id="1001" name="org.foo" long_name="org.foo" description="[null]" - enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="/src/main/java/org/foo" /> + enabled="true" language="[null]" copy_resource_id="[null]" person_id="[null]" path="/src/main/java/org/foo" deprecated_kee="foo:org.foo" /> <snapshots purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="3001" project_id="1001" parent_snapshot_id="[null]" root_project_id="1001" root_snapshot_id="[null]" scope="PRJ" qualifier="TRK" created_at="2010-12-25 00:00:00.00" build_date="2010-12-25 00:00:00.00" version="[null]" path="" status="U" islast="false" depth="0"/> <snapshots purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="3002" project_id="1002" parent_snapshot_id="3001" root_project_id="1001" root_snapshot_id="3001" - scope="DIR" qualifier="PAC" created_at="2010-12-25 00:00:00.00" build_date="2010-12-25 00:00:00.00" version="[null]" path="3001." + scope="DIR" qualifier="DIR" created_at="2010-12-25 00:00:00.00" build_date="2010-12-25 00:00:00.00" version="[null]" path="3001." status="U" islast="false" depth="1"/> </dataset> diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewLibrary-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewLibrary-result.xml index 52fb16bf0b9..745203dabf1 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewLibrary-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewLibrary-result.xml @@ -3,7 +3,7 @@ <!-- other project --> <projects id="1000" scope="PRJ" qualifier="TRK" kee="my:key" root_id="[null]" name="Other project" long_name="Other" description="[null]" - enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" /> + enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="my:key" /> <snapshots purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="3000" project_id="1000" parent_snapshot_id="[null]" root_project_id="1000" root_snapshot_id="[null]" scope="PRJ" qualifier="TRK" created_at="2008-11-01 13:58:00.00" build_date="2008-11-01 13:58:00.00" version="[null]" path="" @@ -13,11 +13,11 @@ <!-- new project --> <projects id="1001" scope="PRJ" qualifier="TRK" kee="foo" root_id="[null]" name="Foo" long_name="Foo" description="some description" - enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" /> + enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="foo" /> <projects id="1002" scope="PRJ" qualifier="LIB" kee="junit:junit" root_id="[null]" name="junit:junit" long_name="junit:junit" description="[null]" - enabled="true" language="[null]" copy_resource_id="[null]" person_id="[null]" /> + enabled="true" language="[null]" copy_resource_id="[null]" person_id="[null]" deprecated_kee="junit:junit" /> <snapshots purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="3001" project_id="1001" parent_snapshot_id="[null]" root_project_id="1001" root_snapshot_id="[null]" scope="PRJ" qualifier="TRK" created_at="2010-12-25 00:00:00.00" build_date="2010-12-25 00:00:00.00" version="[null]" path="" diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewMultiModulesProject-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewMultiModulesProject-result.xml index 7a122621b18..69361522d29 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewMultiModulesProject-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewMultiModulesProject-result.xml @@ -3,7 +3,7 @@ <!-- other project --> <projects id="1000" scope="PRJ" qualifier="TRK" kee="my:key" root_id="[null]" name="Other project" long_name="Other" description="[null]" - enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" /> + enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="my:key" /> <snapshots purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="3000" project_id="1000" parent_snapshot_id="[null]" root_project_id="1000" root_snapshot_id="[null]" scope="PRJ" qualifier="TRK" created_at="2008-11-01 13:58:00.00" build_date="2008-11-01 13:58:00.00" version="[null]" path="" @@ -13,19 +13,19 @@ <!-- new project --> <projects id="1001" scope="PRJ" qualifier="TRK" kee="root" root_id="[null]" name="Root" long_name="Root" description="[null]" - enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" /> + enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="root" /> <projects id="1002" scope="PRJ" qualifier="BRC" kee="a" root_id="1001" name="A" long_name="A" description="[null]" - enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="/moduleA" /> + enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="/moduleA" deprecated_kee="a" /> <projects id="1003" scope="PRJ" qualifier="BRC" kee="b" root_id="1001" name="B" long_name="B" description="[null]" - enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="/moduleB" /> + enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="/moduleB" deprecated_kee="b" /> <projects id="1004" scope="PRJ" qualifier="BRC" kee="b1" root_id="1001" name="B1" long_name="B1" description="[null]" - enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="/moduleB1" /> + enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="/moduleB1" deprecated_kee="b1" /> <snapshots purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="3001" project_id="1001" root_project_id="1001" parent_snapshot_id="[null]" root_snapshot_id="[null]" diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewProject-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewProject-result.xml index 518d992a4a8..419ed6a6278 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewProject-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewProject-result.xml @@ -3,7 +3,7 @@ <!-- other project --> <projects id="1000" scope="PRJ" qualifier="TRK" kee="my:key" root_id="[null]" name="Other project" long_name="Other" description="[null]" - enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" /> + enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="my:key"/> <snapshots purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="3000" project_id="1000" parent_snapshot_id="[null]" root_project_id="1000" root_snapshot_id="[null]" scope="PRJ" qualifier="TRK" created_at="2008-11-01 13:58:00.00" build_date="2008-11-01 13:58:00.00" version="[null]" path="" @@ -13,7 +13,7 @@ <!-- new project --> <projects id="1001" scope="PRJ" qualifier="TRK" kee="foo" root_id="[null]" name="Foo" long_name="Foo" description="some description" - enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" /> + enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="foo" /> <snapshots purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="3001" project_id="1001" parent_snapshot_id="[null]" root_project_id="1001" root_snapshot_id="[null]" scope="PRJ" qualifier="TRK" created_at="2010-12-25 00:00:00.00" build_date="2010-12-25 00:00:00.00" version="[null]" path="" diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldUpdateExistingResource-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldUpdateExistingResource-result.xml index a668b5f3457..40b55dbf641 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldUpdateExistingResource-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldUpdateExistingResource-result.xml @@ -2,7 +2,7 @@ <projects id="1001" scope="PRJ" qualifier="TRK" kee="foo" root_id="[null]" name="new name" long_name="new name" description="new description" - enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" /> + enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="foo" /> <!-- old snapshot --> <snapshots purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="3001" project_id="1001" parent_snapshot_id="[null]" root_project_id="1001" root_snapshot_id="[null]" diff --git a/sonar-core/src/main/java/org/sonar/core/component/ComponentKeys.java b/sonar-core/src/main/java/org/sonar/core/component/ComponentKeys.java index 985b64c7699..550bf27eee2 100644 --- a/sonar-core/src/main/java/org/sonar/core/component/ComponentKeys.java +++ b/sonar-core/src/main/java/org/sonar/core/component/ComponentKeys.java @@ -55,6 +55,19 @@ public final class ComponentKeys { return key; } + public static String createDeprecatedKey(Project project, Resource resource) { + String key = resource.getKey(); + if (!StringUtils.equals(Scopes.PROJECT, resource.getScope())) { + // not a project nor a library + key = new StringBuilder(ResourceModel.KEY_SIZE) + .append(project.getKey()) + .append(':') + .append(resource.getDeprecatedKey()) + .toString(); + } + return key; + } + /** * <p>Test if given parameter is valid for a project/module. Valid format is:</p> * <ul> diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java index 7b51ce46344..1a518f9f8b9 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java @@ -33,7 +33,7 @@ import java.util.List; */ public class DatabaseVersion implements BatchComponent, ServerComponent { - public static final int LAST_VERSION = 487; + public static final int LAST_VERSION = 488; public static enum Status { UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL diff --git a/sonar-core/src/main/java/org/sonar/core/resource/ResourceDto.java b/sonar-core/src/main/java/org/sonar/core/resource/ResourceDto.java index eeae6e4d053..e7c062b86f6 100644 --- a/sonar-core/src/main/java/org/sonar/core/resource/ResourceDto.java +++ b/sonar-core/src/main/java/org/sonar/core/resource/ResourceDto.java @@ -25,6 +25,7 @@ public class ResourceDto { private Long id; private String key; + private String deprecatedKey; private String name; private String longName; private Long rootId; @@ -65,6 +66,15 @@ public class ResourceDto { return this; } + public String getDeprecatedKey() { + return deprecatedKey; + } + + public ResourceDto setDeprecatedKey(String s) { + this.deprecatedKey = s; + return this; + } + public Long getRootId() { return rootId; } diff --git a/sonar-core/src/main/java/org/sonar/core/resource/ResourceKeyUpdaterDao.java b/sonar-core/src/main/java/org/sonar/core/resource/ResourceKeyUpdaterDao.java index 1e99e4baf5d..869d6091e7a 100644 --- a/sonar-core/src/main/java/org/sonar/core/resource/ResourceKeyUpdaterDao.java +++ b/sonar-core/src/main/java/org/sonar/core/resource/ResourceKeyUpdaterDao.java @@ -22,6 +22,7 @@ package org.sonar.core.resource; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; +import org.apache.commons.lang.StringUtils; import org.apache.ibatis.session.SqlSession; import org.sonar.core.persistence.MyBatis; @@ -31,8 +32,8 @@ import java.util.Map; import java.util.Set; /** - * Class used to rename the key of a project and its resources. - * + * Class used to rename the key of a project and its resources. + * * @since 3.2 */ public class ResourceKeyUpdaterDao { @@ -120,6 +121,10 @@ public class ResourceKeyUpdaterDao { for (ResourceDto resource : resources) { String resourceKey = resource.getKey(); resource.setKey(newKey + resourceKey.substring(oldKey.length(), resourceKey.length())); + String resourceDeprecatedKey = resource.getDeprecatedKey(); + if (StringUtils.isNotBlank(resourceDeprecatedKey)) { + resource.setDeprecatedKey(newKey + resourceDeprecatedKey.substring(oldKey.length(), resourceDeprecatedKey.length())); + } mapper.update(resource); } } diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql index 281b89e9e26..b39afa8b967 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql @@ -199,6 +199,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('484'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('485'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('486'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('487'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('488'); INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null); ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2; diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl index 3a5a5ef0b22..091220084ca 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl @@ -271,6 +271,7 @@ CREATE TABLE "PROJECTS" ( "SCOPE" VARCHAR(3), "QUALIFIER" VARCHAR(10), "KEE" VARCHAR(400), + "DEPRECATED_KEE" VARCHAR(400), "PATH" VARCHAR(2000), "ROOT_ID" INTEGER, "LANGUAGE" VARCHAR(20), diff --git a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceKeyUpdaterMapper.xml b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceKeyUpdaterMapper.xml index 3995965d6c2..6f50a88e8c1 100644 --- a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceKeyUpdaterMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceKeyUpdaterMapper.xml @@ -6,6 +6,7 @@ <resultMap id="resourceResultMap" type="Resource"> <id property="id" column="id"/> <result property="key" column="kee"/> + <result property="deprecatedKey" column="deprecated_kee"/> <result property="rootId" column="root_id"/> <result property="scope" column="scope"/> </resultMap> @@ -27,12 +28,12 @@ <select id="selectDescendantProjects" parameterType="long" resultMap="resourceResultMap"> select * from projects where scope='PRJ' and root_id=#{id} </select> - + <update id="update" parameterType="Resource"> - update projects - set kee = #{key} + update projects + set kee = #{key}, deprecated_kee = #{deprecatedKey} where id = #{id} </update> - + </mapper> diff --git a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml index f1ad0f06c26..e2d0d0a4745 100644 --- a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml @@ -6,6 +6,7 @@ <sql id="resourceColumns"> p.id, p.kee as key, + p.deprecated_kee as deprecatedKey, p.name as name, p.long_name as longName, p.root_id as rootId, @@ -253,17 +254,17 @@ <insert id="insert" parameterType="Resource" keyColumn="id" useGeneratedKeys="true" keyProperty="id"> insert into projects - (name, long_name, description, scope, qualifier, kee, path, language, root_id, copy_resource_id, person_id, enabled, created_at) + (name, long_name, description, scope, qualifier, kee, deprecated_kee, path, language, root_id, copy_resource_id, person_id, enabled, created_at) values ( #{name}, #{longName}, #{description}, #{scope}, #{qualifier}, - #{key}, #{path}, #{language}, #{rootId}, #{copyResourceId}, + #{key}, #{deprecatedKey}, #{path}, #{language}, #{rootId}, #{copyResourceId}, #{personId}, #{enabled}, #{createdAt} ) </insert> <update id="update" parameterType="Resource"> update projects set name=#{name}, long_name=#{longName}, description=#{description}, - scope=#{scope}, qualifier=#{qualifier}, kee=#{key}, path=#{path}, + scope=#{scope}, qualifier=#{qualifier}, kee=#{key}, deprecated_kee=#{deprecatedKey}, path=#{path}, language=#{language}, root_id=#{rootId}, copy_resource_id=#{copyResourceId}, person_id=#{personId}, enabled=#{enabled} where id=#{id} </update> diff --git a/sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java b/sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java index 9287ea60fce..e758668c70c 100644 --- a/sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java +++ b/sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java @@ -33,8 +33,9 @@ public class ComponentKeysTest { Project project = new Project("my_project"); assertThat(ComponentKeys.createKey(project, project)).isEqualTo("my_project"); - JavaPackage javaPackage = new JavaPackage("org.foo"); - assertThat(ComponentKeys.createKey(project, javaPackage)).isEqualTo("my_project:org.foo"); + JavaPackage javaPackage = JavaPackage.create("src/org/foo", "org.foo"); + assertThat(ComponentKeys.createKey(project, javaPackage)).isEqualTo("my_project:/src/org/foo"); + assertThat(ComponentKeys.createDeprecatedKey(project, javaPackage)).isEqualTo("my_project:org.foo"); Library library = new Library("junit:junit", "4.7"); assertThat(ComponentKeys.createKey(project, library)).isEqualTo("junit:junit"); diff --git a/sonar-core/src/test/java/org/sonar/core/issue/IssueNotificationsTest.java b/sonar-core/src/test/java/org/sonar/core/issue/IssueNotificationsTest.java index 1b817929d45..a54bb58f8a0 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/IssueNotificationsTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/IssueNotificationsTest.java @@ -35,7 +35,6 @@ import org.sonar.api.resources.File; import org.sonar.api.resources.Project; import org.sonar.api.utils.DateUtils; import org.sonar.core.component.ResourceComponent; -import org.sonar.core.i18n.RuleI18nManager; import java.util.Arrays; import java.util.Date; @@ -133,18 +132,18 @@ public class IssueNotificationsTest { .setAssignee("freddy") .setFieldChange(context, "resolution", null, "FIXED") .setSendNotifications(true) - .setComponentKey("struts:Action") + .setComponentKey("struts:Action.java") .setProjectKey("struts"); DefaultIssueQueryResult queryResult = new DefaultIssueQueryResult(Arrays.<Issue>asList(issue)); queryResult.addProjects(Arrays.<Component>asList(new Project("struts"))); - queryResult.addComponents(Arrays.<Component>asList(new ResourceComponent(new File("struts:Action").setEffectiveKey("struts:Action")))); + queryResult.addComponents(Arrays.<Component>asList(new ResourceComponent(File.create("Action.java", "Action.java", null, false).setEffectiveKey("struts:Action.java")))); Notification notification = issueNotifications.sendChanges(issue, context, queryResult).get(0); assertThat(notification.getFieldValue("message")).isEqualTo("the message"); assertThat(notification.getFieldValue("key")).isEqualTo("ABCDE"); - assertThat(notification.getFieldValue("componentKey")).isEqualTo("struts:Action"); - assertThat(notification.getFieldValue("componentName")).isEqualTo("struts:Action"); + assertThat(notification.getFieldValue("componentKey")).isEqualTo("struts:Action.java"); + assertThat(notification.getFieldValue("componentName")).isEqualTo("/Action.java"); assertThat(notification.getFieldValue("old.resolution")).isNull(); assertThat(notification.getFieldValue("new.resolution")).isEqualTo("FIXED"); Mockito.verify(manager).scheduleForSending(eq(Arrays.asList(notification))); diff --git a/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java b/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java index bc8bd0a7c9d..5420558b1eb 100644 --- a/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java @@ -213,7 +213,8 @@ public class ResourceDaoTest extends AbstractDaoTestCase { setupData("update"); ResourceDto project = new ResourceDto() - .setKey("org.struts:struts").setScope(Scopes.PROJECT).setQualifier(Qualifiers.PROJECT) + .setKey("org.struts:struts") + .setDeprecatedKey("deprecated key").setScope(Scopes.PROJECT).setQualifier(Qualifiers.PROJECT) .setName("Struts").setLongName("Apache Struts").setLanguage("java").setDescription("MVC Framework") .setPath("/foo/bar") .setId(1L); @@ -229,10 +230,12 @@ public class ResourceDaoTest extends AbstractDaoTestCase { setupData("insert"); ResourceDto file1 = new ResourceDto() - .setKey("org.struts:struts:org.struts.Action").setScope(Scopes.FILE).setQualifier(Qualifiers.FILE) + .setKey("org.struts:struts:/src/main/java/org/struts/Action.java") + .setDeprecatedKey("org.struts:struts:org.struts.Action").setScope(Scopes.FILE).setQualifier(Qualifiers.FILE) .setLanguage("java").setName("Action").setLongName("org.struts.Action").setPath("/foo/bar"); ResourceDto file2 = new ResourceDto() - .setKey("org.struts:struts:org.struts.Filter").setScope(Scopes.FILE).setQualifier(Qualifiers.FILE) + .setKey("org.struts:struts:/src/main/java/org/struts/Filter.java") + .setDeprecatedKey("org.struts:struts:org.struts.Filter").setScope(Scopes.FILE).setQualifier(Qualifiers.FILE) .setLanguage("java").setName("Filter").setLongName("org.struts.Filter"); dao.insertOrUpdate(file1, file2); @@ -251,10 +254,12 @@ public class ResourceDaoTest extends AbstractDaoTestCase { setupData("insert"); ResourceDto file1 = new ResourceDto() - .setKey("org.struts:struts:org.struts.Action").setScope(Scopes.FILE).setQualifier(Qualifiers.FILE) + .setKey("org.struts:struts:/src/main/java/org/struts/Action.java") + .setDeprecatedKey("org.struts:struts:org.struts.Action").setScope(Scopes.FILE).setQualifier(Qualifiers.FILE) .setLanguage("java").setName("Action").setLongName("org.struts.Action"); ResourceDto file2 = new ResourceDto() - .setKey("org.struts:struts:org.struts.Filter").setScope(Scopes.FILE).setQualifier(Qualifiers.FILE) + .setKey("org.struts:struts:/src/main/java/org/struts/Filter.java") + .setDeprecatedKey("org.struts:struts:org.struts.Filter").setScope(Scopes.FILE).setQualifier(Qualifiers.FILE) .setLanguage("java").setName("Filter").setLongName("org.struts.Filter"); SqlSession session = getMyBatis().openSession(); diff --git a/sonar-core/src/test/java/org/sonar/core/user/AuthorDaoTest.java b/sonar-core/src/test/java/org/sonar/core/user/AuthorDaoTest.java index 5d8176e0383..c934cd619ac 100644 --- a/sonar-core/src/test/java/org/sonar/core/user/AuthorDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/user/AuthorDaoTest.java @@ -75,7 +75,8 @@ public class AuthorDaoTest extends AbstractDaoTestCase { dao.insertAuthorAndDeveloper(login, resourceDto); checkTables("shouldInsertAuthorAndDeveloper", - new String[] {"created_at", "updated_at", "copy_resource_id", "description", "enabled", "kee", "path", "language", "long_name", "person_id", "root_id", "scope"}, + new String[] {"created_at", "updated_at", "copy_resource_id", "description", "enabled", "kee", "deprecated_kee", "path", "language", "long_name", "person_id", "root_id", + "scope"}, "authors", "projects"); } @@ -106,7 +107,8 @@ public class AuthorDaoTest extends AbstractDaoTestCase { } checkTables("shouldPreventAuthorsAndDevelopersDuplication", - new String[] {"created_at", "updated_at", "copy_resource_id", "description", "enabled", "kee", "path", "language", "long_name", "person_id", "root_id", "scope"}, + new String[] {"created_at", "updated_at", "copy_resource_id", "description", "enabled", "kee", "deprecated_kee", "path", "language", "long_name", "person_id", "root_id", + "scope"}, "authors", "projects"); } } diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles-result.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles-result.xml index 3d2063f3797..fa6f544a993 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles-result.xml @@ -9,17 +9,17 @@ What has been changed : purge_status=1 on snapshot 4 (PRJ) and snapshots 5 and 6 <!-- the project --> <projects id="1" enabled="[true]" root_id="[null]" created_at="[null]" long_name="[null]" scope="PRJ" qualifier="TRK" kee="project" name="project" - description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" /> + description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="[null]" /> <!-- the directory --> <projects id="2" enabled="[true]" root_id="1" created_at="[null]" long_name="[null]" scope="DIR" qualifier="DIR" kee="project:my/dir" name="my/dir" - description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" /> + description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="[null]"/> <!-- the file --> <projects id="3" enabled="[true]" root_id="1" created_at="[null]" long_name="[null]" scope="FIL" qualifier="FIL" kee="project:my/dir/File.java" name="my/dir/File.java" - description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" /> + description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="[null]" /> <!-- do not purge last snapshots --> <snapshots id="1" diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles.xml index 292bc88e7c8..7e4db89bd58 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles.xml @@ -3,17 +3,17 @@ <!-- the project --> <projects id="1" enabled="[true]" root_id="[null]" created_at="[null]" long_name="[null]" scope="PRJ" qualifier="TRK" kee="project" name="project" - description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]"/> + description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="[null]"/> <!-- the directory --> <projects id="2" enabled="[true]" root_id="1" created_at="[null]" long_name="[null]" scope="DIR" qualifier="DIR" kee="project:my/dir" name="my/dir" - description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" /> + description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="[null]" /> <!-- the file --> <projects id="3" enabled="[true]" root_id="1" created_at="[null]" long_name="[null]" scope="FIL" qualifier="FIL" kee="project:my/dir/File.java" name="my/dir/File.java" - description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" /> + description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="[null]" /> <!-- do not purge last snapshots --> <snapshots id="1" diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDisableResourcesWithoutLastSnapshot-result.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDisableResourcesWithoutLastSnapshot-result.xml index 0b1651d2ae2..8857dc5ddca 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDisableResourcesWithoutLastSnapshot-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDisableResourcesWithoutLastSnapshot-result.xml @@ -10,17 +10,17 @@ What has been changed : <!-- the project --> <projects id="1" enabled="[false]" root_id="[null]" created_at="[null]" long_name="[null]" scope="PRJ" qualifier="TRK" kee="project" name="project" - description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" /> + description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="[null]" /> <!-- the directory --> <projects id="2" enabled="[false]" root_id="1" created_at="[null]" long_name="[null]" scope="DIR" qualifier="DIR" kee="project:my/dir" name="my/dir" - description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" /> + description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="[null]" /> <!-- the file --> <projects id="3" enabled="[false]" root_id="1" created_at="[null]" long_name="[null]" scope="FIL" qualifier="FIL" kee="project:my/dir/File.java" name="my/dir/File.java" - description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" /> + description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="[null]" /> <snapshots id="1" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]" diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDisableResourcesWithoutLastSnapshot.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDisableResourcesWithoutLastSnapshot.xml index 61e32cc1f08..fbda7d8a16d 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDisableResourcesWithoutLastSnapshot.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDisableResourcesWithoutLastSnapshot.xml @@ -3,17 +3,17 @@ <!-- the project --> <projects id="1" enabled="[true]" root_id="[null]" created_at="[null]" long_name="[null]" scope="PRJ" qualifier="TRK" kee="project" name="project" - description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" /> + description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="[null]" /> <!-- the directory --> <projects id="2" enabled="[true]" root_id="1" created_at="[null]" long_name="[null]" scope="DIR" qualifier="DIR" kee="project:my/dir" name="my/dir" - description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" /> + description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="[null]" /> <!-- the file --> <projects id="3" enabled="[true]" root_id="1" created_at="[null]" long_name="[null]" scope="FIL" qualifier="FIL" kee="project:my/dir/File.java" name="my/dir/File.java" - description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" /> + description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="[null]" /> <snapshots id="1" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]" diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldPurgeProject-result.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldPurgeProject-result.xml index 9844d964885..917079471ee 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldPurgeProject-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldPurgeProject-result.xml @@ -3,7 +3,7 @@ <!-- the project --> <projects id="1" enabled="[true]" created_at="[null]" long_name="[null]" scope="PRJ" qualifier="TRK" kee="project" name="project" - root_id="[null]" description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" /> + root_id="[null]" description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="[null]" /> <!-- snapshot already purged --> diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldPurgeProject.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldPurgeProject.xml index 7ab36ca2e6c..7fcfe0326af 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldPurgeProject.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldPurgeProject.xml @@ -3,7 +3,7 @@ <!-- the project --> <projects id="1" enabled="[true]" created_at="[null]" long_name="[null]" scope="PRJ" qualifier="TRK" kee="project" name="project" - root_id="[null]" description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" /> + root_id="[null]" description="[null]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="[null]" /> <!-- snapshot already purged --> diff --git a/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/insert-result.xml b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/insert-result.xml index aeadd58b983..3e2403d4518 100644 --- a/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/insert-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/insert-result.xml @@ -1,11 +1,11 @@ <dataset> - <projects id="1" root_id="[null]" scope="FIL" qualifier="FIL" kee="org.struts:struts:org.struts.Action" name="Action" + <projects id="1" root_id="[null]" scope="FIL" qualifier="FIL" kee="org.struts:struts:/src/main/java/org/struts/Action.java" name="Action" description="[null]" long_name="org.struts.Action" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="/foo/bar" /> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="/foo/bar" deprecated_kee="org.struts:struts:org.struts.Action" /> - <projects id="2" root_id="[null]" scope="FIL" qualifier="FIL" kee="org.struts:struts:org.struts.Filter" name="Filter" + <projects id="2" root_id="[null]" scope="FIL" qualifier="FIL" kee="org.struts:struts:/src/main/java/org/struts/Filter.java" name="Filter" description="[null]" long_name="org.struts.Filter" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" /> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.struts:struts:org.struts.Filter" /> </dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/update-result.xml b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/update-result.xml index 60bc0572238..ba1fcbfe097 100644 --- a/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/update-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/update-result.xml @@ -2,6 +2,6 @@ <projects id="1" root_id="[null]" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts" description="MVC Framework" long_name="Apache Struts" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="/foo/bar"/> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="/foo/bar" deprecated_kee="deprecated key"/> </dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/update.xml b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/update.xml index fdd155a71a6..9ba62dc1976 100644 --- a/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/update.xml +++ b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/update.xml @@ -2,6 +2,6 @@ <projects id="1" root_id="200" scope="PRJ" qualifier="TRK" kee="old key" name="old name" description="old name" long_name="old long name" - enabled="[false]" language="old" copy_resource_id="2" person_id="3" created_at="[null]" path="/old/foo/bar"/> + enabled="[false]" language="old" copy_resource_id="2" person_id="3" created_at="[null]" path="/old/foo/bar" deprecated_kee="old deprecated key"/> </dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/resource/ResourceKeyUpdaterDaoTest/shared.xml b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceKeyUpdaterDaoTest/shared.xml index 7a1469afe6b..e3c65aea1e3 100644 --- a/sonar-core/src/test/resources/org/sonar/core/resource/ResourceKeyUpdaterDaoTest/shared.xml +++ b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceKeyUpdaterDaoTest/shared.xml @@ -3,48 +3,48 @@ <!-- root project --> <projects id="1" root_id="[null]" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts" description="[null]" long_name="Apache Struts" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.struts:struts"/> <!-- **************** First sub project **************** --> <projects id="2" root_id="1" kee="org.struts:struts-core" name="Struts Core" scope="PRJ" qualifier="BRC" long_name="Struts Core" - description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.struts:struts-core"/> <!-- directory --> - <projects long_name="org.struts" id="3" scope="DIR" qualifier="PAC" kee="org.struts:struts-core:org.struts" + <projects long_name="org.struts" id="3" scope="DIR" qualifier="DIR" kee="org.struts:struts-core:/src/org/struts" name="org.struts" root_id="2" description="[null]" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.struts:struts-core:org.struts"/> <!-- file --> - <projects long_name="org.struts.RequestContext" id="4" scope="FIL" qualifier="CLA" kee="org.struts:struts-core:org.struts.RequestContext" + <projects long_name="org.struts.RequestContext" id="4" scope="FIL" qualifier="CLA" kee="org.struts:struts-core:/src/org/struts/RequestContext.java" name="RequestContext" root_id="2" description="[null]" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.struts:struts-core:org.struts.RequestContext"/> <!-- **************** Second sub project **************** --> <projects id="5" root_id="1" kee="org.struts:struts-ui" name="Struts UI" scope="PRJ" qualifier="BRC" long_name="Struts UI" - description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.struts:struts-ui"/> <!-- directory --> - <projects long_name="org.struts" id="6" scope="DIR" qualifier="PAC" kee="org.struts:struts-ui:org.struts" + <projects long_name="org.struts" id="6" scope="DIR" qualifier="DIR" kee="org.struts:struts-ui:/src/org/struts" name="org.struts" root_id="5" description="[null]" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.struts:struts-ui:org.struts"/> <!-- file --> - <projects long_name="org.struts.RequestContext" id="7" scope="FIL" qualifier="CLA" kee="org.struts:struts-ui:org.struts.RequestContext" + <projects long_name="org.struts.RequestContext" id="7" scope="FIL" qualifier="CLA" kee="org.struts:struts-ui:/src/org/struts/RequestContext.java" name="RequestContext" root_id="5" description="[null]" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.struts:struts-ui:org.struts.RequestContext"/> <!-- **************** Another independent project **************** --> <projects id="8" root_id="[null]" kee="foo:struts-core" name="Foo Struts Core" scope="PRJ" qualifier="BRC" long_name="Foo Struts Core" - description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="foo:struts-core"/> </dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/resource/ResourceKeyUpdaterDaoTest/shouldBulkUpdateKey-result.xml b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceKeyUpdaterDaoTest/shouldBulkUpdateKey-result.xml index 85e3d646568..b55b2699b11 100644 --- a/sonar-core/src/test/resources/org/sonar/core/resource/ResourceKeyUpdaterDaoTest/shouldBulkUpdateKey-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceKeyUpdaterDaoTest/shouldBulkUpdateKey-result.xml @@ -3,48 +3,48 @@ <!-- root project --> <projects id="1" root_id="[null]" scope="PRJ" qualifier="TRK" kee="org.apache.struts:struts" name="Struts" description="[null]" long_name="Apache Struts" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.apache.struts:struts"/> <!-- **************** First sub project **************** --> <projects id="2" root_id="1" kee="org.apache.struts:struts-core" name="Struts Core" scope="PRJ" qualifier="BRC" long_name="Struts Core" - description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.apache.struts:struts-core"/> <!-- directory --> - <projects long_name="org.struts" id="3" scope="DIR" qualifier="PAC" kee="org.apache.struts:struts-core:org.struts" + <projects long_name="org.struts" id="3" scope="DIR" qualifier="DIR" kee="org.apache.struts:struts-core:/src/org/struts" name="org.struts" root_id="2" description="[null]" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.apache.struts:struts-core:org.struts"/> <!-- file --> - <projects long_name="org.struts.RequestContext" id="4" scope="FIL" qualifier="CLA" kee="org.apache.struts:struts-core:org.struts.RequestContext" + <projects long_name="org.struts.RequestContext" id="4" scope="FIL" qualifier="CLA" kee="org.apache.struts:struts-core:/src/org/struts/RequestContext.java" name="RequestContext" root_id="2" description="[null]" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.apache.struts:struts-core:org.struts.RequestContext"/> <!-- **************** Second sub project **************** --> <projects id="5" root_id="1" kee="org.apache.struts:struts-ui" name="Struts UI" scope="PRJ" qualifier="BRC" long_name="Struts UI" - description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.apache.struts:struts-ui"/> <!-- directory --> - <projects long_name="org.struts" id="6" scope="DIR" qualifier="PAC" kee="org.apache.struts:struts-ui:org.struts" + <projects long_name="org.struts" id="6" scope="DIR" qualifier="DIR" kee="org.apache.struts:struts-ui:/src/org/struts" name="org.struts" root_id="5" description="[null]" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.apache.struts:struts-ui:org.struts"/> <!-- file --> - <projects long_name="org.struts.RequestContext" id="7" scope="FIL" qualifier="CLA" kee="org.apache.struts:struts-ui:org.struts.RequestContext" + <projects long_name="org.struts.RequestContext" id="7" scope="FIL" qualifier="CLA" kee="org.apache.struts:struts-ui:/src/org/struts/RequestContext.java" name="RequestContext" root_id="5" description="[null]" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.apache.struts:struts-ui:org.struts.RequestContext"/> <!-- **************** Another independent project **************** --> <projects id="8" root_id="[null]" kee="foo:struts-core" name="Foo Struts Core" scope="PRJ" qualifier="BRC" long_name="Foo Struts Core" - description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="foo:struts-core"/> </dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/resource/ResourceKeyUpdaterDaoTest/shouldBulkUpdateKeyOnOnlyOneSubmodule-result.xml b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceKeyUpdaterDaoTest/shouldBulkUpdateKeyOnOnlyOneSubmodule-result.xml index 4d5611bdabd..ba73191c96f 100644 --- a/sonar-core/src/test/resources/org/sonar/core/resource/ResourceKeyUpdaterDaoTest/shouldBulkUpdateKeyOnOnlyOneSubmodule-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceKeyUpdaterDaoTest/shouldBulkUpdateKeyOnOnlyOneSubmodule-result.xml @@ -3,48 +3,48 @@ <!-- root project --> <projects id="1" root_id="[null]" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts" description="[null]" long_name="Apache Struts" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.struts:struts"/> <!-- **************** First sub project **************** --> <projects id="2" root_id="1" kee="org.struts:struts-core" name="Struts Core" scope="PRJ" qualifier="BRC" long_name="Struts Core" - description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.struts:struts-core"/> <!-- directory --> - <projects long_name="org.struts" id="3" scope="DIR" qualifier="PAC" kee="org.struts:struts-core:org.struts" + <projects long_name="org.struts" id="3" scope="DIR" qualifier="DIR" kee="org.struts:struts-core:/src/org/struts" name="org.struts" root_id="2" description="[null]" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.struts:struts-core:org.struts"/> <!-- file --> - <projects long_name="org.struts.RequestContext" id="4" scope="FIL" qualifier="CLA" kee="org.struts:struts-core:org.struts.RequestContext" + <projects long_name="org.struts.RequestContext" id="4" scope="FIL" qualifier="CLA" kee="org.struts:struts-core:/src/org/struts/RequestContext.java" name="RequestContext" root_id="2" description="[null]" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.struts:struts-core:org.struts.RequestContext"/> <!-- **************** Second sub project **************** --> <projects id="5" root_id="1" kee="org.struts:struts-web" name="Struts UI" scope="PRJ" qualifier="BRC" long_name="Struts UI" - description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.struts:struts-web"/> <!-- directory --> - <projects long_name="org.struts" id="6" scope="DIR" qualifier="PAC" kee="org.struts:struts-web:org.struts" + <projects long_name="org.struts" id="6" scope="DIR" qualifier="DIR" kee="org.struts:struts-web:/src/org/struts" name="org.struts" root_id="5" description="[null]" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.struts:struts-web:org.struts"/> <!-- file --> - <projects long_name="org.struts.RequestContext" id="7" scope="FIL" qualifier="CLA" kee="org.struts:struts-web:org.struts.RequestContext" + <projects long_name="org.struts.RequestContext" id="7" scope="FIL" qualifier="CLA" kee="org.struts:struts-web:/src/org/struts/RequestContext.java" name="RequestContext" root_id="5" description="[null]" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.struts:struts-web:org.struts.RequestContext"/> <!-- **************** Another independent project **************** --> <projects id="8" root_id="[null]" kee="foo:struts-core" name="Foo Struts Core" scope="PRJ" qualifier="BRC" long_name="Foo Struts Core" - description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="foo:struts-core"/> </dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/resource/ResourceKeyUpdaterDaoTest/shouldNotUpdateAllSubmodules-result.xml b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceKeyUpdaterDaoTest/shouldNotUpdateAllSubmodules-result.xml index 0da70e1fed9..55aa9728ecf 100644 --- a/sonar-core/src/test/resources/org/sonar/core/resource/ResourceKeyUpdaterDaoTest/shouldNotUpdateAllSubmodules-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceKeyUpdaterDaoTest/shouldNotUpdateAllSubmodules-result.xml @@ -3,42 +3,42 @@ <!-- root project --> <projects id="1" root_id="[null]" scope="PRJ" qualifier="TRK" kee="org.apache.struts:struts" name="Struts" description="[null]" long_name="Apache Struts" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.apache.struts:struts"/> <!-- **************** First sub project **************** --> <projects id="2" root_id="1" kee="org.apache.struts:struts-core" name="Struts Core" scope="PRJ" qualifier="BRC" long_name="Struts Core" - description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.apache.struts:struts-core"/> <!-- directory --> - <projects long_name="org.struts" id="3" scope="DIR" qualifier="PAC" kee="org.apache.struts:struts-core:org.struts" + <projects long_name="org.struts" id="3" scope="DIR" qualifier="PAC" kee="org.apache.struts:struts-core:/src/org/struts" name="org.struts" root_id="2" description="[null]" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.apache.struts:struts-core:org.struts"/> <!-- file --> - <projects long_name="org.struts.RequestContext" id="4" scope="FIL" qualifier="CLA" kee="org.apache.struts:struts-core:org.struts.RequestContext" + <projects long_name="org.struts.RequestContext" id="4" scope="FIL" qualifier="CLA" kee="org.apache.struts:struts-core:/src/org/struts/RequestContext.java" name="RequestContext" root_id="2" description="[null]" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.apache.struts:struts-core:org.struts.RequestContext"/> <!-- **************** Second sub project THAT HAS A DIFFERENT GROUP ID => MUST NOT BE UPDATED **************** --> <projects id="5" root_id="1" kee="foo:struts-ui" name="Struts UI" scope="PRJ" qualifier="BRC" long_name="Struts UI" - description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="foo:struts-ui"/> <!-- directory --> - <projects long_name="org.struts" id="6" scope="DIR" qualifier="PAC" kee="foo:struts-ui:org.struts" + <projects long_name="org.struts" id="6" scope="DIR" qualifier="PAC" kee="foo:struts-ui:/src/org/struts" name="org.struts" root_id="5" description="[null]" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="foo:struts-ui:org.struts"/> <!-- file --> - <projects long_name="org.struts.RequestContext" id="7" scope="FIL" qualifier="CLA" kee="foo:struts-ui:org.struts.RequestContext" + <projects long_name="org.struts.RequestContext" id="7" scope="FIL" qualifier="CLA" kee="foo:struts-ui:/src/org/struts/RequestContext.java" name="RequestContext" root_id="5" description="[null]" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="foo:struts-ui:org.struts.RequestContext"/> </dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/resource/ResourceKeyUpdaterDaoTest/shouldNotUpdateAllSubmodules.xml b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceKeyUpdaterDaoTest/shouldNotUpdateAllSubmodules.xml index 8b075699918..58d4452c3b1 100644 --- a/sonar-core/src/test/resources/org/sonar/core/resource/ResourceKeyUpdaterDaoTest/shouldNotUpdateAllSubmodules.xml +++ b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceKeyUpdaterDaoTest/shouldNotUpdateAllSubmodules.xml @@ -3,42 +3,42 @@ <!-- root project --> <projects id="1" root_id="[null]" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts" description="[null]" long_name="Apache Struts" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.struts:struts"/> <!-- **************** First sub project **************** --> <projects id="2" root_id="1" kee="org.struts:struts-core" name="Struts Core" scope="PRJ" qualifier="BRC" long_name="Struts Core" - description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.struts:struts-core"/> <!-- directory --> - <projects long_name="org.struts" id="3" scope="DIR" qualifier="PAC" kee="org.struts:struts-core:org.struts" + <projects long_name="org.struts" id="3" scope="DIR" qualifier="PAC" kee="org.struts:struts-core:/src/org/struts" name="org.struts" root_id="2" description="[null]" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.struts:struts-core:org.struts"/> <!-- file --> - <projects long_name="org.struts.RequestContext" id="4" scope="FIL" qualifier="CLA" kee="org.struts:struts-core:org.struts.RequestContext" + <projects long_name="org.struts.RequestContext" id="4" scope="FIL" qualifier="CLA" kee="org.struts:struts-core:/src/org/struts/RequestContext.java" name="RequestContext" root_id="2" description="[null]" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.struts:struts-core:org.struts.RequestContext"/> <!-- **************** Second sub project THAT HAS A DIFFERENT GROUP ID => MUST NOT BE UPDATED **************** --> <projects id="5" root_id="1" kee="foo:struts-ui" name="Struts UI" scope="PRJ" qualifier="BRC" long_name="Struts UI" - description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="foo:struts-ui"/> <!-- directory --> - <projects long_name="org.struts" id="6" scope="DIR" qualifier="PAC" kee="foo:struts-ui:org.struts" + <projects long_name="org.struts" id="6" scope="DIR" qualifier="PAC" kee="foo:struts-ui:/src/org/struts" name="org.struts" root_id="5" description="[null]" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="foo:struts-ui:org.struts"/> <!-- file --> - <projects long_name="org.struts.RequestContext" id="7" scope="FIL" qualifier="CLA" kee="foo:struts-ui:org.struts.RequestContext" + <projects long_name="org.struts.RequestContext" id="7" scope="FIL" qualifier="CLA" kee="foo:struts-ui:/src/org/struts/RequestContext.java" name="RequestContext" root_id="5" description="[null]" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="foo:struts-ui:org.struts.RequestContext"/> </dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/resource/ResourceKeyUpdaterDaoTest/shouldUpdateKey-result.xml b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceKeyUpdaterDaoTest/shouldUpdateKey-result.xml index 894780b152a..360bd068c94 100644 --- a/sonar-core/src/test/resources/org/sonar/core/resource/ResourceKeyUpdaterDaoTest/shouldUpdateKey-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceKeyUpdaterDaoTest/shouldUpdateKey-result.xml @@ -3,7 +3,7 @@ <!-- root project --> <projects id="1" root_id="[null]" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts" description="[null]" long_name="Apache Struts" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.struts:struts"/> <!-- **************** First sub project **************** --> @@ -11,42 +11,42 @@ <!-- --> <projects id="2" root_id="1" kee="struts:core" name="Struts Core" scope="PRJ" qualifier="BRC" long_name="Struts Core" - description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]"/> + description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="struts:core"/> <!-- directory --> - <projects long_name="org.struts" id="3" scope="DIR" qualifier="PAC" kee="struts:core:org.struts" + <projects long_name="org.struts" id="3" scope="DIR" qualifier="DIR" kee="struts:core:/src/org/struts" name="org.struts" root_id="2" description="[null]" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="struts:core:org.struts"/> <!-- file --> - <projects long_name="org.struts.RequestContext" id="4" scope="FIL" qualifier="CLA" kee="struts:core:org.struts.RequestContext" + <projects long_name="org.struts.RequestContext" id="4" scope="FIL" qualifier="CLA" kee="struts:core:/src/org/struts/RequestContext.java" name="RequestContext" root_id="2" description="[null]" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="struts:core:org.struts.RequestContext"/> <!-- **************** Second sub project **************** --> <projects id="5" root_id="1" kee="org.struts:struts-ui" name="Struts UI" scope="PRJ" qualifier="BRC" long_name="Struts UI" - description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.struts:struts-ui"/> <!-- directory --> - <projects long_name="org.struts" id="6" scope="DIR" qualifier="PAC" kee="org.struts:struts-ui:org.struts" + <projects long_name="org.struts" id="6" scope="DIR" qualifier="DIR" kee="org.struts:struts-ui:/src/org/struts" name="org.struts" root_id="5" description="[null]" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.struts:struts-ui:org.struts"/> <!-- file --> - <projects long_name="org.struts.RequestContext" id="7" scope="FIL" qualifier="CLA" kee="org.struts:struts-ui:org.struts.RequestContext" + <projects long_name="org.struts.RequestContext" id="7" scope="FIL" qualifier="CLA" kee="org.struts:struts-ui:/src/org/struts/RequestContext.java" name="RequestContext" root_id="5" description="[null]" - enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="org.struts:struts-ui:org.struts.RequestContext"/> <!-- **************** Another independent project **************** --> <projects id="8" root_id="[null]" kee="foo:struts-core" name="Foo Struts Core" scope="PRJ" qualifier="BRC" long_name="Foo Struts Core" - description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]"/> + description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="foo:struts-core"/> </dataset> diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SquidUtils.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SquidUtils.java index dec485a41a7..c26100b9825 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SquidUtils.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SquidUtils.java @@ -34,7 +34,7 @@ public final class SquidUtils { String extension = StringUtils.lowerCase(FilenameUtils.getExtension(key)); boolean isJavaFile = "jav".equals(extension) || "java".equals(extension); if (isJavaFile) { - key = key.substring(0, key.length() - extension.length() -1); + key = key.substring(0, key.length() - extension.length() - 1); } String convertedKey = key.replace('/', '.'); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/ResourceModel.java b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/ResourceModel.java index e37f0714b22..e3e97d5f8ac 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/ResourceModel.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/ResourceModel.java @@ -75,9 +75,12 @@ public class ResourceModel extends BaseIdentifiable implements Cloneable { @Column(name = "qualifier", updatable = true, nullable = false, length = 10) private String qualifier; - @Column(name = "kee", updatable = false, nullable = false, length = KEY_SIZE) + @Column(name = "kee", updatable = true, nullable = false, length = KEY_SIZE) private String key; + @Column(name = "deprecated_kee", updatable = true, nullable = true, length = KEY_SIZE) + private String deprecatedKey; + @Column(name = "language", updatable = true, nullable = true, length = 20) private String languageKey; @@ -219,6 +222,10 @@ public class ResourceModel extends BaseIdentifiable implements Cloneable { return key; } + public String getDeprecatedKey() { + return deprecatedKey; + } + public String getLanguageKey() { return languageKey; } @@ -260,6 +267,16 @@ public class ResourceModel extends BaseIdentifiable implements Cloneable { this.key = key; } + /** + * @throws IllegalArgumentException if the key is longer than KEY_SIZE + */ + public void setDeprecatedKey(String deprecatedKey) { + if (deprecatedKey.length() > KEY_SIZE) { + throw new IllegalArgumentException("Resource deprecated key is too long, max is " + KEY_SIZE + " characters. Got : " + deprecatedKey); + } + this.deprecatedKey = deprecatedKey; + } + public Integer getRootId() { return rootId; } @@ -305,13 +322,6 @@ public class ResourceModel extends BaseIdentifiable implements Cloneable { return true; } ResourceModel other = (ResourceModel) obj; - if (StringUtils.isNotBlank(path)) { - return new EqualsBuilder() - .append(path, other.path) - .append(enabled, other.enabled) - .append(rootId, other.rootId) - .isEquals(); - } return new EqualsBuilder() .append(key, other.key) .append(enabled, other.enabled) @@ -321,13 +331,6 @@ public class ResourceModel extends BaseIdentifiable implements Cloneable { @Override public int hashCode() { - if (StringUtils.isNotBlank(path)) { - return new HashCodeBuilder(17, 37) - .append(path) - .append(enabled) - .append(rootId) - .toHashCode(); - } return new HashCodeBuilder(17, 37) .append(key) .append(enabled) @@ -340,6 +343,7 @@ public class ResourceModel extends BaseIdentifiable implements Cloneable { return new ToStringBuilder(this) .append("id", getId()) .append("key", key) + .append("deprecatedKey", deprecatedKey) .append("scope", scope) .append("qualifier", qualifier) .append("name", name) @@ -358,6 +362,7 @@ public class ResourceModel extends BaseIdentifiable implements Cloneable { public Object clone() { ResourceModel clone = new ResourceModel(getScope(), getKey(), getQualifier(), getRootId(), getPath(), getName()); clone.setDescription(getDescription()); + clone.setDeprecatedKey(getDeprecatedKey()); clone.setEnabled(getEnabled()); clone.setProjectLinks(getProjectLinks()); clone.setLanguageKey(getLanguageKey()); @@ -376,6 +381,7 @@ public class ResourceModel extends BaseIdentifiable implements Cloneable { model.setEnabled(Boolean.TRUE); model.setDescription(resource.getDescription()); model.setKey(resource.getKey()); + model.setDeprecatedKey(resource.getDeprecatedKey()); model.setPath(resource.getPath()); if (resource.getLanguage() != null) { model.setLanguageKey(resource.getLanguage().getKey()); 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 98f9c386bf8..1bb04d84886 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 @@ -33,18 +33,30 @@ public class Directory extends Resource { private Language language; - public Directory(String key) { - this(key, null); + private Directory() { + // USed by factory } - public Directory(String key, Language language) { - setKey(parseKey(key)); + /** + * @deprecated since 4.2 use {@link #create(String, String, Language, boolean)} + */ + @Deprecated + public Directory(String deprecatedKey) { + this(deprecatedKey, null); + } + + /** + * @deprecated since 4.2 use {@link #create(String, String, Language, boolean)} + */ + @Deprecated + public Directory(String deprecatedKey, Language language) { + setDeprecatedKey(parseKey(deprecatedKey)); this.language = language; } @Override public String getName() { - return getKey(); + return getDeprecatedKey(); } @Override @@ -95,6 +107,15 @@ public class Directory extends Resource { return key; } + public static Directory create(String path, String directoryDeprecatedKey) { + Directory d = new Directory(); + String normalizedPath = normalize(path); + d.setKey(normalizedPath); + d.setDeprecatedKey(parseKey(directoryDeprecatedKey)); + d.setPath(normalizedPath); + return d; + } + @Override public String toString() { return new ToStringBuilder(this) @@ -103,4 +124,5 @@ public class Directory extends Resource { .append("language", language) .toString(); } + } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/File.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/File.java index 84d2d34ce77..75adc4cb1b3 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/File.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/File.java @@ -35,58 +35,70 @@ public class File extends Resource { public static final String SCOPE = Scopes.FILE; - private String directoryKey; + private String directoryDeprecatedKey; private String filename; private Language language; private Directory parent; private String qualifier = Qualifiers.FILE; + private File() { + // Used by factory method + } + /** * File in project. Key is the path relative to project source directories. It is not the absolute path and it does not include the path * to source directories. Example : <code>new File("org/sonar/foo.sql")</code>. The absolute path may be * c:/myproject/src/main/sql/org/sonar/foo.sql. Project root is c:/myproject and source dir is src/main/sql. + * @deprecated since 4.2 use {@link #create(String, String, Language, boolean)} */ - public File(String key) { - if (key == null) { + @Deprecated + public File(String deprecatedKey) { + if (deprecatedKey == null) { throw new IllegalArgumentException("File key is null"); } - String realKey = parseKey(key); + String realKey = parseKey(deprecatedKey); if (realKey.indexOf(Directory.SEPARATOR) >= 0) { - this.directoryKey = Directory.parseKey(StringUtils.substringBeforeLast(key, Directory.SEPARATOR)); + this.directoryDeprecatedKey = Directory.parseKey(StringUtils.substringBeforeLast(deprecatedKey, Directory.SEPARATOR)); this.filename = StringUtils.substringAfterLast(realKey, Directory.SEPARATOR); - realKey = new StringBuilder().append(this.directoryKey).append(Directory.SEPARATOR).append(filename).toString(); + realKey = new StringBuilder().append(this.directoryDeprecatedKey).append(Directory.SEPARATOR).append(filename).toString(); } else { - this.filename = key; + this.filename = deprecatedKey; } - setKey(realKey); + setDeprecatedKey(realKey); } /** * Creates a file from its containing directory and name + * @deprecated since 4.2 use {@link #create(String, String, Language, boolean)} */ - public File(String directory, String filename) { + @Deprecated + public File(String deprecatedDirectoryKey, String filename) { this.filename = StringUtils.trim(filename); - if (StringUtils.isBlank(directory)) { - setKey(filename); + if (StringUtils.isBlank(deprecatedDirectoryKey)) { + setDeprecatedKey(filename); } else { - this.directoryKey = Directory.parseKey(directory); - setKey(new StringBuilder().append(directoryKey).append(Directory.SEPARATOR).append(this.filename).toString()); + this.directoryDeprecatedKey = Directory.parseKey(deprecatedDirectoryKey); + setDeprecatedKey(new StringBuilder().append(directoryDeprecatedKey).append(Directory.SEPARATOR).append(this.filename).toString()); } } /** * Creates a File from its language and its key + * @deprecated since 4.2 use {@link #create(String, String, Language, boolean)} */ - public File(Language language, String key) { - this(key); + @Deprecated + public File(Language language, String deprecatedKey) { + this(deprecatedKey); this.language = language; } /** * Creates a File from language, directory and filename + * @deprecated since 4.2 use {@link #create(String, String, Language, boolean)} */ + @Deprecated public File(Language language, String directory, String filename) { this(directory, filename); this.language = language; @@ -100,11 +112,7 @@ public class File extends Resource { @Override public Directory getParent() { if (parent == null) { - parent = new Directory(directoryKey); - String filePath = getPath(); - if (StringUtils.isNotBlank(filePath)) { - parent.setPath(StringUtils.substringBeforeLast(filePath, Directory.SEPARATOR)); - } + parent = new Directory(directoryDeprecatedKey); } return parent; } @@ -126,13 +134,15 @@ public class File extends Resource { */ @Override public boolean matchFilePattern(String antPattern) { - WildcardPattern matcher = WildcardPattern.create(antPattern, "/"); + WildcardPattern matcher = WildcardPattern.create(antPattern, Directory.SEPARATOR); return matcher.match(getKey()); } /** * Creates a File from an io.file and a list of sources directories + * @deprecated since 4.2 use {@link #create(String, String, Language, boolean)} */ + @Deprecated public static File fromIOFile(java.io.File file, List<java.io.File> sourceDirs) { PathResolver.RelativePath relativePath = new PathResolver().relativePath(sourceDirs, file); if (relativePath != null) { @@ -143,7 +153,9 @@ public class File extends Resource { /** * Creates a File from its name and a project + * @deprecated since 4.2 use {@link #create(String, String, Language, boolean)} */ + @Deprecated public static File fromIOFile(java.io.File file, Project project) { return fromIOFile(file, project.getFileSystem().getSourceDirs()); } @@ -217,12 +229,35 @@ public class File extends Resource { this.qualifier = qualifier; } + public static File create(String relativePathFromBasedir, String relativePathFromSourceDir, Language language, boolean unitTest) { + File file = new File(); + String normalizedPath = normalize(relativePathFromBasedir); + file.setKey(normalizedPath); + file.setPath(normalizedPath); + String directoryKey = StringUtils.substringBeforeLast(normalizedPath, Directory.SEPARATOR); + file.setLanguage(language); + if (relativePathFromSourceDir.contains(Directory.SEPARATOR)) { + file.filename = StringUtils.substringAfterLast(relativePathFromSourceDir, Directory.SEPARATOR); + file.directoryDeprecatedKey = Directory.parseKey(StringUtils.substringBeforeLast(relativePathFromSourceDir, Directory.SEPARATOR)); + file.setDeprecatedKey(file.directoryDeprecatedKey + Directory.SEPARATOR + file.filename); + } else { + file.filename = relativePathFromSourceDir; + file.directoryDeprecatedKey = Directory.ROOT; + file.setDeprecatedKey(file.filename); + } + if (unitTest) { + file.setQualifier(Qualifiers.UNIT_TEST_FILE); + } + file.parent = Directory.create(directoryKey, file.directoryDeprecatedKey); + return file; + } + @Override public String toString() { return new ToStringBuilder(this) .append("key", getKey()) .append("path", getPath()) - .append("dir", directoryKey) + .append("dir", directoryDeprecatedKey) .append("filename", filename) .append("language", language) .toString(); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/JavaFile.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/JavaFile.java index d3cbf2f88ad..74fce50de45 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/JavaFile.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/JavaFile.java @@ -35,15 +35,21 @@ import java.util.List; public class JavaFile extends Resource { private static final String JAVA_SUFFIX = ".java"; - private String filename; - private String longName; - private String packageKey; + private String className; + private String fullyQualifiedName; + private String packageFullyQualifiedName; private boolean unitTest; private JavaPackage parent; + private JavaFile() { + // Default constructor + } + /** * Creates a JavaFile that is not a class of test based on package and file names + * @deprecated since 4.2 use {@link #create(String, String, boolean)} */ + @Deprecated public JavaFile(String packageName, String className) { this(packageName, className, false); } @@ -52,29 +58,33 @@ public class JavaFile extends Resource { * Creates a JavaFile that can be of any type based on package and file names * * @param unitTest whether it is a unit test file or a source file + * @deprecated since 4.2 use {@link #create(String, String, boolean)} */ + @Deprecated public JavaFile(String packageKey, String className, boolean unitTest) { if (className == null) { throw new IllegalArgumentException("Java filename can not be null"); } - this.filename = StringUtils.trim(className); - String key; + this.className = StringUtils.trim(className); + String deprecatedKey; if (StringUtils.isBlank(packageKey)) { - this.packageKey = JavaPackage.DEFAULT_PACKAGE_NAME; - this.longName = this.filename; - key = new StringBuilder().append(this.packageKey).append(".").append(this.filename).toString(); + this.packageFullyQualifiedName = JavaPackage.DEFAULT_PACKAGE_NAME; + this.fullyQualifiedName = this.className; + deprecatedKey = new StringBuilder().append(this.packageFullyQualifiedName).append(".").append(this.className).toString(); } else { - this.packageKey = packageKey.trim(); - key = new StringBuilder().append(this.packageKey).append(".").append(this.filename).toString(); - this.longName = key; + this.packageFullyQualifiedName = packageKey.trim(); + deprecatedKey = new StringBuilder().append(this.packageFullyQualifiedName).append(".").append(this.className).toString(); + this.fullyQualifiedName = deprecatedKey; } - setKey(key); + setDeprecatedKey(deprecatedKey); this.unitTest = unitTest; } /** * Creates a source file from its key + * @deprecated since 4.2 use {@link #create(String, String, boolean)} */ + @Deprecated public JavaFile(String key) { this(key, false); } @@ -83,7 +93,9 @@ public class JavaFile extends Resource { * Creates any JavaFile from its key * * @param unitTest whether it is a unit test file or a source file + * @deprecated since 4.2 use {@link #create(String, String, boolean)} */ + @Deprecated public JavaFile(String key, boolean unitTest) { if (key == null) { throw new IllegalArgumentException("Java filename can not be null"); @@ -92,17 +104,17 @@ public class JavaFile extends Resource { this.unitTest = unitTest; if (realKey.contains(".")) { - this.filename = StringUtils.substringAfterLast(realKey, "."); - this.packageKey = StringUtils.substringBeforeLast(realKey, "."); - this.longName = realKey; + this.className = StringUtils.substringAfterLast(realKey, "."); + this.packageFullyQualifiedName = StringUtils.substringBeforeLast(realKey, "."); + this.fullyQualifiedName = realKey; } else { - this.filename = realKey; - this.longName = realKey; - this.packageKey = JavaPackage.DEFAULT_PACKAGE_NAME; + this.className = realKey; + this.fullyQualifiedName = realKey; + this.packageFullyQualifiedName = JavaPackage.DEFAULT_PACKAGE_NAME; realKey = new StringBuilder().append(JavaPackage.DEFAULT_PACKAGE_NAME).append(".").append(realKey).toString(); } - setKey(realKey); + setDeprecatedKey(realKey); } /** @@ -111,14 +123,9 @@ public class JavaFile extends Resource { @Override public JavaPackage getParent() { if (parent == null) { - parent = new JavaPackage(packageKey); - String filePath = getPath(); - if (StringUtils.isNotBlank(filePath)) { - parent.setPath(StringUtils.substringBeforeLast(filePath, Directory.SEPARATOR)); - } + parent = new JavaPackage(packageFullyQualifiedName); } return parent; - } /** @@ -142,7 +149,7 @@ public class JavaFile extends Resource { */ @Override public String getName() { - return filename; + return className; } /** @@ -150,7 +157,7 @@ public class JavaFile extends Resource { */ @Override public String getLongName() { - return longName; + return fullyQualifiedName; } /** @@ -181,22 +188,14 @@ public class JavaFile extends Resource { */ @Override public boolean matchFilePattern(String antPattern) { - String fileKey = getKey(); - if (!fileKey.endsWith(JAVA_SUFFIX)) { - fileKey += JAVA_SUFFIX; - } - // Add wildcard extension if not provided - if ((antPattern.contains("/") && StringUtils.substringAfterLast(antPattern, "/").indexOf('.') < 0) || antPattern.indexOf('.') < 0) { - antPattern += ".*"; - } - String noPackagePrefix = JavaPackage.DEFAULT_PACKAGE_NAME + "."; - if (fileKey.startsWith(noPackagePrefix)) { - fileKey = fileKey.substring(noPackagePrefix.length()); - } - WildcardPattern matcher = WildcardPattern.create(antPattern, "."); - return matcher.match(fileKey); + WildcardPattern matcher = WildcardPattern.create(antPattern, Directory.SEPARATOR); + return matcher.match(getKey()); } + /** + * @deprecated since 4.2 use {@link #create(String, String, boolean)} + */ + @Deprecated public static JavaFile fromIOFile(File file, Project module, boolean unitTest) { if (file == null || !StringUtils.endsWithIgnoreCase(file.getName(), JAVA_SUFFIX)) { return null; @@ -212,6 +211,43 @@ public class JavaFile extends Resource { return null; } + /** + * For internal use only. + */ + public static JavaFile create(String relativePathFromBasedir) { + JavaFile javaFile = new JavaFile(); + String normalizedPath = normalize(relativePathFromBasedir); + javaFile.setKey(normalizedPath); + javaFile.setPath(normalizedPath); + String directoryKey = StringUtils.substringBeforeLast(normalizedPath, Directory.SEPARATOR); + javaFile.parent = JavaPackage.create(directoryKey); + return javaFile; + } + + public static JavaFile create(String relativePathFromBasedir, String relativePathFromSourceDir, boolean unitTest) { + JavaFile javaFile = JavaFile.create(relativePathFromBasedir); + if (relativePathFromSourceDir.contains(Directory.SEPARATOR)) { + javaFile.packageFullyQualifiedName = StringUtils.substringBeforeLast(relativePathFromSourceDir, Directory.SEPARATOR); + javaFile.packageFullyQualifiedName = StringUtils.replace(javaFile.packageFullyQualifiedName, Directory.SEPARATOR, "."); + javaFile.className = StringUtils.substringAfterLast(relativePathFromSourceDir, Directory.SEPARATOR); + javaFile.className = StringUtils.removeEndIgnoreCase(javaFile.className, JAVA_SUFFIX); + javaFile.fullyQualifiedName = javaFile.packageFullyQualifiedName + "." + javaFile.className; + javaFile.setDeprecatedKey(javaFile.fullyQualifiedName); + } else { + javaFile.packageFullyQualifiedName = JavaPackage.DEFAULT_PACKAGE_NAME; + javaFile.className = StringUtils.removeEndIgnoreCase(relativePathFromSourceDir, JAVA_SUFFIX); + javaFile.fullyQualifiedName = javaFile.className; + javaFile.setDeprecatedKey(JavaPackage.DEFAULT_PACKAGE_NAME + "." + javaFile.className); + } + javaFile.unitTest = unitTest; + javaFile.parent.setDeprecatedKey(javaFile.packageFullyQualifiedName); + return javaFile; + } + + /** + * @deprecated since 4.2 use {@link #create(String, String, boolean)} + */ + @Deprecated public static JavaFile fromRelativePath(String relativePath, boolean unitTest) { if (relativePath != null) { String pacname = null; @@ -232,7 +268,9 @@ public class JavaFile extends Resource { * Creates a JavaFile from a file in the source directories * * @return the JavaFile created if exists, null otherwise + * @deprecated since 4.2 use {@link #create(String, String, boolean)} */ + @Deprecated public static JavaFile fromIOFile(File file, List<File> sourceDirs, boolean unitTest) { if (file == null || !StringUtils.endsWithIgnoreCase(file.getName(), JAVA_SUFFIX)) { return null; @@ -246,7 +284,9 @@ public class JavaFile extends Resource { /** * Shortcut to fromIOFile with an abolute path + * @deprecated since 4.2 use {@link #create(String, String, boolean)} */ + @Deprecated public static JavaFile fromAbsolutePath(String path, List<File> sourceDirs, boolean unitTest) { if (path == null) { return null; @@ -258,8 +298,9 @@ public class JavaFile extends Resource { public String toString() { return new ToStringBuilder(this) .append("key", getKey()) + .append("deprecatedKey", getDeprecatedKey()) .append("path", getPath()) - .append("filename", filename) + .append("filename", className) .toString(); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/JavaPackage.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/JavaPackage.java index 71bed21e468..499d2706a58 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/JavaPackage.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/JavaPackage.java @@ -22,9 +22,11 @@ package org.sonar.api.resources; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.builder.ToStringBuilder; +import javax.annotation.Nullable; + /** * A class that represents a Java package in Sonar - * + * * @since 1.10 */ public class JavaPackage extends Resource { @@ -36,23 +38,27 @@ public class JavaPackage extends Resource { /** * Default constructor + * @deprecated since 4.2 use {@link #create(String, String)} */ + @Deprecated public JavaPackage() { this(null); } /** - * Creates a JavaPackage from its key. Will use DEFAULT_PACKAGE_NAME if key is null + * Creates a JavaPackage from its key. + * @deprecated since 4.2 use {@link #create(String, String)} */ - public JavaPackage(String key) { - setKey(StringUtils.defaultIfEmpty(StringUtils.trim(key), DEFAULT_PACKAGE_NAME)); + @Deprecated + public JavaPackage(String deprecatedKey) { + setDeprecatedKey(StringUtils.defaultIfEmpty(StringUtils.trim(deprecatedKey), DEFAULT_PACKAGE_NAME)); } /** * @return whether the JavaPackage key is the default key */ public boolean isDefault() { - return StringUtils.equals(getKey(), DEFAULT_PACKAGE_NAME); + return StringUtils.equals(getDeprecatedKey(), DEFAULT_PACKAGE_NAME); } /** @@ -92,7 +98,7 @@ public class JavaPackage extends Resource { */ @Override public String getName() { - return getKey(); + return getDeprecatedKey(); } /** @@ -119,11 +125,29 @@ public class JavaPackage extends Resource { return Java.INSTANCE; } + /** + * For internal use only. + */ + public static JavaPackage create(String path) { + JavaPackage pac = new JavaPackage(); + String normalizedPath = normalize(path); + pac.setKey(normalizedPath); + pac.setPath(normalizedPath); + return pac; + } + + public static JavaPackage create(String relativePathFromBasedir, @Nullable String packageQualifiedName) { + JavaPackage pac = JavaPackage.create(relativePathFromBasedir); + pac.setDeprecatedKey(StringUtils.defaultIfEmpty(StringUtils.trim(packageQualifiedName), DEFAULT_PACKAGE_NAME)); + return pac; + } + @Override public String toString() { return new ToStringBuilder(this) - .append("id", getId()) - .append("key", getKey()) - .toString(); + .append("id", getId()) + .append("key", getKey()) + .append("deprecatedKey", getDeprecatedKey()) + .toString(); } } 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 6588de10201..0bd6309a7e7 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 @@ -19,8 +19,6 @@ */ package org.sonar.api.resources; -import org.apache.commons.lang.StringUtils; - import javax.annotation.Nullable; import java.io.Serializable; @@ -126,10 +124,14 @@ public abstract class Resource implements Serializable { private String key = null; + private String deprecatedKey = null; + private String path = null; private String effectiveKey = null; + private String deprecatedEffectiveKey = null; + private boolean isExcluded = false; /** @@ -139,11 +141,29 @@ public abstract class Resource implements Serializable { return key; } - protected void setKey(String s) { + /** + * Internal use only + */ + public void setKey(String s) { this.key = s; } /** + * @return the resource deprecated key. Should not be used except to deal with backward compatibility. + * @since 4.2 + */ + public final String getDeprecatedKey() { + return deprecatedKey; + } + + /** + * For internal use only + */ + public void setDeprecatedKey(String s) { + this.deprecatedKey = s; + } + + /** * @return the resource name */ public abstract String getName(); @@ -215,7 +235,7 @@ public abstract class Resource implements Serializable { return this; } - private String normalize(@Nullable String path) { + protected static String normalize(@Nullable String path) { if (path == null) { return null; } @@ -242,6 +262,21 @@ public abstract class Resource implements Serializable { } /** + * Internal use only + */ + public String getDeprecatedEffectiveKey() { + return deprecatedEffectiveKey; + } + + /** + * Internal use only + */ + public final Resource setDeprecatedEffectiveKey(String deprecatedEffectiveKey) { + this.deprecatedEffectiveKey = deprecatedEffectiveKey; + return this; + } + + /** * @deprecated since 2.6 should use SensorContext#isExcluded(resource). It will make inheritance of Resource easier. */ @Deprecated @@ -269,15 +304,15 @@ public abstract class Resource implements Serializable { } Resource resource = (Resource) o; - if (StringUtils.isBlank(path)) { + if (key != null) { return key.equals(resource.key); + } else { + return resource.key == null && deprecatedKey.equals(resource.deprecatedKey); } - return path.equals(resource.path); - } @Override public int hashCode() { - return key.hashCode(); + return key != null ? key.hashCode() : deprecatedKey.hashCode(); } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/internal/DefaultInputFile.java b/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/internal/DefaultInputFile.java index cade6314655..43024fdf860 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/internal/DefaultInputFile.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/internal/DefaultInputFile.java @@ -42,6 +42,8 @@ public class DefaultInputFile implements InputFile { */ public static final String ATTRIBUTE_COMPONENT_KEY = "CMP_KEY"; + public static final String ATTRIBUTE_COMPONENT_DEPRECATED_KEY = "CMP_DEPRECATED_KEY"; + private final String absolutePath; private final String path; private final Map<String, String> attributes; diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/DirectoryTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/DirectoryTest.java index b3d10a3a72f..a5f673b1649 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/DirectoryTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/DirectoryTest.java @@ -19,31 +19,40 @@ */ package org.sonar.api.resources; +import org.junit.Test; + import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.nullValue; import static org.junit.Assert.assertThat; -import org.junit.Test; public class DirectoryTest { @Test - public void shouldNotStartOrEndBySlash() { + public void shouldStartBySlashAndNotEndBySlash() { + Resource dir = Directory.create("src/foo/bar/", " /foo/bar/ "); + assertThat(dir.getKey(), is("/src/foo/bar")); + assertThat(dir.getDeprecatedKey(), is("foo/bar")); + assertThat(dir.getName(), is("foo/bar")); + } + + @Test + public void shouldNotStartOrEndBySlashDeprecatedConstructor() { Resource dir = new Directory(" /foo/bar/ "); - assertThat(dir.getKey(), is("foo/bar")); + assertThat(dir.getDeprecatedKey(), is("foo/bar")); assertThat(dir.getName(), is("foo/bar")); } @Test - public void rootDirectory() { - assertThat(new Directory(null).getKey(), is(Directory.ROOT)); - assertThat(new Directory("").getKey(), is(Directory.ROOT)); - assertThat(new Directory(" ").getKey(), is(Directory.ROOT)); + public void rootDirectoryDeprecatedConstructor() { + assertThat(new Directory(null).getDeprecatedKey(), is(Directory.ROOT)); + assertThat(new Directory("").getDeprecatedKey(), is(Directory.ROOT)); + assertThat(new Directory(" ").getDeprecatedKey(), is(Directory.ROOT)); } @Test public void backSlashesShouldBeReplacedBySlashes() { Resource dir = new Directory(" foo\\bar\\ "); - assertThat(dir.getKey(), is("foo/bar")); + assertThat(dir.getDeprecatedKey(), is("foo/bar")); assertThat(dir.getName(), is("foo/bar")); } @@ -66,17 +75,18 @@ public class DirectoryTest { @Test public void matchExclusionPatterns() { - assertThat(new Directory("one/two/third").matchFilePattern("one/two/*.java"), is(false)); - assertThat(new Directory("one/two/third").matchFilePattern("false"), is(false)); - assertThat(new Directory("one/two/third").matchFilePattern("two/one/**"), is(false)); - assertThat(new Directory("one/two/third").matchFilePattern("other*/**"), is(false)); + Directory directory = Directory.create("src/one/two/third", "one/two/third"); + assertThat(directory.matchFilePattern("one/two/*.java"), is(false)); + assertThat(directory.matchFilePattern("false"), is(false)); + assertThat(directory.matchFilePattern("two/one/**"), is(false)); + assertThat(directory.matchFilePattern("other*/**"), is(false)); - assertThat(new Directory("one/two/third").matchFilePattern("one*/**"), is(true)); - assertThat(new Directory("one/two/third").matchFilePattern("one/t?o/**"), is(true)); - assertThat(new Directory("one/two/third").matchFilePattern("**/*"), is(true)); - assertThat(new Directory("one/two/third").matchFilePattern("**"), is(true)); - assertThat(new Directory("one/two/third").matchFilePattern("one/two/*"), is(true)); - assertThat(new Directory("one/two/third").matchFilePattern("/one/two/*"), is(true)); - assertThat(new Directory("one/two/third").matchFilePattern("one/**"), is(true)); + assertThat(directory.matchFilePattern("src/one*/**"), is(true)); + assertThat(directory.matchFilePattern("src/one/t?o/**"), is(true)); + assertThat(directory.matchFilePattern("**/*"), is(true)); + assertThat(directory.matchFilePattern("**"), is(true)); + assertThat(directory.matchFilePattern("src/one/two/*"), is(true)); + assertThat(directory.matchFilePattern("/src/one/two/*"), is(true)); + assertThat(directory.matchFilePattern("src/one/**"), is(true)); } } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/FileTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/FileTest.java index 0caefa9796d..4a2a757ebed 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/FileTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/FileTest.java @@ -19,73 +19,69 @@ */ 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.hamcrest.CoreMatchers.nullValue; import static org.junit.Assert.assertThat; -import org.junit.Test; public class FileTest { @Test public void trimKeyAndName() { File file = new File(" foo/bar/ ", " toto.sql "); - assertThat(file.getKey(), is("foo/bar/toto.sql")); - assertThat(file.getLongName(), is("foo/bar/toto.sql")); + assertThat(file.getDeprecatedKey(), is("foo/bar/toto.sql")); assertThat(file.getName(), is("toto.sql")); - assertThat(file.getParent().getKey(), is("foo/bar")); - assertThat(file.getScope(), is(Resource.SCOPE_ENTITY)); - assertThat(file.getQualifier(), is(Resource.QUALIFIER_FILE)); } @Test public void parentIsDirectory() { - File file = new File(" foo/bar/", "toto.sql "); - assertThat(file.getKey(), is("foo/bar/toto.sql")); - assertThat(file.getLongName(), is("foo/bar/toto.sql")); + File file = File.create("src/foo/bar/toto.sql", "foo/bar/toto.sql", null, false); + assertThat(file.getKey(), is("/src/foo/bar/toto.sql")); + assertThat(file.getDeprecatedKey(), is("foo/bar/toto.sql")); + assertThat(file.getLongName(), is("/src/foo/bar/toto.sql")); assertThat(file.getName(), is("toto.sql")); - assertThat(file.getParent().getKey(), is("foo/bar")); + assertThat(file.getParent().getKey(), is("/src/foo/bar")); assertThat(ResourceUtils.isSpace(file.getParent()), is(true)); } @Test - public void rootFilesHaveParent() { - File file = new File((String) null, "toto.sql"); - assertThat(file.getKey(), is("toto.sql")); - assertThat(file.getName(), is("toto.sql")); - assertThat(file.getParent().getKey(), is(Directory.ROOT)); - - file = new File("", "toto.sql"); - assertThat(file.getKey(), is("toto.sql")); - assertThat(file.getName(), is("toto.sql")); - assertThat(file.getParent().getKey(), is(Directory.ROOT)); + public void parentIsDirectoryWithDeprecatedKey() { + File file = new File(" foo/bar/", "toto.sql "); + assertThat(file.getDeprecatedKey(), is("foo/bar/toto.sql")); + assertThat(file.getParent().getDeprecatedKey(), is("foo/bar")); + assertThat(ResourceUtils.isSpace(file.getParent()), is(true)); + } - file = new File("toto.sql"); - assertThat(file.getKey(), is("toto.sql")); + @Test + public void rootFilesHaveParent() { + File file = File.create("toto.sql", "toto.sql", null, false); + assertThat(file.getKey(), is("/toto.sql")); + assertThat(file.getDeprecatedKey(), is("toto.sql")); assertThat(file.getName(), is("toto.sql")); - assertThat(file.getParent().getKey(), is(Directory.ROOT)); + assertThat(file.getParent().getKey(), is("/")); + assertThat(file.getParent().getDeprecatedKey(), is(Directory.ROOT)); } @Test - public void newFileByKey() { + public void newFileByDeprecatedKey() { File file = new File("toto.sql"); - assertThat(file.getKey(), is("toto.sql")); + assertThat(file.getDeprecatedKey(), is("toto.sql")); assertThat(file.getName(), is("toto.sql")); - assertThat(file.getLongName(), is("toto.sql")); - assertThat(file.getParent().getKey(), is(Directory.ROOT)); + assertThat(file.getParent().getDeprecatedKey(), is(Directory.ROOT)); assertThat(file.getScope(), is(Resource.SCOPE_ENTITY)); assertThat(file.getQualifier(), is(Resource.QUALIFIER_FILE)); file = new File("foo/bar/toto.sql"); - assertThat(file.getKey(), is("foo/bar/toto.sql")); - assertThat(file.getLongName(), is("foo/bar/toto.sql")); + assertThat(file.getDeprecatedKey(), is("foo/bar/toto.sql")); assertThat(file.getName(), is("toto.sql")); - assertThat(file.getParent().getKey(), is("foo/bar")); + assertThat(file.getParent().getDeprecatedKey(), is("foo/bar")); file = new File("/foo/bar/toto.sql "); - assertThat(file.getKey(), is("foo/bar/toto.sql")); - assertThat(file.getLongName(), is("foo/bar/toto.sql")); + assertThat(file.getDeprecatedKey(), is("foo/bar/toto.sql")); assertThat(file.getName(), is("toto.sql")); - assertThat(file.getParent().getKey(), is("foo/bar")); + assertThat(file.getParent().getDeprecatedKey(), is("foo/bar")); } @Test @@ -100,16 +96,17 @@ public class FileTest { @Test public void matchAntPatterns() { - assertThat(new File("one/two/foo.sql").matchFilePattern("one/two/*.java"), is(false)); - assertThat(new File("one/two/foo.sql").matchFilePattern("false"), is(false)); - assertThat(new File("one/two/foo.sql").matchFilePattern("two/one/**"), is(false)); - assertThat(new File("one/two/foo.sql").matchFilePattern("other*/**"), is(false)); + File file = File.create("src/one/two/foo.sql", "one/two/foo.sql", null, false); + assertThat(file.matchFilePattern("/src/one/two/*.java")).isFalse(); + assertThat(file.matchFilePattern("false")).isFalse(); + assertThat(file.matchFilePattern("two/one/**")).isFalse(); + assertThat(file.matchFilePattern("other*/**")).isFalse(); - assertThat(new File("one/two/foo.sql").matchFilePattern("one*/**/*.sql"), is(true)); - assertThat(new File("one/two/foo.sql").matchFilePattern("one/t?o/**/*"), is(true)); - assertThat(new File("one/two/foo.sql").matchFilePattern("**/*"), is(true)); - assertThat(new File("one/two/foo.sql").matchFilePattern("one/two/*"), is(true)); - assertThat(new File("one/two/foo.sql").matchFilePattern("/one/two/*"), is(true)); - assertThat(new File("one/two/foo.sql").matchFilePattern("one/**"), is(true)); + assertThat(file.matchFilePattern("/src/one*/**/*.sql")).isTrue(); + assertThat(file.matchFilePattern("/src/one/t?o/**/*")).isTrue(); + assertThat(file.matchFilePattern("**/*")).isTrue(); + assertThat(file.matchFilePattern("src/one/two/*")).isTrue(); + assertThat(file.matchFilePattern("/src/one/two/*")).isTrue(); + assertThat(file.matchFilePattern("src/**")).isTrue(); } } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/JavaFileTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/JavaFileTest.java index 53b9061bc4e..a826c207c0a 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/JavaFileTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/JavaFileTest.java @@ -27,6 +27,7 @@ import java.io.File; import java.util.Arrays; import java.util.List; +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; @@ -41,42 +42,65 @@ public class JavaFileTest { @Test public void testNewClass() { + JavaFile javaClass = JavaFile.create("src/main/java/org/foo/bar/Hello.java", "org/foo/bar/Hello.java", false); + assertThat(javaClass.getKey()).isEqualTo("/src/main/java/org/foo/bar/Hello.java"); + assertThat(javaClass.getDeprecatedKey(), is("org.foo.bar.Hello")); + assertThat(javaClass.getName(), is("Hello")); + assertThat(javaClass.getLongName(), is("org.foo.bar.Hello")); + assertThat(javaClass.getParent().getKey(), is("/src/main/java/org/foo/bar")); + assertThat(javaClass.getParent().getDeprecatedKey(), is("org.foo.bar")); + } + + @Test + public void testNewClassByDeprecatedKey() { JavaFile javaClass = new JavaFile("org.foo.bar.Hello", false); - assertThat(javaClass.getKey(), is("org.foo.bar.Hello")); + assertThat(javaClass.getDeprecatedKey(), is("org.foo.bar.Hello")); assertThat(javaClass.getName(), is("Hello")); assertThat(javaClass.getLongName(), is("org.foo.bar.Hello")); - assertThat(javaClass.getParent().getKey(), is("org.foo.bar")); + assertThat(javaClass.getParent().getDeprecatedKey(), is("org.foo.bar")); } @Test public void testNewClassWithExplicitPackage() { JavaFile javaClass = new JavaFile("org.foo.bar", "Hello", false); - assertThat(javaClass.getKey(), is("org.foo.bar.Hello")); + assertThat(javaClass.getDeprecatedKey(), is("org.foo.bar.Hello")); assertThat(javaClass.getName(), is("Hello")); assertThat(javaClass.getLongName(), is("org.foo.bar.Hello")); - assertThat(javaClass.getParent().getKey(), is("org.foo.bar")); + assertThat(javaClass.getParent().getDeprecatedKey(), is("org.foo.bar")); } @Test public void shouldAcceptFilenamesWithDollars() { // $ is not used only for inner classes !!! JavaFile javaFile = new JavaFile("org.foo.bar", "Hello$Bar"); - assertThat(javaFile.getKey(), is("org.foo.bar.Hello$Bar")); + assertThat(javaFile.getDeprecatedKey(), is("org.foo.bar.Hello$Bar")); } @Test public void testNewClassWithEmptyPackage() { + JavaFile javaClass = JavaFile.create("src/main/java/Hello.java", "Hello.java", false); + assertThat(javaClass.getKey()).isEqualTo("/src/main/java/Hello.java"); + assertThat(javaClass.getDeprecatedKey(), is(JavaPackage.DEFAULT_PACKAGE_NAME + ".Hello")); + assertThat(javaClass.getName(), is("Hello")); + assertThat(javaClass.getLongName(), is("Hello")); + assertThat(javaClass.getParent().getKey()).isEqualTo("/src/main/java"); + assertThat(javaClass.getParent().getDeprecatedKey()).isEqualTo(JavaPackage.DEFAULT_PACKAGE_NAME); + assertThat(javaClass.getParent().isDefault()).isTrue(); + } + + @Test + public void testNewClassWithEmptyPackageDeprecatedConstructor() { JavaFile javaClass = new JavaFile("", "Hello", false); - assertThat(javaClass.getKey(), is(JavaPackage.DEFAULT_PACKAGE_NAME + ".Hello")); + assertThat(javaClass.getDeprecatedKey(), is(JavaPackage.DEFAULT_PACKAGE_NAME + ".Hello")); assertThat(javaClass.getName(), is("Hello")); assertThat(javaClass.getLongName(), is("Hello")); - assertThat((javaClass.getParent()).isDefault(), is(true)); + assertThat(javaClass.getParent().isDefault(), is(true)); } @Test - public void testNewClassWithNullPackage() { + public void testNewClassWithNullPackageDeprecatedConstructor() { JavaFile javaClass = new JavaFile(null, "Hello", false); - assertThat(javaClass.getKey(), is(JavaPackage.DEFAULT_PACKAGE_NAME + ".Hello")); + assertThat(javaClass.getDeprecatedKey(), is(JavaPackage.DEFAULT_PACKAGE_NAME + ".Hello")); assertThat(javaClass.getName(), is("Hello")); assertThat(javaClass.getLongName(), is("Hello")); assertThat((javaClass.getParent()).isDefault(), is(true)); @@ -85,7 +109,7 @@ public class JavaFileTest { @Test public void shouldBeDefaultPackageIfNoPackage() { JavaFile javaClass = new JavaFile("Hello", false); - assertEquals(JavaPackage.DEFAULT_PACKAGE_NAME + ".Hello", javaClass.getKey()); + assertEquals(JavaPackage.DEFAULT_PACKAGE_NAME + ".Hello", javaClass.getDeprecatedKey()); assertThat(javaClass.getName(), is("Hello")); assertThat(javaClass.getLongName(), is("Hello")); assertThat(javaClass.getParent().isDefault(), is(true)); @@ -94,21 +118,21 @@ public class JavaFileTest { @Test public void aClassShouldBeNamedJava() { JavaFile javaClass = new JavaFile("org.foo.bar.Java", false); - assertThat(javaClass.getKey(), is("org.foo.bar.Java")); + assertThat(javaClass.getDeprecatedKey(), is("org.foo.bar.Java")); assertThat(javaClass.getLongName(), is("org.foo.bar.Java")); assertThat(javaClass.getName(), is("Java")); JavaPackage parent = javaClass.getParent(); - assertEquals("org.foo.bar", parent.getKey()); + assertEquals("org.foo.bar", parent.getDeprecatedKey()); } @Test public void shouldTrimClasses() { JavaFile clazz = new JavaFile(" org.foo.bar.Hello ", false); - assertThat(clazz.getKey(), is("org.foo.bar.Hello")); + assertThat(clazz.getDeprecatedKey(), is("org.foo.bar.Hello")); assertThat(clazz.getLongName(), is("org.foo.bar.Hello")); assertThat(clazz.getName(), is("Hello")); JavaPackage parent = clazz.getParent(); - assertThat(parent.getKey(), is("org.foo.bar")); + assertThat(parent.getDeprecatedKey(), is("org.foo.bar")); } @Test @@ -126,21 +150,21 @@ public class JavaFileTest { @Test public void oneLevelPackage() { JavaFile clazz = new JavaFile("onelevel.MyFile"); - assertEquals("onelevel.MyFile", clazz.getKey()); - assertEquals("onelevel", clazz.getParent().getKey()); + assertEquals("onelevel.MyFile", clazz.getDeprecatedKey()); + assertEquals("onelevel", clazz.getParent().getDeprecatedKey()); clazz = new JavaFile("onelevel", "MyFile"); - assertEquals("onelevel.MyFile", clazz.getKey()); - assertEquals("onelevel", clazz.getParent().getKey()); + assertEquals("onelevel.MyFile", clazz.getDeprecatedKey()); + assertEquals("onelevel", clazz.getParent().getDeprecatedKey()); File sourceDir = newDir("sources"); List<File> sources = Arrays.asList(sourceDir); JavaFile javaFile = JavaFile.fromAbsolutePath(absPath(sourceDir, "onelevel/MyFile.java"), sources, false); - assertEquals("onelevel.MyFile", javaFile.getKey()); + assertEquals("onelevel.MyFile", javaFile.getDeprecatedKey()); assertEquals("MyFile", javaFile.getName()); - assertEquals("onelevel", javaFile.getParent().getKey()); + assertEquals("onelevel", javaFile.getParent().getDeprecatedKey()); assertEquals("onelevel", javaFile.getParent().getName()); - assertThat((javaFile.getParent()).isDefault(), is(false)); + assertThat(javaFile.getParent().isDefault(), is(false)); } @Test @@ -149,10 +173,10 @@ public class JavaFileTest { File sources2 = newDir("source2"); List<File> sources = Arrays.asList(sources1, sources2); JavaFile javaFile = JavaFile.fromAbsolutePath(absPath(sources2, "foo/bar/MyFile.java"), sources, false); - assertThat("foo.bar.MyFile", is(javaFile.getKey())); + assertThat("foo.bar.MyFile", is(javaFile.getDeprecatedKey())); assertThat(javaFile.getLongName(), is("foo.bar.MyFile")); assertThat(javaFile.getName(), is("MyFile")); - assertThat(javaFile.getParent().getKey(), is("foo.bar")); + assertThat(javaFile.getParent().getDeprecatedKey(), is("foo.bar")); } @Test @@ -162,7 +186,7 @@ public class JavaFileTest { List<File> sources = Arrays.asList(source1, source2); JavaFile javaClass = JavaFile.fromAbsolutePath(absPath(source1, "MyClass.java"), sources, false); - assertEquals(JavaPackage.DEFAULT_PACKAGE_NAME + ".MyClass", javaClass.getKey()); + assertEquals(JavaPackage.DEFAULT_PACKAGE_NAME + ".MyClass", javaClass.getDeprecatedKey()); assertEquals("MyClass", javaClass.getName()); assertThat((javaClass.getParent()).isDefault(), is(true)); @@ -184,24 +208,24 @@ public class JavaFileTest { @Test public void shouldMatchFilePatterns() { - JavaFile clazz = new JavaFile("org.sonar.commons.Foo"); + JavaFile clazz = JavaFile.create("src/main/java/org/sonar/commons/Foo.java", "org/sonar/commons/Foo.java", false); assertTrue(clazz.matchFilePattern("**/commons/**/*.java")); assertTrue(clazz.matchFilePattern("/**/commons/**/*.java")); assertTrue(clazz.matchFilePattern("/**/commons/**/*.*")); assertFalse(clazz.matchFilePattern("/**/sonar/*.java")); - assertTrue(clazz.matchFilePattern("/org/*/commons/**/*.java")); - assertTrue(clazz.matchFilePattern("org/sonar/commons/*")); - assertTrue(clazz.matchFilePattern("org/sonar/**/*.java")); - assertFalse(clazz.matchFilePattern("org/sonar/*")); - assertFalse(clazz.matchFilePattern("org/sonar*/*")); - assertTrue(clazz.matchFilePattern("org/**")); - assertTrue(clazz.matchFilePattern("*org/sona?/co??ons/**.*")); - assertFalse(clazz.matchFilePattern("org/sonar/core/**")); - assertTrue(clazz.matchFilePattern("org/sonar/commons/Foo")); - assertTrue(clazz.matchFilePattern("**/*Foo")); + assertTrue(clazz.matchFilePattern("/src/main/java/org/*/commons/**/*.java")); + assertTrue(clazz.matchFilePattern("src/main/java/org/sonar/commons/*")); + assertTrue(clazz.matchFilePattern("src/main/java/org/sonar/**/*.java")); + assertFalse(clazz.matchFilePattern("src/main/java/org/sonar/*")); + assertFalse(clazz.matchFilePattern("src/main/java/org/sonar*/*")); + assertTrue(clazz.matchFilePattern("src/main/java/org/**")); + assertTrue(clazz.matchFilePattern("*src/main/java/org/sona?/co??ons/**.*")); + assertFalse(clazz.matchFilePattern("src/main/java/org/sonar/core/**")); + assertTrue(clazz.matchFilePattern("src/main/java/org/sonar/commons/Foo.java")); + assertTrue(clazz.matchFilePattern("**/*Foo.java")); assertTrue(clazz.matchFilePattern("**/*Foo.*")); - assertTrue(clazz.matchFilePattern("org/*/*/Foo")); - assertTrue(clazz.matchFilePattern("org/**/**/Foo")); + assertTrue(clazz.matchFilePattern("src/main/java/org/*/*/Foo.java")); + assertTrue(clazz.matchFilePattern("src/main/java/org/**/**/Foo.java")); assertTrue(clazz.matchFilePattern("**/commons/**/*")); assertTrue(clazz.matchFilePattern("**/*")); } @@ -209,11 +233,11 @@ public class JavaFileTest { // SONAR-4397 @Test public void shouldMatchFilePatternsWhenNoPackage() { - JavaFile clazz = new JavaFile("[default].Foo.java"); - assertTrue(clazz.matchFilePattern("**/*Foo")); + JavaFile clazz = JavaFile.create("src/main/java/Foo.java", "Foo.java", false); + assertTrue(clazz.matchFilePattern("**/*Foo.java")); assertTrue(clazz.matchFilePattern("**/*Foo.*")); assertTrue(clazz.matchFilePattern("**/*")); - assertTrue(clazz.matchFilePattern("Foo*.*")); + assertTrue(clazz.matchFilePattern("src/main/java/Foo*.*")); } /** @@ -221,14 +245,14 @@ public class JavaFileTest { */ @Test public void doNotMatchAPattern() { - JavaFile file = new JavaFile("org.sonar.commons.Foo"); + JavaFile file = JavaFile.create("src/main/java/org/sonar/commons/Foo.java", "org/sonar/commons/Foo.java", false); assertFalse(file.matchFilePattern("**/*.aj")); assertTrue(file.matchFilePattern("**/*.java")); } @Test public void should_exclude_test_files() { - JavaFile unitTest = new JavaFile("org.sonar.commons.FooTest", true); + JavaFile unitTest = JavaFile.create("src/main/java/org/sonar/commons/Foo.java", "org/sonar/commons/Foo.java", true); assertTrue(unitTest.matchFilePattern("**/*")); } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/JavaPackageTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/JavaPackageTest.java index 1a3a694df31..f2934b14478 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/JavaPackageTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/JavaPackageTest.java @@ -19,25 +19,37 @@ */ package org.sonar.api.resources; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; import org.junit.Test; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; + public class JavaPackageTest { @Test public void defaultPackage() { assertEquals(new JavaPackage(), new JavaPackage()); - assertEquals(JavaPackage.DEFAULT_PACKAGE_NAME, new JavaPackage(null).getKey()); + assertEquals(JavaPackage.DEFAULT_PACKAGE_NAME, new JavaPackage(null).getDeprecatedKey()); assertEquals(JavaPackage.DEFAULT_PACKAGE_NAME, new JavaPackage(null).getName()); - assertEquals(JavaPackage.DEFAULT_PACKAGE_NAME, new JavaPackage("").getKey()); + assertEquals(JavaPackage.DEFAULT_PACKAGE_NAME, new JavaPackage("").getDeprecatedKey()); assertThat(new JavaPackage(null).isDefault(), is(true)); } @Test public void testNewPackage() { + assertEquals(JavaPackage.create("src/foo/bar", " foo.bar "), JavaPackage.create("src/foo/bar", "foo.bar")); + JavaPackage pac = JavaPackage.create("src/foo/bar", "foo.bar"); + assertEquals("/src/foo/bar", pac.getKey()); + assertEquals("foo.bar", pac.getDeprecatedKey()); + assertEquals("foo.bar", pac.getName()); + } + + @Test + public void testNewPackageDeprecatedConstructor() { assertEquals(new JavaPackage(" foo.bar "), new JavaPackage("foo.bar")); JavaPackage pac = new JavaPackage("foo.bar"); - assertEquals("foo.bar", pac.getKey()); + assertEquals("foo.bar", pac.getDeprecatedKey()); assertEquals("foo.bar", pac.getName()); } @@ -45,7 +57,7 @@ public class JavaPackageTest { public void singleLevelPackage() { assertEquals(new JavaPackage("foo"), new JavaPackage("foo")); JavaPackage pac = new JavaPackage("foo"); - assertEquals("foo", pac.getKey()); + assertEquals("foo", pac.getDeprecatedKey()); assertEquals("foo", pac.getName()); } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/test/IsResource.java b/sonar-plugin-api/src/test/java/org/sonar/api/test/IsResource.java index a51e9ff45bc..97c4c048ad8 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/test/IsResource.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/test/IsResource.java @@ -43,7 +43,7 @@ public class IsResource extends ArgumentMatcher<Resource> { @Override public boolean matches(Object o) { Resource r = (Resource) o; - boolean keyMatch = (key != null) ? StringUtils.equals(r.getKey(), key) : true; + boolean keyMatch = (key != null) ? StringUtils.equals(r.getKey() != null ? r.getKey() : r.getDeprecatedKey(), key) : true; return ObjectUtils.equals(r.getScope(), scope) && ObjectUtils.equals(r.getQualifier(), qualifier) && keyMatch; } } diff --git a/sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java b/sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java index 1aecb99a500..ab2502ba3f1 100644 --- a/sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java +++ b/sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java @@ -67,6 +67,7 @@ public class DefaultRubyComponentService implements RubyComponentService { resourceDao.insertOrUpdate( new ResourceDto() .setKey(kee) + .setDeprecatedKey(kee) .setName(name) .setLongName(name) .setScope(Scopes.PROJECT) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/project.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/project.rb index 67566d62e7a..782db34abcd 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/project.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/project.rb @@ -40,7 +40,11 @@ class Project < ActiveRecord::Base ki=Integer(k) Project.find(ki) rescue - Project.first(:conditions => {:kee => k}) + resource = Project.first(:conditions => {:kee => k}) + if (resource.nil?) + resource = Project.first(:conditions => {:deprecated_kee => k}) + end + resource end end @@ -57,9 +61,9 @@ class Project < ActiveRecord::Base java_facade.deleteResourceTree(project.id) end end - + def self.root_qualifiers() - @root_types ||= + @root_types ||= begin Java::OrgSonarServerUi::JRubyFacade.getInstance().getResourceRootTypes().map {|type| type.getQualifier()} end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/488_add_project_deprecated_key_column.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/488_add_project_deprecated_key_column.rb new file mode 100644 index 00000000000..9d22d40d9b9 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/488_add_project_deprecated_key_column.rb @@ -0,0 +1,30 @@ +# +# 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. +# + +# +# SonarQube 4.2 +# SONAR-926 +# +class AddProjectDeprecatedKeyColumn < ActiveRecord::Migration + + def self.up + add_column 'projects', 'deprecated_kee', :string, :null => true, :limit => 400 + end +end |