aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2015-05-13 17:59:15 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2015-05-19 20:18:11 +0200
commit1abbd252c8513f92dbb9875288c5d000bb8f8c29 (patch)
treebb2457b69006e1eb49c0cd049da2745864d3e484
parent10c3297f7506e314f14bf6512f2db48a3fa1eb1b (diff)
downloadsonarqube-1abbd252c8513f92dbb9875288c5d000bb8f8c29.tar.gz
sonarqube-1abbd252c8513f92dbb9875288c5d000bb8f8c29.zip
SONAR-6555 Drop design related features on batch side
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java19
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/DependencySensor.java106
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/DependencySensorTest.java108
-rw-r--r--pom.xml3
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java16
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java43
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/deprecated/decorator/DefaultDecoratorContext.java28
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/design/BaseTangleIndexDecorator.java92
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/design/DirectoryDsmDecorator.java73
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/design/DirectoryTangleIndexDecorator.java34
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/design/DsmDecorator.java124
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/design/DsmSerializer.java92
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/design/FileTangleIndexDecorator.java34
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/design/MavenDependenciesSensor.java278
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/design/ProjectDsmDecorator.java77
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/design/SubProjectDsmDecorator.java76
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java161
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/DependencyPersister.java87
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/ResourceCache.java25
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java68
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java33
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java10
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java7
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java33
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/design/DirectoryDsmDecoratorTest.java218
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/design/DsmSerializerTest.java60
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/design/MavenDependenciesSensorTest.java94
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/design/ProjectDsmDecoratorTest.java137
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/design/SubProjectDsmDecoratorTest.java159
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java16
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java39
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/dependency/DependencyMediumTest.java129
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java4
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/phases/DecoratorsExecutorTest.java3
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorStorageTest.java107
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewLibrary-result.xml34
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProjectUsingIndex-result.xml (renamed from sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProjectAndLibrary-result.xml)4
-rw-r--r--sonar-core/pom.xml4
-rw-r--r--sonar-core/src/main/resources/META-INF/persistence.xml1
-rw-r--r--sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java4
-rw-r--r--sonar-deprecated/pom.xml1
-rw-r--r--sonar-graph/pom.xml47
-rw-r--r--sonar-graph/src/main/java/org/sonar/graph/Cycle.java85
-rw-r--r--sonar-graph/src/main/java/org/sonar/graph/CycleDetector.java153
-rw-r--r--sonar-graph/src/main/java/org/sonar/graph/DirectedGraph.java149
-rw-r--r--sonar-graph/src/main/java/org/sonar/graph/DirectedGraphAccessor.java36
-rw-r--r--sonar-graph/src/main/java/org/sonar/graph/Dsm.java177
-rw-r--r--sonar-graph/src/main/java/org/sonar/graph/DsmCell.java48
-rw-r--r--sonar-graph/src/main/java/org/sonar/graph/DsmManualSorter.java61
-rw-r--r--sonar-graph/src/main/java/org/sonar/graph/DsmPrinter.java105
-rw-r--r--sonar-graph/src/main/java/org/sonar/graph/DsmScanner.java116
-rw-r--r--sonar-graph/src/main/java/org/sonar/graph/DsmTopologicalSorter.java71
-rw-r--r--sonar-graph/src/main/java/org/sonar/graph/Edge.java30
-rw-r--r--sonar-graph/src/main/java/org/sonar/graph/EdgeFactory.java27
-rw-r--r--sonar-graph/src/main/java/org/sonar/graph/FeedbackCycle.java114
-rw-r--r--sonar-graph/src/main/java/org/sonar/graph/FeedbackEdge.java78
-rw-r--r--sonar-graph/src/main/java/org/sonar/graph/IncrementalCyclesAndFESSolver.java88
-rw-r--r--sonar-graph/src/main/java/org/sonar/graph/MinimumFeedbackEdgeSetSolver.java151
-rw-r--r--sonar-graph/src/main/java/org/sonar/graph/StringEdge.java74
-rw-r--r--sonar-graph/src/main/java/org/sonar/graph/StringEdgeFactory.java33
-rw-r--r--sonar-graph/src/main/java/org/sonar/graph/package-info.java25
-rw-r--r--sonar-graph/src/test/java/org/sonar/graph/CycleDetectorTest.java153
-rw-r--r--sonar-graph/src/test/java/org/sonar/graph/CycleTest.java64
-rw-r--r--sonar-graph/src/test/java/org/sonar/graph/DirectedGraphTest.java106
-rw-r--r--sonar-graph/src/test/java/org/sonar/graph/DsmManualSorterTest.java46
-rw-r--r--sonar-graph/src/test/java/org/sonar/graph/DsmPrinterTest.java64
-rw-r--r--sonar-graph/src/test/java/org/sonar/graph/DsmScannerTest.java55
-rw-r--r--sonar-graph/src/test/java/org/sonar/graph/DsmTest.java77
-rw-r--r--sonar-graph/src/test/java/org/sonar/graph/DsmTopologicalSorterTest.java110
-rw-r--r--sonar-graph/src/test/java/org/sonar/graph/FeedbackCycleTest.java66
-rw-r--r--sonar-graph/src/test/java/org/sonar/graph/FeedbackEdgeTest.java81
-rw-r--r--sonar-graph/src/test/java/org/sonar/graph/IncrementalCyclesAndFESSolverTest.java72
-rw-r--r--sonar-graph/src/test/java/org/sonar/graph/MinimumFeedbackEdgeSetSolverTest.java110
-rw-r--r--sonar-graph/src/test/java/org/sonar/graph/StringPrintWriter.java35
-rw-r--r--sonar-plugin-api/pom.xml5
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/DecoratorContext.java13
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java19
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/SonarIndex.java22
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java11
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/Dependency.java39
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/NewDependency.java47
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/internal/DefaultDependency.java137
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/internal/package-info.java21
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/package-info.java21
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java25
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorStorage.java3
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/design/Dependency.java10
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/design/DependencyDto.java200
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java124
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/Library.java4
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/Qualifiers.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceUtils.java3
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/internal/DefaultRequirement.java10
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/internal/SensorContextTesterTest.java11
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/design/DependencyTest.java47
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceUtilsTest.java1
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/resources/ScopesTest.java10
98 files changed, 220 insertions, 5917 deletions
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java
index 2d77a3d90c4..43f8d25f212 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java
@@ -25,8 +25,22 @@ import org.sonar.xoo.coverage.OverallCoverageSensor;
import org.sonar.xoo.coverage.UtCoverageSensor;
import org.sonar.xoo.extensions.XooPostJob;
import org.sonar.xoo.extensions.XooProjectBuilder;
-import org.sonar.xoo.lang.*;
-import org.sonar.xoo.rule.*;
+import org.sonar.xoo.lang.MeasureSensor;
+import org.sonar.xoo.lang.SymbolReferencesSensor;
+import org.sonar.xoo.lang.SyntaxHighlightingSensor;
+import org.sonar.xoo.lang.XooCpdMapping;
+import org.sonar.xoo.lang.XooTokenizer;
+import org.sonar.xoo.rule.ChecksSensor;
+import org.sonar.xoo.rule.CreateIssueByInternalKeySensor;
+import org.sonar.xoo.rule.DeprecatedResourceApiSensor;
+import org.sonar.xoo.rule.OneIssueOnDirPerFileSensor;
+import org.sonar.xoo.rule.OneIssuePerLineSensor;
+import org.sonar.xoo.rule.RandomAccessSensor;
+import org.sonar.xoo.rule.XooFakeExporter;
+import org.sonar.xoo.rule.XooFakeImporter;
+import org.sonar.xoo.rule.XooFakeImporterWithMessages;
+import org.sonar.xoo.rule.XooQualityProfile;
+import org.sonar.xoo.rule.XooRulesDefinition;
import org.sonar.xoo.scm.XooBlameCommand;
import org.sonar.xoo.scm.XooScmProvider;
import org.sonar.xoo.test.CoveragePerTestSensor;
@@ -66,7 +80,6 @@ public class XooPlugin extends SonarPlugin {
MeasureSensor.class,
SyntaxHighlightingSensor.class,
SymbolReferencesSensor.class,
- DependencySensor.class,
ChecksSensor.class,
RandomAccessSensor.class,
DeprecatedResourceApiSensor.class,
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/DependencySensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/DependencySensor.java
deleted file mode 100644
index 1c558ff24c6..00000000000
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/DependencySensor.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * 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.xoo.lang;
-
-import com.google.common.base.Splitter;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.batch.fs.FilePredicates;
-import org.sonar.api.batch.fs.FileSystem;
-import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.sensor.Sensor;
-import org.sonar.api.batch.sensor.SensorContext;
-import org.sonar.api.batch.sensor.SensorDescriptor;
-import org.sonar.api.utils.log.Logger;
-import org.sonar.api.utils.log.Loggers;
-import org.sonar.xoo.Xoo;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * Parse files *.xoo.deps
- */
-public class DependencySensor implements Sensor {
-
- private static final Logger LOG = Loggers.get(DependencySensor.class);
-
- private static final String DEPS_EXTENSION = ".deps";
-
- private void processDependencies(InputFile inputFile, SensorContext context) {
- File ioFile = inputFile.file();
- File depsFile = new File(ioFile.getParentFile(), ioFile.getName() + DEPS_EXTENSION);
- if (depsFile.exists()) {
- LOG.debug("Processing " + depsFile.getAbsolutePath());
- try {
- List<String> lines = FileUtils.readLines(depsFile, context.fileSystem().encoding().name());
- int lineNumber = 0;
- for (String line : lines) {
- lineNumber++;
- if (StringUtils.isBlank(line) || line.startsWith("#")) {
- continue;
- }
- processLine(depsFile, lineNumber, context, line, inputFile);
- }
- } catch (IOException e) {
- throw new IllegalStateException(e);
- }
- }
- }
-
- private void processLine(File coverPerTest, int lineNumber, SensorContext context, String line, InputFile file) {
- try {
- Iterator<String> split = Splitter.on(":").split(line).iterator();
- String otherFileRelativePath = split.next();
- FileSystem fs = context.fileSystem();
- InputFile otherFile = fs.inputFile(fs.predicates().hasRelativePath(otherFileRelativePath));
- if (otherFile == null) {
- throw new IllegalStateException("Unable to find file " + otherFileRelativePath);
- }
- int weight = Integer.parseInt(split.next());
- context.newDependency()
- .from(file)
- .to(otherFile)
- .weight(weight)
- .save();
- } catch (Exception e) {
- throw new IllegalStateException("Error processing line " + lineNumber + " of file " + coverPerTest.getAbsolutePath(), e);
- }
- }
-
- @Override
- public void describe(SensorDescriptor descriptor) {
- descriptor
- .name("Xoo Dependency Sensor")
- .onlyOnLanguages(Xoo.KEY)
- .onlyOnFileType(InputFile.Type.MAIN);
- }
-
- @Override
- public void execute(SensorContext context) {
- FileSystem fs = context.fileSystem();
- FilePredicates p = fs.predicates();
- for (InputFile file : fs.inputFiles(p.and(p.hasLanguages(Xoo.KEY), p.hasType(InputFile.Type.MAIN)))) {
- processDependencies(file, context);
- }
- }
-}
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/DependencySensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/DependencySensorTest.java
deleted file mode 100644
index 73b63909ebc..00000000000
--- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/DependencySensorTest.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * 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.xoo.lang;
-
-import org.sonar.api.batch.sensor.internal.SensorStorage;
-
-import org.apache.commons.io.FileUtils;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-import org.sonar.api.batch.fs.InputFile.Type;
-import org.sonar.api.batch.fs.internal.DefaultFileSystem;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.sensor.SensorContext;
-import org.sonar.api.batch.sensor.dependency.Dependency;
-import org.sonar.api.batch.sensor.dependency.internal.DefaultDependency;
-import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor;
-
-import java.io.File;
-import java.io.IOException;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public class DependencySensorTest {
-
- private DependencySensor sensor;
- private SensorContext context = mock(SensorContext.class);
- private DefaultFileSystem fileSystem;
-
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
- private File baseDir;
-
- @Before
- public void prepare() throws IOException {
- baseDir = temp.newFolder();
- sensor = new DependencySensor();
- fileSystem = new DefaultFileSystem(baseDir.toPath());
- when(context.fileSystem()).thenReturn(fileSystem);
- }
-
- @Test
- public void testDescriptor() {
- sensor.describe(new DefaultSensorDescriptor());
- }
-
- @Test
- public void testNoExecutionIfNoDepsFile() {
- DefaultInputFile file = new DefaultInputFile("foo", "src/foo.xoo").setLanguage("xoo")
- .setType(Type.MAIN);
- fileSystem.add(file);
- sensor.execute(context);
- }
-
- @Test
- public void testExecution() throws IOException {
- File deps = new File(baseDir, "src/foo.xoo.deps");
- FileUtils.write(deps, "src/foo2.xoo:2\nsrc2/foo3.xoo:6\n\n#comment");
- DefaultInputFile inputFile1 = new DefaultInputFile("foo", "src/foo.xoo").setLanguage("xoo");
- DefaultInputFile inputFile2 = new DefaultInputFile("foo", "src/foo2.xoo").setLanguage("xoo");
- DefaultInputFile inputFile3 = new DefaultInputFile("foo", "src2/foo3.xoo").setLanguage("xoo");
- fileSystem.add(inputFile1);
- fileSystem.add(inputFile2);
- fileSystem.add(inputFile3);
-
- final SensorStorage sensorStorage = mock(SensorStorage.class);
-
- when(context.newDependency()).thenAnswer(new Answer<Dependency>() {
- @Override
- public Dependency answer(InvocationOnMock invocation) throws Throwable {
- return new DefaultDependency(sensorStorage);
- }
- });
-
- sensor.execute(context);
-
- verify(sensorStorage).store(new DefaultDependency()
- .from(inputFile1)
- .to(inputFile2)
- .weight(2));
- verify(sensorStorage).store(new DefaultDependency()
- .from(inputFile1)
- .to(inputFile3)
- .weight(6));
- }
-}
diff --git a/pom.xml b/pom.xml
index 7feaf878fb2..9c79b6fd369 100644
--- a/pom.xml
+++ b/pom.xml
@@ -19,7 +19,6 @@
<module>sonar-colorizer</module>
<module>sonar-core</module>
<module>sonar-duplications</module>
- <module>sonar-graph</module>
<module>sonar-home</module>
<module>sonar-java-api</module>
<module>sonar-markdown</module>
@@ -631,7 +630,7 @@
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-graph</artifactId>
- <version>${project.version}</version>
+ <version>5.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.sonar</groupId>
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java
index cc9037a6ada..5c6d7e073d1 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java
@@ -27,12 +27,6 @@ import org.sonar.batch.debt.IssueChangelogDebtCalculator;
import org.sonar.batch.debt.NewDebtDecorator;
import org.sonar.batch.debt.SqaleRatingDecorator;
import org.sonar.batch.debt.SqaleRatingSettings;
-import org.sonar.batch.design.DirectoryDsmDecorator;
-import org.sonar.batch.design.DirectoryTangleIndexDecorator;
-import org.sonar.batch.design.FileTangleIndexDecorator;
-import org.sonar.batch.design.MavenDependenciesSensor;
-import org.sonar.batch.design.ProjectDsmDecorator;
-import org.sonar.batch.design.SubProjectDsmDecorator;
import org.sonar.batch.issue.tracking.InitialOpenIssuesSensor;
import org.sonar.batch.issue.tracking.IssueHandlers;
import org.sonar.batch.issue.tracking.IssueTracking;
@@ -72,13 +66,6 @@ public class BatchComponents {
// Maven
MavenProjectBootstrapper.class, MavenProjectConverter.class, MavenProjectBuilder.class,
- // Design
- ProjectDsmDecorator.class,
- SubProjectDsmDecorator.class,
- DirectoryDsmDecorator.class,
- DirectoryTangleIndexDecorator.class,
- FileTangleIndexDecorator.class,
-
// SCM
ScmConfiguration.class,
ScmSensor.class,
@@ -130,9 +117,6 @@ public class BatchComponents {
components.addAll(CorePropertyDefinitions.all());
// CPD
components.addAll(CpdComponents.all());
- if (!analysisMode.isMediumTest()) {
- components.add(MavenDependenciesSensor.class);
- }
return components;
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java
index 2a70c13ac9d..8cd0656e310 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java
@@ -19,7 +19,6 @@
*/
package org.sonar.batch.deprecated;
-import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.AnalysisMode;
@@ -36,7 +35,10 @@ import org.sonar.api.design.Dependency;
import org.sonar.api.measures.Measure;
import org.sonar.api.measures.MeasuresFilter;
import org.sonar.api.measures.Metric;
-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 org.sonar.api.rules.Violation;
import org.sonar.api.utils.SonarException;
import org.sonar.batch.sensor.DefaultSensorContext;
@@ -44,7 +46,6 @@ import org.sonar.batch.sensor.coverage.CoverageExclusions;
import java.io.Serializable;
import java.util.Collection;
-import java.util.Set;
public class DeprecatedSensorContext extends DefaultSensorContext implements SensorContext {
@@ -70,26 +71,15 @@ public class DeprecatedSensorContext extends DefaultSensorContext implements Sen
@Override
public boolean index(Resource resource) {
// SONAR-5006
- if (indexedByCore(resource)) {
- logWarning();
- return true;
- }
- return index.index(resource);
- }
-
- private boolean indexedByCore(Resource resource) {
- return StringUtils.equals(Qualifiers.DIRECTORY, resource.getQualifier()) ||
- StringUtils.equals(Qualifiers.FILE, resource.getQualifier());
+ logWarning();
+ return true;
}
@Override
public boolean index(Resource resource, Resource parentReference) {
// SONAR-5006
- if (indexedByCore(resource)) {
- logWarning();
- return true;
- }
- return index.index(resource, parentReference);
+ logWarning();
+ return true;
}
private void logWarning() {
@@ -206,22 +196,7 @@ public class DeprecatedSensorContext extends DefaultSensorContext implements Sen
@Override
public Dependency saveDependency(Dependency dependency) {
- return index.addDependency(dependency);
- }
-
- @Override
- public Set<Dependency> getDependencies() {
- return index.getDependencies();
- }
-
- @Override
- public Collection<Dependency> getIncomingDependencies(Resource to) {
- return index.getIncomingEdges(resourceOrProject(to));
- }
-
- @Override
- public Collection<Dependency> getOutgoingDependencies(Resource from) {
- return index.getOutgoingEdges(resourceOrProject(from));
+ return null;
}
@Override
diff --git a/sonar-batch/src/main/java/org/sonar/batch/deprecated/decorator/DefaultDecoratorContext.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/decorator/DefaultDecoratorContext.java
index 5b9d6497fa3..673357db494 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/deprecated/decorator/DefaultDecoratorContext.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/deprecated/decorator/DefaultDecoratorContext.java
@@ -35,13 +35,11 @@ import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.rules.Violation;
import org.sonar.api.utils.SonarException;
-import org.sonar.batch.duplication.DuplicationCache;
import org.sonar.batch.scan.measure.MeasureCache;
import org.sonar.batch.sensor.coverage.CoverageExclusions;
import java.util.Collection;
import java.util.List;
-import java.util.Set;
public class DefaultDecoratorContext implements DecoratorContext {
@@ -55,19 +53,15 @@ public class DefaultDecoratorContext implements DecoratorContext {
private ListMultimap<String, Measure> measuresByMetric = ArrayListMultimap.create();
private MeasureCache measureCache;
private MetricFinder metricFinder;
- private final DuplicationCache duplicationCache;
private final CoverageExclusions coverageFilter;
- public DefaultDecoratorContext(Resource resource,
- SonarIndex index,
- List<DecoratorContext> childrenContexts,
- MeasureCache measureCache, MetricFinder metricFinder, DuplicationCache duplicationCache, CoverageExclusions coverageFilter) {
+ public DefaultDecoratorContext(Resource resource, SonarIndex index, List<DecoratorContext> childrenContexts,
+ MeasureCache measureCache, MetricFinder metricFinder, CoverageExclusions coverageFilter) {
this.sonarIndex = index;
this.resource = resource;
this.childrenContexts = childrenContexts;
this.measureCache = measureCache;
this.metricFinder = metricFinder;
- this.duplicationCache = duplicationCache;
this.coverageFilter = coverageFilter;
}
@@ -190,23 +184,7 @@ public class DefaultDecoratorContext implements DecoratorContext {
@Override
public Dependency saveDependency(Dependency dependency) {
- checkReadOnly("addDependency");
- return sonarIndex.addDependency(dependency);
- }
-
- @Override
- public Set<Dependency> getDependencies() {
- return sonarIndex.getDependencies();
- }
-
- @Override
- public Collection<Dependency> getIncomingDependencies() {
- return sonarIndex.getIncomingEdges(resource);
- }
-
- @Override
- public Collection<Dependency> getOutgoingDependencies() {
- return sonarIndex.getOutgoingEdges(resource);
+ return null;
}
@Override
diff --git a/sonar-batch/src/main/java/org/sonar/batch/design/BaseTangleIndexDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/design/BaseTangleIndexDecorator.java
deleted file mode 100644
index 069b5707236..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/design/BaseTangleIndexDecorator.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * 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.design;
-
-import org.sonar.api.batch.Decorator;
-import org.sonar.api.batch.DecoratorContext;
-import org.sonar.api.batch.DependedUpon;
-import org.sonar.api.batch.DependsUpon;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.measures.MeasureUtils;
-import org.sonar.api.measures.Metric;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Resource;
-
-import java.util.Arrays;
-import java.util.List;
-
-public class BaseTangleIndexDecorator implements Decorator {
-
- private final Metric tanglesMetric;
- private final Metric edgesWeightMetric;
- private final Metric tangleIndexMetric;
-
- protected BaseTangleIndexDecorator(Metric tanglesMetric, Metric edgesWeightMetric, Metric tangleIndexMetric) {
- this.tanglesMetric = tanglesMetric;
- this.edgesWeightMetric = edgesWeightMetric;
- this.tangleIndexMetric = tangleIndexMetric;
- }
-
- @DependsUpon
- public final List<Metric> dependsUponMetrics() {
- return Arrays.asList(tanglesMetric, edgesWeightMetric);
- }
-
- /**
- * Used to define downstream dependencies
- */
- @DependedUpon
- public final Metric generatesMetric() {
- return tangleIndexMetric;
- }
-
- @Override
- public final boolean shouldExecuteOnProject(Project project) {
- return true;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public final void decorate(Resource resource, DecoratorContext context) {
- if (!shouldDecorateResource(context)) {
- return;
- }
- Measure tangles = context.getMeasure(tanglesMetric);
- Measure totalweight = context.getMeasure(edgesWeightMetric);
-
- if (MeasureUtils.hasValue(totalweight)) {
- context.saveMeasure(new Measure(tangleIndexMetric, compute(MeasureUtils.getValue(tangles, 0.0), totalweight.getValue())));
- }
- }
-
- private boolean shouldDecorateResource(DecoratorContext context) {
- return context.getMeasure(tangleIndexMetric) == null;
- }
-
- private double compute(double tangles, double totalWeight) {
- if (Double.doubleToRawLongBits(totalWeight) == 0L) {
- return 0.0;
- }
- double result = 2 * tangles / totalWeight;
- return result * 100;
- }
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/design/DirectoryDsmDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/design/DirectoryDsmDecorator.java
deleted file mode 100644
index f0527ca66f6..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/design/DirectoryDsmDecorator.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * 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.design;
-
-import org.sonar.api.batch.DecoratorContext;
-import org.sonar.api.batch.SonarIndex;
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.resources.ResourceUtils;
-import org.sonar.graph.Cycle;
-import org.sonar.graph.Edge;
-import org.sonar.graph.IncrementalCyclesAndFESSolver;
-import org.sonar.graph.MinimumFeedbackEdgeSetSolver;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
-public class DirectoryDsmDecorator extends DsmDecorator {
-
- public DirectoryDsmDecorator(SonarIndex index) {
- super(index);
- }
-
- @Override
- protected List<Resource> getChildren(Resource resource, DecoratorContext context) {
- List<DecoratorContext> fileContexts = context.getChildren();
- List<Resource> files = new ArrayList<>(fileContexts.size());
- for (DecoratorContext decoratorContext : fileContexts) {
- files.add(decoratorContext.getResource());
- }
- return files;
- }
-
- @Override
- protected Set<Edge> doProcess(List<Resource> children, DecoratorContext context) {
- IncrementalCyclesAndFESSolver<Resource> cycleDetector = new IncrementalCyclesAndFESSolver<>(getIndex(), children);
- Set<Cycle> cycles = cycleDetector.getCycles();
-
- MinimumFeedbackEdgeSetSolver solver = new MinimumFeedbackEdgeSetSolver(cycles);
- Set<Edge> feedbackEdges = solver.getEdges();
- int tangles = solver.getWeightOfFeedbackEdgeSet();
-
- savePositiveMeasure(context, CoreMetrics.FILE_CYCLES, cycles.size());
- savePositiveMeasure(context, CoreMetrics.FILE_FEEDBACK_EDGES, feedbackEdges.size());
- savePositiveMeasure(context, CoreMetrics.FILE_TANGLES, tangles);
- savePositiveMeasure(context, CoreMetrics.FILE_EDGES_WEIGHT, getEdgesWeight(children));
-
- return feedbackEdges;
- }
-
- @Override
- protected boolean shouldDecorateResource(Resource resource, DecoratorContext context) {
- return ResourceUtils.isDirectory(resource);
- }
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/design/DirectoryTangleIndexDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/design/DirectoryTangleIndexDecorator.java
deleted file mode 100644
index 8d8b5c580c4..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/design/DirectoryTangleIndexDecorator.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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.design;
-
-import org.sonar.api.measures.CoreMetrics;
-
-public class DirectoryTangleIndexDecorator extends BaseTangleIndexDecorator {
-
- public DirectoryTangleIndexDecorator() {
- super(CoreMetrics.DIRECTORY_TANGLES, CoreMetrics.DIRECTORY_EDGES_WEIGHT, CoreMetrics.DIRECTORY_TANGLE_INDEX);
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName();
- }
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/design/DsmDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/design/DsmDecorator.java
deleted file mode 100644
index 790debf713b..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/design/DsmDecorator.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * 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.design;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.batch.Decorator;
-import org.sonar.api.batch.DecoratorContext;
-import org.sonar.api.batch.SonarIndex;
-import org.sonar.api.design.Dependency;
-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.resources.Project;
-import org.sonar.api.resources.Resource;
-import org.sonar.graph.Dsm;
-import org.sonar.graph.DsmTopologicalSorter;
-import org.sonar.graph.Edge;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
-
-public abstract class DsmDecorator implements Decorator {
-
- private static final Logger LOG = LoggerFactory.getLogger(DsmDecorator.class);
-
- private static final int MAX_DSM_DIMENSION = 200;
- private SonarIndex index;
-
- public DsmDecorator(SonarIndex index) {
- this.index = index;
- }
-
- public final SonarIndex getIndex() {
- return index;
- }
-
- @Override
- public final boolean shouldExecuteOnProject(Project project) {
- return true;
- }
-
- @Override
- public final void decorate(final Resource resource, DecoratorContext context) {
- if (shouldDecorateResource(resource, context)) {
- List<Resource> children = getChildren(resource, context);
- if (children.isEmpty()) {
- return;
- }
- Set<Edge> feedbackEdges = doProcess(children, context);
-
- if (children.size() > MAX_DSM_DIMENSION) {
- LOG.warn("Too many components under resource '" + resource.getName() + "'. DSM will not be displayed.");
- return;
- }
- Dsm<Resource> dsm = getDsm(children, feedbackEdges);
- saveDsm(context, dsm);
- }
- }
-
- protected abstract boolean shouldDecorateResource(Resource resource, DecoratorContext context);
-
- protected abstract List<Resource> getChildren(Resource resource, DecoratorContext context);
-
- protected abstract Set<Edge> doProcess(List<Resource> children, DecoratorContext context);
-
- protected final void saveDsm(DecoratorContext context, Dsm<Resource> dsm) {
- Measure measure = new Measure(CoreMetrics.DEPENDENCY_MATRIX, DsmSerializer.serialize(dsm));
- measure.setPersistenceMode(PersistenceMode.DATABASE);
- context.saveMeasure(measure);
- }
-
- protected final Dsm<Resource> getDsm(Collection<Resource> children, Set<Edge> feedbackEdges) {
- Dsm<Resource> dsm = new Dsm<>(index, children, feedbackEdges);
- DsmTopologicalSorter.sort(dsm);
- return dsm;
- }
-
- protected final void savePositiveMeasure(DecoratorContext context, Metric<Integer> metric, double value) {
- if (value >= 0.0) {
- context.saveMeasure(new Measure(metric, value));
- }
- }
-
- protected final int getEdgesWeight(Collection<Resource> sourceCodes) {
- List<Dependency> edges = getEdges(sourceCodes);
- int total = 0;
- for (Dependency edge : edges) {
- total += edge.getWeight();
- }
- return total;
- }
-
- protected final List<Dependency> getEdges(Collection<Resource> vertices) {
- List<Dependency> result = new ArrayList<>();
- for (Resource vertice : vertices) {
- Collection<Dependency> outgoingEdges = index.getOutgoingEdges(vertice);
- if (outgoingEdges != null) {
- result.addAll(outgoingEdges);
- }
- }
- return result;
- }
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/design/DsmSerializer.java b/sonar-batch/src/main/java/org/sonar/batch/design/DsmSerializer.java
deleted file mode 100644
index 039921a94cf..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/design/DsmSerializer.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * 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.design;
-
-import org.sonar.api.design.Dependency;
-import org.sonar.api.resources.Resource;
-import org.sonar.graph.Dsm;
-import org.sonar.graph.DsmCell;
-
-public final class DsmSerializer {
-
- private Dsm dsm;
- private StringBuilder json;
-
- private DsmSerializer(Dsm<Resource> dsm) {
- this.dsm = dsm;
- this.json = new StringBuilder();
- }
-
- private String serialize() {
- json.append('[');
- serializeRows();
- json.append(']');
- return json.toString();
- }
-
- private void serializeRows() {
- for (int y = 0; y < dsm.getDimension(); y++) {
- if (y > 0) {
- json.append(',');
- }
- serializeRow(y);
- }
- }
-
- private void serializeRow(int y) {
- Resource resource = (Resource) dsm.getVertex(y);
-
- json.append("{");
- if (resource != null) {
- json.append("\"i\":");
- json.append(resource.getId());
- json.append(",\"n\":\"");
- json.append(resource.getName());
- json.append("\",\"q\":\"");
- json.append(resource.getQualifier());
- json.append("\",\"v\":[");
- for (int x = 0; x < dsm.getDimension(); x++) {
- if (x > 0) {
- json.append(',');
- }
- serializeCell(y, x);
- }
- json.append("]");
- }
- json.append("}");
- }
-
- private void serializeCell(int y, int x) {
- DsmCell cell = dsm.cell(x, y);
- json.append('{');
- if (cell != null && cell.getEdge() != null && cell.getWeight() > 0) {
- Dependency dep = (Dependency) cell.getEdge();
- json.append("\"i\":");
- json.append(dep.getId());
- json.append(",\"w\":");
- json.append(cell.getWeight());
- }
- json.append('}');
- }
-
- public static String serialize(Dsm<Resource> dsm) {
- return new DsmSerializer(dsm).serialize();
- }
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/design/FileTangleIndexDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/design/FileTangleIndexDecorator.java
deleted file mode 100644
index b4d46f85e11..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/design/FileTangleIndexDecorator.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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.design;
-
-import org.sonar.api.measures.CoreMetrics;
-
-public class FileTangleIndexDecorator extends BaseTangleIndexDecorator {
-
- public FileTangleIndexDecorator() {
- super(CoreMetrics.FILE_TANGLES, CoreMetrics.FILE_EDGES_WEIGHT, CoreMetrics.FILE_TANGLE_INDEX);
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName();
- }
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/design/MavenDependenciesSensor.java b/sonar-batch/src/main/java/org/sonar/batch/design/MavenDependenciesSensor.java
deleted file mode 100644
index 6956cac89b7..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/design/MavenDependenciesSensor.java
+++ /dev/null
@@ -1,278 +0,0 @@
-/*
- * 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.design;
-
-import org.sonar.api.batch.RequiresDB;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.reflect.TypeToken;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.resolver.ArtifactCollector;
-import org.apache.maven.shared.dependency.tree.DependencyNode;
-import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder;
-import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException;
-import org.apache.maven.shared.dependency.tree.filter.AncestorOrSelfDependencyNodeFilter;
-import org.apache.maven.shared.dependency.tree.filter.DependencyNodeFilter;
-import org.apache.maven.shared.dependency.tree.filter.StateDependencyNodeFilter;
-import org.apache.maven.shared.dependency.tree.traversal.BuildingDependencyNodeVisitor;
-import org.apache.maven.shared.dependency.tree.traversal.CollectingDependencyNodeVisitor;
-import org.apache.maven.shared.dependency.tree.traversal.DependencyNodeVisitor;
-import org.apache.maven.shared.dependency.tree.traversal.FilteringDependencyNodeVisitor;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.batch.Sensor;
-import org.sonar.api.batch.SensorContext;
-import org.sonar.api.batch.SonarIndex;
-import org.sonar.api.batch.SupportedEnvironment;
-import org.sonar.api.config.Settings;
-import org.sonar.api.design.Dependency;
-import org.sonar.api.resources.Library;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.utils.SonarException;
-import org.sonar.batch.index.ResourcePersister;
-
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-@SupportedEnvironment("maven")
-@RequiresDB
-public class MavenDependenciesSensor implements Sensor {
-
- private static final String SONAR_MAVEN_PROJECT_DEPENDENCY = "sonar.maven.projectDependencies";
-
- private static final Logger LOG = LoggerFactory.getLogger(MavenDependenciesSensor.class);
-
- private final ArtifactRepository localRepository;
- private final ArtifactFactory artifactFactory;
- private final ArtifactMetadataSource artifactMetadataSource;
- private final ArtifactCollector artifactCollector;
- private final DependencyTreeBuilder treeBuilder;
- private final SonarIndex index;
- private final Settings settings;
- private final ResourcePersister resourcePersister;
-
- public MavenDependenciesSensor(Settings settings, ArtifactRepository localRepository, ArtifactFactory artifactFactory, ArtifactMetadataSource artifactMetadataSource,
- ArtifactCollector artifactCollector, DependencyTreeBuilder treeBuilder, SonarIndex index, ResourcePersister resourcePersister) {
- this.settings = settings;
- this.localRepository = localRepository;
- this.artifactFactory = artifactFactory;
- this.artifactMetadataSource = artifactMetadataSource;
- this.artifactCollector = artifactCollector;
- this.index = index;
- this.treeBuilder = treeBuilder;
- this.resourcePersister = resourcePersister;
- }
-
- /**
- * Used with SQ Maven plugin 2.5+
- */
- public MavenDependenciesSensor(Settings settings, SonarIndex index, ResourcePersister resourcePersister) {
- this(settings, null, null, null, null, null, index, resourcePersister);
- }
-
- @Override
- public boolean shouldExecuteOnProject(Project project) {
- return true;
- }
-
- private static class InputDependency {
-
- private final String key;
-
- private final String version;
-
- private String scope;
-
- List<InputDependency> dependencies = new ArrayList<>();
-
- public InputDependency(String key, String version) {
- this.key = key;
- this.version = version;
- }
-
- public String key() {
- return key;
- }
-
- public String version() {
- return version;
- }
-
- public String scope() {
- return scope;
- }
-
- public InputDependency setScope(String scope) {
- this.scope = scope;
- return this;
- }
-
- public List<InputDependency> dependencies() {
- return dependencies;
- }
- }
-
- private static class DependencyDeserializer implements JsonDeserializer<InputDependency> {
-
- @Override
- public InputDependency deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {
-
- JsonObject dep = json.getAsJsonObject();
- String key = dep.get("k").getAsString();
- String version = dep.get("v").getAsString();
- InputDependency result = new InputDependency(key, version);
- result.setScope(dep.get("s").getAsString());
- JsonElement subDeps = dep.get("d");
- if (subDeps != null) {
- JsonArray arrayOfSubDeps = subDeps.getAsJsonArray();
- for (JsonElement e : arrayOfSubDeps) {
- result.dependencies().add(deserialize(e, typeOfT, context));
- }
- }
- return result;
- }
-
- }
-
- @Override
- public void analyse(final Project project, final SensorContext context) {
- if (settings.hasKey(SONAR_MAVEN_PROJECT_DEPENDENCY)) {
- LOG.debug("Using dependency provided by property " + SONAR_MAVEN_PROJECT_DEPENDENCY);
- String depsAsJson = settings.getString(SONAR_MAVEN_PROJECT_DEPENDENCY);
- Collection<InputDependency> deps;
- try {
- GsonBuilder gsonBuilder = new GsonBuilder();
- gsonBuilder.registerTypeAdapter(InputDependency.class, new DependencyDeserializer());
- Gson gson = gsonBuilder.create();
-
- Type collectionType = new TypeToken<Collection<InputDependency>>() {
- }.getType();
- deps = gson.fromJson(depsAsJson, collectionType);
- saveDependencies(project, project, deps, context);
- } catch (Exception e) {
- throw new IllegalStateException("Unable to deserialize dependency information: " + depsAsJson, e);
- }
- } else if (treeBuilder != null) {
- computeDependencyTree(project, context);
- }
- }
-
- private void computeDependencyTree(final Project project, final SensorContext context) {
- LOG.warn("Computation of Maven dependencies by SonarQube is deprecated. Please update the version of SonarQube Maven plugin to 2.5+");
- try {
- DependencyNode root = treeBuilder.buildDependencyTree(project.getPom(), localRepository, artifactFactory, artifactMetadataSource, null, artifactCollector);
-
- DependencyNodeVisitor visitor = new BuildingDependencyNodeVisitor(new DependencyNodeVisitor() {
- @Override
- public boolean visit(DependencyNode node) {
- return true;
- }
-
- @Override
- public boolean endVisit(DependencyNode node) {
- if (node.getParent() != null && node.getParent() != node) {
- saveDependency(project, node, context);
- }
- return true;
- }
- });
-
- // mode verbose OFF : do not show the same lib many times
- DependencyNodeFilter filter = StateDependencyNodeFilter.INCLUDED;
-
- CollectingDependencyNodeVisitor collectingVisitor = new CollectingDependencyNodeVisitor();
- DependencyNodeVisitor firstPassVisitor = new FilteringDependencyNodeVisitor(collectingVisitor, filter);
- root.accept(firstPassVisitor);
-
- DependencyNodeFilter secondPassFilter = new AncestorOrSelfDependencyNodeFilter(collectingVisitor.getNodes());
- visitor = new FilteringDependencyNodeVisitor(visitor, secondPassFilter);
-
- root.accept(visitor);
-
- } catch (DependencyTreeBuilderException e) {
- throw new SonarException("Can not load the graph of dependencies of the project " + project.getKey(), e);
- }
- }
-
- private void saveDependencies(Project project, Resource from, Collection<InputDependency> deps, SensorContext context) {
- for (InputDependency inputDep : deps) {
- Resource to = toResource(project, inputDep, context);
- Dependency dependency = new Dependency(from, to);
- dependency.setUsage(inputDep.scope());
- dependency.setWeight(1);
- context.saveDependency(dependency);
- if (!inputDep.dependencies().isEmpty()) {
- saveDependencies(project, to, inputDep.dependencies(), context);
- }
- }
- }
-
- private Resource toResource(Project project, InputDependency dependency, SensorContext context) {
- Project depProject = new Project(dependency.key(), project.getBranch(), dependency.key());
- Resource result = context.getResource(depProject);
- if (result == null || !((Project) result).getAnalysisVersion().equals(dependency.version())) {
- Library lib = new Library(dependency.key(), dependency.version());
- index.addResource(lib);
- // Temporary hack since we need snapshot id to persist dependencies
- resourcePersister.persist();
- result = context.getResource(lib);
- }
- return result;
- }
-
- protected void saveDependency(final Project project, DependencyNode node, SensorContext context) {
- Resource from = (node.getParent().getParent() == null) ? index.getProject() : toResource(project, node.getParent().getArtifact(), context);
- Resource to = toResource(project, node.getArtifact(), context);
- Dependency dependency = new Dependency(from, to);
- dependency.setUsage(node.getArtifact().getScope());
- dependency.setWeight(1);
- context.saveDependency(dependency);
- }
-
- protected Resource toResource(final Project project, Artifact artifact, SensorContext context) {
- Project depWithBranch = Project.createFromMavenIds(artifact.getGroupId(), artifact.getArtifactId(), project.getBranch());
- Resource result = context.getResource(depWithBranch);
- if (result == null || !((Project) result).getAnalysisVersion().equals(artifact.getBaseVersion())) {
- Library lib = Library.createFromMavenIds(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion());
- index.addResource(lib);
- // Temporary hack since we need snapshot id to persist dependencies
- resourcePersister.persist();
- result = context.getResource(lib);
- }
- return result;
- }
-
- @Override
- public String toString() {
- return "Maven dependencies";
- }
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/design/ProjectDsmDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/design/ProjectDsmDecorator.java
deleted file mode 100644
index 620ceeabd3f..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/design/ProjectDsmDecorator.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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.design;
-
-import com.google.common.collect.Lists;
-import org.sonar.api.batch.DecoratorContext;
-import org.sonar.api.batch.SonarIndex;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.resources.ResourceUtils;
-import org.sonar.graph.Cycle;
-import org.sonar.graph.CycleDetector;
-import org.sonar.graph.Edge;
-import org.sonar.graph.MinimumFeedbackEdgeSetSolver;
-
-import java.util.List;
-import java.util.Set;
-
-public class ProjectDsmDecorator extends DsmDecorator {
-
- public ProjectDsmDecorator(SonarIndex index) {
- super(index);
- }
-
- /**
- * sub-projects, including all descendants but not only direct children
- */
- @Override
- protected List<Resource> getChildren(Resource resource, DecoratorContext context) {
- List<Resource> subProjects = Lists.newArrayList();
- addSubProjects((Project) resource, subProjects);
- return subProjects;
- }
-
- private void addSubProjects(Project project, List<Resource> subProjects) {
- for (Project subProject : project.getModules()) {
- Project indexedSubProject = getIndex().getResource(subProject);
- if (indexedSubProject != null) {
- subProjects.add(indexedSubProject);
- }
- addSubProjects(subProject, subProjects);
- }
- }
-
- @Override
- protected Set<Edge> doProcess(List<Resource> children, DecoratorContext context) {
- CycleDetector<Resource> cycleDetector = new CycleDetector<>(getIndex(), children);
- Set<Cycle> cycles = cycleDetector.getCycles();
-
- MinimumFeedbackEdgeSetSolver solver = new MinimumFeedbackEdgeSetSolver(cycles);
- return solver.getEdges();
- }
-
- @Override
- protected boolean shouldDecorateResource(Resource resource, DecoratorContext context) {
- // Should not execute on views
- return (ResourceUtils.isRootProject(resource) || ResourceUtils.isModuleProject(resource))
- && !((Project) resource).getModules().isEmpty();
- }
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/design/SubProjectDsmDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/design/SubProjectDsmDecorator.java
deleted file mode 100644
index 62aa622b11d..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/design/SubProjectDsmDecorator.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * 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.design;
-
-import org.sonar.api.batch.DecoratorContext;
-import org.sonar.api.batch.SonarIndex;
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.resources.ResourceUtils;
-import org.sonar.graph.Cycle;
-import org.sonar.graph.Edge;
-import org.sonar.graph.IncrementalCyclesAndFESSolver;
-import org.sonar.graph.MinimumFeedbackEdgeSetSolver;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
-public class SubProjectDsmDecorator extends DsmDecorator {
-
- public SubProjectDsmDecorator(SonarIndex index) {
- super(index);
- }
-
- @Override
- protected List<Resource> getChildren(Resource resource, DecoratorContext context) {
- List<DecoratorContext> directoryContexts = context.getChildren();
- List<Resource> directories = new ArrayList<>(directoryContexts.size());
- for (DecoratorContext decoratorContext : directoryContexts) {
- directories.add(decoratorContext.getResource());
- }
- return directories;
- }
-
- @Override
- protected Set<Edge> doProcess(List<Resource> children, DecoratorContext context) {
- IncrementalCyclesAndFESSolver<Resource> cycleDetector = new IncrementalCyclesAndFESSolver<>(getIndex(), children);
- Set<Cycle> cycles = cycleDetector.getCycles();
-
- MinimumFeedbackEdgeSetSolver solver = new MinimumFeedbackEdgeSetSolver(cycles);
- Set<Edge> feedbackEdges = solver.getEdges();
- int tangles = solver.getWeightOfFeedbackEdgeSet();
-
- savePositiveMeasure(context, CoreMetrics.DIRECTORY_CYCLES, cycles.size());
- savePositiveMeasure(context, CoreMetrics.DIRECTORY_FEEDBACK_EDGES, feedbackEdges.size());
- savePositiveMeasure(context, CoreMetrics.DIRECTORY_TANGLES, tangles);
- savePositiveMeasure(context, CoreMetrics.DIRECTORY_EDGES_WEIGHT, getEdgesWeight(children));
- return feedbackEdges;
- }
-
- @Override
- protected boolean shouldDecorateResource(Resource resource, DecoratorContext context) {
- // Should not execute on views
- return (ResourceUtils.isRootProject(resource) || ResourceUtils.isModuleProject(resource))
- // Only on leaf projects
- && ((Project) resource).getModules().isEmpty();
- }
-}
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 c56ddb46c17..bed28c439a5 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
@@ -19,10 +19,8 @@
*/
package org.sonar.batch.index;
-import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
@@ -60,8 +58,6 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -72,20 +68,7 @@ public class DefaultIndex extends SonarIndex {
private static final Logger LOG = LoggerFactory.getLogger(DefaultIndex.class);
private static final List<Metric> INTERNAL_METRICS = Arrays.<Metric>asList(
- // Computed by DsmDecorator
- CoreMetrics.DEPENDENCY_MATRIX,
- CoreMetrics.DIRECTORY_CYCLES,
- CoreMetrics.DIRECTORY_EDGES_WEIGHT,
- CoreMetrics.DIRECTORY_FEEDBACK_EDGES,
- CoreMetrics.DIRECTORY_TANGLE_INDEX,
- CoreMetrics.DIRECTORY_TANGLES,
- CoreMetrics.FILE_CYCLES,
- CoreMetrics.FILE_EDGES_WEIGHT,
- CoreMetrics.FILE_FEEDBACK_EDGES,
- CoreMetrics.FILE_TANGLE_INDEX,
- CoreMetrics.FILE_TANGLES,
// Computed by CpdSensor
- CoreMetrics.DUPLICATIONS_DATA,
CoreMetrics.DUPLICATED_FILES,
CoreMetrics.DUPLICATED_LINES,
CoreMetrics.DUPLICATED_BLOCKS,
@@ -93,23 +76,32 @@ public class DefaultIndex extends SonarIndex {
CoreMetrics.LINES
);
+ private static final List<String> DEPRECATED_METRICS_KEYS = Arrays.<String>asList(
+ CoreMetrics.DEPENDENCY_MATRIX_KEY,
+ CoreMetrics.DIRECTORY_CYCLES_KEY,
+ CoreMetrics.DIRECTORY_EDGES_WEIGHT_KEY,
+ CoreMetrics.DIRECTORY_FEEDBACK_EDGES_KEY,
+ CoreMetrics.DIRECTORY_TANGLE_INDEX_KEY,
+ CoreMetrics.DIRECTORY_TANGLES_KEY,
+ CoreMetrics.FILE_CYCLES_KEY,
+ CoreMetrics.FILE_EDGES_WEIGHT_KEY,
+ CoreMetrics.FILE_FEEDBACK_EDGES_KEY,
+ CoreMetrics.FILE_TANGLE_INDEX_KEY,
+ CoreMetrics.FILE_TANGLES_KEY,
+ CoreMetrics.DUPLICATIONS_DATA_KEY
+ );
+
private final ResourceCache resourceCache;
private final MetricFinder metricFinder;
private final MeasureCache measureCache;
- private final DependencyPersister dependencyPersister;
// caches
private Project currentProject;
private Map<Resource, Bucket> buckets = Maps.newLinkedHashMap();
- private Set<Dependency> dependencies = Sets.newLinkedHashSet();
- private Map<Resource, Map<Resource, Dependency>> outgoingDependenciesByResource = Maps.newLinkedHashMap();
- private Map<Resource, Map<Resource, Dependency>> incomingDependenciesByResource = Maps.newLinkedHashMap();
private DefaultProjectTree projectTree;
private ModuleIssues moduleIssues;
- public DefaultIndex(ResourceCache resourceCache, DependencyPersister dependencyPersister,
- DefaultProjectTree projectTree, MetricFinder metricFinder, MeasureCache measureCache) {
+ public DefaultIndex(ResourceCache resourceCache, DefaultProjectTree projectTree, MetricFinder metricFinder, MeasureCache measureCache) {
this.resourceCache = resourceCache;
- this.dependencyPersister = dependencyPersister;
this.projectTree = projectTree;
this.metricFinder = metricFinder;
this.measureCache = measureCache;
@@ -175,16 +167,6 @@ public class DefaultIndex extends SonarIndex {
}
}
-
- // Keep only inter module dependencies
- Set<Dependency> projectDependencies = getDependenciesBetweenProjects();
- dependencies.clear();
- incomingDependenciesByResource.clear();
- outgoingDependenciesByResource.clear();
- for (Dependency projectDependency : projectDependencies) {
- projectDependency.setId(null);
- registerDependency(projectDependency);
- }
}
@CheckForNull
@@ -221,6 +203,10 @@ public class DefaultIndex extends SonarIndex {
public Measure addMeasure(Resource resource, Measure measure) {
Bucket bucket = getBucket(resource);
if (bucket != null) {
+ if (DEPRECATED_METRICS_KEYS.contains(measure.getMetricKey())) {
+ // Ignore deprecated metrics
+ return null;
+ }
org.sonar.api.batch.measure.Metric metric = metricFinder.findByKey(measure.getMetricKey());
if (metric == null) {
throw new SonarException("Unknown metric: " + measure.getMetricKey());
@@ -237,121 +223,16 @@ public class DefaultIndex extends SonarIndex {
return measure;
}
- //
- //
- //
- // DEPENDENCIES
- //
- //
- //
-
@Override
public Dependency addDependency(Dependency dependency) {
- // Reload resources
- Resource from = getResource(dependency.getFrom());
- Preconditions.checkArgument(from != null, dependency.getFrom() + " is not indexed");
- dependency.setFrom(from);
- Resource to = getResource(dependency.getTo());
- Preconditions.checkArgument(to != null, dependency.getTo() + " is not indexed");
- dependency.setTo(to);
-
- Dependency existingDep = getEdge(from, to);
- if (existingDep != null) {
- return existingDep;
- }
-
- Dependency parentDependency = dependency.getParent();
- if (parentDependency != null) {
- addDependency(parentDependency);
- }
- registerDependency(dependency);
- dependencyPersister.saveDependency(currentProject, dependency);
return dependency;
}
- boolean registerDependency(Dependency dependency) {
- Bucket fromBucket = doIndex(dependency.getFrom());
- Bucket toBucket = doIndex(dependency.getTo());
-
- if (fromBucket != null && toBucket != null) {
- dependencies.add(dependency);
- registerOutgoingDependency(dependency);
- registerIncomingDependency(dependency);
- return true;
- }
- return false;
- }
-
- private void registerOutgoingDependency(Dependency dependency) {
- Map<Resource, Dependency> outgoingDeps = outgoingDependenciesByResource.get(dependency.getFrom());
- if (outgoingDeps == null) {
- outgoingDeps = new HashMap<>();
- outgoingDependenciesByResource.put(dependency.getFrom(), outgoingDeps);
- }
- outgoingDeps.put(dependency.getTo(), dependency);
- }
-
- private void registerIncomingDependency(Dependency dependency) {
- Map<Resource, Dependency> incomingDeps = incomingDependenciesByResource.get(dependency.getTo());
- if (incomingDeps == null) {
- incomingDeps = new HashMap<>();
- incomingDependenciesByResource.put(dependency.getTo(), incomingDeps);
- }
- incomingDeps.put(dependency.getFrom(), dependency);
- }
-
- @Override
- public Set<Dependency> getDependencies() {
- return dependencies;
- }
-
- @Override
- public Dependency getEdge(Resource from, Resource to) {
- Map<Resource, Dependency> map = outgoingDependenciesByResource.get(from);
- if (map != null) {
- return map.get(to);
- }
- return null;
- }
-
- @Override
- public boolean hasEdge(Resource from, Resource to) {
- return getEdge(from, to) != null;
- }
-
@Override
- public Set<Resource> getVertices() {
+ public Set<Resource> getResources() {
return buckets.keySet();
}
- @Override
- public Collection<Dependency> getOutgoingEdges(Resource from) {
- Map<Resource, Dependency> deps = outgoingDependenciesByResource.get(from);
- if (deps != null) {
- return deps.values();
- }
- return Collections.emptyList();
- }
-
- @Override
- public Collection<Dependency> getIncomingEdges(Resource to) {
- Map<Resource, Dependency> deps = incomingDependenciesByResource.get(to);
- if (deps != null) {
- return deps.values();
- }
- return Collections.emptyList();
- }
-
- Set<Dependency> getDependenciesBetweenProjects() {
- Set<Dependency> result = Sets.newLinkedHashSet();
- for (Dependency dependency : dependencies) {
- if (ResourceUtils.isSet(dependency.getFrom()) || ResourceUtils.isSet(dependency.getTo())) {
- result.add(dependency);
- }
- }
- return result;
- }
-
//
//
//
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DependencyPersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/DependencyPersister.java
deleted file mode 100644
index 5c4195bb719..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/index/DependencyPersister.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * 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.index;
-
-import org.sonar.api.database.DatabaseSession;
-import org.sonar.api.design.Dependency;
-import org.sonar.api.design.DependencyDto;
-import org.sonar.api.resources.Project;
-import org.sonar.batch.protocol.output.BatchReport;
-import org.sonar.batch.report.ReportPublisher;
-
-import javax.annotation.Nullable;
-
-public final class DependencyPersister {
-
- private final ResourceCache resourceCache;
- private final DatabaseSession session;
- private final ReportPublisher reportPublisher;
- private final BatchReport.FileDependency.Builder builder = BatchReport.FileDependency.newBuilder();
-
- public DependencyPersister(ResourceCache resourceCache, ReportPublisher reportPublisher, @Nullable DatabaseSession session) {
- this.resourceCache = resourceCache;
- this.reportPublisher = reportPublisher;
- this.session = session;
- }
-
- public DependencyPersister(ResourceCache resourceCache, ReportPublisher reportPublisher) {
- this(resourceCache, reportPublisher, null);
- }
-
- public void saveDependency(Project project, Dependency dependency) {
- BatchResource fromResource = resourceCache.get(dependency.getFrom());
- BatchResource toResource = resourceCache.get(dependency.getTo());
- BatchResource projectResource = resourceCache.get(project);
-
- if (fromResource.isFile() && toResource.isFile()) {
- builder.clear();
- reportPublisher.getWriter().appendFileDependency(fromResource.batchId(), builder.setToFileRef(toResource.batchId()).setWeight(dependency.getWeight()).build());
- }
-
- if (session != null) {
- saveInDB(project, dependency, fromResource, toResource, projectResource);
- }
- }
-
- private void saveInDB(Project project, Dependency dependency, BatchResource fromResource, BatchResource toResource, BatchResource projectResource) {
- DependencyDto model = new DependencyDto();
- model.setProjectSnapshotId(projectResource.snapshotId());
- model.setUsage(dependency.getUsage());
- model.setWeight(dependency.getWeight());
-
- model.setFromComponentUuid(fromResource.resource().getUuid());
- model.setFromScope(fromResource.resource().getScope());
- model.setFromSnapshotId(fromResource.snapshotId());
-
- model.setToComponentUuid(toResource.resource().getUuid());
- model.setToScope(toResource.resource().getScope());
- model.setToSnapshotId(toResource.snapshotId());
-
- Dependency parentDependency = dependency.getParent();
- if (parentDependency != null) {
- if (parentDependency.getId() == null) {
- saveDependency(project, parentDependency);
- }
- model.setParentDependencyId(parentDependency.getId());
- }
- session.save(model);
- dependency.setId(model.getId());
- }
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/ResourceCache.java b/sonar-batch/src/main/java/org/sonar/batch/index/ResourceCache.java
index 19de9fb7791..c95d0d72b53 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/ResourceCache.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/ResourceCache.java
@@ -26,7 +26,6 @@ import com.google.common.collect.Maps;
import org.sonar.api.BatchSide;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.resources.Library;
import org.sonar.api.resources.Resource;
import org.sonar.api.resources.ResourceUtils;
import org.sonar.core.component.ScanGraph;
@@ -41,8 +40,6 @@ import java.util.Map;
public class ResourceCache {
// resource by component key
private final Map<String, BatchResource> resources = Maps.newLinkedHashMap();
- // dedicated cache for libraries
- private final Map<Library, BatchResource> libraries = Maps.newLinkedHashMap();
private BatchResource root;
private final ScanGraph scanGraph;
@@ -62,11 +59,7 @@ public class ResourceCache {
}
public BatchResource get(Resource resource) {
- if (!(resource instanceof Library)) {
- return resources.get(resource.getEffectiveKey());
- } else {
- return libraries.get(resource);
- }
+ return resources.get(resource.getEffectiveKey());
}
public BatchResource get(InputFile inputFile) {
@@ -78,14 +71,10 @@ public class ResourceCache {
Preconditions.checkState(!Strings.isNullOrEmpty(componentKey), "Missing resource effective key");
BatchResource parent = parentResource != null ? get(parentResource.getEffectiveKey()) : null;
BatchResource batchResource = new BatchResource(resources.size() + 1, resource, parent);
- if (!(resource instanceof Library)) {
- // Libraries can have the same effective key than a project so we can't cache by effectiveKey
- resources.put(componentKey, batchResource);
- if (parent == null) {
- root = batchResource;
- }
- } else {
- libraries.put((Library) resource, batchResource);
+ // Libraries can have the same effective key than a project so we can't cache by effectiveKey
+ resources.put(componentKey, batchResource);
+ if (parent == null) {
+ root = batchResource;
}
if (scanGraph != null && ResourceUtils.isPersistable(batchResource.resource())) {
scanGraph.addComponent(batchResource.resource());
@@ -97,10 +86,6 @@ public class ResourceCache {
return resources.values();
}
- public Collection<BatchResource> allLibraries() {
- return libraries.values();
- }
-
public BatchResource getRoot() {
return root;
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java
index d76e69c6830..cf31dfdcaf5 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java
@@ -26,7 +26,6 @@ import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.ResourceModel;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.Language;
-import org.sonar.api.resources.Library;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Resource;
@@ -35,15 +34,10 @@ import org.sonar.api.resources.Scopes;
import org.sonar.api.security.ResourcePermissions;
import org.sonar.api.utils.SonarException;
import org.sonar.api.utils.internal.Uuids;
-import org.sonar.batch.DefaultProjectTree;
import org.sonar.core.component.ScanGraph;
import javax.annotation.Nullable;
import javax.persistence.NonUniqueResultException;
-import javax.persistence.Query;
-
-import java.util.Date;
-import java.util.List;
import static org.sonar.api.utils.DateUtils.dateToLong;
@@ -51,20 +45,13 @@ public class ResourcePersister implements ScanPersister {
@VisibleForTesting
static final String MODULE_UUID_PATH_SEPARATOR = ".";
- private static final String RESOURCE_ID = "resourceId";
- private static final String LAST = "last";
- private static final String VERSION = "version";
- private static final String SCOPE = "scope";
- private static final String QUALIFIER = "qualifier";
private final DatabaseSession session;
private final ResourcePermissions permissions;
private final ResourceCache resourceCache;
- private final DefaultProjectTree projectTree;
private final ScanGraph scanGraph;
- public ResourcePersister(DefaultProjectTree projectTree, DatabaseSession session, ResourcePermissions permissions, ResourceCache resourceCache, ScanGraph scanGraph) {
- this.projectTree = projectTree;
+ public ResourcePersister(DatabaseSession session, ResourcePermissions permissions, ResourceCache resourceCache, ScanGraph scanGraph) {
this.session = session;
this.permissions = permissions;
this.resourceCache = resourceCache;
@@ -76,19 +63,6 @@ public class ResourcePersister implements ScanPersister {
for (BatchResource resource : resourceCache.all()) {
persist(resource);
}
-
- for (BatchResource lib : resourceCache.allLibraries()) {
- if (lib.snapshot() != null) {
- // already persisted
- continue;
- }
- persistLibrary(lib);
- }
- }
-
- private void persistLibrary(BatchResource lib) {
- Snapshot s = persistLibrary(projectTree.getRootProject().getAnalysisDate(), (Library) lib.resource());
- lib.setSnapshot(s);
}
private void persist(BatchResource batchResource) {
@@ -169,46 +143,6 @@ public class ResourcePersister implements ScanPersister {
return snapshot;
}
- Snapshot persistLibrary(Date analysisDate, Library library) {
- ResourceModel model = findOrCreateModel(library, null);
- model = session.save(model);
- // TODO to be removed
- library.setId(model.getId());
- library.setUuid(model.getUuid());
- library.setEffectiveKey(library.getKey());
-
- Snapshot snapshot = findLibrarySnapshot(model.getId(), library.getVersion());
- if (snapshot == null) {
- snapshot = new Snapshot(model, null);
- snapshot.setCreatedAtMs(dateToLong(analysisDate));
- snapshot.setBuildDateMs(System.currentTimeMillis());
- snapshot.setVersion(library.getVersion());
- snapshot.setStatus(Snapshot.STATUS_PROCESSED);
-
- // see http://jira.codehaus.org/browse/SONAR-1850
- // The qualifier must be LIB, even if the resource is TRK, because this snapshot has no measures.
- snapshot.setQualifier(Qualifiers.LIBRARY);
- snapshot = session.save(snapshot);
- }
- session.commit();
- return snapshot;
- }
-
- private Snapshot findLibrarySnapshot(Integer resourceId, String version) {
- Query query = session.createQuery("from " + Snapshot.class.getSimpleName() +
- " s WHERE s.resourceId=:resourceId AND s.version=:version AND s.scope=:scope AND s.qualifier<>:qualifier AND s.last=:last");
- query.setParameter(RESOURCE_ID, resourceId);
- query.setParameter(VERSION, version);
- query.setParameter(SCOPE, Scopes.PROJECT);
- query.setParameter(QUALIFIER, Qualifiers.LIBRARY);
- query.setParameter(LAST, Boolean.TRUE);
- List<Snapshot> snapshots = query.getResultList();
- if (snapshots.isEmpty()) {
- snapshots = session.getResults(Snapshot.class, RESOURCE_ID, resourceId, VERSION, version, SCOPE, Scopes.PROJECT, QUALIFIER, Qualifiers.LIBRARY);
- }
- return snapshots.isEmpty() ? null : snapshots.get(0);
- }
-
/**
* Everything except project and library
*/
diff --git a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java
index b352631eddd..321d495f929 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java
@@ -27,7 +27,11 @@ import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.AnalysisMode;
-import org.sonar.api.batch.fs.*;
+import org.sonar.api.batch.fs.InputDir;
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.fs.InputPath;
+import org.sonar.api.batch.fs.TextPointer;
+import org.sonar.api.batch.fs.TextRange;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.sensor.duplication.Duplication;
import org.sonar.api.batch.sensor.highlighting.TypeOfText;
@@ -39,11 +43,12 @@ import org.sonar.batch.duplication.DuplicationCache;
import org.sonar.batch.index.Cache.Entry;
import org.sonar.batch.index.ResourceCache;
import org.sonar.batch.issue.IssueCache;
-import org.sonar.batch.protocol.output.*;
+import org.sonar.batch.protocol.output.BatchReport;
import org.sonar.batch.protocol.output.BatchReport.Component;
import org.sonar.batch.protocol.output.BatchReport.Metadata;
import org.sonar.batch.protocol.output.BatchReport.Range;
import org.sonar.batch.protocol.output.BatchReport.Symbols.Symbol;
+import org.sonar.batch.protocol.output.BatchReportReader;
import org.sonar.batch.report.BatchReportUtils;
import org.sonar.batch.report.ReportPublisher;
import org.sonar.batch.scan.ProjectScanContainer;
@@ -56,7 +61,12 @@ import javax.annotation.Nullable;
import java.io.File;
import java.io.InputStream;
import java.io.Serializable;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
public class TaskResult implements org.sonar.batch.mediumtest.ScanTaskObserver {
@@ -272,23 +282,6 @@ public class TaskResult implements org.sonar.batch.mediumtest.ScanTaskObserver {
return null;
}
- public BatchReport.FileDependency fileDependencyFor(InputFile file, InputFile anotherFile) {
- int ref = reportComponents.get(((DefaultInputFile) file).key()).getRef();
- int otherRef = reportComponents.get(((DefaultInputFile) anotherFile).key()).getRef();
- try (InputStream inputStream = FileUtils.openInputStream(getReportReader().readFileDependencies(ref))) {
- BatchReport.FileDependency dep = BatchReport.FileDependency.PARSER.parseDelimitedFrom(inputStream);
- while (dep != null) {
- if (dep.getToFileRef() == otherRef) {
- return dep;
- }
- dep = BatchReport.FileDependency.PARSER.parseDelimitedFrom(inputStream);
- }
- } catch (Exception e) {
- throw new IllegalStateException(e);
- }
- return null;
- }
-
public BatchReport.CoverageDetail coveragePerTestFor(InputFile testFile, String testName) {
int ref = reportComponents.get(((DefaultInputFile) testFile).key()).getRef();
try (InputStream inputStream = FileUtils.openInputStream(getReportReader().readCoverageDetails(ref))) {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java
index bf7dcb4731a..995de90ec2a 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java
@@ -33,7 +33,6 @@ import org.sonar.api.utils.SonarException;
import org.sonar.batch.bootstrap.BatchExtensionDictionnary;
import org.sonar.batch.deprecated.decorator.DecoratorsSelector;
import org.sonar.batch.deprecated.decorator.DefaultDecoratorContext;
-import org.sonar.batch.duplication.DuplicationCache;
import org.sonar.batch.events.EventBus;
import org.sonar.batch.scan.measure.MeasureCache;
import org.sonar.batch.sensor.coverage.CoverageExclusions;
@@ -51,15 +50,12 @@ public class DecoratorsExecutor {
private final CoverageExclusions coverageFilter;
private final MeasureCache measureCache;
private final MetricFinder metricFinder;
- private final DuplicationCache duplicationCache;
private final AnalysisMode analysisMode;
- public DecoratorsExecutor(BatchExtensionDictionnary batchExtDictionnary,
- Project project, SonarIndex index, EventBus eventBus, CoverageExclusions coverageFilter, MeasureCache measureCache, MetricFinder metricFinder,
- DuplicationCache duplicationCache, AnalysisMode analysisMode) {
+ public DecoratorsExecutor(BatchExtensionDictionnary batchExtDictionnary, Project project, SonarIndex index, EventBus eventBus, CoverageExclusions coverageFilter,
+ MeasureCache measureCache, MetricFinder metricFinder, AnalysisMode analysisMode) {
this.measureCache = measureCache;
this.metricFinder = metricFinder;
- this.duplicationCache = duplicationCache;
this.analysisMode = analysisMode;
this.decoratorsSelector = new DecoratorsSelector(batchExtDictionnary);
this.index = index;
@@ -87,7 +83,7 @@ public class DecoratorsExecutor {
childrenContexts.add(childContext.end());
}
- DefaultDecoratorContext context = new DefaultDecoratorContext(resource, index, childrenContexts, measureCache, metricFinder, duplicationCache, coverageFilter);
+ DefaultDecoratorContext context = new DefaultDecoratorContext(resource, index, childrenContexts, measureCache, metricFinder, coverageFilter);
context.init();
if (executeDecorators) {
for (Decorator decorator : decorators) {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
index 5da07abfd86..08b4ba77719 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
@@ -46,7 +46,6 @@ import org.sonar.batch.duplication.DuplicationCache;
import org.sonar.batch.events.EventBus;
import org.sonar.batch.index.Caches;
import org.sonar.batch.index.DefaultIndex;
-import org.sonar.batch.index.DependencyPersister;
import org.sonar.batch.index.ResourceCache;
import org.sonar.batch.index.ResourcePersister;
import org.sonar.batch.issue.DefaultProjectIssues;
@@ -198,9 +197,6 @@ public class ProjectScanContainer extends ComponentContainer {
// Duplications
DuplicationCache.class,
- // Dependencies
- DependencyPersister.class,
-
// Quality Gate
new QualityGateProvider(),
diff --git a/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java b/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java
index 9387f3c832e..d0f6f4f6fcc 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java
@@ -25,8 +25,6 @@ import org.sonar.api.batch.rule.ActiveRules;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.coverage.NewCoverage;
import org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage;
-import org.sonar.api.batch.sensor.dependency.NewDependency;
-import org.sonar.api.batch.sensor.dependency.internal.DefaultDependency;
import org.sonar.api.batch.sensor.duplication.NewDuplication;
import org.sonar.api.batch.sensor.duplication.internal.DefaultDuplication;
import org.sonar.api.batch.sensor.highlighting.NewHighlighting;
@@ -101,9 +99,4 @@ public class DefaultSensorContext implements SensorContext {
return new DefaultCoverage(sensorStorage);
}
- @Override
- public NewDependency newDependency() {
- return new DefaultDependency(sensorStorage);
- }
-
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java b/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java
index be0c84ee4cf..cf4b285971a 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java
@@ -20,7 +20,6 @@
package org.sonar.batch.sensor;
import com.google.common.base.Function;
-import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
@@ -41,13 +40,11 @@ import org.sonar.api.batch.sensor.issue.Issue;
import org.sonar.api.batch.sensor.measure.Measure;
import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure;
import org.sonar.api.config.Settings;
-import org.sonar.api.design.Dependency;
import org.sonar.api.issue.internal.DefaultIssue;
import org.sonar.api.measures.Formula;
import org.sonar.api.measures.Metric;
import org.sonar.api.measures.PersistenceMode;
import org.sonar.api.measures.SumChildDistributionFormula;
-import org.sonar.api.resources.Directory;
import org.sonar.api.resources.File;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Scopes;
@@ -73,7 +70,6 @@ import java.util.Set;
public class DefaultSensorStorage implements SensorStorage {
- private static final String USES = "USES";
private final MetricFinder metricFinder;
private final Project project;
private final ModuleIssues moduleIssues;
@@ -190,35 +186,6 @@ public class DefaultSensorStorage implements SensorStorage {
}
@Override
- public void store(org.sonar.api.batch.sensor.dependency.Dependency dep) {
- BatchResource fromBatchResource = resourceCache.get(dep.fromKey());
- BatchResource toBatchResource = resourceCache.get(dep.toKey());
- Preconditions.checkNotNull(fromBatchResource, "Unable to find origin resource " + dep.fromKey());
- Preconditions.checkNotNull(toBatchResource, "Unable to find destination resource " + dep.toKey());
- File fromResource = (File) fromBatchResource.resource();
- File toResource = (File) toBatchResource.resource();
- if (sonarIndex.getEdge(fromResource, toResource) != null) {
- throw new IllegalStateException("Dependency between " + dep.fromKey() + " and " + dep.toKey() + " was already saved.");
- }
- Directory fromParent = fromResource.getParent();
- Directory toParent = toResource.getParent();
- Dependency parentDep = null;
- if (!fromParent.equals(toParent)) {
- parentDep = sonarIndex.getEdge(fromParent, toParent);
- if (parentDep != null) {
- parentDep.setWeight(parentDep.getWeight() + 1);
- } else {
- parentDep = new Dependency(fromParent, toParent).setUsage(USES).setWeight(1);
- parentDep = sonarIndex.addDependency(parentDep);
- }
- }
- sonarIndex.addDependency(new Dependency(fromResource, toResource)
- .setUsage(USES)
- .setWeight(dep.weight())
- .setParent(parentDep));
- }
-
- @Override
public void store(Duplication duplication) {
duplicationCache.put(duplication.originBlock().resourceKey(), (DefaultDuplication) duplication);
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/design/DirectoryDsmDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/design/DirectoryDsmDecoratorTest.java
deleted file mode 100644
index e24265ab7cf..00000000000
--- a/sonar-batch/src/test/java/org/sonar/batch/design/DirectoryDsmDecoratorTest.java
+++ /dev/null
@@ -1,218 +0,0 @@
-/*
- * 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.design;
-
-import edu.emory.mathcs.backport.java.util.Collections;
-import org.apache.commons.lang.ObjectUtils;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.ArgumentMatcher;
-import org.sonar.api.batch.DecoratorContext;
-import org.sonar.api.batch.SonarIndex;
-import org.sonar.api.design.Dependency;
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.measures.Metric;
-import org.sonar.api.resources.Directory;
-import org.sonar.api.resources.File;
-import org.sonar.api.resources.Project;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.argThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public class DirectoryDsmDecoratorTest {
-
- private DirectoryDsmDecorator decorator;
- private Directory dir;
- private DecoratorContext dirContext;
- private SonarIndex index;
- private File file1;
- private File file2;
- private DecoratorContext file1Context;
- private DecoratorContext file2Context;
-
- @Before
- public void prepare() {
- index = mock(SonarIndex.class);
- decorator = new DirectoryDsmDecorator(index);
- dir = Directory.create("src");
- dirContext = mock(DecoratorContext.class);
-
- file1 = File.create("src/Foo1.java", null, false);
- file1.setId(1);
- file2 = File.create("src/Foo2.java", null, false);
- file2.setId(2);
-
- file1Context = mock(DecoratorContext.class);
- when(file1Context.getResource()).thenReturn(file1);
- file2Context = mock(DecoratorContext.class);
- when(file2Context.getResource()).thenReturn(file2);
-
- when(dirContext.getChildren()).thenReturn(Arrays.asList(file1Context, file2Context));
-
- }
-
- @Test
- public void testDirectoryDsmDecoratorNoExecution() {
- assertThat(decorator.shouldExecuteOnProject(null)).isTrue();
-
- // Should not execute on project
- decorator.decorate(new Project("foo"), dirContext);
-
- // Should not do anything if dir has no files
- when(dirContext.getChildren()).thenReturn(Collections.emptyList());
- decorator.decorate(dir, dirContext);
-
- verify(dirContext, never()).saveMeasure(any(Measure.class));
- }
-
- @Test
- public void testDirectoryDsmDecoratorNoDependency() {
- decorator.decorate(dir, dirContext);
-
- verify(dirContext, times(5)).saveMeasure(any(Measure.class));
-
- verify(dirContext).saveMeasure(isMeasureWithValue(CoreMetrics.FILE_CYCLES, 0.0));
- verify(dirContext).saveMeasure(isMeasureWithValue(CoreMetrics.FILE_FEEDBACK_EDGES, 0.0));
- verify(dirContext).saveMeasure(isMeasureWithValue(CoreMetrics.FILE_TANGLES, 0.0));
- verify(dirContext).saveMeasure(isMeasureWithValue(CoreMetrics.FILE_EDGES_WEIGHT, 0.0));
- verify(dirContext).saveMeasure(
- isMeasureWithValue(CoreMetrics.DEPENDENCY_MATRIX,
- "[{\"i\":1,\"n\":\"Foo1.java\",\"q\":\"FIL\",\"v\":[{},{}]},{\"i\":2,\"n\":\"Foo2.java\",\"q\":\"FIL\",\"v\":[{},{}]}]"));
-
- }
-
- @Test
- public void testDirectoryDsmDecoratorDependency() {
- Dependency dependency = new Dependency(file1, file2).setWeight(1).setId(51L);
- when(index.getEdge(file1, file2)).thenReturn(dependency);
- when(index.hasEdge(file1, file2)).thenReturn(true);
- when(index.getOutgoingEdges(file1)).thenReturn(Arrays.asList(dependency));
- when(index.getIncomingEdges(file2)).thenReturn(Arrays.asList(dependency));
-
- decorator.decorate(dir, dirContext);
-
- verify(dirContext, times(5)).saveMeasure(any(Measure.class));
-
- verify(dirContext).saveMeasure(isMeasureWithValue(CoreMetrics.FILE_CYCLES, 0.0));
- verify(dirContext).saveMeasure(isMeasureWithValue(CoreMetrics.FILE_FEEDBACK_EDGES, 0.0));
- verify(dirContext).saveMeasure(isMeasureWithValue(CoreMetrics.FILE_TANGLES, 0.0));
- verify(dirContext).saveMeasure(isMeasureWithValue(CoreMetrics.FILE_EDGES_WEIGHT, 1.0));
-
- verify(dirContext).saveMeasure(
- isMeasureWithValue(CoreMetrics.DEPENDENCY_MATRIX,
- "[{\"i\":1,\"n\":\"Foo1.java\",\"q\":\"FIL\",\"v\":[{},{}]},{\"i\":2,\"n\":\"Foo2.java\",\"q\":\"FIL\",\"v\":[{\"i\":51,\"w\":1},{}]}]"));
- }
-
- @Test
- public void testDirectoryDsmDecoratorNoDSMIfMoreThan200Components() {
- Dependency dependency = new Dependency(file1, file2).setWeight(1).setId(51L);
- when(index.getEdge(file1, file2)).thenReturn(dependency);
- when(index.hasEdge(file1, file2)).thenReturn(true);
- when(index.getOutgoingEdges(file1)).thenReturn(Arrays.asList(dependency));
- when(index.getIncomingEdges(file2)).thenReturn(Arrays.asList(dependency));
-
- List<DecoratorContext> contexts = new ArrayList<>(201);
- contexts.add(file1Context);
- contexts.add(file2Context);
- for (int i = 0; i < 199; i++) {
- DecoratorContext fileContext = mock(DecoratorContext.class);
- when(fileContext.getResource()).thenReturn(File.create("file" + i));
- contexts.add(fileContext);
- }
-
- when(dirContext.getChildren()).thenReturn(contexts);
-
- decorator.decorate(dir, dirContext);
-
- verify(dirContext, times(4)).saveMeasure(any(Measure.class));
-
- verify(dirContext).saveMeasure(isMeasureWithValue(CoreMetrics.FILE_CYCLES, 0.0));
- verify(dirContext).saveMeasure(isMeasureWithValue(CoreMetrics.FILE_FEEDBACK_EDGES, 0.0));
- verify(dirContext).saveMeasure(isMeasureWithValue(CoreMetrics.FILE_TANGLES, 0.0));
- verify(dirContext).saveMeasure(isMeasureWithValue(CoreMetrics.FILE_EDGES_WEIGHT, 1.0));
- }
-
- @Test
- public void testDirectoryDsmDecoratorCycleDependency() {
- Dependency dependency1to2 = new Dependency(file1, file2).setWeight(1).setId(50L);
- when(index.getEdge(file1, file2)).thenReturn(dependency1to2);
- when(index.hasEdge(file1, file2)).thenReturn(true);
- when(index.getOutgoingEdges(file1)).thenReturn(Arrays.asList(dependency1to2));
- when(index.getIncomingEdges(file2)).thenReturn(Arrays.asList(dependency1to2));
- Dependency dependency2to1 = new Dependency(file2, file1).setWeight(2).setId(51L);
- when(index.getEdge(file2, file1)).thenReturn(dependency2to1);
- when(index.hasEdge(file2, file1)).thenReturn(true);
- when(index.getOutgoingEdges(file2)).thenReturn(Arrays.asList(dependency2to1));
- when(index.getIncomingEdges(file1)).thenReturn(Arrays.asList(dependency2to1));
-
- decorator.decorate(dir, dirContext);
-
- verify(dirContext, times(5)).saveMeasure(any(Measure.class));
-
- verify(dirContext).saveMeasure(isMeasureWithValue(CoreMetrics.FILE_CYCLES, 1.0));
- verify(dirContext).saveMeasure(isMeasureWithValue(CoreMetrics.FILE_FEEDBACK_EDGES, 1.0));
- verify(dirContext).saveMeasure(isMeasureWithValue(CoreMetrics.FILE_TANGLES, 1.0));
- verify(dirContext).saveMeasure(isMeasureWithValue(CoreMetrics.FILE_EDGES_WEIGHT, 3.0));
-
- verify(dirContext).saveMeasure(
- isMeasureWithValue(CoreMetrics.DEPENDENCY_MATRIX,
- "[{\"i\":2,\"n\":\"Foo2.java\",\"q\":\"FIL\",\"v\":[{},{\"i\":50,\"w\":1}]},{\"i\":1,\"n\":\"Foo1.java\",\"q\":\"FIL\",\"v\":[{\"i\":51,\"w\":2},{}]}]"));
- }
-
- Measure isMeasureWithValue(Metric metric, Double value) {
- return argThat(new IsMeasureWithValue(metric, value));
- }
-
- Measure isMeasureWithValue(Metric metric, String data) {
- return argThat(new IsMeasureWithValue(metric, data));
- }
-
- class IsMeasureWithValue extends ArgumentMatcher<Measure> {
-
- private Metric metric;
- private Double value;
- private String data;
-
- public IsMeasureWithValue(Metric metric, Double value) {
- this.metric = metric;
- this.value = value;
- }
-
- public IsMeasureWithValue(Metric metric, String data) {
- this.metric = metric;
- this.data = data;
- }
-
- public boolean matches(Object m) {
- return ((Measure) m).getMetric().equals(metric) && ObjectUtils.equals(((Measure) m).getValue(), value) && ObjectUtils.equals(((Measure) m).getData(), data);
- }
- }
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/design/DsmSerializerTest.java b/sonar-batch/src/test/java/org/sonar/batch/design/DsmSerializerTest.java
deleted file mode 100644
index 5d807287771..00000000000
--- a/sonar-batch/src/test/java/org/sonar/batch/design/DsmSerializerTest.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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.design;
-
-import org.apache.commons.io.IOUtils;
-import org.junit.Test;
-import org.sonar.api.design.Dependency;
-import org.sonar.api.resources.Directory;
-import org.sonar.api.resources.Resource;
-import org.sonar.graph.DirectedGraph;
-import org.sonar.graph.Dsm;
-import org.sonar.graph.DsmManualSorter;
-import org.sonar.graph.Edge;
-
-import java.io.IOException;
-
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
-
-public class DsmSerializerTest {
- @Test
- public void serializeEmptyDsm() {
- Dsm<Resource> dsm = new Dsm<>(new DirectedGraph<Resource, Edge<Resource>>());
- assertThat(DsmSerializer.serialize(dsm), is("[]"));
- }
-
- @Test
- public void serialize() throws IOException {
- Resource foo = Directory.create("src/org/foo").setId(7);
- Resource bar = Directory.create("src/org/bar").setId(8);
- Dependency dep = new Dependency(foo, bar).setId(30l).setWeight(1);
-
- DirectedGraph<Resource, Dependency> graph = new DirectedGraph<>();
- graph.addVertex(foo);
- graph.addVertex(bar);
- graph.addEdge(dep);
-
- Dsm<Resource> dsm = new Dsm<>(graph);
- DsmManualSorter.sort(dsm, bar, foo); // for test reproductibility
- String json = IOUtils.toString(getClass().getResourceAsStream("/org/sonar/batch/design/DsmSerializerTest/dsm.json")).trim();
- assertThat(DsmSerializer.serialize(dsm), is(json));
- }
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/design/MavenDependenciesSensorTest.java b/sonar-batch/src/test/java/org/sonar/batch/design/MavenDependenciesSensorTest.java
deleted file mode 100644
index bdad05d8fd5..00000000000
--- a/sonar-batch/src/test/java/org/sonar/batch/design/MavenDependenciesSensorTest.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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.design;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-import org.sonar.api.batch.SensorContext;
-import org.sonar.api.batch.SonarIndex;
-import org.sonar.api.config.Settings;
-import org.sonar.api.design.Dependency;
-import org.sonar.api.resources.Library;
-import org.sonar.api.resources.Project;
-import org.sonar.batch.index.ResourcePersister;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public class MavenDependenciesSensorTest {
-
- private MavenDependenciesSensor sensor;
- private Settings settings;
- private SonarIndex sonarIndex;
- private SensorContext sensorContext;
-
- @Before
- public void prepare() {
- settings = new Settings();
- sonarIndex = mock(SonarIndex.class);
- sensor = new MavenDependenciesSensor(settings, sonarIndex, mock(ResourcePersister.class));
- sensorContext = mock(SensorContext.class);
- when(sensorContext.getResource(any(Library.class))).thenAnswer(new Answer<Library>() {
- public Library answer(InvocationOnMock invocation) throws Throwable {
- return (invocation.getArguments()[0] instanceof Library) ? (Library) invocation.getArguments()[0] : null;
- }
- });
-
- }
-
- @Test
- public void testDependenciesProvidedAsProperties() {
- settings
- .setProperty(
- "sonar.maven.projectDependencies",
- "[{\"k\":\"antlr:antlr\",\"v\":\"2.7.2\",\"s\":\"compile\",\"d\":[]},"
- + "{\"k\":\"commons-beanutils:commons-beanutils\",\"v\":\"1.7.0\",\"s\":\"compile\",\"d\":[]},"
- + "{\"k\":\"commons-chain:commons-chain\",\"v\":\"1.1\",\"s\":\"compile\",\"d\":[]},"
- + "{\"k\":\"commons-digester:commons-digester\",\"v\":\"1.8\",\"s\":\"compile\",\"d\":[]},"
- + "{\"k\":\"commons-fileupload:commons-fileupload\",\"v\":\"1.1.1\",\"s\":\"compile\",\"d\":[{\"k\":\"commons-io:commons-io\",\"v\":\"1.1\",\"s\":\"compile\",\"d\":[]}]},"
- + "{\"k\":\"commons-logging:commons-logging\",\"v\":\"1.0.4\",\"s\":\"compile\",\"d\":[]},"
- + "{\"k\":\"commons-validator:commons-validator\",\"v\":\"1.3.1\",\"s\":\"compile\",\"d\":[]},"
- + "{\"k\":\"javax.servlet:servlet-api\",\"v\":\"2.3\",\"s\":\"provided\",\"d\":[]},"
- + "{\"k\":\"junit:junit\",\"v\":\"3.8.1\",\"s\":\"test\",\"d\":[]},"
- + "{\"k\":\"oro:oro\",\"v\":\"2.0.8\",\"s\":\"compile\",\"d\":[]}]");
-
- Project project = new Project("foo");
- sensor.analyse(project, sensorContext);
-
- Library antlr = new Library("antlr:antlr", "2.7.2");
- verify(sonarIndex).addResource(eq(antlr));
- Library commonsFU = new Library("commons-fileupload:commons-fileupload", "1.1.1");
- verify(sonarIndex).addResource(eq(commonsFU));
- Library commonsIo = new Library("commons-io:commons-io", "1.1");
- verify(sonarIndex).addResource(eq(commonsIo));
- Library junit = new Library("junit:junit", "3.8.1");
- verify(sonarIndex).addResource(eq(junit));
-
- verify(sensorContext).saveDependency(new Dependency(project, antlr).setUsage("compile").setWeight(1));
- verify(sensorContext).saveDependency(new Dependency(commonsFU, commonsIo).setUsage("compile").setWeight(1));
- verify(sensorContext).saveDependency(new Dependency(project, junit).setUsage("test").setWeight(1));
- }
-
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/design/ProjectDsmDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/design/ProjectDsmDecoratorTest.java
deleted file mode 100644
index 0d78693fa59..00000000000
--- a/sonar-batch/src/test/java/org/sonar/batch/design/ProjectDsmDecoratorTest.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * 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.design;
-
-import org.apache.commons.lang.ObjectUtils;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.ArgumentMatcher;
-import org.sonar.api.batch.DecoratorContext;
-import org.sonar.api.batch.SonarIndex;
-import org.sonar.api.design.Dependency;
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.measures.Metric;
-import org.sonar.api.resources.Directory;
-import org.sonar.api.resources.Project;
-
-import java.util.Arrays;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.argThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public class ProjectDsmDecoratorTest {
-
- private ProjectDsmDecorator decorator;
- private Project root;
- private DecoratorContext rootContext;
- private SonarIndex index;
- private Project module1;
- private Project module2;
-
- @Before
- public void prepare() {
- index = mock(SonarIndex.class);
- decorator = new ProjectDsmDecorator(index);
- root = new Project("root");
- rootContext = mock(DecoratorContext.class);
-
- module1 = new Project("module1").setName("Module1").setParent(root);
- module1.setId(1);
- when(index.getResource(module1)).thenReturn(module1);
- module2 = new Project("module2").setName("Module2").setParent(root);
- module2.setId(2);
- when(index.getResource(module2)).thenReturn(module2);
-
- DecoratorContext module1Context = mock(DecoratorContext.class);
- when(module1Context.getResource()).thenReturn(module1);
- DecoratorContext module2Context = mock(DecoratorContext.class);
- when(module2Context.getResource()).thenReturn(module2);
-
- when(rootContext.getChildren()).thenReturn(Arrays.asList(module1Context, module2Context));
-
- }
-
- @Test
- public void testProjectDsmDecoratorNoExecution() {
- assertThat(decorator.shouldExecuteOnProject(null)).isTrue();
-
- // Should not execute on directory
- decorator.decorate(Directory.create("foo"), rootContext);
- // Should not execute on aggregator projects
- Project p = new Project("parent");
- Project child = new Project("child").setParent(p);
- decorator.decorate(p, rootContext);
-
- verify(rootContext, never()).saveMeasure(any(Measure.class));
- }
-
- @Test
- public void testProjectDsmDecoratorDependency() {
- Dependency dependency = new Dependency(module1, module2).setWeight(1).setId(51L);
- when(index.getEdge(module1, module2)).thenReturn(dependency);
- when(index.hasEdge(module1, module2)).thenReturn(true);
- when(index.getOutgoingEdges(module1)).thenReturn(Arrays.asList(dependency));
- when(index.getIncomingEdges(module2)).thenReturn(Arrays.asList(dependency));
-
- decorator.decorate(root, rootContext);
-
- verify(rootContext, times(1)).saveMeasure(any(Measure.class));
-
- verify(rootContext).saveMeasure(
- isMeasureWithValue(CoreMetrics.DEPENDENCY_MATRIX,
- "[{\"i\":1,\"n\":\"Module1\",\"q\":\"BRC\",\"v\":[{},{}]},{\"i\":2,\"n\":\"Module2\",\"q\":\"BRC\",\"v\":[{\"i\":51,\"w\":1},{}]}]"));
- }
-
- Measure isMeasureWithValue(Metric metric, Double value) {
- return argThat(new IsMeasureWithValue(metric, value));
- }
-
- Measure isMeasureWithValue(Metric metric, String data) {
- return argThat(new IsMeasureWithValue(metric, data));
- }
-
- class IsMeasureWithValue extends ArgumentMatcher<Measure> {
-
- private Metric metric;
- private Double value;
- private String data;
-
- public IsMeasureWithValue(Metric metric, Double value) {
- this.metric = metric;
- this.value = value;
- }
-
- public IsMeasureWithValue(Metric metric, String data) {
- this.metric = metric;
- this.data = data;
- }
-
- public boolean matches(Object m) {
- return ((Measure) m).getMetric().equals(metric) && ObjectUtils.equals(((Measure) m).getValue(), value) && ObjectUtils.equals(((Measure) m).getData(), data);
- }
- }
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/design/SubProjectDsmDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/design/SubProjectDsmDecoratorTest.java
deleted file mode 100644
index bc65050aab2..00000000000
--- a/sonar-batch/src/test/java/org/sonar/batch/design/SubProjectDsmDecoratorTest.java
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * 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.design;
-
-import edu.emory.mathcs.backport.java.util.Collections;
-import org.apache.commons.lang.ObjectUtils;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.ArgumentMatcher;
-import org.sonar.api.batch.DecoratorContext;
-import org.sonar.api.batch.SonarIndex;
-import org.sonar.api.design.Dependency;
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.measures.Metric;
-import org.sonar.api.resources.Directory;
-import org.sonar.api.resources.Project;
-
-import java.util.Arrays;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.argThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public class SubProjectDsmDecoratorTest {
-
- private SubProjectDsmDecorator decorator;
- private Project module;
- private DecoratorContext moduleContext;
- private SonarIndex index;
- private Directory dir1;
- private Directory dir2;
-
- @Before
- public void prepare() {
- index = mock(SonarIndex.class);
- decorator = new SubProjectDsmDecorator(index);
- module = new Project("foo");
- moduleContext = mock(DecoratorContext.class);
-
- dir1 = Directory.create("src/foo1");
- dir1.setId(1);
- dir2 = Directory.create("src/foo2");
- dir2.setId(2);
-
- DecoratorContext dir1Context = mock(DecoratorContext.class);
- when(dir1Context.getResource()).thenReturn(dir1);
- DecoratorContext dir2Context = mock(DecoratorContext.class);
- when(dir2Context.getResource()).thenReturn(dir2);
-
- when(moduleContext.getChildren()).thenReturn(Arrays.asList(dir1Context, dir2Context));
-
- }
-
- @Test
- public void testSubProjectDsmDecoratorNoExecution() {
- assertThat(decorator.shouldExecuteOnProject(null)).isTrue();
-
- // Should not execute on directory
- decorator.decorate(Directory.create("foo"), moduleContext);
- // Should not execute on aggregator projects
- Project p = new Project("parent");
- Project child = new Project("child").setParent(p);
- decorator.decorate(p, moduleContext);
-
- // Should not do anything if module has no dir
- when(moduleContext.getChildren()).thenReturn(Collections.emptyList());
- decorator.decorate(module, moduleContext);
-
- verify(moduleContext, never()).saveMeasure(any(Measure.class));
- }
-
- @Test
- public void testSubProjectDsmDecoratorNoDependency() {
- decorator.decorate(module, moduleContext);
-
- verify(moduleContext, times(5)).saveMeasure(any(Measure.class));
-
- verify(moduleContext).saveMeasure(isMeasureWithValue(CoreMetrics.DIRECTORY_CYCLES, 0.0));
- verify(moduleContext).saveMeasure(isMeasureWithValue(CoreMetrics.DIRECTORY_FEEDBACK_EDGES, 0.0));
- verify(moduleContext).saveMeasure(isMeasureWithValue(CoreMetrics.DIRECTORY_TANGLES, 0.0));
- verify(moduleContext).saveMeasure(isMeasureWithValue(CoreMetrics.DIRECTORY_EDGES_WEIGHT, 0.0));
- verify(moduleContext).saveMeasure(isMeasureWithValue(CoreMetrics.DEPENDENCY_MATRIX,
- "[{\"i\":1,\"n\":\"src/foo1\",\"q\":\"DIR\",\"v\":[{},{}]},{\"i\":2,\"n\":\"src/foo2\",\"q\":\"DIR\",\"v\":[{},{}]}]"));
- }
-
- @Test
- public void testSubProjectDsmDecoratorDependency() {
- Dependency dependency = new Dependency(dir1, dir2).setWeight(1).setId(51L);
- when(index.getEdge(dir1, dir2)).thenReturn(dependency);
- when(index.hasEdge(dir1, dir2)).thenReturn(true);
- when(index.getOutgoingEdges(dir1)).thenReturn(Arrays.asList(dependency));
- when(index.getIncomingEdges(dir2)).thenReturn(Arrays.asList(dependency));
-
- decorator.decorate(module, moduleContext);
-
- verify(moduleContext, times(5)).saveMeasure(any(Measure.class));
-
- verify(moduleContext).saveMeasure(isMeasureWithValue(CoreMetrics.DIRECTORY_CYCLES, 0.0));
- verify(moduleContext).saveMeasure(isMeasureWithValue(CoreMetrics.DIRECTORY_FEEDBACK_EDGES, 0.0));
- verify(moduleContext).saveMeasure(isMeasureWithValue(CoreMetrics.DIRECTORY_TANGLES, 0.0));
- verify(moduleContext).saveMeasure(isMeasureWithValue(CoreMetrics.DIRECTORY_EDGES_WEIGHT, 1.0));
-
- verify(moduleContext).saveMeasure(
- isMeasureWithValue(CoreMetrics.DEPENDENCY_MATRIX,
- "[{\"i\":1,\"n\":\"src/foo1\",\"q\":\"DIR\",\"v\":[{},{}]},{\"i\":2,\"n\":\"src/foo2\",\"q\":\"DIR\",\"v\":[{\"i\":51,\"w\":1},{}]}]"));
- }
-
- Measure isMeasureWithValue(Metric metric, Double value) {
- return argThat(new IsMeasureWithValue(metric, value));
- }
-
- Measure isMeasureWithValue(Metric metric, String data) {
- return argThat(new IsMeasureWithValue(metric, data));
- }
-
- class IsMeasureWithValue extends ArgumentMatcher<Measure> {
-
- private Metric metric;
- private Double value;
- private String data;
-
- public IsMeasureWithValue(Metric metric, Double value) {
- this.metric = metric;
- this.value = value;
- }
-
- public IsMeasureWithValue(Metric metric, String data) {
- this.metric = metric;
- this.data = data;
- }
-
- public boolean matches(Object m) {
- return ((Measure) m).getMetric().equals(metric) && ObjectUtils.equals(((Measure) m).getValue(), value) && ObjectUtils.equals(((Measure) m).getData(), data);
- }
- }
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java
index c16abe19c2d..bab64fa049b 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java
@@ -32,9 +32,7 @@ import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.resources.Directory;
import org.sonar.api.resources.File;
import org.sonar.api.resources.Java;
-import org.sonar.api.resources.Library;
import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Resource;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleFinder;
@@ -71,8 +69,7 @@ public class DefaultIndexTest {
DefaultProjectTree projectTree = mock(DefaultProjectTree.class);
ResourceCache resourceCache = new ResourceCache();
- index = new DefaultIndex(resourceCache, null, projectTree, metricFinder,
- mock(MeasureCache.class));
+ index = new DefaultIndex(resourceCache, projectTree, metricFinder, mock(MeasureCache.class));
baseDir = temp.newFolder();
project = new Project("project");
@@ -136,17 +133,6 @@ public class DefaultIndexTest {
}
@Test
- public void shouldIndexLibraryOutsideProjectTree() {
- Library lib = new Library("junit", "4.8");
- assertThat(index.index(lib)).isTrue();
-
- Library reference = new Library("junit", "4.8");
- assertThat(index.getResource(reference).getQualifier()).isEqualTo(Qualifiers.LIBRARY);
- assertThat(index.isIndexed(reference, true)).isTrue();
- assertThat(index.isExcluded(reference)).isFalse();
- }
-
- @Test
public void shouldNotIndexResourceIfParentNotIndexed() {
Directory directory = Directory.create("src/org/other");
File file = File.create("src/org/foo/Bar.java", null, false);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java
index 626037a043b..4ef7d6173e6 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java
@@ -32,7 +32,6 @@ import org.sonar.api.config.Settings;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.Directory;
import org.sonar.api.resources.File;
-import org.sonar.api.resources.Library;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.security.ResourcePermissions;
@@ -48,7 +47,6 @@ import javax.persistence.Query;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
-import java.util.Arrays;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@@ -108,7 +106,7 @@ public class ResourcePersisterTest extends AbstractDbUnitTestCase {
projectTree = mock(DefaultProjectTree.class);
permissions = mock(ResourcePermissions.class);
- persister = new ResourcePersister(projectTree, getSession(), permissions, resourceCache, mock(ScanGraph.class));
+ persister = new ResourcePersister(getSession(), permissions, resourceCache, mock(ScanGraph.class));
}
@Test
@@ -225,8 +223,7 @@ public class ResourcePersisterTest extends AbstractDbUnitTestCase {
when(projectTree.getProjectDefinition(moduleB)).thenReturn(ProjectDefinition.create().setBaseDir(new java.io.File(baseDir, "moduleB")));
when(projectTree.getProjectDefinition(moduleB1)).thenReturn(ProjectDefinition.create().setBaseDir(new java.io.File(baseDir, "moduleB/moduleB1")));
- DefaultIndex index = new DefaultIndex(resourceCache, null, projectTree, mock(MetricFinder.class),
- mock(MeasureCache.class));
+ DefaultIndex index = new DefaultIndex(resourceCache, projectTree, mock(MetricFinder.class), mock(MeasureCache.class));
index.start();
@@ -235,12 +232,9 @@ public class ResourcePersisterTest extends AbstractDbUnitTestCase {
index.setCurrentProject(moduleB1, null);
index.index(file);
- // Emulate another project having library dependency on moduleA
- index.addResource(new Library(moduleA.getKey(), "1.0"));
-
persister.persist();
- checkTables("shouldSaveNewMultiModulesProjectAndLibrary",
+ checkTables("shouldSaveNewMultiModulesProjectUsingIndex",
new String[] {"build_date", "created_at", "authorization_updated_at", "uuid", "project_uuid", "module_uuid", "module_uuid_path"}, "projects", "snapshots");
// Need to enable snapshot to make resource visible using ComponentMapper
@@ -324,33 +318,6 @@ public class ResourcePersisterTest extends AbstractDbUnitTestCase {
}
@Test
- public void shouldSaveNewLibrary() {
- setupData("shared");
-
- persister.persist(null, singleProject, null);
- persister.persistLibrary(singleProject.getAnalysisDate(), (Library) new Library("junit:junit", "4.8.2").setEffectiveKey("junit:junit"));
- persister.persistLibrary(singleProject.getAnalysisDate(), (Library) new Library("junit:junit", "4.8.2").setEffectiveKey("junit:junit"));// do
- // nothing,
- // already
- // saved
- persister.persistLibrary(singleProject.getAnalysisDate(), (Library) new Library("junit:junit", "3.2").setEffectiveKey("junit:junit"));
-
- checkTables("shouldSaveNewLibrary", new String[] {"build_date", "created_at", "authorization_updated_at", "uuid", "project_uuid", "module_uuid", "module_uuid_path"},
- "projects", "snapshots");
-
- // Need to enable snapshot to make resource visible using ComponentMapper
- enableSnapshot(1002);
- try (SqlSession session = getMyBatis().openSession(false)) {
- // FIXME selectByKey returns duplicates for libraries because of the join on snapshots table
- ComponentDto newLib = session.getMapper(ComponentMapper.class).selectByKeys(Arrays.asList("junit:junit")).get(0);
- assertThat(newLib.uuid()).isNotNull();
- assertThat(newLib.projectUuid()).isEqualTo(newLib.uuid());
- assertThat(newLib.moduleUuid()).isNull();
- assertThat(newLib.moduleUuidPath()).isEqualTo(MODULE_UUID_PATH_SEPARATOR + newLib.uuid() + MODULE_UUID_PATH_SEPARATOR);
- }
- }
-
- @Test
public void shouldUpdateExistingResource() {
setupData("shouldUpdateExistingResource");
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/dependency/DependencyMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/dependency/DependencyMediumTest.java
deleted file mode 100644
index e6e7e616555..00000000000
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/dependency/DependencyMediumTest.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * 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.mediumtest.dependency;
-
-import com.google.common.collect.ImmutableMap;
-import org.apache.commons.io.FileUtils;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.junit.rules.TestName;
-import org.sonar.batch.mediumtest.BatchMediumTester;
-import org.sonar.batch.mediumtest.TaskResult;
-import org.sonar.xoo.XooPlugin;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class DependencyMediumTest {
-
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
-
- @Rule
- public TestName testName = new TestName();
-
- public BatchMediumTester tester = BatchMediumTester.builder()
- .registerPlugin("xoo", new XooPlugin())
- .addDefaultQProfile("xoo", "Sonar Way")
- .build();
-
- @Before
- public void prepare() {
- tester.start();
- }
-
- @After
- public void stop() {
- tester.stop();
- }
-
- @Test
- public void populateDependenciesOnTempProject() throws IOException {
-
- File baseDir = temp.newFolder();
- File srcDir = new File(baseDir, "src");
- srcDir.mkdir();
-
- File xooFile = new File(srcDir, "sample.xoo");
- File xooFile2 = new File(srcDir, "sample2.xoo");
- File xooFile3 = new File(srcDir, "foo/sample3.xoo");
- File xooDepsFile = new File(srcDir, "sample.xoo.deps");
- FileUtils.write(xooFile, "Sample xoo\ncontent");
- FileUtils.write(xooFile2, "Sample xoo\ncontent");
- FileUtils.write(xooFile3, "Sample xoo\ncontent");
- FileUtils.write(xooDepsFile, "src/sample2.xoo:3\nsrc/foo/sample3.xoo:6");
-
- TaskResult result = tester.newTask()
- .properties(ImmutableMap.<String, String>builder()
- .put("sonar.task", "scan")
- .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
- .put("sonar.projectKey", "com.foo.project")
- .put("sonar.projectName", "Foo Project")
- .put("sonar.projectVersion", "1.0-SNAPSHOT")
- .put("sonar.projectDescription", "Description of Foo Project")
- .put("sonar.sources", "src")
- .build())
- .start();
-
- assertThat(result.fileDependencyFor(result.inputFile("src/sample.xoo"), result.inputFile("src/sample2.xoo")).getWeight()).isEqualTo(3);
- assertThat(result.fileDependencyFor(result.inputFile("src/sample.xoo"), result.inputFile("src/foo/sample3.xoo")).getWeight()).isEqualTo(6);
- }
-
- @Test
- public void manyDependenciesNoCycle() throws IOException {
-
- File baseDir = temp.newFolder();
- File srcDir = new File(baseDir, "src");
- srcDir.mkdir();
-
- int nbFiles = 100;
- for (int nb = 1; nb <= nbFiles; nb++) {
- File xooFile = new File(srcDir, "dir1/sample" + nb + ".xoo");
- FileUtils.write(xooFile, "foo");
- File xooFile2 = new File(srcDir, "dir2/sample" + nb + ".xoo");
- FileUtils.write(xooFile2, "foo");
- File xooDepFile = new File(srcDir, "dir1/sample" + nb + ".xoo.deps");
- for (int otherId = 1; otherId <= nbFiles; otherId++) {
- FileUtils.write(xooDepFile, "src/dir2/sample" + otherId + ".xoo:1\n", StandardCharsets.UTF_8, true);
- }
- }
-
- TaskResult result = tester.newTask()
- .properties(ImmutableMap.<String, String>builder()
- .put("sonar.task", "scan")
- .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
- .put("sonar.projectKey", "com.foo.project")
- .put("sonar.projectName", "Foo Project")
- .put("sonar.projectVersion", "1.0-SNAPSHOT")
- .put("sonar.projectDescription", "Description of Foo Project")
- .put("sonar.sources", "src")
- .build())
- .start();
-
- assertThat(result.fileDependencyFor(result.inputFile("src/dir1/sample1.xoo"), result.inputFile("src/dir2/sample1.xoo")).getWeight()).isEqualTo(1);
-
- }
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java
index 2ac9bab0fff..41bdd9c67df 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java
@@ -66,7 +66,7 @@ public class MeasuresMediumTest {
.newScanTask(new File(projectDir, "sonar-project.properties"))
.start();
- assertThat(result.allMeasures()).hasSize(79);
+ assertThat(result.allMeasures()).hasSize(61);
}
@Test
@@ -93,7 +93,7 @@ public class MeasuresMediumTest {
.build())
.start();
- assertThat(result.allMeasures()).hasSize(37);
+ assertThat(result.allMeasures()).hasSize(25);
assertThat(result.allMeasures()).contains(new DefaultMeasure<Integer>()
.forMetric(CoreMetrics.LINES)
diff --git a/sonar-batch/src/test/java/org/sonar/batch/phases/DecoratorsExecutorTest.java b/sonar-batch/src/test/java/org/sonar/batch/phases/DecoratorsExecutorTest.java
index 6ee9a66aab3..e296e3aff78 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/phases/DecoratorsExecutorTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/phases/DecoratorsExecutorTest.java
@@ -31,7 +31,6 @@ import org.sonar.api.resources.Resource;
import org.sonar.api.utils.SonarException;
import org.sonar.batch.bootstrap.BatchExtensionDictionnary;
import org.sonar.batch.deprecated.decorator.DefaultDecoratorContext;
-import org.sonar.batch.duplication.DuplicationCache;
import org.sonar.batch.events.EventBus;
import org.sonar.batch.scan.measure.MeasureCache;
import org.sonar.batch.sensor.coverage.CoverageExclusions;
@@ -68,7 +67,7 @@ public class DecoratorsExecutorTest {
doThrow(new SonarException()).when(decorator).decorate(any(Resource.class), any(DecoratorContext.class));
DecoratorsExecutor executor = new DecoratorsExecutor(mock(BatchExtensionDictionnary.class), new Project("key"), mock(SonarIndex.class),
- mock(EventBus.class), mock(CoverageExclusions.class), mock(MeasureCache.class), mock(MetricFinder.class), mock(DuplicationCache.class), mock(AnalysisMode.class));
+ mock(EventBus.class), mock(CoverageExclusions.class), mock(MeasureCache.class), mock(MetricFinder.class), mock(AnalysisMode.class));
try {
executor.executeDecorator(decorator, mock(DefaultDecoratorContext.class), File.create("src/org/foo/Bar.java", null, false));
fail("Exception has not been thrown");
diff --git a/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorStorageTest.java b/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorStorageTest.java
index 2ebab61ace3..e3135e79a34 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorStorageTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorStorageTest.java
@@ -27,7 +27,6 @@ import org.junit.rules.TemporaryFolder;
import org.mockito.ArgumentCaptor;
import org.sonar.api.batch.fs.InputDir;
import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.InputFile.Type;
import org.sonar.api.batch.fs.internal.DefaultFileSystem;
import org.sonar.api.batch.fs.internal.DefaultInputDir;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
@@ -35,15 +34,12 @@ import org.sonar.api.batch.measure.MetricFinder;
import org.sonar.api.batch.rule.ActiveRules;
import org.sonar.api.batch.rule.Severity;
import org.sonar.api.batch.rule.internal.ActiveRulesBuilder;
-import org.sonar.api.batch.sensor.dependency.internal.DefaultDependency;
import org.sonar.api.batch.sensor.issue.internal.DefaultIssue;
import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure;
import org.sonar.api.config.Settings;
-import org.sonar.api.design.Dependency;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
import org.sonar.api.measures.PersistenceMode;
-import org.sonar.api.resources.Directory;
import org.sonar.api.resources.File;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
@@ -59,7 +55,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -236,106 +231,4 @@ public class DefaultSensorStorageTest {
assertThat(issue.effortToFix()).isEqualTo(10.0);
}
- @Test
- public void shouldStoreDependencyInSameFolder() {
-
- Resource foo = File.create("src/Foo.java").setEffectiveKey("foo:src/Foo.java");
- Resource bar = File.create("src/Bar.java").setEffectiveKey("foo:src/Bar.java");
- resourceCache.add(foo, null);
- resourceCache.add(bar, null);
-
- sensorStorage.store(new DefaultDependency()
- .from(new DefaultInputFile("foo", "src/Foo.java").setType(Type.MAIN))
- .to(new DefaultInputFile("foo", "src/Bar.java").setType(Type.MAIN))
- .weight(3));
-
- ArgumentCaptor<Dependency> argumentCaptor = ArgumentCaptor.forClass(Dependency.class);
-
- verify(sonarIndex).addDependency(argumentCaptor.capture());
- assertThat(argumentCaptor.getValue().getFrom()).isEqualTo(foo);
- assertThat(argumentCaptor.getValue().getTo()).isEqualTo(bar);
- assertThat(argumentCaptor.getValue().getWeight()).isEqualTo(3);
- assertThat(argumentCaptor.getValue().getUsage()).isEqualTo("USES");
- }
-
- @Test
- public void throw_if_attempt_to_save_same_dep_twice() {
-
- Resource foo = File.create("src/Foo.java").setEffectiveKey("foo:src/Foo.java");
- Resource bar = File.create("src/Bar.java").setEffectiveKey("foo:src/Bar.java");
- resourceCache.add(foo, null);
- resourceCache.add(bar, null);
-
- when(sonarIndex.getEdge(foo, bar)).thenReturn(new Dependency(foo, bar));
-
- thrown.expect(IllegalStateException.class);
- thrown.expectMessage("Dependency between foo:src/Foo.java and foo:src/Bar.java was already saved.");
-
- sensorStorage.store(new DefaultDependency()
- .from(new DefaultInputFile("foo", "src/Foo.java").setType(Type.MAIN))
- .to(new DefaultInputFile("foo", "src/Bar.java").setType(Type.MAIN))
- .weight(3));
- }
-
- @Test
- public void shouldStoreDependencyInDifferentFolder() {
-
- Resource foo = File.create("src1/Foo.java").setEffectiveKey("foo:src1/Foo.java");
- Resource bar = File.create("src2/Bar.java").setEffectiveKey("foo:src2/Bar.java");
- resourceCache.add(foo, null);
- resourceCache.add(bar, null);
-
- sensorStorage.store(new DefaultDependency()
- .from(new DefaultInputFile("foo", "src1/Foo.java").setType(Type.MAIN))
- .to(new DefaultInputFile("foo", "src2/Bar.java").setType(Type.MAIN))
- .weight(3));
-
- ArgumentCaptor<Dependency> argumentCaptor = ArgumentCaptor.forClass(Dependency.class);
-
- verify(sonarIndex, times(2)).addDependency(argumentCaptor.capture());
- assertThat(argumentCaptor.getAllValues()).hasSize(2);
- Dependency value1 = argumentCaptor.getAllValues().get(0);
- assertThat(value1.getFrom()).isEqualTo(Directory.create("src1"));
- assertThat(value1.getTo()).isEqualTo(Directory.create("src2"));
- assertThat(value1.getWeight()).isEqualTo(1);
- assertThat(value1.getUsage()).isEqualTo("USES");
-
- Dependency value2 = argumentCaptor.getAllValues().get(1);
- assertThat(value2.getFrom()).isEqualTo(foo);
- assertThat(value2.getTo()).isEqualTo(bar);
- assertThat(value2.getWeight()).isEqualTo(3);
- assertThat(value2.getUsage()).isEqualTo("USES");
- }
-
- @Test
- public void shouldIncrementParentWeight() {
-
- Resource src1 = Directory.create("src1").setEffectiveKey("foo:src1");
- Resource src2 = Directory.create("src2").setEffectiveKey("foo:src2");
- Resource foo = File.create("src1/Foo.java").setEffectiveKey("foo:src1/Foo.java");
- Resource bar = File.create("src2/Bar.java").setEffectiveKey("foo:src2/Bar.java");
- resourceCache.add(src1, null);
- resourceCache.add(src2, null);
- resourceCache.add(foo, src1);
- resourceCache.add(bar, src2);
- Dependency parentDep = new Dependency(src1, src2).setWeight(4);
- when(sonarIndex.getEdge(src1, src2)).thenReturn(parentDep);
-
- sensorStorage.store(new DefaultDependency()
- .from(new DefaultInputFile("foo", "src1/Foo.java").setType(Type.MAIN))
- .to(new DefaultInputFile("foo", "src2/Bar.java").setType(Type.MAIN))
- .weight(3));
-
- ArgumentCaptor<Dependency> argumentCaptor = ArgumentCaptor.forClass(Dependency.class);
-
- verify(sonarIndex).addDependency(argumentCaptor.capture());
-
- assertThat(parentDep.getWeight()).isEqualTo(5);
-
- Dependency value = argumentCaptor.getValue();
- assertThat(value.getFrom()).isEqualTo(foo);
- assertThat(value.getTo()).isEqualTo(bar);
- assertThat(value.getWeight()).isEqualTo(3);
- assertThat(value.getUsage()).isEqualTo("USES");
- }
}
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewLibrary-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewLibrary-result.xml
deleted file mode 100644
index 1fa430d877b..00000000000
--- a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewLibrary-result.xml
+++ /dev/null
@@ -1,34 +0,0 @@
-<dataset>
-
- <!-- other project -->
- <projects id="1000" scope="PRJ" qualifier="TRK" kee="my:key" root_id="[null]" uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="[null]"
- name="Other project" long_name="Other" description="[null]"
- enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="my:key" />
-
- <snapshots purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="3000" project_id="1000" parent_snapshot_id="[null]" root_project_id="1000" root_snapshot_id="[null]"
- scope="PRJ" qualifier="TRK" created_at="1225544280000" build_date="1225544280000" version="[null]" path=""
- status="P" islast="false" depth="0" />
-
-
- <!-- new project -->
- <projects id="1001" scope="PRJ" qualifier="TRK" kee="foo" root_id="[null]" project_uuid="[null]" module_uuid="[null]" module_uuid_path="[null]"
- name="Foo" long_name="Foo" description="some description"
- enabled="true" language="[null]" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="foo" />
-
- <projects id="1002" scope="PRJ" qualifier="LIB" kee="junit:junit" root_id="[null]" project_uuid="[null]" module_uuid="[null]" module_uuid_path="[null]"
- name="junit:junit" long_name="junit:junit" description="[null]"
- enabled="true" language="[null]" copy_resource_id="[null]" person_id="[null]" deprecated_kee="[null]" />
-
- <snapshots purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="3001" project_id="1001" parent_snapshot_id="[null]" root_project_id="1001" root_snapshot_id="[null]"
- scope="PRJ" qualifier="TRK" created_at="1293231600000" build_date="1293231600000" version="[null]" path=""
- status="U" islast="false" depth="0" />
-
- <snapshots purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="3002" project_id="1002" parent_snapshot_id="[null]" root_project_id="1002" root_snapshot_id="[null]"
- scope="PRJ" qualifier="LIB" created_at="1293231600000" build_date="1293231600000" version="4.8.2" path=""
- status="P" islast="false" depth="0" />
-
- <snapshots purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="3003" project_id="1002" parent_snapshot_id="[null]" root_project_id="1002" root_snapshot_id="[null]"
- scope="PRJ" qualifier="LIB" created_at="1293231600000" build_date="1293231600000" version="3.2" path=""
- status="P" islast="false" depth="0" />
-
-</dataset>
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProjectAndLibrary-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProjectUsingIndex-result.xml
index f475284edcb..9fa0dd09762 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProjectAndLibrary-result.xml
+++ b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProjectUsingIndex-result.xml
@@ -58,8 +58,4 @@
scope="FIL" qualifier="FIL" created_at="1293231600000" build_date="1293231600000" version="[null]" path="3001.3003.3004.3005."
status="U" islast="false" depth="4" />
- <snapshots purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="3007" project_id="1002" parent_snapshot_id="[null]" root_project_id="1002" root_snapshot_id="[null]"
- scope="PRJ" qualifier="LIB" created_at="1293231600000" build_date="1293231600000" version="1.0" path=""
- status="P" islast="false" depth="0" />
-
</dataset>
diff --git a/sonar-core/pom.xml b/sonar-core/pom.xml
index cc7a1f934db..a2037dc6ebc 100644
--- a/sonar-core/pom.xml
+++ b/sonar-core/pom.xml
@@ -103,6 +103,10 @@
</exclusion>
</exclusions>
</dependency>
+ <dependency>
+ <groupId>org.codehaus.sonar</groupId>
+ <artifactId>sonar-graph</artifactId>
+ </dependency>
<!-- logging -->
<dependency>
diff --git a/sonar-core/src/main/resources/META-INF/persistence.xml b/sonar-core/src/main/resources/META-INF/persistence.xml
index c4fe7406836..42388ef66e3 100644
--- a/sonar-core/src/main/resources/META-INF/persistence.xml
+++ b/sonar-core/src/main/resources/META-INF/persistence.xml
@@ -12,7 +12,6 @@
<class>org.sonar.api.database.model.User</class>
<class>org.sonar.api.database.model.Snapshot</class>
<class>org.sonar.api.database.model.MeasureModel</class>
- <class>org.sonar.api.design.DependencyDto</class>
<class>org.sonar.api.measures.Metric</class>
<class>org.sonar.api.database.model.ResourceModel</class>
<class>org.sonar.api.rules.Rule</class>
diff --git a/sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java b/sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java
index 3e52e829af4..37fd8d45777 100644
--- a/sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java
@@ -23,7 +23,6 @@ import org.junit.Test;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.resources.Directory;
-import org.sonar.api.resources.Library;
import org.sonar.api.resources.Project;
import static org.assertj.core.api.Assertions.assertThat;
@@ -38,9 +37,6 @@ public class ComponentKeysTest {
Directory dir = Directory.create("src/org/foo");
assertThat(ComponentKeys.createEffectiveKey(project, dir)).isEqualTo("my_project:src/org/foo");
- Library library = new Library("junit:junit", "4.7");
- assertThat(ComponentKeys.createEffectiveKey(project, library)).isEqualTo("junit:junit");
-
InputFile file = new DefaultInputFile("foo", "foo/Bar.php");
assertThat(ComponentKeys.createEffectiveKey("my_project", file)).isEqualTo("my_project:foo/Bar.php");
}
diff --git a/sonar-deprecated/pom.xml b/sonar-deprecated/pom.xml
index d6d933204ac..5ba175213bd 100644
--- a/sonar-deprecated/pom.xml
+++ b/sonar-deprecated/pom.xml
@@ -24,7 +24,6 @@
<scope>provided</scope>
</dependency>
-
<!-- unit test -->
<dependency>
<groupId>org.codehaus.sonar</groupId>
diff --git a/sonar-graph/pom.xml b/sonar-graph/pom.xml
deleted file mode 100644
index 1acc1c390be..00000000000
--- a/sonar-graph/pom.xml
+++ /dev/null
@@ -1,47 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.codehaus.sonar</groupId>
- <artifactId>sonar</artifactId>
- <version>5.2-SNAPSHOT</version>
- <relativePath>..</relativePath>
- </parent>
- <artifactId>sonar-graph</artifactId>
- <packaging>jar</packaging>
- <name>SonarQube :: Graph</name>
-
- <dependencies>
- <dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- </dependency>
- <dependency>
- <groupId>com.google.guava</groupId>
- <artifactId>guava</artifactId>
- </dependency>
- <dependency>
- <groupId>com.google.code.findbugs</groupId>
- <artifactId>jsr305</artifactId>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
- <groupId>org.codehaus.sonar</groupId>
- <artifactId>sonar-testing-harness</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <skipTests>${skipBatchTests}</skipTests>
- </configuration>
- </plugin>
- </plugins>
- </build>
-</project>
diff --git a/sonar-graph/src/main/java/org/sonar/graph/Cycle.java b/sonar-graph/src/main/java/org/sonar/graph/Cycle.java
deleted file mode 100644
index d0134492f67..00000000000
--- a/sonar-graph/src/main/java/org/sonar/graph/Cycle.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * 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.graph;
-
-import java.util.List;
-
-public class Cycle {
-
- private Edge[] edges;
- private int hashcode = 0;
-
- public Cycle(List<Edge> edges) {
- this.edges = edges.toArray(new Edge[edges.size()]);
- for(Edge edge : edges) {
- hashcode += edge.hashCode();
- }
- }
-
- public int size() {
- return edges.length;
- }
-
- public boolean contains(Edge e) {
- for (Edge edge : edges) {
- if (edge.equals(e)) {
- return true;
- }
- }
- return false;
- }
-
- public Edge[] getEdges() {
- return edges;
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder("Cycle with " + size() + " edges : ");
- for (Edge edge : edges) {
- builder.append(edge.getFrom()).append(" -> ");
- }
- return builder.toString();
- }
-
- @Override
- public int hashCode() {
- return hashcode;
- }
-
- @Override
- public boolean equals(Object object) {
- if (object instanceof Cycle) {
- Cycle otherCycle = (Cycle) object;
- if (otherCycle.hashcode == hashcode && otherCycle.edges.length == edges.length) {
- mainLoop: for (Edge otherEdge : otherCycle.edges) {
- for (Edge edge : edges) {
- if (otherEdge.equals(edge)) {
- continue mainLoop;
- }
- }
- return false;
- }
- return true;
- }
- }
- return false;
- }
-}
diff --git a/sonar-graph/src/main/java/org/sonar/graph/CycleDetector.java b/sonar-graph/src/main/java/org/sonar/graph/CycleDetector.java
deleted file mode 100644
index 49a9b4c9f60..00000000000
--- a/sonar-graph/src/main/java/org/sonar/graph/CycleDetector.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * 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.graph;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Set;
-
-public class CycleDetector<V> {
-
- private Set<V> vertices;
- private DirectedGraphAccessor<V, ? extends Edge> graph;
- private Set<V> analyzedVertices;
- private Set<Cycle> cycles = new LinkedHashSet<>();
- private Set<Edge> edgesToExclude;
- private long searchCyclesCalls = 0;
- private int maxSearchDepth = -1;
- private boolean maxSearchDepthActivated = false;
- private int maxCyclesToFound = Integer.MAX_VALUE;
-
- public CycleDetector(DirectedGraphAccessor<V, ? extends Edge> graph, Collection<V> vertices) {
- init(graph, vertices, new LinkedHashSet<Edge>());
- }
-
- public CycleDetector(DirectedGraphAccessor<V, ? extends Edge> graph, Collection<V> vertices, Set<Edge> edgesToExclude) {
- init(graph, vertices, edgesToExclude);
- }
-
- public CycleDetector(DirectedGraphAccessor<V, ? extends Edge> graph) {
- init(graph, graph.getVertices(), new LinkedHashSet<Edge>());
- }
-
- public CycleDetector(DirectedGraphAccessor<V, ? extends Edge> graph, Set<Edge> edgesToExclude) {
- init(graph, graph.getVertices(), edgesToExclude);
- }
-
- private void init(DirectedGraphAccessor<V, ? extends Edge> graph, Collection<V> vertices, Set<Edge> edgesToExclude) {
- this.graph = graph;
- this.vertices = new LinkedHashSet<>(vertices);
- this.analyzedVertices = new LinkedHashSet<>();
- this.edgesToExclude = edgesToExclude;
- }
-
- public Set<Cycle> detectCycles() {
- run();
- return getCycles();
- }
-
- public Set<Cycle> detectCyclesWithUpperLimit(int maxCyclesToFound) {
- this.maxCyclesToFound = maxCyclesToFound;
- run();
- return getCycles();
- }
-
- public Set<Cycle> detectCyclesWithMaxSearchDepth(int maxSearchDepth) {
- if (maxSearchDepth > 1) {
- maxSearchDepthActivated = true;
- this.maxSearchDepth = maxSearchDepth;
- }
- run();
- return getCycles();
- }
-
- private void run() {
- if (!cycles.isEmpty()) {
- throw new IllegalStateException("Cycle detection can't be executed twice on the same CycleDetector object.");
- }
- try {
- for (V vertex : vertices) {
- if (maxSearchDepthActivated || !analyzedVertices.contains(vertex)) {
- Set<V> tmpAnalyzedVertices = new LinkedHashSet<>();
- searchCycles(vertex, new ArrayList<V>(), tmpAnalyzedVertices);
- analyzedVertices.addAll(tmpAnalyzedVertices);
- }
- }
- } catch (MaximumCyclesToFoundException e) {
- // ignore
- }
- }
-
- private void searchCycles(V fromVertex, List<V> path, Set<V> tmpAnalyzedVertices) {
- searchCyclesCalls++;
- path.add(fromVertex);
- tmpAnalyzedVertices.add(fromVertex);
- for (Edge<V> edge : graph.getOutgoingEdges(fromVertex)) {
- V toVertex = edge.getTo();
- if (!edgesToExclude.contains(edge) && vertices.contains(toVertex)
- && (maxSearchDepthActivated || !analyzedVertices.contains(toVertex))) {
- if (path.contains(toVertex)) {
- path.add(toVertex);
- List<V> cyclePath = path.subList(path.indexOf(toVertex), path.size());
- Cycle cycle = convertListOfVerticesToCycle(cyclePath);
- cycles.add(cycle);
-
- if (cycles.size() >= maxCyclesToFound) {
- throw new MaximumCyclesToFoundException();
- }
- path.remove(path.size() - 1);
- } else if (!maxSearchDepthActivated || (maxSearchDepthActivated && path.size() < maxSearchDepth)) {
- searchCycles(toVertex, path, tmpAnalyzedVertices);
- }
- }
- }
- path.remove(path.size() - 1);
- }
-
- private Cycle convertListOfVerticesToCycle(List<V> vertices) {
- List<Edge> edges = new ArrayList<>();
- V firstVertex = vertices.get(0);
- V from = firstVertex;
- for (int index = 1; index < vertices.size(); index++) {
- V to = vertices.get(index);
- edges.add(graph.getEdge(from, to));
- from = to;
- }
- return new Cycle(edges);
- }
-
- public Set<Cycle> getCycles() {
- return cycles;
- }
-
- public boolean isAcyclicGraph() {
- return cycles.isEmpty();
- }
-
- public long getSearchCyclesCalls() {
- return searchCyclesCalls;
- }
-
-}
-
-class MaximumCyclesToFoundException extends RuntimeException {
-}
diff --git a/sonar-graph/src/main/java/org/sonar/graph/DirectedGraph.java b/sonar-graph/src/main/java/org/sonar/graph/DirectedGraph.java
deleted file mode 100644
index 9dab7d83b5f..00000000000
--- a/sonar-graph/src/main/java/org/sonar/graph/DirectedGraph.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * 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.graph;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-public class DirectedGraph<V, E extends Edge<V>> implements DirectedGraphAccessor<V, E> {
-
- private EdgeFactory<V, E> edgeFactory;
- private Map<V, Map<V, E>> outgoingEdgesByVertex = new HashMap<>();
- private Map<V, Map<V, E>> incomingEdgesByVertex = new HashMap<>();
- private Set<V> vertices = new LinkedHashSet<>();
-
- public DirectedGraph() {
- }
-
- public DirectedGraph(EdgeFactory<V, E> edgeFactory) {
- this.edgeFactory = edgeFactory;
- }
-
- public static DirectedGraph<String, StringEdge> createStringDirectedGraph() {
- return new DirectedGraph<>(new StringEdgeFactory());
- }
-
- public DirectedGraph<V, E> addEdge(V from, V to) {
- checkEdgeFacory();
- E edge = edgeFactory.createEdge(from, to);
- return addEdge(edge);
- }
-
- public DirectedGraph<V, E> addEdge(V from, V to, int weight) {
- checkEdgeFacory();
- E edge = edgeFactory.createEdge(from, to, weight);
- return addEdge(edge);
- }
-
- private void checkEdgeFacory() {
- if (edgeFactory == null) {
- throw new IllegalStateException(
- "EdgeFactory<V, E> has not been defined. Please use the 'public E addEdge(V from, V to, E edge)' method.");
- }
- }
-
- public DirectedGraph<V, E> addEdge(E edge) {
- addEdgeToMap(edge.getFrom(), edge.getTo(), edge, outgoingEdgesByVertex);
- addEdgeToMap(edge.getTo(), edge.getFrom(), edge, incomingEdgesByVertex);
- vertices.add(edge.getFrom());
- vertices.add(edge.getTo());
- return this;
- }
-
- private void addEdgeToMap(V vertexKey1, V vertexKey2, E edge, Map<V, Map<V, E>> edgesByVertex) {
- Map<V, E> edges = edgesByVertex.get(vertexKey1);
- if (edges == null) {
- edges = new HashMap<>();
- edgesByVertex.put(vertexKey1, edges);
- }
- if (edges.containsKey(vertexKey2)) {
- throw new IllegalStateException("The graph already contains the edge : " + edge);
- }
- edges.put(vertexKey2, edge);
- }
-
- @Override
- public E getEdge(V from, V to) {
- Map<V, E> outgoingEdgesFrom = outgoingEdgesByVertex.get(from);
- if (outgoingEdgesFrom == null) {
- return null;
- } else {
- return outgoingEdgesFrom.get(to);
- }
- }
-
- @Override
- public boolean hasEdge(V from, V to) {
- Map<V, E> outgoingEdges = outgoingEdgesByVertex.get(from);
- if (outgoingEdges == null) {
- return false;
- }
- return outgoingEdges.containsKey(to);
- }
-
- public void addVertex(V vertex) {
- vertices.add(vertex);
- }
-
- public void addVertices(Collection<V> vertices) {
- for (V vertex : vertices) {
- addVertex(vertex);
- }
- }
-
- @Override
- public Set<V> getVertices() {
- return vertices;
- }
-
- public List<E> getEdges(Collection<V> vertices) {
- List<E> result = new ArrayList<>();
- for (V vertice : vertices) {
- Collection<E> outgoingEdges = getOutgoingEdges(vertice);
- if (outgoingEdges != null) {
- result.addAll(outgoingEdges);
- }
- }
- return result;
- }
-
- @Override
- public Collection<E> getOutgoingEdges(V from) {
- Map<V, E> outgoingEdges = outgoingEdgesByVertex.get(from);
- if (outgoingEdges == null) {
- return new LinkedHashSet<>();
- }
- return outgoingEdges.values();
- }
-
- @Override
- public Collection<E> getIncomingEdges(V to) {
- Map<V, E> incomingEdges = incomingEdgesByVertex.get(to);
- if (incomingEdges == null) {
- return new LinkedHashSet<>();
- }
- return incomingEdges.values();
- }
-}
diff --git a/sonar-graph/src/main/java/org/sonar/graph/DirectedGraphAccessor.java b/sonar-graph/src/main/java/org/sonar/graph/DirectedGraphAccessor.java
deleted file mode 100644
index 4e4c453db85..00000000000
--- a/sonar-graph/src/main/java/org/sonar/graph/DirectedGraphAccessor.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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.graph;
-
-import java.util.Collection;
-import java.util.Set;
-
-public interface DirectedGraphAccessor<V, E extends Edge<V>> {
-
- E getEdge(V from, V to);
-
- boolean hasEdge(V from, V to);
-
- Set<V> getVertices();
-
- Collection<E> getOutgoingEdges(V from);
-
- Collection<E> getIncomingEdges(V to);
-}
diff --git a/sonar-graph/src/main/java/org/sonar/graph/Dsm.java b/sonar-graph/src/main/java/org/sonar/graph/Dsm.java
deleted file mode 100644
index 811cad56e3e..00000000000
--- a/sonar-graph/src/main/java/org/sonar/graph/Dsm.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * 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.graph;
-
-import javax.annotation.CheckForNull;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Set;
-
-public class Dsm<V> {
-
- private final V[] vertices;
- private final DsmCell[][] cells;
- private final int dimension;
- private final DirectedGraphAccessor<V, ? extends Edge<V>> graph;
-
- public Dsm(DirectedGraphAccessor<V, ? extends Edge<V>> graph, Collection<V> vertices, Set<Edge> feedbackEdges) {
- this.graph = graph;
- this.dimension = vertices.size();
- this.vertices = initVertices(vertices);
- this.cells = initCells(feedbackEdges);
- }
-
- public Dsm(DirectedGraphAccessor<V, ? extends Edge<V>> acyclicGraph, Set<Edge> feedbackEdges) {
- this(acyclicGraph, acyclicGraph.getVertices(), feedbackEdges);
- }
-
- public Dsm(DirectedGraphAccessor<V, ? extends Edge<V>> acyclicGraph) {
- this(acyclicGraph, acyclicGraph.getVertices(), Collections.<Edge>emptySet());
- }
-
- private DsmCell[][] initCells(Set<Edge> feedbackEdges) {
- DsmCell[][] result = new DsmCell[dimension][dimension];
- for (int x = 0; x < dimension; x++) {
- for (int y = 0; y < dimension; y++) {
- V from = vertices[x];
- V to = vertices[y];
-
- Edge<V> edge = graph.getEdge(from, to);
- if (edge != null) {
- boolean isFeedbackEdge = feedbackEdges.contains(edge);
- result[x][y] = new DsmCell(edge, isFeedbackEdge);
- }
- }
- }
- return result;
- }
-
- private V[] initVertices(Collection<V> verticesCol) {
- V[] result = (V[]) new Object[dimension];
- int i = 0;
- for (V vertex : verticesCol) {
- result[i] = vertex;
- i++;
- }
- return result;
- }
-
- public V getVertex(int rowIndex) {
- return vertices[rowIndex];
- }
-
- public int getDimension() {
- return dimension;
- }
-
- public void permute(int fromIndex, int toIndex) {
- if (fromIndex != toIndex) {
- checkIndicesBoudaries(fromIndex, toIndex);
- permuteVertice(fromIndex, toIndex);
- permuteColumns(fromIndex, toIndex);
- permuteRows(fromIndex, toIndex);
- }
- }
-
- private void checkIndicesBoudaries(int... indices) {
- for (int index : indices) {
- if (index < 0 || index >= dimension) {
- StringBuilder builder = new StringBuilder("DSM contains the following vertices : ");
- for (V vertex : vertices) {
- builder.append(vertex.toString()).append(" | ");
- }
- builder.append(". Trying to reach index ").append(index);
- throw new ArrayIndexOutOfBoundsException(builder.toString());
- }
- }
- }
-
- private void permuteVertice(int fromIndex, int toIndex) {
- V fromVertex = vertices[fromIndex];
- V toVertex = vertices[toIndex];
- vertices[fromIndex] = toVertex;
- vertices[toIndex] = fromVertex;
- }
-
- private void permuteRows(int fromYIndex, int toYIndex) {
- for (int x = 0; x < dimension; x++) {
- permuteCells(x, fromYIndex, x, toYIndex);
- }
- }
-
- private void permuteColumns(int fromXIndex, int toXIndex) {
- for (int y = 0; y < dimension; y++) {
- permuteCells(fromXIndex, y, toXIndex, y);
- }
- }
-
- private void permuteCells(int fromXIndex, int fromYIndex, int toXIndex, int toYIndex) {
- DsmCell fromCell = cells[fromXIndex][fromYIndex];
- DsmCell toCell = cells[toXIndex][toYIndex];
- cells[toXIndex][toYIndex] = fromCell;
- cells[fromXIndex][fromYIndex] = toCell;
- }
-
- public int getNumberOfIncomingEdges(int y, int from, int to) {
- int incomingEdges = 0;
- for (int x = from; x <= to; x++) {
- DsmCell cell = cells[x][y];
- if (cell != null && cell.getWeight() != 0 && !cell.isFeedbackEdge()) {
- incomingEdges++;
- }
- }
- return incomingEdges;
- }
-
- public int getNumberOfOutgoingEdges(int x, int from, int to) {
- int outgoingEdges = 0;
- for (int y = from; y <= to; y++) {
- DsmCell cell = cells[x][y];
- if (cell != null && cell.getWeight() != 0 && !cell.isFeedbackEdge()) {
- outgoingEdges++;
- }
- }
- return outgoingEdges;
- }
-
- /**
- * @deprecated since 5.0 use {@link #cell(int, int)}
- */
- @Deprecated
- public DsmCell getCell(int x, int y) {
- DsmCell cell = cells[x][y];
- return cell != null ? cell : new DsmCell(null, false);
- }
-
- /**
- * @since 5.0
- */
- @CheckForNull
- public DsmCell cell(int x, int y) {
- return cells[x][y];
- }
-
- public V[] getVertices() {
- V[] verticesCopy = (V[]) new Object[vertices.length];
- System.arraycopy(vertices, 0, verticesCopy, 0, vertices.length);
- return verticesCopy;
- }
-}
diff --git a/sonar-graph/src/main/java/org/sonar/graph/DsmCell.java b/sonar-graph/src/main/java/org/sonar/graph/DsmCell.java
deleted file mode 100644
index 88729bff2bc..00000000000
--- a/sonar-graph/src/main/java/org/sonar/graph/DsmCell.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.graph;
-
-import javax.annotation.Nullable;
-
-public class DsmCell {
-
- private final Edge edge;
- private final boolean feedbackEdge;
-
- public DsmCell(@Nullable Edge edge, boolean isFeedbackEdge) {
- this.feedbackEdge = isFeedbackEdge;
- this.edge = edge;
- }
-
- public int getWeight() {
- return (edge==null) ? 0 : edge.getWeight();
- }
-
- public boolean isFeedbackEdge() {
- return feedbackEdge;
- }
-
- /**
- * @return nullable edge
- */
- public Edge getEdge() {
- return edge;
- }
-}
diff --git a/sonar-graph/src/main/java/org/sonar/graph/DsmManualSorter.java b/sonar-graph/src/main/java/org/sonar/graph/DsmManualSorter.java
deleted file mode 100644
index 685dfbe348e..00000000000
--- a/sonar-graph/src/main/java/org/sonar/graph/DsmManualSorter.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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.graph;
-
-import java.util.Arrays;
-import java.util.List;
-
-
-public final class DsmManualSorter<V> {
-
- private final Dsm<V> dsm;
- private final List<V> verticesInDesiredOrder;
-
- private DsmManualSorter(Dsm<V> dsm, List<V> verticesInDesiredOrder) {
- this.dsm = dsm;
- this.verticesInDesiredOrder = verticesInDesiredOrder;
- }
-
- public static <V> void sort(Dsm<V> dsm, List<V> vertices) {
- DsmManualSorter<V> sorter = new DsmManualSorter<>(dsm, vertices);
- sorter.sort();
- }
-
- public static <V> void sort(Dsm<V> dsm, V... vertices) {
- sort(dsm, Arrays.asList(vertices));
- }
-
- private void sort() {
- for (int desiredIndex = 0; desiredIndex < verticesInDesiredOrder.size(); desiredIndex++) {
- int currentIndex = getCurrentIndex(verticesInDesiredOrder.get(desiredIndex));
- dsm.permute(currentIndex, desiredIndex);
- }
- }
-
- private int getCurrentIndex(V v) {
- for (int currentIndex = 0; currentIndex < dsm.getVertices().length; currentIndex++) {
- if (dsm.getVertices()[currentIndex].equals(v)) {
- return currentIndex;
- }
- }
- throw new IllegalStateException("Vertex " + v + " is not contained in the DSM.");
- }
-
-}
diff --git a/sonar-graph/src/main/java/org/sonar/graph/DsmPrinter.java b/sonar-graph/src/main/java/org/sonar/graph/DsmPrinter.java
deleted file mode 100644
index 5cdbd694829..00000000000
--- a/sonar-graph/src/main/java/org/sonar/graph/DsmPrinter.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * 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.graph;
-
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
-
-public final class DsmPrinter {
-
- private final Writer writer;
- private final Dsm dsm;
- private static final String CELL_SEPARATOR = "| ";
- private static final String FEEDBACK_EDGE_FLAG = "*";
- private final boolean displayColumnHeaders;
-
- private DsmPrinter(Writer writer, Dsm dsm, boolean displayColumnHeaders) {
- this.writer = writer;
- this.dsm = dsm;
- this.displayColumnHeaders = displayColumnHeaders;
- }
-
- private void print() {
- try {
- if (displayColumnHeaders) {
- printColumnHeaders();
- }
- for (int y = 0; y < dsm.getDimension(); y++) {
- printRow(y);
- }
- writer.flush();
-
- } catch (IOException e) {
- throw new RuntimeException("Unable to print the desired DSM.", e); // NOSONAR
- }
- }
-
- public static String print(Dsm dsm, boolean displayColumnHeaders) {
- StringWriter writer = new StringWriter();
- print(writer, dsm, displayColumnHeaders);
- return writer.toString();
- }
-
- public static String print(Dsm dsm) {
- return print(dsm, true);
- }
-
- public static void print(Writer writer, Dsm dsm, boolean displayColumnHeaders) {
- DsmPrinter printer = new DsmPrinter(writer, dsm, displayColumnHeaders);
- printer.print();
- }
-
- private void printRow(int y) throws IOException {
- printRowHeader(y);
- for (int x = 0; x < dsm.getDimension(); x++) {
- printCell(y, x);
- }
- writer.append((char) Character.LINE_SEPARATOR);
- }
-
- private void printCell(int y, int x) throws IOException {
- DsmCell cell = dsm.cell(x, y);
- if (cell == null || cell.getWeight() == 0) {
- writer.append(" ");
- } else {
- writer.append("").append(String.valueOf(cell.getWeight()));
- }
- if (cell != null && cell.isFeedbackEdge()) {
- writer.append(FEEDBACK_EDGE_FLAG);
- } else {
- writer.append(' ');
- }
- writer.append(CELL_SEPARATOR);
- }
-
- private void printRowHeader(int y) throws IOException {
- writer.append(String.valueOf(dsm.getVertex(y))).append(" " + CELL_SEPARATOR);
- }
-
- private void printColumnHeaders() throws IOException {
- writer.append(" " + CELL_SEPARATOR);
- for (int i = 0; i < dsm.getDimension(); i++) {
- printRowHeader(i);
- }
- writer.append((char) Character.LINE_SEPARATOR);
- }
-
-}
diff --git a/sonar-graph/src/main/java/org/sonar/graph/DsmScanner.java b/sonar-graph/src/main/java/org/sonar/graph/DsmScanner.java
deleted file mode 100644
index 268edcc1b84..00000000000
--- a/sonar-graph/src/main/java/org/sonar/graph/DsmScanner.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * 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.graph;
-
-import org.apache.commons.lang.ArrayUtils;
-
-import java.io.IOException;
-import java.io.LineNumberReader;
-import java.io.Reader;
-import java.io.StringReader;
-import java.util.Arrays;
-import java.util.LinkedHashSet;
-import java.util.Set;
-
-public final class DsmScanner {
-
- private final LineNumberReader reader;
- private static final String CELL_SEPARATOR = "|";
- private static final char FEEDBACK_EDGE_FLAG = '*';
- private final DirectedGraph<String, StringEdge> graph = DirectedGraph.createStringDirectedGraph();
- private String[] vertices;
- private Set<Edge> feedbackEdges = new LinkedHashSet<>();
-
- private DsmScanner(Reader reader) {
- this.reader = new LineNumberReader(reader);
- }
-
- private Dsm<String> scan() {
- try {
- readColumnHeadersAndcreateDsmBuilder();
- for (int i = 0; i < vertices.length; i++) {
- readRow(i);
- }
- } catch (IOException e) {
- throw new RuntimeException("Unable to read DSM content.", e); // NOSONAR
- }
- Dsm<String> dsm = new Dsm<>(graph, graph.getVertices(), feedbackEdges);
- DsmManualSorter.sort(dsm, Arrays.asList(vertices));
- return dsm;
- }
-
- private void readRow(int i) throws IOException {
- String[] tokens = splitLine(reader.readLine());
- for (int j = 1; j < tokens.length - 1; j++) {
- int toVertexIndex = j - 1;
- int weight = extractWeight(tokens[j]);
- if (i != toVertexIndex) {
- StringEdge edge = new StringEdge(vertices[toVertexIndex], vertices[i], weight);
- if (isFeedbackEdge(tokens[j])) {
- feedbackEdges.add(edge);
- }
- graph.addEdge(edge);
- }
- }
- }
-
- private boolean isFeedbackEdge(String cellContent) {
- return cellContent.indexOf(FEEDBACK_EDGE_FLAG) != -1;
- }
-
- private int extractWeight(String stringContent) {
- try {
- return Integer.valueOf(stringContent.replace(FEEDBACK_EDGE_FLAG, ' ').trim());
- } catch (NumberFormatException e) {
- return 0;
- }
- }
-
- private void readColumnHeadersAndcreateDsmBuilder() throws IOException {
- String[] tokens = splitLine(reader.readLine());
- if (tokens != null) {
- vertices = new String[tokens.length - 2];
- System.arraycopy(tokens, 1, vertices, 0, tokens.length - 2);
- graph.addVertices(Arrays.asList(vertices));
- }
- }
-
- private String[] splitLine(String line) {
- if (line == null) {
- return ArrayUtils.EMPTY_STRING_ARRAY;
- }
- String[] tokens = line.split("\\" + CELL_SEPARATOR);
- String[] result = new String[tokens.length];
- for (int i = 0; i < tokens.length; i++) {
- result[i] = tokens[i].trim();
- }
- return result;
- }
-
- public static Dsm<String> scan(String textDsm) {
- StringReader reader = new StringReader(textDsm);
- return scan(reader);
- }
-
- public static Dsm<String> scan(Reader dsmReader) {
- DsmScanner scanner = new DsmScanner(dsmReader);
- return scanner.scan();
- }
-}
diff --git a/sonar-graph/src/main/java/org/sonar/graph/DsmTopologicalSorter.java b/sonar-graph/src/main/java/org/sonar/graph/DsmTopologicalSorter.java
deleted file mode 100644
index a55ec749fd8..00000000000
--- a/sonar-graph/src/main/java/org/sonar/graph/DsmTopologicalSorter.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * 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.graph;
-
-public final class DsmTopologicalSorter<V> {
-
- private final Dsm<V> dsm;
- private int leftOrderedIndex;
- private int rightOrderedIndex;
-
- private DsmTopologicalSorter(Dsm<V> dsm) {
- this.dsm = dsm;
- leftOrderedIndex = 0;
- rightOrderedIndex = dsm.getDimension() - 1;
- }
-
- public static <V> void sort(Dsm<V> dsm) {
- DsmTopologicalSorter<V> partitionner = new DsmTopologicalSorter<>(dsm);
- boolean dsmCanBeSorted = true;
- while (dsmCanBeSorted) {
- boolean dsmCanBeSortedOnLeft = partitionner.pushToLeftVerticesWithoutIncomingEdges();
- boolean dsmCanBeSortedOnRight = partitionner.pushToRightVerticesWithoutOutgointEdges();
- dsmCanBeSorted = dsmCanBeSortedOnLeft || dsmCanBeSortedOnRight;
- }
- boolean isCyclicGraph = partitionner.leftOrderedIndex < partitionner.rightOrderedIndex;
- if (isCyclicGraph) {
- throw new IllegalStateException("Can't sort a cyclic graph.");
- }
- }
-
- private boolean pushToLeftVerticesWithoutIncomingEdges() {
- boolean permutationsDone = false;
- for (int i = leftOrderedIndex; i <= rightOrderedIndex; i++) {
- if (dsm.getNumberOfIncomingEdges(i, leftOrderedIndex, rightOrderedIndex) == 0) {
- dsm.permute(i, leftOrderedIndex);
- leftOrderedIndex++;
- permutationsDone = true;
- }
- }
- return permutationsDone;
- }
-
- private boolean pushToRightVerticesWithoutOutgointEdges() {
- boolean permutationsDone = false;
- for (int i = leftOrderedIndex; i <= rightOrderedIndex; i++) {
- if (dsm.getNumberOfOutgoingEdges(i, leftOrderedIndex, rightOrderedIndex) == 0) {
- dsm.permute(i, rightOrderedIndex);
- rightOrderedIndex--;
- permutationsDone = true;
- }
- }
- return permutationsDone;
- }
-}
diff --git a/sonar-graph/src/main/java/org/sonar/graph/Edge.java b/sonar-graph/src/main/java/org/sonar/graph/Edge.java
deleted file mode 100644
index 93ea29cb55b..00000000000
--- a/sonar-graph/src/main/java/org/sonar/graph/Edge.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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.graph;
-
-public interface Edge<V> {
-
- int getWeight();
-
- V getFrom();
-
- V getTo();
-
-}
diff --git a/sonar-graph/src/main/java/org/sonar/graph/EdgeFactory.java b/sonar-graph/src/main/java/org/sonar/graph/EdgeFactory.java
deleted file mode 100644
index 93a4229ed8e..00000000000
--- a/sonar-graph/src/main/java/org/sonar/graph/EdgeFactory.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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.graph;
-
-public interface EdgeFactory<V, E> {
-
- E createEdge(V from, V to);
-
- E createEdge(V from, V to, int weigth);
-}
diff --git a/sonar-graph/src/main/java/org/sonar/graph/FeedbackCycle.java b/sonar-graph/src/main/java/org/sonar/graph/FeedbackCycle.java
deleted file mode 100644
index 30822911df2..00000000000
--- a/sonar-graph/src/main/java/org/sonar/graph/FeedbackCycle.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * 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.graph;
-
-import com.google.common.collect.LinkedHashMultiset;
-import com.google.common.collect.Multiset;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-/**
- * Note: this class has a natural ordering that is inconsistent with equals
- */
-public final class FeedbackCycle implements Iterable<FeedbackEdge>, Comparable<FeedbackCycle> {
-
- private List<FeedbackEdge> orderedFeedbackEdges;
- private int totalOccurrencesOfEdgesInCycle;
- private final Cycle cycle;
-
- private FeedbackCycle(Cycle cycle) {
- orderedFeedbackEdges = new ArrayList<>();
- totalOccurrencesOfEdgesInCycle = 0;
- this.cycle = cycle;
- }
-
- private void add(FeedbackEdge feedbackEdge) {
- orderedFeedbackEdges.add(feedbackEdge);
- }
-
- public static List<FeedbackCycle> buildFeedbackCycles(Set<Cycle> cycles) {
- Multiset<Edge> edgesBag = createBagWithAllEdgesOfCycles(cycles);
-
- List<FeedbackCycle> feedbackCycles = new ArrayList<>();
- for (Cycle cycle : cycles) {
- FeedbackCycle feedbackCycle = new FeedbackCycle(cycle);
- int totalOccurrences = 0;
- for (Edge edge : cycle.getEdges()) {
- FeedbackEdge feedbackEdge = new FeedbackEdge(edge, edgesBag.count(edge));
- feedbackCycle.add(feedbackEdge);
- totalOccurrences += feedbackEdge.getOccurences();
- }
- feedbackCycle.setTotalOccurrencesOfEdgesInCycle(totalOccurrences);
- Collections.sort(feedbackCycle.orderedFeedbackEdges);
- feedbackCycles.add(feedbackCycle);
- }
- Collections.sort(feedbackCycles);
-
- return feedbackCycles;
- }
-
- private static Multiset<Edge> createBagWithAllEdgesOfCycles(Set<Cycle> cycles) {
- Multiset<Edge> edgesBag = LinkedHashMultiset.create();
- for (Cycle cycle : cycles) {
- for (Edge edge : cycle.getEdges()) {
- edgesBag.add(edge);
- }
- }
- return edgesBag;
- }
-
- private void setTotalOccurrencesOfEdgesInCycle(int totalOccurrencesOfEdgesInCycle) {
- this.totalOccurrencesOfEdgesInCycle = totalOccurrencesOfEdgesInCycle;
- }
-
- public int getTotalOccurrencesOfEdgesInCycle() {
- return totalOccurrencesOfEdgesInCycle;
- }
-
- @Override
- public Iterator<FeedbackEdge> iterator() {
- return orderedFeedbackEdges.iterator();
- }
-
- @Override
- public int compareTo(FeedbackCycle feedbackCycle) {
- if (getTotalOccurrencesOfEdgesInCycle() < feedbackCycle.getTotalOccurrencesOfEdgesInCycle()) {// NOSONAR this class has a natural
- // ordering that is inconsistent with
- // equals
- return -1;
- }
- if (getTotalOccurrencesOfEdgesInCycle() == feedbackCycle.getTotalOccurrencesOfEdgesInCycle()) {
- if (cycle.size() == feedbackCycle.cycle.size()) {
- return orderedFeedbackEdges.get(0).compareTo(feedbackCycle.orderedFeedbackEdges.get(0));
- }
- return cycle.size() - feedbackCycle.cycle.size();
- }
- return 1;
- }
-
- public Cycle getCycle() {
- return cycle;
- }
-}
diff --git a/sonar-graph/src/main/java/org/sonar/graph/FeedbackEdge.java b/sonar-graph/src/main/java/org/sonar/graph/FeedbackEdge.java
deleted file mode 100644
index 6e24a466058..00000000000
--- a/sonar-graph/src/main/java/org/sonar/graph/FeedbackEdge.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * 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.graph;
-
-import org.apache.commons.lang.math.NumberUtils;
-
-public class FeedbackEdge implements Comparable<FeedbackEdge> {
-
- private Edge edge;
- private double relativeWeight;
- private int occurences;
- private final int hashcode;
-
- public FeedbackEdge(Edge edge, int occurences) {
- this.edge = edge;
- this.hashcode = edge.hashCode();
- this.occurences = occurences;
- this.relativeWeight = (double) edge.getWeight() / occurences;
- }
-
- protected Edge getEdge() {
- return edge;
- }
-
- protected int getWeight() {
- return edge.getWeight();
- }
-
- protected double getRelativeWeight() {
- return relativeWeight;
- }
-
- protected int getOccurences() {
- return occurences;
- }
-
- @Override
- public int compareTo(FeedbackEdge feedbackEdge) {
- if (this.getRelativeWeight() < feedbackEdge.getRelativeWeight()) {
- return -1;
- }
- if (NumberUtils.compare(this.getRelativeWeight(), feedbackEdge.getRelativeWeight())==0) {
- return this.getEdge().getFrom().toString().compareTo(feedbackEdge.getEdge().getFrom().toString());
- }
- return 1;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (!(obj instanceof FeedbackEdge) || this.hashCode() != obj.hashCode()) {
- return false;
- }
- FeedbackEdge otherEdge = (FeedbackEdge) obj;
- return edge.equals(otherEdge.edge);
- }
-
- @Override
- public int hashCode() {
- return hashcode;
- }
-}
diff --git a/sonar-graph/src/main/java/org/sonar/graph/IncrementalCyclesAndFESSolver.java b/sonar-graph/src/main/java/org/sonar/graph/IncrementalCyclesAndFESSolver.java
deleted file mode 100644
index 4e8bda55c77..00000000000
--- a/sonar-graph/src/main/java/org/sonar/graph/IncrementalCyclesAndFESSolver.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * 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.graph;
-
-import java.util.Collection;
-import java.util.LinkedHashSet;
-import java.util.Set;
-
-public class IncrementalCyclesAndFESSolver<V> {
-
- private Set<Cycle> cycles = new LinkedHashSet<>();
- private long searchCyclesCalls = 0;
- private static final int DEFAULT_MAX_SEARCH_DEPTH_AT_FIRST = 3;
- private static final int DEFAULT_MAX_CYCLES_TO_FOUND_BY_ITERATION = 100;
- private MinimumFeedbackEdgeSetSolver solver;
- private int iterations = 0;
-
- public IncrementalCyclesAndFESSolver(DirectedGraphAccessor<V, ? extends Edge> graph, Collection<V> vertices) {
- this(graph, vertices, DEFAULT_MAX_SEARCH_DEPTH_AT_FIRST, DEFAULT_MAX_CYCLES_TO_FOUND_BY_ITERATION);
- }
-
- public IncrementalCyclesAndFESSolver(DirectedGraphAccessor<V, ? extends Edge> graph, Collection<V> vertices, int maxSearchDepthAtFirst,
- int maxCyclesToFoundByIteration) {
-
- iterations++;
- CycleDetector<V> cycleDetector = new CycleDetector<>(graph, vertices);
- cycleDetector.detectCyclesWithMaxSearchDepth(maxSearchDepthAtFirst);
- searchCyclesCalls += cycleDetector.getSearchCyclesCalls();
- cycles.addAll(cycleDetector.getCycles());
- solver = new MinimumFeedbackEdgeSetSolver(cycles);
- Set<Edge> edgesToExclude = solver.getEdges();
-
- do {
- iterations++;
- cycleDetector = new CycleDetector<>(graph, vertices, edgesToExclude);
- cycleDetector.detectCyclesWithUpperLimit(maxCyclesToFoundByIteration);
- searchCyclesCalls += cycleDetector.getSearchCyclesCalls();
- cycles.addAll(cycleDetector.getCycles());
- solver = new MinimumFeedbackEdgeSetSolver(cycles);
- edgesToExclude = solver.getEdges();
- } while (!cycleDetector.getCycles().isEmpty());
- }
-
- public int getWeightOfFeedbackEdgeSet() {
- return solver.getWeightOfFeedbackEdgeSet();
- }
-
- public int getNumberOfLoops() {
- return solver.getNumberOfLoops();
- }
-
- public Set<Edge> getFeedbackEdgeSet() {
- return solver.getEdges();
- }
-
- public Set<Cycle> getCycles() {
- return cycles;
- }
-
- public boolean isAcyclicGraph() {
- return cycles.isEmpty();
- }
-
- public long getSearchCyclesCalls() {
- return searchCyclesCalls;
- }
-
- public int getIterations() {
- return iterations;
- }
-}
diff --git a/sonar-graph/src/main/java/org/sonar/graph/MinimumFeedbackEdgeSetSolver.java b/sonar-graph/src/main/java/org/sonar/graph/MinimumFeedbackEdgeSetSolver.java
deleted file mode 100644
index 6f9ec3b1ce1..00000000000
--- a/sonar-graph/src/main/java/org/sonar/graph/MinimumFeedbackEdgeSetSolver.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * 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.graph;
-
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Set;
-
-public class MinimumFeedbackEdgeSetSolver {
-
- private final List<FeedbackCycle> feedbackCycles;
- private Set<FeedbackEdge> feedbackEdges;
- private int minimumFeedbackEdgesWeight = Integer.MAX_VALUE;
- private final int cyclesNumber;
- private final int maxNumberCyclesForSearchingMinimumFeedback;
- private static final int DEFAULT_MAXIMUM_NUMBER_OF_LOOPS = 1000000;
- private static final int MAXIMUM_NUMBER_OF_CYCLE_THAT_CAN_BE_HANDLED = 1500;
- private final int maximumNumberOfLoops;
-
- public int getNumberOfLoops() {
- return numberOfLoops;
- }
-
- private int numberOfLoops = 0;
-
- public MinimumFeedbackEdgeSetSolver(Set<Cycle> cycles, int maxCycles) {
- this(cycles, DEFAULT_MAXIMUM_NUMBER_OF_LOOPS, maxCycles);
- }
-
- public MinimumFeedbackEdgeSetSolver(Set<Cycle> cycles) {
- this(cycles, DEFAULT_MAXIMUM_NUMBER_OF_LOOPS, MAXIMUM_NUMBER_OF_CYCLE_THAT_CAN_BE_HANDLED);
- }
-
- public MinimumFeedbackEdgeSetSolver(Set<Cycle> cycles, int maximumNumberOfLoops, int maxNumberCyclesForSearchingMinimumFeedback) {
- this.maximumNumberOfLoops = maximumNumberOfLoops;
- this.feedbackCycles = FeedbackCycle.buildFeedbackCycles(cycles);
- this.cyclesNumber = cycles.size();
- this.maxNumberCyclesForSearchingMinimumFeedback = maxNumberCyclesForSearchingMinimumFeedback;
- this.run();
- }
-
- public int getWeightOfFeedbackEdgeSet() {
- return minimumFeedbackEdgesWeight;
- }
-
- /**
- * Get edges tagged as feedback.
- */
- public Set<Edge> getEdges() {
- Set<Edge> edges = new LinkedHashSet<>();
- for (FeedbackEdge fe : feedbackEdges) {
- edges.add(fe.getEdge());
- }
- return edges;
- }
-
- private void run() {
- Set<FeedbackEdge> pendingFeedbackEdges = new LinkedHashSet<>();
- if (cyclesNumber < maxNumberCyclesForSearchingMinimumFeedback) {
- searchFeedbackEdges(0, 0, pendingFeedbackEdges);
- } else {
- lightResearchForFeedbackEdges();
- }
- }
-
- private void lightResearchForFeedbackEdges() {
- feedbackEdges = new LinkedHashSet<>();
- for (FeedbackCycle cycle : feedbackCycles) {
- for (FeedbackEdge edge : cycle) {
- feedbackEdges.add(edge);
- break;
- }
- }
- minimumFeedbackEdgesWeight = 0;
- for (FeedbackEdge edge : feedbackEdges) {
- minimumFeedbackEdgesWeight += edge.getWeight();
- }
- }
-
- private void searchFeedbackEdges(int level, int pendingWeight, Set<FeedbackEdge> pendingFeedbackEdges) {
- if (numberOfLoops++ > maximumNumberOfLoops) {
- return;
- }
-
- if (pendingWeight >= minimumFeedbackEdgesWeight) {
- return;
- }
-
- if (level == cyclesNumber) {
- minimumFeedbackEdgesWeight = pendingWeight;
- feedbackEdges = new LinkedHashSet<>(pendingFeedbackEdges);
- return;
- }
-
- FeedbackCycle feedbackCycle = feedbackCycles.get(level);
-
- if (doesFeedbackEdgesContainAnEdgeOfTheCycle(pendingFeedbackEdges, feedbackCycle)) {
- searchFeedbackEdges(level + 1, pendingWeight, pendingFeedbackEdges);
- } else {
- boolean hasAnEdgeWithOccurrenceOfOneBeenUsed = false;
- for (FeedbackEdge feedbackEdge : feedbackCycle) {
- if (feedbackEdge.getOccurences() == 1) {
- if (hasAnEdgeWithOccurrenceOfOneBeenUsed) {
- continue;
- } else {
- hasAnEdgeWithOccurrenceOfOneBeenUsed = true;
- }
- }
- int edgeWeight = addNewEdge(feedbackEdge, pendingFeedbackEdges);
- pendingWeight += edgeWeight;
-
- searchFeedbackEdges(level + 1, pendingWeight, pendingFeedbackEdges);
- pendingWeight -= edgeWeight;
- pendingFeedbackEdges.remove(feedbackEdge);
- }
- }
- }
-
- private boolean doesFeedbackEdgesContainAnEdgeOfTheCycle(Set<FeedbackEdge> pendingFeedbackEdges, FeedbackCycle cycle) {
- boolean contains = false;
- for (FeedbackEdge feedbackEdge : cycle) {
- if (pendingFeedbackEdges.contains(feedbackEdge)) {
- contains = true;
- break;
- }
- }
- return contains;
- }
-
- private int addNewEdge(FeedbackEdge feedbackEdge, Set<FeedbackEdge> pendingFeedbackEdges) {
- pendingFeedbackEdges.add(feedbackEdge);
- return feedbackEdge.getWeight();
- }
-}
diff --git a/sonar-graph/src/main/java/org/sonar/graph/StringEdge.java b/sonar-graph/src/main/java/org/sonar/graph/StringEdge.java
deleted file mode 100644
index c5aa7bb1844..00000000000
--- a/sonar-graph/src/main/java/org/sonar/graph/StringEdge.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * 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.graph;
-
-import org.apache.commons.lang.builder.ToStringBuilder;
-
-public class StringEdge implements Edge<String> {
-
- private final String from;
- private final String to;
- private int weight;
-
- public StringEdge(String from, String to) {
- this.from = from;
- this.to = to;
- this.weight = 1;
- }
-
- public StringEdge(String from, String to, int weight) {
- this(from, to);
- this.weight = weight;
- }
-
- @Override
- public String getFrom() {
- return from;
- }
-
- @Override
- public String getTo() {
- return to;
- }
-
- @Override
- public int getWeight() {
- return weight;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (!(obj instanceof StringEdge)) {
- return false;
- }
- StringEdge edge = (StringEdge) obj;
- return from.equals(edge.from) && to.equals(edge.to);
- }
-
- @Override
- public int hashCode() {
- return 3*from.hashCode() + to.hashCode(); //NOSONAR Magic number 3 is suitable here
- }
-
- @Override
- public String toString() {
- return new ToStringBuilder(this).append("from", from).append("to", to).toString();
- }
-}
diff --git a/sonar-graph/src/main/java/org/sonar/graph/StringEdgeFactory.java b/sonar-graph/src/main/java/org/sonar/graph/StringEdgeFactory.java
deleted file mode 100644
index a7dd4dee50c..00000000000
--- a/sonar-graph/src/main/java/org/sonar/graph/StringEdgeFactory.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.graph;
-
-public class StringEdgeFactory implements EdgeFactory<String, StringEdge> {
-
- @Override
- public StringEdge createEdge(String from, String to) {
- return new StringEdge(from, to);
- }
-
- @Override
- public StringEdge createEdge(String from, String to, int weight) {
- return new StringEdge(from, to, weight);
- }
-}
diff --git a/sonar-graph/src/main/java/org/sonar/graph/package-info.java b/sonar-graph/src/main/java/org/sonar/graph/package-info.java
deleted file mode 100644
index e1f395aea51..00000000000
--- a/sonar-graph/src/main/java/org/sonar/graph/package-info.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * 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.
- */
-
-@ParametersAreNonnullByDefault
-package org.sonar.graph;
-
-import javax.annotation.ParametersAreNonnullByDefault;
-
diff --git a/sonar-graph/src/test/java/org/sonar/graph/CycleDetectorTest.java b/sonar-graph/src/test/java/org/sonar/graph/CycleDetectorTest.java
deleted file mode 100644
index 244ae9f6ada..00000000000
--- a/sonar-graph/src/test/java/org/sonar/graph/CycleDetectorTest.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * 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.graph;
-
-import org.junit.Test;
-
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class CycleDetectorTest {
-
- @Test
- public void testIsAcyclicGraph() {
- DirectedGraph<String, StringEdge> dag = DirectedGraph.createStringDirectedGraph();
- dag.addEdge("A", "B").addEdge("B", "C").addEdge("C", "D");
- dag.addEdge("B", "D");
- dag.addEdge("A", "D");
-
- CycleDetector<String> cycleDetector = new CycleDetector<>(dag);
- cycleDetector.detectCycles();
- assertThat(cycleDetector.isAcyclicGraph()).isTrue();
- }
-
- @Test
- public void testIsNotAcyclicGraph() {
- DirectedGraph<String, StringEdge> dcg = DirectedGraph.createStringDirectedGraph();
- dcg.addEdge("A", "B").addEdge("B", "C").addEdge("C", "A");
-
- CycleDetector<String> cycleDetector = new CycleDetector<>(dcg);
- cycleDetector.detectCycles();
- assertThat(cycleDetector.isAcyclicGraph()).isFalse();
- }
-
- @Test
- public void testGetCyclesWithMultipleCycles() {
- DirectedGraph<String, StringEdge> dcg = DirectedGraph.createStringDirectedGraph();
- dcg.addEdge("A", "B").addEdge("B", "C").addEdge("C", "D").addEdge("D", "A");
- dcg.addEdge("C", "A");
- dcg.addEdge("B", "A");
- dcg.addEdge("A", "E").addEdge("E", "C");
- dcg.addEdge("E", "D");
- dcg.addEdge("E", "F");
- dcg.addEdge("F", "C");
-
- CycleDetector<String> cycleDetector = new CycleDetector<>(dcg);
- cycleDetector.detectCycles();
- assertThat(cycleDetector.getCycles()).hasSize(8);
- assertThat(cycleDetector.getSearchCyclesCalls()).isEqualTo(11);
- }
-
- @Test
- public void testMaxSearchDepthOption() {
- DirectedGraph<String, StringEdge> dcg = DirectedGraph.createStringDirectedGraph();
- dcg.addEdge("A", "B").addEdge("B", "C").addEdge("C", "D").addEdge("D", "A");
- dcg.addEdge("C", "A");
- dcg.addEdge("B", "A");
-
- CycleDetector<String> cycleDetector = new CycleDetector<>(dcg);
- cycleDetector.detectCyclesWithMaxSearchDepth(3);
- assertThat(cycleDetector.getCycles()).hasSize(2);
-
- cycleDetector = new CycleDetector<>(dcg);
- cycleDetector.detectCyclesWithMaxSearchDepth(2);
- assertThat(cycleDetector.getCycles()).hasSize(1);
- }
-
- @Test
- public void testExcludeEdgesFromSearch() {
- DirectedGraph<String, StringEdge> dcg = DirectedGraph.createStringDirectedGraph();
- dcg.addEdge("A", "B").addEdge("B", "C").addEdge("C", "D").addEdge("D", "A");
- dcg.addEdge("C", "A");
- dcg.addEdge("B", "A");
-
- Set<Edge> excludedEdges = new HashSet<>();
- excludedEdges.add(dcg.getEdge("C", "A"));
- excludedEdges.add(dcg.getEdge("B", "A"));
-
- CycleDetector<String> cycleDetector = new CycleDetector<>(dcg, excludedEdges);
- cycleDetector.detectCycles();
- assertThat(cycleDetector.getCycles()).hasSize(1);
- }
-
- @Test
- public void testGetCyclesWithOneCycle() {
- DirectedGraph<String, StringEdge> dcg = DirectedGraph.createStringDirectedGraph();
- dcg.addEdge("A", "B").addEdge("B", "C").addEdge("C", "D").addEdge("D", "E");
- dcg.addEdge("B", "A");
-
- CycleDetector<String> cycleDetector = new CycleDetector<>(dcg);
- cycleDetector.detectCycles();
- assertThat(cycleDetector.getCycles()).hasSize(1);
- Cycle cycle = cycleDetector.getCycles().iterator().next();
- assertThat(cycle.size()).isEqualTo(2);
- assertThat(cycle.contains(new StringEdge("A", "B"))).isTrue();
- assertThat(cycle.contains(new StringEdge("B", "A"))).isTrue();
- }
-
- @Test
- public void getCyclesInLimitedSetOfVertices() {
- DirectedGraph<String, StringEdge> dcg = DirectedGraph.createStringDirectedGraph();
- dcg.addEdge("A", "B").addEdge("B", "C").addEdge("C", "A");
-
- // C must not be used to find cycles
- CycleDetector<String> cycleDetector = new CycleDetector<>(dcg, Arrays.asList("A", "B"));
- cycleDetector.detectCycles();
- assertThat(cycleDetector.getCycles()).isEmpty();
-
- // C is used to find cycles
- cycleDetector = new CycleDetector<>(dcg, Arrays.asList("A", "B", "C"));
- cycleDetector.detectCycles();
- assertThat(cycleDetector.getCycles().size()).isEqualTo(1);
- }
-
- @Test(expected = IllegalStateException.class)
- public void testExecutingTwoCycleDetectionsOnSameObject() {
- DirectedGraph<String, StringEdge> dcg = DirectedGraph.createStringDirectedGraph();
- dcg.addEdge("A", "B").addEdge("B", "C").addEdge("C", "A");
-
- CycleDetector<String> cycleDetector = new CycleDetector<>(dcg);
- cycleDetector.detectCycles();
- cycleDetector.detectCycles();
- }
-
- @Test
- public void testDetectCyclesWithUpperLimit() {
- DirectedGraph<String, StringEdge> dcg = DirectedGraph.createStringDirectedGraph();
- dcg.addEdge("A", "B").addEdge("B", "C").addEdge("C", "D").addEdge("D", "A");
- dcg.addEdge("B", "A");
-
- CycleDetector<String> cycleDetector = new CycleDetector<>(dcg);
- assertThat(cycleDetector.detectCyclesWithUpperLimit(1)).hasSize(1);
- }
-}
diff --git a/sonar-graph/src/test/java/org/sonar/graph/CycleTest.java b/sonar-graph/src/test/java/org/sonar/graph/CycleTest.java
deleted file mode 100644
index b90e0cc32e0..00000000000
--- a/sonar-graph/src/test/java/org/sonar/graph/CycleTest.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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.graph;
-
-import org.junit.Test;
-
-import java.util.Arrays;
-import java.util.List;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class CycleTest {
- static List<Edge> AB_BA = list(new StringEdge("A", "B"), new StringEdge("B", "A"));
- static List<Edge> BA_AB = list(new StringEdge("B", "A"), new StringEdge("A", "B"));
- static List<Edge> AB_BC_CA = list(new StringEdge("A", "B"), new StringEdge("B", "C"), new StringEdge("C", "A"));
- static List<Edge> HI_IJ_JH = list(new StringEdge("H", "I"), new StringEdge("I", "J"), new StringEdge("J", "H"));
- static List<Edge> AB_BC_CD_DA = list(new StringEdge("A", "B"), new StringEdge("B", "C"), new StringEdge("C", "D"), new StringEdge("D", "A"));
- static List<Edge> BC_CD_DA_AB = list(new StringEdge("B", "C"), new StringEdge("C", "D"), new StringEdge("D", "A"), new StringEdge("A", "B"));
-
- @Test
- public void testHashCode() {
- assertThat(new Cycle(AB_BA).hashCode()).isEqualTo(new Cycle(BA_AB).hashCode());
- assertThat(new Cycle(BC_CD_DA_AB).hashCode()).isEqualTo(new Cycle(AB_BC_CD_DA).hashCode());
- assertThat(new Cycle(AB_BA).hashCode()).isNotEqualTo(new Cycle(AB_BC_CA).hashCode());
- }
-
- @Test
- public void testContains() {
- assertThat(new Cycle(AB_BC_CD_DA).contains(new StringEdge("B", "C"))).isTrue();
- }
-
- @Test
- public void testEqualsObject() {
- assertThat(new Cycle(AB_BA)).isEqualTo(new Cycle(BA_AB));
- assertThat(new Cycle(BC_CD_DA_AB)).isEqualTo(new Cycle(AB_BC_CD_DA));
- }
-
- @Test
- public void testNotEqualsObject() {
- assertThat(new Cycle(BC_CD_DA_AB)).isNotEqualTo(new Cycle(AB_BA));
- assertThat(new Cycle(AB_BC_CA)).isNotEqualTo(new Cycle(HI_IJ_JH));
- }
-
- static List<Edge> list(StringEdge... edges) {
- return Arrays.<Edge> asList(edges);
- }
-}
diff --git a/sonar-graph/src/test/java/org/sonar/graph/DirectedGraphTest.java b/sonar-graph/src/test/java/org/sonar/graph/DirectedGraphTest.java
deleted file mode 100644
index fac53692e1a..00000000000
--- a/sonar-graph/src/test/java/org/sonar/graph/DirectedGraphTest.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * 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.graph;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.graph.DirectedGraph;
-import org.sonar.graph.StringEdge;
-
-import java.util.Arrays;
-
-import static org.hamcrest.Matchers.*;
-import static org.junit.Assert.*;
-
-public class DirectedGraphTest {
-
- private DirectedGraph<String, StringEdge> graph;
-
- @Before
- public void init() {
- graph = DirectedGraph.createStringDirectedGraph();
- graph.addEdge("A", "B");
- graph.addEdge("A", "C");
- graph.addEdge("B", "C");
- }
-
- @Test
- public void testGetVertices() {
- assertThat(graph.getVertices(), hasItems("A", "B"));
- assertThat(graph.getVertices().size(), is(3));
- }
-
- @Test
- public void testGetEdge() {
- assertNull(graph.getEdge("A", "T"));
- graph.addEdge("A", "T", 5);
- assertThat(graph.getEdge("A", "T").getWeight(), is(5));
- }
-
- @Test(expected = IllegalStateException.class)
- public void testAddEdgeThrowsException() {
- graph.addEdge("B", "C");
- }
-
- @Test
- public void testAddEdgeWithWeight() {
- graph.addEdge("D", "B", 4);
- assertThat(graph.getOutgoingEdges("D").iterator().next().getWeight(), is(4));
- }
-
- @Test
- public void testGetOutgoingEdges() {
- assertThat(graph.getOutgoingEdges("A"), hasItem(new StringEdge("A", "B")));
- assertThat(graph.getOutgoingEdges("A").size(), is(2));
- assertThat(graph.getOutgoingEdges("B"), hasItem(new StringEdge("B", "C")));
- }
-
- @Test
- public void testGetIncomingEdges() {
- assertThat(graph.getIncomingEdges("C"), hasItem(new StringEdge("A", "C")));
- assertThat(graph.getIncomingEdges("A").size(), is(0));
- }
-
- @Test
- public void testGetEdges() {
- assertTrue(graph.getEdges(Arrays.asList("A")).containsAll(Arrays.asList(new StringEdge("A", "B"), new StringEdge("A", "C"))));
- assertTrue(graph.getEdges(Arrays.asList("A", "B")).containsAll(Arrays.asList(new StringEdge("A", "B"), new StringEdge("A", "C"), new StringEdge("B", "C"))));
- }
-
- @Test
- public void testHasEdge() {
- assertTrue(graph.hasEdge("A", "B"));
- assertFalse(graph.hasEdge("C", "A"));
- }
-
- @Test
- public void testAddVertex() {
- graph.addVertex("X");
- assertThat(graph.getVertices(), hasItem("X"));
- assertThat(graph.getOutgoingEdges("X").size(), is(0));
- }
-
- @Test
- public void testAddVertices() {
- String[] vertices = { "X", "Y", "Z" };
- graph.addVertices(Arrays.asList(vertices));
- assertThat(graph.getVertices(), hasItems("X", "Y", "Z"));
- }
-}
diff --git a/sonar-graph/src/test/java/org/sonar/graph/DsmManualSorterTest.java b/sonar-graph/src/test/java/org/sonar/graph/DsmManualSorterTest.java
deleted file mode 100644
index 7735dd510c5..00000000000
--- a/sonar-graph/src/test/java/org/sonar/graph/DsmManualSorterTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.graph;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-public class DsmManualSorterTest {
-
- @Test
- public void testSort() {
- DirectedGraph<String, StringEdge> graph = DirectedGraph.createStringDirectedGraph();
- graph.addEdge("A", "B", 2);
- graph.addEdge("A", "C", 3);
- graph.addEdge("C", "B", 1);
- Dsm<String> dsm = new Dsm<>(graph);
- DsmManualSorter.sort(dsm, "B", "A", "C");
-
- StringPrintWriter expectedDsm = new StringPrintWriter();
- expectedDsm.println(" | B | A | C |");
- expectedDsm.println("B | | 2 | 1 |");
- expectedDsm.println("A | | | |");
- expectedDsm.println("C | | 3 | |");
-
- assertEquals(expectedDsm.toString(), DsmPrinter.print(dsm));
- }
-
-}
diff --git a/sonar-graph/src/test/java/org/sonar/graph/DsmPrinterTest.java b/sonar-graph/src/test/java/org/sonar/graph/DsmPrinterTest.java
deleted file mode 100644
index 063e1955b89..00000000000
--- a/sonar-graph/src/test/java/org/sonar/graph/DsmPrinterTest.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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.graph;
-
-import com.google.common.collect.Sets;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.HashSet;
-
-import static org.junit.Assert.assertEquals;
-
-public class DsmPrinterTest {
-
- private Dsm<String> dsm;
-
- @Before
- public void init() {
- DirectedGraph<String, StringEdge> graph = DirectedGraph.createStringDirectedGraph();
- graph.addEdge("A", "B", 3).addEdge("A", "C", 2);
- graph.addEdge("C", "B", 4).addEdge("C", "A", 1);
- HashSet<Edge> feedbackEdges = Sets.<Edge>newHashSet(graph.getEdge("C", "A"));
- dsm = new Dsm<>(graph, feedbackEdges);
- DsmManualSorter.sort(dsm, "A", "C", "B");
- }
-
- @Test
- public void testPrintDsm() {
- StringPrintWriter expectedResult = new StringPrintWriter();
- expectedResult.println(" | A | C | B |");
- expectedResult.println("A | | 1*| |");
- expectedResult.println("C | 2 | | |");
- expectedResult.println("B | 3 | 4 | |");
-
- assertEquals(expectedResult.toString(), DsmPrinter.print(dsm));
- }
-
- @Test
- public void testPrintDsmWithoutColumnHeaders() {
- StringPrintWriter expectedResult = new StringPrintWriter();
- expectedResult.println("A | | 1*| |");
- expectedResult.println("C | 2 | | |");
- expectedResult.println("B | 3 | 4 | |");
-
- assertEquals(expectedResult.toString(), DsmPrinter.print(dsm, false));
- }
-}
diff --git a/sonar-graph/src/test/java/org/sonar/graph/DsmScannerTest.java b/sonar-graph/src/test/java/org/sonar/graph/DsmScannerTest.java
deleted file mode 100644
index 676a812796e..00000000000
--- a/sonar-graph/src/test/java/org/sonar/graph/DsmScannerTest.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.graph;
-
-import org.junit.Test;
-import org.sonar.graph.Dsm;
-import org.sonar.graph.DsmCell;
-import org.sonar.graph.DsmScanner;
-
-import static org.junit.Assert.*;
-
-public class DsmScannerTest {
-
- @Test
- public void testScanString() {
- StringPrintWriter builder = new StringPrintWriter();
- builder.println(" | A | B |");
- builder.println("A | | 1*|");
- builder.println("B | 3 | |");
- Dsm dsm = DsmScanner.scan(builder.toString());
-
- assertEquals("A", dsm.getVertex(0).toString());
- assertEquals("B", dsm.getVertex(1).toString());
-
- assertEquals(2, dsm.getDimension());
-
- DsmCell ba = dsm.getCell(1, 0);
- assertEquals(1, ba.getWeight());
- assertTrue(ba.isFeedbackEdge());
-
- DsmCell ab = dsm.getCell(0, 1);
- assertEquals(3, ab.getWeight());
- assertFalse(ab.isFeedbackEdge());
-
- assertEquals(0, dsm.getCell(1, 1).getWeight());
- }
-
-}
diff --git a/sonar-graph/src/test/java/org/sonar/graph/DsmTest.java b/sonar-graph/src/test/java/org/sonar/graph/DsmTest.java
deleted file mode 100644
index 9d01eaf1467..00000000000
--- a/sonar-graph/src/test/java/org/sonar/graph/DsmTest.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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.graph;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.graph.Dsm;
-import org.sonar.graph.DsmScanner;
-
-import static org.hamcrest.Matchers.equalTo;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-
-public class DsmTest {
-
- private Dsm<String> dsm;
-
- @Before
- public void init() {
- StringPrintWriter textDsm = new StringPrintWriter();
- textDsm.println(" | A | B | C | D | E |");
- textDsm.println("A | | 1 | | | |");
- textDsm.println("B | 2 | | | | |");
- textDsm.println("C | 4 | | | | |");
- textDsm.println("D | | 7 | | | 5 |");
- textDsm.println("E | | | | | |");
- dsm = DsmScanner.scan(textDsm.toString());
- }
-
- @Test
- public void testGetVertex() {
- assertEquals("A", dsm.getVertex(0));
- assertEquals("B", dsm.getVertex(1));
- assertEquals("C", dsm.getVertex(2));
- assertEquals("D", dsm.getVertex(3));
- assertEquals("E", dsm.getVertex(4));
- }
-
- @Test
- public void testPermute() {
- assertEquals(2, dsm.getCell(0, 1).getWeight());
- assertEquals(4, dsm.getCell(0, 2).getWeight());
-
- dsm.permute(0, 1);
- assertEquals(1, dsm.getCell(0, 1).getWeight());
- assertEquals(0, dsm.getCell(0, 2).getWeight());
- }
-
- @Test
- public void testGetNumberOfOutgoingEdges() {
- assertEquals(0, dsm.getNumberOfOutgoingEdges(3, 0, 4));
- assertEquals(2, dsm.getNumberOfOutgoingEdges(0, 0, 4));
- }
-
- @Test
- public void testGetNumberOfIncomingEdges() {
- assertThat(dsm.getNumberOfIncomingEdges(0, 0, 4), equalTo(1));
- assertThat(dsm.getNumberOfIncomingEdges(4, 0, 4), equalTo(0));
- }
-}
diff --git a/sonar-graph/src/test/java/org/sonar/graph/DsmTopologicalSorterTest.java b/sonar-graph/src/test/java/org/sonar/graph/DsmTopologicalSorterTest.java
deleted file mode 100644
index 9a22ea4555b..00000000000
--- a/sonar-graph/src/test/java/org/sonar/graph/DsmTopologicalSorterTest.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * 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.graph;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-public class DsmTopologicalSorterTest {
-
- @Test
- public void sortAcyclicGraph() {
- StringPrintWriter textDsm = new StringPrintWriter();
- textDsm.println(" | A | B | C | D | E |");
- textDsm.println("A | | | | | |");
- textDsm.println("B | 3 | | 4 | | |");
- textDsm.println("C | 1 | | | | |");
- textDsm.println("D | | 2 | | | 1 |");
- textDsm.println("E | | 5 | | | |");
-
- Dsm<String> dsm = DsmScanner.scan(textDsm.toString());
- DsmTopologicalSorter.sort(dsm);
-
- StringPrintWriter expectedTextDsm = new StringPrintWriter();
- expectedTextDsm.println(" | A | C | B | E | D |");
- expectedTextDsm.println("A | | | | | |");
- expectedTextDsm.println("C | 1 | | | | |");
- expectedTextDsm.println("B | 3 | 4 | | | |");
- expectedTextDsm.println("E | | | 5 | | |");
- expectedTextDsm.println("D | | | 2 | 1 | |");
-
- Dsm<String> expectedDsm = DsmScanner.scan(expectedTextDsm.toString());
- DsmTopologicalSorter.sort(expectedDsm);
-
- assertEquals(DsmPrinter.print(dsm), DsmPrinter.print(expectedDsm));
- }
-
- @Test(expected = IllegalStateException.class)
- public void sortCyclicGraph() {
- StringPrintWriter textDsm = new StringPrintWriter();
- textDsm.println(" | A | B | C | D |");
- textDsm.println("A | | | | |");
- textDsm.println("B | 3 | | 4 | |");
- textDsm.println("C | 1 | 1 | | |");
- textDsm.println("D | | 2 | | |");
-
- Dsm<String> dsm = DsmScanner.scan(textDsm.toString());
- DsmTopologicalSorter.sort(dsm);
- }
-
- @Test
- public void sortCyclicGraphWithManuallyFlaggedFeedbackEdges() {
- StringPrintWriter textDsm = new StringPrintWriter();
- textDsm.println(" | A | B | C | D |");
- textDsm.println("A | | | | |");
- textDsm.println("B | 3 | | 4 | |");
- textDsm.println("C | 1 | 1*| | |");
- textDsm.println("D | | 2 | | |");
-
- Dsm<String> dsm = DsmScanner.scan(textDsm.toString());
- DsmTopologicalSorter.sort(dsm);
-
- StringPrintWriter expectedDsm = new StringPrintWriter();
- expectedDsm.println(" | A | C | B | D |");
- expectedDsm.println("A | | | | |");
- expectedDsm.println("C | 1 | | 1*| |");
- expectedDsm.println("B | 3 | 4 | | |");
- expectedDsm.println("D | | | 2 | |");
-
- assertEquals(expectedDsm.toString(), DsmPrinter.print(dsm));
- }
-
- @Test
- public void sortCyclicGraphWithFlaggedFeedbackEdges() {
- DirectedGraph<String, StringEdge> dcg = DirectedGraph.createStringDirectedGraph();
- dcg.addEdge("A", "B", 3).addEdge("B", "A", 1);
- CycleDetector<String> cycleDetector = new CycleDetector<>(dcg);
- cycleDetector.detectCycles();
-
- MinimumFeedbackEdgeSetSolver solver = new MinimumFeedbackEdgeSetSolver(cycleDetector.getCycles());
-
- Dsm<String> dsm = new Dsm<>(dcg, solver.getEdges());
- DsmTopologicalSorter.sort(dsm);
-
- StringPrintWriter expectedDsm = new StringPrintWriter();
- expectedDsm.println(" | A | B |");
- expectedDsm.println("A | | 1*|");
- expectedDsm.println("B | 3 | |");
-
- assertEquals(expectedDsm.toString(), DsmPrinter.print(dsm));
- }
-
-}
diff --git a/sonar-graph/src/test/java/org/sonar/graph/FeedbackCycleTest.java b/sonar-graph/src/test/java/org/sonar/graph/FeedbackCycleTest.java
deleted file mode 100644
index e14a97e691a..00000000000
--- a/sonar-graph/src/test/java/org/sonar/graph/FeedbackCycleTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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.graph;
-
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-public class FeedbackCycleTest {
-
- private Edge[] AB_Edges = { new StringEdge("A", "B"), new StringEdge("B", "A") };
- private Edge[] ABC_Edges = { new StringEdge("A", "B"), new StringEdge("B", "C"), new StringEdge("C", "A") };
- private Edge[] BCDA_Edges = { new StringEdge("B", "C"), new StringEdge("C", "D"), new StringEdge("D", "A"), new StringEdge("A", "B"), };
- private Edge[] EF_Edges = { new StringEdge("E", "F"), new StringEdge("F", "E") };
- private Edge[] GHIJ_Edges = { new StringEdge("G", "H"), new StringEdge("H", "I"), new StringEdge("I", "J"), new StringEdge("J", "G") };
- private Edge[] XYZW_Edges = { new StringEdge("X", "Y"), new StringEdge("Y", "Z"), new StringEdge("Z", "W"), new StringEdge("W", "X") };
-
- private Cycle AB_Cycle = new Cycle(Arrays.asList(AB_Edges));
- private Cycle ABC_Cycle = new Cycle(Arrays.asList(ABC_Edges));
- private Cycle BCDA_Cycle = new Cycle(Arrays.asList(BCDA_Edges));
- private Cycle EF_Cycle = new Cycle(Arrays.asList(EF_Edges));
- private Cycle GHIJ_Cycle = new Cycle(Arrays.asList(GHIJ_Edges));
- private Cycle XYZW_Cycle = new Cycle(Arrays.asList(XYZW_Edges));
-
- @Test
- public void testBuildFeedbackCycles() {
- Set<Cycle> cycles = new HashSet<>();
- cycles.add(AB_Cycle);
- cycles.add(ABC_Cycle);
- cycles.add(BCDA_Cycle);
- cycles.add(EF_Cycle);
- cycles.add(GHIJ_Cycle);
- cycles.add(XYZW_Cycle);
-
- List<FeedbackCycle> feedbackCycles = FeedbackCycle.buildFeedbackCycles(cycles);
- assertEquals(6, feedbackCycles.size());
- assertEquals(EF_Cycle, feedbackCycles.get(0).getCycle());
- assertEquals(AB_Cycle, feedbackCycles.get(1).getCycle());
- assertEquals(GHIJ_Cycle, feedbackCycles.get(2).getCycle());
- assertEquals(XYZW_Cycle, feedbackCycles.get(3).getCycle());
- assertEquals(ABC_Cycle, feedbackCycles.get(4).getCycle());
- assertEquals(BCDA_Cycle, feedbackCycles.get(5).getCycle());
- }
-}
diff --git a/sonar-graph/src/test/java/org/sonar/graph/FeedbackEdgeTest.java b/sonar-graph/src/test/java/org/sonar/graph/FeedbackEdgeTest.java
deleted file mode 100644
index 366b5d2a231..00000000000
--- a/sonar-graph/src/test/java/org/sonar/graph/FeedbackEdgeTest.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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.graph;
-
-import org.junit.Test;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.greaterThan;
-import static org.hamcrest.Matchers.is;
-
-public class FeedbackEdgeTest {
-
- @Test
- public void testWeights() {
- FeedbackEdge fEdge = mockFeedbackEdge(14, 2);
- assertThat(fEdge.getWeight(), is(14));
- assertThat(fEdge.getRelativeWeight(), is(7.0));
- assertThat(fEdge.getOccurences(), is(2));
- }
-
- @Test
- public void testCompareTo() {
- FeedbackEdge feedbackEdge1;
- FeedbackEdge feedbackEdge2;
- FeedbackEdge feedbackEdge3;
-
- feedbackEdge1 = mockFeedbackEdge(14, 2);
- feedbackEdge2 = mockFeedbackEdge(10, 2);
- assertThat(feedbackEdge1.compareTo(feedbackEdge2), is(1));
-
- feedbackEdge1 = mockFeedbackEdge(10, 2);
- feedbackEdge2 = mockFeedbackEdge(14, 2);
- assertThat(feedbackEdge1.compareTo(feedbackEdge2), is(-1));
-
- feedbackEdge1 = mockFeedbackEdge(14, 2);
- feedbackEdge2 = mockFeedbackEdge(14, 2);
- assertThat(feedbackEdge1.compareTo(feedbackEdge2), is(0));
-
- feedbackEdge1 = mockFeedbackEdge(14, 2);
- feedbackEdge2 = mockFeedbackEdge(13, 2);
- assertThat(feedbackEdge1.compareTo(feedbackEdge2), is(1));
-
- feedbackEdge1 = mockFeedbackEdge(13, 2);
- feedbackEdge2 = mockFeedbackEdge(14, 2);
- assertThat(feedbackEdge1.compareTo(feedbackEdge2), is(-1));
-
- feedbackEdge1 = mockFeedbackEdge("A", "B", 14, 2);
- feedbackEdge2 = mockFeedbackEdge("B", "C", 14, 2);
- feedbackEdge3 = mockFeedbackEdge("C", "A", 14, 2);
- assertThat(feedbackEdge1.compareTo(feedbackEdge2), is(-1));
- assertThat(feedbackEdge2.compareTo(feedbackEdge3), is(-1));
- assertThat(feedbackEdge3.compareTo(feedbackEdge1), greaterThan(1));
- }
-
- private FeedbackEdge mockFeedbackEdge(int weight, int occurrences) {
- return mockFeedbackEdge("from", "to", weight, occurrences);
- }
-
- private FeedbackEdge mockFeedbackEdge(String from, String to, int weight, int occurrences) {
- Edge edge = new StringEdge(from, to, weight);
- return new FeedbackEdge(edge, occurrences);
- }
-
-}
diff --git a/sonar-graph/src/test/java/org/sonar/graph/IncrementalCyclesAndFESSolverTest.java b/sonar-graph/src/test/java/org/sonar/graph/IncrementalCyclesAndFESSolverTest.java
deleted file mode 100644
index 104c11044a9..00000000000
--- a/sonar-graph/src/test/java/org/sonar/graph/IncrementalCyclesAndFESSolverTest.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * 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.graph;
-
-import org.junit.Test;
-
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-
-public class IncrementalCyclesAndFESSolverTest {
-
- @Test
- public void testSimpleCase() {
- DirectedGraph<String, StringEdge> dcg = DirectedGraph.createStringDirectedGraph();
- dcg.addEdge("A", "B").addEdge("B", "C").addEdge("C", "D").addEdge("D", "A");
- dcg.addEdge("C", "A");
- dcg.addEdge("B", "A");
- dcg.addEdge("A", "E").addEdge("E", "C");
- dcg.addEdge("E", "D");
- dcg.addEdge("E", "F");
- dcg.addEdge("F", "C");
-
- IncrementalCyclesAndFESSolver<String> cyclesAndFESSolver = new IncrementalCyclesAndFESSolver<>(dcg, dcg.getVertices(), 3,
- Integer.MAX_VALUE);
- assertThat(cyclesAndFESSolver.getCycles().size(), is(4));
- assertThat(cyclesAndFESSolver.getFeedbackEdgeSet().size(), is(2));
- assertThat(cyclesAndFESSolver.getWeightOfFeedbackEdgeSet(), is(2));
- }
-
- @Test
- public void testWithNoCycleUnderTheThreshold() {
- DirectedGraph<String, StringEdge> dcg = DirectedGraph.createStringDirectedGraph();
- dcg.addEdge("A", "B").addEdge("B", "C").addEdge("C", "D").addEdge("D", "A");
-
- IncrementalCyclesAndFESSolver<String> cyclesAndFESSolver = new IncrementalCyclesAndFESSolver<>(dcg, dcg.getVertices(), 2,
- Integer.MAX_VALUE);
- assertThat(cyclesAndFESSolver.getCycles().size(), is(1));
- assertThat(cyclesAndFESSolver.getFeedbackEdgeSet().size(), is(1));
- assertThat(cyclesAndFESSolver.getWeightOfFeedbackEdgeSet(), is(1));
- }
-
- @Test
- public void testBothMaxSearchDepthAtFirstAndMaxCyclesToFoundByIteration() {
- DirectedGraph<String, StringEdge> dcg = DirectedGraph.createStringDirectedGraph();
- dcg.addEdge("A", "B").addEdge("B", "C").addEdge("C", "D").addEdge("D", "A");
- dcg.addEdge("E", "F").addEdge("F", "G").addEdge("G", "E");
- dcg.addEdge("H", "I").addEdge("I", "H");
-
- IncrementalCyclesAndFESSolver<String> cyclesAndFESSolver = new IncrementalCyclesAndFESSolver<>(dcg, dcg.getVertices(), 2, 1);
- assertThat(cyclesAndFESSolver.getCycles().size(), is(3));
- assertThat(cyclesAndFESSolver.getIterations(), is(4));
- cyclesAndFESSolver.getFeedbackEdgeSet();
- }
-
-}
diff --git a/sonar-graph/src/test/java/org/sonar/graph/MinimumFeedbackEdgeSetSolverTest.java b/sonar-graph/src/test/java/org/sonar/graph/MinimumFeedbackEdgeSetSolverTest.java
deleted file mode 100644
index 580cc64f37f..00000000000
--- a/sonar-graph/src/test/java/org/sonar/graph/MinimumFeedbackEdgeSetSolverTest.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * 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.graph;
-
-import java.util.Set;
-
-import org.junit.Test;
-
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-public class MinimumFeedbackEdgeSetSolverTest {
-
- @Test
- public void testGetFeedbackEdgesOnSimpleLoop() {
- DirectedGraph<String, StringEdge> dcg = DirectedGraph.createStringDirectedGraph();
- dcg.addEdge("A", "B", 3).addEdge("B", "A", 1);
- CycleDetector<String> cycleDetector = new CycleDetector<>(dcg);
- cycleDetector.detectCycles();
-
- MinimumFeedbackEdgeSetSolver solver = new MinimumFeedbackEdgeSetSolver(cycleDetector.getCycles());
- Set<Edge> feedbackEdges = solver.getEdges();
- assertThat(feedbackEdges.size(), is(1));
- }
-
- @Test
- public void testFlagFeedbackEdgesOnSimpleLoop() {
- DirectedGraph<String, StringEdge> dcg = DirectedGraph.createStringDirectedGraph();
- dcg.addEdge("A", "B", 3).addEdge("B", "A", 1);
- CycleDetector<String> cycleDetector = new CycleDetector<>(dcg);
- cycleDetector.detectCycles();
-
- MinimumFeedbackEdgeSetSolver solver = new MinimumFeedbackEdgeSetSolver(cycleDetector.getCycles());
- Set<Edge> feedbackEdges = solver.getEdges();
- assertTrue(feedbackEdges.contains(dcg.getEdge("B", "A")));
- }
-
- @Test
- public void testGetFeedbackEdgesOnComplexGraph() {
- DirectedGraph<String, StringEdge> dcg = DirectedGraph.createStringDirectedGraph();
- dcg.addEdge("A", "B", 7).addEdge("B", "C", 3).addEdge("C", "D", 1).addEdge("D", "A", 3);
- dcg.addEdge("B", "A", 12);
- CycleDetector<String> cycleDetector = new CycleDetector<>(dcg);
- cycleDetector.detectCycles();
-
- MinimumFeedbackEdgeSetSolver solver = new MinimumFeedbackEdgeSetSolver(cycleDetector.getCycles());
- Set<Edge> feedbackEdges = solver.getEdges();
- assertThat(feedbackEdges.size(), is(1));
-
- assertTrue(feedbackEdges.contains(dcg.getEdge("A", "B")));
- }
-
- @Test
- public void testFlagFeedbackEdgesOnUnrelatedCycles() {
- DirectedGraph<String, StringEdge> dcg = DirectedGraph.createStringDirectedGraph();
- dcg.addEdge("A", "B", 7).addEdge("B", "C", 3).addEdge("C", "A", 2);
- dcg.addEdge("D", "E", 3).addEdge("E", "D", 5);
- dcg.addEdge("F", "G", 1).addEdge("G", "H", 4).addEdge("H", "F", 7);
-
- CycleDetector<String> cycleDetector = new CycleDetector<>(dcg);
- cycleDetector.detectCycles();
-
- MinimumFeedbackEdgeSetSolver solver = new MinimumFeedbackEdgeSetSolver(cycleDetector.getCycles());
- Set<Edge> feedbackEdges = solver.getEdges();
-
- assertThat(feedbackEdges.size(), is(3));
-
- assertTrue(feedbackEdges.contains(dcg.getEdge("C", "A")));
- assertTrue(feedbackEdges.contains(dcg.getEdge("D", "E")));
- assertTrue(feedbackEdges.contains(dcg.getEdge("F", "G")));
- }
-
- @Test
- public void testApproximateMinimumFeedbackEdges() {
- DirectedGraph<String, StringEdge> dcg = DirectedGraph.createStringDirectedGraph();
- dcg.addEdge("A", "B", 5).addEdge("B", "C", 9).addEdge("C", "A", 1);
- dcg.addEdge("D", "B", 5).addEdge("C", "D", 7);
- dcg.addEdge("F", "B", 5).addEdge("C", "F", 4);
- CycleDetector<String> cycleDetector = new CycleDetector<>(dcg);
- cycleDetector.detectCycles();
-
- MinimumFeedbackEdgeSetSolver minimumSolver = new MinimumFeedbackEdgeSetSolver(cycleDetector.getCycles());
- assertThat(minimumSolver.getEdges().size(), is(1));
- assertTrue(minimumSolver.getEdges().contains(dcg.getEdge("B", "C")));
-
- MinimumFeedbackEdgeSetSolver approximateSolver = new MinimumFeedbackEdgeSetSolver(cycleDetector.getCycles(), 2);
- assertThat(approximateSolver.getEdges().size(), is(2));
- assertTrue(approximateSolver.getEdges().contains(dcg.getEdge("B", "C")));
- assertTrue(approximateSolver.getEdges().contains(dcg.getEdge("C", "A")));
- }
-
-}
diff --git a/sonar-graph/src/test/java/org/sonar/graph/StringPrintWriter.java b/sonar-graph/src/test/java/org/sonar/graph/StringPrintWriter.java
deleted file mode 100644
index 4ac77c0675d..00000000000
--- a/sonar-graph/src/test/java/org/sonar/graph/StringPrintWriter.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.graph;
-
-public class StringPrintWriter {
-
- private StringBuilder builder = new StringBuilder();
-
- public void println(String line) {
- builder.append(line + " \r");
- }
-
- @Override
- public String toString() {
- return builder.toString();
- }
-
-}
diff --git a/sonar-plugin-api/pom.xml b/sonar-plugin-api/pom.xml
index e9f69c71055..d49195a8d01 100644
--- a/sonar-plugin-api/pom.xml
+++ b/sonar-plugin-api/pom.xml
@@ -55,11 +55,6 @@
</exclusion>
</exclusions>
</dependency>
- <dependency>
- <groupId>org.codehaus.sonar</groupId>
- <artifactId>sonar-graph</artifactId>
- </dependency>
-
<!-- TODO we can't remove hibernate-annotations, because currently it's used
moreover it contains transitive dependency on dom4j, which is used in some plugins
-->
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/DecoratorContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/DecoratorContext.java
index 018d22cc0a0..ee248eb6772 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/DecoratorContext.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/DecoratorContext.java
@@ -29,7 +29,6 @@ import org.sonar.api.rules.Violation;
import java.util.Collection;
import java.util.List;
-import java.util.Set;
/**
* @since 1.10
@@ -88,17 +87,13 @@ public interface DecoratorContext {
DecoratorContext saveMeasure(Metric metric, Double value);
// DEPENDENCIES
-
+ /**
+ * @deprecated since 5.2 No more design features. No-op.
+ */
+ @Deprecated
Dependency saveDependency(Dependency dependency);
- Set<Dependency> getDependencies();
-
- Collection<Dependency> getIncomingDependencies();
-
- Collection<Dependency> getOutgoingDependencies();
-
// RULES
-
/**
* Save a coding rule violation. The decorator which calls this method must be depended upon BatchBarriers.END_OF_VIOLATIONS_GENERATION.
*
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java
index f5b73a25722..e95d0e15a84 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java
@@ -32,7 +32,6 @@ import javax.annotation.CheckForNull;
import java.io.Serializable;
import java.util.Collection;
-import java.util.Set;
/**
* @since 1.10
@@ -191,25 +190,11 @@ public interface SensorContext extends org.sonar.api.batch.sensor.SensorContext
// ----------- DEPENDENCIES BETWEEN RESOURCES --------------
- Dependency saveDependency(Dependency dependency);
-
- /**
- * @deprecated since 5.1 Sensors should not read but only save data
- */
- @Deprecated
- Set<Dependency> getDependencies();
-
/**
- * @deprecated since 5.1 Sensors should not read but only save data
+ * @deprecated since 5.2 No more design features. No-op
*/
@Deprecated
- Collection<Dependency> getIncomingDependencies(Resource to);
-
- /**
- * @deprecated since 5.1 Sensors should not read but only save data
- */
- @Deprecated
- Collection<Dependency> getOutgoingDependencies(Resource from);
+ Dependency saveDependency(Dependency dependency);
// ----------- FILE SOURCES --------------
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SonarIndex.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SonarIndex.java
index 5032c68afcc..2c89ca8987c 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SonarIndex.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SonarIndex.java
@@ -26,18 +26,16 @@ import org.sonar.api.measures.MeasuresFilter;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.rules.Violation;
-import org.sonar.graph.DirectedGraphAccessor;
import javax.annotation.CheckForNull;
import java.util.Collection;
-import java.util.Set;
/**
* @deprecated since 4.5.2 should not be used by plugins. Everything should be accessed using {@link SensorContext}.
*/
@Deprecated
-public abstract class SonarIndex implements DirectedGraphAccessor<Resource, Dependency> {
+public abstract class SonarIndex {
/**
* Indexes a resource as a direct child of project. This method does nothing and returns true if the resource already indexed.
@@ -101,9 +99,7 @@ public abstract class SonarIndex implements DirectedGraphAccessor<Resource, Depe
public abstract Project getProject();
- public final Collection<Resource> getResources() {
- return getVertices();
- }
+ public abstract Collection<Resource> getResources();
/**
* Indexes the resource.
@@ -140,15 +136,9 @@ public abstract class SonarIndex implements DirectedGraphAccessor<Resource, Depe
*/
public abstract Measure addMeasure(Resource resource, Measure measure);
+ /**
+ * @deprecated since 5.2 No more design features. No op.
+ */
+ @Deprecated
public abstract Dependency addDependency(Dependency dependency);
-
- public abstract Set<Dependency> getDependencies();
-
- public final Collection<Dependency> getOutgoingDependencies(Resource from) {
- return getOutgoingEdges(from);
- }
-
- public final Collection<Dependency> getIncomingDependencies(Resource to) {
- return getIncomingEdges(to);
- }
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java
index 187c784ff00..87a98418dff 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java
@@ -25,7 +25,6 @@ import org.sonar.api.batch.CpdMapping;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.rule.ActiveRules;
import org.sonar.api.batch.sensor.coverage.NewCoverage;
-import org.sonar.api.batch.sensor.dependency.NewDependency;
import org.sonar.api.batch.sensor.duplication.NewDuplication;
import org.sonar.api.batch.sensor.highlighting.NewHighlighting;
import org.sonar.api.batch.sensor.internal.SensorContextTester;
@@ -106,14 +105,4 @@ public interface SensorContext {
*/
NewCoverage newCoverage();
- // TODO
-
- // ------------ DEPENDENCIES ------------
-
- /**
- * Create a new dependency.
- * Don't forget to call {@link NewDependency#save()} once all parameters are provided.
- */
- NewDependency newDependency();
-
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/Dependency.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/Dependency.java
deleted file mode 100644
index 69644789673..00000000000
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/Dependency.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.api.batch.sensor.dependency;
-
-import com.google.common.annotations.Beta;
-
-/**
- * @since 5.1
- */
-@Beta
-public interface Dependency {
-
- String fromKey();
-
- String toKey();
-
- /**
- * Default weight value is 1.
- */
- int weight();
-
-}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/NewDependency.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/NewDependency.java
deleted file mode 100644
index 9e0de3c991b..00000000000
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/NewDependency.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.api.batch.sensor.dependency;
-
-import com.google.common.annotations.Beta;
-import org.sonar.api.batch.fs.InputFile;
-
-/**
- * Builder to create new Dependency.
- * Should not be implemented by client.
- * @since 5.1
- */
-@Beta
-public interface NewDependency {
-
- NewDependency from(InputFile from);
-
- NewDependency to(InputFile to);
-
- /**
- * Set the weight of the dependency. If not set default weight is 1.
- */
- NewDependency weight(int weight);
-
- /**
- * Save the dependency. It is not permitted so save several time a dependency between two same files.
- */
- void save();
-
-}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/internal/DefaultDependency.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/internal/DefaultDependency.java
deleted file mode 100644
index 3ea8f9ef4d3..00000000000
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/internal/DefaultDependency.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * 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.api.batch.sensor.dependency.internal;
-
-import com.google.common.base.Preconditions;
-import org.apache.commons.lang.builder.EqualsBuilder;
-import org.apache.commons.lang.builder.HashCodeBuilder;
-import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.sensor.dependency.Dependency;
-import org.sonar.api.batch.sensor.dependency.NewDependency;
-import org.sonar.api.batch.sensor.internal.DefaultStorable;
-import org.sonar.api.batch.sensor.internal.SensorStorage;
-
-import javax.annotation.Nullable;
-
-public class DefaultDependency extends DefaultStorable implements Dependency, NewDependency {
-
- private String fromKey;
- private String toKey;
- private int weight = 1;
-
- public DefaultDependency() {
- super(null);
- }
-
- public DefaultDependency(@Nullable SensorStorage storage) {
- super(storage);
- }
-
- @Override
- public DefaultDependency from(InputFile from) {
- Preconditions.checkNotNull(from, "InputFile should be non null");
- this.fromKey = ((DefaultInputFile) from).key();
- return this;
- }
-
- @Override
- public DefaultDependency to(InputFile to) {
- Preconditions.checkNotNull(to, "InputFile should be non null");
- this.toKey = ((DefaultInputFile) to).key();
- return this;
- }
-
- @Override
- public DefaultDependency weight(int weight) {
- Preconditions.checkArgument(weight >= 1, "weight should be greater than 0");
- this.weight = weight;
- return this;
- }
-
- @Override
- public void doSave() {
- Preconditions.checkState(!this.fromKey.equals(this.toKey), "From and To can't be the same inputFile");
- Preconditions.checkNotNull(this.fromKey, "From inputFile can't be null");
- Preconditions.checkNotNull(this.toKey, "To inputFile can't be null");
- storage.store(this);
- }
-
- @Override
- public String fromKey() {
- return this.fromKey;
- }
-
- public DefaultDependency setFromKey(String fromKey) {
- this.fromKey = fromKey;
- return this;
- }
-
- @Override
- public String toKey() {
- return this.toKey;
- }
-
- public DefaultDependency setToKey(String toKey) {
- this.toKey = toKey;
- return this;
- }
-
- @Override
- public int weight() {
- return this.weight;
- }
-
- public DefaultDependency setWeight(int weight) {
- this.weight = weight;
- return this;
- }
-
- // For testing purpose
-
- @Override
- public boolean equals(Object obj) {
- if (obj == null) {
- return false;
- }
- if (obj == this) {
- return true;
- }
- if (obj.getClass() != getClass()) {
- return false;
- }
- DefaultDependency rhs = (DefaultDependency) obj;
- return new EqualsBuilder()
- .append(fromKey, rhs.fromKey)
- .append(toKey, rhs.toKey)
- .append(weight, rhs.weight)
- .isEquals();
- }
-
- @Override
- public int hashCode() {
- return new HashCodeBuilder(27, 45).
- append(fromKey).
- append(toKey).
- append(weight).
- toHashCode();
- }
-
-}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/internal/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/internal/package-info.java
deleted file mode 100644
index d45dd459268..00000000000
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/internal/package-info.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * 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.api.batch.sensor.dependency.internal;
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/package-info.java
deleted file mode 100644
index e42fabac294..00000000000
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/package-info.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * 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.api.batch.sensor.dependency;
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java
index 13027e24426..9b018f6bc2c 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java
@@ -35,9 +35,6 @@ import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.coverage.CoverageType;
import org.sonar.api.batch.sensor.coverage.NewCoverage;
import org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage;
-import org.sonar.api.batch.sensor.dependency.Dependency;
-import org.sonar.api.batch.sensor.dependency.NewDependency;
-import org.sonar.api.batch.sensor.dependency.internal.DefaultDependency;
import org.sonar.api.batch.sensor.duplication.Duplication;
import org.sonar.api.batch.sensor.duplication.NewDuplication;
import org.sonar.api.batch.sensor.duplication.internal.DefaultDuplication;
@@ -59,7 +56,12 @@ import javax.annotation.Nullable;
import java.io.File;
import java.io.Serializable;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
/**
* Utility class to help testing {@link Sensor}.
@@ -243,15 +245,6 @@ public class SensorContextTester implements SensorContext {
return sensorStorage.duplications;
}
- @Override
- public NewDependency newDependency() {
- return new DefaultDependency(sensorStorage);
- }
-
- public Collection<Dependency> dependencies() {
- return sensorStorage.dependencies;
- }
-
public static class MockAnalysisMode implements AnalysisMode {
private boolean isIncremental = false;
private boolean isPreview = false;
@@ -287,7 +280,6 @@ public class SensorContextTester implements SensorContext {
private Map<String, Map<CoverageType, DefaultCoverage>> coverageByComponent = new HashMap<>();
private List<Duplication> duplications = new ArrayList<>();
- private List<Dependency> dependencies = new ArrayList<>();
@Override
public void store(Measure measure) {
@@ -321,11 +313,6 @@ public class SensorContextTester implements SensorContext {
}
@Override
- public void store(Dependency dependency) {
- dependencies.add(dependency);
- }
-
- @Override
public void store(DefaultHighlighting highlighting) {
highlightingByComponent.put(getKey(highlighting.inputFile()), highlighting);
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorStorage.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorStorage.java
index 10beba2c5d3..c653c61abbc 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorStorage.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorStorage.java
@@ -21,7 +21,6 @@ package org.sonar.api.batch.sensor.internal;
import org.sonar.api.BatchSide;
import org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage;
-import org.sonar.api.batch.sensor.dependency.Dependency;
import org.sonar.api.batch.sensor.duplication.Duplication;
import org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting;
import org.sonar.api.batch.sensor.issue.Issue;
@@ -40,8 +39,6 @@ public interface SensorStorage {
void store(Duplication duplication);
- void store(Dependency dependency);
-
void store(DefaultHighlighting highlighting);
/**
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/design/Dependency.java b/sonar-plugin-api/src/main/java/org/sonar/api/design/Dependency.java
index bc965583881..5bfe69d6d0d 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/design/Dependency.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/design/Dependency.java
@@ -23,9 +23,12 @@ import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.sonar.api.resources.Resource;
-import org.sonar.graph.Edge;
-public class Dependency implements Edge<Resource> {
+/**
+ * @deprecated since 5.2 No more design features
+ */
+@Deprecated
+public class Dependency {
private Resource from;
private Resource to;
@@ -45,7 +48,6 @@ public class Dependency implements Edge<Resource> {
this.to = to;
}
- @Override
public Resource getFrom() {
return from;
}
@@ -57,7 +59,6 @@ public class Dependency implements Edge<Resource> {
this.from = from;
}
- @Override
public Resource getTo() {
return to;
}
@@ -78,7 +79,6 @@ public class Dependency implements Edge<Resource> {
return this;
}
- @Override
public int getWeight() {
return weight;
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/design/DependencyDto.java b/sonar-plugin-api/src/main/java/org/sonar/api/design/DependencyDto.java
deleted file mode 100644
index 5e575bc09e2..00000000000
--- a/sonar-plugin-api/src/main/java/org/sonar/api/design/DependencyDto.java
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * 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.api.design;
-
-import org.apache.commons.lang.builder.EqualsBuilder;
-import org.apache.commons.lang.builder.HashCodeBuilder;
-import org.apache.commons.lang.builder.ReflectionToStringBuilder;
-import org.apache.commons.lang.builder.ToStringStyle;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.Table;
-
-@Entity
-@Table(name = "dependencies")
-public class DependencyDto {
-
- @Id
- @Column(name = "id")
- @GeneratedValue
- private Long id;
-
- @Column(name = "from_snapshot_id", updatable = true, nullable = false)
- private Integer fromSnapshotId;
-
- @Column(name = "from_component_uuid", updatable = true, nullable = false)
- private String fromComponentUuid;
-
- @Column(name = "from_scope", updatable = true, nullable = true)
- private String fromScope;
-
- @Column(name = "to_snapshot_id", updatable = true, nullable = false)
- private Integer toSnapshotId;
-
- @Column(name = "to_component_uuid", updatable = true, nullable = false)
- private String toComponentUuid;
-
- @Column(name = "to_scope", updatable = true, nullable = true)
- private String toScope;
-
- @Column(name = "dep_weight", updatable = true, nullable = true)
- private Integer weight;
-
- @Column(name = "dep_usage", updatable = true, nullable = true, length = 30)
- private String usage;
-
- @Column(name = "project_snapshot_id", updatable = true, nullable = false)
- private Integer projectSnapshotId;
-
- @Column(name = "parent_dependency_id", updatable = true, nullable = true)
- private Long parentDependencyId;
-
- public Long getId() {
- return id;
- }
-
- public void setId(Long id) {
- this.id = id;
- }
-
- public Integer getFromSnapshotId() {
- return fromSnapshotId;
- }
-
- public DependencyDto setFromSnapshotId(Integer fromSnapshotId) {
- this.fromSnapshotId = fromSnapshotId;
- return this;
- }
-
- public String getFromComponentUuid() {
- return fromComponentUuid;
- }
-
- public DependencyDto setFromComponentUuid(String fromComponentUuid) {
- this.fromComponentUuid = fromComponentUuid;
- return this;
- }
-
- public Integer getToSnapshotId() {
- return toSnapshotId;
- }
-
- public DependencyDto setToSnapshotId(Integer toSnapshotId) {
- this.toSnapshotId = toSnapshotId;
- return this;
- }
-
- public String getToComponentUuid() {
- return toComponentUuid;
- }
-
- public DependencyDto setToComponentUuid(String toComponentUuid) {
- this.toComponentUuid = toComponentUuid;
- return this;
- }
-
- public Integer getWeight() {
- return weight;
- }
-
- public DependencyDto setWeight(Integer weight) {
- if (weight < 0) {
- throw new IllegalArgumentException("Dependency weight can not be negative");
- }
- this.weight = weight;
- return this;
- }
-
- public String getFromScope() {
- return fromScope;
- }
-
- public DependencyDto setFromScope(String fromScope) {
- this.fromScope = fromScope;
- return this;
- }
-
- public String getToScope() {
- return toScope;
- }
-
- public DependencyDto setToScope(String toScope) {
- this.toScope = toScope;
- return this;
- }
-
- public String getUsage() {
- return usage;
- }
-
- public DependencyDto setUsage(String usage) {
- this.usage = usage;
- return this;
- }
-
- public Integer getProjectSnapshotId() {
- return projectSnapshotId;
- }
-
- public DependencyDto setProjectSnapshotId(Integer projectSnapshotId) {
- this.projectSnapshotId = projectSnapshotId;
- return this;
- }
-
- public Long getParentDependencyId() {
- return parentDependencyId;
- }
-
- public DependencyDto setParentDependencyId(Long parentDependencyId) {
- this.parentDependencyId = parentDependencyId;
- return this;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (!(obj instanceof DependencyDto)) {
- return false;
- }
- if (this == obj) {
- return true;
- }
- DependencyDto other = (DependencyDto) obj;
- return new EqualsBuilder()
- .append(fromSnapshotId, other.fromSnapshotId)
- .append(toSnapshotId, other.toSnapshotId)
- .isEquals();
- }
-
- @Override
- public int hashCode() {
- return new HashCodeBuilder(17, 37)
- .append(fromSnapshotId)
- .append(toSnapshotId)
- .toHashCode();
- }
-
- @Override
- public String toString() {
- return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString();
- }
-}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java
index eeb92f0a798..227a27d7d73 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java
@@ -1604,7 +1604,7 @@ public final class CoreMetrics {
* @deprecated since 4.0. See SONAR-4643
*/
@Deprecated
- public static final Metric<Integer> DEPTH_IN_TREE = new Metric.Builder(DEPTH_IN_TREE_KEY, "Depth in Tree", Metric.ValueType.INT)
+ public static final transient Metric<Integer> DEPTH_IN_TREE = new Metric.Builder(DEPTH_IN_TREE_KEY, "Depth in Tree", Metric.ValueType.INT)
.setDescription("Depth in Inheritance Tree")
.setDirection(Metric.DIRECTION_NONE)
.setQualitative(false)
@@ -1621,7 +1621,7 @@ public final class CoreMetrics {
* @deprecated since 4.0. See SONAR-4643
*/
@Deprecated
- public static final Metric<Integer> NUMBER_OF_CHILDREN = new Metric.Builder(NUMBER_OF_CHILDREN_KEY, "Number of Children", Metric.ValueType.INT)
+ public static final transient Metric<Integer> NUMBER_OF_CHILDREN = new Metric.Builder(NUMBER_OF_CHILDREN_KEY, "Number of Children", Metric.ValueType.INT)
.setDescription("Number of Children")
.setDirection(Metric.DIRECTION_NONE)
.setQualitative(false)
@@ -1639,7 +1639,7 @@ public final class CoreMetrics {
* @deprecated since 4.2. See SONAR-5042
*/
@Deprecated
- public static final Metric<Integer> RFC = new Metric.Builder(RFC_KEY, "RFC", Metric.ValueType.INT)
+ public static final transient Metric<Integer> RFC = new Metric.Builder(RFC_KEY, "RFC", Metric.ValueType.INT)
.setDescription("Response for Class")
.setDirection(Metric.DIRECTION_WORST)
.setQualitative(false)
@@ -1658,7 +1658,7 @@ public final class CoreMetrics {
* @deprecated since 4.2. See SONAR-5042
*/
@Deprecated
- public static final Metric<String> RFC_DISTRIBUTION = new Metric.Builder(RFC_DISTRIBUTION_KEY, "Class distribution /RFC", Metric.ValueType.DISTRIB)
+ public static final transient Metric<String> RFC_DISTRIBUTION = new Metric.Builder(RFC_DISTRIBUTION_KEY, "Class distribution /RFC", Metric.ValueType.DISTRIB)
.setDescription("Class distribution /RFC")
.setDirection(Metric.DIRECTION_NONE)
.setQualitative(true)
@@ -1677,7 +1677,7 @@ public final class CoreMetrics {
* @deprecated in 4.1. See http://jira.codehaus.org/browse/SONAR-4853
*/
@Deprecated
- public static final Metric<Double> LCOM4 = new Metric.Builder(LCOM4_KEY, "LCOM4", Metric.ValueType.FLOAT)
+ public static final transient Metric<Double> LCOM4 = new Metric.Builder(LCOM4_KEY, "LCOM4", Metric.ValueType.FLOAT)
.setDescription("Lack of Cohesion of Functions")
.setDirection(Metric.DIRECTION_WORST)
.setQualitative(true)
@@ -1696,7 +1696,7 @@ public final class CoreMetrics {
* @deprecated in 4.1. See http://jira.codehaus.org/browse/SONAR-4853
*/
@Deprecated
- public static final Metric<String> LCOM4_BLOCKS = new Metric.Builder(LCOM4_BLOCKS_KEY, "LCOM4 blocks", Metric.ValueType.DATA)
+ public static final transient Metric<String> LCOM4_BLOCKS = new Metric.Builder(LCOM4_BLOCKS_KEY, "LCOM4 blocks", Metric.ValueType.DATA)
.setDescription("LCOM4 blocks")
.setDirection(Metric.DIRECTION_NONE)
.setQualitative(false)
@@ -1715,7 +1715,7 @@ public final class CoreMetrics {
* @deprecated in 4.1. See http://jira.codehaus.org/browse/SONAR-4853
*/
@Deprecated
- public static final Metric<String> LCOM4_DISTRIBUTION = new Metric.Builder(LCOM4_DISTRIBUTION_KEY, "Class distribution /LCOM4", Metric.ValueType.DISTRIB)
+ public static final transient Metric<String> LCOM4_DISTRIBUTION = new Metric.Builder(LCOM4_DISTRIBUTION_KEY, "Class distribution /LCOM4", Metric.ValueType.DISTRIB)
.setDescription("Class distribution /LCOM4")
.setDirection(Metric.DIRECTION_NONE)
.setQualitative(true)
@@ -1734,7 +1734,7 @@ public final class CoreMetrics {
* @deprecated in 4.1. See http://jira.codehaus.org/browse/SONAR-4853
*/
@Deprecated
- public static final Metric<Double> SUSPECT_LCOM4_DENSITY = new Metric.Builder(SUSPECT_LCOM4_DENSITY_KEY, "Suspect LCOM4 density", Metric.ValueType.PERCENT)
+ public static final transient Metric<Double> SUSPECT_LCOM4_DENSITY = new Metric.Builder(SUSPECT_LCOM4_DENSITY_KEY, "Suspect LCOM4 density", Metric.ValueType.PERCENT)
.setDescription("Density of classes having LCOM4>1")
.setDirection(Metric.DIRECTION_WORST)
.setQualitative(true)
@@ -1751,7 +1751,7 @@ public final class CoreMetrics {
* @deprecated since 5.0 this is an internal metric that should not be accessed by plugins
*/
@Deprecated
- public static final Metric<String> DEPENDENCY_MATRIX = new Metric.Builder(DEPENDENCY_MATRIX_KEY, "Dependency Matrix", Metric.ValueType.DATA)
+ public static final transient Metric<String> DEPENDENCY_MATRIX = new Metric.Builder(DEPENDENCY_MATRIX_KEY, "Dependency Matrix", Metric.ValueType.DATA)
.setDescription("Dependency Matrix")
.setDirection(Metric.DIRECTION_NONE)
.setQualitative(false)
@@ -1759,8 +1759,16 @@ public final class CoreMetrics {
.setDeleteHistoricalData(true)
.create();
+ /**
+ * @deprecated since 5.2 No more design features
+ */
+ @Deprecated
public static final String DIRECTORY_CYCLES_KEY = "package_cycles";
- public static final Metric<Integer> DIRECTORY_CYCLES = new Metric.Builder(DIRECTORY_CYCLES_KEY, "Directory cycles", Metric.ValueType.INT)
+ /**
+ * @deprecated since 5.2 No more design features
+ */
+ @Deprecated
+ public static final transient Metric<Integer> DIRECTORY_CYCLES = new Metric.Builder(DIRECTORY_CYCLES_KEY, "Directory cycles", Metric.ValueType.INT)
.setDescription("Directory cycles")
.setDirection(Metric.DIRECTION_WORST)
.setQualitative(true)
@@ -1780,8 +1788,16 @@ public final class CoreMetrics {
@Deprecated
public static final transient Metric<Integer> PACKAGE_CYCLES = DIRECTORY_CYCLES;
+ /**
+ * @deprecated since 5.2 No more design features
+ */
+ @Deprecated
public static final String DIRECTORY_TANGLE_INDEX_KEY = "package_tangle_index";
- public static final Metric<Double> DIRECTORY_TANGLE_INDEX = new Metric.Builder(DIRECTORY_TANGLE_INDEX_KEY, "Directory tangle index", Metric.ValueType.PERCENT)
+ /**
+ * @deprecated since 5.2 No more design features
+ */
+ @Deprecated
+ public static final transient Metric<Double> DIRECTORY_TANGLE_INDEX = new Metric.Builder(DIRECTORY_TANGLE_INDEX_KEY, "Directory tangle index", Metric.ValueType.PERCENT)
.setDescription("Directory tangle index")
.setDirection(Metric.DIRECTION_WORST)
.setQualitative(true)
@@ -1800,8 +1816,16 @@ public final class CoreMetrics {
@Deprecated
public static final transient Metric<Double> PACKAGE_TANGLE_INDEX = DIRECTORY_TANGLE_INDEX;
+ /**
+ * @deprecated since 5.2 No more design features
+ */
+ @Deprecated
public static final String DIRECTORY_TANGLES_KEY = "package_tangles";
- public static final Metric<Integer> DIRECTORY_TANGLES = new Metric.Builder(DIRECTORY_TANGLES_KEY, "File dependencies to cut", Metric.ValueType.INT)
+ /**
+ * @deprecated since 5.2 No more design features
+ */
+ @Deprecated
+ public static final transient Metric<Integer> DIRECTORY_TANGLES = new Metric.Builder(DIRECTORY_TANGLES_KEY, "File dependencies to cut", Metric.ValueType.INT)
.setDescription("File dependencies to cut")
.setDirection(Metric.DIRECTION_WORST)
.setQualitative(false)
@@ -1820,8 +1844,16 @@ public final class CoreMetrics {
@Deprecated
public static final transient Metric<Integer> PACKAGE_TANGLES = DIRECTORY_TANGLES;
+ /**
+ * @deprecated since 5.2 No more design features
+ */
+ @Deprecated
public static final String DIRECTORY_FEEDBACK_EDGES_KEY = "package_feedback_edges";
- public static final Metric<Integer> DIRECTORY_FEEDBACK_EDGES = new Metric.Builder(DIRECTORY_FEEDBACK_EDGES_KEY, "Package dependencies to cut", Metric.ValueType.INT)
+ /**
+ * @deprecated since 5.2 No more design features
+ */
+ @Deprecated
+ public static final transient Metric<Integer> DIRECTORY_FEEDBACK_EDGES = new Metric.Builder(DIRECTORY_FEEDBACK_EDGES_KEY, "Package dependencies to cut", Metric.ValueType.INT)
.setDescription("Package dependencies to cut")
.setDirection(Metric.DIRECTION_WORST)
.setQualitative(false)
@@ -1841,8 +1873,16 @@ public final class CoreMetrics {
@Deprecated
public static final transient Metric<Integer> PACKAGE_FEEDBACK_EDGES = DIRECTORY_FEEDBACK_EDGES;
+ /**
+ * @deprecated since 5.2 No more design features
+ */
+ @Deprecated
public static final String DIRECTORY_EDGES_WEIGHT_KEY = "package_edges_weight";
- public static final Metric<Integer> DIRECTORY_EDGES_WEIGHT = new Metric.Builder(DIRECTORY_EDGES_WEIGHT_KEY, "Directory edges weight", Metric.ValueType.INT)
+ /**
+ * @deprecated since 5.2 No more design features
+ */
+ @Deprecated
+ public static final transient Metric<Integer> DIRECTORY_EDGES_WEIGHT = new Metric.Builder(DIRECTORY_EDGES_WEIGHT_KEY, "Directory edges weight", Metric.ValueType.INT)
.setDescription("Directory edges weight")
.setDirection(Metric.DIRECTION_BETTER)
.setQualitative(false)
@@ -1863,8 +1903,16 @@ public final class CoreMetrics {
@Deprecated
public static final transient Metric<Integer> PACKAGE_EDGES_WEIGHT = DIRECTORY_EDGES_WEIGHT;
+ /**
+ * @deprecated since 5.2 No more design features
+ */
+ @Deprecated
public static final String FILE_CYCLES_KEY = "file_cycles";
- public static final Metric<Integer> FILE_CYCLES = new Metric.Builder(FILE_CYCLES_KEY, "File cycles", Metric.ValueType.INT)
+ /**
+ * @deprecated since 5.2 No more design features
+ */
+ @Deprecated
+ public static final transient Metric<Integer> FILE_CYCLES = new Metric.Builder(FILE_CYCLES_KEY, "File cycles", Metric.ValueType.INT)
.setDescription("File cycles")
.setDirection(Metric.DIRECTION_WORST)
.setQualitative(true)
@@ -1874,8 +1922,16 @@ public final class CoreMetrics {
.setBestValue(0.0)
.create();
+ /**
+ * @deprecated since 5.2 No more design features
+ */
+ @Deprecated
public static final String FILE_TANGLE_INDEX_KEY = "file_tangle_index";
- public static final Metric<Double> FILE_TANGLE_INDEX = new Metric.Builder(FILE_TANGLE_INDEX_KEY, "File tangle index", Metric.ValueType.PERCENT)
+ /**
+ * @deprecated since 5.2 No more design features
+ */
+ @Deprecated
+ public static final transient Metric<Double> FILE_TANGLE_INDEX = new Metric.Builder(FILE_TANGLE_INDEX_KEY, "File tangle index", Metric.ValueType.PERCENT)
.setDescription("File tangle index")
.setDirection(Metric.DIRECTION_WORST)
.setQualitative(true)
@@ -1885,8 +1941,16 @@ public final class CoreMetrics {
.setBestValue(0.0)
.create();
+ /**
+ * @deprecated since 5.2 No more design features
+ */
+ @Deprecated
public static final String FILE_TANGLES_KEY = "file_tangles";
- public static final Metric<Integer> FILE_TANGLES = new Metric.Builder(FILE_TANGLES_KEY, "File tangles", Metric.ValueType.INT)
+ /**
+ * @deprecated since 5.2 No more design features
+ */
+ @Deprecated
+ public static final transient Metric<Integer> FILE_TANGLES = new Metric.Builder(FILE_TANGLES_KEY, "File tangles", Metric.ValueType.INT)
.setDescription("Files tangles")
.setDirection(Metric.DIRECTION_WORST)
.setQualitative(false)
@@ -1895,8 +1959,16 @@ public final class CoreMetrics {
.setDeleteHistoricalData(true)
.create();
+ /**
+ * @deprecated since 5.2 No more design features
+ */
+ @Deprecated
public static final String FILE_FEEDBACK_EDGES_KEY = "file_feedback_edges";
- public static final Metric<Integer> FILE_FEEDBACK_EDGES = new Metric.Builder(FILE_FEEDBACK_EDGES_KEY, "Suspect file dependencies", Metric.ValueType.INT)
+ /**
+ * @deprecated since 5.2 No more design features
+ */
+ @Deprecated
+ public static final transient Metric<Integer> FILE_FEEDBACK_EDGES = new Metric.Builder(FILE_FEEDBACK_EDGES_KEY, "Suspect file dependencies", Metric.ValueType.INT)
.setDescription("Suspect file dependencies")
.setDirection(Metric.DIRECTION_WORST)
.setQualitative(false)
@@ -1906,8 +1978,16 @@ public final class CoreMetrics {
.setBestValue(0.0)
.create();
+ /**
+ * @deprecated since 5.2 No more design features
+ */
+ @Deprecated
public static final String FILE_EDGES_WEIGHT_KEY = "file_edges_weight";
- public static final Metric<Integer> FILE_EDGES_WEIGHT = new Metric.Builder(FILE_EDGES_WEIGHT_KEY, "File edges weight", Metric.ValueType.INT)
+ /**
+ * @deprecated since 5.2 No more design features
+ */
+ @Deprecated
+ public static final transient Metric<Integer> FILE_EDGES_WEIGHT = new Metric.Builder(FILE_EDGES_WEIGHT_KEY, "File edges weight", Metric.ValueType.INT)
.setDescription("File edges weight")
.setDirection(Metric.DIRECTION_BETTER)
.setQualitative(false)
@@ -1938,7 +2018,7 @@ public final class CoreMetrics {
* @deprecated since 5.0 SCM data will no more be stored as measures
*/
@Deprecated
- public static final Metric<String> SCM_AUTHORS_BY_LINE = new Metric.Builder(SCM_AUTHORS_BY_LINE_KEY, "Authors by line", Metric.ValueType.DATA)
+ public static final transient Metric<String> SCM_AUTHORS_BY_LINE = new Metric.Builder(SCM_AUTHORS_BY_LINE_KEY, "Authors by line", Metric.ValueType.DATA)
.setDomain(DOMAIN_SCM)
.create();
@@ -1958,7 +2038,7 @@ public final class CoreMetrics {
* @deprecated since 5.0 SCM data will no more be stored as measures
*/
@Deprecated
- public static final Metric<String> SCM_REVISIONS_BY_LINE = new Metric.Builder(SCM_REVISIONS_BY_LINE_KEY, "Revisions by line", Metric.ValueType.DATA)
+ public static final transient Metric<String> SCM_REVISIONS_BY_LINE = new Metric.Builder(SCM_REVISIONS_BY_LINE_KEY, "Revisions by line", Metric.ValueType.DATA)
.setDomain(DOMAIN_SCM)
.create();
@@ -1978,7 +2058,7 @@ public final class CoreMetrics {
* @deprecated since 5.0 SCM data will no more be stored as measures
*/
@Deprecated
- public static final Metric<String> SCM_LAST_COMMIT_DATETIMES_BY_LINE = new Metric.Builder(SCM_LAST_COMMIT_DATETIMES_BY_LINE_KEY, "Last commit dates by line",
+ public static final transient Metric<String> SCM_LAST_COMMIT_DATETIMES_BY_LINE = new Metric.Builder(SCM_LAST_COMMIT_DATETIMES_BY_LINE_KEY, "Last commit dates by line",
Metric.ValueType.DATA)
.setDomain(DOMAIN_SCM)
.create();
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Library.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Library.java
index 607d2ea9640..d75fd75fce2 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Library.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Library.java
@@ -21,6 +21,10 @@ package org.sonar.api.resources;
import org.apache.commons.lang.builder.ToStringBuilder;
+/**
+ * @deprecated since 5.2 No more design features
+ */
+@Deprecated
public final class Library extends Resource {
private String name;
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Qualifiers.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Qualifiers.java
index 80e12802b63..1aa25c066de 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Qualifiers.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Qualifiers.java
@@ -46,7 +46,9 @@ public final class Qualifiers {
/**
* Library, for example a JAR dependency of Java projects.
* Scope of libraries is Scopes.PROJECT
+ * @deprecated since 5.2 No more design features
*/
+ @Deprecated
public static final String LIBRARY = "LIB";
/**
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceUtils.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceUtils.java
index 4241f174b5a..b3ab973e7ac 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceUtils.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceUtils.java
@@ -135,8 +135,9 @@ public final class ResourceUtils {
}
/**
- * @return whether a resource is a library
+ * @deprecated since 5.2 No more design features
*/
+ @Deprecated
public static boolean isLibrary(Resource resource) {
return Qualifiers.LIBRARY.equals(resource.getQualifier());
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/internal/DefaultRequirement.java b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/internal/DefaultRequirement.java
index 2cc8c26107c..5d5f0bf7027 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/internal/DefaultRequirement.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/internal/DefaultRequirement.java
@@ -20,6 +20,8 @@
package org.sonar.api.technicaldebt.batch.internal;
+import java.util.Date;
+import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
@@ -28,10 +30,6 @@ import org.sonar.api.technicaldebt.batch.Requirement;
import org.sonar.api.utils.WorkUnit;
import org.sonar.api.utils.internal.WorkDuration;
-import javax.annotation.CheckForNull;
-
-import java.util.Date;
-
/**
* @deprecated since 4.3
*/
@@ -207,7 +205,7 @@ public class DefaultRequirement implements Requirement {
return this;
}
- public static WorkDuration.UNIT toUnit(String requirementUnit){
+ public static WorkDuration.UNIT toUnit(String requirementUnit) {
if (WorkUnit.DAYS.equals(requirementUnit)) {
return WorkDuration.UNIT.DAYS;
} else if (WorkUnit.HOURS.equals(requirementUnit)) {
@@ -218,7 +216,7 @@ public class DefaultRequirement implements Requirement {
throw new IllegalStateException("Invalid unit : " + requirementUnit);
}
- private static String fromUnit(WorkDuration.UNIT unit){
+ private static String fromUnit(WorkDuration.UNIT unit) {
if (WorkDuration.UNIT.DAYS.equals(unit)) {
return WorkUnit.DAYS;
} else if (WorkDuration.UNIT.HOURS.equals(unit)) {
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/internal/SensorContextTesterTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/internal/SensorContextTesterTest.java
index 8fcc6f3a6ce..eef71735990 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/internal/SensorContextTesterTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/internal/SensorContextTesterTest.java
@@ -168,17 +168,6 @@ public class SensorContextTesterTest {
}
@Test
- public void testDependencies() {
- assertThat(tester.dependencies()).isEmpty();
- tester.newDependency()
- .from(new DefaultInputFile("foo", "src/Foo.java"))
- .to(new DefaultInputFile("foo", "src/Foo2.java"))
- .weight(3)
- .save();
- assertThat(tester.dependencies()).hasSize(1);
- }
-
- @Test
public void testLineHits() {
assertThat(tester.lineHits("foo:src/Foo.java", CoverageType.UNIT, 1)).isNull();
assertThat(tester.lineHits("foo:src/Foo.java", CoverageType.UNIT, 4)).isNull();
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/design/DependencyTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/design/DependencyTest.java
deleted file mode 100644
index 3e6618cb37b..00000000000
--- a/sonar-plugin-api/src/test/java/org/sonar/api/design/DependencyTest.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.api.design;
-
-import org.junit.Test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class DependencyTest {
-
- @Test
- public void equalsAndHashCode() {
- DependencyDto dep1 = new DependencyDto().setFromSnapshotId(10).setToSnapshotId(30);
- DependencyDto dep1Clone = new DependencyDto().setFromSnapshotId(10).setToSnapshotId(30);
- DependencyDto dep2 = new DependencyDto().setFromSnapshotId(10).setToSnapshotId(31);
-
- assertThat(dep1.equals(dep2)).isFalse();
- assertThat(dep1.equals(dep1)).isTrue();
- assertThat(dep1.equals(dep1Clone)).isTrue();
-
- assertThat(dep1.hashCode()).isEqualTo(dep1.hashCode());
- assertThat(dep1.hashCode()).isEqualTo(dep1Clone.hashCode());
- assertThat(dep1.toString()).isEqualTo(dep1.toString());
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void weightCanNotBeNegative() {
- new DependencyDto().setWeight(-2);
- }
-}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceUtilsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceUtilsTest.java
index 14b0b7bf6ba..47b7e26ca9a 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceUtilsTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceUtilsTest.java
@@ -72,7 +72,6 @@ public class ResourceUtilsTest {
assertThat(ResourceUtils.isPersistable(File.create("Foo.java"))).isTrue();
assertThat(ResourceUtils.isPersistable(Directory.create("bar/Foo.java"))).isTrue();
assertThat(ResourceUtils.isPersistable(new Project("foo"))).isTrue();
- assertThat(ResourceUtils.isPersistable(new Library("foo", "1.2"))).isTrue();
}
@Test
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/ScopesTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/ScopesTest.java
index 8364aed52c1..a3561acc9c8 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/ScopesTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/ScopesTest.java
@@ -37,16 +37,6 @@ public class ScopesTest {
}
@Test
- public void testLibrary() {
- Resource resource = new Library("key", "1.0");
- assertThat(Scopes.isProject(resource), is(true));
- assertThat(Scopes.isDirectory(resource), is(false));
- assertThat(Scopes.isFile(resource), is(false));
- assertThat(Scopes.isBlockUnit(resource), is(false));
- assertThat(Scopes.isProgramUnit(resource), is(false));
- }
-
- @Test
public void testDirectory() {
Resource resource = Directory.create("org/foo");
assertThat(Scopes.isProject(resource), is(false));