]> source.dussan.org Git - sonarqube.git/commitdiff
SONARJAVA-51 Files not ending with '.java' or '.jav' should not be taken into account
authorEvgeny Mandrikov <mandrikov@gmail.com>
Tue, 5 Feb 2013 14:56:15 +0000 (15:56 +0100)
committerEvgeny Mandrikov <mandrikov@gmail.com>
Tue, 5 Feb 2013 15:02:23 +0000 (16:02 +0100)
sonar-plugin-api/src/main/java/org/sonar/api/resources/Java.java
sonar-plugin-api/src/main/java/org/sonar/api/resources/Language.java
sonar-plugin-api/src/test/java/org/sonar/api/resources/JavaTest.java [new file with mode: 0644]

index d9b2f99ebf880e2774f9d1fed918311bacf9f21e..16beba017d972e005521978c4c2aeeeb22769c90 100644 (file)
@@ -40,14 +40,16 @@ public class Java extends AbstractLanguage {
    * Java name
    */
   public static final String NAME = "Java";
+
   /**
    * Default package name for classes without package def
    */
   public static final String DEFAULT_PACKAGE_NAME = "[default]";
+
   /**
    * Java files knows suffixes
    */
-  public static final String[] SUFFIXES = {"java", "jav"};
+  public static final String[] SUFFIXES = {".java", ".jav"};
 
   /**
    * Default constructor
@@ -66,7 +68,8 @@ public class Java extends AbstractLanguage {
   }
 
   public static boolean isJavaFile(java.io.File file) {
-    String suffix = StringUtils.substringAfterLast(file.getName(), ".");
+    String suffix = "." + StringUtils.substringAfterLast(file.getName(), ".");
     return ArrayUtils.contains(SUFFIXES, suffix);
   }
+
 }
index 6aee345fe1f3d8e4d1bc2b812aefd632064d7acf..8a025a32108d6300a46e1a77a5d8c0cfb21db09c 100644 (file)
@@ -40,7 +40,9 @@ public interface Language extends BatchExtension, ServerExtension {
   String getName();
 
   /**
-   * For example ["jav","java"]. If empty, then all files in source directories are considered as sources.
+   * Make sure that dot is a prefix for all values.
+   * For example [".jav", ".java"].
+   * If empty, then all files in source directories are considered as sources.
    */
   String[] getFileSuffixes();
 
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/JavaTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/JavaTest.java
new file mode 100644 (file)
index 0000000..a9425b8
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+package org.sonar.api.resources;
+
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class JavaTest {
+
+  @Test
+  public void test() {
+    Java language = new Java();
+    assertThat(language.getFileSuffixes()).isEqualTo(new String[] {".java", ".jav"});
+
+    assertThat(Java.isJavaFile(new java.io.File("Example.java"))).isTrue();
+    assertThat(Java.isJavaFile(new java.io.File("Example.jav"))).isTrue();
+    assertThat(Java.isJavaFile(new java.io.File("Example.notjava"))).isFalse();
+  }
+
+}