From 1c2189b45f0a81436fcaab886b7072aea77a7d01 Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Fri, 28 Jan 2011 13:16:11 +0300 Subject: SONAR-2151: Add new property to manage source encoding --- .../main/java/org/sonar/batch/MavenProjectBuilder.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'sonar-batch') diff --git a/sonar-batch/src/main/java/org/sonar/batch/MavenProjectBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/MavenProjectBuilder.java index d10a4b35516..7fde1c352b7 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/MavenProjectBuilder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/MavenProjectBuilder.java @@ -20,6 +20,7 @@ package org.sonar.batch; import org.apache.commons.configuration.*; +import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.time.DateUtils; import org.apache.maven.project.MavenProject; import org.sonar.api.CoreProperties; @@ -79,18 +80,23 @@ public class MavenProjectBuilder { MavenProject pom = project.getPom(); if (pom != null) { /* - * TODO actually this is a dirty hack to get Java source and target versions from maven-compiler-plugin + * TODO actually this is a dirty hack * See http://jira.codehaus.org/browse/SONAR-2148 - * In fact we should try to get rid of it and use concept of configurator, - * which would be active only in Maven environment - * and would be responsible for setting values from corresponding maven-plugin. + * Get Java source and target versions from maven-compiler-plugin. */ - if (projectConfiguration.getProperty(JavaUtils.JAVA_SOURCE_PROPERTY) == null) { + if (StringUtils.isBlank(projectConfiguration.getString(JavaUtils.JAVA_SOURCE_PROPERTY))) { projectConfiguration.setProperty(JavaUtils.JAVA_SOURCE_PROPERTY, MavenUtils.getJavaSourceVersion(pom)); } - if (projectConfiguration.getProperty(JavaUtils.JAVA_TARGET_PROPERTY) == null) { + if (StringUtils.isBlank(projectConfiguration.getString(JavaUtils.JAVA_TARGET_PROPERTY))) { projectConfiguration.setProperty(JavaUtils.JAVA_TARGET_PROPERTY, MavenUtils.getJavaVersion(pom)); } + /* + * See http://jira.codehaus.org/browse/SONAR-2151 + * Get source encoding from POM + */ + if (StringUtils.isBlank(projectConfiguration.getString(CoreProperties.ENCODING_PROPERTY))) { + projectConfiguration.setProperty(CoreProperties.ENCODING_PROPERTY, MavenUtils.getSourceEncoding(pom)); + } } project.setConfiguration(projectConfiguration) .setExclusionPatterns(loadExclusionPatterns(projectConfiguration)) -- cgit v1.2.3