From 28d1d3a14f28fd57cb3948d29cb7dcb53dea43c8 Mon Sep 17 00:00:00 2001 From: SimonBrandhof Date: Fri, 5 Apr 2013 19:19:58 +0200 Subject: [PATCH] Refactor initialization of dirs --- .../main/java/org/sonar/runner/api/Dirs.java | 68 +++++++++++++ .../java/org/sonar/runner/api/Runner.java | 57 ++++++----- .../sonar/runner/api/RunnerProperties.java | 48 ++++++++++ .../org/sonar/runner/api/ScanProperties.java | 83 ++++++++++++++++ .../org/sonar/runner/api/SourceEncoding.java | 41 ++++++++ .../java/org/sonar/runner/api/DirsTest.java | 95 +++++++++++++++++++ .../sonar/runner/api/EmbeddedRunnerTest.java | 6 +- .../org/sonar/runner/api/SimpleRunner.java | 26 +++++ .../sonar/runner/api/SourceEncodingTest.java | 46 +++++++++ .../src/main/java/org/sonar/runner/Cli.java | 4 +- .../org/sonar/runner/impl/BatchLauncher.java | 4 +- .../sonar/runner/impl/BatchLauncherMain.java | 2 +- .../org/sonar/runner/impl/FileDownloader.java | 6 +- ...Constants.java => InternalProperties.java} | 7 +- 14 files changed, 447 insertions(+), 46 deletions(-) create mode 100644 sonar-runner-api/src/main/java/org/sonar/runner/api/Dirs.java create mode 100644 sonar-runner-api/src/main/java/org/sonar/runner/api/RunnerProperties.java create mode 100644 sonar-runner-api/src/main/java/org/sonar/runner/api/ScanProperties.java create mode 100644 sonar-runner-api/src/main/java/org/sonar/runner/api/SourceEncoding.java create mode 100644 sonar-runner-api/src/test/java/org/sonar/runner/api/DirsTest.java create mode 100644 sonar-runner-api/src/test/java/org/sonar/runner/api/SimpleRunner.java create mode 100644 sonar-runner-api/src/test/java/org/sonar/runner/api/SourceEncodingTest.java rename sonar-runner-impl/src/main/java/org/sonar/runner/impl/{Constants.java => InternalProperties.java} (83%) diff --git a/sonar-runner-api/src/main/java/org/sonar/runner/api/Dirs.java b/sonar-runner-api/src/main/java/org/sonar/runner/api/Dirs.java new file mode 100644 index 0000000..a831d05 --- /dev/null +++ b/sonar-runner-api/src/main/java/org/sonar/runner/api/Dirs.java @@ -0,0 +1,68 @@ +/* + * Sonar Runner - API + * Copyright (C) 2011 SonarSource + * dev@sonar.codehaus.org + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.runner.api; + +import org.apache.commons.io.FileUtils; + +import java.io.File; + +class Dirs { + + void init(Runner runner) { + boolean onProject = ScanProperties.SCAN_TASK.equals(runner.property(RunnerProperties.TASK, null)); + if (onProject) { + initProjectDirs(runner); + } else { + initTaskDirs(runner); + } + } + + private void initProjectDirs(Runner runner) { + String path = runner.property(ScanProperties.PROJECT_BASEDIR, "."); + File projectDir = new File(path); + if (!projectDir.isDirectory()) { + throw new IllegalStateException("Project home must be an existing directory: " + path); + } + runner.setProperty(ScanProperties.PROJECT_BASEDIR, projectDir.getAbsolutePath()); + + File workDir; + path = runner.property(RunnerProperties.WORK_DIR, ""); + if ("".equals(path.trim())) { + workDir = new File(projectDir, ".sonar"); + + } else { + workDir = new File(path); + if (!workDir.isAbsolute()) { + workDir = new File(projectDir, path); + } + } + FileUtils.deleteQuietly(workDir); + runner.setProperty(RunnerProperties.WORK_DIR, workDir.getAbsolutePath()); + } + + /** + * Non-scan task + */ + private void initTaskDirs(Runner runner) { + String path = runner.property(RunnerProperties.WORK_DIR, "."); + File workDir = new File(path); + runner.setProperty(RunnerProperties.WORK_DIR, workDir.getAbsolutePath()); + } +} diff --git a/sonar-runner-api/src/main/java/org/sonar/runner/api/Runner.java b/sonar-runner-api/src/main/java/org/sonar/runner/api/Runner.java index 03e0099..0fbd4ba 100644 --- a/sonar-runner-api/src/main/java/org/sonar/runner/api/Runner.java +++ b/sonar-runner-api/src/main/java/org/sonar/runner/api/Runner.java @@ -19,13 +19,9 @@ */ package org.sonar.runner.api; -import org.sonar.runner.impl.Constants; -import org.sonar.runner.impl.Logs; +import org.sonar.runner.impl.InternalProperties; import javax.annotation.Nullable; - -import java.nio.charset.Charset; -import java.util.Locale; import java.util.Properties; /** @@ -36,15 +32,6 @@ public abstract class Runner { private final Properties properties = new Properties(); protected Runner() { - initProperties(); - } - - private void initProperties() { - // default values - properties.put(Constants.HOST_URL, "http://localhost:9000"); - properties.put(Constants.TASK, "scan"); - properties.put(Constants.RUNNER_APP, "SonarRunner"); - properties.put(Constants.RUNNER_APP_VERSION, RunnerVersion.version()); } public Properties properties() { @@ -55,12 +42,20 @@ public abstract class Runner { /** * Declare Sonar properties, for example sonar.projectKey=>foo. + * + * @see #setProperty(String, String) */ public T addProperties(Properties p) { properties.putAll(p); return (T) this; } + /** + * Declare a Sonar property. + * + * @see RunnerProperties + * @see ScanProperties + */ public T setProperty(String key, String value) { properties.setProperty(key, value); return (T) this; @@ -74,35 +69,39 @@ public abstract class Runner { * User-agent used in the HTTP requests to the Sonar server */ public T setApp(String app, String version) { - setProperty(Constants.RUNNER_APP, app); - setProperty(Constants.RUNNER_APP_VERSION, version); + setProperty(InternalProperties.RUNNER_APP, app); + setProperty(InternalProperties.RUNNER_APP_VERSION, version); return (T) this; } public String app() { - return property(Constants.RUNNER_APP, null); + return property(InternalProperties.RUNNER_APP, null); } public String appVersion() { - return property(Constants.RUNNER_APP_VERSION, null); + return property(InternalProperties.RUNNER_APP_VERSION, null); } public void execute() { - initSourceEncoding(); + initDefaultValues(); + new SourceEncoding().init(this); + new Dirs().init(this); doExecute(); } - private void initSourceEncoding() { - String sourceEncoding = property(Constants.SOURCE_ENCODING, null); - boolean platformDependent = false; - if (sourceEncoding == null || sourceEncoding.equals("")) { - sourceEncoding = Charset.defaultCharset().name(); - platformDependent = true; - setProperty(Constants.SOURCE_ENCODING, sourceEncoding); + protected abstract void doExecute(); + + private void initDefaultValues() { + setDefaultValue(RunnerProperties.HOST_URL, "http://localhost:9000"); + setDefaultValue(RunnerProperties.TASK, "scan"); + setDefaultValue(InternalProperties.RUNNER_APP, "SonarRunner"); + setDefaultValue(InternalProperties.RUNNER_APP_VERSION, RunnerVersion.version()); + } + + private void setDefaultValue(String key, String value) { + if (!properties.containsKey(key)) { + setProperty(key, value); } - Logs.info("Default locale: \"" + Locale.getDefault() + "\", source code encoding: \"" + sourceEncoding + "\"" - + (platformDependent ? " (analysis is platform dependent)" : "")); } - protected abstract void doExecute(); } diff --git a/sonar-runner-api/src/main/java/org/sonar/runner/api/RunnerProperties.java b/sonar-runner-api/src/main/java/org/sonar/runner/api/RunnerProperties.java new file mode 100644 index 0000000..80c4a0c --- /dev/null +++ b/sonar-runner-api/src/main/java/org/sonar/runner/api/RunnerProperties.java @@ -0,0 +1,48 @@ +/* + * Sonar Runner - API + * Copyright (C) 2011 SonarSource + * dev@sonar.codehaus.org + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.runner.api; + +/** + * Mostly used properties that can be injected in {@link Runner#setProperty(String, String)}. + * See documentation for more properties. + * + * @since 2.2 + */ +public interface RunnerProperties { + /** + * HTTP URL of Sonar server, "http://localhost:9000" by default + */ + String HOST_URL = "sonar.host.url"; + + /** + * Task to execute, "scan" by default + */ + 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. + */ + String WORK_DIR = "sonar.working.directory"; +} diff --git a/sonar-runner-api/src/main/java/org/sonar/runner/api/ScanProperties.java b/sonar-runner-api/src/main/java/org/sonar/runner/api/ScanProperties.java new file mode 100644 index 0000000..f41459b --- /dev/null +++ b/sonar-runner-api/src/main/java/org/sonar/runner/api/ScanProperties.java @@ -0,0 +1,83 @@ +/* + * Sonar Runner - API + * Copyright (C) 2011 SonarSource + * dev@sonar.codehaus.org + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.runner.api; + +/** + * Most commonly used properties of the task "scan". These properties are injected in {@link Runner#setProperty(String, String)}. + * See documentation for more properties. + * + * @since 2.2 + */ +public interface ScanProperties { + + /** + * Default task + * @see RunnerProperties#TASK + */ + String SCAN_TASK = "scan"; + + /** + * Required project key + */ + String PROJECT_KEY = "sonar.projectKey"; + + + String PROJECT_NAME = "sonar.projectName"; + + String PROJECT_VERSION = "sonar.projectVersion"; + + /** + * Optional description + */ + String PROJECT_DESCRIPTION = "sonar.projectDescription"; + + /** + * Required paths to source directories, separated by commas, for example: "srcDir1,srcDir2" + */ + String PROJECT_SOURCE_DIRS = "sonar.sources"; + + /** + * Optional paths to test directories, separated by commas, for example: "testDir1,testDir2" + */ + String PROJECT_TEST_DIRS = "sonar.tests"; + + /** + * Optional paths to binaries, for example to declare the directory of Java bytecode. Example : "binDir" + */ + String PROJECT_BINARY_DIRS = "sonar.binaries"; + + /** + * Optional comma-separated list of paths to libraries. Example : path/to/library/*.jar,path/to/specific/library/myLibrary.jar,parent/*.jar + */ + String PROJECT_LIBRARIES = "sonar.libraries"; + + String PROJECT_LANGUAGE = "sonar.language"; + + /** + * It becomes quickly necessary to input historical data and to highlight some events. It is possible by going for example in a subversion tag + * and use this property. Format is yyyy-MM-dd, for example 2010-12-25. + */ + String PROJECT_DATE = "sonar.projectDate"; + + /** + * Property used to specify the base directory of the project to analyse. Default is ".". + */ + String PROJECT_BASEDIR = "sonar.projectBaseDir"; +} diff --git a/sonar-runner-api/src/main/java/org/sonar/runner/api/SourceEncoding.java b/sonar-runner-api/src/main/java/org/sonar/runner/api/SourceEncoding.java new file mode 100644 index 0000000..8782ebd --- /dev/null +++ b/sonar-runner-api/src/main/java/org/sonar/runner/api/SourceEncoding.java @@ -0,0 +1,41 @@ +/* + * Sonar Runner - API + * Copyright (C) 2011 SonarSource + * dev@sonar.codehaus.org + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.runner.api; + +import org.sonar.runner.impl.Logs; + +import java.nio.charset.Charset; +import java.util.Locale; + +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); + } + Logs.info("Default locale: \"" + Locale.getDefault() + "\", source code encoding: \"" + sourceEncoding + "\"" + + (platformDependent ? " (analysis is platform dependent)" : "")); + } + +} diff --git a/sonar-runner-api/src/test/java/org/sonar/runner/api/DirsTest.java b/sonar-runner-api/src/test/java/org/sonar/runner/api/DirsTest.java new file mode 100644 index 0000000..410cea5 --- /dev/null +++ b/sonar-runner-api/src/test/java/org/sonar/runner/api/DirsTest.java @@ -0,0 +1,95 @@ +/* + * Sonar Runner - API + * Copyright (C) 2011 SonarSource + * dev@sonar.codehaus.org + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.runner.api; + +import org.apache.commons.io.FilenameUtils; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import java.io.File; + +import static org.fest.assertions.Assertions.assertThat; + +public class DirsTest { + + Runner runner = new SimpleRunner(); + Dirs dirs = new Dirs(); + + @Rule + public TemporaryFolder temp = new TemporaryFolder(); + + @Test + public void should_init_default_task_work_dir() throws Exception { + runner.setProperty("sonar.task", "views"); + dirs.init(runner); + + File workDir = new File(runner.property("sonar.working.directory", null)); + assertThat(workDir).isNotNull().isDirectory(); + assertThat(workDir.getCanonicalPath()).isEqualTo(new File(".").getCanonicalPath()); + } + + @Test + public void should_use_parameterized_task_work_dir() throws Exception { + runner.setProperty("sonar.task", "views"); + runner.setProperty("sonar.working.directory", "generated/reports"); + dirs.init(runner); + + File workDir = new File(runner.property("sonar.working.directory", null)); + assertThat(workDir).isNotNull(); + assertThat(FilenameUtils.separatorsToUnix(workDir.getCanonicalPath())).contains("generated/reports"); + } + + @Test + public void should_init_default_project_dirs() throws Exception { + runner.setProperty("sonar.task", "scan"); + dirs.init(runner); + + + File projectDir = new File(runner.property("sonar.projectBaseDir", null)); + File workDir = new File(runner.property("sonar.working.directory", null)); + + assertThat(projectDir).isNotNull().isDirectory(); + assertThat(workDir).isNotNull(); + + assertThat(projectDir.getCanonicalPath()).isEqualTo(new File(".").getCanonicalPath()); + assertThat(workDir.getName()).isEqualTo(".sonar"); + assertThat(workDir.getParentFile()).isEqualTo(projectDir); + } + + @Test + public void should_set_relative_path_to_project_work_dir() throws Exception { + File initialProjectDir = temp.newFolder(); + runner.setProperty("sonar.task", "scan"); + runner.setProperty("sonar.working.directory", "relative/path"); + runner.setProperty("sonar.projectBaseDir", initialProjectDir.getAbsolutePath()); + dirs.init(runner); + + + File projectDir = new File(runner.property("sonar.projectBaseDir", null)); + File workDir = new File(runner.property("sonar.working.directory", null)); + + assertThat(projectDir).isNotNull().isDirectory(); + assertThat(projectDir.getCanonicalPath()).isEqualTo(initialProjectDir.getCanonicalPath()); + + assertThat(workDir).isNotNull(); + assertThat(workDir.getCanonicalPath()).isEqualTo(new File(projectDir, "relative/path").getCanonicalPath()); + } +} diff --git a/sonar-runner-api/src/test/java/org/sonar/runner/api/EmbeddedRunnerTest.java b/sonar-runner-api/src/test/java/org/sonar/runner/api/EmbeddedRunnerTest.java index 798dd05..4b06069 100644 --- a/sonar-runner-api/src/test/java/org/sonar/runner/api/EmbeddedRunnerTest.java +++ b/sonar-runner-api/src/test/java/org/sonar/runner/api/EmbeddedRunnerTest.java @@ -22,7 +22,7 @@ package org.sonar.runner.api; import org.junit.Test; import org.mockito.ArgumentMatcher; import org.sonar.runner.impl.BatchLauncher; -import org.sonar.runner.impl.Constants; +import org.sonar.runner.impl.InternalProperties; import java.util.List; import java.util.Properties; @@ -48,10 +48,10 @@ public class EmbeddedRunnerTest { @Test public void should_set_unmasked_packages() { EmbeddedRunner runner = EmbeddedRunner.create(); - assertThat(runner.property(Constants.RUNNER_UNMASKED_PACKAGES, null)).isNull(); + assertThat(runner.property(InternalProperties.RUNNER_UNMASKED_PACKAGES, null)).isNull(); runner = EmbeddedRunner.create().setUnmaskedPackages("org.apache.ant", "org.ant"); - assertThat(runner.property(Constants.RUNNER_UNMASKED_PACKAGES, null)).isEqualTo("org.apache.ant,org.ant"); + assertThat(runner.property(InternalProperties.RUNNER_UNMASKED_PACKAGES, null)).isEqualTo("org.apache.ant,org.ant"); } @Test diff --git a/sonar-runner-api/src/test/java/org/sonar/runner/api/SimpleRunner.java b/sonar-runner-api/src/test/java/org/sonar/runner/api/SimpleRunner.java new file mode 100644 index 0000000..2d485ef --- /dev/null +++ b/sonar-runner-api/src/test/java/org/sonar/runner/api/SimpleRunner.java @@ -0,0 +1,26 @@ +/* + * Sonar Runner - API + * Copyright (C) 2011 SonarSource + * dev@sonar.codehaus.org + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.runner.api; + +class SimpleRunner extends Runner { + @Override + protected void doExecute() { + } +} diff --git a/sonar-runner-api/src/test/java/org/sonar/runner/api/SourceEncodingTest.java b/sonar-runner-api/src/test/java/org/sonar/runner/api/SourceEncodingTest.java new file mode 100644 index 0000000..b7270e9 --- /dev/null +++ b/sonar-runner-api/src/test/java/org/sonar/runner/api/SourceEncodingTest.java @@ -0,0 +1,46 @@ +/* + * Sonar Runner - API + * Copyright (C) 2011 SonarSource + * dev@sonar.codehaus.org + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.runner.api; + +import org.junit.Test; + +import java.nio.charset.Charset; + +import static org.fest.assertions.Assertions.assertThat; + +public class SourceEncodingTest { + + SourceEncoding encoding = new SourceEncoding(); + Runner runner = new SimpleRunner(); + + @Test + public void should_set_default_platform_encoding() throws Exception { + 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.sourceEncoding", "THE_ISO_1234"); + encoding.init(runner); + assertThat(runner.property("sonar.sourceEncoding", null)).isEqualTo("THE_ISO_1234"); + } + +} diff --git a/sonar-runner-dist/src/main/java/org/sonar/runner/Cli.java b/sonar-runner-dist/src/main/java/org/sonar/runner/Cli.java index b23c54a..0acb6ee 100644 --- a/sonar-runner-dist/src/main/java/org/sonar/runner/Cli.java +++ b/sonar-runner-dist/src/main/java/org/sonar/runner/Cli.java @@ -19,7 +19,7 @@ */ package org.sonar.runner; -import org.sonar.runner.impl.Constants; +import org.sonar.runner.api.RunnerProperties; import org.sonar.runner.impl.Logs; import java.util.Properties; @@ -53,7 +53,7 @@ class Cli { for (int i = 0; i < args.length; i++) { String arg = args[i]; if (i == 0 && !arg.startsWith("-")) { - props.setProperty(Constants.TASK, arg); + props.setProperty(RunnerProperties.TASK, arg); } else if ("-h".equals(arg) || "--help".equals(arg)) { printUsage(); diff --git a/sonar-runner-impl/src/main/java/org/sonar/runner/impl/BatchLauncher.java b/sonar-runner-impl/src/main/java/org/sonar/runner/impl/BatchLauncher.java index 8a946d5..949af5e 100644 --- a/sonar-runner-impl/src/main/java/org/sonar/runner/impl/BatchLauncher.java +++ b/sonar-runner-impl/src/main/java/org/sonar/runner/impl/BatchLauncher.java @@ -34,14 +34,14 @@ public class BatchLauncher { if (serverVersion.is35Compatible()) { jarFiles = new Jars35(fileDownloader, new JarExtractor()).download(); } else if (serverVersion.is30Compatible()) { - String workDir = properties.getProperty(Constants.RUNNER_WORK_DIR); + String workDir = properties.getProperty("sonar.working.directory"); jarFiles = new Jars30(fileDownloader).download(new File(workDir), new JarExtractor()); } else { throw new IllegalStateException("Sonar " + serverVersion.version() + " is not supported. Please upgrade Sonar to version 3.0 or more."); } - String unmaskedPackages = properties.getProperty(Constants.RUNNER_UNMASKED_PACKAGES, ""); + String unmaskedPackages = properties.getProperty(InternalProperties.RUNNER_UNMASKED_PACKAGES, ""); IsolatedClassloader classloader = new IsolatedClassloader(getClass().getClassLoader(), unmaskedPackages.split(":")); classloader.addFiles(jarFiles); delegateExecution(classloader, properties, extensions); diff --git a/sonar-runner-impl/src/main/java/org/sonar/runner/impl/BatchLauncherMain.java b/sonar-runner-impl/src/main/java/org/sonar/runner/impl/BatchLauncherMain.java index 280157d..afeb993 100644 --- a/sonar-runner-impl/src/main/java/org/sonar/runner/impl/BatchLauncherMain.java +++ b/sonar-runner-impl/src/main/java/org/sonar/runner/impl/BatchLauncherMain.java @@ -41,7 +41,7 @@ public class BatchLauncherMain { try { props.load(input); // just to be clean, do not forward properties that do not make sense in fork mode - props.remove(Constants.RUNNER_UNMASKED_PACKAGES); + props.remove(InternalProperties.RUNNER_UNMASKED_PACKAGES); } finally { IOUtils.closeQuietly(input); diff --git a/sonar-runner-impl/src/main/java/org/sonar/runner/impl/FileDownloader.java b/sonar-runner-impl/src/main/java/org/sonar/runner/impl/FileDownloader.java index d8d0462..3597f92 100644 --- a/sonar-runner-impl/src/main/java/org/sonar/runner/impl/FileDownloader.java +++ b/sonar-runner-impl/src/main/java/org/sonar/runner/impl/FileDownloader.java @@ -52,9 +52,9 @@ class FileDownloader { } static FileDownloader create(Properties properties) { - String serverUrl = properties.getProperty(Constants.HOST_URL); - String app = properties.getProperty(Constants.RUNNER_APP); - String appVersion = properties.getProperty(Constants.RUNNER_APP_VERSION); + String serverUrl = properties.getProperty("sonar.host.url"); + String app = properties.getProperty(InternalProperties.RUNNER_APP); + String appVersion = properties.getProperty(InternalProperties.RUNNER_APP_VERSION); return new FileDownloader(serverUrl, app, appVersion); } diff --git a/sonar-runner-impl/src/main/java/org/sonar/runner/impl/Constants.java b/sonar-runner-impl/src/main/java/org/sonar/runner/impl/InternalProperties.java similarity index 83% rename from sonar-runner-impl/src/main/java/org/sonar/runner/impl/Constants.java rename to sonar-runner-impl/src/main/java/org/sonar/runner/impl/InternalProperties.java index a06ba1c..8f9956e 100644 --- a/sonar-runner-impl/src/main/java/org/sonar/runner/impl/Constants.java +++ b/sonar-runner-impl/src/main/java/org/sonar/runner/impl/InternalProperties.java @@ -19,13 +19,8 @@ */ package org.sonar.runner.impl; -public interface Constants { - String HOST_URL = "sonar.host.url"; - String TASK = "sonar.task"; - String SOURCE_ENCODING = "sonar.sourceEncoding"; - +public interface InternalProperties { String RUNNER_APP = "sonarRunner.app"; String RUNNER_APP_VERSION = "sonarRunner.appVersion"; String RUNNER_UNMASKED_PACKAGES = "sonarRunner.unmaskedPackages"; - String RUNNER_WORK_DIR = "sonarRunner.workDir"; } -- 2.39.5