]> source.dussan.org Git - sonarqube.git/commitdiff
Replace enum Environment by class EnvironmentInformation
authorEvgeny Mandrikov <mandrikov@gmail.com>
Fri, 4 Feb 2011 14:54:57 +0000 (17:54 +0300)
committerEvgeny Mandrikov <mandrikov@gmail.com>
Fri, 4 Feb 2011 16:48:41 +0000 (19:48 +0300)
* Each environment should provide key and version

* Plugins for Maven 2.x and Maven 3.x have same key "Maven"
  and provide a real version of Maven

13 files changed:
plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/batch/MavenDependenciesSensor.java
sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java
sonar-batch/src/main/java/org/sonar/batch/bootstrapper/EnvironmentInformation.java [new file with mode: 0644]
sonar-batch/src/main/java/org/sonar/batch/bootstrapper/ProjectDefinition.java
sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Reactor.java
sonar-batch/src/main/java/org/sonar/batch/bootstrapper/package-info.java [new file with mode: 0644]
sonar-core-maven-plugin/src/main/java/org/sonar/maven2/BatchMojo.java
sonar-maven-plugin/src/main/java/org/sonar/maven/SonarMojo.java
sonar-maven3-plugin/pom.xml
sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMojo.java
sonar-plugin-api/src/main/java/org/sonar/api/platform/Environment.java [deleted file]
sonar-plugin-api/src/test/java/org/sonar/api/platform/EnvironmentTest.java [deleted file]
sonar-server/src/main/java/org/sonar/server/platform/Platform.java

index eb00b801d4c01580b6b9bab940217b7b8271289a..198340252c46ebef250a7094c0b2818115a6d3b8 100644 (file)
@@ -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;
index af4d177edb37bccf8c0dacf57bc1df2178f3a23b..5ec8ac920aef226da61174fc9809557f8a430eb3 100644 (file)
@@ -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 (file)
index 0000000..c3325e1
--- /dev/null
@@ -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;
+  }
+
+}
index f660f7a83e23f1adcb41892a41d2e9a00ebb9749..b632feb60ac63c9f7cf308c1380f3d53ef5e745f 100644 (file)
  */
 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
  */
index c2e4472be338a06e089e25461db6422f4292df16..2df674053f96ecfc9e5b763321b577b6289215a2 100644 (file)
  */
 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-batch/src/main/java/org/sonar/batch/bootstrapper/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/package-info.java
new file mode 100644 (file)
index 0000000..d9a22ff
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * 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;
+
index cbb50901388044b529e5a1297b81a31a22524b4b..075dfe9110a541bae1725dab269b744592f30525 100644 (file)
@@ -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());
index e78939fc39b3e09b058af3efa1e1dbc71ab9151d..ab0123210f5aa56290ca64e04978aeb01a678e2b 100644 (file)
@@ -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();
index 020128773a839b55440397841eefc172bf8cd959..5ccb6c95fa7f8321ec73d1aa8889f4bc56feb40d 100644 (file)
       <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>
index 058bc88625342de63e5eb130a136e4d1c725e1c1..baca606b8746173ae6db55a6200c34c28a51c2ea 100644 (file)
@@ -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/main/java/org/sonar/api/platform/Environment.java b/sonar-plugin-api/src/main/java/org/sonar/api/platform/Environment.java
deleted file mode 100644 (file)
index 57d3628..0000000
+++ /dev/null
@@ -1,50 +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.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();
-  }
-}
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 (file)
index 81ecf23..0000000
+++ /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));
-  }
-}
index aaa69ba804753ffd1245b1554d0815aaef4beea2..53c6ab24b4a776c8c652c847c47cb3a597fe66c6 100644 (file)
@@ -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);