aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--it/src/test/java/com/sonar/runner/it/CacheTest.java14
-rw-r--r--sonar-runner-api/src/main/java/org/sonar/runner/api/Dirs.java34
-rw-r--r--sonar-runner-api/src/test/java/org/sonar/runner/api/DirsTest.java2
3 files changed, 20 insertions, 30 deletions
diff --git a/it/src/test/java/com/sonar/runner/it/CacheTest.java b/it/src/test/java/com/sonar/runner/it/CacheTest.java
index d4c82ec..df6186f 100644
--- a/it/src/test/java/com/sonar/runner/it/CacheTest.java
+++ b/it/src/test/java/com/sonar/runner/it/CacheTest.java
@@ -19,8 +19,6 @@
*/
package com.sonar.runner.it;
-import org.sonar.wsclient.issue.Issue;
-import org.sonar.wsclient.issue.IssueQuery;
import org.junit.BeforeClass;
import org.junit.rules.TemporaryFolder;
import org.junit.Rule;
@@ -32,7 +30,6 @@ import org.junit.Test;
import java.io.File;
import java.io.IOException;
-import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
@@ -45,7 +42,6 @@ public class CacheTest extends RunnerTestCase {
@BeforeClass
public static void setUpClass() {
- System.out.println("SETTING UP");
orchestrator.getServer().restoreProfile(ResourceLocation.create("/sonar-way-profile.xml"));
orchestrator.getServer().provisionProject("java:sample", "Java Sample, with comma");
orchestrator.getServer().associateProjectToQualityProfile("java:sample", "java", "sonar-way");
@@ -96,8 +92,7 @@ public class CacheTest extends RunnerTestCase {
SonarRunner build = createRunner("publish");
BuildResult result = orchestrator.executeBuild(build, false);
assertThat(result.isSuccess()).isTrue();
- getIssues();
-
+
// offline (cache not used) -> should fail
ensureStopped();
build = createRunner("publish", false);
@@ -109,13 +104,6 @@ public class CacheTest extends RunnerTestCase {
}
- private void getIssues() {
- List<Issue> issues = orchestrator.getServer().wsClient().issueClient()
- .find(IssueQuery.create()).list();
- System.out.println(issues.size());
-
- }
-
private SonarRunner createRunner(String mode) throws IOException {
return createRunner(mode, false);
}
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
index a5da52d..a2b0bd3 100644
--- 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
@@ -20,7 +20,11 @@
package org.sonar.runner.api;
import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.Properties;
+
import org.sonar.home.cache.Logger;
class Dirs {
@@ -41,27 +45,25 @@ class Dirs {
}
private void initProjectDirs(Properties p) {
- String path = p.getProperty(ScanProperties.PROJECT_BASEDIR, ".");
- File projectDir = new File(path);
- if (!projectDir.isDirectory()) {
- throw new IllegalStateException("Project home must be an existing directory: " + path);
+ String pathString = p.getProperty(ScanProperties.PROJECT_BASEDIR, "");
+ Path absoluteProjectPath = Paths.get(pathString).toAbsolutePath().normalize();
+ if (!Files.isDirectory(absoluteProjectPath)) {
+ throw new IllegalStateException("Project home must be an existing directory: " + pathString);
}
- p.setProperty(ScanProperties.PROJECT_BASEDIR, projectDir.getAbsolutePath());
-
- File workDir;
- path = p.getProperty(RunnerProperties.WORK_DIR, "");
- if ("".equals(path.trim())) {
- workDir = new File(projectDir, ".sonar");
+ p.setProperty(ScanProperties.PROJECT_BASEDIR, absoluteProjectPath.toString());
+ Path workDirPath;
+ pathString = p.getProperty(RunnerProperties.WORK_DIR, "");
+ if ("".equals(pathString.trim())) {
+ workDirPath = absoluteProjectPath.resolve(".sonar");
} else {
- workDir = new File(path);
- if (!workDir.isAbsolute()) {
- workDir = new File(projectDir, path);
+ workDirPath = Paths.get(pathString);
+ if (!workDirPath.isAbsolute()) {
+ workDirPath = absoluteProjectPath.resolve(pathString);
}
}
- Utils.deleteQuietly(workDir);
- p.setProperty(RunnerProperties.WORK_DIR, workDir.getAbsolutePath());
- logger.info("Work directory: " + workDir.getAbsolutePath());
+ p.setProperty(RunnerProperties.WORK_DIR, workDirPath.normalize().toString());
+ logger.info("Work directory: " + workDirPath.normalize().toString());
}
/**
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
index 0bce312..d8a4eda 100644
--- 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
@@ -76,7 +76,7 @@ public class DirsTest {
@Test
public void should_set_relative_path_to_project_work_dir() throws Exception {
- File initialProjectDir = temp.newFolder();
+ File initialProjectDir = temp.getRoot();
p.setProperty("sonar.task", "scan");
p.setProperty(RunnerProperties.WORK_DIR, "relative/path");
p.setProperty(ScanProperties.PROJECT_BASEDIR, initialProjectDir.getAbsolutePath());