]> source.dussan.org Git - sonarqube.git/commitdiff
A singleton is not needed. The code can be simpler
authorDavid Gageot <david@gageot.net>
Mon, 30 Apr 2012 05:41:40 +0000 (07:41 +0200)
committerDavid Gageot <david@gageot.net>
Mon, 30 Apr 2012 05:42:50 +0000 (07:42 +0200)
plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdVersion.java
plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdVersionTest.java

index abbb79a34e9bbc03ff254106ea7a7e7f117e291c..0b70b225453326dd44a219a8ca3975cdc480b0e8 100644 (file)
@@ -26,29 +26,22 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.util.Properties;
 
-public enum PmdVersion {
-  INSTANCE;
-
+public final class PmdVersion {
   private static final String PROPERTIES_PATH = "/org/sonar/plugins/pmd/pmd-plugin.properties";
-  private String version;
-
-  public static String getVersion() {
-    return INSTANCE.version;
-  }
 
   private PmdVersion() {
-    version = readVersion();
+    // Static utility class
   }
 
-  public String readVersion() {
+  public static String getVersion() {
     Properties properties = new Properties();
 
     InputStream input = null;
     try {
-      input = getClass().getResourceAsStream(PROPERTIES_PATH);
+      input = PmdVersion.class.getResourceAsStream(PROPERTIES_PATH);
       properties.load(input);
     } catch (IOException e) {
-      LoggerFactory.getLogger(getClass()).warn("Can not load the PMD version from the file " + PROPERTIES_PATH);
+      LoggerFactory.getLogger(PmdVersion.class).warn("Can not load the PMD version from the file " + PROPERTIES_PATH);
     } finally {
       Closeables.closeQuietly(input);
     }
index 2b325d5e7e73d59f552f449c506123a6ea2cb3e0..c373456029cef41e53343e5762fe34b6cf76ec37 100644 (file)
@@ -26,6 +26,6 @@ import static org.fest.assertions.Assertions.assertThat;
 public class PmdVersionTest {
   @Test
   public void should_get_pmd_version() {
-    assertThat(PmdVersion.getVersion()).isNotEmpty().isSameAs(PmdVersion.getVersion());
+    assertThat(PmdVersion.getVersion()).isNotEmpty();
   }
 }