From 00a71853b7b223005c429e7582ee01b59f5ff50f Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Wed, 8 Oct 2014 10:32:49 +0200 Subject: [PATCH] Fix some quality flaws --- .../core/timemachine/VariationDecorator.java | 4 +- .../batch/mediumtest/BatchMediumTester.java | 10 ++--- .../core/plugins/DefaultPluginMetadata.java | 4 ++ .../org/sonar/core/plugins/RemotePlugin.java | 4 +- .../plugins/DefaultPluginMetadataTest.java | 42 +++++++++---------- .../core/plugins/PluginClassloadersTest.java | 16 +++---- 6 files changed, 40 insertions(+), 40 deletions(-) diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java index 19d1dd93207..8f54748066f 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java @@ -95,10 +95,10 @@ public class VariationDecorator implements Decorator { private void computeVariation(Resource resource, DecoratorContext context, PastSnapshot pastSnapshot) { List pastMeasures = pastMeasuresLoader.getPastMeasures(resource, pastSnapshot); - compareWithPastMeasures(resource, context, pastSnapshot.getIndex(), pastMeasures); + compareWithPastMeasures(context, pastSnapshot.getIndex(), pastMeasures); } - void compareWithPastMeasures(Resource resource, DecoratorContext context, int index, List pastMeasures) { + private void compareWithPastMeasures(DecoratorContext context, int index, List pastMeasures) { Map pastMeasuresByKey = Maps.newHashMap(); for (Object[] pastMeasure : pastMeasures) { pastMeasuresByKey.put(new MeasureKey(pastMeasure), pastMeasure); diff --git a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java index be3185f7b6d..cc0d2577e82 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java +++ b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java @@ -89,7 +89,7 @@ public class BatchMediumTester { public static class BatchMediumTesterBuilder { private final FakeGlobalReferentialsLoader globalRefProvider = new FakeGlobalReferentialsLoader(); private final FakeProjectReferentialsLoader projectRefProvider = new FakeProjectReferentialsLoader(); - private final FackPluginsReferential pluginsReferential = new FackPluginsReferential(); + private final FakePluginsReferential pluginsReferential = new FakePluginsReferential(); private final Map bootstrapProperties = new HashMap(); public BatchMediumTester build() { @@ -378,7 +378,7 @@ public class BatchMediumTester { } } - private static class FackPluginsReferential implements PluginsReferential { + private static class FakePluginsReferential implements PluginsReferential { private List pluginList = new ArrayList(); private Map pluginFiles = new HashMap(); @@ -394,15 +394,15 @@ public class BatchMediumTester { return pluginFiles.get(remote); } - public FackPluginsReferential addPlugin(String pluginKey, File location) { + public FakePluginsReferential addPlugin(String pluginKey, File location) { RemotePlugin plugin = new RemotePlugin(pluginKey, false); pluginList.add(plugin); pluginFiles.put(plugin, location); return this; } - public FackPluginsReferential addPlugin(String pluginKey, SonarPlugin pluginInstance) { - localPlugins.put(DefaultPluginMetadata.create(null).setKey(pluginKey), pluginInstance); + public FakePluginsReferential addPlugin(String pluginKey, SonarPlugin pluginInstance) { + localPlugins.put(DefaultPluginMetadata.create(pluginKey), pluginInstance); return this; } diff --git a/sonar-core/src/main/java/org/sonar/core/plugins/DefaultPluginMetadata.java b/sonar-core/src/main/java/org/sonar/core/plugins/DefaultPluginMetadata.java index 55239eb3410..8a4a103cd5a 100644 --- a/sonar-core/src/main/java/org/sonar/core/plugins/DefaultPluginMetadata.java +++ b/sonar-core/src/main/java/org/sonar/core/plugins/DefaultPluginMetadata.java @@ -63,6 +63,10 @@ public class DefaultPluginMetadata implements PluginMetadata, Comparable 2) { String[] nameAndHash = StringUtils.split(fields[2], "|"); - result.setFile(nameAndHash[0], nameAndHash.length > 1 ? nameAndHash[1] : null); + result.setFile(nameAndHash[0], nameAndHash[1]); } return result; } @@ -72,7 +72,7 @@ public class RemotePlugin { } public RemotePlugin setFile(File f) { - return this.setFile(f.getName(), f.exists() ? new FileHashes().of(f) : null); + return this.setFile(f.getName(), new FileHashes().of(f)); } public RemotePluginFile file() { diff --git a/sonar-core/src/test/java/org/sonar/core/plugins/DefaultPluginMetadataTest.java b/sonar-core/src/test/java/org/sonar/core/plugins/DefaultPluginMetadataTest.java index f7d7dea4e59..d3f819392b5 100644 --- a/sonar-core/src/test/java/org/sonar/core/plugins/DefaultPluginMetadataTest.java +++ b/sonar-core/src/test/java/org/sonar/core/plugins/DefaultPluginMetadataTest.java @@ -36,19 +36,19 @@ public class DefaultPluginMetadataTest { public void testGettersAndSetters() { DefaultPluginMetadata metadata = DefaultPluginMetadata.create(new File("sonar-checkstyle-plugin.jar")); metadata.setKey("checkstyle") - .setParent("java") - .setLicense("LGPL") - .setDescription("description") - .setHomepage("http://home") - .setIssueTrackerUrl("http://jira.codehuas.org") - .setMainClass("org.Main") - .setOrganization("SonarSource") - .setOrganizationUrl("http://sonarsource.org") - .setVersion("1.1") - .setSonarVersion("3.0") - .setUseChildFirstClassLoader(true) - .setCore(false) - .setImplementationBuild("abcdef"); + .setParent("java") + .setLicense("LGPL") + .setDescription("description") + .setHomepage("http://home") + .setIssueTrackerUrl("http://jira.codehuas.org") + .setMainClass("org.Main") + .setOrganization("SonarSource") + .setOrganizationUrl("http://sonarsource.org") + .setVersion("1.1") + .setSonarVersion("3.0") + .setUseChildFirstClassLoader(true) + .setCore(false) + .setImplementationBuild("abcdef"); assertThat(metadata.getKey()).isEqualTo("checkstyle"); assertThat(metadata.getParent()).isEqualTo("java"); @@ -72,8 +72,8 @@ public class DefaultPluginMetadataTest { @Test public void testDeployedFiles() { DefaultPluginMetadata metadata = DefaultPluginMetadata.create(new File("sonar-checkstyle-plugin.jar")) - .addDeployedFile(new File("foo.jar")) - .addDeployedFile(new File("bar.jar")); + .addDeployedFile(new File("foo.jar")) + .addDeployedFile(new File("bar.jar")); assertThat(metadata.getDeployedFiles()).hasSize(2); } @@ -81,7 +81,7 @@ public class DefaultPluginMetadataTest { @Test public void testInternalPathToDependencies() { DefaultPluginMetadata metadata = DefaultPluginMetadata.create(new File("sonar-checkstyle-plugin.jar")) - .setPathsToInternalDeps(newArrayList("META-INF/lib/commons-lang.jar", "META-INF/lib/commons-io.jar")); + .setPathsToInternalDeps(newArrayList("META-INF/lib/commons-lang.jar", "META-INF/lib/commons-io.jar")); assertThat(metadata.getPathsToInternalDeps()).containsOnly("META-INF/lib/commons-lang.jar", "META-INF/lib/commons-io.jar"); } @@ -99,11 +99,11 @@ public class DefaultPluginMetadataTest { @Test public void shouldCompare() { DefaultPluginMetadata checkstyle = DefaultPluginMetadata.create(new File("sonar-checkstyle-plugin.jar")) - .setKey("checkstyle") - .setName("Checkstyle"); + .setKey("checkstyle") + .setName("Checkstyle"); DefaultPluginMetadata pmd = DefaultPluginMetadata.create(new File("sonar-pmd-plugin.jar")) - .setKey("pmd") - .setName("PMD"); + .setKey("pmd") + .setName("PMD"); List plugins = Arrays.asList(pmd, checkstyle); assertThat(natural().sortedCopy(plugins)).onProperty("key").containsExactly("checkstyle", "pmd"); @@ -141,6 +141,6 @@ public class DefaultPluginMetadataTest { } static DefaultPluginMetadata pluginWithVersion(String version) { - return DefaultPluginMetadata.create(null).setSonarVersion(version); + return DefaultPluginMetadata.create("foo").setSonarVersion(version); } } diff --git a/sonar-core/src/test/java/org/sonar/core/plugins/PluginClassloadersTest.java b/sonar-core/src/test/java/org/sonar/core/plugins/PluginClassloadersTest.java index 95bb9da245c..120680b1998 100644 --- a/sonar-core/src/test/java/org/sonar/core/plugins/PluginClassloadersTest.java +++ b/sonar-core/src/test/java/org/sonar/core/plugins/PluginClassloadersTest.java @@ -62,8 +62,8 @@ public class PluginClassloadersTest { @Test public void shouldImport() throws Exception { - classloaders.add(DefaultPluginMetadata.create(null).setKey("foo").addDeployedFile(getFile("PluginClassloadersTest/foo.jar"))); - classloaders.add(DefaultPluginMetadata.create(null).setKey("bar").addDeployedFile(getFile("PluginClassloadersTest/bar.jar"))); + classloaders.add(DefaultPluginMetadata.create("foo").addDeployedFile(getFile("PluginClassloadersTest/foo.jar"))); + classloaders.add(DefaultPluginMetadata.create("bar").addDeployedFile(getFile("PluginClassloadersTest/bar.jar"))); classloaders.done(); String resourceName = "org/sonar/plugins/bar/api/resource.txt"; @@ -74,8 +74,7 @@ public class PluginClassloadersTest { @Test public void shouldCreateBaseClassloader() { classloaders = new PluginClassloaders(getClass().getClassLoader()); - DefaultPluginMetadata checkstyle = DefaultPluginMetadata.create(null) - .setKey("checkstyle") + DefaultPluginMetadata checkstyle = DefaultPluginMetadata.create("checkstyle") .setMainClass("org.sonar.plugins.checkstyle.CheckstylePlugin") .addDeployedFile(getFile("sonar-checkstyle-plugin-2.8.jar")); @@ -90,13 +89,11 @@ public class PluginClassloadersTest { public void shouldExtendPlugin() { classloaders = new PluginClassloaders(getClass().getClassLoader()); - DefaultPluginMetadata checkstyle = DefaultPluginMetadata.create(null) - .setKey("checkstyle") + DefaultPluginMetadata checkstyle = DefaultPluginMetadata.create("checkstyle") .setMainClass("org.sonar.plugins.checkstyle.CheckstylePlugin") .addDeployedFile(getFile("sonar-checkstyle-plugin-2.8.jar")); - DefaultPluginMetadata checkstyleExt = DefaultPluginMetadata.create(null) - .setKey("checkstyle-ext") + DefaultPluginMetadata checkstyleExt = DefaultPluginMetadata.create("checkstyle-ext") .setBasePlugin("checkstyle") .setMainClass("com.mycompany.sonar.checkstyle.CheckstyleExtensionsPlugin") .addDeployedFile(getFile("sonar-checkstyle-extensions-plugin-0.1-SNAPSHOT.jar")); @@ -119,8 +116,7 @@ public class PluginClassloadersTest { classloaders = new PluginClassloaders(getClass().getClassLoader(), world); - DefaultPluginMetadata checkstyle = DefaultPluginMetadata.create(null) - .setKey("checkstyle") + DefaultPluginMetadata checkstyle = DefaultPluginMetadata.create("checkstyle") .setMainClass("org.sonar.plugins.checkstyle.CheckstylePlugin") .addDeployedFile(getFile("sonar-checkstyle-plugin-2.8.jar")); -- 2.39.5