import org.sonar.api.batch.bootstrap.ProjectBootstrapper;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.bootstrap.ProjectReactor;
-import org.sonar.api.config.Settings;
+import org.sonar.batch.bootstrap.BootstrapSettings;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
PROPERTY_OLD_TESTS, PROPERTY_TESTS,
PROPERTY_OLD_BINARIES, PROPERTY_BINARIES,
PROPERTY_OLD_LIBRARIES, PROPERTY_LIBRARIES
- );
+ );
/**
* @since 1.4
*/
private static final List<String> NON_HERITED_PROPERTIES_FOR_CHILD = Lists.newArrayList(PROPERTY_PROJECT_BASEDIR, PROPERTY_MODULES, CoreProperties.PROJECT_DESCRIPTION_PROPERTY);
- private Settings settings;
+ private BootstrapSettings settings;
private File rootProjectWorkDir;
- DefaultProjectBootstrapper(Settings settings) {
+ DefaultProjectBootstrapper(BootstrapSettings settings) {
this.settings = settings;
}
@Override
public ProjectReactor bootstrap() {
Properties bootstrapProperties = new Properties();
- bootstrapProperties.putAll(settings.getProperties());
+ bootstrapProperties.putAll(settings.properties());
ProjectDefinition rootProject = defineProject(bootstrapProperties, null);
rootProjectWorkDir = rootProject.getWorkDir();
defineChildren(rootProject);
}
ProjectDefinition definition = ProjectDefinition.create().setProperties(properties)
- .setBaseDir(baseDir)
- .setWorkDir(workDir);
+ .setBaseDir(baseDir)
+ .setWorkDir(workDir);
return definition;
}
@VisibleForTesting
protected File initRootProjectWorkDir(File baseDir) {
- String workDir = settings.getString(PROPERTY_WORK_DIRECTORY);
+ String workDir = settings.property(PROPERTY_WORK_DIRECTORY);
if (StringUtils.isBlank(workDir)) {
return new File(baseDir, DEF_VALUE_WORK_DIRECTORY);
}
if (sourceFolder.isDirectory()) {
LOG.warn("/!\\ A multi-module project can't have source folders, so '{}' won't be used for the analysis. " +
"If you want to analyse files of this folder, you should create another sub-module and move them inside it.",
- sourceFolder.toString());
+ sourceFolder.toString());
}
}
import org.sonar.batch.DefaultResourceCreationLock;
import org.sonar.batch.ProjectConfigurator;
import org.sonar.batch.ProjectTree;
+import org.sonar.batch.bootstrap.BootstrapSettings;
import org.sonar.batch.bootstrap.ExtensionInstaller;
import org.sonar.batch.bootstrap.ExtensionMatcher;
import org.sonar.batch.bootstrap.ExtensionUtils;
ProjectBootstrapper bootstrapper = getComponentByType(ProjectBootstrapper.class);
if (bootstrapper == null) {
// Use default SonarRunner project bootstrapper
- Settings settings = getComponentByType(Settings.class);
+ BootstrapSettings settings = getComponentByType(BootstrapSettings.class);
bootstrapper = new DefaultProjectBootstrapper(settings);
}
reactor = bootstrapper.bootstrap();
private void addBatchComponents() {
add(
- DefaultResourceCreationLock.class,
- DefaultPersistenceManager.class,
- DependencyPersister.class,
- EventPersister.class,
- LinkPersister.class,
- MeasurePersister.class,
- MemoryOptimizer.class,
- DefaultResourcePersister.class,
- SourcePersister.class,
- DefaultNotificationManager.class,
- MetricProvider.class,
- ProjectConfigurator.class,
- DefaultIndex.class,
- DefaultFileLinesContextFactory.class,
- ProjectLock.class,
- LastSnapshots.class,
- Caches.class,
- SnapshotCache.class,
- ResourceCache.class,
- ComponentDataCache.class,
- ComponentDataPersister.class,
+ DefaultResourceCreationLock.class,
+ DefaultPersistenceManager.class,
+ DependencyPersister.class,
+ EventPersister.class,
+ LinkPersister.class,
+ MeasurePersister.class,
+ MemoryOptimizer.class,
+ DefaultResourcePersister.class,
+ SourcePersister.class,
+ DefaultNotificationManager.class,
+ MetricProvider.class,
+ ProjectConfigurator.class,
+ DefaultIndex.class,
+ DefaultFileLinesContextFactory.class,
+ ProjectLock.class,
+ LastSnapshots.class,
+ Caches.class,
+ SnapshotCache.class,
+ ResourceCache.class,
+ ComponentDataCache.class,
+ ComponentDataPersister.class,
- // issues
- IssueUpdater.class,
- FunctionExecutor.class,
- IssueWorkflow.class,
- DeprecatedViolations.class,
- IssueCache.class,
- ScanIssueStorage.class,
- IssuePersister.class,
- IssueNotifications.class,
+ // issues
+ IssueUpdater.class,
+ FunctionExecutor.class,
+ IssueWorkflow.class,
+ DeprecatedViolations.class,
+ IssueCache.class,
+ ScanIssueStorage.class,
+ IssuePersister.class,
+ IssueNotifications.class,
- // tests
- TestPlanPerspectiveLoader.class,
- TestablePerspectiveLoader.class,
- TestPlanBuilder.class,
- TestableBuilder.class,
- ScanGraph.create(),
- GraphPersister.class,
+ // tests
+ TestPlanPerspectiveLoader.class,
+ TestablePerspectiveLoader.class,
+ TestPlanBuilder.class,
+ TestableBuilder.class,
+ ScanGraph.create(),
+ GraphPersister.class,
- // lang
- HighlightableBuilder.class,
- SymbolizableBuilder.class,
+ // lang
+ HighlightableBuilder.class,
+ SymbolizableBuilder.class,
- ProjectSettingsReady.class);
+ ProjectSettingsReady.class);
}
private void fixMavenExecutor() {
*/
package org.sonar.batch.scan;
+import com.google.common.collect.Maps;
import org.apache.commons.io.IOUtils;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.bootstrap.ProjectReactor;
-import org.sonar.api.config.Settings;
+import org.sonar.batch.bootstrap.BootstrapProperties;
+import org.sonar.batch.bootstrap.BootstrapSettings;
import org.sonar.test.TestUtils;
import java.io.File;
assertThat(projectDefinition.getDescription()).isEqualTo("Description of Foo Project");
assertThat(projectDefinition.getSourceDirs()).contains("sources");
assertThat(projectDefinition.getLibraries()).contains(TestUtils.getResource(this.getClass(), "simple-project/libs/lib2.txt").getAbsolutePath(),
- TestUtils.getResource(this.getClass(), "simple-project/libs/lib2.txt").getAbsolutePath());
+ TestUtils.getResource(this.getClass(), "simple-project/libs/lib2.txt").getAbsolutePath());
}
@Test
assertThat(projectDefinition.getSourceDirs()).contains("sources");
assertThat(projectDefinition.getLibraries()).contains(
- TestUtils.getResource(this.getClass(), "simple-project-with-deprecated-props/libs/lib2.txt").getAbsolutePath(),
- TestUtils.getResource(this.getClass(), "simple-project-with-deprecated-props/libs/lib2.txt").getAbsolutePath());
+ TestUtils.getResource(this.getClass(), "simple-project-with-deprecated-props/libs/lib2.txt").getAbsolutePath(),
+ TestUtils.getResource(this.getClass(), "simple-project-with-deprecated-props/libs/lib2.txt").getAbsolutePath());
}
@Test
assertThat(rootProject.getProperties().getProperty("module2.sonar.projectKey")).isNull();
// Check baseDir and workDir
assertThat(rootProject.getBaseDir().getCanonicalFile())
- .isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root"));
+ .isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root"));
assertThat(rootProject.getWorkDir().getCanonicalFile())
- .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root"), ".sonar"));
+ .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root"), ".sonar"));
// CHECK MODULES
List<ProjectDefinition> modules = rootProject.getSubProjects();
assertThat(module1.getProperties().getProperty("module2.sonar.projectKey")).isNull();
// Check baseDir and workDir
assertThat(module1.getBaseDir().getCanonicalFile())
- .isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root/module1"));
+ .isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root/module1"));
assertThat(module1.getWorkDir().getCanonicalFile())
- .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root"), ".sonar/com.foo.project_module1"));
+ .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root"), ".sonar/com.foo.project_module1"));
// Module 2
ProjectDefinition module2 = modules.get(1);
assertThat(module2.getProperties().getProperty("module2.sonar.projectKey")).isNull();
// Check baseDir and workDir
assertThat(module2.getBaseDir().getCanonicalFile())
- .isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root/module2"));
+ .isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root/module2"));
assertThat(module2.getWorkDir().getCanonicalFile())
- .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root"), ".sonar/com.foo.project_com.foo.project.module2"));
+ .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root"), ".sonar/com.foo.project_com.foo.project.module2"));
}
@Test
assertThat(module1.getSourceDirs()).contains("src/main/java");
// and module properties must have been cleaned
assertThat(module1.getWorkDir().getCanonicalFile())
- .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-language-definitions-all-in-root"), ".sonar/example_java-module"));
+ .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-language-definitions-all-in-root"), ".sonar/example_java-module"));
// Module 2
ProjectDefinition module2 = modules.get(1);
assertThat(module2.getSourceDirs()).contains("src/main/groovy");
// and module properties must have been cleaned
assertThat(module2.getWorkDir().getCanonicalFile())
- .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-language-definitions-all-in-root"), ".sonar/example_groovy-module"));
+ .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-language-definitions-all-in-root"), ".sonar/example_groovy-module"));
}
@Test
@Test
public void shouldGetRelativeFile() {
assertThat(DefaultProjectBootstrapper.getFileFromPath("shouldGetFile/foo.properties", TestUtils.getResource(this.getClass(), "/")))
- .isEqualTo(TestUtils.getResource(this.getClass(), "shouldGetFile/foo.properties"));
+ .isEqualTo(TestUtils.getResource(this.getClass(), "shouldGetFile/foo.properties"));
}
@Test
File file = TestUtils.getResource(this.getClass(), "shouldGetFile/foo.properties");
assertThat(DefaultProjectBootstrapper.getFileFromPath(file.getAbsolutePath(), TestUtils.getResource(this.getClass(), "/")))
- .isEqualTo(file);
+ .isEqualTo(file);
}
@Test
@Test
public void shouldInitRootWorkDir() {
- DefaultProjectBootstrapper builder = new DefaultProjectBootstrapper(new Settings());
+ DefaultProjectBootstrapper builder = new DefaultProjectBootstrapper(new BootstrapSettings(new BootstrapProperties(Maps.<String, String> newHashMap())));
File baseDir = new File("target/tmp/baseDir");
File workDir = builder.initRootProjectWorkDir(baseDir);
@Test
public void shouldInitWorkDirWithCustomRelativeFolder() {
- Settings settings = new Settings();
- settings.setProperty("sonar.working.directory", ".foo");
- DefaultProjectBootstrapper builder = new DefaultProjectBootstrapper(settings);
+ Map<String, String> props = Maps.<String, String> newHashMap();
+ props.put("sonar.working.directory", ".foo");
+ DefaultProjectBootstrapper builder = new DefaultProjectBootstrapper(new BootstrapSettings(new BootstrapProperties(props)));
File baseDir = new File("target/tmp/baseDir");
File workDir = builder.initRootProjectWorkDir(baseDir);
@Test
public void shouldInitRootWorkDirWithCustomAbsoluteFolder() {
- Settings settings = new Settings();
- settings.setProperty("sonar.working.directory", new File("src").getAbsolutePath());
- DefaultProjectBootstrapper builder = new DefaultProjectBootstrapper(settings);
+ Map<String, String> props = Maps.<String, String> newHashMap();
+ props.put("sonar.working.directory", new File("src").getAbsolutePath());
+ DefaultProjectBootstrapper builder = new DefaultProjectBootstrapper(new BootstrapSettings(new BootstrapProperties(props)));
File baseDir = new File("target/tmp/baseDir");
File workDir = builder.initRootProjectWorkDir(baseDir);
}
private ProjectDefinition loadProjectDefinition(String projectFolder) throws IOException {
- Settings settings = new Settings();
- settings.addProperties(DefaultProjectBootstrapper.toProperties(TestUtils.getResource(this.getClass(), projectFolder + "/sonar-project.properties")));
- settings.setProperty("sonar.projectBaseDir", TestUtils.getResource(this.getClass(), projectFolder).getAbsolutePath());
- ProjectReactor projectReactor = new DefaultProjectBootstrapper(settings).bootstrap();
+ Map<String, String> props = Maps.<String, String> newHashMap();
+ Properties runnerProps = DefaultProjectBootstrapper.toProperties(TestUtils.getResource(this.getClass(), projectFolder + "/sonar-project.properties"));
+ for (final String name : runnerProps.stringPropertyNames()) {
+ props.put(name, runnerProps.getProperty(name));
+ }
+ props.put("sonar.projectBaseDir", TestUtils.getResource(this.getClass(), projectFolder).getAbsolutePath());
+ BootstrapProperties bootstrapProps = new BootstrapProperties(props);
+ ProjectReactor projectReactor = new DefaultProjectBootstrapper(new BootstrapSettings(bootstrapProps)).bootstrap();
return projectReactor.getRoot();
}