From 33080cbd8883a540a0e366923d47ebbfb2683984 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Thu, 3 Apr 2014 18:13:34 +0200 Subject: [PATCH] Fix some quality flaws --- .../org/sonar/batch/scan/ProjectReactorBuilder.java | 13 ++++++++----- .../api/batch/bootstrap/ProjectDefinition.java | 9 +++++++-- .../sonar/api/component/mock/MockSourceFile.java | 6 ------ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java index 181e66670d5..6fcd09ad568 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java @@ -35,11 +35,13 @@ import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.batch.bootstrap.BootstrapSettings; import javax.annotation.CheckForNull; +import javax.annotation.Nullable; import java.io.File; import java.io.FileFilter; import java.io.FileInputStream; import java.io.IOException; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -51,6 +53,8 @@ import java.util.Properties; */ public class ProjectReactorBuilder { + private static final String INVALID_VALUE_OF_X_FOR_Y = "Invalid value of {0} for {1}"; + private static final Logger LOG = LoggerFactory.getLogger(ProjectReactorBuilder.class); /** @@ -114,7 +118,7 @@ public class ProjectReactorBuilder { return new ProjectReactor(rootProject); } - protected ProjectDefinition defineProject(Properties properties, ProjectDefinition parent) { + protected ProjectDefinition defineProject(Properties properties, @Nullable ProjectDefinition parent) { File baseDir = new File(properties.getProperty(PROPERTY_PROJECT_BASEDIR)); if (properties.containsKey(PROPERTY_MODULES)) { checkMandatoryProperties(properties, MANDATORY_PROPERTIES_FOR_MULTIMODULE_PROJECT); @@ -130,11 +134,10 @@ public class ProjectReactorBuilder { workDir = initModuleWorkDir(baseDir, properties); } - ProjectDefinition definition = ProjectDefinition.create().setProperties(properties) + return ProjectDefinition.create().setProperties(properties) .setBaseDir(baseDir) .setWorkDir(workDir) .setBuildDir(initModuleBuildDir(baseDir, properties)); - return definition; } @VisibleForTesting @@ -295,7 +298,7 @@ public class ProjectReactorBuilder { for (String pattern : getListFromProperty(props, PROPERTY_LIBRARIES)) { File[] files = getLibraries(baseDir, pattern); if (files == null || files.length == 0) { - LOG.error("Invalid value of " + PROPERTY_LIBRARIES + " for " + projectId); + LOG.error(MessageFormat.format(INVALID_VALUE_OF_X_FOR_Y, PROPERTY_LIBRARIES, projectId)); throw new IllegalStateException("No files nor directories matching '" + pattern + "' in directory " + baseDir); } } @@ -416,7 +419,7 @@ public class ProjectReactorBuilder { for (String path : sourceDirs) { File sourceFolder = resolvePath(baseDir, path); if (!sourceFolder.isDirectory()) { - LOG.error("Invalid value of " + propName + " for " + moduleRef); + LOG.error(MessageFormat.format(INVALID_VALUE_OF_X_FOR_Y, propName, moduleRef)); throw new IllegalStateException("The folder '" + path + "' does not exist for '" + moduleRef + "' (base directory = " + baseDir.getAbsolutePath() + ")"); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java index 1df8ecfc4bf..62c4da3d653 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java @@ -23,6 +23,9 @@ import com.google.common.collect.Lists; import org.apache.commons.lang.StringUtils; import org.sonar.api.CoreProperties; +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; + import java.io.File; import java.util.List; import java.util.Properties; @@ -80,20 +83,22 @@ public class ProjectDefinition { return baseDir; } - public ProjectDefinition setWorkDir(File workDir) { + public ProjectDefinition setWorkDir(@Nullable File workDir) { this.workDir = workDir; return this; } + @CheckForNull public File getWorkDir() { return workDir; } - public ProjectDefinition setBuildDir(File d) { + public ProjectDefinition setBuildDir(@Nullable File d) { this.buildDir = d; return this; } + @CheckForNull public File getBuildDir() { return buildDir; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/component/mock/MockSourceFile.java b/sonar-plugin-api/src/main/java/org/sonar/api/component/mock/MockSourceFile.java index 1c6e70a7863..61422d00169 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/component/mock/MockSourceFile.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/component/mock/MockSourceFile.java @@ -24,7 +24,6 @@ import org.sonar.api.component.SourceFile; public class MockSourceFile implements SourceFile { private String key; private String path; - private String moduleKey; private String qualifier; private String language; private String name; @@ -52,11 +51,6 @@ public class MockSourceFile implements SourceFile { return this; } - public MockSourceFile setModuleKey(String moduleKey) { - this.moduleKey = moduleKey; - return this; - } - public String qualifier() { return qualifier; } -- 2.39.5