aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/batch/MavenDependenciesSensor.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java9
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrapper/EnvironmentInformation.java54
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrapper/ProjectDefinition.java7
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Reactor.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrapper/package-info.java (renamed from sonar-plugin-api/src/main/java/org/sonar/api/platform/Environment.java)29
-rw-r--r--sonar-core-maven-plugin/src/main/java/org/sonar/maven2/BatchMojo.java33
-rw-r--r--sonar-maven-plugin/src/main/java/org/sonar/maven/SonarMojo.java21
-rw-r--r--sonar-maven3-plugin/pom.xml6
-rw-r--r--sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMojo.java21
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/platform/EnvironmentTest.java52
-rw-r--r--sonar-server/src/main/java/org/sonar/server/platform/Platform.java2
12 files changed, 128 insertions, 112 deletions
diff --git a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/batch/MavenDependenciesSensor.java b/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/batch/MavenDependenciesSensor.java
index eb00b801d4c..198340252c4 100644
--- a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/batch/MavenDependenciesSensor.java
+++ b/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/batch/MavenDependenciesSensor.java
@@ -44,7 +44,7 @@ import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.utils.SonarException;
-@SupportedEnvironment({ "maven2", "maven3" })
+@SupportedEnvironment("maven")
public class MavenDependenciesSensor implements Sensor {
private ArtifactRepository localRepository;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java
index af4d177edb3..5ec8ac920ae 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java
@@ -37,11 +37,11 @@ import org.sonar.api.Plugin;
import org.sonar.api.batch.AbstractCoverageExtension;
import org.sonar.api.batch.CoverageExtension;
import org.sonar.api.batch.SupportedEnvironment;
-import org.sonar.api.platform.Environment;
import org.sonar.api.resources.Java;
import org.sonar.api.resources.Project;
import org.sonar.api.utils.AnnotationUtils;
import org.sonar.api.utils.SonarException;
+import org.sonar.batch.bootstrapper.EnvironmentInformation;
import org.sonar.core.classloaders.ClassLoadersCollection;
import org.sonar.core.plugin.AbstractPluginRepository;
import org.sonar.core.plugin.JpaPlugin;
@@ -56,12 +56,13 @@ public class BatchPluginRepository extends AbstractPluginRepository {
private ClassLoadersCollection classLoaders;
private ExtensionDownloader extensionDownloader;
- private Environment environment;
+ private EnvironmentInformation environment;
- public BatchPluginRepository(JpaPluginDao dao, ExtensionDownloader extensionDownloader, Environment environment) {
+ public BatchPluginRepository(JpaPluginDao dao, ExtensionDownloader extensionDownloader, EnvironmentInformation environment) {
this.dao = dao;
this.extensionDownloader = extensionDownloader;
this.environment = environment;
+ LOG.info("Execution environment: {} {}", environment.getKey(), environment.getVersion());
}
/**
@@ -133,7 +134,7 @@ public class BatchPluginRepository extends AbstractPluginRepository {
return true;
}
for (String supported : env.value()) {
- if (StringUtils.equalsIgnoreCase(environment.toString(), supported)) {
+ if (StringUtils.equalsIgnoreCase(environment.getKey(), supported)) {
return true;
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/EnvironmentInformation.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/EnvironmentInformation.java
new file mode 100644
index 00000000000..c3325e1ea96
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/EnvironmentInformation.java
@@ -0,0 +1,54 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.batch.bootstrapper;
+
+import org.sonar.api.BatchComponent;
+
+/**
+ * Describes execution environment.
+ *
+ * @since 2.6
+ */
+public class EnvironmentInformation implements BatchComponent {
+
+ private String key;
+ private String version;
+
+ public EnvironmentInformation(String key, String version) {
+ this.key = key;
+ this.version = version;
+ }
+
+ /**
+ * @return unique key of environment, for example - "maven", "ant"
+ */
+ public String getKey() {
+ return key;
+ }
+
+ /**
+ * @return version of environment, for example Maven can have "2.2.1" or "3.0.2",
+ * but there is no guarantees about format - it's just a string.
+ */
+ public String getVersion() {
+ return version;
+ }
+
+}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/ProjectDefinition.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/ProjectDefinition.java
index f660f7a83e2..b632feb60ac 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/ProjectDefinition.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/ProjectDefinition.java
@@ -19,16 +19,15 @@
*/
package org.sonar.batch.bootstrapper;
-import com.google.common.collect.Lists;
-
import java.io.File;
import java.util.List;
import java.util.Properties;
+import com.google.common.collect.Lists;
+
/**
- * Defines project in a form suitable to bootstrap Sonar batch.
+ * Describes project in a form suitable to bootstrap Sonar batch.
* We assume that project is just a set of configuration properties and directories.
- * This is a part of bootstrap process, so we should take care about backward compatibility.
*
* @since 2.6
*/
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Reactor.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Reactor.java
index c2e4472be33..2df674053f9 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Reactor.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Reactor.java
@@ -19,13 +19,11 @@
*/
package org.sonar.batch.bootstrapper;
-
import java.util.Collections;
import java.util.List;
/**
- * Defines order of projects.
- * This is a part of bootstrap process, so we should take care about backward compatibility.
+ * Describes order of projects.
*
* @since 2.6
*/
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/platform/Environment.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/package-info.java
index 57d36283fe9..d9a22ffcdf0 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/platform/Environment.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/package-info.java
@@ -17,34 +17,9 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.api.platform;
-
-import org.sonar.api.BatchComponent;
-import org.sonar.api.ServerComponent;
/**
- * @since 2.2
+ * This package is a part of bootstrap process, so we should take care about backward compatibility.
*/
-public enum Environment implements BatchComponent, ServerComponent {
-
- /*
- * When will GRADLE, ANT, ECLIPSE, INTELLIJ_IDEA be added to this list ? :-)
- */
- SERVER, MAVEN3, MAVEN2, ANT;
-
- public boolean isServer() {
- return this==SERVER;
- }
-
- public boolean isMaven2Batch() {
- return this==MAVEN2;
- }
-
- public boolean isMaven3Batch() {
- return this==MAVEN3;
- }
+package org.sonar.batch.bootstrapper;
- public boolean isBatch() {
- return isMaven2Batch() || isMaven3Batch();
- }
-}
diff --git a/sonar-core-maven-plugin/src/main/java/org/sonar/maven2/BatchMojo.java b/sonar-core-maven-plugin/src/main/java/org/sonar/maven2/BatchMojo.java
index cbb50901388..075dfe9110a 100644
--- a/sonar-core-maven-plugin/src/main/java/org/sonar/maven2/BatchMojo.java
+++ b/sonar-core-maven-plugin/src/main/java/org/sonar/maven2/BatchMojo.java
@@ -19,7 +19,7 @@
*/
package org.sonar.maven2;
-import org.sonar.batch.MavenReactor;
+import java.io.InputStream;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
@@ -31,6 +31,7 @@ import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactCollector;
import org.apache.maven.execution.MavenSession;
+import org.apache.maven.execution.RuntimeInformation;
import org.apache.maven.lifecycle.LifecycleExecutor;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
@@ -40,10 +41,9 @@ import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder;
import org.slf4j.LoggerFactory;
-import org.sonar.api.platform.Environment;
import org.sonar.batch.Batch;
-
-import java.io.InputStream;
+import org.sonar.batch.MavenReactor;
+import org.sonar.batch.bootstrapper.EnvironmentInformation;
/**
* @goal internal
@@ -80,7 +80,7 @@ public final class BatchMojo extends AbstractMojo {
/**
* The artifact factory to use.
- *
+ *
* @component
* @required
* @readonly
@@ -89,7 +89,7 @@ public final class BatchMojo extends AbstractMojo {
/**
* The artifact repository to use.
- *
+ *
* @parameter expression="${localRepository}"
* @required
* @readonly
@@ -98,7 +98,7 @@ public final class BatchMojo extends AbstractMojo {
/**
* The artifact metadata source to use.
- *
+ *
* @component
* @required
* @readonly
@@ -107,7 +107,7 @@ public final class BatchMojo extends AbstractMojo {
/**
* The artifact collector to use.
- *
+ *
* @component
* @required
* @readonly
@@ -116,7 +116,7 @@ public final class BatchMojo extends AbstractMojo {
/**
* The dependency tree builder to use.
- *
+ *
* @component
* @required
* @readonly
@@ -130,21 +130,32 @@ public final class BatchMojo extends AbstractMojo {
*/
private MavenProjectBuilder projectBuilder;
+ /**
+ * @component
+ * @required
+ * @readonly
+ */
+ private RuntimeInformation runtimeInformation;
+
public void execute() throws MojoExecutionException, MojoFailureException {
initLogging();
executeBatch();
}
-
private void executeBatch() throws MojoExecutionException {
MavenReactor reactor = new MavenReactor(session);
Batch batch = new Batch(getInitialConfiguration(), reactor, session, project,
getLog(), lifecycleExecutor, pluginManager, artifactFactory,
localRepository, artifactMetadataSource, artifactCollector,
- dependencyTreeBuilder, projectBuilder, Environment.MAVEN2, Maven2PluginExecutor.class);
+ dependencyTreeBuilder, projectBuilder, getEnvironmentInformation(), Maven2PluginExecutor.class);
batch.execute();
}
+ private EnvironmentInformation getEnvironmentInformation() {
+ String mavenVersion = runtimeInformation.getApplicationVersion().toString();
+ return new EnvironmentInformation("Maven", mavenVersion);
+ }
+
private Configuration getInitialConfiguration() {
CompositeConfiguration configuration = new CompositeConfiguration();
configuration.addConfiguration(new SystemConfiguration());
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 e78939fc39b..ab0123210f5 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,6 +19,8 @@
*/
package org.sonar.maven;
+import java.io.InputStream;
+
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.joran.spi.JoranException;
@@ -29,6 +31,7 @@ import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactCollector;
import org.apache.maven.execution.MavenSession;
+import org.apache.maven.execution.RuntimeInformation;
import org.apache.maven.lifecycle.LifecycleExecutor;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
@@ -38,11 +41,9 @@ import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder;
import org.slf4j.LoggerFactory;
-import org.sonar.api.platform.Environment;
import org.sonar.batch.Batch;
import org.sonar.batch.MavenReactor;
-
-import java.io.InputStream;
+import org.sonar.batch.bootstrapper.EnvironmentInformation;
/**
* @goal sonar
@@ -129,6 +130,13 @@ public final class SonarMojo extends AbstractMojo {
*/
private MavenProjectBuilder projectBuilder;
+ /**
+ * @component
+ * @required
+ * @readonly
+ */
+ private RuntimeInformation runtimeInformation;
+
public void execute() throws MojoExecutionException, MojoFailureException {
initLogging();
executeBatch();
@@ -139,10 +147,15 @@ public final class SonarMojo extends AbstractMojo {
Batch batch = new Batch(getInitialConfiguration(),
reactor, session, project, getLog(), lifecycleExecutor, pluginManager, artifactFactory,
localRepository, artifactMetadataSource, artifactCollector, dependencyTreeBuilder,
- projectBuilder, Environment.MAVEN2, Maven2PluginExecutor.class);
+ projectBuilder, getEnvironmentInformation(), Maven2PluginExecutor.class);
batch.execute();
}
+ private EnvironmentInformation getEnvironmentInformation() {
+ String mavenVersion = runtimeInformation.getApplicationVersion().toString();
+ return new EnvironmentInformation("Maven", mavenVersion);
+ }
+
private void initLogging() throws MojoExecutionException {
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
JoranConfigurator jc = new JoranConfigurator();
diff --git a/sonar-maven3-plugin/pom.xml b/sonar-maven3-plugin/pom.xml
index 020128773a8..5ccb6c95fa7 100644
--- a/sonar-maven3-plugin/pom.xml
+++ b/sonar-maven3-plugin/pom.xml
@@ -47,6 +47,12 @@
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
+ <artifactId>maven-compat</artifactId>
+ <version>${maven.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
<artifactId>maven-settings</artifactId>
<version>${maven.version}</version>
<scope>provided</scope>
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 058bc886253..baca606b874 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,6 +19,8 @@
*/
package org.sonar.maven3;
+import java.io.InputStream;
+
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.joran.spi.JoranException;
@@ -29,6 +31,7 @@ import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactCollector;
import org.apache.maven.execution.MavenSession;
+import org.apache.maven.execution.RuntimeInformation;
import org.apache.maven.lifecycle.LifecycleExecutor;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
@@ -37,11 +40,9 @@ import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder;
import org.slf4j.LoggerFactory;
-import org.sonar.api.platform.Environment;
import org.sonar.batch.Batch;
import org.sonar.batch.MavenReactor;
-
-import java.io.InputStream;
+import org.sonar.batch.bootstrapper.EnvironmentInformation;
/**
* @goal sonar
@@ -122,6 +123,13 @@ public final class SonarMojo extends AbstractMojo {
*/
private MavenProjectBuilder projectBuilder;
+ /**
+ * @component
+ * @required
+ * @readonly
+ */
+ private RuntimeInformation runtimeInformation;
+
public void execute() throws MojoExecutionException, MojoFailureException {
initLogging();
executeBatch();
@@ -132,10 +140,15 @@ public final class SonarMojo extends AbstractMojo {
Batch batch = new Batch(getInitialConfiguration(),
reactor, session, project, getLog(), lifecycleExecutor, artifactFactory,
localRepository, artifactMetadataSource, artifactCollector, dependencyTreeBuilder,
- projectBuilder, Environment.MAVEN3, Maven3PluginExecutor.class);
+ projectBuilder, getEnvironmentInformation(), Maven3PluginExecutor.class);
batch.execute();
}
+ private EnvironmentInformation getEnvironmentInformation() {
+ String mavenVersion = runtimeInformation.getApplicationVersion().toString();
+ return new EnvironmentInformation("Maven", mavenVersion);
+ }
+
private void initLogging() throws MojoExecutionException {
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
JoranConfigurator jc = new JoranConfigurator();
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/platform/EnvironmentTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/platform/EnvironmentTest.java
deleted file mode 100644
index 81ecf2389c4..00000000000
--- a/sonar-plugin-api/src/test/java/org/sonar/api/platform/EnvironmentTest.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.api.platform;
-
-import org.junit.Test;
-
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
-
-public class EnvironmentTest {
-
- @Test
- public void testMaven2() {
- assertThat(Environment.MAVEN2.isBatch(), is(true));
- assertThat(Environment.MAVEN2.isMaven2Batch(), is(true));
- assertThat(Environment.MAVEN2.isMaven3Batch(), is(false));
- assertThat(Environment.MAVEN2.isServer(), is(false));
- }
-
- @Test
- public void testMaven3() {
- assertThat(Environment.MAVEN3.isBatch(), is(true));
- assertThat(Environment.MAVEN3.isMaven2Batch(), is(false));
- assertThat(Environment.MAVEN3.isMaven3Batch(), is(true));
- assertThat(Environment.MAVEN3.isServer(), is(false));
- }
-
- @Test
- public void testServer() {
- assertThat(Environment.SERVER.isBatch(), is(false));
- assertThat(Environment.SERVER.isMaven2Batch(), is(false));
- assertThat(Environment.SERVER.isMaven3Batch(), is(false));
- assertThat(Environment.SERVER.isServer(), is(true));
- }
-}
diff --git a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
index aaa69ba8047..53c6ab24b4a 100644
--- a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
+++ b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
@@ -26,7 +26,6 @@ import org.picocontainer.MutablePicoContainer;
import org.slf4j.LoggerFactory;
import org.sonar.api.Plugins;
import org.sonar.api.database.configuration.DatabaseConfiguration;
-import org.sonar.api.platform.Environment;
import org.sonar.api.platform.Server;
import org.sonar.api.profiles.AnnotationProfileParser;
import org.sonar.api.profiles.XMLProfileParser;
@@ -126,7 +125,6 @@ public final class Platform {
private void startCoreComponents() {
coreContainer = rootContainer.makeChildContainer();
- coreContainer.as(Characteristics.CACHE).addComponent(Environment.SERVER);
coreContainer.as(Characteristics.CACHE).addComponent(PluginClassLoaders.class);
coreContainer.as(Characteristics.CACHE).addComponent(PluginDeployer.class);
coreContainer.as(Characteristics.CACHE).addComponent(ServerImpl.class);