diff options
Diffstat (limited to 'src/main/java/org')
-rw-r--r-- | src/main/java/org/sonar/runner/Main.java | 2 | ||||
-rw-r--r-- | src/main/java/org/sonar/runner/Runner.java | 21 | ||||
-rw-r--r-- | src/main/java/org/sonar/runner/RunnerException.java | 35 |
3 files changed, 55 insertions, 3 deletions
diff --git a/src/main/java/org/sonar/runner/Main.java b/src/main/java/org/sonar/runner/Main.java index 8ee7ccb..d596cc5 100644 --- a/src/main/java/org/sonar/runner/Main.java +++ b/src/main/java/org/sonar/runner/Main.java @@ -55,7 +55,7 @@ public final class Main { log("Work directory: " + runner.getWorkDir().getCanonicalPath()); runner.execute(); } catch (IOException e) { - throw new RuntimeException(e); + throw new RunnerException(e); } finally { printStats(startTime); } diff --git a/src/main/java/org/sonar/runner/Runner.java b/src/main/java/org/sonar/runner/Runner.java index 5928c8f..1b7c9a9 100644 --- a/src/main/java/org/sonar/runner/Runner.java +++ b/src/main/java/org/sonar/runner/Runner.java @@ -48,6 +48,16 @@ public final class Runner { */ public static final String VERBOSE = "sonar.verbose"; + /** + * Array of prefixes of versions of Sonar without support of this runner. + */ + private static final String[] unsupportedVersions = { "1", "2.0", "2.1", "2.2", "2.3", "2.4", "2.5" }; + + /** + * Array of all mandatory properties required to execute runner. + */ + private static final String[] MANDATORY_PROPERTIES = { "sonar.projectKey", "sonar.projectName", "sonar.projectVersion", "sources" }; + private File projectDir; private File workDir; private Properties properties; @@ -62,11 +72,20 @@ public final class Runner { } public void execute() { + checkMandatoryProperties(); Bootstrapper bootstrapper = new Bootstrapper("SonarRunner/" + getRunnerVersion(), getServerURl(), getWorkDir()); checkSonarVersion(bootstrapper); delegateExecution(createClassLoader(bootstrapper)); } + void checkMandatoryProperties() { + for (String mandatoryProperty : MANDATORY_PROPERTIES) { + if (!properties.containsKey(mandatoryProperty)) { + throw new RunnerException("You must define mandatory property: " + mandatoryProperty); + } + } + } + public String getServerURl() { return properties.getProperty("sonar.host.url", "http://localhost:9000"); } @@ -131,8 +150,6 @@ public final class Runner { getClass().getClassLoader()); } - private static final String[] unsupportedVersions = { "1", "2.0", "2.1", "2.2", "2.3", "2.4", "2.5" }; - static boolean isUnsupportedVersion(String version) { for (String unsupportedVersion : unsupportedVersions) { if (isVersion(version, unsupportedVersion)) { diff --git a/src/main/java/org/sonar/runner/RunnerException.java b/src/main/java/org/sonar/runner/RunnerException.java new file mode 100644 index 0000000..eb44490 --- /dev/null +++ b/src/main/java/org/sonar/runner/RunnerException.java @@ -0,0 +1,35 @@ +/* + * Sonar Standalone Runner + * 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; + +/** + * @since 1.2 + */ +public class RunnerException extends RuntimeException { + + public RunnerException(String message) { + super(message); + } + + public RunnerException(Throwable cause) { + super(cause); + } + +} |