diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-06-30 16:08:07 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2015-06-30 16:08:20 +0200 |
commit | 0063b92f605464e8d684e5e4aabc41c23a04f513 (patch) | |
tree | 1784a758b2fb9807a6f0147020c4394df64cbaab | |
parent | 3f109b182cd3fa3d80f3a3b56e90fa4283e64e86 (diff) | |
download | sonarqube-0063b92f605464e8d684e5e4aabc41c23a04f513.tar.gz sonarqube-0063b92f605464e8d684e5e4aabc41c23a04f513.zip |
Fix some quality flaws
16 files changed, 162 insertions, 175 deletions
diff --git a/microbenchmark-template/pom.xml b/microbenchmark-template/pom.xml index 7a07993a8b8..261b3d4a58d 100644 --- a/microbenchmark-template/pom.xml +++ b/microbenchmark-template/pom.xml @@ -5,7 +5,7 @@ <parent> <groupId>org.codehaus.sonar</groupId> <artifactId>sonar</artifactId> - <version>5.1-SNAPSHOT</version> + <version>5.2-SNAPSHOT</version> </parent> <artifactId>microbenchmark-template</artifactId> <packaging>jar</packaging> diff --git a/microbenchmark-template/src/main/java/org/sonar/microbenchmark/FileSourceDbBenchmark.java b/microbenchmark-template/src/main/java/org/sonar/microbenchmark/FileSourceDbBenchmark.java index 99bd0c1026f..94110d436cc 100644 --- a/microbenchmark-template/src/main/java/org/sonar/microbenchmark/FileSourceDbBenchmark.java +++ b/microbenchmark-template/src/main/java/org/sonar/microbenchmark/FileSourceDbBenchmark.java @@ -20,6 +20,11 @@ package org.sonar.microbenchmark; import com.google.protobuf.CodedOutputStream; +import java.io.ByteArrayOutputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.TimeUnit; import org.apache.commons.lang.RandomStringUtils; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; @@ -38,12 +43,6 @@ import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import org.sonar.server.source.db.FileSourceDb; -import java.io.ByteArrayOutputStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.TimeUnit; - /** * * See https://code.google.com/p/xxhash/ and https://github.com/jpountz/lz4-java @@ -79,7 +78,7 @@ public class FileSourceDbBenchmark { .setSource(RandomStringUtils.randomAlphanumeric(10)) .setHighlighting(RandomStringUtils.randomAlphanumeric(20)) .setSymbols(RandomStringUtils.randomAlphanumeric(20)) - .addAllDuplications(Arrays.asList(12,13,15)) + .addAllDuplication(Arrays.asList(12, 13, 15)) .build()); } data = builder.build(); diff --git a/microbenchmark-template/src/main/java/org/sonar/microbenchmark/SerializationBenchmark.java b/microbenchmark-template/src/main/java/org/sonar/microbenchmark/SerializationBenchmark.java index 7286eabff3b..ff9361d7a0c 100644 --- a/microbenchmark-template/src/main/java/org/sonar/microbenchmark/SerializationBenchmark.java +++ b/microbenchmark-template/src/main/java/org/sonar/microbenchmark/SerializationBenchmark.java @@ -24,6 +24,21 @@ import com.esotericsoftware.kryo.io.Output; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.stream.JsonWriter; +import java.io.BufferedOutputStream; +import java.io.BufferedWriter; +import java.io.Externalizable; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.ObjectOutputStream; +import java.io.OutputStream; +import java.io.Serializable; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.TimeUnit; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; @@ -41,22 +56,6 @@ import org.openjdk.jmh.runner.options.OptionsBuilder; import org.sonar.batch.protocol.Constants; import org.sonar.batch.protocol.output.BatchReport; -import java.io.BufferedOutputStream; -import java.io.BufferedWriter; -import java.io.Externalizable; -import java.io.File; -import java.io.FileOutputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.io.ObjectOutputStream; -import java.io.OutputStream; -import java.io.Serializable; -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.TimeUnit; - @OutputTimeUnit(TimeUnit.MILLISECONDS) @State(Scope.Thread) @Fork(1) @@ -103,7 +102,7 @@ public class SerializationBenchmark { issueBuilder.setMsg("this is the message of issue " + i); issueBuilder.setLine(i); issueBuilder.setAuthorLogin("someone"); - issueBuilder.addAllTags(Arrays.asList("tag" + i, "othertag" + i)); + issueBuilder.addAllTag(Arrays.asList("tag" + i, "othertag" + i)); issueBuilder.build().writeDelimitedTo(out); } } 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 dfd3a7c009c..ee49c44441a 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 @@ -22,6 +22,15 @@ package org.sonar.batch.bootstrap; import com.google.common.base.Predicates; import com.google.common.collect.Collections2; import com.google.common.collect.Lists; +import java.lang.annotation.Annotation; +import java.lang.reflect.Array; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import javax.annotation.Nullable; import org.apache.commons.lang.ClassUtils; import org.sonar.api.batch.CheckProject; import org.sonar.api.batch.DependedUpon; @@ -31,7 +40,6 @@ import org.sonar.api.batch.postjob.PostJob; import org.sonar.api.batch.postjob.PostJobContext; import org.sonar.api.batch.sensor.Sensor; import org.sonar.api.batch.sensor.SensorContext; -import org.sonar.core.platform.ComponentContainer; import org.sonar.api.resources.Project; import org.sonar.api.utils.AnnotationUtils; import org.sonar.api.utils.dag.DirectAcyclicGraph; @@ -40,17 +48,7 @@ import org.sonar.batch.postjob.PostJobWrapper; import org.sonar.batch.sensor.DefaultSensorContext; import org.sonar.batch.sensor.SensorOptimizer; import org.sonar.batch.sensor.SensorWrapper; - -import javax.annotation.Nullable; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Array; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; +import org.sonar.core.platform.ComponentContainer; /** * @since 2.6 @@ -245,7 +243,7 @@ public class BatchExtensionDictionnary { } } - private void checkAnnotatedMethod(Method method) { + private static void checkAnnotatedMethod(Method method) { if (!Modifier.isPublic(method.getModifiers())) { throw new IllegalStateException("Annotated method must be public:" + method); } @@ -254,7 +252,7 @@ public class BatchExtensionDictionnary { } } - private boolean shouldKeep(Class type, Object extension, @Nullable Project project, @Nullable ExtensionMatcher matcher) { + private static boolean shouldKeep(Class type, Object extension, @Nullable Project project, @Nullable ExtensionMatcher matcher) { boolean keep = (ClassUtils.isAssignable(extension.getClass(), type) || (org.sonar.api.batch.Sensor.class.equals(type) && ClassUtils.isAssignable(extension.getClass(), Sensor.class))) && (matcher == null || matcher.accept(extension)); diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java index c0574deddd6..4f40634966f 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java @@ -19,7 +19,6 @@ */ package org.sonar.batch.bootstrap; -import org.sonar.home.cache.PersistentCache; import com.google.common.base.Joiner; import com.google.common.base.Preconditions; import com.google.common.base.Strings; @@ -29,17 +28,6 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang.StringEscapeUtils; -import org.apache.commons.lang.StringUtils; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.CoreProperties; -import org.sonar.api.utils.HttpDownloader; -import org.sonar.batch.bootstrapper.EnvironmentInformation; -import org.sonar.core.util.DefaultHttpDownloader; - -import javax.annotation.Nullable; - import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; @@ -50,6 +38,16 @@ import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; import java.util.concurrent.Callable; +import javax.annotation.Nullable; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.StringEscapeUtils; +import org.apache.commons.lang.StringUtils; +import org.sonar.api.CoreProperties; +import org.sonar.api.batch.BatchSide; +import org.sonar.api.utils.HttpDownloader; +import org.sonar.batch.bootstrapper.EnvironmentInformation; +import org.sonar.core.util.DefaultHttpDownloader; +import org.sonar.home.cache.PersistentCache; /** * Replace the deprecated org.sonar.batch.ServerMetadata @@ -180,7 +178,7 @@ public class ServerClient { return new IllegalStateException(String.format("Fail to execute request [code=%s, url=%s]", he.getResponseCode(), he.getUri()), he); } - private String tryParseAsJsonError(String responseContent) { + private static String tryParseAsJsonError(String responseContent) { try { JsonParser parser = new JsonParser(); JsonObject obj = parser.parse(responseContent).getAsJsonObject(); 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 8cd0656e310..0a33396354a 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,6 +19,8 @@ */ package org.sonar.batch.deprecated; +import java.io.Serializable; +import java.util.Collection; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.batch.AnalysisMode; @@ -44,9 +46,6 @@ import org.sonar.api.utils.SonarException; import org.sonar.batch.sensor.DefaultSensorContext; import org.sonar.batch.sensor.coverage.CoverageExclusions; -import java.io.Serializable; -import java.util.Collection; - public class DeprecatedSensorContext extends DefaultSensorContext implements SensorContext { private static final Logger LOG = LoggerFactory.getLogger(DeprecatedSensorContext.class); @@ -82,7 +81,7 @@ public class DeprecatedSensorContext extends DefaultSensorContext implements Sen return true; } - private void logWarning() { + private static void logWarning() { if (LOG.isDebugEnabled()) { LOG.debug("Plugins are no more responsible for indexing physical resources like directories and files. This is now handled by the platform.", new SonarException( "Plugin should not index physical resources")); 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 673357db494..a8e06058ecf 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 @@ -22,6 +22,8 @@ package org.sonar.batch.deprecated.decorator; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ListMultimap; import com.google.common.collect.Lists; +import java.util.Collection; +import java.util.List; import org.sonar.api.batch.DecoratorContext; import org.sonar.api.batch.SonarIndex; import org.sonar.api.design.Dependency; @@ -38,9 +40,6 @@ import org.sonar.api.utils.SonarException; import org.sonar.batch.scan.measure.MeasureCache; import org.sonar.batch.sensor.coverage.CoverageExclusions; -import java.util.Collection; -import java.util.List; - public class DefaultDecoratorContext implements DecoratorContext { private static final String SAVE_MEASURE_METHOD = "saveMeasure"; @@ -111,7 +110,7 @@ public class DefaultDecoratorContext implements DecoratorContext { } private <M> Collection<Measure> getMeasuresOfASingleMetric(MeasuresFilters.MetricFilter<M> filter) { - String metricKey = ((MeasuresFilters.MetricFilter<M>) filter).filterOnMetricKey(); + String metricKey = filter.filterOnMetricKey(); return measuresByMetric.get(metricKey); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/profiling/ModuleProfiling.java b/sonar-batch/src/main/java/org/sonar/batch/profiling/ModuleProfiling.java index 72f150aa9c5..17b3756fccc 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/profiling/ModuleProfiling.java +++ b/sonar-batch/src/main/java/org/sonar/batch/profiling/ModuleProfiling.java @@ -70,7 +70,7 @@ public class ModuleProfiling extends AbstractTimeProfiling { categories.putAll(profilingPerBatchStep); for (Map.Entry<Object, AbstractTimeProfiling> batchStep : categories.entrySet()) { - props.setProperty(batchStep.getKey().toString(), "" + batchStep.getValue().totalTime()); + props.setProperty(batchStep.getKey().toString(), Long.toString(batchStep.getValue().totalTime())); } for (Map.Entry<Object, AbstractTimeProfiling> batchStep : sortByDescendingTotalTime(categories).entrySet()) { diff --git a/sonar-batch/src/main/java/org/sonar/batch/profiling/PhaseProfiling.java b/sonar-batch/src/main/java/org/sonar/batch/profiling/PhaseProfiling.java index 15b16d02b49..b13767eefca 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/profiling/PhaseProfiling.java +++ b/sonar-batch/src/main/java/org/sonar/batch/profiling/PhaseProfiling.java @@ -19,12 +19,11 @@ */ package org.sonar.batch.profiling; -import org.sonar.api.utils.System2; - import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import java.util.Properties; +import org.sonar.api.utils.System2; public class PhaseProfiling extends AbstractTimeProfiling { @@ -76,7 +75,7 @@ public class PhaseProfiling extends AbstractTimeProfiling { public void dump(Properties props) { double percent = this.totalTime() / 100.0; for (ItemProfiling itemProfiling : profilingPerItem.values()) { - props.setProperty(itemProfiling.itemName(), "" + itemProfiling.totalTime()); + props.setProperty(itemProfiling.itemName(), Long.toString(itemProfiling.totalTime())); } for (ItemProfiling itemProfiling : truncate(sortByDescendingTotalTime(profilingPerItem).values())) { println(" o " + itemProfiling.itemName() + ": ", percent, itemProfiling); diff --git a/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java b/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java index c89e0027c36..c4506f9beda 100644 --- a/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java +++ b/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java @@ -51,11 +51,11 @@ public class CorePropertyDefinitions { .defaultValue(CoreProperties.SERVER_BASE_URL_DEFAULT_VALUE) .build(), - PropertyDefinition.builder(CoreProperties.LINKS_HOME_PAGE) - .name("Project Home Page") - .description("HTTP URL of the home page of the project.") - .hidden() - .build(), + PropertyDefinition.builder(CoreProperties.LINKS_HOME_PAGE) + .name("Project Home Page") + .description("HTTP URL of the home page of the project.") + .hidden() + .build(), PropertyDefinition.builder(CoreProperties.LINKS_CI) .name("CI server") .description("HTTP URL of the continuous integration server.") @@ -134,7 +134,7 @@ public class CorePropertyDefinitions { .type(PropertyType.BOOLEAN) .defaultValue(String.valueOf(false)) .hidden() - .build(), + .build(), PropertyDefinition.builder("sonar.enableFileVariation") .name("Enable file variation") .hidden() @@ -163,8 +163,8 @@ public class CorePropertyDefinitions { .category(CoreProperties.CATEGORY_SCM) .onlyOnQualifiers(Qualifiers.PROJECT) .build(), - - // WEB LOOK&FEEL + + // WEB LOOK&FEEL PropertyDefinition.builder("sonar.lf.logoUrl") .deprecatedKey("sonar.branding.image") .name("Logo URL") @@ -195,7 +195,7 @@ public class CorePropertyDefinitions { .subCategory(CoreProperties.SUBCATEGORY_LOOKNFEEL) .build(), - // ISSUES + // ISSUES PropertyDefinition.builder(CoreProperties.DEFAULT_ISSUE_ASSIGNEE) .name("Default Assignee") .description("New issues will be assigned to this user each time it is not possible to determine the user who is the author of the issue.") @@ -205,70 +205,70 @@ public class CorePropertyDefinitions { .type(PropertyType.USER_LOGIN) .build(), - // BATCH + // BATCH - PropertyDefinition.builder(CoreProperties.CORE_VIOLATION_LOCALE_PROPERTY) - .defaultValue("en") - .name("Locale used for issue messages") - .description("Deprecated property. Keep default value for backward compatibility.") - .hidden() - .build(), + PropertyDefinition.builder(CoreProperties.CORE_VIOLATION_LOCALE_PROPERTY) + .defaultValue("en") + .name("Locale used for issue messages") + .description("Deprecated property. Keep default value for backward compatibility.") + .hidden() + .build(), - PropertyDefinition.builder(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + 1) - .name("Period 1") - .description("Period used to compare measures and track new issues. Values are : <ul class='bullet'><li>Number of days before " + - "analysis, for example 5.</li><li>A custom date. Format is yyyy-MM-dd, for example 2010-12-25</li><li>'previous_analysis' to " + - "compare to previous analysis</li><li>'previous_version' to compare to the previous version in the project history</li></ul>" + - "<p>When specifying a number of days or a date, the snapshot selected for comparison is " + - " the first one available inside the corresponding time range. </p>" + - "<p>Changing this property only takes effect after subsequent project inspections.<p/>") - .defaultValue(CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_1) - .category(CoreProperties.CATEGORY_GENERAL) - .subCategory(CoreProperties.SUBCATEGORY_DIFFERENTIAL_VIEWS) - .build(), + PropertyDefinition.builder(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + 1) + .name("Period 1") + .description("Period used to compare measures and track new issues. Values are : <ul class='bullet'><li>Number of days before " + + "analysis, for example 5.</li><li>A custom date. Format is yyyy-MM-dd, for example 2010-12-25</li><li>'previous_analysis' to " + + "compare to previous analysis</li><li>'previous_version' to compare to the previous version in the project history</li></ul>" + + "<p>When specifying a number of days or a date, the snapshot selected for comparison is " + + " the first one available inside the corresponding time range. </p>" + + "<p>Changing this property only takes effect after subsequent project inspections.<p/>") + .defaultValue(CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_1) + .category(CoreProperties.CATEGORY_GENERAL) + .subCategory(CoreProperties.SUBCATEGORY_DIFFERENTIAL_VIEWS) + .build(), - PropertyDefinition.builder(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + 2) - .name("Period 2") - .description("See the property 'Period 1'") - .defaultValue(CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_2) - .category(CoreProperties.CATEGORY_GENERAL) - .subCategory(CoreProperties.SUBCATEGORY_DIFFERENTIAL_VIEWS) - .build(), + PropertyDefinition.builder(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + 2) + .name("Period 2") + .description("See the property 'Period 1'") + .defaultValue(CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_2) + .category(CoreProperties.CATEGORY_GENERAL) + .subCategory(CoreProperties.SUBCATEGORY_DIFFERENTIAL_VIEWS) + .build(), - PropertyDefinition.builder(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + 3) - .name("Period 3") - .description("See the property 'Period 1'") - .defaultValue(CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_3) - .category(CoreProperties.CATEGORY_GENERAL) - .subCategory(CoreProperties.SUBCATEGORY_DIFFERENTIAL_VIEWS) - .build(), + PropertyDefinition.builder(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + 3) + .name("Period 3") + .description("See the property 'Period 1'") + .defaultValue(CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_3) + .category(CoreProperties.CATEGORY_GENERAL) + .subCategory(CoreProperties.SUBCATEGORY_DIFFERENTIAL_VIEWS) + .build(), - PropertyDefinition.builder(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + 4) - .name("Period 4") - .description("Period used to compare measures and track new issues. This property is specific to the project. Values are : " + - "<ul class='bullet'><li>Number of days before analysis, for example 5.</li><li>A custom date. Format is yyyy-MM-dd, " + - "for example 2010-12-25</li><li>'previous_analysis' to compare to previous analysis</li>" + - "<li>'previous_version' to compare to the previous version in the project history</li><li>A version, for example 1.2</li></ul>" + - "<p>When specifying a number of days or a date, the snapshot selected for comparison is the first one available inside the corresponding time range. </p>" + - "<p>Changing this property only takes effect after subsequent project inspections.<p/>") - .defaultValue(CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_4) - .onlyOnQualifiers(Qualifiers.PROJECT) - .category(CoreProperties.CATEGORY_GENERAL) - .subCategory(CoreProperties.SUBCATEGORY_DIFFERENTIAL_VIEWS) - .build(), + PropertyDefinition.builder(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + 4) + .name("Period 4") + .description("Period used to compare measures and track new issues. This property is specific to the project. Values are : " + + "<ul class='bullet'><li>Number of days before analysis, for example 5.</li><li>A custom date. Format is yyyy-MM-dd, " + + "for example 2010-12-25</li><li>'previous_analysis' to compare to previous analysis</li>" + + "<li>'previous_version' to compare to the previous version in the project history</li><li>A version, for example 1.2</li></ul>" + + "<p>When specifying a number of days or a date, the snapshot selected for comparison is the first one available inside the corresponding time range. </p>" + + "<p>Changing this property only takes effect after subsequent project inspections.<p/>") + .defaultValue(CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_4) + .onlyOnQualifiers(Qualifiers.PROJECT) + .category(CoreProperties.CATEGORY_GENERAL) + .subCategory(CoreProperties.SUBCATEGORY_DIFFERENTIAL_VIEWS) + .build(), - PropertyDefinition.builder(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + 5) - .name("Period 5") - .description("See the property 'Period 4'") - .defaultValue(CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_5) - .onlyOnQualifiers(Qualifiers.PROJECT) - .category(CoreProperties.CATEGORY_GENERAL) - .subCategory(CoreProperties.SUBCATEGORY_DIFFERENTIAL_VIEWS) - .build(), + PropertyDefinition.builder(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + 5) + .name("Period 5") + .description("See the property 'Period 4'") + .defaultValue(CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_5) + .onlyOnQualifiers(Qualifiers.PROJECT) + .category(CoreProperties.CATEGORY_GENERAL) + .subCategory(CoreProperties.SUBCATEGORY_DIFFERENTIAL_VIEWS) + .build(), - // CPD + // CPD PropertyDefinition.builder(CoreProperties.CPD_CROSS_PROJECT) - .defaultValue(CoreProperties.CPD_CROSS_RPOJECT_DEFAULT_VALUE + "") + .defaultValue(Boolean.toString(CoreProperties.CPD_CROSS_RPOJECT_DEFAULT_VALUE)) .name("Cross project duplication detection") .description("By default, SonarQube detects duplications at sub-project level. This means that a block " + "duplicated on two sub-projects of the same project won't be reported. Setting this parameter to \"true\" " @@ -297,8 +297,7 @@ public class CorePropertyDefinitions { .category(CoreProperties.CATEGORY_EXCLUSIONS) .subCategory(CoreProperties.SUBCATEGORY_DUPLICATIONS_EXCLUSIONS) .multiValues(true) - .build() - )); + .build())); return defs; } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java index 88553184e82..769c0f521e6 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java @@ -424,6 +424,7 @@ public interface CoreProperties { * @since 4.0 * @deprecated in 5.1 no more used */ + @Deprecated String PREVIEW_READ_TIMEOUT_SEC = "sonar.preview.readTimeout"; /** @@ -467,15 +468,14 @@ public interface CoreProperties { * @since 4.0 */ String WORKING_DIRECTORY = "sonar.working.directory"; - + String WORKING_DIRECTORY_DEFAULT_VALUE = ".sonar"; - + /** * @since 5.2 */ String GLOBAL_WORKING_DIRECTORY = "sonar.globalWorking.directory"; String GLOBAL_WORKING_DIRECTORY_DEFAULT_VALUE = "."; - /** * @since 3.4 diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java index 5cea4cad69d..df42847def6 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java @@ -20,15 +20,6 @@ package org.sonar.api.batch.fs.internal; import com.google.common.base.Preconditions; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.TextPointer; -import org.sonar.api.batch.fs.TextRange; -import org.sonar.api.batch.fs.internal.FileMetadata.Metadata; -import org.sonar.api.utils.PathUtils; - -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; - import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; @@ -37,6 +28,13 @@ import java.io.InputStream; import java.nio.charset.Charset; import java.nio.file.Path; import java.util.Arrays; +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; +import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.batch.fs.TextPointer; +import org.sonar.api.batch.fs.TextRange; +import org.sonar.api.batch.fs.internal.FileMetadata.Metadata; +import org.sonar.api.utils.PathUtils; /** * @since 4.2 @@ -234,7 +232,7 @@ public class DefaultInputFile implements InputFile, org.sonar.api.resources.Inpu return newRangeValidPointers(start, end); } - private TextRange newRangeValidPointers(TextPointer start, TextPointer end) { + private static TextRange newRangeValidPointers(TextPointer start, TextPointer end) { Preconditions.checkArgument(start.compareTo(end) < 0, "Start pointer %s should be before end pointer %s", start, end); return new DefaultTextRange(start, end); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/internal/DefaultHighlighting.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/internal/DefaultHighlighting.java index 1712f50be88..1f1333a65bf 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/internal/DefaultHighlighting.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/internal/DefaultHighlighting.java @@ -20,6 +20,12 @@ package org.sonar.api.batch.sensor.highlighting.internal; import com.google.common.base.Preconditions; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import javax.annotation.Nullable; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.TextRange; import org.sonar.api.batch.fs.internal.DefaultInputFile; @@ -28,10 +34,6 @@ import org.sonar.api.batch.sensor.highlighting.TypeOfText; import org.sonar.api.batch.sensor.internal.DefaultStorable; import org.sonar.api.batch.sensor.internal.SensorStorage; -import javax.annotation.Nullable; - -import java.util.*; - public class DefaultHighlighting extends DefaultStorable implements NewHighlighting { private DefaultInputFile inputFile; @@ -56,7 +58,7 @@ public class DefaultHighlighting extends DefaultStorable implements NewHighlight SyntaxHighlightingRule previous = it.next(); while (it.hasNext()) { SyntaxHighlightingRule current = it.next(); - if (previous.range().end().compareTo(current.range().start()) > 0 && !(previous.range().end().compareTo(current.range().end()) >= 0)) { + if (previous.range().end().compareTo(current.range().start()) > 0 && (previous.range().end().compareTo(current.range().end()) < 0)) { String errorMsg = String.format("Cannot register highlighting rule for characters at %s as it " + "overlaps at least one existing rule", current.range()); throw new IllegalStateException(errorMsg); 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 9b018f6bc2c..b264e35ce85 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 @@ -20,6 +20,17 @@ package org.sonar.api.batch.sensor.internal; import com.google.common.annotations.Beta; +import java.io.File; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.EnumMap; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; import org.sonar.api.batch.AnalysisMode; import org.sonar.api.batch.fs.InputDir; import org.sonar.api.batch.fs.InputFile; @@ -51,18 +62,6 @@ import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure; import org.sonar.api.config.Settings; import org.sonar.api.measures.Metric; -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; - -import java.io.File; -import java.io.Serializable; -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}. * @@ -321,13 +320,13 @@ public class SensorContextTester implements SensorContext { public void store(DefaultCoverage defaultCoverage) { String key = getKey(defaultCoverage.inputFile()); if (!coverageByComponent.containsKey(key)) { - coverageByComponent.put(key, new HashMap<CoverageType, DefaultCoverage>()); + coverageByComponent.put(key, new EnumMap<CoverageType, DefaultCoverage>(CoverageType.class)); } coverageByComponent.get(key).put(defaultCoverage.type(), defaultCoverage); } @CheckForNull - private String getKey(@Nullable InputPath inputPath) { + private static String getKey(@Nullable InputPath inputPath) { if (inputPath == null) { return null; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/ResourceModel.java b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/ResourceModel.java index 554e25db743..b66e440dba8 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/ResourceModel.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/ResourceModel.java @@ -241,7 +241,7 @@ public class ResourceModel extends BaseIdentifiable implements Cloneable, Serial this.key = key; } - private void checkSize(String key) { + private static void checkSize(String key) { if (key.length() > KEY_SIZE) { throw new IllegalArgumentException("Resource key is too long, max is " + KEY_SIZE + " characters. Got : " + key); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileParser.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileParser.java index c33d9e1d645..ea09d2bddfc 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileParser.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileParser.java @@ -19,27 +19,25 @@ */ package org.sonar.api.profiles; +import java.io.InputStreamReader; +import java.io.Reader; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.Map; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.codehaus.staxmate.SMInputFactory; import org.codehaus.staxmate.in.SMHierarchicCursor; import org.codehaus.staxmate.in.SMInputCursor; -import org.sonar.api.server.ServerSide; import org.sonar.api.rules.ActiveRule; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleFinder; import org.sonar.api.rules.RulePriority; +import org.sonar.api.server.ServerSide; import org.sonar.api.utils.ValidationMessages; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamException; - -import java.io.InputStreamReader; -import java.io.Reader; -import java.nio.charset.StandardCharsets; -import java.util.HashMap; -import java.util.Map; - /** * @since 2.3 */ @@ -160,7 +158,7 @@ public class XMLProfileParser { } } - private String ruleToString(String repositoryKey, String key) { + private static String ruleToString(String repositoryKey, String key) { return "[repository=" + repositoryKey + ", key=" + key + "]"; } |