diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2013-06-17 17:45:56 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2013-06-17 17:45:56 +0200 |
commit | 32ec8599d050066e41e12acd4b554febd3920197 (patch) | |
tree | f06a136a4e426e4b8ef8491627e1eb52fb1529c6 | |
parent | a07ebb829958f3aa566b6246e4643dad91b96b6c (diff) | |
download | sonarqube-32ec8599d050066e41e12acd4b554febd3920197.tar.gz sonarqube-32ec8599d050066e41e12acd4b554febd3920197.zip |
Revert "SONAR-3979, SONAR-4047 Fix Sonar Maven goal to support Maven 3.1"
This reverts commit ceaddeb0db54d29fd67d11f23488f61f85041446.
12 files changed, 142 insertions, 267 deletions
@@ -153,12 +153,13 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> - <version>3.1</version> + <version>3.0</version> </plugin> <plugin> + <!-- not thread safe --> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> - <version>2.7</version> + <version>2.5.1</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> @@ -173,7 +174,7 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> - <version>2.15</version> + <version>2.12</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> @@ -218,7 +219,7 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-plugin-plugin</artifactId> - <version>3.2</version> + <version>2.9</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> @@ -249,12 +250,12 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> - <version>2.14.1</version> + <version>2.12.4</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> - <version>2.3</version> + <version>2.1.1</version> </plugin> <plugin> <!-- not thread safe --> @@ -265,7 +266,7 @@ <plugin> <groupId>org.codehaus.sonar</groupId> <artifactId>sonar-packaging-maven-plugin</artifactId> - <version>1.7</version> + <version>1.6</version> </plugin> </plugins> </pluginManagement> @@ -935,7 +936,7 @@ <dependency> <groupId>org.apache.maven.shared</groupId> <artifactId>maven-dependency-tree</artifactId> - <version>2.1</version> + <version>1.2</version> <exclusions> <exclusion> <!-- See SONAR-2455 --> diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Batch.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Batch.java index 5503d5f03de..dfd4fcb2bc1 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Batch.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Batch.java @@ -55,7 +55,7 @@ public final class Batch { } projectReactor = builder.projectReactor; if (builder.isEnableLoggingConfiguration()) { - logging = LoggingConfiguration.create(builder.environment).setProperties(bootstrapProperties); + logging = LoggingConfiguration.create().setProperties(bootstrapProperties); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/LoggingConfiguration.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/LoggingConfiguration.java index 0f87fd7990b..fc654057d2a 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/LoggingConfiguration.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/LoggingConfiguration.java @@ -19,13 +19,10 @@ */ package org.sonar.batch.bootstrapper; -import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.Maps; import org.apache.commons.lang.StringUtils; import org.sonar.core.config.Logback; -import javax.annotation.Nullable; - import java.io.File; import java.util.Map; @@ -46,26 +43,19 @@ public final class LoggingConfiguration { public static final String LEVEL_SQL_RESULTS_VERBOSE = "DEBUG"; public static final String LEVEL_SQL_RESULTS_DEFAULT = "WARN"; - @VisibleForTesting - static final String FORMAT_DEFAULT = "%d{HH:mm:ss.SSS} %-5level - %msg%n"; - @VisibleForTesting - static final String FORMAT_MAVEN = "[%level] [%d{HH:mm:ss.SSS}] %msg%n"; + public static final String FORMAT_DEFAULT = "%d{HH:mm:ss.SSS} %-5level - %msg%n"; + public static final String FORMAT_MAVEN = "[%level] [%d{HH:mm:ss.SSS}] %msg%n"; private Map<String, String> substitutionVariables = Maps.newHashMap(); - private LoggingConfiguration(@Nullable EnvironmentInformation environment) { + private LoggingConfiguration() { setVerbose(false); setShowSql(false); - if (environment != null && "maven".equalsIgnoreCase(environment.getKey())) { - setFormat(FORMAT_MAVEN); - } - else { - setFormat(FORMAT_DEFAULT); - } + setFormat(FORMAT_DEFAULT); } - static LoggingConfiguration create(@Nullable EnvironmentInformation environment) { - return new LoggingConfiguration(environment); + static LoggingConfiguration create() { + return new LoggingConfiguration(); } public LoggingConfiguration setProperties(Map<String, String> properties) { @@ -99,8 +89,7 @@ public final class LoggingConfiguration { return addSubstitutionVariable(PROPERTY_SQL_RESULTS_LOGGER_LEVEL, level); } - @VisibleForTesting - LoggingConfiguration setFormat(String format) { + public LoggingConfiguration setFormat(String format) { return addSubstitutionVariable(PROPERTY_FORMAT, StringUtils.defaultIfBlank(format, FORMAT_DEFAULT)); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/maven/MavenProjectConverter.java b/sonar-batch/src/main/java/org/sonar/batch/scan/maven/MavenProjectConverter.java index 41f0e8f72e1..47659b43ace 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/maven/MavenProjectConverter.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/maven/MavenProjectConverter.java @@ -20,8 +20,6 @@ package org.sonar.batch.scan.maven; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Predicate; -import com.google.common.collect.Collections2; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import org.apache.commons.lang.StringUtils; @@ -52,12 +50,6 @@ public class MavenProjectConverter { } public static ProjectDefinition convert(List<MavenProject> poms, MavenProject root) { - ProjectDefinition def = ProjectDefinition.create(); - configure(def, poms, root); - return def; - } - - public static void configure(ProjectDefinition rootProjectDefinition, List<MavenProject> poms, MavenProject root) { // projects by canonical path to pom.xml Map<String, MavenProject> paths = Maps.newHashMap(); Map<MavenProject, ProjectDefinition> defs = Maps.newHashMap(); @@ -65,9 +57,7 @@ public class MavenProjectConverter { try { for (MavenProject pom : poms) { paths.put(pom.getFile().getCanonicalPath(), pom); - ProjectDefinition def = pom == root ? rootProjectDefinition : ProjectDefinition.create(); - merge(pom, def); - defs.put(pom, def); + defs.put(pom, convert(pom)); } for (Map.Entry<String, MavenProject> entry : paths.entrySet()) { @@ -96,6 +86,7 @@ public class MavenProjectConverter { if (rootProject == null) { throw new IllegalStateException(UNABLE_TO_DETERMINE_PROJECT_STRUCTURE_EXCEPTION_MESSAGE); } + return rootProject; } private static MavenProject findMavenProject(final File modulePath, Map<String, MavenProject> paths) throws IOException { @@ -113,29 +104,27 @@ public class MavenProjectConverter { } @VisibleForTesting - static void merge(MavenProject pom, ProjectDefinition definition) { - String key = getSonarKey(pom); + static ProjectDefinition convert(MavenProject pom) { + String key = new StringBuilder().append(pom.getGroupId()).append(":").append(pom.getArtifactId()).toString(); + ProjectDefinition definition = ProjectDefinition.create(); // IMPORTANT NOTE : reference on properties from POM model must not be saved, // instead they should be copied explicitly - see SONAR-2896 definition - .setProperties(pom.getModel().getProperties()) - .setKey(key) - .setVersion(pom.getVersion()) - .setName(pom.getName()) - .setDescription(pom.getDescription()) - .addContainerExtension(pom); + .setProperties(pom.getModel().getProperties()) + .setKey(key) + .setVersion(pom.getVersion()) + .setName(pom.getName()) + .setDescription(pom.getDescription()) + .addContainerExtension(pom); guessJavaVersion(pom, definition); guessEncoding(pom, definition); convertMavenLinksToProperties(definition, pom); synchronizeFileSystem(pom, definition); - } - - public static String getSonarKey(MavenProject pom) { - return new StringBuilder().append(pom.getGroupId()).append(":").append(pom.getArtifactId()).toString(); + return definition; } private static void guessEncoding(MavenProject pom, ProjectDefinition definition) { - // See http://jira.codehaus.org/browse/SONAR-2151 + //See http://jira.codehaus.org/browse/SONAR-2151 String encoding = MavenUtils.getSourceEncoding(pom); if (encoding != null) { definition.setProperty(CoreProperties.ENCODING_PROPERTY, encoding); @@ -189,47 +178,27 @@ public class MavenProjectConverter { public static void synchronizeFileSystem(MavenProject pom, ProjectDefinition into) { into.setBaseDir(pom.getBasedir()); - File buildDir = getBuildDir(pom); + File buildDir = resolvePath(pom.getBuild().getDirectory(), pom.getBasedir()); if (buildDir != null) { into.setBuildDir(buildDir); - into.setWorkDir(getSonarWorkDir(pom)); + into.setWorkDir(new File(buildDir, "sonar")); } - List<String> filteredCompileSourceRoots = filterExisting(pom.getCompileSourceRoots(), pom.getBasedir()); - List<String> filteredTestCompileSourceRoots = filterExisting(pom.getTestCompileSourceRoots(), pom.getBasedir()); - into.setSourceDirs((String[]) filteredCompileSourceRoots.toArray(new String[filteredCompileSourceRoots.size()])); - into.setTestDirs((String[]) filteredTestCompileSourceRoots.toArray(new String[filteredTestCompileSourceRoots.size()])); + into.setSourceDirs((String[]) pom.getCompileSourceRoots().toArray(new String[pom.getCompileSourceRoots().size()])); + into.setTestDirs((String[]) pom.getTestCompileSourceRoots().toArray(new String[pom.getTestCompileSourceRoots().size()])); File binaryDir = resolvePath(pom.getBuild().getOutputDirectory(), pom.getBasedir()); if (binaryDir != null) { into.addBinaryDir(binaryDir); } } - public static File getSonarWorkDir(MavenProject pom) { - return new File(getBuildDir(pom), "sonar"); - } - - private static File getBuildDir(MavenProject pom) { - return resolvePath(pom.getBuild().getDirectory(), pom.getBasedir()); - } - - private static List<String> filterExisting(List<String> filePaths, final File baseDir) { - return Lists.newArrayList(Collections2.filter(filePaths, new Predicate<String>() { - @Override - public boolean apply(String filePath) { - File file = resolvePath(filePath, baseDir); - return file != null && file.exists(); - } - })); - } - public static void synchronizeFileSystem(MavenProject pom, DefaultModuleFileSystem into) { into.resetDirs( - pom.getBasedir(), - getBuildDir(pom), - resolvePaths((List<String>) pom.getCompileSourceRoots(), pom.getBasedir()), - resolvePaths((List<String>) pom.getTestCompileSourceRoots(), pom.getBasedir()), - Arrays.asList(resolvePath(pom.getBuild().getOutputDirectory(), pom.getBasedir())) - ); + pom.getBasedir(), + resolvePath(pom.getBuild().getDirectory(), pom.getBasedir()), + resolvePaths((List<String>) pom.getCompileSourceRoots(), pom.getBasedir()), + resolvePaths((List<String>) pom.getTestCompileSourceRoots(), pom.getBasedir()), + Arrays.asList(resolvePath(pom.getBuild().getOutputDirectory(), pom.getBasedir())) + ); } static File resolvePath(String path, File basedir) { diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrapper/LoggingConfigurationTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrapper/LoggingConfigurationTest.java index 1f818ea82e9..d091aac62a5 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrapper/LoggingConfigurationTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrapper/LoggingConfigurationTest.java @@ -20,107 +20,102 @@ package org.sonar.batch.bootstrapper; import com.google.common.collect.Maps; +import org.hamcrest.core.Is; import org.junit.Test; import java.util.Map; -import static org.fest.assertions.Assertions.assertThat; +import static org.junit.Assert.assertThat; public class LoggingConfigurationTest { @Test public void testSqlLevel() { - assertThat(LoggingConfiguration.create(null).setShowSql(true) - .getSubstitutionVariable(LoggingConfiguration.PROPERTY_SQL_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_SQL_VERBOSE); + assertThat(LoggingConfiguration.create().setShowSql(true) + .getSubstitutionVariable(LoggingConfiguration.PROPERTY_SQL_LOGGER_LEVEL), Is.is(LoggingConfiguration.LEVEL_SQL_VERBOSE)); - assertThat(LoggingConfiguration.create(null).setShowSql(false) - .getSubstitutionVariable(LoggingConfiguration.PROPERTY_SQL_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_SQL_DEFAULT); + assertThat(LoggingConfiguration.create().setShowSql(false) + .getSubstitutionVariable(LoggingConfiguration.PROPERTY_SQL_LOGGER_LEVEL), Is.is(LoggingConfiguration.LEVEL_SQL_DEFAULT)); - assertThat(LoggingConfiguration.create(null).setSqlLevel("ERROR") - .getSubstitutionVariable(LoggingConfiguration.PROPERTY_SQL_LOGGER_LEVEL)).isEqualTo("ERROR"); + assertThat(LoggingConfiguration.create().setSqlLevel("ERROR") + .getSubstitutionVariable(LoggingConfiguration.PROPERTY_SQL_LOGGER_LEVEL), Is.is("ERROR")); } @Test public void shouldNotShowSqlByDefault() { - assertThat(LoggingConfiguration.create(null) - .getSubstitutionVariable(LoggingConfiguration.PROPERTY_SQL_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_SQL_DEFAULT); + assertThat(LoggingConfiguration.create() + .getSubstitutionVariable(LoggingConfiguration.PROPERTY_SQL_LOGGER_LEVEL), Is.is(LoggingConfiguration.LEVEL_SQL_DEFAULT)); } @Test public void testSetVerbose() { - assertThat(LoggingConfiguration.create(null).setVerbose(true) - .getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_ROOT_VERBOSE); + assertThat(LoggingConfiguration.create().setVerbose(true) + .getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL), Is.is(LoggingConfiguration.LEVEL_ROOT_VERBOSE)); - assertThat(LoggingConfiguration.create(null).setVerbose(false) - .getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_ROOT_DEFAULT); + assertThat(LoggingConfiguration.create().setVerbose(false) + .getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL), Is.is(LoggingConfiguration.LEVEL_ROOT_DEFAULT)); - assertThat(LoggingConfiguration.create(null).setRootLevel("ERROR") - .getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL)).isEqualTo("ERROR"); + assertThat(LoggingConfiguration.create().setRootLevel("ERROR") + .getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL), Is.is("ERROR")); } @Test public void shouldNotBeVerboseByDefault() { - assertThat(LoggingConfiguration.create(null) - .getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_ROOT_DEFAULT); + assertThat(LoggingConfiguration.create() + .getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL), Is.is(LoggingConfiguration.LEVEL_ROOT_DEFAULT)); } @Test public void testSetVerboseProperty() { Map<String, String> properties = Maps.newHashMap(); - assertThat(LoggingConfiguration.create(null).setProperties(properties) - .getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_ROOT_DEFAULT); + assertThat(LoggingConfiguration.create().setProperties(properties) + .getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL), Is.is(LoggingConfiguration.LEVEL_ROOT_DEFAULT)); properties.put("sonar.verbose", "true"); - assertThat(LoggingConfiguration.create(null).setProperties(properties) - .getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_ROOT_VERBOSE); + assertThat(LoggingConfiguration.create().setProperties(properties) + .getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL), Is.is(LoggingConfiguration.LEVEL_ROOT_VERBOSE)); properties.put("sonar.verbose", "false"); - assertThat(LoggingConfiguration.create(null).setProperties(properties) - .getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_ROOT_DEFAULT); + assertThat(LoggingConfiguration.create().setProperties(properties) + .getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL), Is.is(LoggingConfiguration.LEVEL_ROOT_DEFAULT)); } @Test public void testSetShowSqlProperty() { Map<String, String> properties = Maps.newHashMap(); - assertThat(LoggingConfiguration.create(null).setProperties(properties) - .getSubstitutionVariable(LoggingConfiguration.PROPERTY_SQL_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_SQL_DEFAULT); + assertThat(LoggingConfiguration.create().setProperties(properties) + .getSubstitutionVariable(LoggingConfiguration.PROPERTY_SQL_LOGGER_LEVEL), Is.is(LoggingConfiguration.LEVEL_SQL_DEFAULT)); properties.put("sonar.showSql", "true"); - assertThat(LoggingConfiguration.create(null).setProperties(properties) - .getSubstitutionVariable(LoggingConfiguration.PROPERTY_SQL_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_SQL_VERBOSE); + assertThat(LoggingConfiguration.create().setProperties(properties) + .getSubstitutionVariable(LoggingConfiguration.PROPERTY_SQL_LOGGER_LEVEL), Is.is(LoggingConfiguration.LEVEL_SQL_VERBOSE)); properties.put("sonar.showSql", "false"); - assertThat(LoggingConfiguration.create(null).setProperties(properties) - .getSubstitutionVariable(LoggingConfiguration.PROPERTY_SQL_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_SQL_DEFAULT); + assertThat(LoggingConfiguration.create().setProperties(properties) + .getSubstitutionVariable(LoggingConfiguration.PROPERTY_SQL_LOGGER_LEVEL), Is.is(LoggingConfiguration.LEVEL_SQL_DEFAULT)); } @Test public void testDefaultFormat() { - assertThat(LoggingConfiguration.create(null) - .getSubstitutionVariable(LoggingConfiguration.PROPERTY_FORMAT)).isEqualTo(LoggingConfiguration.FORMAT_DEFAULT); - } - - @Test - public void testMavenFormat() { - assertThat(LoggingConfiguration.create(new EnvironmentInformation("maven", "1.0")) - .getSubstitutionVariable(LoggingConfiguration.PROPERTY_FORMAT)).isEqualTo(LoggingConfiguration.FORMAT_MAVEN); + assertThat(LoggingConfiguration.create() + .getSubstitutionVariable(LoggingConfiguration.PROPERTY_FORMAT), Is.is(LoggingConfiguration.FORMAT_DEFAULT)); } @Test public void testSetFormat() { - assertThat(LoggingConfiguration.create(null).setFormat("%d %level") - .getSubstitutionVariable(LoggingConfiguration.PROPERTY_FORMAT)).isEqualTo("%d %level"); + assertThat(LoggingConfiguration.create().setFormat("%d %level") + .getSubstitutionVariable(LoggingConfiguration.PROPERTY_FORMAT), Is.is("%d %level")); } @Test public void shouldNotSetBlankFormat() { - assertThat(LoggingConfiguration.create(null).setFormat(null) - .getSubstitutionVariable(LoggingConfiguration.PROPERTY_FORMAT)).isEqualTo(LoggingConfiguration.FORMAT_DEFAULT); + assertThat(LoggingConfiguration.create().setFormat(null) + .getSubstitutionVariable(LoggingConfiguration.PROPERTY_FORMAT), Is.is(LoggingConfiguration.FORMAT_DEFAULT)); - assertThat(LoggingConfiguration.create(null).setFormat("") - .getSubstitutionVariable(LoggingConfiguration.PROPERTY_FORMAT)).isEqualTo(LoggingConfiguration.FORMAT_DEFAULT); + assertThat(LoggingConfiguration.create().setFormat("") + .getSubstitutionVariable(LoggingConfiguration.PROPERTY_FORMAT), Is.is(LoggingConfiguration.FORMAT_DEFAULT)); - assertThat(LoggingConfiguration.create(null).setFormat(" ") - .getSubstitutionVariable(LoggingConfiguration.PROPERTY_FORMAT)).isEqualTo(LoggingConfiguration.FORMAT_DEFAULT); + assertThat(LoggingConfiguration.create().setFormat(" ") + .getSubstitutionVariable(LoggingConfiguration.PROPERTY_FORMAT), Is.is(LoggingConfiguration.FORMAT_DEFAULT)); } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/maven/MavenProjectConverterTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/maven/MavenProjectConverterTest.java index f4fc136cab9..bdb65b90861 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/maven/MavenProjectConverterTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/maven/MavenProjectConverterTest.java @@ -105,8 +105,7 @@ public class MavenProjectConverterTest { pom.setDescription("just test"); pom.setFile(new File("/foo/pom.xml")); pom.getBuild().setDirectory("target"); - ProjectDefinition project = ProjectDefinition.create(); - MavenProjectConverter.merge(pom, project); + ProjectDefinition project = MavenProjectConverter.convert(pom); Properties properties = project.getProperties(); assertThat(properties.getProperty(CoreProperties.PROJECT_KEY_PROPERTY), is("foo:bar")); diff --git a/sonar-maven-plugin/pom.xml b/sonar-maven-plugin/pom.xml index 4dadfc59428..6efe191c675 100644 --- a/sonar-maven-plugin/pom.xml +++ b/sonar-maven-plugin/pom.xml @@ -18,11 +18,7 @@ <dependency> <groupId>org.apache.maven.shared</groupId> <artifactId>maven-dependency-tree</artifactId> - </dependency> - <dependency> - <groupId>org.codehaus.sonar.runner</groupId> - <artifactId>sonar-runner-api</artifactId> - <version>2.2.2</version> + <version>1.2</version> </dependency> <dependency> <groupId>org.codehaus.sonar</groupId> diff --git a/sonar-maven-plugin/src/main/java/org/sonar/maven/SonarMaven2ProjectBuilder.java b/sonar-maven-plugin/src/main/java/org/sonar/maven/SonarMaven2ProjectBuilder.java deleted file mode 100644 index 6ec6ea0704a..00000000000 --- a/sonar-maven-plugin/src/main/java/org/sonar/maven/SonarMaven2ProjectBuilder.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.sonar.maven; - -import org.apache.maven.execution.MavenSession; -import org.apache.maven.project.MavenProject; -import org.sonar.api.batch.bootstrap.ProjectBuilder; -import org.sonar.api.batch.bootstrap.ProjectBuilderContext; -import org.sonar.batch.scan.maven.MavenProjectConverter; - -import java.util.List; - -public class SonarMaven2ProjectBuilder extends ProjectBuilder { - - private MavenSession session; - - public SonarMaven2ProjectBuilder(MavenSession session) { - this.session = session; - } - - @Override - public void build(ProjectBuilderContext context) { - List<MavenProject> sortedProjects = session.getSortedProjects(); - MavenProject topLevelProject = null; - for (MavenProject project : sortedProjects) { - if (project.isExecutionRoot()) { - topLevelProject = project; - break; - } - } - MavenProjectConverter.configure(context.getProjectReactor().getRoot(), sortedProjects, topLevelProject); - } - -} diff --git a/sonar-maven-plugin/src/main/java/org/sonar/maven/SonarMojo.java b/sonar-maven-plugin/src/main/java/org/sonar/maven/SonarMojo.java index c5215e28a85..ffce333b4c3 100644 --- a/sonar-maven-plugin/src/main/java/org/sonar/maven/SonarMojo.java +++ b/sonar-maven-plugin/src/main/java/org/sonar/maven/SonarMojo.java @@ -19,8 +19,7 @@ */ package org.sonar.maven; -import org.apache.commons.lang.ObjectUtils; -import org.apache.commons.lang.StringUtils; +import com.google.common.collect.Maps; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.repository.ArtifactRepository; @@ -35,14 +34,12 @@ import org.apache.maven.plugin.PluginManager; import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder; -import org.sonar.api.batch.maven.MavenUtils; +import org.sonar.api.batch.bootstrap.ProjectDefinition; +import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.batch.scan.maven.MavenProjectConverter; -import org.sonar.runner.api.EmbeddedRunner; -import org.sonar.runner.api.RunnerProperties; -import org.sonar.runner.api.ScanProperties; - -import java.util.Map.Entry; -import java.util.Set; +import org.sonar.batch.bootstrapper.Batch; +import org.sonar.batch.bootstrapper.EnvironmentInformation; +import org.sonar.batch.bootstrapper.LoggingConfiguration; /** * @goal sonar @@ -137,39 +134,32 @@ public final class SonarMojo extends AbstractMojo { private RuntimeInformation runtimeInformation; public void execute() throws MojoExecutionException, MojoFailureException { + ProjectDefinition def = MavenProjectConverter.convert(session.getSortedProjects(), project); + ProjectReactor reactor = new ProjectReactor(def); + + Batch batch = Batch.builder() + .setEnvironment(getEnvironmentInformation()) + .setProjectReactor(reactor) + .addComponents( + session, getLog(), lifecycleExecutor, pluginManager, artifactFactory, + localRepository, artifactMetadataSource, artifactCollector, dependencyTreeBuilder, + projectBuilder, Maven2PluginExecutor.class) + .build(); + + configureLogging(batch.getLoggingConfiguration()); + batch.execute(); + } - EmbeddedRunner runner = EmbeddedRunner.create() - .setApp("Maven", getMavenVersion()); - // Workaround for SONARPLUGINS-2947 - // TODO remove when it will be fixed - runner.setProperty("sonarRunner.userAgent", "Maven"); - runner.setProperty("sonarRunner.userAgentVersion", getMavenVersion()); - Set<Entry<Object, Object>> properties = project.getModel().getProperties().entrySet(); - for (Entry<Object, Object> entry : properties) { - runner.setProperty(ObjectUtils.toString(entry.getKey()), ObjectUtils.toString(entry.getValue())); - } - String encoding = MavenUtils.getSourceEncoding(project); - if (encoding != null) { - runner.setProperty(ScanProperties.PROJECT_SOURCE_ENCODING, encoding); - } - runner.setProperty(ScanProperties.PROJECT_KEY, MavenProjectConverter.getSonarKey(project)) - .setProperty(RunnerProperties.WORK_DIR, MavenProjectConverter.getSonarWorkDir(project).getAbsolutePath()) - .setProperty(ScanProperties.PROJECT_BASEDIR, project.getBasedir().getAbsolutePath()) - .setProperty(ScanProperties.PROJECT_VERSION, StringUtils.defaultString(project.getVersion())) - .setProperty(ScanProperties.PROJECT_NAME, StringUtils.defaultString(project.getName())) - .setProperty(ScanProperties.PROJECT_DESCRIPTION, StringUtils.defaultString(project.getDescription())) - .setProperty(ScanProperties.PROJECT_SOURCE_DIRS, ".") - // Required to share ProjectBuilder extension between SonarMavenProjectBuilder and Sonar classloader - .setUnmaskedPackages("org.sonar.api.batch.bootstrap") - .addExtensions(session, getLog(), lifecycleExecutor, artifactFactory, localRepository, artifactMetadataSource, artifactCollector, - dependencyTreeBuilder, projectBuilder, Maven2PluginExecutor.class, new SonarMaven2ProjectBuilder(session)); + private void configureLogging(LoggingConfiguration logging) { + logging.setProperties(Maps.fromProperties(session.getExecutionProperties())); + logging.setFormat(LoggingConfiguration.FORMAT_MAVEN); if (getLog().isDebugEnabled()) { - runner.setProperty("sonar.verbose", "true"); + logging.setVerbose(true); } - runner.execute(); } - private String getMavenVersion() { - return runtimeInformation.getApplicationVersion().toString(); + private EnvironmentInformation getEnvironmentInformation() { + String mavenVersion = runtimeInformation.getApplicationVersion().toString(); + return new EnvironmentInformation("Maven", mavenVersion); } } diff --git a/sonar-maven3-plugin/pom.xml b/sonar-maven3-plugin/pom.xml index 79415af2b4d..2e5cf98cd49 100644 --- a/sonar-maven3-plugin/pom.xml +++ b/sonar-maven3-plugin/pom.xml @@ -18,11 +18,7 @@ <dependency> <groupId>org.apache.maven.shared</groupId> <artifactId>maven-dependency-tree</artifactId> - </dependency> - <dependency> - <groupId>org.codehaus.sonar.runner</groupId> - <artifactId>sonar-runner-api</artifactId> - <version>2.2.2</version> + <version>1.2</version> </dependency> <dependency> <groupId>org.codehaus.sonar</groupId> @@ -34,6 +30,10 @@ <artifactId>slf4j-api</artifactId> </dependency> <dependency> + <groupId>ch.qos.logback</groupId> + <artifactId>logback-classic</artifactId> + </dependency> + <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-plugin-api</artifactId> <version>${maven.version}</version> diff --git a/sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMaven3ProjectBuilder.java b/sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMaven3ProjectBuilder.java deleted file mode 100644 index 50843f90c8d..00000000000 --- a/sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMaven3ProjectBuilder.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.sonar.maven3; - -import org.apache.maven.execution.MavenSession; -import org.sonar.api.batch.bootstrap.ProjectBuilder; -import org.sonar.api.batch.bootstrap.ProjectBuilderContext; -import org.sonar.batch.scan.maven.MavenProjectConverter; - -public class SonarMaven3ProjectBuilder extends ProjectBuilder { - - private MavenSession session; - - public SonarMaven3ProjectBuilder(MavenSession session) { - this.session = session; - } - - @Override - public void build(ProjectBuilderContext context) { - MavenProjectConverter.configure(context.getProjectReactor().getRoot(), session.getProjects(), session.getTopLevelProject()); - } - -} diff --git a/sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMojo.java b/sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMojo.java index 0558954d7dd..63ee50dc889 100644 --- a/sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMojo.java +++ b/sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMojo.java @@ -19,8 +19,7 @@ */ package org.sonar.maven3; -import org.apache.commons.lang.ObjectUtils; -import org.apache.commons.lang.StringUtils; +import com.google.common.collect.Maps; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.repository.ArtifactRepository; @@ -34,14 +33,12 @@ import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder; -import org.sonar.api.batch.maven.MavenUtils; +import org.sonar.api.batch.bootstrap.ProjectDefinition; +import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.batch.scan.maven.MavenProjectConverter; -import org.sonar.runner.api.EmbeddedRunner; -import org.sonar.runner.api.RunnerProperties; -import org.sonar.runner.api.ScanProperties; - -import java.util.Map.Entry; -import java.util.Set; +import org.sonar.batch.bootstrapper.Batch; +import org.sonar.batch.bootstrapper.EnvironmentInformation; +import org.sonar.batch.bootstrapper.LoggingConfiguration; /** * @goal sonar @@ -130,40 +127,32 @@ public final class SonarMojo extends AbstractMojo { private RuntimeInformation runtimeInformation; public void execute() throws MojoExecutionException, MojoFailureException { + ProjectDefinition def = MavenProjectConverter.convert(session.getProjects(), project); + ProjectReactor reactor = new ProjectReactor(def); + + Batch batch = Batch.builder() + .setEnvironment(getEnvironmentInformation()) + .setProjectReactor(reactor) + .addComponents( + session, getLog(), lifecycleExecutor, artifactFactory, localRepository, artifactMetadataSource, artifactCollector, + dependencyTreeBuilder, projectBuilder, Maven3PluginExecutor.class) + .build(); + + configureLogging(batch.getLoggingConfiguration()); + batch.execute(); + } - EmbeddedRunner runner = EmbeddedRunner.create() - .setApp("Maven", getMavenVersion()); - // Workaround for SONARPLUGINS-2947 - // TODO remove when it will be fixed - runner.setProperty("sonarRunner.userAgent", "Maven"); - runner.setProperty("sonarRunner.userAgentVersion", getMavenVersion()); - Set<Entry<Object, Object>> properties = project.getModel().getProperties().entrySet(); - for (Entry<Object, Object> entry : properties) { - runner.setProperty(ObjectUtils.toString(entry.getKey()), ObjectUtils.toString(entry.getValue())); - } - String encoding = MavenUtils.getSourceEncoding(project); - if (encoding != null) { - runner.setProperty(ScanProperties.PROJECT_SOURCE_ENCODING, encoding); - } - runner.setProperty(ScanProperties.PROJECT_KEY, MavenProjectConverter.getSonarKey(project)) - .setProperty(RunnerProperties.WORK_DIR, MavenProjectConverter.getSonarWorkDir(project).getAbsolutePath()) - .setProperty(ScanProperties.PROJECT_BASEDIR, project.getBasedir().getAbsolutePath()) - .setProperty(ScanProperties.PROJECT_VERSION, StringUtils.defaultString(project.getVersion())) - .setProperty(ScanProperties.PROJECT_NAME, StringUtils.defaultString(project.getName())) - .setProperty(ScanProperties.PROJECT_DESCRIPTION, StringUtils.defaultString(project.getDescription())) - .setProperty(ScanProperties.PROJECT_SOURCE_DIRS, ".") - // Required to share ProjectBuilder extension between SonarMavenProjectBuilder and Sonar classloader - .setUnmaskedPackages("org.sonar.api.batch.bootstrap") - .addExtensions(session, getLog(), lifecycleExecutor, artifactFactory, localRepository, artifactMetadataSource, artifactCollector, - dependencyTreeBuilder, projectBuilder, Maven3PluginExecutor.class, new SonarMaven3ProjectBuilder(session)); + private void configureLogging(LoggingConfiguration logging) { + logging.setProperties(Maps.fromProperties(session.getSystemProperties())); + logging.setFormat(LoggingConfiguration.FORMAT_MAVEN); if (getLog().isDebugEnabled()) { - runner.setProperty("sonar.verbose", "true"); + logging.setVerbose(true); } - runner.execute(); } - private String getMavenVersion() { - return runtimeInformation.getApplicationVersion().toString(); + private EnvironmentInformation getEnvironmentInformation() { + String mavenVersion = runtimeInformation.getApplicationVersion().toString(); + return new EnvironmentInformation("Maven", mavenVersion); } } |