aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-java-api
diff options
context:
space:
mode:
authorEvgeny Mandrikov <mandrikov@gmail.com>2011-07-12 12:45:43 +0400
committerEvgeny Mandrikov <mandrikov@gmail.com>2011-07-12 13:18:57 +0400
commitab6af5363626a14f9cdba7ded99125075a317881 (patch)
tree249ee2d2fe2bb9cccaa81d7458a74e5446a4ffef /sonar-java-api
parent43da0ad5489f38cfbde2b1728fd791c4528f1ab7 (diff)
downloadsonarqube-ab6af5363626a14f9cdba7ded99125075a317881.tar.gz
sonarqube-ab6af5363626a14f9cdba7ded99125075a317881.zip
SONAR-2604 Default value for properties "sonar.java.source" and "sonar.java.target" should be "1.5"
Diffstat (limited to 'sonar-java-api')
-rw-r--r--sonar-java-api/pom.xml9
-rw-r--r--sonar-java-api/src/main/java/org/sonar/java/api/JavaUtils.java22
-rw-r--r--sonar-java-api/src/test/java/org/sonar/java/api/JavaUtilsTest.java27
3 files changed, 41 insertions, 17 deletions
diff --git a/sonar-java-api/pom.xml b/sonar-java-api/pom.xml
index 8275240d889..42ba5c7932d 100644
--- a/sonar-java-api/pom.xml
+++ b/sonar-java-api/pom.xml
@@ -16,13 +16,8 @@
<!-- unit tests -->
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-all</artifactId>
+ <groupId>org.codehaus.sonar</groupId>
+ <artifactId>sonar-testing-harness</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
diff --git a/sonar-java-api/src/main/java/org/sonar/java/api/JavaUtils.java b/sonar-java-api/src/main/java/org/sonar/java/api/JavaUtils.java
index b3cc844574b..03951cc9dac 100644
--- a/sonar-java-api/src/main/java/org/sonar/java/api/JavaUtils.java
+++ b/sonar-java-api/src/main/java/org/sonar/java/api/JavaUtils.java
@@ -47,10 +47,20 @@ public final class JavaUtils {
public static final String JAVA_SOURCE_PROPERTY = "sonar.java.source";
/**
+ * Default value for property {@link #JAVA_SOURCE_PROPERTY}.
+ */
+ public static final String JAVA_SOURCE_DEFAULT_VALUE = "1.5";
+
+ /**
* To determine value of this property use {@link #getTargetVersion(Project)}.
*/
public static final String JAVA_TARGET_PROPERTY = "sonar.java.target";
+ /**
+ * Default value for property {@link #JAVA_TARGET_PROPERTY}.
+ */
+ public static final String JAVA_TARGET_DEFAULT_VALUE = "1.5";
+
private JavaUtils() {
// only static methods
}
@@ -68,16 +78,12 @@ public final class JavaUtils {
}
public static String getSourceVersion(Project project) {
- if (project.getConfiguration() != null) {
- return project.getConfiguration().getString(JAVA_SOURCE_PROPERTY);
- }
- return null;
+ String version = project.getConfiguration() != null ? project.getConfiguration().getString(JAVA_SOURCE_PROPERTY) : null;
+ return StringUtils.isNotBlank(version) ? version : JAVA_SOURCE_DEFAULT_VALUE;
}
public static String getTargetVersion(Project project) {
- if (project.getConfiguration() != null) {
- return project.getConfiguration().getString(JAVA_TARGET_PROPERTY);
- }
- return null;
+ String version = project.getConfiguration() != null ? project.getConfiguration().getString(JAVA_TARGET_PROPERTY) : null;
+ return StringUtils.isNotBlank(version) ? version : JAVA_TARGET_DEFAULT_VALUE;
}
}
diff --git a/sonar-java-api/src/test/java/org/sonar/java/api/JavaUtilsTest.java b/sonar-java-api/src/test/java/org/sonar/java/api/JavaUtilsTest.java
index 5cf2aecc0ea..e55e76205b8 100644
--- a/sonar-java-api/src/test/java/org/sonar/java/api/JavaUtilsTest.java
+++ b/sonar-java-api/src/test/java/org/sonar/java/api/JavaUtilsTest.java
@@ -19,11 +19,13 @@
*/
package org.sonar.java.api;
-import org.junit.Test;
-
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
+import org.apache.commons.configuration.BaseConfiguration;
+import org.junit.Test;
+import org.sonar.api.resources.Project;
+
public class JavaUtilsTest {
@Test
@@ -36,4 +38,25 @@ public class JavaUtilsTest {
assertThat(JavaUtils.abbreviatePackage("com.foo."), is("com.f"));
assertThat(JavaUtils.abbreviatePackage("com.foo..bar"), is("com.f.b"));
}
+
+ @Test
+ public void shouldReturnDefaultJavaVersion() {
+ BaseConfiguration configuration = new BaseConfiguration();
+ Project project = new Project("").setConfiguration(configuration);
+
+ assertThat(JavaUtils.getSourceVersion(project), is("1.5"));
+ assertThat(JavaUtils.getTargetVersion(project), is("1.5"));
+ }
+
+ @Test
+ public void shouldReturnSpecifiedJavaVersion() {
+ BaseConfiguration configuration = new BaseConfiguration();
+ Project project = new Project("").setConfiguration(configuration);
+ configuration.setProperty(JavaUtils.JAVA_SOURCE_PROPERTY, "1.4");
+ configuration.setProperty(JavaUtils.JAVA_TARGET_PROPERTY, "1.6");
+
+ assertThat(JavaUtils.getSourceVersion(project), is("1.4"));
+ assertThat(JavaUtils.getTargetVersion(project), is("1.6"));
+ }
+
}