diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2010-10-28 10:23:58 +0000 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2010-10-28 10:23:58 +0000 |
commit | 5078541b8e1e33d790fe63c2faa37de70f18e376 (patch) | |
tree | 01f0099a7c8064ba014438c3dcdecc733f4a3f7a /sonar-plugin-api | |
parent | 7a8fe553fe231961e9095348042a296dbbc6679e (diff) | |
download | sonarqube-5078541b8e1e33d790fe63c2faa37de70f18e376.tar.gz sonarqube-5078541b8e1e33d790fe63c2faa37de70f18e376.zip |
SONAR-1643 move core widgets from sonar-server to sonar-core-plugin + improve UI
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/batch/SquidUtils.java | 11 | ||||
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/batch/SquidUtilsTest.java | 10 |
2 files changed, 19 insertions, 2 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 d0ced27f6d9..e101640a6ee 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,6 +19,7 @@ */ package org.sonar.api.batch; +import org.apache.commons.lang.StringUtils; import org.sonar.api.resources.JavaFile; import org.sonar.api.resources.JavaPackage; @@ -49,4 +50,14 @@ public final class SquidUtils { String convertedKey = key.replace('/', '.'); return new JavaPackage(convertedKey); } + + 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"; + } } 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 e8888e54671..3b9d1a6ab6b 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 @@ -23,7 +23,9 @@ import org.junit.Test; import org.sonar.api.resources.JavaFile; import org.sonar.api.resources.JavaPackage; +import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; public class SquidUtilsTest { @@ -36,11 +38,15 @@ public class SquidUtilsTest { } @Test - public void convertJavaPackageKeyFromSquidFormat() { + public void shouldConvertJavaPackageKeyFromSquidFormat() { assertEquals(new JavaPackage("java.lang"), SquidUtils.convertJavaPackageKeyFromSquidFormat("java/lang")); assertEquals(new JavaPackage(""), SquidUtils.convertJavaPackageKeyFromSquidFormat("")); assertEquals(new JavaPackage("singlepackage"), SquidUtils.convertJavaPackageKeyFromSquidFormat("singlepackage")); } - + @Test + public void shouldConvertToSquidKeyFormat() { + assertThat(SquidUtils.convertToSquidKeyFormat(new JavaFile("com.foo.Bar")), is("com/foo/Bar.java")); + assertThat(SquidUtils.convertToSquidKeyFormat(new JavaFile("Bar")), is("Bar.java")); + } }
\ No newline at end of file |