class Dirs {
void init(Runner runner) {
- boolean onProject = ScanProperties.SCAN_TASK.equals(runner.property(RunnerProperties.TASK, null));
+ boolean onProject = Utils.taskRequiresProject(runner.properties());
if (onProject) {
initProjectDirs(runner);
} else {
*/
String TASK = "sonar.task";
- /**
- * Encoding of source and test files. By default it's the platform encoding.
- */
- String SOURCE_ENCODING = "sonar.sourceEncoding";
-
/**
* Working directory containing generated reports and temporary data.
*/
/**
* Default task
+ *
* @see RunnerProperties#TASK
*/
String SCAN_TASK = "scan";
* Property used to specify the base directory of the project to analyse. Default is ".".
*/
String PROJECT_BASEDIR = "sonar.projectBaseDir";
+
+ /**
+ * Encoding of source and test files. By default it's the platform encoding.
+ */
+ String PROJECT_SOURCE_ENCODING = "sonar.sourceEncoding";
+
}
class SourceEncoding {
void init(Runner runner) {
- String sourceEncoding = runner.property(RunnerProperties.SOURCE_ENCODING, "");
- boolean platformDependent = false;
- if ("".equals(sourceEncoding)) {
- sourceEncoding = Charset.defaultCharset().name();
- platformDependent = true;
- runner.setProperty(RunnerProperties.SOURCE_ENCODING, sourceEncoding);
+ boolean onProject = Utils.taskRequiresProject(runner.properties());
+ if (onProject) {
+ String sourceEncoding = runner.property(ScanProperties.PROJECT_SOURCE_ENCODING, "");
+ boolean platformDependent = false;
+ if ("".equals(sourceEncoding)) {
+ sourceEncoding = Charset.defaultCharset().name();
+ platformDependent = true;
+ runner.setProperty(ScanProperties.PROJECT_SOURCE_ENCODING, sourceEncoding);
+ }
+ Logs.info("Default locale: \"" + Locale.getDefault() + "\", source code encoding: \"" + sourceEncoding + "\""
+ + (platformDependent ? " (analysis is platform dependent)" : ""));
}
- Logs.info("Default locale: \"" + Locale.getDefault() + "\", source code encoding: \"" + sourceEncoding + "\""
- + (platformDependent ? " (analysis is platform dependent)" : ""));
}
-
}
import java.util.Arrays;
import java.util.Iterator;
+import java.util.Properties;
class Utils {
private Utils() {
}
return sb.toString();
}
+
+ static boolean taskRequiresProject(Properties props) {
+ return ScanProperties.SCAN_TASK.equals(props.get(RunnerProperties.TASK));
+ }
}
@Test
public void should_set_default_platform_encoding() throws Exception {
+ runner.setProperty("sonar.task", "scan");
encoding.init(runner);
assertThat(runner.property("sonar.sourceEncoding", null)).isEqualTo(Charset.defaultCharset().name());
}
@Test
public void should_use_parameterized_encoding() throws Exception {
+ runner.setProperty("sonar.task", "scan");
runner.setProperty("sonar.sourceEncoding", "THE_ISO_1234");
encoding.init(runner);
assertThat(runner.property("sonar.sourceEncoding", null)).isEqualTo("THE_ISO_1234");
}
+ @Test
+ public void should_not_init_encoding_if_not_project_task() throws Exception {
+ runner.setProperty("sonar.task", "views");
+ encoding.init(runner);
+ assertThat(runner.property("sonar.sourceEncoding", null)).isNull();
+ }
}
import org.junit.Test;
+import java.util.Properties;
+
import static org.fest.assertions.Assertions.assertThat;
public class UtilsTest {
assertThat(Utils.join(new String[]{"foo"}, ",")).isEqualTo("foo");
assertThat(Utils.join(new String[]{"foo", "bar"}, ",")).isEqualTo("foo,bar");
}
+
+ @Test
+ public void task_should_require_project() {
+ Properties props = new Properties();
+ props.setProperty("sonar.task", "scan");
+ assertThat(Utils.taskRequiresProject(props)).isTrue();
+ }
+
+ @Test
+ public void task_should_not_require_project() {
+ Properties props = new Properties();
+ assertThat(Utils.taskRequiresProject(props)).isFalse();
+ props.setProperty("sonar.task", "views");
+ assertThat(Utils.taskRequiresProject(props)).isFalse();
+ }
}
// Logs.info("Server: " + runner.getSonarServerURL());
// try {
// Logs.info("Work directory: " + runner.getWorkDir().getCanonicalPath());
- //Logs.info("Cache directory: " + runner.getCache().getCacheLocation());
// } catch (IOException e) {
// throw new RunnerException("Unable to resolve directory", e);
// }