aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2013-10-11 17:48:37 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2013-10-11 17:48:37 +0200
commit5b4b4172c45aa794d7b40c8e5b9fde6d3a001492 (patch)
tree1b0677c93e8b76382510f1115088bd89a9076faf /sonar-plugin-api
parent2b2e799a13915bcf60fc6cb855f53b80611f1b77 (diff)
downloadsonarqube-5b4b4172c45aa794d7b40c8e5b9fde6d3a001492.tar.gz
sonarqube-5b4b4172c45aa794d7b40c8e5b9fde6d3a001492.zip
SONAR-4768 Fail to analyze java files with extension .jav
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/SquidUtils.java17
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/Java.java2
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/SquidUtilsTest.java10
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/resources/JavaTest.java2
4 files changed, 16 insertions, 15 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SquidUtils.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SquidUtils.java
index dbb2e2e2132..b9136c0fb69 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SquidUtils.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SquidUtils.java
@@ -19,22 +19,23 @@
*/
package org.sonar.api.batch;
+import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.StringUtils;
+import org.sonar.api.resources.Java;
import org.sonar.api.resources.JavaFile;
import org.sonar.api.resources.JavaPackage;
public final class SquidUtils {
- private static final String JAVA_FILE_SUFFIX = ".java";
-
private SquidUtils() {
// only static methods
}
public static JavaFile convertJavaFileKeyFromSquidFormat(String key) {
- boolean isJavaFile = key.endsWith(JAVA_FILE_SUFFIX);
+ String extension = StringUtils.lowerCase(FilenameUtils.getExtension(key));
+ boolean isJavaFile = "jav".equals(extension) || "java".equals(extension);
if (isJavaFile) {
- key = key.substring(0, key.length() - JAVA_FILE_SUFFIX.length());
+ key = key.substring(0, key.length() - extension.length() -1);
}
String convertedKey = key.replace('/', '.');
@@ -54,12 +55,6 @@ public final class SquidUtils {
}
public static String convertToSquidKeyFormat(JavaFile file) {
- String key = file.getKey();
- if (file.getParent() == null || file.getParent().isDefault()) {
- key = StringUtils.substringAfterLast(file.getKey(), ".");
- } else {
- key = StringUtils.replace(key, ".", "/");
- }
- return key + JAVA_FILE_SUFFIX;
+ throw new UnsupportedOperationException("Not supported since v4.0. Was badly implemented");
}
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Java.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Java.java
index 7f1337e15f1..917c0ad7dc5 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Java.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Java.java
@@ -72,7 +72,7 @@ public class Java extends AbstractLanguage {
}
public static boolean isJavaFile(java.io.File file) {
- String suffix = "." + StringUtils.substringAfterLast(file.getName(), ".");
+ String suffix = "." + StringUtils.lowerCase(StringUtils.substringAfterLast(file.getName(), "."));
return ArrayUtils.contains(SUFFIXES, suffix);
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/SquidUtilsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/SquidUtilsTest.java
index 7f6c318e26b..de1448021d9 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/SquidUtilsTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/SquidUtilsTest.java
@@ -31,7 +31,12 @@ public class SquidUtilsTest {
public void convertJavaFileKeyFromSquidFormat() {
assertThat(new JavaFile("java.lang.String")).isEqualTo(SquidUtils.convertJavaFileKeyFromSquidFormat("java/lang/String"));
assertThat(new JavaFile("java.lang.String")).isEqualTo(SquidUtils.convertJavaFileKeyFromSquidFormat("java/lang/String.java"));
+ assertThat(new JavaFile("java.lang.String")).isEqualTo(SquidUtils.convertJavaFileKeyFromSquidFormat("java/lang/String.jav"));
+ assertThat(new JavaFile("java.lang.String")).isEqualTo(SquidUtils.convertJavaFileKeyFromSquidFormat("java/lang/String.JAVA"));
+ assertThat(new JavaFile("java.lang.String")).isEqualTo(SquidUtils.convertJavaFileKeyFromSquidFormat("java/lang/String.JAV"));
assertThat(new JavaFile("String")).isEqualTo(SquidUtils.convertJavaFileKeyFromSquidFormat("String.java"));
+ assertThat(new JavaFile("String")).isEqualTo(SquidUtils.convertJavaFileKeyFromSquidFormat("String.JAVA"));
+ assertThat(new JavaFile("String")).isEqualTo(SquidUtils.convertJavaFileKeyFromSquidFormat("String.JAV"));
assertThat(new JavaFile("String")).isEqualTo(SquidUtils.convertJavaFileKeyFromSquidFormat("String"));
}
@@ -42,9 +47,8 @@ public class SquidUtilsTest {
assertThat(new JavaPackage("singlepackage")).isEqualTo(SquidUtils.convertJavaPackageKeyFromSquidFormat("singlepackage"));
}
- @Test
+ @Test(expected = UnsupportedOperationException.class)
public void shouldConvertToSquidKeyFormat() {
- assertThat(SquidUtils.convertToSquidKeyFormat(new JavaFile("com.foo.Bar"))).isEqualTo(("com/foo/Bar.java"));
- assertThat(SquidUtils.convertToSquidKeyFormat(new JavaFile("Bar"))).isEqualTo(("Bar.java"));
+ SquidUtils.convertToSquidKeyFormat(new JavaFile("com.foo.Bar"));
}
}
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
index 65e66d5cdeb..5eb1af9fa81 100644
--- 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
@@ -31,7 +31,9 @@ public class JavaTest {
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.JAVA"))).isTrue();
assertThat(Java.isJavaFile(new java.io.File("Example.jav"))).isTrue();
+ assertThat(Java.isJavaFile(new java.io.File("Example.Jav"))).isTrue();
assertThat(Java.isJavaFile(new java.io.File("Example.notjava"))).isFalse();
}