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;
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;
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());
}
File workDir;
if (parent == null) {
validateDirectories(rootProperties, baseDir, projectKey);
- workDir = initRootProjectWorkDir(baseDir);
+ workDir = initRootProjectWorkDir(baseDir, rootProperties);
} else {
workDir = initModuleWorkDir(baseDir, rootProperties);
}
}
@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);
}
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;
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;
@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);
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);
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"));
}
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"));
}
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());
}