aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2013-01-30 10:19:34 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2013-01-30 10:19:34 +0100
commit9f2628c20da0a377f81bdeffdec77691568e23c6 (patch)
tree743a4527737deeb837fe94afd336d6c8798c6935 /src/test/java/org
parent6c62a2c27cc29c9a74a833f2226adbd734c132ff (diff)
downloadsonar-scanner-cli-9f2628c20da0a377f81bdeffdec77691568e23c6.tar.gz
sonar-scanner-cli-9f2628c20da0a377f81bdeffdec77691568e23c6.zip
SONAR-2291 Implemented cache on Sonar Runner side (for bootstrap JARs).
Diffstat (limited to 'src/test/java/org')
-rw-r--r--src/test/java/org/sonar/runner/BootstrapClassLoaderTest.java62
-rw-r--r--src/test/java/org/sonar/runner/BootstrapperTest.java66
-rw-r--r--src/test/java/org/sonar/runner/IOUtilsTest.java34
-rw-r--r--src/test/java/org/sonar/runner/LogsTest.java84
-rw-r--r--src/test/java/org/sonar/runner/MainTest.java131
-rw-r--r--src/test/java/org/sonar/runner/RunnerTest.java224
-rw-r--r--src/test/java/org/sonar/runner/StatsTest.java42
-rw-r--r--src/test/java/org/sonar/runner/VersionTest.java36
-rw-r--r--src/test/java/org/sonar/runner/internal/batch/LauncherTest.java75
-rw-r--r--src/test/java/org/sonar/runner/internal/batch/SonarProjectBuilderTest.java580
-rw-r--r--src/test/java/org/sonar/runner/internal/batch/SonarRunnerUtilsTest.java62
11 files changed, 0 insertions, 1396 deletions
diff --git a/src/test/java/org/sonar/runner/BootstrapClassLoaderTest.java b/src/test/java/org/sonar/runner/BootstrapClassLoaderTest.java
deleted file mode 100644
index 9b59b55..0000000
--- a/src/test/java/org/sonar/runner/BootstrapClassLoaderTest.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Sonar 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;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class BootstrapClassLoaderTest {
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- @Test
- public void should_restrict_loading_from_parent() throws Exception {
- BootstrapClassLoader classLoader = new BootstrapClassLoader(getClass().getClassLoader(), "org.apache.ant");
- assertThat(classLoader.canLoadFromParent("org.sonar.runner.internal.batch.Launcher")).isFalse();
- assertThat(classLoader.canLoadFromParent("org.sonar.runner.Runner")).isTrue();
- assertThat(classLoader.canLoadFromParent("org.objectweb.asm.ClassVisitor")).isFalse();
- assertThat(classLoader.canLoadFromParent("org.apache.ant.project.Project")).isTrue();
- }
-
- @Test
- public void should_use_isolated_system_classloader_when_parent_is_excluded() throws ClassNotFoundException {
- thrown.expect(ClassNotFoundException.class);
- thrown.expectMessage("org.junit.Test");
- ClassLoader parent = getClass().getClassLoader();
- BootstrapClassLoader classLoader = new BootstrapClassLoader(parent);
-
- // JUnit is available in the parent classloader (classpath used to execute this test) but not in the core JVM
- assertThat(classLoader.loadClass("java.lang.String", false)).isNotNull();
- classLoader.loadClass("org.junit.Test", false);
- }
-
- @Test
- public void should_find_in_parent_when_matches_unmasked_packages() throws ClassNotFoundException {
- ClassLoader parent = getClass().getClassLoader();
- BootstrapClassLoader classLoader = new BootstrapClassLoader(parent, "org.junit");
-
- // JUnit is available in the parent classloader (classpath used to execute this test) but not in the core JVM
- assertThat(classLoader.loadClass("org.junit.Test", false)).isNotNull();
- }
-}
diff --git a/src/test/java/org/sonar/runner/BootstrapperTest.java b/src/test/java/org/sonar/runner/BootstrapperTest.java
deleted file mode 100644
index 448858c..0000000
--- a/src/test/java/org/sonar/runner/BootstrapperTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Sonar 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;
-
-import org.sonar.runner.Bootstrapper;
-
-import org.junit.Test;
-
-import java.io.File;
-import java.io.IOException;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class BootstrapperTest {
-
- @Test
- public void shouldRemoveLastUrlSlash() {
- Bootstrapper bootstrapper = new Bootstrapper("", "http://test/", new File("target"));
- assertThat(bootstrapper.getServerUrl()).isEqualTo("http://test");
- }
-
- @Test(expected = Exception.class)
- public void shouldFailIfCanNotConnectServer() {
- Bootstrapper bootstrapper = new Bootstrapper("", "http://unknown.foo", new File("target"));
- bootstrapper.getServerVersion();
- }
-
- @Test
- public void shouldReturnUserAgent() {
- Bootstrapper bootstrapper = new Bootstrapper("test/0.1", "http://unknown.foo", new File("target"));
- String userAgent = bootstrapper.getUserAgent();
-
- assertThat(userAgent.length()).isGreaterThan(0);
- assertThat(userAgent).startsWith("sonar-bootstrapper/");
- assertThat(userAgent).endsWith(" test/0.1");
- }
-
- @Test
- public void shouldReturnValidVersion() {
- Bootstrapper bootstrapper = new Bootstrapper("", "http://test", new File("target")) {
- @Override
- String remoteContent(String path) throws IOException {
- return "2.6";
- }
- };
- assertThat(bootstrapper.getServerVersion()).isEqualTo("2.6");
- }
-
-}
diff --git a/src/test/java/org/sonar/runner/IOUtilsTest.java b/src/test/java/org/sonar/runner/IOUtilsTest.java
deleted file mode 100644
index d7ff4d6..0000000
--- a/src/test/java/org/sonar/runner/IOUtilsTest.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Sonar 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;
-
-import org.junit.Test;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class IOUtilsTest {
-
- @Test
- public void shouldParseEncodingFromContentType() {
- assertThat(IOUtils.getCharsetFromContentType("text/html; charset=EUC-JP")).isEqualTo("EUC-JP");
- assertThat(IOUtils.getCharsetFromContentType("text/html")).isNull();
- }
-
-}
diff --git a/src/test/java/org/sonar/runner/LogsTest.java b/src/test/java/org/sonar/runner/LogsTest.java
deleted file mode 100644
index 19ce1cf..0000000
--- a/src/test/java/org/sonar/runner/LogsTest.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Sonar 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;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.utils.SonarException;
-
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class LogsTest {
-
- private PrintStream oldSysout;
- private PrintStream oldSyserr;
-
- private ByteArrayOutputStream baosOut;
- private ByteArrayOutputStream baosErr;
-
- @Before
- public void prepare() {
- oldSysout = System.out;
- oldSyserr = System.err;
- baosOut = new ByteArrayOutputStream();
- System.setOut(new PrintStream(baosOut));
- baosErr = new ByteArrayOutputStream();
- System.setErr(new PrintStream(baosErr));
- }
-
- @After
- public void restore() {
- System.setOut(oldSysout);
- System.setErr(oldSyserr);
- }
-
- @Test
- public void shouldLogInfo() {
- Logs.info("info");
- assertThat(baosOut.toString()).contains("INFO: info");
- assertThat(baosErr.toString()).isEmpty();
- }
-
- @Test
- public void shouldLogError() {
- Logs.error("error");
- assertThat(baosOut.toString()).isEmpty();
- assertThat(baosErr.toString()).contains("ERROR: error");
- }
-
- @Test
- public void shouldLogErrorWithoutThrowable() {
- Logs.error("error", null);
- assertThat(baosOut.toString()).isEmpty();
- assertThat(baosErr.toString()).contains("ERROR: error");
- }
-
- @Test
- public void shouldLogErrorWithThrowable() {
- Logs.error("error", new SonarException());
- assertThat(baosOut.toString()).isEmpty();
- assertThat(baosErr.toString()).contains("ERROR: error").contains("SonarException");
- }
-
-}
diff --git a/src/test/java/org/sonar/runner/MainTest.java b/src/test/java/org/sonar/runner/MainTest.java
deleted file mode 100644
index a915857..0000000
--- a/src/test/java/org/sonar/runner/MainTest.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Sonar 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;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import java.io.File;
-import java.util.Properties;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class MainTest {
-
- private Main main;
-
- @Before
- public void prepare() {
- main = new Main();
- }
-
- @Test
- public void shouldParseEmptyArguments() {
- Properties props = main.parseArguments(new String[] {});
- assertThat(props).isEmpty();
- }
-
- @Test
- public void shouldParseArguments() {
- Properties props = main.parseArguments(new String[] {"-D", "foo=bar", "--define", "hello=world", "-Dboolean"});
- assertThat(props).hasSize(3);
- assertThat(props.getProperty("foo")).isEqualTo("bar");
- assertThat(props.getProperty("hello")).isEqualTo("world");
- assertThat(props.getProperty("boolean")).isEqualTo("true");
- }
-
- @Test
- public void shouldParseCommand() {
-
- Properties props = main.parseArguments(new String[] {"cmd", "-D", "foo=bar", "--define", "hello=world", "-Dboolean"});
- assertThat(main.command).isEqualTo("cmd");
- assertThat(props).hasSize(3);
- }
-
- @Test
- public void shouldEnableDebugMode() {
- Properties props = main.parseArguments(new String[] {"-X"});
- assertThat(main.debugMode).isTrue();
- assertThat(main.displayStackTrace).isTrue();
- assertThat(props.getProperty(Runner.PROPERTY_VERBOSE)).isEqualTo("true");
- }
-
- @Test
- public void shouldEnableError() {
- Properties props = main.parseArguments(new String[] {"-e"});
- assertThat(main.debugMode).isFalse();
- assertThat(main.displayStackTrace).isTrue();
- assertThat(props.getProperty(Runner.PROPERTY_VERBOSE)).isNull();
- }
-
- @Test
- public void shouldDisableDebugModeAndStackByDefault() {
- Properties props = main.parseArguments(new String[] {});
- assertThat(main.debugMode).isFalse();
- assertThat(main.displayStackTrace).isFalse();
- assertThat(props.getProperty(Runner.PROPERTY_VERBOSE)).isNull();
- }
-
- @Test
- public void shouldLoadRunnerSettingsByHome() throws Exception {
- File home = new File(getClass().getResource("/org/sonar/runner/MainTest/shouldLoadRunnerSettingsByHome/").toURI());
- Properties args = new Properties();
- args.setProperty("runner.home", home.getCanonicalPath());
-
- Properties props = new Main().loadRunnerConfiguration(args);
-
- assertThat(props.getProperty("sonar.host.url")).isEqualTo("http://moon/sonar");
- }
-
- @Test
- public void shouldNotFailIfNoHome() throws Exception {
- Properties args = new Properties();
- Properties props = new Main().loadRunnerConfiguration(args);
-
- assertThat(props).isEmpty();
- }
-
- @Test
- public void shouldLoadRunnerSettingsByDirectPath() throws Exception {
- File settings = new File(getClass().getResource("/org/sonar/runner/MainTest/shouldLoadRunnerSettingsByDirectPath/other-conf.properties").toURI());
- Properties args = new Properties();
- args.setProperty("runner.settings", settings.getCanonicalPath());
- Properties props = new Main().loadRunnerConfiguration(args);
-
- assertThat(props.getProperty("sonar.host.url")).isEqualTo("http://other/sonar");
- }
-
- @Test
- public void shouldLoadCompleteConfiguration() throws Exception {
- File runnerHome = new File(getClass().getResource("/org/sonar/runner/MainTest/shouldLoadCompleteConfiguration/runner").toURI());
- File projectHome = new File(getClass().getResource("/org/sonar/runner/MainTest/shouldLoadCompleteConfiguration/project").toURI());
- Main main = new Main();
- Properties args = main.parseArguments(new String[] {
- "-D", "runner.home=" + runnerHome.getCanonicalPath(),
- "-D", "project.home=" + projectHome.getCanonicalPath()
- });
- main.loadProperties(args);
-
- assertThat(main.projectProperties.getProperty("project.prop")).isEqualTo("foo");
- assertThat(main.projectProperties.getProperty("overridden.prop")).isEqualTo("project scope");
- assertThat(main.globalProperties.getProperty("global.prop")).isEqualTo("jdbc:mysql:localhost/sonar");
- }
-
-}
diff --git a/src/test/java/org/sonar/runner/RunnerTest.java b/src/test/java/org/sonar/runner/RunnerTest.java
deleted file mode 100644
index d3e89de..0000000
--- a/src/test/java/org/sonar/runner/RunnerTest.java
+++ /dev/null
@@ -1,224 +0,0 @@
-/*
- * Sonar 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;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.test.TestUtils;
-
-import java.io.File;
-import java.nio.charset.Charset;
-import java.util.Properties;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class RunnerTest {
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- @Test
- public void shouldHaveDefaultEncodingIfNotForce() {
- Runner runner = Runner.create(new Properties());
- assertThat(runner.getSourceCodeEncoding()).isEqualTo(Charset.defaultCharset().name());
- assertThat(runner.isEncodingPlatformDependant()).isTrue();
- }
-
- @Test
- public void shouldKeepEncodingIfSpecified() {
- Properties props = new Properties();
- // Yeah, windows charset!
- props.setProperty("sonar.sourceEncoding", "cp1252");
- Runner runner = Runner.create(props);
- assertThat(runner.getSourceCodeEncoding()).isEqualTo("cp1252");
- assertThat(runner.isEncodingPlatformDependant()).isFalse();
- }
-
- @Test
- public void shouldHaveDefaultEnvironmentInformationValues() {
- Runner runner = Runner.create(new Properties());
- assertThat(runner.getProperties().getProperty(Runner.PROPERTY_ENVIRONMENT_INFORMATION_KEY)).isEqualTo("Runner");
- assertThat(runner.getProperties().getProperty(Runner.PROPERTY_ENVIRONMENT_INFORMATION_VERSION)).contains(".");
- assertThat(runner.getProperties().getProperty(Runner.PROPERTY_ENVIRONMENT_INFORMATION_VERSION)).doesNotContain("$");
- }
-
- @Test
- public void shouldOverwriteDefaultEnvironmentInformationValues() {
- Runner runner = Runner.create(new Properties());
- runner.setEnvironmentInformation("Ant", "1.2.3");
- assertThat(runner.getProperties().getProperty(Runner.PROPERTY_ENVIRONMENT_INFORMATION_KEY)).isEqualTo("Ant");
- assertThat(runner.getProperties().getProperty(Runner.PROPERTY_ENVIRONMENT_INFORMATION_VERSION)).isEqualTo("1.2.3");
- }
-
- @Test
- public void shouldCheckVersion() {
- assertThat(Runner.isUnsupportedVersion("1.0")).isTrue();
- assertThat(Runner.isUnsupportedVersion("2.0")).isTrue();
- assertThat(Runner.isUnsupportedVersion("2.1")).isTrue();
- assertThat(Runner.isUnsupportedVersion("2.2")).isTrue();
- assertThat(Runner.isUnsupportedVersion("2.3")).isTrue();
- assertThat(Runner.isUnsupportedVersion("2.4")).isTrue();
- assertThat(Runner.isUnsupportedVersion("2.4.1")).isTrue();
- assertThat(Runner.isUnsupportedVersion("2.5")).isTrue();
- assertThat(Runner.isUnsupportedVersion("2.11")).isFalse();
- assertThat(Runner.isUnsupportedVersion("3.0")).isFalse();
- assertThat(Runner.isUnsupportedVersion("3.1")).isFalse();
- assertThat(Runner.isUnsupportedVersion("3.2")).isFalse();
- assertThat(Runner.isUnsupportedVersion("3.3")).isFalse();
- assertThat(Runner.isUnsupportedVersion("3.4")).isFalse();
- assertThat(Runner.isUnsupportedVersion("3.5")).isFalse();
- }
-
- @Test
- public void shouldCheckVersionForTasks() {
- assertThat(Runner.isUnsupportedVersionForTasks("1.0")).isTrue();
- assertThat(Runner.isUnsupportedVersionForTasks("2.0")).isTrue();
- assertThat(Runner.isUnsupportedVersionForTasks("2.1")).isTrue();
- assertThat(Runner.isUnsupportedVersionForTasks("2.2")).isTrue();
- assertThat(Runner.isUnsupportedVersionForTasks("2.3")).isTrue();
- assertThat(Runner.isUnsupportedVersionForTasks("2.4")).isTrue();
- assertThat(Runner.isUnsupportedVersionForTasks("2.4.1")).isTrue();
- assertThat(Runner.isUnsupportedVersionForTasks("2.5")).isTrue();
- assertThat(Runner.isUnsupportedVersionForTasks("2.11")).isTrue();
- assertThat(Runner.isUnsupportedVersionForTasks("3.0")).isTrue();
- assertThat(Runner.isUnsupportedVersionForTasks("3.1")).isTrue();
- assertThat(Runner.isUnsupportedVersionForTasks("3.2")).isTrue();
- assertThat(Runner.isUnsupportedVersionForTasks("3.3")).isTrue();
- assertThat(Runner.isUnsupportedVersionForTasks("3.4")).isTrue();
- assertThat(Runner.isUnsupportedVersionForTasks("3.5")).isFalse();
- }
-
- @Test
- public void shouldGetServerUrl() {
- Properties properties = new Properties();
- Runner runner = Runner.create(properties);
- assertThat(runner.getSonarServerURL()).isEqualTo("http://localhost:9000");
- properties.setProperty("sonar.host.url", "foo");
- assertThat(runner.getSonarServerURL()).isEqualTo("foo");
- }
-
- @Test
- public void shouldInitDirs() throws Exception {
- Properties props = new Properties();
- File home = TestUtils.getResource(this.getClass(), "shouldInitDirs");
- props.setProperty(Runner.PROPERTY_SONAR_PROJECT_BASEDIR, home.getCanonicalPath());
- Runner runner = Runner.create(props);
- assertThat(runner.getProperties().get(Runner.PROPERTY_SONAR_PROJECT_BASEDIR)).isEqualTo(home.getCanonicalPath());
-
- assertThat(runner.getProjectDir()).isEqualTo(home);
- assertThat(runner.getWorkDir()).isEqualTo(new File(home, ".sonar"));
- }
-
- @Test
- public void shouldInitProjectDirWithCurrentDir() throws Exception {
- Runner runner = Runner.create(new Properties());
-
- assertThat(runner.getProjectDir().isDirectory()).isTrue();
- assertThat(runner.getProjectDir().exists()).isTrue();
- }
-
- @Test
- public void shouldSetValidBaseDirOnConstructor() {
- File baseDir = TestUtils.getResource(this.getClass(), "shouldInitDirs");
- Runner runner = Runner.create(new Properties(), baseDir);
- assertThat(runner.getProjectDir()).isEqualTo(baseDir);
- }
-
- @Test
- public void shouldFailIfBaseDirDoesNotExist() {
- File fakeBasedir = new File("fake");
-
- thrown.expect(RunnerException.class);
- thrown.expectMessage("Project home must be an existing directory: " + fakeBasedir.getAbsolutePath());
-
- Runner.create(new Properties(), fakeBasedir);
- }
-
- @Test
- public void shouldSpecifyWorkingDirectory() {
- Properties properties = new Properties();
- Runner runner = Runner.create(properties);
- assertThat(runner.getWorkDir()).isEqualTo(new File(".", ".sonar"));
-
- // empty string
- properties.setProperty(Runner.PROPERTY_WORK_DIRECTORY, " ");
- runner = Runner.create(properties);
- assertThat(runner.getWorkDir()).isEqualTo(new File(".", ".sonar").getAbsoluteFile());
-
- // real relative path
- properties.setProperty(Runner.PROPERTY_WORK_DIRECTORY, "temp-dir");
- runner = Runner.create(properties);
- assertThat(runner.getWorkDir()).isEqualTo(new File(".", "temp-dir").getAbsoluteFile());
-
- // real absolute path
- properties.setProperty(Runner.PROPERTY_WORK_DIRECTORY, new File("target", "temp-dir2").getAbsolutePath());
- runner = Runner.create(properties);
- assertThat(runner.getWorkDir()).isEqualTo(new File("target", "temp-dir2").getAbsoluteFile());
- }
-
- @Test
- public void shouldDeleteWorkingDirectory() {
- Properties properties = new Properties();
- File workDir = new File("target", "temp-dir-should-be-deleted");
- workDir.mkdirs();
- assertThat(workDir.exists()).isTrue();
- // real absolute path
- properties.setProperty(Runner.PROPERTY_WORK_DIRECTORY, workDir.getAbsolutePath());
- Runner.create(properties);
- assertThat(workDir.exists()).isFalse();
- }
-
- @Test
- public void shouldCheckSonarVersion() {
- Properties properties = new Properties();
- Runner runner = Runner.create(properties);
- Bootstrapper bootstrapper = mock(Bootstrapper.class);
-
- // nothing happens, OK
- when(bootstrapper.getServerVersion()).thenReturn("3.0");
- runner.checkSonarVersion(bootstrapper);
-
- // but fails with older versions
- when(bootstrapper.getServerVersion()).thenReturn("2.1");
- thrown.expect(RunnerException.class);
- thrown.expectMessage("Sonar 2.1 is not supported. Please upgrade Sonar to version 2.11 or more.");
- runner.checkSonarVersion(bootstrapper);
- }
-
- @Test
- public void shouldCheckSonarVersionForTasks() {
- Properties properties = new Properties();
- Runner runner = Runner.create("foo-cmd", properties, properties);
- Bootstrapper bootstrapper = mock(Bootstrapper.class);
-
- // nothing happens, OK
- when(bootstrapper.getServerVersion()).thenReturn("3.5");
- runner.checkSonarVersion(bootstrapper);
-
- // but fails with older versions
- when(bootstrapper.getServerVersion()).thenReturn("3.4");
- thrown.expect(RunnerException.class);
- thrown.expectMessage("Sonar 3.4 doesn't support tasks. Please upgrade Sonar to version 3.5 or more.");
- runner.checkSonarVersion(bootstrapper);
- }
-}
diff --git a/src/test/java/org/sonar/runner/StatsTest.java b/src/test/java/org/sonar/runner/StatsTest.java
deleted file mode 100644
index 2df6426..0000000
--- a/src/test/java/org/sonar/runner/StatsTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Sonar 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;
-
-import org.junit.Test;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-
-public class StatsTest {
-
- @Test
- public void shouldPrintStats() {
- new Stats().start().stop();
- //TODO mock Logs
- }
-
- @Test
- public void shouldFormatTime() {
- assertThat(Stats.formatTime(1 * 60 * 60 * 1000 + 2 * 60 * 1000 + 3 * 1000 + 400)).isEqualTo("1:02:03.400s");
- assertThat(Stats.formatTime(2 * 60 * 1000 + 3 * 1000 + 400)).isEqualTo("2:03.400s");
- assertThat(Stats.formatTime(3 * 1000 + 400)).isEqualTo("3.400s");
- assertThat(Stats.formatTime(400)).isEqualTo("0.400s");
- }
-}
diff --git a/src/test/java/org/sonar/runner/VersionTest.java b/src/test/java/org/sonar/runner/VersionTest.java
deleted file mode 100644
index 1ca1470..0000000
--- a/src/test/java/org/sonar/runner/VersionTest.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Sonar 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;
-
-import org.junit.Test;
-import org.sonar.runner.Version;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class VersionTest {
-
- @Test
- public void shouldLoadVersion() {
- String version = Version.getVersion();
- assertThat(version).contains(".");
- assertThat(version).doesNotContain("$");
- }
-
-}
diff --git a/src/test/java/org/sonar/runner/internal/batch/LauncherTest.java b/src/test/java/org/sonar/runner/internal/batch/LauncherTest.java
deleted file mode 100644
index b06ba86..0000000
--- a/src/test/java/org/sonar/runner/internal/batch/LauncherTest.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Sonar 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.internal.batch;
-
-import com.google.common.collect.Lists;
-import org.junit.Test;
-import org.sonar.runner.Runner;
-
-import java.util.Properties;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class LauncherTest {
-
- @Test
- public void testGetSqlLevel() throws Exception {
- Properties conf = new Properties();
-
- assertThat(Launcher.getSqlLevel(conf)).isEqualTo("WARN");
-
- conf.setProperty("sonar.showSql", "true");
- assertThat(Launcher.getSqlLevel(conf)).isEqualTo("DEBUG");
-
- conf.setProperty("sonar.showSql", "false");
- assertThat(Launcher.getSqlLevel(conf)).isEqualTo("WARN");
- }
-
- @Test
- public void testGetSqlResultsLevel() throws Exception {
- Properties conf = new Properties();
-
- assertThat(Launcher.getSqlResultsLevel(conf)).isEqualTo("WARN");
-
- conf.setProperty("sonar.showSqlResults", "true");
- assertThat(Launcher.getSqlResultsLevel(conf)).isEqualTo("DEBUG");
-
- conf.setProperty("sonar.showSqlResults", "false");
- assertThat(Launcher.getSqlResultsLevel(conf)).isEqualTo("WARN");
- }
-
- @Test
- public void shouldDetermineVerboseMode() {
- Properties properties = new Properties();
- Launcher launcher = new Launcher(properties, Lists.newArrayList());
- assertThat(launcher.isDebug()).isFalse();
- properties.setProperty(Runner.PROPERTY_VERBOSE, "true");
- assertThat(launcher.isDebug()).isTrue();
- }
-
- @Test
- public void shouldSupportDeprecatedDebugProperty() {
- Properties properties = new Properties();
- Launcher launcher = new Launcher(properties, Lists.newArrayList());
- properties.setProperty(Runner.PROPERTY_OLD_DEBUG_MODE, "true");
- assertThat(launcher.isDebug()).isTrue();
- }
-
-}
diff --git a/src/test/java/org/sonar/runner/internal/batch/SonarProjectBuilderTest.java b/src/test/java/org/sonar/runner/internal/batch/SonarProjectBuilderTest.java
deleted file mode 100644
index 4cb65ab..0000000
--- a/src/test/java/org/sonar/runner/internal/batch/SonarProjectBuilderTest.java
+++ /dev/null
@@ -1,580 +0,0 @@
-/*
- * Sonar 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.internal.batch;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.runner.RunnerException;
-import org.sonar.test.TestUtils;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.List;
-import java.util.Properties;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class SonarProjectBuilderTest {
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- @Test
- public void shouldDefineSimpleProject() throws IOException {
- ProjectDefinition projectDefinition = loadProjectDefinition("simple-project");
-
- assertThat(projectDefinition.getKey()).isEqualTo("com.foo.project");
- assertThat(projectDefinition.getName()).isEqualTo("Foo Project");
- assertThat(projectDefinition.getVersion()).isEqualTo("1.0-SNAPSHOT");
- assertThat(projectDefinition.getDescription()).isEqualTo("Description of Foo Project");
- assertThat(projectDefinition.getSourceDirs()).contains("sources");
- assertThat(projectDefinition.getTestDirs()).contains("tests");
- assertThat(projectDefinition.getBinaries()).contains("target/classes");
- assertThat(projectDefinition.getLibraries()).contains(TestUtils.getResource(this.getClass(), "simple-project/libs/lib2.txt").getAbsolutePath(),
- TestUtils.getResource(this.getClass(), "simple-project/libs/lib2.txt").getAbsolutePath());
- }
-
- @Test
- public void shouldDefineSimpleProjectWithDeprecatedProperties() throws IOException {
- ProjectDefinition projectDefinition = loadProjectDefinition("simple-project-with-deprecated-props");
-
- assertThat(projectDefinition.getSourceDirs()).contains("sources");
- assertThat(projectDefinition.getTestDirs()).contains("tests");
- assertThat(projectDefinition.getBinaries()).contains("target/classes");
- assertThat(projectDefinition.getLibraries()).contains(
- TestUtils.getResource(this.getClass(), "simple-project-with-deprecated-props/libs/lib2.txt").getAbsolutePath(),
- TestUtils.getResource(this.getClass(), "simple-project-with-deprecated-props/libs/lib2.txt").getAbsolutePath());
- }
-
- @Test
- public void shouldFailIfUnexistingSourceDirectory() throws IOException {
- thrown.expect(RunnerException.class);
- thrown.expectMessage("The folder 'unexisting-source-dir' does not exist for 'com.foo.project' (base directory = "
- + TestUtils.getResource(this.getClass(), "simple-project-with-unexisting-source-dir") + ")");
-
- loadProjectDefinition("simple-project-with-unexisting-source-dir");
- }
-
- @Test
- public void shouldDefineMultiModuleProjectWithDefinitionsAllInRootProject() throws IOException {
- ProjectDefinition rootProject = loadProjectDefinition("multi-module-definitions-all-in-root");
-
- // CHECK ROOT
- assertThat(rootProject.getKey()).isEqualTo("com.foo.project");
- assertThat(rootProject.getName()).isEqualTo("Foo Project");
- assertThat(rootProject.getVersion()).isEqualTo("1.0-SNAPSHOT");
- assertThat(rootProject.getDescription()).isEqualTo("Description of Foo Project");
- // root project must not contain some properties - even if they are defined in the root properties file
- assertThat(rootProject.getSourceDirs().contains("sources")).isFalse();
- assertThat(rootProject.getTestDirs().contains("tests")).isFalse();
- assertThat(rootProject.getBinaries().contains("target/classes")).isFalse();
- // and module properties must have been cleaned
- assertThat(rootProject.getProperties().getProperty("module1.sonar.projectKey")).isNull();
- assertThat(rootProject.getProperties().getProperty("module2.sonar.projectKey")).isNull();
- // Check baseDir and workDir
- assertThat(rootProject.getBaseDir().getCanonicalFile())
- .isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root"));
- assertThat(rootProject.getWorkDir().getCanonicalFile())
- .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root"), ".sonar"));
-
- // CHECK MODULES
- List<ProjectDefinition> modules = rootProject.getSubProjects();
- assertThat(modules.size()).isEqualTo(2);
-
- // Module 1
- ProjectDefinition module1 = modules.get(0);
- assertThat(module1.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root/module1"));
- assertThat(module1.getKey()).isEqualTo("com.foo.project:module1");
- assertThat(module1.getName()).isEqualTo("module1");
- assertThat(module1.getVersion()).isEqualTo("1.0-SNAPSHOT");
- // Description should not be inherited from parent if not set
- assertThat(module1.getDescription()).isNull();
- assertThat(module1.getSourceDirs()).contains("sources");
- assertThat(module1.getTestDirs()).contains("tests");
- assertThat(module1.getBinaries()).contains("target/classes");
- // and module properties must have been cleaned
- assertThat(module1.getProperties().getProperty("module1.sonar.projectKey")).isNull();
- assertThat(module1.getProperties().getProperty("module2.sonar.projectKey")).isNull();
- // Check baseDir and workDir
- assertThat(module1.getBaseDir().getCanonicalFile())
- .isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root/module1"));
- assertThat(module1.getWorkDir().getCanonicalFile())
- .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root"), ".sonar/com.foo.project_module1"));
-
- // Module 2
- ProjectDefinition module2 = modules.get(1);
- assertThat(module2.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root/module2"));
- assertThat(module2.getKey()).isEqualTo("com.foo.project:com.foo.project.module2");
- assertThat(module2.getName()).isEqualTo("Foo Module 2");
- assertThat(module2.getVersion()).isEqualTo("1.0-SNAPSHOT");
- assertThat(module2.getDescription()).isEqualTo("Description of Module 2");
- assertThat(module2.getSourceDirs()).contains("src");
- assertThat(module2.getTestDirs()).contains("tests");
- assertThat(module2.getBinaries()).contains("target/classes");
- // and module properties must have been cleaned
- assertThat(module2.getProperties().getProperty("module1.sonar.projectKey")).isNull();
- assertThat(module2.getProperties().getProperty("module2.sonar.projectKey")).isNull();
- // Check baseDir and workDir
- assertThat(module2.getBaseDir().getCanonicalFile())
- .isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root/module2"));
- assertThat(module2.getWorkDir().getCanonicalFile())
- .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root"), ".sonar/com.foo.project_com.foo.project.module2"));
- }
-
- @Test
- public void shouldDefineMultiModuleProjectWithDefinitionsAllInEachModule() throws IOException {
- ProjectDefinition rootProject = loadProjectDefinition("multi-module-definitions-in-each-module");
-
- // CHECK ROOT
- assertThat(rootProject.getKey()).isEqualTo("com.foo.project");
- assertThat(rootProject.getName()).isEqualTo("Foo Project");
- assertThat(rootProject.getVersion()).isEqualTo("1.0-SNAPSHOT");
- assertThat(rootProject.getDescription()).isEqualTo("Description of Foo Project");
- // root project must not contain some properties - even if they are defined in the root properties file
- assertThat(rootProject.getSourceDirs().contains("sources")).isFalse();
- assertThat(rootProject.getTestDirs().contains("tests")).isFalse();
- assertThat(rootProject.getBinaries().contains("target/classes")).isFalse();
- // and module properties must have been cleaned
- assertThat(rootProject.getProperties().getProperty("module1.sonar.projectKey")).isNull();
- assertThat(rootProject.getProperties().getProperty("module2.sonar.projectKey")).isNull();
-
- // CHECK MODULES
- List<ProjectDefinition> modules = rootProject.getSubProjects();
- assertThat(modules.size()).isEqualTo(2);
-
- // Module 1
- ProjectDefinition module1 = modules.get(0);
- assertThat(module1.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-in-each-module/module1"));
- assertThat(module1.getKey()).isEqualTo("com.foo.project:com.foo.project.module1");
- assertThat(module1.getName()).isEqualTo("Foo Module 1");
- assertThat(module1.getVersion()).isEqualTo("1.0-SNAPSHOT");
- // Description should not be inherited from parent if not set
- assertThat(module1.getDescription()).isEqualTo("Description of Module 1");
- assertThat(module1.getSourceDirs()).contains("sources");
- assertThat(module1.getTestDirs()).contains("tests");
- assertThat(module1.getBinaries()).contains("target/classes");
- // and module properties must have been cleaned
- assertThat(module1.getProperties().getProperty("module1.sonar.projectKey")).isNull();
- assertThat(module1.getProperties().getProperty("module2.sonar.projectKey")).isNull();
-
- // Module 2
- ProjectDefinition module2 = modules.get(1);
- assertThat(module2.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-in-each-module/module2/newBaseDir"));
- assertThat(module2.getKey()).isEqualTo("com.foo.project:com.foo.project.module2");
- assertThat(module2.getName()).isEqualTo("Foo Module 2");
- assertThat(module2.getVersion()).isEqualTo("1.0-SNAPSHOT");
- assertThat(module2.getDescription()).isEqualTo("Description of Module 2");
- assertThat(module2.getSourceDirs()).contains("src");
- assertThat(module2.getTestDirs()).contains("tests");
- assertThat(module2.getBinaries()).contains("target/classes");
- // and module properties must have been cleaned
- assertThat(module2.getProperties().getProperty("module1.sonar.projectKey")).isNull();
- assertThat(module2.getProperties().getProperty("module2.sonar.projectKey")).isNull();
- }
-
- @Test
- public void shouldDefineMultiModuleProjectWithDefinitionsModule1Inherited() throws IOException {
- ProjectDefinition rootProject = loadProjectDefinition("multi-module-definitions-in-each-module-inherited");
-
- // CHECK ROOT
- assertThat(rootProject.getKey()).isEqualTo("com.foo.project");
- assertThat(rootProject.getName()).isEqualTo("Foo Project");
- assertThat(rootProject.getVersion()).isEqualTo("1.0-SNAPSHOT");
- assertThat(rootProject.getDescription()).isEqualTo("Description of Foo Project");
- // root project must not contain some properties - even if they are defined in the root properties file
- assertThat(rootProject.getSourceDirs().contains("sources")).isFalse();
- assertThat(rootProject.getTestDirs().contains("tests")).isFalse();
- assertThat(rootProject.getBinaries().contains("target/classes")).isFalse();
- // and module properties must have been cleaned
- assertThat(rootProject.getProperties().getProperty("module1.sonar.projectKey")).isNull();
- assertThat(rootProject.getProperties().getProperty("module2.sonar.projectKey")).isNull();
-
- // CHECK MODULES
- List<ProjectDefinition> modules = rootProject.getSubProjects();
- assertThat(modules.size()).isEqualTo(2);
-
- // Module 1
- ProjectDefinition module1 = modules.get(0);
- assertThat(module1.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-in-each-module-inherited/module1"));
- assertThat(module1.getKey()).isEqualTo("com.foo.project:module1");
- assertThat(module1.getName()).isEqualTo("module1");
- assertThat(module1.getVersion()).isEqualTo("1.0-SNAPSHOT");
- // Description should not be inherited from parent if not set
- assertThat(module1.getDescription()).isNull();
- assertThat(module1.getSourceDirs()).contains("sources");
- assertThat(module1.getTestDirs()).contains("tests");
- assertThat(module1.getBinaries()).contains("target/classes");
- // and module properties must have been cleaned
- assertThat(module1.getProperties().getProperty("module1.sonar.projectKey")).isNull();
- assertThat(module1.getProperties().getProperty("module2.sonar.projectKey")).isNull();
-
- // Module 2
- ProjectDefinition module2 = modules.get(1);
- assertThat(module2.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-in-each-module-inherited/module2/newBaseDir"));
- assertThat(module2.getKey()).isEqualTo("com.foo.project:com.foo.project.module2");
- assertThat(module2.getName()).isEqualTo("Foo Module 2");
- assertThat(module2.getVersion()).isEqualTo("1.0-SNAPSHOT");
- assertThat(module2.getDescription()).isEqualTo("Description of Module 2");
- assertThat(module2.getSourceDirs()).contains("src");
- assertThat(module2.getTestDirs()).contains("tests");
- assertThat(module2.getBinaries()).contains("target/classes");
- // and module properties must have been cleaned
- assertThat(module2.getProperties().getProperty("module1.sonar.projectKey")).isNull();
- assertThat(module2.getProperties().getProperty("module2.sonar.projectKey")).isNull();
- }
-
- // SONARPLUGINS-2421
- @Test
- public void shouldDefineMultiLanguageProjectWithDefinitionsAllInRootProject() throws IOException {
- ProjectDefinition rootProject = loadProjectDefinition("multi-language-definitions-all-in-root");
-
- // CHECK ROOT
- assertThat(rootProject.getKey()).isEqualTo("example");
- assertThat(rootProject.getName()).isEqualTo("Example");
- assertThat(rootProject.getVersion()).isEqualTo("1.0");
-
- // CHECK MODULES
- List<ProjectDefinition> modules = rootProject.getSubProjects();
- assertThat(modules.size()).isEqualTo(2);
-
- // Module 1
- ProjectDefinition module1 = modules.get(0);
- assertThat(module1.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-language-definitions-all-in-root"));
- assertThat(module1.getSourceDirs()).contains("src/main/java");
- // and module properties must have been cleaned
- assertThat(module1.getWorkDir().getCanonicalFile())
- .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-language-definitions-all-in-root"), ".sonar/example_java-module"));
-
- // Module 2
- ProjectDefinition module2 = modules.get(1);
- assertThat(module2.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-language-definitions-all-in-root"));
- assertThat(module2.getSourceDirs()).contains("src/main/groovy");
- // and module properties must have been cleaned
- assertThat(module2.getWorkDir().getCanonicalFile())
- .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-language-definitions-all-in-root"), ".sonar/example_groovy-module"));
- }
-
- @Test
- public void shouldDefineMultiModuleProjectWithBaseDir() throws IOException {
- ProjectDefinition rootProject = loadProjectDefinition("multi-module-with-basedir");
- List<ProjectDefinition> modules = rootProject.getSubProjects();
- assertThat(modules.size()).isEqualTo(1);
- assertThat(modules.get(0).getKey()).isEqualTo("com.foo.project:com.foo.project.module1");
- }
-
- @Test
- public void shouldDefineMultiModuleProjectWithConfigFile() throws IOException {
- ProjectDefinition rootProject = loadProjectDefinition("multi-module-with-configfile");
- List<ProjectDefinition> modules = rootProject.getSubProjects();
- assertThat(modules.size()).isEqualTo(1);
- ProjectDefinition module = modules.get(0);
- assertThat(module.getKey()).isEqualTo("com.foo.project:com.foo.project.module1");
- // verify the base directory that has been changed in this config file
- assertThat(module.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-with-configfile/any-folder"));
- }
-
- @Test
- public void shouldDefineMultiModuleProjectWithConfigFileAndOverwrittenBasedir() throws IOException {
- ProjectDefinition rootProject = loadProjectDefinition("multi-module-with-configfile-and-overwritten-basedir");
- List<ProjectDefinition> modules = rootProject.getSubProjects();
- assertThat(modules.size()).isEqualTo(1);
- ProjectDefinition module = modules.get(0);
- assertThat(module.getKey()).isEqualTo("com.foo.project:com.foo.project.module1");
- // verify the base directory that has been changed in this config file
- assertThat(module.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-with-configfile-and-overwritten-basedir/any-folder"));
- }
-
- @Test
- public void shouldFailIfUnexistingModuleBaseDir() throws IOException {
- thrown.expect(RunnerException.class);
- thrown.expectMessage("The base directory of the module 'module1' does not exist: "
- + TestUtils.getResource(this.getClass(), "multi-module-with-unexisting-basedir").getAbsolutePath() + File.separator + "module1");
-
- loadProjectDefinition("multi-module-with-unexisting-basedir");
- }
-
- @Test
- public void shouldFailIfUnexistingModuleFile() throws IOException {
- thrown.expect(RunnerException.class);
- thrown.expectMessage("The properties file of the module 'module1' does not exist: "
- + TestUtils.getResource(this.getClass(), "multi-module-with-unexisting-file").getAbsolutePath() + File.separator + "any-folder"
- + File.separator + "any-file.properties");
-
- loadProjectDefinition("multi-module-with-unexisting-file");
- }
-
- @Test
- public void shouldFailIfUnexistingSourceFolderInheritedInMultimodule() throws IOException {
- thrown.expect(RunnerException.class);
- thrown.expectMessage("The folder 'unexisting-source-dir' does not exist for 'com.foo.project:module1' (base directory = "
- + TestUtils.getResource(this.getClass(), "multi-module-with-unexisting-source-dir").getAbsolutePath() + File.separator + "module1)");
-
- loadProjectDefinition("multi-module-with-unexisting-source-dir");
- }
-
- @Test
- public void shouldNotFailIfUnexistingTestBinLibFolderInheritedInMultimodule() throws IOException {
- loadProjectDefinition("multi-module-with-unexisting-test-bin-lib-dir");
- }
-
- @Test
- public void shouldFailIfExplicitUnexistingTestFolder() throws IOException {
- thrown.expect(RunnerException.class);
- thrown.expectMessage("The folder 'tests' does not exist for 'module1' (base directory = "
- + TestUtils.getResource(this.getClass(), "multi-module-with-explicit-unexisting-test-dir").getAbsolutePath() + File.separator + "module1)");
-
- loadProjectDefinition("multi-module-with-explicit-unexisting-test-dir");
- }
-
- @Test
- public void shouldFailIfExplicitUnexistingBinaryFolder() throws IOException {
- thrown.expect(RunnerException.class);
- thrown.expectMessage("The folder 'bin' does not exist for 'module1' (base directory = "
- + TestUtils.getResource(this.getClass(), "multi-module-with-explicit-unexisting-binary-dir").getAbsolutePath() + File.separator + "module1)");
-
- loadProjectDefinition("multi-module-with-explicit-unexisting-binary-dir");
- }
-
- @Test
- public void shouldFailIfExplicitUnmatchingLibFolder() throws IOException {
- thrown.expect(RunnerException.class);
- thrown.expectMessage("No files matching pattern \"lib/*.jar\" in directory \""
- + TestUtils.getResource(this.getClass(), "multi-module-with-explicit-unexisting-lib").getAbsolutePath() + File.separator + "module1\"");
-
- loadProjectDefinition("multi-module-with-explicit-unexisting-lib");
- }
-
- @Test
- public void shouldExtractModuleProperties() {
- Properties props = new Properties();
- props.setProperty("sources", "src/main/java");
- props.setProperty("tests", "src/test/java");
- props.setProperty("foo.sources", "src/main/java");
- props.setProperty("foobar.tests", "src/test/java");
- props.setProperty("foobar.binaries", "target/classes");
-
- Properties moduleProps = SonarProjectBuilder.extractModuleProperties("bar", props);
- assertThat(moduleProps.size()).isEqualTo(0);
-
- moduleProps = SonarProjectBuilder.extractModuleProperties("foo", props);
- assertThat(moduleProps.size()).isEqualTo(1);
- assertThat(moduleProps.get("sources")).isEqualTo("src/main/java");
-
- moduleProps = SonarProjectBuilder.extractModuleProperties("foobar", props);
- assertThat(moduleProps.size()).isEqualTo(2);
- assertThat(moduleProps.get("tests")).isEqualTo("src/test/java");
- assertThat(moduleProps.get("binaries")).isEqualTo("target/classes");
- }
-
- @Test
- public void shouldFailIfMandatoryPropertiesAreNotPresent() {
- Properties props = new Properties();
- props.setProperty("foo1", "bla");
- props.setProperty("foo4", "bla");
-
- thrown.expect(RunnerException.class);
- thrown.expectMessage("You must define the following mandatory properties for 'Unknown': foo2, foo3");
-
- SonarProjectBuilder.checkMandatoryProperties(props, new String[] {"foo1", "foo2", "foo3"});
- }
-
- @Test
- public void shouldFailIfMandatoryPropertiesAreNotPresentButWithProjectKey() {
- Properties props = new Properties();
- props.setProperty("foo1", "bla");
- props.setProperty("sonar.projectKey", "my-project");
-
- thrown.expect(RunnerException.class);
- thrown.expectMessage("You must define the following mandatory properties for 'my-project': foo2, foo3");
-
- SonarProjectBuilder.checkMandatoryProperties(props, new String[] {"foo1", "foo2", "foo3"});
- }
-
- @Test
- public void shouldNotFailIfMandatoryPropertiesArePresent() {
- Properties props = new Properties();
- props.setProperty("foo1", "bla");
- props.setProperty("foo4", "bla");
-
- SonarProjectBuilder.checkMandatoryProperties(props, new String[] {"foo1"});
-
- // No exception should be thrown
- }
-
- @Test
- public void shouldFilterFiles() throws Exception {
- File baseDir = TestUtils.getResource(this.getClass(), "shouldFilterFiles");
- assertThat(SonarProjectBuilder.getLibraries(baseDir, "in*.txt").length).isEqualTo(1);
- assertThat(SonarProjectBuilder.getLibraries(baseDir, "*.txt").length).isEqualTo(2);
- assertThat(SonarProjectBuilder.getLibraries(baseDir.getParentFile(), "shouldFilterFiles/in*.txt").length).isEqualTo(1);
- assertThat(SonarProjectBuilder.getLibraries(baseDir.getParentFile(), "shouldFilterFiles/*.txt").length).isEqualTo(2);
- }
-
- @Test
- public void shouldWorkWithAbsolutePath() throws Exception {
- File baseDir = new File("not-exists");
- String absolutePattern = TestUtils.getResource(this.getClass(), "shouldFilterFiles").getAbsolutePath() + "/in*.txt";
- assertThat(SonarProjectBuilder.getLibraries(baseDir.getParentFile(), absolutePattern).length).isEqualTo(1);
- }
-
- @Test
- public void shouldGetRelativeFile() {
- assertThat(SonarProjectBuilder.getFileFromPath("shouldGetFile/foo.properties", TestUtils.getResource(this.getClass(), "/")))
- .isEqualTo(TestUtils.getResource(this.getClass(), "shouldGetFile/foo.properties"));
- }
-
- @Test
- public void shouldGetAbsoluteFile() {
- File file = TestUtils.getResource(this.getClass(), "shouldGetFile/foo.properties");
-
- assertThat(SonarProjectBuilder.getFileFromPath(file.getAbsolutePath(), TestUtils.getResource(this.getClass(), "/")))
- .isEqualTo(file);
- }
-
- @Test
- public void shouldMergeParentProperties() {
- Properties parentProps = new Properties();
- parentProps.setProperty("toBeMergeProps", "fooParent");
- parentProps.setProperty("existingChildProp", "barParent");
- parentProps.setProperty("sonar.modules", "mod1,mod2");
- parentProps.setProperty("sonar.projectDescription", "Desc from Parent");
- parentProps.setProperty("mod1.sonar.projectDescription", "Desc for Mod1");
- parentProps.setProperty("mod2.sonar.projectkey", "Key for Mod2");
-
- Properties childProps = new Properties();
- childProps.setProperty("existingChildProp", "barChild");
- childProps.setProperty("otherProp", "tutuChild");
-
- SonarProjectBuilder.mergeParentProperties(childProps, parentProps);
-
- assertThat(childProps.size()).isEqualTo(3);
- assertThat(childProps.getProperty("toBeMergeProps")).isEqualTo("fooParent");
- assertThat(childProps.getProperty("existingChildProp")).isEqualTo("barChild");
- assertThat(childProps.getProperty("otherProp")).isEqualTo("tutuChild");
- assertThat(childProps.getProperty("sonar.modules")).isNull();
- assertThat(childProps.getProperty("sonar.projectDescription")).isNull();
- assertThat(childProps.getProperty("mod1.sonar.projectDescription")).isNull();
- assertThat(childProps.getProperty("mod2.sonar.projectkey")).isNull();
- }
-
- @Test
- public void shouldInitRootWorkDir() {
- SonarProjectBuilder builder = SonarProjectBuilder.create(new Properties());
- File baseDir = new File("target/tmp/baseDir");
-
- File workDir = builder.initRootProjectWorkDir(baseDir);
-
- assertThat(workDir).isEqualTo(new File(baseDir, ".sonar"));
- }
-
- @Test
- public void shouldInitWorkDirWithCustomRelativeFolder() {
- Properties properties = new Properties();
- properties.put("sonar.working.directory", ".foo");
- SonarProjectBuilder builder = SonarProjectBuilder.create(properties);
- File baseDir = new File("target/tmp/baseDir");
-
- File workDir = builder.initRootProjectWorkDir(baseDir);
-
- assertThat(workDir).isEqualTo(new File(baseDir, ".foo"));
- }
-
- @Test
- public void shouldInitRootWorkDirWithCustomAbsoluteFolder() {
- Properties properties = new Properties();
- properties.put("sonar.working.directory", new File("src").getAbsolutePath());
- SonarProjectBuilder builder = SonarProjectBuilder.create(properties);
- File baseDir = new File("target/tmp/baseDir");
-
- File workDir = builder.initRootProjectWorkDir(baseDir);
-
- assertThat(workDir).isEqualTo(new File("src").getAbsoluteFile());
- }
-
- @Test
- public void shouldReturnPrefixedKey() {
- Properties props = new Properties();
- props.put("sonar.projectKey", "my-module-key");
-
- SonarProjectBuilder.prefixProjectKeyWithParentKey(props, "my-parent-key");
- assertThat(props.getProperty("sonar.projectKey")).isEqualTo("my-parent-key:my-module-key");
- }
-
- @Test
- public void shouldFailIf2ModulesWithSameKey() {
- Properties props = new Properties();
- props.put("sonar.projectKey", "root");
- ProjectDefinition root = ProjectDefinition.create().setProperties(props);
-
- Properties props1 = new Properties();
- props1.put("sonar.projectKey", "mod1");
- root.addSubProject(ProjectDefinition.create().setProperties(props1));
-
- // Check uniqueness of a new module: OK
- Properties props2 = new Properties();
- props2.put("sonar.projectKey", "mod2");
- ProjectDefinition mod2 = ProjectDefinition.create().setProperties(props2);
- SonarProjectBuilder.checkUniquenessOfChildKey(mod2, root);
-
- // Now, add it and check again
- root.addSubProject(mod2);
-
- thrown.expect(RunnerException.class);
- thrown.expectMessage("Project 'root' can't have 2 modules with the following key: mod2");
-
- SonarProjectBuilder.checkUniquenessOfChildKey(mod2, root);
- }
-
- @Test
- public void shouldSetProjectKeyIfNotPresent() {
- Properties props = new Properties();
- props.put("sonar.projectVersion", "1.0");
-
- // should be set
- SonarProjectBuilder.setProjectKeyAndNameIfNotDefined(props, "foo");
- assertThat(props.getProperty("sonar.projectKey")).isEqualTo("foo");
- assertThat(props.getProperty("sonar.projectName")).isEqualTo("foo");
-
- // but not this 2nd time
- SonarProjectBuilder.setProjectKeyAndNameIfNotDefined(props, "bar");
- assertThat(props.getProperty("sonar.projectKey")).isEqualTo("foo");
- assertThat(props.getProperty("sonar.projectName")).isEqualTo("foo");
- }
-
- @Test
- public void shouldFailToLoadPropertiesFile() throws Exception {
- thrown.expect(RunnerException.class);
- thrown.expectMessage("Impossible to read the property file");
-
- SonarProjectBuilder.toProperties(new File("foo.properties"));
- }
-
- private ProjectDefinition loadProjectDefinition(String projectFolder) throws FileNotFoundException, IOException {
- Properties props = SonarProjectBuilder.toProperties(TestUtils.getResource(this.getClass(), projectFolder + "/sonar-project.properties"));
- props.put("sonar.projectBaseDir", TestUtils.getResource(this.getClass(), projectFolder).getAbsolutePath());
- ProjectDefinition projectDefinition = SonarProjectBuilder.create(props)
- .generateProjectDefinition();
- return projectDefinition;
- }
-
-}
diff --git a/src/test/java/org/sonar/runner/internal/batch/SonarRunnerUtilsTest.java b/src/test/java/org/sonar/runner/internal/batch/SonarRunnerUtilsTest.java
deleted file mode 100644
index db00f63..0000000
--- a/src/test/java/org/sonar/runner/internal/batch/SonarRunnerUtilsTest.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Sonar 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.internal.batch;
-
-import org.apache.commons.io.IOUtils;
-import org.junit.Test;
-import org.sonar.test.TestUtils;
-
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.Properties;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class SonarRunnerUtilsTest {
-
- @Test
- public void shouldGetList() {
- Properties props = new Properties();
-
- props.put("prop", " foo , bar , \n\ntoto,tutu");
- assertThat(SonarRunnerUtils.getListFromProperty(props, "prop")).containsOnly("foo", "bar", "toto", "tutu");
- }
-
- @Test
- public void shouldGetListFromFile() throws IOException {
- String filePath = "shouldGetList/foo.properties";
- Properties props = loadPropsFromFile(filePath);
-
- assertThat(SonarRunnerUtils.getListFromProperty(props, "prop")).containsOnly("foo", "bar", "toto", "tutu");
- }
-
- private Properties loadPropsFromFile(String filePath) throws IOException {
- Properties props = new Properties();
- FileInputStream fileInputStream = null;
- try {
- fileInputStream = new FileInputStream(TestUtils.getResource(this.getClass(), filePath));
- props.load(fileInputStream);
- } finally {
- IOUtils.closeQuietly(fileInputStream);
- }
- return props;
- }
-
-}