import java.util.List;
+/**
+ * @deprecated since 4.3 kept only to support old version of SonarQube Mojo
+ */
+@Deprecated
@SupportedEnvironment("maven")
public class MavenProjectBootstrapper implements ProjectBootstrapper {
import java.util.List;
import java.util.Map;
+/**
+ * @deprecated since 4.3 kept only to support old version of SonarQube Mojo
+ */
+@Deprecated
@SupportedEnvironment("maven")
public class MavenProjectConverter implements TaskExtension {
import org.apache.commons.io.filefilter.IOFileFilter;
import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.apache.commons.lang.StringUtils;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.project.MavenProject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
import org.sonar.batch.bootstrap.BootstrapSettings;
import org.sonar.core.component.ComponentKeys;
+import javax.annotation.Nullable;
+
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
private BootstrapSettings settings;
private File rootProjectWorkDir;
+ private MavenSession mavenSession;
- DefaultProjectBootstrapper(BootstrapSettings settings) {
+ DefaultProjectBootstrapper(BootstrapSettings settings, @Nullable MavenSession mavenSession) {
this.settings = settings;
+ this.mavenSession = mavenSession;
}
@Override
ProjectDefinition definition = ProjectDefinition.create().setProperties(properties)
.setBaseDir(baseDir)
.setWorkDir(workDir);
+ setMavenProjectIfApplicable(definition);
return definition;
}
+ private void setMavenProjectIfApplicable(ProjectDefinition definition) {
+ if (mavenSession != null) {
+ String moduleKey = definition.getKey();
+ MavenProject foundMavenModule = null;
+ for (MavenProject mavenModule : (List<MavenProject>) mavenSession.getSortedProjects()) {
+ String mavenModuleKey = mavenModule.getGroupId() + ":" + mavenModule.getArtifactId();
+ if (mavenModuleKey.equals(moduleKey)) {
+ foundMavenModule = mavenModule;
+ break;
+ }
+ }
+ if (foundMavenModule == null) {
+ throw new IllegalStateException("Unable to find Maven project in reactor with key " + moduleKey);
+ }
+ definition.addContainerExtension(foundMavenModule);
+ }
+ }
+
private void checkProjectKeyValid(String projectKey) {
if (!ComponentKeys.isValidModuleKey(projectKey)) {
throw new IllegalStateException(String.format(
package org.sonar.batch.scan;
import com.google.common.annotations.VisibleForTesting;
+import org.apache.maven.execution.MavenSession;
import org.sonar.api.BatchExtension;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.InstantiationStrategy;
import org.sonar.batch.DefaultResourceCreationLock;
import org.sonar.batch.ProjectConfigurator;
import org.sonar.batch.ProjectTree;
-import org.sonar.batch.bootstrap.*;
+import org.sonar.batch.bootstrap.BootstrapSettings;
+import org.sonar.batch.bootstrap.ExtensionInstaller;
+import org.sonar.batch.bootstrap.ExtensionMatcher;
+import org.sonar.batch.bootstrap.ExtensionUtils;
+import org.sonar.batch.bootstrap.MetricProvider;
import org.sonar.batch.components.PeriodsDefinition;
import org.sonar.batch.debt.DebtModelProvider;
import org.sonar.batch.debt.IssueChangelogDebtCalculator;
-import org.sonar.batch.index.*;
-import org.sonar.batch.issue.*;
+import org.sonar.batch.index.Caches;
+import org.sonar.batch.index.ComponentDataCache;
+import org.sonar.batch.index.ComponentDataPersister;
+import org.sonar.batch.index.DefaultIndex;
+import org.sonar.batch.index.DefaultPersistenceManager;
+import org.sonar.batch.index.DefaultResourcePersister;
+import org.sonar.batch.index.DependencyPersister;
+import org.sonar.batch.index.EventPersister;
+import org.sonar.batch.index.LinkPersister;
+import org.sonar.batch.index.MeasurePersister;
+import org.sonar.batch.index.MemoryOptimizer;
+import org.sonar.batch.index.ResourceCache;
+import org.sonar.batch.index.ResourceKeyMigration;
+import org.sonar.batch.index.SnapshotCache;
+import org.sonar.batch.index.SourcePersister;
+import org.sonar.batch.issue.DefaultProjectIssues;
+import org.sonar.batch.issue.DeprecatedViolations;
+import org.sonar.batch.issue.IssueCache;
+import org.sonar.batch.issue.IssuePersister;
+import org.sonar.batch.issue.ScanIssueStorage;
import org.sonar.batch.phases.GraphPersister;
import org.sonar.batch.profiling.PhasesSumUpTimeProfiler;
import org.sonar.batch.rule.RulesProvider;
if (reactor == null) {
// OK, not present, so look for a custom ProjectBootstrapper
ProjectBootstrapper bootstrapper = getComponentByType(ProjectBootstrapper.class);
- if (bootstrapper == null) {
+ BootstrapSettings settings = getComponentByType(BootstrapSettings.class);
+ if (bootstrapper == null
+ // Starting from Maven plugin 2.3 then only DefaultProjectBootstrapper should be used.
+ || "true".equals(settings.property("sonar.mojoUseRunner"))) {
// Use default SonarRunner project bootstrapper
- BootstrapSettings settings = getComponentByType(BootstrapSettings.class);
- bootstrapper = new DefaultProjectBootstrapper(settings);
+ bootstrapper = new DefaultProjectBootstrapper(settings, getComponentByType(MavenSession.class));
}
reactor = bootstrapper.bootstrap();
if (reactor == null) {
// Differential periods
PeriodsDefinition.class,
- ProjectSettingsReady.class
- );
+ ProjectSettingsReady.class);
}
private void fixMavenExecutor() {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("You must define the following mandatory properties for 'Unknown': foo2, foo3");
- DefaultProjectBootstrapper.checkMandatoryProperties(props, new String[]{"foo1", "foo2", "foo3"});
+ DefaultProjectBootstrapper.checkMandatoryProperties(props, new String[] {"foo1", "foo2", "foo3"});
}
@Test
thrown.expect(IllegalStateException.class);
thrown.expectMessage("You must define the following mandatory properties for 'my-project': foo2, foo3");
- DefaultProjectBootstrapper.checkMandatoryProperties(props, new String[]{"foo1", "foo2", "foo3"});
+ DefaultProjectBootstrapper.checkMandatoryProperties(props, new String[] {"foo1", "foo2", "foo3"});
}
@Test
props.setProperty("foo1", "bla");
props.setProperty("foo4", "bla");
- DefaultProjectBootstrapper.checkMandatoryProperties(props, new String[]{"foo1"});
+ DefaultProjectBootstrapper.checkMandatoryProperties(props, new String[] {"foo1"});
// No exception should be thrown
}
@Test
public void shouldInitRootWorkDir() {
- DefaultProjectBootstrapper builder = new DefaultProjectBootstrapper(new BootstrapSettings(new BootstrapProperties(Maps.<String, String>newHashMap())));
+ DefaultProjectBootstrapper builder = new DefaultProjectBootstrapper(new BootstrapSettings(new BootstrapProperties(Maps.<String, String>newHashMap())), null);
File baseDir = new File("target/tmp/baseDir");
File workDir = builder.initRootProjectWorkDir(baseDir);
public void shouldInitWorkDirWithCustomRelativeFolder() {
Map<String, String> props = Maps.<String, String>newHashMap();
props.put("sonar.working.directory", ".foo");
- DefaultProjectBootstrapper builder = new DefaultProjectBootstrapper(new BootstrapSettings(new BootstrapProperties(props)));
+ DefaultProjectBootstrapper builder = new DefaultProjectBootstrapper(new BootstrapSettings(new BootstrapProperties(props)), null);
File baseDir = new File("target/tmp/baseDir");
File workDir = builder.initRootProjectWorkDir(baseDir);
public void shouldInitRootWorkDirWithCustomAbsoluteFolder() {
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)));
+ DefaultProjectBootstrapper builder = new DefaultProjectBootstrapper(new BootstrapSettings(new BootstrapProperties(props)), null);
File baseDir = new File("target/tmp/baseDir");
File workDir = builder.initRootProjectWorkDir(baseDir);
}
props.put("sonar.projectBaseDir", TestUtils.getResource(this.getClass(), projectFolder).getAbsolutePath());
BootstrapProperties bootstrapProps = new BootstrapProperties(props);
- ProjectReactor projectReactor = new DefaultProjectBootstrapper(new BootstrapSettings(bootstrapProps)).bootstrap();
+ ProjectReactor projectReactor = new DefaultProjectBootstrapper(new BootstrapSettings(bootstrapProps), null).bootstrap();
return projectReactor.getRoot();
}
*/
package org.sonar.batch.scan;
+import com.google.common.collect.Maps;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.BatchExtension;
import org.sonar.api.config.Settings;
import org.sonar.api.platform.ComponentContainer;
import org.sonar.api.task.TaskExtension;
+import org.sonar.batch.bootstrap.BootstrapProperties;
+import org.sonar.batch.bootstrap.BootstrapSettings;
import org.sonar.batch.bootstrap.ExtensionInstaller;
import org.sonar.batch.profiling.PhasesSumUpTimeProfiler;
import org.sonar.batch.scan.maven.MavenPluginExecutor;
public class ProjectScanContainerTest {
private ProjectBootstrapper projectBootstrapper;
+ private BootstrapSettings bootstrapSettings;
@Before
public void prepare() {
projectBootstrapper = mock(ProjectBootstrapper.class);
when(projectBootstrapper.bootstrap()).thenReturn(new ProjectReactor(ProjectDefinition.create()));
+ bootstrapSettings = new BootstrapSettings(new BootstrapProperties(Maps.<String, String>newHashMap()));
}
@Test
public void should_add_fake_maven_executor_on_non_maven_env() {
ProjectScanContainer container = new ProjectScanContainer(new ComponentContainer());
- container.add(mock(ExtensionInstaller.class), projectBootstrapper);
+ container.add(mock(ExtensionInstaller.class), projectBootstrapper, bootstrapSettings);
container.doBeforeStart();
assertThat(container.getComponentByType(MavenPluginExecutor.class)).isNotNull();
@Test
public void should_use_maven_executor_provided_by_maven() {
ProjectScanContainer container = new ProjectScanContainer(new ComponentContainer());
- container.add(mock(ExtensionInstaller.class), projectBootstrapper);
+ container.add(mock(ExtensionInstaller.class), projectBootstrapper, bootstrapSettings);
MavenPluginExecutor mavenPluginExecutor = mock(MavenPluginExecutor.class);
container.add(mavenPluginExecutor);
container.doBeforeStart();
Settings settings = new Settings();
parentContainer.add(settings);
ProjectScanContainer container = new ProjectScanContainer(parentContainer);
- container.add(mock(ExtensionInstaller.class), projectBootstrapper);
+ container.add(mock(ExtensionInstaller.class), projectBootstrapper, bootstrapSettings);
container.doBeforeStart();
assertThat(container.getComponentsByType(PhasesSumUpTimeProfiler.class)).hasSize(0);
settings.setProperty(CoreProperties.PROFILING_LOG_PROPERTY, "true");
container = new ProjectScanContainer(parentContainer);
- container.add(mock(ExtensionInstaller.class), projectBootstrapper);
+ container.add(mock(ExtensionInstaller.class), projectBootstrapper, bootstrapSettings);
container.doBeforeStart();
assertThat(container.getComponentsByType(PhasesSumUpTimeProfiler.class)).hasSize(1);
* Only one instance is allowed per environment.
*
* @since 3.7
+ * @deprecated since 4.3 All bootstrappers should use SQ Runner API and provide a set of properties
*/
+@Deprecated
public interface ProjectBootstrapper extends TaskExtension {
/**