aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/DirectoriesDecoratorTest.java33
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ManualMeasureDecoratorTest.java4
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TendencyDecoratorTest.java30
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java39
-rw-r--r--plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/decorators/SumDuplicationsDecoratorTest.java11
-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
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/batch/SquidUtils.java28
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/resources/JavaFile.java239
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/resources/JavaPackage.java79
-rw-r--r--sonar-deprecated/src/test/java/org/sonar/api/batch/SquidUtilsTest.java21
-rw-r--r--sonar-deprecated/src/test/java/org/sonar/api/resources/JavaFileTest.java264
-rw-r--r--sonar-deprecated/src/test/java/org/sonar/api/resources/JavaPackageTest.java70
-rw-r--r--sonar-deprecated/src/test/java/org/sonar/api/utils/CoberturaReportParserUtilsTest.java23
26 files changed, 441 insertions, 701 deletions
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/DirectoriesDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/DirectoriesDecoratorTest.java
index 5078959dfe9..adb52dfece0 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/DirectoriesDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/DirectoriesDecoratorTest.java
@@ -23,14 +23,20 @@ import org.junit.Test;
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
-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.Resource;
import java.util.Arrays;
import java.util.Collections;
import static org.mockito.Matchers.anyDouble;
import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class DirectoriesDecoratorTest {
@@ -61,33 +67,24 @@ public class DirectoriesDecoratorTest {
DecoratorContext context = mock(DecoratorContext.class);
when(context.getChildrenMeasures(CoreMetrics.DIRECTORIES)).thenReturn(Arrays.<Measure>asList(
- new Measure(CoreMetrics.DIRECTORIES, 1.0),
- new Measure(CoreMetrics.DIRECTORIES, 1.0),
- new Measure(CoreMetrics.DIRECTORIES, 1.0)
- ));
+ new Measure(CoreMetrics.DIRECTORIES, 1.0),
+ new Measure(CoreMetrics.DIRECTORIES, 1.0),
+ new Measure(CoreMetrics.DIRECTORIES, 1.0)
+ ));
decorator.decorate(project, context);
verify(context).saveMeasure(CoreMetrics.DIRECTORIES, 3.0);
}
@Test
- public void packagesAreConsideredAsDirectories() {
- DirectoriesDecorator decorator = new DirectoriesDecorator();
- Resource pac = new JavaPackage("org/foo");
- DecoratorContext context = mock(DecoratorContext.class);
- decorator.decorate(pac, context);
- verify(context).saveMeasure(eq(CoreMetrics.DIRECTORIES), eq(1.0));
- }
-
- @Test
public void noProjectValueWhenOnlyPackages() {
DirectoriesDecorator decorator = new DirectoriesDecorator();
Resource project = new Project("project");
DecoratorContext context = mock(DecoratorContext.class);
when(context.getChildrenMeasures(CoreMetrics.DIRECTORIES)).thenReturn(Collections.<Measure>emptyList());
when(context.getChildrenMeasures(CoreMetrics.PACKAGES)).thenReturn(Arrays.<Measure>asList(
- new Measure(CoreMetrics.PACKAGES, 1.0),
- new Measure(CoreMetrics.PACKAGES, 1.0)
- ));
+ new Measure(CoreMetrics.PACKAGES, 1.0),
+ new Measure(CoreMetrics.PACKAGES, 1.0)
+ ));
decorator.decorate(project, context);
verify(context, never()).saveMeasure(eq(CoreMetrics.DIRECTORIES), anyDouble());
}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ManualMeasureDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ManualMeasureDecoratorTest.java
index ed824032359..2731680adc9 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ManualMeasureDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ManualMeasureDecoratorTest.java
@@ -22,7 +22,7 @@ package org.sonar.plugins.core.sensors;
import org.junit.Test;
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.measures.Metric;
-import org.sonar.api.resources.JavaFile;
+import org.sonar.api.resources.File;
import org.sonar.api.test.IsMeasure;
import org.sonar.core.metric.DefaultMetricFinder;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
@@ -39,7 +39,7 @@ public class ManualMeasureDecoratorTest extends AbstractDbUnitTestCase {
public void testCopyManualMeasures() throws Exception {
setupData("testCopyManualMeasures");
- JavaFile javaFile = new JavaFile("Foo.java");
+ File javaFile = new File("Foo.java");
javaFile.setId(40);
ManualMeasureDecorator decorator = new ManualMeasureDecorator(getSession(), new DefaultMetricFinder(getSessionFactory()));
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TendencyDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TendencyDecoratorTest.java
index 55c8316da8b..8713c66537b 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TendencyDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TendencyDecoratorTest.java
@@ -26,7 +26,7 @@ import org.sonar.api.batch.TimeMachineQuery;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
import org.sonar.api.measures.MetricFinder;
-import org.sonar.api.resources.JavaPackage;
+import org.sonar.api.resources.Directory;
import org.sonar.api.resources.Project;
import java.text.ParseException;
@@ -37,7 +37,11 @@ import java.util.Date;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.matchers.JUnitMatchers.hasItems;
-import static org.mockito.Mockito.*;
+import static org.mockito.Matchers.anyList;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class TendencyDecoratorTest {
@@ -65,19 +69,19 @@ public class TendencyDecoratorTest {
TimeMachine timeMachine = mock(TimeMachine.class);
when(timeMachine.getMeasuresFields(query)).thenReturn(Arrays.<Object[]>asList(
- new Object[]{date("2009-12-01"), CoreMetrics.LINES, 1200.0},
- new Object[]{date("2009-12-01"), CoreMetrics.COVERAGE, 80.5},
- new Object[]{date("2009-12-02"), CoreMetrics.LINES, 1300.0},
- new Object[]{date("2009-12-02"), CoreMetrics.COVERAGE, 79.6},
- new Object[]{date("2009-12-15"), CoreMetrics.LINES, 1150.0}
- ));
+ new Object[] {date("2009-12-01"), CoreMetrics.LINES, 1200.0},
+ new Object[] {date("2009-12-01"), CoreMetrics.COVERAGE, 80.5},
+ new Object[] {date("2009-12-02"), CoreMetrics.LINES, 1300.0},
+ new Object[] {date("2009-12-02"), CoreMetrics.COVERAGE, 79.6},
+ new Object[] {date("2009-12-15"), CoreMetrics.LINES, 1150.0}
+ ));
DecoratorContext context = mock(DecoratorContext.class);
when(context.getMeasure(CoreMetrics.LINES)).thenReturn(new Measure(CoreMetrics.LINES, 1400.0));
when(context.getMeasure(CoreMetrics.COVERAGE)).thenReturn(new Measure(CoreMetrics.LINES, 90.0));
TendencyDecorator decorator = new TendencyDecorator(timeMachine, query, analyser);
- decorator.decorate(new JavaPackage("org.foo"), context);
+ decorator.decorate(new Directory("org/foo"), context);
verify(analyser).analyseLevel(Arrays.asList(1200.0, 1300.0, 1150.0, 1400.0));
verify(analyser).analyseLevel(Arrays.asList(80.5, 79.6, 90.0));
@@ -90,13 +94,13 @@ public class TendencyDecoratorTest {
TimeMachine timeMachine = mock(TimeMachine.class);
when(timeMachine.getMeasuresFields(query)).thenReturn(Arrays.<Object[]>asList(
- new Object[]{date("2009-12-01"), CoreMetrics.LINES, 1200.0},
- new Object[]{date("2009-12-02"), CoreMetrics.LINES, 1300.0}
- ));
+ new Object[] {date("2009-12-01"), CoreMetrics.LINES, 1200.0},
+ new Object[] {date("2009-12-02"), CoreMetrics.LINES, 1300.0}
+ ));
DecoratorContext context = mock(DecoratorContext.class);
TendencyDecorator decorator = new TendencyDecorator(timeMachine, query, analyser);
- decorator.decorate(new JavaPackage("org.foo"), context);
+ decorator.decorate(new Directory("org/foo"), context);
verify(analyser, never()).analyseLevel(anyList());
}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java
index bd502b99ede..fe48596751c 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java
@@ -22,9 +22,13 @@ package org.sonar.plugins.core.timemachine;
import org.junit.Test;
import org.mockito.Matchers;
import org.sonar.api.batch.DecoratorContext;
-import org.sonar.api.measures.*;
+import org.sonar.api.measures.Measure;
+import org.sonar.api.measures.MeasuresFilter;
+import org.sonar.api.measures.Metric;
+import org.sonar.api.measures.MetricFinder;
+import org.sonar.api.measures.RuleMeasure;
+import org.sonar.api.resources.Directory;
import org.sonar.api.resources.File;
-import org.sonar.api.resources.JavaPackage;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.rules.Rule;
@@ -37,7 +41,10 @@ import java.util.Arrays;
import java.util.Date;
import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class VariationDecoratorTest extends AbstractDbUnitTestCase {
@@ -61,20 +68,20 @@ public class VariationDecoratorTest extends AbstractDbUnitTestCase {
@Test
public void shouldCompareAndSaveVariation() {
- Resource javaPackage = new JavaPackage("org.foo");
+ Resource dir = new Directory("org/foo");
PastMeasuresLoader pastMeasuresLoader = mock(PastMeasuresLoader.class);
PastSnapshot pastSnapshot1 = new PastSnapshot("days", new Date()).setIndex(1);
PastSnapshot pastSnapshot3 = new PastSnapshot("days", new Date()).setIndex(3);
// first past analysis
- when(pastMeasuresLoader.getPastMeasures(javaPackage, pastSnapshot1)).thenReturn(Arrays.asList(
- new Object[]{NCLOC_ID, null, null, null, 180.0},
- new Object[]{COVERAGE_ID, null, null, null, 75.0}));
+ when(pastMeasuresLoader.getPastMeasures(dir, pastSnapshot1)).thenReturn(Arrays.asList(
+ new Object[] {NCLOC_ID, null, null, null, 180.0},
+ new Object[] {COVERAGE_ID, null, null, null, 75.0}));
// second past analysis
- when(pastMeasuresLoader.getPastMeasures(javaPackage, pastSnapshot3)).thenReturn(Arrays.<Object[]>asList(
- new Object[]{NCLOC_ID, null, null, null, 240.0}));
+ when(pastMeasuresLoader.getPastMeasures(dir, pastSnapshot3)).thenReturn(Arrays.<Object[]>asList(
+ new Object[] {NCLOC_ID, null, null, null, 240.0}));
// current analysis
DecoratorContext context = mock(DecoratorContext.class);
@@ -83,7 +90,7 @@ public class VariationDecoratorTest extends AbstractDbUnitTestCase {
when(context.getMeasures(Matchers.<MeasuresFilter>anyObject())).thenReturn(Arrays.asList(currentNcloc, currentCoverage));
VariationDecorator decorator = new VariationDecorator(pastMeasuresLoader, mock(MetricFinder.class), Arrays.asList(pastSnapshot1, pastSnapshot3));
- decorator.decorate(javaPackage, context);
+ decorator.decorate(dir, context);
// context updated for each variation : 2 times for ncloc and 1 time for coverage
verify(context, times(3)).saveMeasure(Matchers.<Measure>anyObject());
@@ -104,16 +111,16 @@ public class VariationDecoratorTest extends AbstractDbUnitTestCase {
Rule rule2 = Rule.create();
rule2.setId(2);
- Resource javaPackage = new JavaPackage("org.foo");
+ Resource dir = new Directory("org/foo");
PastMeasuresLoader pastMeasuresLoader = mock(PastMeasuresLoader.class);
PastSnapshot pastSnapshot1 = new PastSnapshot("days", new Date()).setIndex(1);
// first past analysis
- when(pastMeasuresLoader.getPastMeasures(javaPackage, pastSnapshot1)).thenReturn(Arrays.asList(
- new Object[]{VIOLATIONS_ID, null, null, null, 180.0},// total
- new Object[]{VIOLATIONS_ID, null, null, rule1.getId(), 100.0},// rule 1
- new Object[]{VIOLATIONS_ID, null, null, rule2.getId(), 80.0})); // rule 2
+ when(pastMeasuresLoader.getPastMeasures(dir, pastSnapshot1)).thenReturn(Arrays.asList(
+ new Object[] {VIOLATIONS_ID, null, null, null, 180.0},// total
+ new Object[] {VIOLATIONS_ID, null, null, rule1.getId(), 100.0},// rule 1
+ new Object[] {VIOLATIONS_ID, null, null, rule2.getId(), 80.0})); // rule 2
// current analysis
DecoratorContext context = mock(DecoratorContext.class);
@@ -123,7 +130,7 @@ public class VariationDecoratorTest extends AbstractDbUnitTestCase {
when(context.getMeasures(Matchers.<MeasuresFilter>anyObject())).thenReturn(Arrays.asList(violations, violationsRule1, violationsRule2));
VariationDecorator decorator = new VariationDecorator(pastMeasuresLoader, mock(MetricFinder.class), Arrays.asList(pastSnapshot1));
- decorator.decorate(javaPackage, context);
+ decorator.decorate(dir, context);
// context updated for each variation
verify(context, times(3)).saveMeasure(Matchers.<Measure>anyObject());
diff --git a/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/decorators/SumDuplicationsDecoratorTest.java b/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/decorators/SumDuplicationsDecoratorTest.java
index c1af92310c4..7ebae1da257 100644
--- a/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/decorators/SumDuplicationsDecoratorTest.java
+++ b/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/decorators/SumDuplicationsDecoratorTest.java
@@ -23,8 +23,8 @@ import org.junit.Test;
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
-import org.sonar.api.resources.JavaFile;
-import org.sonar.api.resources.Resource;
+import org.sonar.api.resources.File;
+import org.sonar.api.resources.Qualifiers;
import org.sonar.api.test.IsMeasure;
import static org.hamcrest.CoreMatchers.is;
@@ -48,7 +48,8 @@ public class SumDuplicationsDecoratorTest {
@Test
public void doNotSetDuplicationsOnUnitTests() {
SumDuplicationsDecorator decorator = new SumDuplicationsDecorator();
- Resource unitTest = new JavaFile("org.foo.BarTest", true);
+ File unitTest = new File("org/foo/BarTest.java");
+ unitTest.setQualifier(Qualifiers.UNIT_TEST_FILE);
DecoratorContext context = mock(DecoratorContext.class);
decorator.decorate(unitTest, context);
@@ -59,10 +60,10 @@ public class SumDuplicationsDecoratorTest {
@Test
public void saveZeroIfNoDuplications() {
SumDuplicationsDecorator decorator = new SumDuplicationsDecorator();
- Resource unitTest = new JavaFile("org.foo.BarTest", false);
+ File file = new File("org/foo/BarTest.java");
DecoratorContext context = mock(DecoratorContext.class);
- decorator.decorate(unitTest, context);
+ decorator.decorate(file, context);
verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.DUPLICATED_LINES, 0.0)));
}
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");
+ }
+}
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/batch/SquidUtils.java b/sonar-deprecated/src/main/java/org/sonar/api/batch/SquidUtils.java
index 45d15d7494a..5a7e3a1475e 100644
--- a/sonar-deprecated/src/main/java/org/sonar/api/batch/SquidUtils.java
+++ b/sonar-deprecated/src/main/java/org/sonar/api/batch/SquidUtils.java
@@ -19,11 +19,13 @@
*/
package org.sonar.api.batch;
-import org.apache.commons.io.FilenameUtils;
-import org.apache.commons.lang.StringUtils;
import org.sonar.api.resources.JavaFile;
import org.sonar.api.resources.JavaPackage;
+/**
+ * @deprecated since 4.2
+ */
+@Deprecated
public final class SquidUtils {
private SquidUtils() {
@@ -35,21 +37,7 @@ public final class SquidUtils {
*/
@Deprecated
public static JavaFile convertJavaFileKeyFromSquidFormat(String key) {
- 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);
- }
-
- String convertedKey = key.replace('/', '.');
- if (convertedKey.indexOf('.') == -1 && !"".equals(convertedKey)) {
- convertedKey = "[default]." + convertedKey;
-
- } else if (convertedKey.indexOf('.') == -1) {
- convertedKey = "[default]";
- }
-
- return new JavaFile(convertedKey);
+ throw new UnsupportedOperationException("Not supported since v4.2. See http://docs.codehaus.org/display/SONAR/API+Changes");
}
/**
@@ -57,9 +45,13 @@ public final class SquidUtils {
*/
@Deprecated
public static JavaPackage convertJavaPackageKeyFromSquidFormat(String key) {
- return new JavaPackage(key);
+ throw new UnsupportedOperationException("Not supported since v4.2. See http://docs.codehaus.org/display/SONAR/API+Changes");
}
+ /**
+ * @deprecated since 4.0
+ */
+ @Deprecated
public static String convertToSquidKeyFormat(JavaFile file) {
throw new UnsupportedOperationException("Not supported since v4.0. Was badly implemented");
}
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/resources/JavaFile.java b/sonar-deprecated/src/main/java/org/sonar/api/resources/JavaFile.java
index 461820a5bec..0b0f7a983eb 100644
--- a/sonar-deprecated/src/main/java/org/sonar/api/resources/JavaFile.java
+++ b/sonar-deprecated/src/main/java/org/sonar/api/resources/JavaFile.java
@@ -19,10 +19,7 @@
*/
package org.sonar.api.resources;
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.builder.ToStringBuilder;
-import org.sonar.api.scan.filesystem.PathResolver;
-import org.sonar.api.utils.WildcardPattern;
+import com.google.common.annotations.VisibleForTesting;
import java.io.File;
import java.util.List;
@@ -36,280 +33,84 @@ import java.util.List;
@Deprecated
public class JavaFile extends Resource {
- private static final String JAVA_SUFFIX = ".java";
- private static final String JAV_SUFFIX = ".jav";
- private String className;
- private String filename;
- private String fullyQualifiedName;
- private String packageFullyQualifiedName;
- private boolean unitTest;
- private JavaPackage parent;
-
- private JavaFile() {
- // Default constructor
+ @VisibleForTesting
+ JavaFile() {
}
- /**
- * Creates a JavaFile that is not a class of test based on package and file names
- */
public JavaFile(String packageName, String className) {
- this(packageName, className, false);
+ throw new UnsupportedOperationException("Not supported since v4.2. See http://docs.codehaus.org/display/SONAR/API+Changes");
}
- /**
- * 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
- */
public JavaFile(String packageKey, String className, boolean unitTest) {
- if (className == null) {
- throw new IllegalArgumentException("Java filename can not be null");
- }
- this.className = StringUtils.trim(className);
- String deprecatedKey;
- if (StringUtils.isBlank(packageKey)) {
- this.packageFullyQualifiedName = JavaPackage.DEFAULT_PACKAGE_NAME;
- this.fullyQualifiedName = this.className;
- deprecatedKey = new StringBuilder().append(this.packageFullyQualifiedName).append(".").append(this.className).toString();
- } else {
- this.packageFullyQualifiedName = packageKey.trim();
- deprecatedKey = new StringBuilder().append(this.packageFullyQualifiedName).append(".").append(this.className).toString();
- this.fullyQualifiedName = deprecatedKey;
- }
- setDeprecatedKey(deprecatedKey);
- this.unitTest = unitTest;
+ throw new UnsupportedOperationException("Not supported since v4.2. See http://docs.codehaus.org/display/SONAR/API+Changes");
}
- /**
- * Creates a source file from its key
- */
public JavaFile(String deprecatedKey) {
- this(deprecatedKey, false);
+ throw new UnsupportedOperationException("Not supported since v4.2. See http://docs.codehaus.org/display/SONAR/API+Changes");
}
- /**
- * Creates any JavaFile from its key
- *
- * @param unitTest whether it is a unit test file or a source file
- */
public JavaFile(String deprecatedKey, boolean unitTest) {
- if (deprecatedKey == null) {
- throw new IllegalArgumentException("Java filename can not be null");
- }
- String realKey = StringUtils.trim(deprecatedKey);
- this.unitTest = unitTest;
-
- if (realKey.contains(".")) {
- this.className = StringUtils.substringAfterLast(realKey, ".");
- this.packageFullyQualifiedName = StringUtils.substringBeforeLast(realKey, ".");
- this.fullyQualifiedName = realKey;
-
- } else {
- this.className = realKey;
- this.fullyQualifiedName = realKey;
- this.packageFullyQualifiedName = JavaPackage.DEFAULT_PACKAGE_NAME;
- realKey = new StringBuilder().append(JavaPackage.DEFAULT_PACKAGE_NAME).append(".").append(realKey).toString();
- }
- setDeprecatedKey(realKey);
+ throw new UnsupportedOperationException("Not supported since v4.2. See http://docs.codehaus.org/display/SONAR/API+Changes");
}
- /**
- * {@inheritDoc}
- */
@Override
public JavaPackage getParent() {
- if (parent == null) {
- parent = new JavaPackage(packageFullyQualifiedName);
- }
- return parent;
+ throw new UnsupportedOperationException("Not supported since v4.2. See http://docs.codehaus.org/display/SONAR/API+Changes");
}
- /**
- * @return null
- */
@Override
public String getDescription() {
- return null;
+ throw new UnsupportedOperationException("Not supported since v4.2. See http://docs.codehaus.org/display/SONAR/API+Changes");
}
- /**
- * @return Java
- */
@Override
public Language getLanguage() {
- return Java.INSTANCE;
+ throw new UnsupportedOperationException("Not supported since v4.2. See http://docs.codehaus.org/display/SONAR/API+Changes");
}
- /**
- * {@inheritDoc}
- */
@Override
public String getName() {
- return StringUtils.isNotBlank(filename) ? filename : (className + JAVA_SUFFIX);
+ throw new UnsupportedOperationException("Not supported since v4.2. See http://docs.codehaus.org/display/SONAR/API+Changes");
}
- /**
- * {@inheritDoc}
- */
@Override
public String getLongName() {
- return fullyQualifiedName;
+ throw new UnsupportedOperationException("Not supported since v4.2. See http://docs.codehaus.org/display/SONAR/API+Changes");
}
- /**
- * @return SCOPE_ENTITY
- */
@Override
public String getScope() {
- return Scopes.FILE;
+ throw new UnsupportedOperationException("Not supported since v4.2. See http://docs.codehaus.org/display/SONAR/API+Changes");
}
- /**
- * @return QUALIFIER_UNIT_TEST_CLASS or QUALIFIER_FILE depending whether it is a unit test class
- */
@Override
public String getQualifier() {
- return unitTest ? Qualifiers.UNIT_TEST_FILE : Qualifiers.FILE;
+ throw new UnsupportedOperationException("Not supported since v4.2. See http://docs.codehaus.org/display/SONAR/API+Changes");
}
- /**
- * @return whether the JavaFile is a unit test class or not
- */
public boolean isUnitTest() {
- return unitTest;
+ throw new UnsupportedOperationException("Not supported since v4.2. See http://docs.codehaus.org/display/SONAR/API+Changes");
}
- /**
- * {@inheritDoc}
- */
@Override
public boolean matchFilePattern(String antPattern) {
- WildcardPattern matcher = WildcardPattern.create(antPattern, Directory.SEPARATOR);
- return matcher.match(getKey());
+ throw new UnsupportedOperationException("Not supported since v4.2. See http://docs.codehaus.org/display/SONAR/API+Changes");
}
public static JavaFile fromIOFile(File file, Project module, boolean unitTest) {
- if (file == null || !StringUtils.endsWithIgnoreCase(file.getName(), JAVA_SUFFIX)) {
- return null;
- }
- PathResolver.RelativePath relativePath = new PathResolver().relativePath(
- unitTest ? module.getFileSystem().getTestDirs() : module.getFileSystem().getSourceDirs(),
- file);
- if (relativePath != null) {
- JavaFile sonarFile = fromRelativePath(relativePath.path(), unitTest);
- sonarFile.setPath(new PathResolver().relativePath(module.getFileSystem().getBasedir(), file));
- return sonarFile;
- }
- return null;
+ throw new UnsupportedOperationException("Not supported since v4.2. See http://docs.codehaus.org/display/SONAR/API+Changes");
}
- /**
- * For internal use only.
- */
- public static JavaFile create(String relativePathFromBasedir) {
- JavaFile javaFile = new JavaFile();
- String normalizedPath = normalize(relativePathFromBasedir);
- javaFile.setKey(normalizedPath);
- javaFile.setPath(normalizedPath);
- javaFile.parent = new JavaPackage();
- String directoryPath;
- if (normalizedPath != null && normalizedPath.contains(Directory.SEPARATOR)) {
- directoryPath = StringUtils.substringBeforeLast(normalizedPath, Directory.SEPARATOR);
- } else {
- directoryPath = Directory.SEPARATOR;
- }
- String normalizedParentPath = normalize(directoryPath);
- javaFile.parent.setKey(normalizedParentPath);
- javaFile.parent.setPath(normalizedParentPath);
- return javaFile;
- }
-
- /**
- * For internal use only.
- */
- 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.filename = StringUtils.substringAfterLast(relativePathFromSourceDir, Directory.SEPARATOR);
- if (javaFile.filename.endsWith(JAVA_SUFFIX)) {
- javaFile.className = StringUtils.removeEndIgnoreCase(javaFile.filename, JAVA_SUFFIX);
- } else if (javaFile.filename.endsWith(JAV_SUFFIX)) {
- javaFile.className = StringUtils.removeEndIgnoreCase(javaFile.filename, JAV_SUFFIX);
- }
- javaFile.fullyQualifiedName = javaFile.packageFullyQualifiedName + "." + javaFile.className;
- javaFile.setDeprecatedKey(javaFile.fullyQualifiedName);
- javaFile.parent.setDeprecatedKey(Directory.parseKey(StringUtils.substringBeforeLast(relativePathFromSourceDir, Directory.SEPARATOR)));
- } 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.parent.setDeprecatedKey(Directory.ROOT);
- }
- javaFile.unitTest = unitTest;
- 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;
- String classname = relativePath;
-
- if (relativePath.indexOf('/') >= 0) {
- pacname = StringUtils.substringBeforeLast(relativePath, "/");
- pacname = StringUtils.replace(pacname, "/", ".");
- classname = StringUtils.substringAfterLast(relativePath, "/");
- }
- classname = StringUtils.substringBeforeLast(classname, ".");
- return new JavaFile(pacname, classname, unitTest);
- }
- return null;
+ throw new UnsupportedOperationException("Not supported since v4.2. See http://docs.codehaus.org/display/SONAR/API+Changes");
}
- /**
- * 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;
- }
- PathResolver.RelativePath relativePath = new PathResolver().relativePath(sourceDirs, file);
- if (relativePath != null) {
- return fromRelativePath(relativePath.path(), unitTest);
- }
- return null;
+ throw new UnsupportedOperationException("Not supported since v4.2. See http://docs.codehaus.org/display/SONAR/API+Changes");
}
- /**
- * 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;
- }
- return fromIOFile(new File(path), sourceDirs, unitTest);
- }
-
- @Override
- public String toString() {
- return new ToStringBuilder(this)
- .append("key", getKey())
- .append("deprecatedKey", getDeprecatedKey())
- .append("path", getPath())
- .append("filename", className)
- .toString();
+ throw new UnsupportedOperationException("Not supported since v4.2. See http://docs.codehaus.org/display/SONAR/API+Changes");
}
}
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/resources/JavaPackage.java b/sonar-deprecated/src/main/java/org/sonar/api/resources/JavaPackage.java
index 8cfb6672275..1c021775ae1 100644
--- a/sonar-deprecated/src/main/java/org/sonar/api/resources/JavaPackage.java
+++ b/sonar-deprecated/src/main/java/org/sonar/api/resources/JavaPackage.java
@@ -19,9 +19,6 @@
*/
package org.sonar.api.resources;
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.builder.ToStringBuilder;
-
/**
* A class that represents a Java package in Sonar
*
@@ -31,111 +28,57 @@ import org.apache.commons.lang.builder.ToStringBuilder;
@Deprecated
public class JavaPackage extends Resource {
- /**
- * Default package name for classes without package definition
- */
public static final String DEFAULT_PACKAGE_NAME = "[default]";
- /**
- * Default constructor
- * @deprecated since 4.2 use {@link #create(String, String)}
- */
- @Deprecated
public JavaPackage() {
- this(null);
+ // For testing
}
- /**
- * Creates a JavaPackage from its key.
- * @deprecated since 4.2 use {@link #create(String, String)}
- */
- @Deprecated
public JavaPackage(String deprecatedKey) {
- if (DEFAULT_PACKAGE_NAME.equals(deprecatedKey)) {
- deprecatedKey = Directory.ROOT;
- }
- String deprecatedDirectoryKey = StringUtils.trimToEmpty(deprecatedKey);
- deprecatedDirectoryKey = deprecatedDirectoryKey.replaceAll("\\.", Directory.SEPARATOR);
- setDeprecatedKey(StringUtils.defaultIfEmpty(deprecatedDirectoryKey, Directory.ROOT));
+ throw new UnsupportedOperationException("Not supported since v4.2. See http://docs.codehaus.org/display/SONAR/API+Changes");
}
- /**
- * @return whether the JavaPackage key is the default key
- */
public boolean isDefault() {
- return StringUtils.equals(getDeprecatedKey(), Directory.ROOT);
+ throw new UnsupportedOperationException("Not supported since v4.2. See http://docs.codehaus.org/display/SONAR/API+Changes");
}
- /**
- * {@inheritDoc}
- */
@Override
public boolean matchFilePattern(String antPattern) {
- return false;
+ throw new UnsupportedOperationException("Not supported since v4.2. See http://docs.codehaus.org/display/SONAR/API+Changes");
}
- /**
- * {@inheritDoc}
- */
@Override
public String getDescription() {
- return null;
+ throw new UnsupportedOperationException("Not supported since v4.2. See http://docs.codehaus.org/display/SONAR/API+Changes");
}
- /**
- * @return SCOPE_SPACE
- */
@Override
public String getScope() {
- return Scopes.DIRECTORY;
+ throw new UnsupportedOperationException("Not supported since v4.2. See http://docs.codehaus.org/display/SONAR/API+Changes");
}
- /**
- * @return QUALIFIER_PACKAGE
- */
@Override
public String getQualifier() {
- return Qualifiers.DIRECTORY;
+ throw new UnsupportedOperationException("Not supported since v4.2. See http://docs.codehaus.org/display/SONAR/API+Changes");
}
- /**
- * {@inheritDoc}
- */
@Override
public String getName() {
- return getKey();
+ throw new UnsupportedOperationException("Not supported since v4.2. See http://docs.codehaus.org/display/SONAR/API+Changes");
}
- /**
- * {@inheritDoc}
- */
@Override
public Resource getParent() {
- return null;
+ throw new UnsupportedOperationException("Not supported since v4.2. See http://docs.codehaus.org/display/SONAR/API+Changes");
}
- /**
- * {@inheritDoc}
- */
@Override
public String getLongName() {
- return null;
+ throw new UnsupportedOperationException("Not supported since v4.2. See http://docs.codehaus.org/display/SONAR/API+Changes");
}
- /**
- * @return null
- */
@Override
public Language getLanguage() {
- return null;
- }
-
- @Override
- public String toString() {
- return new ToStringBuilder(this)
- .append("id", getId())
- .append("key", getKey())
- .append("deprecatedKey", getDeprecatedKey())
- .toString();
+ throw new UnsupportedOperationException("Not supported since v4.2. See http://docs.codehaus.org/display/SONAR/API+Changes");
}
}
diff --git a/sonar-deprecated/src/test/java/org/sonar/api/batch/SquidUtilsTest.java b/sonar-deprecated/src/test/java/org/sonar/api/batch/SquidUtilsTest.java
index bf646390cf0..643d24d575e 100644
--- a/sonar-deprecated/src/test/java/org/sonar/api/batch/SquidUtilsTest.java
+++ b/sonar-deprecated/src/test/java/org/sonar/api/batch/SquidUtilsTest.java
@@ -21,30 +21,17 @@ package org.sonar.api.batch;
import org.junit.Test;
import org.sonar.api.resources.JavaFile;
-import org.sonar.api.resources.JavaPackage;
-
-import static org.fest.assertions.Assertions.assertThat;
public class SquidUtilsTest {
- @Test
+ @Test(expected = UnsupportedOperationException.class)
public void convertJavaFileKeyFromSquidFormat() {
- assertThat(new JavaFile("java.lang.String")).isEqualTo(SquidUtils.convertJavaFileKeyFromSquidFormat("java/lang/String"));
- assertThat(new JavaFile("java.lang.String")).isEqualTo(SquidUtils.convertJavaFileKeyFromSquidFormat("java/lang/String.java"));
- assertThat(new JavaFile("java.lang.String")).isEqualTo(SquidUtils.convertJavaFileKeyFromSquidFormat("java/lang/String.jav"));
- assertThat(new JavaFile("java.lang.String")).isEqualTo(SquidUtils.convertJavaFileKeyFromSquidFormat("java/lang/String.JAVA"));
- assertThat(new JavaFile("java.lang.String")).isEqualTo(SquidUtils.convertJavaFileKeyFromSquidFormat("java/lang/String.JAV"));
- assertThat(new JavaFile("String")).isEqualTo(SquidUtils.convertJavaFileKeyFromSquidFormat("String.java"));
- assertThat(new JavaFile("String")).isEqualTo(SquidUtils.convertJavaFileKeyFromSquidFormat("String.JAVA"));
- assertThat(new JavaFile("String")).isEqualTo(SquidUtils.convertJavaFileKeyFromSquidFormat("String.JAV"));
- assertThat(new JavaFile("String")).isEqualTo(SquidUtils.convertJavaFileKeyFromSquidFormat("String"));
+ SquidUtils.convertJavaFileKeyFromSquidFormat("java/lang/String");
}
- @Test
+ @Test(expected = UnsupportedOperationException.class)
public void shouldConvertJavaPackageKeyFromSquidFormat() {
- assertThat(new JavaPackage("java/lang")).isEqualTo(SquidUtils.convertJavaPackageKeyFromSquidFormat("java/lang"));
- assertThat(new JavaPackage("")).isEqualTo(SquidUtils.convertJavaPackageKeyFromSquidFormat(""));
- assertThat(new JavaPackage("singlepackage")).isEqualTo(SquidUtils.convertJavaPackageKeyFromSquidFormat("singlepackage"));
+ SquidUtils.convertJavaPackageKeyFromSquidFormat("java/lang");
}
@Test(expected = UnsupportedOperationException.class)
diff --git a/sonar-deprecated/src/test/java/org/sonar/api/resources/JavaFileTest.java b/sonar-deprecated/src/test/java/org/sonar/api/resources/JavaFileTest.java
index f2982758b30..017e6c4a34b 100644
--- a/sonar-deprecated/src/test/java/org/sonar/api/resources/JavaFileTest.java
+++ b/sonar-deprecated/src/test/java/org/sonar/api/resources/JavaFileTest.java
@@ -19,256 +19,96 @@
*/
package org.sonar.api.resources;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-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.assertThat;
-
public class JavaFileTest {
- @Rule
- public TemporaryFolder tempFolder = new TemporaryFolder();
-
- @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.java"));
- 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.getDeprecatedKey(), is("org.foo.bar.Hello"));
- assertThat(javaClass.getName(), is("Hello.java"));
- assertThat(javaClass.getLongName(), is("org.foo.bar.Hello"));
- assertThat(javaClass.getParent().getDeprecatedKey(), is("org/foo/bar"));
- }
-
- @Test
- public void testNewClassWithExplicitPackage() {
- JavaFile javaClass = new JavaFile("org.foo.bar", "Hello", false);
- assertThat(javaClass.getDeprecatedKey(), is("org.foo.bar.Hello"));
- assertThat(javaClass.getName(), is("Hello.java"));
- assertThat(javaClass.getLongName(), is("org.foo.bar.Hello"));
- 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.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.java"));
- assertThat(javaClass.getLongName(), is("Hello"));
- assertThat(javaClass.getParent().getKey()).isEqualTo("src/main/java");
- assertThat(javaClass.getParent().getDeprecatedKey()).isEqualTo(Directory.ROOT);
- assertThat(javaClass.getParent().isDefault()).isTrue();
- }
+ JavaFile javaFile = new JavaFile();
- @Test
- public void testNewClassInRootFolder() {
- JavaFile javaClass = JavaFile.create("Hello.java", "Hello.java", false);
- assertThat(javaClass.getKey()).isEqualTo("Hello.java");
- assertThat(javaClass.getDeprecatedKey(), is(JavaPackage.DEFAULT_PACKAGE_NAME + ".Hello"));
- assertThat(javaClass.getName(), is("Hello.java"));
- assertThat(javaClass.getLongName(), is("Hello"));
- assertThat(javaClass.getParent().getKey()).isEqualTo("/");
- assertThat(javaClass.getParent().getDeprecatedKey()).isEqualTo(Directory.ROOT);
- assertThat(javaClass.getParent().isDefault()).isTrue();
+ @Test(expected = UnsupportedOperationException.class)
+ public void testConstructor() {
+ JavaFile javaClass = new JavaFile("", "");
}
- @Test
- public void testNewClassWithEmptyPackageDeprecatedConstructor() {
- JavaFile javaClass = new JavaFile("", "Hello", false);
- assertThat(javaClass.getDeprecatedKey(), is(JavaPackage.DEFAULT_PACKAGE_NAME + ".Hello"));
- assertThat(javaClass.getName(), is("Hello.java"));
- assertThat(javaClass.getLongName(), is("Hello"));
- assertThat(javaClass.getParent().isDefault(), is(true));
+ @Test(expected = UnsupportedOperationException.class)
+ public void testConstructor2() {
+ JavaFile javaClass = new JavaFile("", "", true);
}
- @Test
- public void testNewClassWithNullPackageDeprecatedConstructor() {
- JavaFile javaClass = new JavaFile(null, "Hello", false);
- assertThat(javaClass.getDeprecatedKey(), is(JavaPackage.DEFAULT_PACKAGE_NAME + ".Hello"));
- assertThat(javaClass.getName(), is("Hello.java"));
- assertThat(javaClass.getLongName(), is("Hello"));
- assertThat((javaClass.getParent()).isDefault(), is(true));
+ @Test(expected = UnsupportedOperationException.class)
+ public void testConstructor3() {
+ JavaFile javaClass = new JavaFile("");
}
- @Test
- public void shouldBeDefaultPackageIfNoPackage() {
- JavaFile javaClass = new JavaFile("Hello", false);
- assertEquals(JavaPackage.DEFAULT_PACKAGE_NAME + ".Hello", javaClass.getDeprecatedKey());
- assertThat(javaClass.getName(), is("Hello.java"));
- assertThat(javaClass.getLongName(), is("Hello"));
- assertThat(javaClass.getParent().isDefault(), is(true));
+ @Test(expected = UnsupportedOperationException.class)
+ public void testConstructor4() {
+ JavaFile javaClass = new JavaFile("", true);
}
- @Test
- public void aClassShouldBeNamedJava() {
- JavaFile javaClass = new JavaFile("org.foo.bar.Java", false);
- assertThat(javaClass.getDeprecatedKey(), is("org.foo.bar.Java"));
- assertThat(javaClass.getLongName(), is("org.foo.bar.Java"));
- assertThat(javaClass.getName(), is("Java.java"));
- JavaPackage parent = javaClass.getParent();
- assertEquals("org/foo/bar", parent.getDeprecatedKey());
+ @Test(expected = UnsupportedOperationException.class)
+ public void testGetParent() {
+ javaFile.getParent();
}
- @Test
- public void shouldTrimClasses() {
- JavaFile clazz = new JavaFile(" org.foo.bar.Hello ", false);
- assertThat(clazz.getDeprecatedKey(), is("org.foo.bar.Hello"));
- assertThat(clazz.getLongName(), is("org.foo.bar.Hello"));
- assertThat(clazz.getName(), is("Hello.java"));
- JavaPackage parent = clazz.getParent();
- assertThat(parent.getDeprecatedKey(), is("org/foo/bar"));
+ @Test(expected = UnsupportedOperationException.class)
+ public void testGetDescription() {
+ javaFile.getDescription();
}
- @Test
- public void testEqualsOnClasses() {
- JavaFile class1 = new JavaFile("foo.bar", "Hello", false);
- JavaFile class2 = new JavaFile("foo.bar.Hello", false);
- assertThat(class1).isEqualTo(class2);
-
- class1 = new JavaFile("NoPackage", false);
- class2 = new JavaFile("NoPackage", false);
- assertThat(class1).isEqualTo(class2);
- assertThat(class1).isEqualTo(class1);
+ @Test(expected = UnsupportedOperationException.class)
+ public void testGetLanguage() {
+ javaFile.getLanguage();
}
- @Test
- public void oneLevelPackage() {
- JavaFile clazz = new JavaFile("onelevel.MyFile");
- assertEquals("onelevel.MyFile", clazz.getDeprecatedKey());
- assertEquals("onelevel", clazz.getParent().getDeprecatedKey());
-
- clazz = new JavaFile("onelevel", "MyFile");
- 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.getDeprecatedKey());
- assertEquals("MyFile.java", javaFile.getName());
- assertEquals("onelevel", javaFile.getParent().getDeprecatedKey());
- assertThat(javaFile.getParent().isDefault(), is(false));
+ @Test(expected = UnsupportedOperationException.class)
+ public void testGetName() {
+ javaFile.getName();
}
- @Test
- public void shouldResolveClassFromAbsolutePath() {
- File sources1 = newDir("source1");
- 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.getDeprecatedKey()));
- assertThat(javaFile.getLongName(), is("foo.bar.MyFile"));
- assertThat(javaFile.getName(), is("MyFile.java"));
- assertThat(javaFile.getParent().getDeprecatedKey(), is("foo/bar"));
- }
-
- @Test
- public void shouldResolveFromAbsolutePathEvenIfDefaultPackage() {
- File source1 = newDir("source1");
- File source2 = newDir("source2");
- List<File> sources = Arrays.asList(source1, source2);
-
- JavaFile javaClass = JavaFile.fromAbsolutePath(absPath(source1, "MyClass.java"), sources, false);
- assertEquals(JavaPackage.DEFAULT_PACKAGE_NAME + ".MyClass", javaClass.getDeprecatedKey());
- assertEquals("MyClass.java", javaClass.getName());
-
- assertThat((javaClass.getParent()).isDefault()).isEqualTo(true);
+ @Test(expected = UnsupportedOperationException.class)
+ public void testGetLongName() {
+ javaFile.getLongName();
}
- @Test
- public void shouldResolveOnlyJavaFromAbsolutePath() {
- File source1 = newDir("source1");
- List<File> sources = Arrays.asList(source1);
- assertThat(JavaFile.fromAbsolutePath(absPath(source1, "foo/bar/my_file.sql"), sources, false)).isNull();
+ @Test(expected = UnsupportedOperationException.class)
+ public void testGetScope() {
+ javaFile.getScope();
}
- @Test
- public void shouldNotFailWhenResolvingUnknownClassFromAbsolutePath() {
- File source1 = newDir("source1");
- List<File> sources = Arrays.asList(source1);
- assertThat(JavaFile.fromAbsolutePath("/home/other/src/main/java/foo/bar/MyClass.java", sources, false)).isNull();
+ @Test(expected = UnsupportedOperationException.class)
+ public void testGetQualifier() {
+ javaFile.getQualifier();
}
- @Test
- public void shouldMatchFilePatterns() {
- JavaFile clazz = JavaFile.create("src/main/java/org/sonar/commons/Foo.java", "org/sonar/commons/Foo.java", false);
- assertThat(clazz.matchFilePattern("**/commons/**/*.java")).isTrue();
- assertThat(clazz.matchFilePattern("/**/commons/**/*.java")).isTrue();
- assertThat(clazz.matchFilePattern("/**/commons/**/*.*")).isTrue();
- assertThat(clazz.matchFilePattern("/**/sonar/*.java")).isFalse();
- assertThat(clazz.matchFilePattern("src/main/java/org/*/commons/**/*.java")).isTrue();
- assertThat(clazz.matchFilePattern("src/main/java/org/sonar/commons/*")).isTrue();
- assertThat(clazz.matchFilePattern("src/main/java/org/sonar/**/*.java")).isTrue();
- assertThat(clazz.matchFilePattern("src/main/java/org/sonar/*")).isFalse();
- assertThat(clazz.matchFilePattern("src/main/java/org/sonar*/*")).isFalse();
- assertThat(clazz.matchFilePattern("src/main/java/org/**")).isTrue();
- assertThat(clazz.matchFilePattern("*src/main/java/org/sona?/co??ons/**.*")).isTrue();
- assertThat(clazz.matchFilePattern("src/main/java/org/sonar/core/**")).isFalse();
- assertThat(clazz.matchFilePattern("src/main/java/org/sonar/commons/Foo.java")).isTrue();
- assertThat(clazz.matchFilePattern("**/*Foo.java")).isTrue();
- assertThat(clazz.matchFilePattern("**/*Foo.*")).isTrue();
- assertThat(clazz.matchFilePattern("src/main/java/org/*/*/Foo.java")).isTrue();
- assertThat(clazz.matchFilePattern("src/main/java/org/**/**/Foo.java")).isTrue();
- assertThat(clazz.matchFilePattern("**/commons/**/*")).isTrue();
- assertThat(clazz.matchFilePattern("**/*")).isTrue();
+ @Test(expected = UnsupportedOperationException.class)
+ public void testIsUnitTest() {
+ javaFile.isUnitTest();
}
- // SONAR-4397
- @Test
- public void shouldMatchFilePatternsWhenNoPackage() {
- JavaFile clazz = JavaFile.create("src/main/java/Foo.java", "Foo.java", false);
- assertThat(clazz.matchFilePattern("**/*Foo.java")).isTrue();
- assertThat(clazz.matchFilePattern("**/*Foo.*")).isTrue();
- assertThat(clazz.matchFilePattern("**/*")).isTrue();
- assertThat(clazz.matchFilePattern("src/main/java/Foo*.*")).isTrue();
+ @Test(expected = UnsupportedOperationException.class)
+ public void testMathFilePattern() {
+ javaFile.matchFilePattern("");
}
- /**
- * See http://jira.codehaus.org/browse/SONAR-1449
- */
- @Test
- public void doNotMatchAPattern() {
- JavaFile file = JavaFile.create("src/main/java/org/sonar/commons/Foo.java", "org/sonar/commons/Foo.java", false);
- assertThat(file.matchFilePattern("**/*.aj")).isFalse();
- assertThat(file.matchFilePattern("**/*.java")).isTrue();
+ @Test(expected = UnsupportedOperationException.class)
+ public void fromIoFile1() {
+ JavaFile.fromIOFile(null, (Project) null, true);
}
- @Test
- public void should_exclude_test_files() {
- JavaFile unitTest = JavaFile.create("src/main/java/org/sonar/commons/Foo.java", "org/sonar/commons/Foo.java", true);
- assertThat(unitTest.matchFilePattern("**/*")).isTrue();
+ @Test(expected = UnsupportedOperationException.class)
+ public void fromIoFile2() {
+ JavaFile.fromIOFile(null, (List<java.io.File>) null, true);
}
- private File newDir(String dirName) {
- return tempFolder.newFolder(dirName);
+ @Test(expected = UnsupportedOperationException.class)
+ public void fromRelativePath() {
+ JavaFile.fromRelativePath("", false);
}
- private String absPath(File dir, String filePath) {
- return new File(dir, filePath).getPath();
+ @Test(expected = UnsupportedOperationException.class)
+ public void fromAbsolutePath() {
+ JavaFile.fromAbsolutePath("", (List<java.io.File>) null, false);
}
}
diff --git a/sonar-deprecated/src/test/java/org/sonar/api/resources/JavaPackageTest.java b/sonar-deprecated/src/test/java/org/sonar/api/resources/JavaPackageTest.java
index e4cfd63d15b..10479b91229 100644
--- a/sonar-deprecated/src/test/java/org/sonar/api/resources/JavaPackageTest.java
+++ b/sonar-deprecated/src/test/java/org/sonar/api/resources/JavaPackageTest.java
@@ -21,38 +21,58 @@ package org.sonar.api.resources;
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 defaultPackageDeprecatedConstructor() {
- assertEquals(new JavaPackage(), new JavaPackage());
- assertEquals(Directory.ROOT, new JavaPackage(null).getDeprecatedKey());
- assertEquals(Directory.ROOT, new JavaPackage("").getDeprecatedKey());
- assertThat(new JavaPackage(null).isDefault(), is(true));
+
+ JavaPackage javaPackage = new JavaPackage();
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testConstructor() {
+ new JavaPackage("");
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testGetParent() {
+ javaPackage.getParent();
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testGetDescription() {
+ javaPackage.getDescription();
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testGetLanguage() {
+ javaPackage.getLanguage();
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testGetName() {
+ javaPackage.getName();
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testGetLongName() {
+ javaPackage.getLongName();
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testGetScope() {
+ javaPackage.getScope();
}
- @Test
- public void testNewPackageDeprecatedConstructor() {
- assertEquals(new JavaPackage(" foo.bar "), new JavaPackage("foo.bar"));
- JavaPackage pac = new JavaPackage("foo.bar");
- assertEquals("foo/bar", pac.getDeprecatedKey());
+ @Test(expected = UnsupportedOperationException.class)
+ public void testGetQualifier() {
+ javaPackage.getQualifier();
}
- @Test
- public void singleLevelPackageDeprecatedConstructor() {
- assertEquals(new JavaPackage("foo"), new JavaPackage("foo"));
- JavaPackage pac = new JavaPackage("foo");
- assertEquals("foo", pac.getDeprecatedKey());
+ @Test(expected = UnsupportedOperationException.class)
+ public void testIsUnitTest() {
+ javaPackage.isDefault();
}
- @Test
- public void shouldNotMatchFilePatterns() {
- JavaPackage pac = new JavaPackage("org.sonar.commons");
- assertFalse(pac.matchFilePattern("**"));
+ @Test(expected = UnsupportedOperationException.class)
+ public void testMathFilePattern() {
+ javaPackage.matchFilePattern("");
}
}
diff --git a/sonar-deprecated/src/test/java/org/sonar/api/utils/CoberturaReportParserUtilsTest.java b/sonar-deprecated/src/test/java/org/sonar/api/utils/CoberturaReportParserUtilsTest.java
index 48bf282c431..8573d4c834c 100644
--- a/sonar-deprecated/src/test/java/org/sonar/api/utils/CoberturaReportParserUtilsTest.java
+++ b/sonar-deprecated/src/test/java/org/sonar/api/utils/CoberturaReportParserUtilsTest.java
@@ -24,7 +24,6 @@ import org.junit.Test;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
-import org.sonar.api.resources.JavaFile;
import org.sonar.api.resources.JavaPackage;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Resource;
@@ -59,7 +58,7 @@ public class CoberturaReportParserUtilsTest {
@Override
public Resource resolve(String filename) {
- return new JavaFile(filename);
+ return new org.sonar.api.resources.File(filename);
}
};
@@ -110,20 +109,20 @@ public class CoberturaReportParserUtilsTest {
@Test
public void collectFileLineCoverage() throws URISyntaxException {
- when(context.getResource(any(Resource.class))).thenReturn(new JavaFile("org.sonar.MyClass"));
+ when(context.getResource(any(Resource.class))).thenReturn(new org.sonar.api.resources.File("org.sonar.MyClass"));
CoberturaReportParserUtils.parseReport(getCoverageReport(), context, JAVA_FILE_RESOLVER);
- final JavaFile file = new JavaFile("org.apache.commons.chain.config.ConfigParser");
+ final org.sonar.api.resources.File file = new org.sonar.api.resources.File("org.apache.commons.chain.config.ConfigParser");
verify(context).saveMeasure(eq(file), argThat(new IsMeasure(CoreMetrics.LINES_TO_COVER, 30.0)));
verify(context).saveMeasure(eq(file), argThat(new IsMeasure(CoreMetrics.UNCOVERED_LINES, 5.0)));
}
@Test
public void collectFileBranchCoverage() throws URISyntaxException {
- when(context.getResource(any(Resource.class))).thenReturn(new JavaFile("org.sonar.MyClass"));
+ when(context.getResource(any(Resource.class))).thenReturn(new org.sonar.api.resources.File("org.sonar.MyClass"));
CoberturaReportParserUtils.parseReport(getCoverageReport(), context, JAVA_FILE_RESOLVER);
- final JavaFile file = new JavaFile("org.apache.commons.chain.config.ConfigParser");
+ final org.sonar.api.resources.File file = new org.sonar.api.resources.File("org.apache.commons.chain.config.ConfigParser");
verify(context).saveMeasure(eq(file), argThat(new IsMeasure(CoreMetrics.CONDITIONS_TO_COVER, 6.0)));
verify(context).saveMeasure(eq(file), argThat(new IsMeasure(CoreMetrics.UNCOVERED_CONDITIONS, 2.0)));
}
@@ -139,7 +138,7 @@ public class CoberturaReportParserUtilsTest {
public void javaInterfaceHasNoCoverage() throws URISyntaxException {
CoberturaReportParserUtils.parseReport(getCoverageReport(), context, JAVA_FILE_RESOLVER);
- final JavaFile interfaze = new JavaFile("org.apache.commons.chain.Chain");
+ final org.sonar.api.resources.File interfaze = new org.sonar.api.resources.File("org.apache.commons.chain.Chain");
verify(context, never()).saveMeasure(eq(interfaze), argThat(new IsMeasure(CoreMetrics.COVERAGE)));
verify(context, never()).saveMeasure(eq(interfaze), argThat(new IsMeasure(CoreMetrics.LINE_COVERAGE)));
@@ -155,7 +154,7 @@ public class CoberturaReportParserUtilsTest {
public void shouldInsertCoverageAtFileLevel() throws URISyntaxException {
File coverage = new File(getClass().getResource(
"/org/sonar/api/utils/CoberturaReportParserUtilsTest/shouldInsertCoverageAtFileLevel/coverage.xml").toURI());
- when(context.getResource(any(Resource.class))).thenReturn(new JavaFile("org.sonar.MyClass"));
+ when(context.getResource(any(Resource.class))).thenReturn(new org.sonar.api.resources.File("org.sonar.MyClass"));
CoberturaReportParserUtils.parseReport(coverage, context, JAVA_FILE_RESOLVER);
verify(context).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.FILE, "org.sonar.samples.InnerClass")),
@@ -196,7 +195,7 @@ public class CoberturaReportParserUtilsTest {
verify(context)
.saveMeasure(
- eq(new JavaFile("org.sonar.samples.InnerClass")),
+ eq(new org.sonar.api.resources.File("org.sonar.samples.InnerClass")),
argThat(new IsMeasure(
CoreMetrics.COVERAGE_LINE_HITS_DATA,
"22=2;25=0;26=0;29=0;30=0;31=0;34=1;35=1;36=1;37=0;39=1;41=1;44=2;46=1;47=1;50=0;51=0;52=0;53=0;55=0;57=0;60=0;61=0;64=1;71=1;73=1;76=0;77=0;80=0;81=0;85=0;87=0;91=0;93=0;96=1")));
@@ -204,10 +203,10 @@ public class CoberturaReportParserUtilsTest {
@Test
public void collectFileLineHitsData() throws URISyntaxException {
- when(context.getResource(any(Resource.class))).thenReturn(new JavaFile("org.sonar.MyClass"));
+ when(context.getResource(any(Resource.class))).thenReturn(new org.sonar.api.resources.File("org.sonar.MyClass"));
CoberturaReportParserUtils.parseReport(getCoverageReport(), context, JAVA_FILE_RESOLVER);
verify(context).saveMeasure(
- eq(new JavaFile("org.apache.commons.chain.impl.CatalogBase")),
+ eq(new org.sonar.api.resources.File("org.apache.commons.chain.impl.CatalogBase")),
argThat(new IsMeasure(CoreMetrics.COVERAGE_LINE_HITS_DATA,
"48=117;56=234;66=0;67=0;68=0;84=999;86=999;98=318;111=18;121=0;122=0;125=0;126=0;127=0;128=0;131=0;133=0")));
}
@@ -215,7 +214,7 @@ public class CoberturaReportParserUtilsTest {
@Test
public void shouldNotCountTwiceAnonymousClasses() throws URISyntaxException {
File coverage = new File(getClass().getResource("/org/sonar/api/utils/CoberturaReportParserUtilsTest/shouldNotCountTwiceAnonymousClasses.xml").toURI());
- when(context.getResource(any(Resource.class))).thenReturn(new JavaFile("org.sonar.samples.MyClass"));
+ when(context.getResource(any(Resource.class))).thenReturn(new org.sonar.api.resources.File("org.sonar.samples.MyClass"));
CoberturaReportParserUtils.parseReport(coverage, context, JAVA_FILE_RESOLVER);
verify(context).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.FILE, "org.sonar.samples.MyFile")),