aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-06-20 11:53:57 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-06-20 12:03:10 +0200
commit4cb80adde707a46e28e2e0d414a19a3790767424 (patch)
treed34856e021029cc21ffa293d8c942eddf942551f /sonar-batch
parente70fe0b9efe571d593d29dbc18bb3afea1f56306 (diff)
downloadsonarqube-4cb80adde707a46e28e2e0d414a19a3790767424.tar.gz
sonarqube-4cb80adde707a46e28e2e0d414a19a3790767424.zip
Fix some quality flaws
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/DefaultProjectClasspath.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionDictionnary.java7
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/Bucket.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java11
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java5
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/PersistenceManager.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/mediumtest/AnalyzerMediumTester.java5
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/phases/PhaseExecutor.java10
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/SensorWrapper.java5
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan2/AnalysisPublisher.java (renamed from sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzisPublisher.java)10
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan2/ModuleScanContainer.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan2/ModuleScanExecutor.java8
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionDictionnaryTest.java5
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/XooMediumTest.java2
15 files changed, 39 insertions, 47 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/DefaultProjectClasspath.java b/sonar-batch/src/main/java/org/sonar/batch/DefaultProjectClasspath.java
index 3c124baad67..d497906439f 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/DefaultProjectClasspath.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/DefaultProjectClasspath.java
@@ -25,6 +25,8 @@ import org.sonar.api.batch.ProjectClasspath;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.resources.ProjectFileSystem;
+import javax.annotation.Nullable;
+
import java.io.File;
import java.util.List;
@@ -37,7 +39,7 @@ public class DefaultProjectClasspath extends ProjectClasspath {
this(def, projectFileSystem, null);
}
- public DefaultProjectClasspath(ProjectDefinition def, ProjectFileSystem projectFileSystem, MavenProject pom) {
+ public DefaultProjectClasspath(ProjectDefinition def, ProjectFileSystem projectFileSystem, @Nullable MavenProject pom) {
super(pom);
this.def = def;
this.projectFileSystem = projectFileSystem;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionDictionnary.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionDictionnary.java
index 622a7ef92b9..8d0d2692656 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionDictionnary.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionDictionnary.java
@@ -25,7 +25,6 @@ import org.sonar.api.batch.CheckProject;
import org.sonar.api.batch.Sensor;
import org.sonar.api.batch.analyzer.Analyzer;
import org.sonar.api.batch.analyzer.AnalyzerContext;
-import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.platform.ComponentContainer;
import org.sonar.api.resources.Project;
import org.sonar.batch.scan.SensorWrapper;
@@ -41,13 +40,11 @@ import java.util.List;
*/
public class BatchExtensionDictionnary extends org.sonar.api.batch.BatchExtensionDictionnary {
- private FileSystem fs;
private AnalyzerContext context;
private AnalyzerOptimizer analyzerOptimizer;
- public BatchExtensionDictionnary(ComponentContainer componentContainer, FileSystem fs, AnalyzerContext context, AnalyzerOptimizer analyzerOptimizer) {
+ public BatchExtensionDictionnary(ComponentContainer componentContainer, AnalyzerContext context, AnalyzerOptimizer analyzerOptimizer) {
super(componentContainer);
- this.fs = fs;
this.context = context;
this.analyzerOptimizer = analyzerOptimizer;
}
@@ -64,7 +61,7 @@ public class BatchExtensionDictionnary extends org.sonar.api.batch.BatchExtensio
List<T> result = Lists.newArrayList();
for (Object extension : getExtensions(type)) {
if (type == Sensor.class && extension instanceof Analyzer) {
- extension = new SensorWrapper((Analyzer) extension, context, fs, analyzerOptimizer);
+ extension = new SensorWrapper((Analyzer) extension, context, analyzerOptimizer);
}
if (shouldKeep(type, extension, project, matcher)) {
result.add((T) extension);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/Bucket.java b/sonar-batch/src/main/java/org/sonar/batch/index/Bucket.java
index ea4ed3b11a0..5f058e3632d 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/Bucket.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/Bucket.java
@@ -22,6 +22,8 @@ package org.sonar.batch.index;
import com.google.common.collect.Lists;
import org.sonar.api.resources.Resource;
+import javax.annotation.Nullable;
+
import java.util.Collections;
import java.util.List;
@@ -40,7 +42,7 @@ public final class Bucket {
return resource;
}
- public Bucket setParent(Bucket parent) {
+ public Bucket setParent(@Nullable Bucket parent) {
this.parent = parent;
if (parent != null) {
parent.addChild(this);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java
index 1e6f9d8af48..4e9082bc458 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java
@@ -36,6 +36,7 @@ import org.sonar.api.resources.Scopes;
import org.sonar.api.security.ResourcePermissions;
import org.sonar.api.utils.SonarException;
+import javax.annotation.Nullable;
import javax.persistence.NonUniqueResultException;
import javax.persistence.Query;
@@ -65,7 +66,7 @@ public final class DefaultResourcePersister implements ResourcePersister {
this.resourceCache = resourceCache;
}
- public Snapshot saveProject(Project project, Project parent) {
+ public Snapshot saveProject(Project project, @Nullable Project parent) {
Snapshot snapshot = snapshotsByResource.get(project);
if (snapshot == null) {
snapshot = persistProject(project, parent);
@@ -85,7 +86,7 @@ public final class DefaultResourcePersister implements ResourcePersister {
}
}
- private Snapshot persistProject(Project project, Project parent) {
+ private Snapshot persistProject(Project project, @Nullable Project parent) {
// temporary hack
project.setEffectiveKey(project.getKey());
@@ -157,7 +158,7 @@ public final class DefaultResourcePersister implements ResourcePersister {
return saveResource(project, resource, null);
}
- public Snapshot saveResource(Project project, Resource resource, Resource parent) {
+ public Snapshot saveResource(Project project, Resource resource, @Nullable Resource parent) {
Snapshot snapshot = snapshotsByResource.get(resource);
if (snapshot == null) {
snapshot = persist(project, resource, parent);
@@ -166,7 +167,7 @@ public final class DefaultResourcePersister implements ResourcePersister {
return snapshot;
}
- private Snapshot persist(Project project, Resource resource, Resource parent) {
+ private Snapshot persist(Project project, Resource resource, @Nullable Resource parent) {
Snapshot snapshot;
if (resource instanceof Project) {
// should not occur, please use the method saveProject()
@@ -224,7 +225,7 @@ public final class DefaultResourcePersister implements ResourcePersister {
/**
* Everything except project and library
*/
- private Snapshot persistFileOrDirectory(Project project, Resource resource, Resource parentReference) {
+ private Snapshot persistFileOrDirectory(Project project, Resource resource, @Nullable Resource parentReference) {
Snapshot moduleSnapshot = snapshotsByResource.get(project);
Integer moduleId = moduleSnapshot.getResourceId();
ResourceModel model = findOrCreateModel(resource);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java
index e317fe80566..2a63d4b8b9e 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java
@@ -82,7 +82,10 @@ public final class MeasurePersister implements ScanPersister {
@VisibleForTesting
static boolean shouldPersistMeasure(@Nullable Resource resource, @Nullable Measure measure) {
- return resource != null && measure != null && measure.getPersistenceMode().useDatabase() &&
+ if (resource == null || measure == null) {
+ return false;
+ }
+ return measure.getPersistenceMode().useDatabase() &&
!(ResourceUtils.isEntity(resource) && measure.isBestValue()) && isMeasureNotEmpty(measure);
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/PersistenceManager.java b/sonar-batch/src/main/java/org/sonar/batch/index/PersistenceManager.java
index d90f63d8b66..b97baa1b8ea 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/PersistenceManager.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/PersistenceManager.java
@@ -26,12 +26,14 @@ import org.sonar.api.resources.Project;
import org.sonar.api.resources.ProjectLink;
import org.sonar.api.resources.Resource;
+import javax.annotation.Nullable;
+
import java.util.List;
public interface PersistenceManager {
void clear();
- void saveProject(Project project, Project parent);
+ void saveProject(Project project, @Nullable Project parent);
Snapshot saveResource(Project project, Resource resource, Resource parent);
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 8ee6c8faf7d..af78d773c8d 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
@@ -24,9 +24,11 @@ import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
+import javax.annotation.Nullable;
+
public interface ResourcePersister {
- Snapshot saveProject(Project project, Project parent);
+ Snapshot saveProject(Project project, @Nullable Project parent);
/**
* Persist a resource in database. Returns null if the resource must not be persisted (scope lower than file)
diff --git a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/AnalyzerMediumTester.java b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/AnalyzerMediumTester.java
index c35ccff3216..b55e13ae912 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/AnalyzerMediumTester.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/AnalyzerMediumTester.java
@@ -105,7 +105,8 @@ public class AnalyzerMediumTester {
}
public AnalyzerMediumTesterBuilder registerMetric(Metric<?> metric) {
- metricFinder.add(metricId++, metric);
+ metricFinder.add(metricId, metric);
+ metricId++;
return this;
}
@@ -143,7 +144,7 @@ public class AnalyzerMediumTester {
}
- public void start() throws Throwable {
+ public void start() {
batch.start();
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/PhaseExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/phases/PhaseExecutor.java
index 90bafa7dc3e..5fc37a64dfd 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/phases/PhaseExecutor.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/phases/PhaseExecutor.java
@@ -88,16 +88,6 @@ public final class PhaseExecutor {
this.issueExclusionsLoader = issueExclusionsLoader;
}
- public PhaseExecutor(Phases phases, DecoratorsExecutor decoratorsExecutor,
- MavenPluginsConfigurator mavenPluginsConfigurator, InitializersExecutor initializersExecutor,
- PostJobsExecutor postJobsExecutor, SensorsExecutor sensorsExecutor,
- PersistenceManager persistenceManager, SensorContext sensorContext, DefaultIndex index,
- EventBus eventBus, ProjectInitializer pi, ScanPersister[] persisters, FileSystemLogger fsLogger, JsonReport jsonReport,
- DefaultModuleFileSystem fs, QProfileVerifier profileVerifier, IssueExclusionsLoader issueExclusionsLoader) {
- this(phases, decoratorsExecutor, mavenPluginsConfigurator, initializersExecutor, postJobsExecutor,
- sensorsExecutor, persistenceManager, sensorContext, index, eventBus, null, pi, persisters, fsLogger, jsonReport, fs, profileVerifier, issueExclusionsLoader);
- }
-
public static Collection<Class> getPhaseClasses() {
return Lists.<Class>newArrayList(DecoratorsExecutor.class, MavenPluginsConfigurator.class,
PostJobsExecutor.class, SensorsExecutor.class,
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/SensorWrapper.java b/sonar-batch/src/main/java/org/sonar/batch/scan/SensorWrapper.java
index 701233abbef..5489b9da528 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/SensorWrapper.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/SensorWrapper.java
@@ -26,7 +26,6 @@ import org.sonar.api.batch.SensorContext;
import org.sonar.api.batch.analyzer.Analyzer;
import org.sonar.api.batch.analyzer.AnalyzerContext;
import org.sonar.api.batch.analyzer.internal.DefaultAnalyzerDescriptor;
-import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.measure.Metric;
import org.sonar.api.resources.Project;
import org.sonar.batch.scan2.AnalyzerOptimizer;
@@ -38,17 +37,15 @@ public class SensorWrapper implements Sensor {
private Analyzer analyzer;
private AnalyzerContext adaptor;
- private FileSystem fs;
private DefaultAnalyzerDescriptor descriptor;
private AnalyzerOptimizer optimizer;
- public SensorWrapper(Analyzer analyzer, AnalyzerContext adaptor, FileSystem fs, AnalyzerOptimizer optimizer) {
+ public SensorWrapper(Analyzer analyzer, AnalyzerContext adaptor, AnalyzerOptimizer optimizer) {
this.analyzer = analyzer;
this.optimizer = optimizer;
descriptor = new DefaultAnalyzerDescriptor();
analyzer.describe(descriptor);
this.adaptor = adaptor;
- this.fs = fs;
}
@DependedUpon
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzisPublisher.java b/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalysisPublisher.java
index 2c2e29d9067..c422da9a3c3 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzisPublisher.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalysisPublisher.java
@@ -37,16 +37,16 @@ import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;
-public final class AnalyzisPublisher {
+public final class AnalysisPublisher {
- public static final Logger LOG = LoggerFactory.getLogger(AnalyzisPublisher.class);
+ private static final Logger LOG = LoggerFactory.getLogger(AnalysisPublisher.class);
private final Settings settings;
private final FileSystem fs;
private final AnalyzerMeasureCache measureCache;
private final ProjectDefinition def;
private AnalyzerIssueCache issueCache;
- public AnalyzisPublisher(ProjectDefinition def, Settings settings, FileSystem fs, AnalyzerMeasureCache measureCache, AnalyzerIssueCache analyzerIssueCache) {
+ public AnalysisPublisher(ProjectDefinition def, Settings settings, FileSystem fs, AnalyzerMeasureCache measureCache, AnalyzerIssueCache analyzerIssueCache) {
this.def = def;
this.settings = settings;
this.fs = fs;
@@ -113,7 +113,7 @@ public final class AnalyzisPublisher {
.endObject()
.close();
} catch (IOException e) {
-
+ throw unableToExport(e);
} finally {
IOUtils.closeQuietly(issueWriter);
}
@@ -141,7 +141,7 @@ public final class AnalyzisPublisher {
.endObject()
.close();
} catch (IOException e) {
-
+ throw unableToExport(e);
} finally {
IOUtils.closeQuietly(measureWriter);
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan2/ModuleScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan2/ModuleScanContainer.java
index 6309146221c..d4fc0d708fd 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan2/ModuleScanContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan2/ModuleScanContainer.java
@@ -123,7 +123,7 @@ public class ModuleScanContainer extends ComponentContainer {
EnforceIssuesFilter.class,
IgnoreIssuesFilter.class,
- AnalyzisPublisher.class);
+ AnalysisPublisher.class);
}
private void addExtensions() {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan2/ModuleScanExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/scan2/ModuleScanExecutor.java
index db5406afad4..15e78df740c 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan2/ModuleScanExecutor.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan2/ModuleScanExecutor.java
@@ -20,8 +20,6 @@
package org.sonar.batch.scan2;
import com.google.common.collect.Lists;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.batch.analyzer.AnalyzerContext;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.batch.issue.ignore.scanner.IssueExclusionsLoader;
@@ -34,8 +32,6 @@ import java.util.Collection;
public final class ModuleScanExecutor {
- public static final Logger LOGGER = LoggerFactory.getLogger(ModuleScanExecutor.class);
-
private final AnalyzersExecutor analyzersExecutor;
private final AnalyzerContext analyzerContext;
private final FileSystemLogger fsLogger;
@@ -43,12 +39,12 @@ public final class ModuleScanExecutor {
private final QProfileVerifier profileVerifier;
private final IssueExclusionsLoader issueExclusionsLoader;
- private AnalyzisPublisher analyzisPublisher;
+ private AnalysisPublisher analyzisPublisher;
public ModuleScanExecutor(AnalyzersExecutor analyzersExecutor,
AnalyzerContext analyzerContext,
FileSystemLogger fsLogger, DefaultModuleFileSystem fs, QProfileVerifier profileVerifier,
- IssueExclusionsLoader issueExclusionsLoader, AnalyzisPublisher analyzisPublisher) {
+ IssueExclusionsLoader issueExclusionsLoader, AnalysisPublisher analyzisPublisher) {
this.analyzersExecutor = analyzersExecutor;
this.analyzerContext = analyzerContext;
this.fsLogger = fsLogger;
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionDictionnaryTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionDictionnaryTest.java
index 368dba8268f..796408efea0 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionDictionnaryTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionDictionnaryTest.java
@@ -24,16 +24,15 @@ import org.sonar.api.BatchExtension;
import org.sonar.api.batch.Sensor;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.batch.analyzer.AnalyzerContext;
-import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.platform.ComponentContainer;
import org.sonar.api.resources.Project;
import org.sonar.batch.scan2.AnalyzerOptimizer;
import java.util.Collection;
+import static org.hamcrest.Matchers.hasItem;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
-import static org.hamcrest.Matchers.hasItem;
import static org.mockito.Mockito.mock;
public class BatchExtensionDictionnaryTest {
@@ -43,7 +42,7 @@ public class BatchExtensionDictionnaryTest {
for (BatchExtension extension : extensions) {
iocContainer.addSingleton(extension);
}
- return new BatchExtensionDictionnary(iocContainer, mock(FileSystem.class), mock(AnalyzerContext.class), mock(AnalyzerOptimizer.class));
+ return new BatchExtensionDictionnary(iocContainer, mock(AnalyzerContext.class), mock(AnalyzerOptimizer.class));
}
@Test
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/XooMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/XooMediumTest.java
index 6a9fdb2403f..14a22cbb14c 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/XooMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/XooMediumTest.java
@@ -55,7 +55,7 @@ public class XooMediumTest {
.build();
@Before
- public void prepare() throws Throwable {
+ public void prepare() {
tester.start();
}