aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-03-25 10:24:16 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2014-03-25 12:45:16 +0100
commit74abc65d43b9f5af2fd67a8c316c36afec4bed8d (patch)
treed378ed4ebdee816272ea0f46510afa2ab06c0c53 /sonar-batch
parent9e4f4088f57a688e7865604ac3eef7153fc19eec (diff)
downloadsonarqube-74abc65d43b9f5af2fd67a8c316c36afec4bed8d.tar.gz
sonarqube-74abc65d43b9f5af2fd67a8c316c36afec4bed8d.zip
SONAR-5154 A plugin should fail when using classes JavaFile or JavaPackage
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java27
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/ResourceKeyMigration.java17
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java6
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputFileBuilder.java7
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/util/DeprecatedKeyUtils.java74
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/util/package-info.java23
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/BucketTest.java24
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java7
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java30
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/ResourceCacheTest.java8
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java6
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java22
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java10
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/util/DeprecatedKeyUtilsTest.java40
14 files changed, 225 insertions, 76 deletions
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 4f304015b01..8ef04f07abc 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
@@ -31,8 +31,19 @@ import org.sonar.api.batch.SonarIndex;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.design.Dependency;
-import org.sonar.api.measures.*;
-import org.sonar.api.resources.*;
+import org.sonar.api.measures.Measure;
+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.Project;
+import org.sonar.api.resources.ProjectLink;
+import org.sonar.api.resources.Qualifiers;
+import org.sonar.api.resources.Resource;
+import org.sonar.api.resources.ResourceUtils;
+import org.sonar.api.resources.Scopes;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.Violation;
import org.sonar.api.scan.filesystem.PathResolver;
@@ -46,7 +57,15 @@ import org.sonar.core.component.ScanGraph;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-import java.util.*;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
public class DefaultIndex extends SonarIndex {
@@ -566,7 +585,7 @@ public class DefaultIndex extends SonarIndex {
* Should support 2 situations
* 1) key = new key and deprecatedKey = old key : this is the standard use case in a perfect world
* 2) key = null and deprecatedKey = oldKey : this is for plugins that are using deprecated constructors of
- * {@link JavaFile}, {@link JavaPackage}, {@link File}, {@link Directory}
+ * {@link File} and {@link Directory}
*
* @param reference
* @return
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/ResourceKeyMigration.java b/sonar-batch/src/main/java/org/sonar/batch/index/ResourceKeyMigration.java
index 3c1266e58f3..b0b6cf50cb6 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/ResourceKeyMigration.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/ResourceKeyMigration.java
@@ -29,8 +29,14 @@ import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.ResourceModel;
-import org.sonar.api.resources.*;
+import org.sonar.api.resources.Directory;
+import org.sonar.api.resources.File;
+import org.sonar.api.resources.Project;
+import org.sonar.api.resources.Qualifiers;
+import org.sonar.api.resources.Resource;
+import org.sonar.api.resources.Scopes;
import org.sonar.api.utils.PathUtils;
+import org.sonar.batch.util.DeprecatedKeyUtils;
import java.util.HashMap;
import java.util.List;
@@ -90,8 +96,8 @@ public class ResourceKeyMigration implements BatchComponent {
}
private void migrateFiles(Project module, Map<String, InputFile> deprecatedFileKeyMapper, Map<String, InputFile> deprecatedTestKeyMapper,
- Map<String, String> deprecatedDirectoryKeyMapper,
- int moduleId) {
+ Map<String, String> deprecatedDirectoryKeyMapper,
+ int moduleId) {
// Find all FIL or CLA resources for this module
StringBuilder hql = new StringBuilder().append("from ")
.append(ResourceModel.class.getSimpleName())
@@ -108,12 +114,13 @@ public class ResourceKeyMigration implements BatchComponent {
// Now compute migration of the parent dir
String oldKey = StringUtils.substringAfterLast(oldEffectiveKey, ":");
Resource sonarFile;
+ String parentOldKey;
if ("java".equals(resourceModel.getLanguageKey())) {
- sonarFile = new JavaFile(oldKey);
+ parentOldKey = module.getEffectiveKey() + ":" + DeprecatedKeyUtils.getJavaFileParentDeprecatedKey(oldKey);
} else {
sonarFile = new File(oldKey);
+ parentOldKey = module.getEffectiveKey() + ":" + sonarFile.getParent().getDeprecatedKey();
}
- String parentOldKey = module.getEffectiveKey() + ":" + sonarFile.getParent().getDeprecatedKey();
String parentNewKey = module.getEffectiveKey() + ":" + getParentKey(matchedFile);
if (!deprecatedDirectoryKeyMapper.containsKey(parentOldKey)) {
deprecatedDirectoryKeyMapper.put(parentOldKey, parentNewKey);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java
index 8d31f3b5a39..e398cd6b98b 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java
@@ -30,12 +30,12 @@ import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.config.Settings;
import org.sonar.api.resources.File;
-import org.sonar.api.resources.JavaFile;
import org.sonar.api.resources.Languages;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.utils.SonarException;
import org.sonar.batch.index.ResourceKeyMigration;
+import org.sonar.batch.util.DeprecatedKeyUtils;
/**
* Index all files/directories of the module in SQ database and importing source code.
@@ -52,7 +52,7 @@ public class ComponentIndexer implements BatchComponent {
private InputFileCache fileCache;
public ComponentIndexer(Project module, Languages languages, SonarIndex sonarIndex, Settings settings, ResourceKeyMigration migration,
- InputFileCache fileCache) {
+ InputFileCache fileCache) {
this.module = module;
this.languages = languages;
this.sonarIndex = sonarIndex;
@@ -74,7 +74,7 @@ public class ComponentIndexer implements BatchComponent {
}
Resource sonarFile = File.create(inputFile.relativePath(), pathFromSourceDir, languages.get(languageKey), unitTest);
if ("java".equals(languageKey)) {
- sonarFile.setDeprecatedKey(JavaFile.fromRelativePath(pathFromSourceDir, false).getDeprecatedKey());
+ sonarFile.setDeprecatedKey(DeprecatedKeyUtils.getJavaFileDeprecatedKey(pathFromSourceDir));
} else {
sonarFile.setDeprecatedKey(pathFromSourceDir);
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputFileBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputFileBuilder.java
index 99c7f0fe08a..ca456838bf9 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputFileBuilder.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputFileBuilder.java
@@ -24,11 +24,12 @@ import org.slf4j.LoggerFactory;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.resources.JavaFile;
import org.sonar.api.scan.filesystem.PathResolver;
import org.sonar.batch.bootstrap.AnalysisMode;
+import org.sonar.batch.util.DeprecatedKeyUtils;
import javax.annotation.CheckForNull;
+
import java.io.File;
import java.util.List;
@@ -42,7 +43,7 @@ class InputFileBuilder {
private final AnalysisMode analysisMode;
InputFileBuilder(String moduleKey, PathResolver pathResolver, LanguageDetection langDetection,
- StatusDetection statusDetection, DefaultModuleFileSystem fs, AnalysisMode analysisMode) {
+ StatusDetection statusDetection, DefaultModuleFileSystem fs, AnalysisMode analysisMode) {
this.moduleKey = moduleKey;
this.pathResolver = pathResolver;
this.langDetection = langDetection;
@@ -119,7 +120,7 @@ class InputFileBuilder {
if ("java".equals(inputFile.language())) {
inputFile.setDeprecatedKey(new StringBuilder()
- .append(moduleKey).append(":").append(JavaFile.fromRelativePath(sourceRelativePath, false).getDeprecatedKey()).toString());
+ .append(moduleKey).append(":").append(DeprecatedKeyUtils.getJavaFileDeprecatedKey(sourceRelativePath)).toString());
} else {
inputFile.setDeprecatedKey(new StringBuilder().append(moduleKey).append(":").append(sourceRelativePath).toString());
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/util/DeprecatedKeyUtils.java b/sonar-batch/src/main/java/org/sonar/batch/util/DeprecatedKeyUtils.java
new file mode 100644
index 00000000000..30db633da28
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/util/DeprecatedKeyUtils.java
@@ -0,0 +1,74 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.batch.util;
+
+import org.apache.commons.lang.StringUtils;
+import org.sonar.api.resources.Directory;
+import org.sonar.api.resources.JavaPackage;
+
+public class DeprecatedKeyUtils {
+
+ private DeprecatedKeyUtils() {
+ // Utility class
+ }
+
+ /**
+ * Return the parent directory deprecated key for a given deprecated Java file key.
+ * "com.foo.Bar" -> "com/foo"
+ * "[root].Bar" -> "[root]"
+ * "Bar" -> "[root]"
+ */
+ public static String getJavaFileParentDeprecatedKey(String deprecatedJavaFileKey) {
+ String packageFullyQualifiedName;
+ String realKey = StringUtils.trim(deprecatedJavaFileKey);
+ if (realKey.contains(".")) {
+ packageFullyQualifiedName = StringUtils.substringBeforeLast(realKey, ".");
+ String deprecatedDirectoryKey = StringUtils.trimToEmpty(packageFullyQualifiedName);
+ if (JavaPackage.DEFAULT_PACKAGE_NAME.equals(deprecatedDirectoryKey)) {
+ return Directory.ROOT;
+ }
+ deprecatedDirectoryKey = deprecatedDirectoryKey.replaceAll("\\.", Directory.SEPARATOR);
+ return StringUtils.defaultIfEmpty(deprecatedDirectoryKey, Directory.ROOT);
+ } else {
+ return Directory.ROOT;
+ }
+ }
+
+ /**
+ * Return the deprecated key of a Java file given its path relative to source directory.
+ */
+ public static String getJavaFileDeprecatedKey(String sourceRelativePath) {
+ String pacname = null;
+ String classname = sourceRelativePath;
+
+ if (sourceRelativePath.indexOf('/') >= 0) {
+ pacname = StringUtils.substringBeforeLast(sourceRelativePath, "/");
+ pacname = StringUtils.replace(pacname, "/", ".");
+ classname = StringUtils.substringAfterLast(sourceRelativePath, "/");
+ }
+ classname = StringUtils.substringBeforeLast(classname, ".");
+ if (StringUtils.isBlank(pacname)) {
+ return new StringBuilder().append(JavaPackage.DEFAULT_PACKAGE_NAME).append(".").append(classname).toString();
+ } else {
+ return new StringBuilder().append(pacname.trim()).append(".").append(classname).toString();
+ }
+ }
+
+}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/util/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/util/package-info.java
new file mode 100644
index 00000000000..66aecc70d7b
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/util/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 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.
+ */
+
+@javax.annotation.ParametersAreNonnullByDefault
+package org.sonar.batch.util;
+
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/BucketTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/BucketTest.java
index 62cbb1e5d04..2fc521a64d5 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/BucketTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/BucketTest.java
@@ -23,26 +23,26 @@ import org.junit.Test;
import org.sonar.api.measures.Measure;
import org.sonar.api.measures.MeasuresFilters;
import org.sonar.api.measures.Metric;
-import org.sonar.api.resources.JavaFile;
-import org.sonar.api.resources.JavaPackage;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.Violation;
+import org.sonar.api.resources.Directory;
+import org.sonar.api.resources.File;
import org.sonar.api.utils.SonarException;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.core.IsNot.not;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
import static org.junit.internal.matchers.IsCollectionContaining.hasItem;
public class BucketTest {
- JavaPackage javaPackage = new JavaPackage("org.foo");
- JavaFile javaFile = new JavaFile("org.foo.Bar");
+ Directory directory = new Directory("org/foo");
+ File javaFile = new File("org/foo/Bar.java");
Metric ncloc = new Metric("ncloc");
@Test
public void shouldManageRelationships() {
- Bucket packageBucket = new Bucket(javaPackage);
+ Bucket packageBucket = new Bucket(directory);
Bucket fileBucket = new Bucket(javaFile);
fileBucket.setParent(packageBucket);
@@ -89,13 +89,13 @@ public class BucketTest {
@Test
public void shouldBeEquals() {
- assertEquals(new Bucket(javaPackage), new Bucket(javaPackage));
- assertEquals(new Bucket(javaPackage).hashCode(), new Bucket(javaPackage).hashCode());
+ assertEquals(new Bucket(directory), new Bucket(directory));
+ assertEquals(new Bucket(directory).hashCode(), new Bucket(directory).hashCode());
}
@Test
public void shouldNotBeEquals() {
- assertFalse(new Bucket(javaPackage).equals(new Bucket(javaFile)));
- assertThat(new Bucket(javaPackage).hashCode(), not(is(new Bucket(javaFile).hashCode())));
+ assertFalse(new Bucket(directory).equals(new Bucket(javaFile)));
+ assertThat(new Bucket(directory).hashCode(), not(is(new Bucket(javaFile).hashCode())));
}
}
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 7ce169a9dae..a89a72bdd87 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
@@ -26,8 +26,7 @@ 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.File;
import org.sonar.api.resources.Library;
import org.sonar.api.resources.Project;
import org.sonar.api.security.ResourcePermissions;
@@ -172,8 +171,8 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
DefaultResourcePersister persister = new DefaultResourcePersister(getSession(), mock(ResourcePermissions.class), snapshotCache, resourceCache);
persister.saveProject(multiModuleProject, null);
persister.saveProject(moduleA, multiModuleProject);
- persister.saveResource(moduleA, new JavaPackage("org.foo").setEffectiveKey("a:org.foo"));
- persister.saveResource(moduleA, new JavaFile("org.foo.MyClass").setEffectiveKey("a:org.foo.MyClass"));
+ persister.saveResource(moduleA, new Directory("org/foo").setEffectiveKey("a:org/foo"));
+ persister.saveResource(moduleA, new File("org/foo/MyClass.java").setEffectiveKey("a:org/foo/MyClass.java"));
persister.clear();
assertThat(persister.getSnapshotsByResource().size(), is(2));
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java
index f67844538c7..fc3a69628d2 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java
@@ -26,9 +26,13 @@ import org.junit.rules.ExpectedException;
import org.mockito.ArgumentCaptor;
import org.sonar.api.database.model.MeasureModel;
import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.measures.*;
-import org.sonar.api.resources.JavaFile;
-import org.sonar.api.resources.JavaPackage;
+import org.sonar.api.measures.CoreMetrics;
+import org.sonar.api.measures.Measure;
+import org.sonar.api.measures.Metric;
+import org.sonar.api.measures.PersistenceMode;
+import org.sonar.api.measures.RuleMeasure;
+import org.sonar.api.resources.Directory;
+import org.sonar.api.resources.File;
import org.sonar.api.resources.Project;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleFinder;
@@ -39,7 +43,9 @@ import org.sonar.core.persistence.AbstractDaoTestCase;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class MeasurePersisterTest extends AbstractDaoTestCase {
@@ -60,17 +66,17 @@ public class MeasurePersisterTest extends AbstractDaoTestCase {
ResourcePersister resourcePersister = mock(ResourcePersister.class);
MemoryOptimizer memoryOptimizer = mock(MemoryOptimizer.class);
Project project = new Project("foo");
- JavaPackage aPackage = new JavaPackage("org.foo");
- JavaFile aFile = new JavaFile("org.foo.Bar");
+ Directory aDirectory = new Directory("org/foo");
+ File aFile = new File("org/foo/Bar.java");
Snapshot projectSnapshot = snapshot(PROJECT_SNAPSHOT_ID);
Snapshot packageSnapshot = snapshot(PACKAGE_SNAPSHOT_ID);
@Before
public void mockResourcePersister() {
when(resourcePersister.getSnapshotOrFail(project)).thenReturn(projectSnapshot);
- when(resourcePersister.getSnapshotOrFail(aPackage)).thenReturn(packageSnapshot);
+ when(resourcePersister.getSnapshotOrFail(aDirectory)).thenReturn(packageSnapshot);
when(resourcePersister.getSnapshot(project)).thenReturn(projectSnapshot);
- when(resourcePersister.getSnapshot(aPackage)).thenReturn(packageSnapshot);
+ when(resourcePersister.getSnapshot(aDirectory)).thenReturn(packageSnapshot);
measurePersister = new MeasurePersister(getMyBatis(), resourcePersister, ruleFinder, memoryOptimizer);
}
@@ -160,7 +166,7 @@ public class MeasurePersisterTest extends AbstractDaoTestCase {
setupData("empty");
measurePersister.saveMeasure(project, new Measure(ncloc()).setValue(200.0));
- measurePersister.saveMeasure(aPackage, new Measure(ncloc()).setValue(300.0));
+ measurePersister.saveMeasure(aDirectory, new Measure(ncloc()).setValue(300.0));
checkTables("shouldAlwaysPersistNonFileMeasures", "project_measures");
}
@@ -171,7 +177,7 @@ public class MeasurePersisterTest extends AbstractDaoTestCase {
measurePersister.saveMeasure(project, new Measure(coverage()).setValue(12.5).setId(1L));
measurePersister.saveMeasure(project, new Measure(coverage()).setData(SHORT).setId(2L));
- measurePersister.saveMeasure(aPackage, new Measure(coverage()).setData(LONG).setId(3L));
+ measurePersister.saveMeasure(aDirectory, new Measure(coverage()).setData(LONG).setId(3L));
checkTables("shouldUpdateMeasure", "project_measures", "measure_data");
}
@@ -196,7 +202,7 @@ public class MeasurePersisterTest extends AbstractDaoTestCase {
measurePersister.setDelayedMode(true);
measurePersister.saveMeasure(project, new Measure(ncloc()).setValue(1234.0).setData(SHORT));
- measurePersister.saveMeasure(aPackage, new Measure(ncloc()).setValue(50.0).setData(LONG));
+ measurePersister.saveMeasure(aDirectory, new Measure(ncloc()).setValue(50.0).setData(LONG));
assertEmptyTables("project_measures");
@@ -224,7 +230,7 @@ public class MeasurePersisterTest extends AbstractDaoTestCase {
measurePersister.setDelayedMode(true);
measurePersister.saveMeasure(project, new Measure(ncloc()).setValue(1234.0).setPersistenceMode(PersistenceMode.DATABASE));
- measurePersister.saveMeasure(aPackage, new Measure(ncloc()).setValue(50.0));
+ measurePersister.saveMeasure(aDirectory, new Measure(ncloc()).setValue(50.0));
checkTables("shouldInsertMeasure", "project_measures");
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/ResourceCacheTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/ResourceCacheTest.java
index 7a6014c22cc..20e04957309 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/ResourceCacheTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/ResourceCacheTest.java
@@ -20,7 +20,7 @@
package org.sonar.batch.index;
import org.junit.Test;
-import org.sonar.api.resources.JavaFile;
+import org.sonar.api.resources.File;
import org.sonar.api.resources.Resource;
import static org.fest.assertions.Assertions.assertThat;
@@ -30,8 +30,8 @@ public class ResourceCacheTest {
@Test
public void should_cache_resource() throws Exception {
ResourceCache cache = new ResourceCache();
- String componentKey = "struts:org.struts.Action";
- Resource resource = new JavaFile("org.struts.Action").setEffectiveKey(componentKey);
+ String componentKey = "struts:src/org/struts/Action.java";
+ Resource resource = new File("org/struts/Action.java").setEffectiveKey(componentKey);
cache.add(resource);
assertThat(cache.get(componentKey)).isSameAs(resource);
@@ -41,7 +41,7 @@ public class ResourceCacheTest {
@Test
public void should_fail_if_missing_component_key() throws Exception {
ResourceCache cache = new ResourceCache();
- Resource resource = new JavaFile("org.struts.Action").setEffectiveKey(null);
+ Resource resource = new File("org/struts/Action.java").setEffectiveKey(null);
try {
cache.add(resource);
fail();
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java
index c30991832d9..39f4095ccd2 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java
@@ -23,7 +23,7 @@ import org.junit.Before;
import org.junit.Test;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.DuplicatedSourceException;
-import org.sonar.api.resources.JavaFile;
+import org.sonar.api.resources.File;
import org.sonar.api.resources.Resource;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
@@ -46,13 +46,13 @@ public class SourcePersisterTest extends AbstractDbUnitTestCase {
@Test
public void shouldSaveSource() {
- sourcePersister.saveSource(new JavaFile("org.foo.Bar"), "this is the file content");
+ sourcePersister.saveSource(new File("org/foo/Bar.java"), "this is the file content");
checkTables("shouldSaveSource", "snapshot_sources");
}
@Test(expected = DuplicatedSourceException.class)
public void shouldFailIfSourceSavedSeveralTimes() {
- JavaFile file = new JavaFile("org.foo.Bar");
+ File file = new File("org/foo/Bar.java");
sourcePersister.saveSource(file, "this is the file content");
sourcePersister.saveSource(file, "new content"); // fail
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java
index 48f3315445c..d11d0a72111 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java
@@ -24,10 +24,8 @@ import org.mockito.Mockito;
import org.sonar.api.component.Component;
import org.sonar.api.issue.Issuable;
import org.sonar.api.resources.File;
-import org.sonar.api.resources.JavaFile;
import org.sonar.api.resources.Project;
import org.sonar.core.component.ResourceComponent;
-import org.sonar.java.api.JavaClass;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@@ -58,24 +56,4 @@ public class IssuableFactoryTest {
assertThat(issuable.component()).isSameAs(component);
assertThat(issuable.issues()).isEmpty();
}
-
- @Test
- public void java_file_should_be_issuable() throws Exception {
- IssuableFactory factory = new IssuableFactory(moduleIssues, cache);
- Component component = new ResourceComponent(new JavaFile("org.apache.Action").setEffectiveKey("struts:org.apache.Action"));
- Issuable issuable = factory.loadPerspective(Issuable.class, component);
-
- assertThat(issuable).isNotNull();
- assertThat(issuable.component()).isSameAs(component);
- assertThat(issuable.issues()).isEmpty();
- }
-
- @Test
- public void java_class_should_not_be_issuable() throws Exception {
- IssuableFactory factory = new IssuableFactory(moduleIssues, cache);
- Component component = new ResourceComponent(JavaClass.create("org.apache.Action").setEffectiveKey("struts:org.apache.Action"));
- Issuable issuable = factory.loadPerspective(Issuable.class, component);
-
- assertThat(issuable).isNull();
- }
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java
index f5b920c3b3c..5a5f8ef282d 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java
@@ -30,7 +30,7 @@ import org.sonar.api.batch.rule.DebtRemediationFunction;
import org.sonar.api.batch.rule.internal.ActiveRulesBuilder;
import org.sonar.api.batch.rule.internal.RulesBuilder;
import org.sonar.api.issue.internal.DefaultIssue;
-import org.sonar.api.resources.JavaFile;
+import org.sonar.api.resources.File;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.rule.RuleKey;
@@ -47,7 +47,9 @@ import static org.fest.assertions.Assertions.assertThat;
import static org.fest.assertions.Fail.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class ModuleIssuesTest {
@@ -205,7 +207,7 @@ public class ModuleIssuesTest {
initModuleIssues();
org.sonar.api.rules.Rule rule = org.sonar.api.rules.Rule.create("squid", "AvoidCycle", "Avoid Cycle");
- Resource resource = new JavaFile("org.struts.Action").setEffectiveKey("struts:org.struts.Action");
+ Resource resource = new File("org/struts/Action.java").setEffectiveKey("struts:src/org/struts/Action.java");
Violation violation = new Violation(rule, resource);
violation.setLineId(42);
violation.setSeverity(RulePriority.CRITICAL);
@@ -224,7 +226,7 @@ public class ModuleIssuesTest {
assertThat(issue.message()).isEqualTo("the message");
assertThat(issue.key()).isNotEmpty();
assertThat(issue.ruleKey().toString()).isEqualTo("squid:AvoidCycle");
- assertThat(issue.componentKey()).isEqualTo("struts:org.struts.Action");
+ assertThat(issue.componentKey()).isEqualTo("struts:src/org/struts/Action.java");
}
@Test
diff --git a/sonar-batch/src/test/java/org/sonar/batch/util/DeprecatedKeyUtilsTest.java b/sonar-batch/src/test/java/org/sonar/batch/util/DeprecatedKeyUtilsTest.java
new file mode 100644
index 00000000000..989bcd27ceb
--- /dev/null
+++ b/sonar-batch/src/test/java/org/sonar/batch/util/DeprecatedKeyUtilsTest.java
@@ -0,0 +1,40 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.batch.util;
+
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class DeprecatedKeyUtilsTest {
+
+ @Test
+ public void testGetJavaFileParentDeprecatedKey() {
+ assertThat(DeprecatedKeyUtils.getJavaFileParentDeprecatedKey("org.foo.bar.Hello")).isEqualTo("org/foo/bar");
+ assertThat(DeprecatedKeyUtils.getJavaFileParentDeprecatedKey("[default].Hello")).isEqualTo("[root]");
+ assertThat(DeprecatedKeyUtils.getJavaFileParentDeprecatedKey("Hello")).isEqualTo("[root]");
+ }
+
+ @Test
+ public void testGetJavaFileDeprecatedKey() {
+ assertThat(DeprecatedKeyUtils.getJavaFileDeprecatedKey("org/foo/bar/Hello.java")).isEqualTo("org.foo.bar.Hello");
+ assertThat(DeprecatedKeyUtils.getJavaFileDeprecatedKey("Hello.java")).isEqualTo("[default].Hello");
+ }
+}