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;
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;
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());
}
/**
return true;
}
for (String supported : env.value()) {
- if (StringUtils.equalsIgnoreCase(environment.toString(), supported)) {
+ if (StringUtils.equalsIgnoreCase(environment.getKey(), supported)) {
return true;
}
}
--- /dev/null
+/*
+ * 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;
+ }
+
+}
*/
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
*/
*/
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
*/
--- /dev/null
+/*
+ * 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
+ */
+
+/**
+ * This package is a part of bootstrap process, so we should take care about backward compatibility.
+ */
+package org.sonar.batch.bootstrapper;
+
*/
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;
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;
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
/**
* The artifact factory to use.
- *
+ *
* @component
* @required
* @readonly
/**
* The artifact repository to use.
- *
+ *
* @parameter expression="${localRepository}"
* @required
* @readonly
/**
* The artifact metadata source to use.
- *
+ *
* @component
* @required
* @readonly
/**
* The artifact collector to use.
- *
+ *
* @component
* @required
* @readonly
/**
* The dependency tree builder to use.
- *
+ *
* @component
* @required
* @readonly
*/
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());
*/
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;
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;
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
*/
private MavenProjectBuilder projectBuilder;
+ /**
+ * @component
+ * @required
+ * @readonly
+ */
+ private RuntimeInformation runtimeInformation;
+
public void execute() throws MojoExecutionException, MojoFailureException {
initLogging();
executeBatch();
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();
<version>${maven.version}</version>
<scope>provided</scope>
</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>
*/
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;
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;
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
*/
private MavenProjectBuilder projectBuilder;
+ /**
+ * @component
+ * @required
+ * @readonly
+ */
+ private RuntimeInformation runtimeInformation;
+
public void execute() throws MojoExecutionException, MojoFailureException {
initLogging();
executeBatch();
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();
+++ /dev/null
-/*
- * 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.sonar.api.BatchComponent;
-import org.sonar.api.ServerComponent;
-
-/**
- * @since 2.2
- */
-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;
- }
-
- public boolean isBatch() {
- return isMaven2Batch() || isMaven3Batch();
- }
-}
+++ /dev/null
-/*
- * 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));
- }
-}
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;
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);