From 1bee96aec33f4fa92c82a2d4359ae47e9b42a51a Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Tue, 10 Nov 2015 17:12:59 +0100 Subject: Improve quality --- .../main/java/org/sonar/batch/cache/WSLoader.java | 6 ++--- .../org/sonar/batch/issue/TrackedIssueAdapter.java | 2 +- .../java/org/sonar/batch/rule/QProfileSensor.java | 2 +- .../scan/filesystem/DefaultModuleFileSystem.java | 28 ++++++++-------------- .../org/sonar/batch/scan/report/JSONReport.java | 2 +- 5 files changed, 16 insertions(+), 24 deletions(-) (limited to 'sonar-batch') diff --git a/sonar-batch/src/main/java/org/sonar/batch/cache/WSLoader.java b/sonar-batch/src/main/java/org/sonar/batch/cache/WSLoader.java index 5845469dcf9..13845f0808e 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/cache/WSLoader.java +++ b/sonar-batch/src/main/java/org/sonar/batch/cache/WSLoader.java @@ -122,7 +122,7 @@ public class WSLoader { } private int getReadTimeout() { - return userProperties.properties().containsKey(SONAR_WS_TIMEOUT_PROPS) ? Integer.parseInt(userProperties.property(SONAR_WS_TIMEOUT_PROPS)) * 1000 : DEFAULT_READ_TIMEOUT; + return userProperties.properties().containsKey(SONAR_WS_TIMEOUT_PROPS) ? (Integer.parseInt(userProperties.property(SONAR_WS_TIMEOUT_PROPS)) * 1000) : DEFAULT_READ_TIMEOUT; } @Nonnull @@ -221,7 +221,7 @@ public class WSLoader { if (result == null) { throw new NotAvailableException("resource not cached"); } - return new WSLoaderResult(result, true); + return new WSLoaderResult<>(result, true); } @Nonnull @@ -232,7 +232,7 @@ public class WSLoader { try { T t = loader.load(id); switchToOnline(); - return new WSLoaderResult(t, false); + return new WSLoaderResult<>(t, false); } catch (IllegalStateException e) { if (e.getCause() instanceof HttpException) { // fail fast if it could connect but there was a application-level error diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/TrackedIssueAdapter.java b/sonar-batch/src/main/java/org/sonar/batch/issue/TrackedIssueAdapter.java index 3776236ae1e..575df94cd5f 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/TrackedIssueAdapter.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/TrackedIssueAdapter.java @@ -107,7 +107,7 @@ public class TrackedIssueAdapter implements Issue { @Override public Date creationDate() { - return null; + return issue.getCreationDate(); } @Override diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileSensor.java b/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileSensor.java index 0f2d528a49c..8215cba4b29 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileSensor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileSensor.java @@ -61,7 +61,7 @@ public class QProfileSensor implements Sensor { used.add(profile); } } - Measure detailsMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, used.toJson()); + Measure detailsMeasure = new Measure<>(CoreMetrics.QUALITY_PROFILES, used.toJson()); context.saveMeasure(detailsMeasure); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java index ad73100f467..f57c5db36f9 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java @@ -53,9 +53,9 @@ import org.sonar.api.utils.MessageException; */ public class DefaultModuleFileSystem extends DefaultFileSystem implements ModuleFileSystem { - private final String moduleKey; - private final FileIndexer indexer; - private final Settings settings; + private String moduleKey; + private FileIndexer indexer; + private Settings settings; private File buildDir; private List sourceDirsOrFiles = Lists.newArrayList(); @@ -67,26 +67,18 @@ public class DefaultModuleFileSystem extends DefaultFileSystem implements Module public DefaultModuleFileSystem(ModuleInputFileCache moduleInputFileCache, Project project, Settings settings, FileIndexer indexer, ModuleFileSystemInitializer initializer, ComponentIndexer componentIndexer, DefaultAnalysisMode mode) { super(initializer.baseDir(), moduleInputFileCache); - this.componentIndexer = componentIndexer; - this.moduleKey = project.getKey(); - this.settings = settings; - this.indexer = indexer; - setWorkDir(initializer.workingDir()); - this.buildDir = initializer.buildDir(); - this.sourceDirsOrFiles = initializer.sources(); - this.testDirsOrFiles = initializer.tests(); - this.binaryDirs = initializer.binaryDirs(); - - // filter the files that sensors have access to (SONAR-6931) - if (!mode.scanAllFiles()) { - setDefaultPredicate(predicates.not(predicates.hasStatus(Status.SAME))); - } + setFields(project, settings, indexer, initializer, componentIndexer, mode); } @VisibleForTesting public DefaultModuleFileSystem(Project project, Settings settings, FileIndexer indexer, ModuleFileSystemInitializer initializer, ComponentIndexer componentIndexer, DefaultAnalysisMode mode) { super(initializer.baseDir().toPath()); + setFields(project, settings, indexer, initializer, componentIndexer, mode); + } + + private void setFields(Project project, + Settings settings, FileIndexer indexer, ModuleFileSystemInitializer initializer, ComponentIndexer componentIndexer, DefaultAnalysisMode mode) { this.componentIndexer = componentIndexer; this.moduleKey = project.getKey(); this.settings = settings; @@ -96,7 +88,7 @@ public class DefaultModuleFileSystem extends DefaultFileSystem implements Module this.sourceDirsOrFiles = initializer.sources(); this.testDirsOrFiles = initializer.tests(); this.binaryDirs = initializer.binaryDirs(); - + // filter the files sensors have access to if (!mode.scanAllFiles()) { setDefaultPredicate(predicates.not(predicates.hasStatus(Status.SAME))); diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/JSONReport.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/JSONReport.java index f7cd9bf6e0b..6f7965fa069 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/JSONReport.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/JSONReport.java @@ -219,7 +219,7 @@ public class JSONReport implements Reporter { } private void writeUsers(JsonWriter json, Collection userLogins) throws IOException { - List users = new LinkedList(); + List users = new LinkedList<>(); for (String userLogin : userLogins) { User user = userRepository.load(userLogin); if (user != null) { -- cgit v1.2.3