]> source.dussan.org Git - sonarqube.git/commitdiff
Fix regression concerning SONAR-5878 (custom working directory was not considered)
authorJulien HENRY <julien.henry@sonarsource.com>
Fri, 5 Dec 2014 10:13:09 +0000 (11:13 +0100)
committerJulien HENRY <julien.henry@sonarsource.com>
Fri, 5 Dec 2014 10:40:37 +0000 (11:40 +0100)
sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java
sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java
sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java
sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorBuilderTest.java

index 55b5b4f4b94a01f287420d0078fe4e34622d5efe..186e37edaa64e1f0c7fef1d45048e1c4716a1054 100644 (file)
@@ -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;
index 58417768e005071c6178517cc1c99295c9006cb4..fbed697fec7b9c34498f581cbfa424ec8518f698 100644 (file)
@@ -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<String, String> 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<String, String> rootProperties) {
+    String workDir = rootProperties.get(CoreProperties.WORKING_DIRECTORY);
     if (StringUtils.isBlank(workDir)) {
       return new File(baseDir, CoreProperties.WORKING_DIRECTORY_DEFAULT_VALUE);
     }
index 2d771d166f6f11d79ba5a806cf304a10378f723d..af2c5474d94db4aab1fac01132a45e63ff8eea88 100644 (file)
@@ -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.<org.sonar.api.measures.Measure>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);
index fe0ee966ec5cf523c6c2ef5e2739d9aee21d4c61..8c427e207239dcde7e4ccd65280a49d43c174cb4 100644 (file)
@@ -437,7 +437,7 @@ public class ProjectReactorBuilderTest {
     ProjectReactorBuilder builder = new ProjectReactorBuilder(new TaskProperties(Maps.<String, String>newHashMap(), null));
     File baseDir = new File("target/tmp/baseDir");
 
-    File workDir = builder.initRootProjectWorkDir(baseDir);
+    File workDir = builder.initRootProjectWorkDir(baseDir, Maps.<String, String>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());
   }