aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2015-02-17 14:57:13 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2015-02-17 14:57:13 +0100
commita79475f5042b7e566ae64e58be770fde4febf546 (patch)
tree3c2d4f5ee0073d5ac28693958118e92a8f08c58d /sonar-batch/src
parent4a7d9f727f06b08f2241300ed5ead5868df4c4c6 (diff)
downloadsonarqube-a79475f5042b7e566ae64e58be770fde4febf546.tar.gz
sonarqube-a79475f5042b7e566ae64e58be770fde4febf546.zip
SONAR-6190 Dumping profiler info into a file fails when module key contains a colon
Diffstat (limited to 'sonar-batch/src')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/profiling/PhasesSumUpTimeProfiler.java3
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java5
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/util/BatchUtils.java37
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/profiling/PhasesSumUpTimeProfilerTest.java2
4 files changed, 42 insertions, 5 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/profiling/PhasesSumUpTimeProfiler.java b/sonar-batch/src/main/java/org/sonar/batch/profiling/PhasesSumUpTimeProfiler.java
index 30956a0a263..137b1419d9c 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/profiling/PhasesSumUpTimeProfiler.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/profiling/PhasesSumUpTimeProfiler.java
@@ -43,6 +43,7 @@ import org.sonar.batch.events.BatchStepHandler;
import org.sonar.batch.phases.Phases;
import org.sonar.batch.phases.event.PersisterExecutionHandler;
import org.sonar.batch.phases.event.PersistersPhaseHandler;
+import org.sonar.batch.util.BatchUtils;
import javax.annotation.Nullable;
@@ -118,7 +119,7 @@ public class PhasesSumUpTimeProfiler implements ProjectAnalysisHandler, SensorEx
println(" -------- End of profiling of module " + module.getName() + " --------");
println("");
String fileName = module.getKey() + "-profiler.properties";
- dumpToFile(props, fileName);
+ dumpToFile(props, BatchUtils.cleanKeyForFilename(fileName));
totalProfiling.merge(currentModuleProfiling);
if (module.isRoot() && !module.getModules().isEmpty()) {
dumpTotalExecutionSummary();
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java
index eadf7155dc1..e3ef6349a51 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java
@@ -33,6 +33,7 @@ import org.sonar.api.CoreProperties;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.batch.bootstrap.TaskProperties;
+import org.sonar.batch.util.BatchUtils;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
@@ -189,9 +190,7 @@ public class ProjectReactorBuilder {
protected File initModuleWorkDir(File moduleBaseDir, Map<String, String> moduleProperties) {
String workDir = moduleProperties.get(CoreProperties.WORKING_DIRECTORY);
if (StringUtils.isBlank(workDir)) {
- String cleanKey = StringUtils.deleteWhitespace(moduleProperties.get(CoreProperties.PROJECT_KEY_PROPERTY));
- cleanKey = StringUtils.replace(cleanKey, ":", "_");
- return new File(rootProjectWorkDir, cleanKey);
+ return new File(rootProjectWorkDir, BatchUtils.cleanKeyForFilename(moduleProperties.get(CoreProperties.PROJECT_KEY_PROPERTY)));
}
File customWorkDir = new File(workDir);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/util/BatchUtils.java b/sonar-batch/src/main/java/org/sonar/batch/util/BatchUtils.java
new file mode 100644
index 00000000000..e6321ac8b3b
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/util/BatchUtils.java
@@ -0,0 +1,37 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 02110-1301, USA.
+ */
+package org.sonar.batch.util;
+
+import org.apache.commons.lang.StringUtils;
+
+public class BatchUtils {
+
+ private BatchUtils() {
+ }
+
+ /**
+ * Clean provided string to remove chars that are not valid as file name.
+ * @param projectKey e.g. my:file
+ */
+ public static String cleanKeyForFilename(String projectKey) {
+ String cleanKey = StringUtils.deleteWhitespace(projectKey);
+ return StringUtils.replace(cleanKey, ":", "_");
+ }
+}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/profiling/PhasesSumUpTimeProfilerTest.java b/sonar-batch/src/test/java/org/sonar/batch/profiling/PhasesSumUpTimeProfilerTest.java
index 2802d2f7058..e04c6843313 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/profiling/PhasesSumUpTimeProfilerTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/profiling/PhasesSumUpTimeProfilerTest.java
@@ -81,7 +81,7 @@ public class PhasesSumUpTimeProfilerTest {
@Test
public void testSimpleProject() throws InterruptedException {
- final Project project = mockProject("project", true);
+ final Project project = mockProject("my:project", true);
when(project.getModules()).thenReturn(Collections.<Project>emptyList());
fakeAnalysis(profiler, project);