From 80ff8563344f727ee611f3c6932d4af063bb5605 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Fri, 5 Dec 2014 11:13:09 +0100 Subject: [PATCH] Fix regression concerning SONAR-5878 (custom working directory was not considered) --- .../main/java/org/sonar/batch/index/SourcePersister.java | 4 +--- .../java/org/sonar/batch/scan/ProjectReactorBuilder.java | 9 ++++----- .../java/org/sonar/batch/index/SourcePersisterTest.java | 6 +----- .../org/sonar/batch/scan/ProjectReactorBuilderTest.java | 6 +++--- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java index 55b5b4f4b94..186e37edaa6 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java @@ -71,7 +71,6 @@ public class SourcePersister implements ScanPersister { private static final Logger LOG = LoggerFactory.getLogger(SourcePersister.class); private static final String BOM = "\uFEFF"; - private final ResourcePersister resourcePersister; private final InputPathCache inputPathCache; private final MyBatis mybatis; private final MeasureCache measureCache; @@ -82,10 +81,9 @@ public class SourcePersister implements ScanPersister { private CodeColorizers codeColorizers; private DuplicationCache duplicationCache; - public SourcePersister(ResourcePersister resourcePersister, InputPathCache inputPathCache, + public SourcePersister(InputPathCache inputPathCache, MyBatis mybatis, MeasureCache measureCache, ComponentDataCache componentDataCache, ProjectTree projectTree, System2 system2, ResourceCache resourceCache, CodeColorizers codeColorizers, DuplicationCache duplicationCache) { - this.resourcePersister = resourcePersister; this.inputPathCache = inputPathCache; this.mybatis = mybatis; this.measureCache = measureCache; 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 58417768e00..fbed697fec7 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 @@ -115,8 +115,7 @@ public class ProjectReactorBuilder { rootProjectWorkDir = rootProject.getWorkDir(); defineChildren(rootProject, propertiesByModuleId); cleanAndCheckProjectDefinitions(rootProject); - // Optimization remove all children properties from taskProps - taskProps.properties().clear(); + // Since task properties are now empty we should add root module properties for (Map.Entry entry : propertiesByModuleId.get("").entrySet()) { taskProps.properties().put((String) entry.getKey(), (String) entry.getValue()); } @@ -157,7 +156,7 @@ public class ProjectReactorBuilder { File workDir; if (parent == null) { validateDirectories(rootProperties, baseDir, projectKey); - workDir = initRootProjectWorkDir(baseDir); + workDir = initRootProjectWorkDir(baseDir, rootProperties); } else { workDir = initModuleWorkDir(baseDir, rootProperties); } @@ -169,8 +168,8 @@ public class ProjectReactorBuilder { } @VisibleForTesting - protected File initRootProjectWorkDir(File baseDir) { - String workDir = taskProps.property(CoreProperties.WORKING_DIRECTORY); + protected File initRootProjectWorkDir(File baseDir, Map rootProperties) { + String workDir = rootProperties.get(CoreProperties.WORKING_DIRECTORY); if (StringUtils.isBlank(workDir)) { return new File(baseDir, CoreProperties.WORKING_DIRECTORY_DEFAULT_VALUE); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java index 2d771d166f6..af2c5474d94 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java @@ -34,7 +34,6 @@ import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Measure; import org.sonar.api.resources.File; import org.sonar.api.resources.Project; -import org.sonar.api.resources.Resource; import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.System2; import org.sonar.batch.ProjectTree; @@ -56,7 +55,6 @@ import java.util.Collections; import java.util.Date; import static org.fest.assertions.Assertions.assertThat; -import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -81,10 +79,8 @@ public class SourcePersisterTest extends AbstractDaoTestCase { @Before public void before() throws IOException { - ResourcePersister resourcePersister = mock(ResourcePersister.class); Snapshot snapshot = new Snapshot(); snapshot.setId(1000); - when(resourcePersister.getSnapshotOrFail(any(Resource.class))).thenReturn(snapshot); inputPathCache = mock(InputPathCache.class); resourceCache = mock(ResourceCache.class); projectTree = mock(ProjectTree.class); @@ -93,7 +89,7 @@ public class SourcePersisterTest extends AbstractDaoTestCase { when(measureCache.byMetric(anyString(), anyString())).thenReturn(Collections.emptyList()); componentDataCache = mock(ComponentDataCache.class); duplicationCache = mock(DuplicationCache.class); - sourcePersister = new SourcePersister(resourcePersister, inputPathCache, + sourcePersister = new SourcePersister(inputPathCache, getMyBatis(), measureCache, componentDataCache, projectTree, system2, resourceCache, mock(CodeColorizers.class), duplicationCache); Project project = new Project(PROJECT_KEY); diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorBuilderTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorBuilderTest.java index fe0ee966ec5..8c427e20723 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorBuilderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorBuilderTest.java @@ -437,7 +437,7 @@ public class ProjectReactorBuilderTest { ProjectReactorBuilder builder = new ProjectReactorBuilder(new TaskProperties(Maps.newHashMap(), null)); File baseDir = new File("target/tmp/baseDir"); - File workDir = builder.initRootProjectWorkDir(baseDir); + File workDir = builder.initRootProjectWorkDir(baseDir, Maps.newHashMap()); assertThat(workDir).isEqualTo(new File(baseDir, ".sonar")); } @@ -449,7 +449,7 @@ public class ProjectReactorBuilderTest { ProjectReactorBuilder builder = new ProjectReactorBuilder(new TaskProperties(props, null)); File baseDir = new File("target/tmp/baseDir"); - File workDir = builder.initRootProjectWorkDir(baseDir); + File workDir = builder.initRootProjectWorkDir(baseDir, props); assertThat(workDir).isEqualTo(new File(baseDir, ".foo")); } @@ -461,7 +461,7 @@ public class ProjectReactorBuilderTest { ProjectReactorBuilder builder = new ProjectReactorBuilder(new TaskProperties(props, null)); File baseDir = new File("target/tmp/baseDir"); - File workDir = builder.initRootProjectWorkDir(baseDir); + File workDir = builder.initRootProjectWorkDir(baseDir, props); assertThat(workDir).isEqualTo(new File("src").getAbsoluteFile()); } -- 2.39.5