aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-graph
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-11-07 15:53:07 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2014-11-07 16:15:09 +0100
commit07dee4c58e8be5e83c3c3c17ee2c47600ccf27e6 (patch)
tree951a2857990ea8148130c682c2f6260940bcb948 /sonar-graph
parent1ce597bb9c13cc9b403da355b48e2188344fed71 (diff)
downloadsonarqube-07dee4c58e8be5e83c3c3c17ee2c47600ccf27e6.tar.gz
sonarqube-07dee4c58e8be5e83c3c3c17ee2c47600ccf27e6.zip
SONAR-5672 Don't save DSM when there is no dependency or more than 200 components
Diffstat (limited to 'sonar-graph')
-rw-r--r--sonar-graph/src/main/java/org/sonar/graph/DirectedGraph.java10
-rw-r--r--sonar-graph/src/main/java/org/sonar/graph/Dsm.java34
-rw-r--r--sonar-graph/src/main/java/org/sonar/graph/DsmScanner.java6
-rw-r--r--sonar-graph/src/main/java/org/sonar/graph/FeedbackCycle.java12
-rw-r--r--sonar-graph/src/main/java/org/sonar/graph/IncrementalCyclesAndFESSolver.java6
-rw-r--r--sonar-graph/src/main/java/org/sonar/graph/MinimumFeedbackEdgeSetSolver.java14
6 files changed, 50 insertions, 32 deletions
diff --git a/sonar-graph/src/main/java/org/sonar/graph/DirectedGraph.java b/sonar-graph/src/main/java/org/sonar/graph/DirectedGraph.java
index ecbb0fb6d72..c0d63887b89 100644
--- a/sonar-graph/src/main/java/org/sonar/graph/DirectedGraph.java
+++ b/sonar-graph/src/main/java/org/sonar/graph/DirectedGraph.java
@@ -22,7 +22,7 @@ package org.sonar.graph;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -32,7 +32,7 @@ public class DirectedGraph<V, E extends Edge<V>> implements DirectedGraphAccesso
private EdgeFactory<V, E> edgeFactory;
private Map<V, Map<V, E>> outgoingEdgesByVertex = new HashMap<V, Map<V, E>>();
private Map<V, Map<V, E>> incomingEdgesByVertex = new HashMap<V, Map<V, E>>();
- private Set<V> vertices = new HashSet<V>();
+ private Set<V> vertices = new LinkedHashSet<V>();
public DirectedGraph() {
}
@@ -60,7 +60,7 @@ public class DirectedGraph<V, E extends Edge<V>> implements DirectedGraphAccesso
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.");
+ "EdgeFactory<V, E> has not been defined. Please use the 'public E addEdge(V from, V to, E edge)' method.");
}
}
@@ -133,7 +133,7 @@ public class DirectedGraph<V, E extends Edge<V>> implements DirectedGraphAccesso
public Collection<E> getOutgoingEdges(V from) {
Map<V, E> outgoingEdges = outgoingEdgesByVertex.get(from);
if (outgoingEdges == null) {
- return new HashSet<E>();
+ return new LinkedHashSet<E>();
}
return outgoingEdges.values();
}
@@ -142,7 +142,7 @@ public class DirectedGraph<V, E extends Edge<V>> implements DirectedGraphAccesso
public Collection<E> getIncomingEdges(V to) {
Map<V, E> incomingEdges = incomingEdgesByVertex.get(to);
if (incomingEdges == null) {
- return new HashSet<E>();
+ return new LinkedHashSet<E>();
}
return incomingEdges.values();
}
diff --git a/sonar-graph/src/main/java/org/sonar/graph/Dsm.java b/sonar-graph/src/main/java/org/sonar/graph/Dsm.java
index fc9f386fff2..69e85c251da 100644
--- a/sonar-graph/src/main/java/org/sonar/graph/Dsm.java
+++ b/sonar-graph/src/main/java/org/sonar/graph/Dsm.java
@@ -27,17 +27,17 @@ import java.util.Set;
public class Dsm<V> {
- private V[] vertices;
- private DsmCell[][] cells;
- private int dimension;
- private DirectedGraphAccessor<V, ? extends Edge<V>> graph;
+ private final V[] vertices;
+ private final DsmCell[][] cells;
+ private final int dimension;
+ private final DirectedGraphAccessor<V, ? extends Edge<V>> graph;
+ private boolean atLeastOneDependency = false;
public Dsm(DirectedGraphAccessor<V, ? extends Edge<V>> graph, Collection<V> vertices, Set<Edge> feedbackEdges) {
this.graph = graph;
this.dimension = vertices.size();
- this.cells = new DsmCell[dimension][dimension];
- initVertices(vertices);
- initCells(feedbackEdges);
+ this.vertices = initVertices(vertices);
+ this.cells = initCells(feedbackEdges);
}
public Dsm(DirectedGraphAccessor<V, ? extends Edge<V>> acyclicGraph, Set<Edge> feedbackEdges) {
@@ -48,7 +48,8 @@ public class Dsm<V> {
this(acyclicGraph, acyclicGraph.getVertices(), Collections.<Edge>emptySet());
}
- private void initCells(Set<Edge> feedbackEdges) {
+ private DsmCell[][] initCells(Set<Edge> feedbackEdges) {
+ DsmCell[][] cells = new DsmCell[dimension][dimension];
for (int x = 0; x < dimension; x++) {
for (int y = 0; y < dimension; y++) {
V from = vertices[x];
@@ -56,20 +57,23 @@ public class Dsm<V> {
Edge<V> edge = graph.getEdge(from, to);
if (edge != null) {
+ atLeastOneDependency = true;
boolean isFeedbackEdge = feedbackEdges.contains(edge);
cells[x][y] = new DsmCell(edge, isFeedbackEdge);
}
}
}
+ return cells;
}
- private void initVertices(Collection<V> verticesCol) {
- this.vertices = (V[]) new Object[dimension];
+ private V[] initVertices(Collection<V> verticesCol) {
+ V[] vertices = (V[]) new Object[dimension];
int i = 0;
for (V vertex : verticesCol) {
vertices[i] = vertex;
i++;
}
+ return vertices;
}
public V getVertex(int rowIndex) {
@@ -159,11 +163,21 @@ public class Dsm<V> {
return cell != null ? cell : new DsmCell(null, false);
}
+ /**
+ * @since 5.0
+ */
@CheckForNull
public DsmCell cell(int x, int y) {
return cells[x][y];
}
+ /**
+ * @since 5.0
+ */
+ public boolean hasAtLeastOneDependency() {
+ return atLeastOneDependency;
+ }
+
public V[] getVertices() {
V[] verticesCopy = (V[]) new Object[vertices.length];
System.arraycopy(vertices, 0, verticesCopy, 0, vertices.length);
diff --git a/sonar-graph/src/main/java/org/sonar/graph/DsmScanner.java b/sonar-graph/src/main/java/org/sonar/graph/DsmScanner.java
index 4057748c2c6..beb5318f74b 100644
--- a/sonar-graph/src/main/java/org/sonar/graph/DsmScanner.java
+++ b/sonar-graph/src/main/java/org/sonar/graph/DsmScanner.java
@@ -26,7 +26,7 @@ import java.io.LineNumberReader;
import java.io.Reader;
import java.io.StringReader;
import java.util.Arrays;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
import java.util.Set;
public final class DsmScanner {
@@ -36,7 +36,7 @@ public final class DsmScanner {
private static final char FEEDBACK_EDGE_FLAG = '*';
private final DirectedGraph<String, StringEdge> graph = DirectedGraph.createStringDirectedGraph();
private String[] vertices;
- private Set<Edge> feedbackEdges = new HashSet<Edge>();
+ private Set<Edge> feedbackEdges = new LinkedHashSet<Edge>();
private DsmScanner(Reader reader) {
this.reader = new LineNumberReader(reader);
@@ -49,7 +49,7 @@ public final class DsmScanner {
readRow(i);
}
} catch (IOException e) {
- throw new RuntimeException("Unable to read DSM content.", e); //NOSONAR
+ throw new RuntimeException("Unable to read DSM content.", e); // NOSONAR
}
Dsm<String> dsm = new Dsm<String>(graph, graph.getVertices(), feedbackEdges);
DsmManualSorter.sort(dsm, Arrays.asList(vertices));
diff --git a/sonar-graph/src/main/java/org/sonar/graph/FeedbackCycle.java b/sonar-graph/src/main/java/org/sonar/graph/FeedbackCycle.java
index 81de9669e43..7a22fcd0c0d 100644
--- a/sonar-graph/src/main/java/org/sonar/graph/FeedbackCycle.java
+++ b/sonar-graph/src/main/java/org/sonar/graph/FeedbackCycle.java
@@ -20,15 +20,15 @@
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;
-import com.google.common.collect.HashMultiset;
-import com.google.common.collect.Multiset;
-
/**
* Note: this class has a natural ordering that is inconsistent with equals
*/
@@ -70,7 +70,7 @@ public final class FeedbackCycle implements Iterable<FeedbackEdge>, Comparable<F
}
private static Multiset<Edge> createBagWithAllEdgesOfCycles(Set<Cycle> cycles) {
- Multiset<Edge> edgesBag = HashMultiset.create();
+ Multiset<Edge> edgesBag = LinkedHashMultiset.create();
for (Cycle cycle : cycles) {
for (Edge edge : cycle.getEdges()) {
edgesBag.add(edge);
@@ -94,7 +94,9 @@ public final class FeedbackCycle implements Iterable<FeedbackEdge>, Comparable<F
@Override
public int compareTo(FeedbackCycle feedbackCycle) {
- if (getTotalOccurrencesOfEdgesInCycle() < feedbackCycle.getTotalOccurrencesOfEdgesInCycle()) {//NOSONAR this class has a natural ordering that is inconsistent with equals
+ if (getTotalOccurrencesOfEdgesInCycle() < feedbackCycle.getTotalOccurrencesOfEdgesInCycle()) {// NOSONAR this class has a natural
+ // ordering that is inconsistent with
+ // equals
return -1;
}
if (getTotalOccurrencesOfEdgesInCycle() == feedbackCycle.getTotalOccurrencesOfEdgesInCycle()) {
diff --git a/sonar-graph/src/main/java/org/sonar/graph/IncrementalCyclesAndFESSolver.java b/sonar-graph/src/main/java/org/sonar/graph/IncrementalCyclesAndFESSolver.java
index 576f461e4c1..cd814c615f4 100644
--- a/sonar-graph/src/main/java/org/sonar/graph/IncrementalCyclesAndFESSolver.java
+++ b/sonar-graph/src/main/java/org/sonar/graph/IncrementalCyclesAndFESSolver.java
@@ -20,12 +20,12 @@
package org.sonar.graph;
import java.util.Collection;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
import java.util.Set;
public class IncrementalCyclesAndFESSolver<V> {
- private Set<Cycle> cycles = new HashSet<Cycle>();
+ private Set<Cycle> cycles = new LinkedHashSet<Cycle>();
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;
@@ -37,7 +37,7 @@ public class IncrementalCyclesAndFESSolver<V> {
}
public IncrementalCyclesAndFESSolver(DirectedGraphAccessor<V, ? extends Edge> graph, Collection<V> vertices, int maxSearchDepthAtFirst,
- int maxCyclesToFoundByIteration) {
+ int maxCyclesToFoundByIteration) {
iterations++;
CycleDetector<V> cycleDetector = new CycleDetector<V>(graph, vertices);
diff --git a/sonar-graph/src/main/java/org/sonar/graph/MinimumFeedbackEdgeSetSolver.java b/sonar-graph/src/main/java/org/sonar/graph/MinimumFeedbackEdgeSetSolver.java
index 39a5c374b9f..aaebdced22c 100644
--- a/sonar-graph/src/main/java/org/sonar/graph/MinimumFeedbackEdgeSetSolver.java
+++ b/sonar-graph/src/main/java/org/sonar/graph/MinimumFeedbackEdgeSetSolver.java
@@ -19,7 +19,9 @@
*/
package org.sonar.graph;
-import java.util.*;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
public class MinimumFeedbackEdgeSetSolver {
@@ -62,7 +64,7 @@ public class MinimumFeedbackEdgeSetSolver {
* Get edges tagged as feedback.
*/
public Set<Edge> getEdges() {
- Set<Edge> edges = new HashSet<Edge>();
+ Set<Edge> edges = new LinkedHashSet<Edge>();
for (FeedbackEdge fe : feedbackEdges) {
edges.add(fe.getEdge());
}
@@ -70,7 +72,7 @@ public class MinimumFeedbackEdgeSetSolver {
}
private void run() {
- Set<FeedbackEdge> pendingFeedbackEdges = new HashSet<FeedbackEdge>();
+ Set<FeedbackEdge> pendingFeedbackEdges = new LinkedHashSet<FeedbackEdge>();
if (cyclesNumber < maxNumberCyclesForSearchingMinimumFeedback) {
searchFeedbackEdges(0, 0, pendingFeedbackEdges);
} else {
@@ -79,7 +81,7 @@ public class MinimumFeedbackEdgeSetSolver {
}
private void lightResearchForFeedbackEdges() {
- feedbackEdges = new HashSet<FeedbackEdge>();
+ feedbackEdges = new LinkedHashSet<FeedbackEdge>();
for (FeedbackCycle cycle : feedbackCycles) {
for (FeedbackEdge edge : cycle) {
feedbackEdges.add(edge);
@@ -87,7 +89,7 @@ public class MinimumFeedbackEdgeSetSolver {
}
}
minimumFeedbackEdgesWeight = 0;
- for(FeedbackEdge edge : feedbackEdges) {
+ for (FeedbackEdge edge : feedbackEdges) {
minimumFeedbackEdgesWeight += edge.getWeight();
}
}
@@ -103,7 +105,7 @@ public class MinimumFeedbackEdgeSetSolver {
if (level == cyclesNumber) {
minimumFeedbackEdgesWeight = pendingWeight;
- feedbackEdges = new HashSet<FeedbackEdge>(pendingFeedbackEdges);
+ feedbackEdges = new LinkedHashSet<FeedbackEdge>(pendingFeedbackEdges);
return;
}