aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2015-07-17 15:30:01 +0200
committerDuarte Meneses <duarte.meneses@sonarsource.com>2015-07-17 15:30:24 +0200
commit465e65dfe825b8d6336e145b72d940f800d44002 (patch)
tree9da9db99dc7ff5dae96bd23aa572ad70c7b58713 /sonar-batch
parentbdcfb7eeb7caaeb9019ff0d3946153c33bc6c5e9 (diff)
downloadsonarqube-465e65dfe825b8d6336e145b72d940f800d44002.tar.gz
sonarqube-465e65dfe825b8d6336e145b72d940f800d44002.zip
Fix medium tests and improve temp folders
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectTempFolderProvider.java10
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/TempFolderProvider.java29
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesMediumTest.java16
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java6
4 files changed, 38 insertions, 23 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectTempFolderProvider.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectTempFolderProvider.java
index 5e2cf79e97e..d259919fb58 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectTempFolderProvider.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectTempFolderProvider.java
@@ -37,12 +37,12 @@ public class ProjectTempFolderProvider extends LifecycleProviderAdapter {
if (projectTempFolder == null) {
String workingDirPath = StringUtils.defaultIfBlank(props.property(CoreProperties.WORKING_DIRECTORY), CoreProperties.WORKING_DIRECTORY_DEFAULT_VALUE);
Path workingDir = Paths.get(workingDirPath).normalize();
-
- if(!workingDir.isAbsolute()) {
+
+ if (!workingDir.isAbsolute()) {
Path base = getBasePath(props);
workingDir = base.resolve(workingDir);
}
-
+
Path tempDir = workingDir.resolve(TMP_NAME);
try {
Files.createDirectories(tempDir);
@@ -54,10 +54,10 @@ public class ProjectTempFolderProvider extends LifecycleProviderAdapter {
}
return projectTempFolder;
}
-
+
private Path getBasePath(AnalysisProperties props) {
String baseDir = props.property("sonar.projectBaseDir");
- if(baseDir == null) {
+ if (baseDir == null) {
throw new IllegalStateException("sonar.projectBaseDir needs to be specified");
}
return Paths.get(baseDir);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TempFolderProvider.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TempFolderProvider.java
index 487296f1ba9..4ca4fe75dcb 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TempFolderProvider.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TempFolderProvider.java
@@ -20,7 +20,6 @@
package org.sonar.batch.bootstrap;
import org.sonar.api.utils.System2;
-
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.apache.commons.io.FileUtils;
@@ -36,22 +35,20 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicLong;
public class TempFolderProvider extends LifecycleProviderAdapter {
private static final Logger LOG = Loggers.get(TempFolderProvider.class);
private static final long CLEAN_MAX_AGE = TimeUnit.DAYS.toMillis(21);
- private static final AtomicLong nextId = new AtomicLong();
static final String TMP_NAME_PREFIX = ".sonartmp_";
private System2 system;
private DefaultTempFolder tempFolder;
-
+
public TempFolderProvider() {
this(new System2());
}
-
+
TempFolderProvider(System2 system) {
this.system = system;
}
@@ -72,19 +69,27 @@ public class TempFolderProvider extends LifecycleProviderAdapter {
} catch (IOException e) {
LOG.error(String.format("failed to clean global working directory: %s", workingPath), e);
}
-
- Path tempDir = workingPath.resolve(TMP_NAME_PREFIX + System.currentTimeMillis() + nextId.incrementAndGet());
- try {
- Files.createDirectories(tempDir);
- } catch (IOException e) {
- throw new IllegalStateException("Unable to create root temp directory " + tempDir, e);
- }
+ Path tempDir = createTempFolder(workingPath);
tempFolder = new DefaultTempFolder(tempDir.toFile(), true);
this.instance = tempFolder;
}
return tempFolder;
}
+ private Path createTempFolder(Path workingPath) {
+ try {
+ Files.createDirectories(workingPath);
+ } catch (IOException e) {
+ throw new IllegalStateException("Failed to create working path: " + workingPath);
+ }
+
+ try {
+ return Files.createTempDirectory(workingPath, TMP_NAME_PREFIX);
+ } catch (IOException e) {
+ throw new IllegalStateException("Failed to create temporary folder in " + workingPath);
+ }
+ }
+
private Path findHome(BootstrapProperties props) {
String home = props.property("sonar.userHome");
if (home != null) {
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesMediumTest.java
index d97f6ba995d..8f46a5d0800 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesMediumTest.java
@@ -60,9 +60,11 @@ public class IssuesMediumTest {
@Test
public void testOneIssuePerLine() throws Exception {
File projectDir = new File(IssuesMediumTest.class.getResource("/mediumtest/xoo/sample").toURI());
+ File tmpDir = temp.newFolder();
+ FileUtils.copyDirectory(projectDir, tmpDir);
TaskResult result = tester
- .newScanTask(new File(projectDir, "sonar-project.properties"))
+ .newScanTask(new File(tmpDir, "sonar-project.properties"))
.start();
assertThat(result.issues()).hasSize(14);
@@ -71,9 +73,11 @@ public class IssuesMediumTest {
@Test
public void findActiveRuleByInternalKey() throws Exception {
File projectDir = new File(IssuesMediumTest.class.getResource("/mediumtest/xoo/sample").toURI());
+ File tmpDir = temp.newFolder();
+ FileUtils.copyDirectory(projectDir, tmpDir);
TaskResult result = tester
- .newScanTask(new File(projectDir, "sonar-project.properties"))
+ .newScanTask(new File(tmpDir, "sonar-project.properties"))
.property("sonar.xoo.internalKey", "OneIssuePerLine.internal")
.start();
@@ -83,9 +87,11 @@ public class IssuesMediumTest {
@Test
public void testOverrideQProfileSeverity() throws Exception {
File projectDir = new File(IssuesMediumTest.class.getResource("/mediumtest/xoo/sample").toURI());
+ File tmpDir = temp.newFolder();
+ FileUtils.copyDirectory(projectDir, tmpDir);
TaskResult result = tester
- .newScanTask(new File(projectDir, "sonar-project.properties"))
+ .newScanTask(new File(tmpDir, "sonar-project.properties"))
.property("sonar.oneIssuePerLine.forceSeverity", "CRITICAL")
.start();
@@ -95,9 +101,11 @@ public class IssuesMediumTest {
@Test
public void testIssueExclusion() throws Exception {
File projectDir = new File(IssuesMediumTest.class.getResource("/mediumtest/xoo/sample").toURI());
+ File tmpDir = temp.newFolder();
+ FileUtils.copyDirectory(projectDir, tmpDir);
TaskResult result = tester
- .newScanTask(new File(projectDir, "sonar-project.properties"))
+ .newScanTask(new File(tmpDir, "sonar-project.properties"))
.property("sonar.issue.ignore.allfile", "1")
.property("sonar.issue.ignore.allfile.1.fileRegexp", "object")
.start();
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java
index 87d124989ed..e32707e023e 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java
@@ -60,9 +60,11 @@ public class MeasuresMediumTest {
@Test
public void computeMeasuresOnSampleProject() throws Exception {
File projectDir = new File(MeasuresMediumTest.class.getResource("/mediumtest/xoo/sample").toURI());
-
+ File tmpDir = temp.newFolder();
+ FileUtils.copyDirectory(projectDir, tmpDir);
+
TaskResult result = tester
- .newScanTask(new File(projectDir, "sonar-project.properties"))
+ .newScanTask(new File(tmpDir, "sonar-project.properties"))
.start();
assertThat(result.allMeasures()).hasSize(63);