]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4493 End of support of Maven 2.0 and 2.1
authorJulien HENRY <julien.henry@sonarsource.com>
Mon, 15 Jul 2013 14:17:21 +0000 (16:17 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Mon, 15 Jul 2013 14:17:46 +0000 (16:17 +0200)
sonar-maven-plugin/pom.xml
sonar-maven-plugin/src/main/java/org/sonar/maven/SonarMojo.java
sonar-maven-plugin/src/test/java/org/sonar/maven/SonarMojoTest.java [new file with mode: 0644]

index f4cdd7cd1a1614068df0cdf2e06e3a8f452a9907..8b7e3a38d26086575f57f31eb1454401d7e555b8 100644 (file)
       <artifactId>maven-project</artifactId>
       <scope>provided</scope>
     </dependency>
+
+    <!-- Test -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-all</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.easytesting</groupId>
+      <artifactId>fest-assert</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 </project>
index dc1c764a51e4a87cd6062fbecdf2c57753e9eee8..14213720c231bddded940d5d510f4ced02c8cdf4 100644 (file)
@@ -23,6 +23,7 @@ import org.apache.maven.artifact.factory.ArtifactFactory;
 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.artifact.versioning.ArtifactVersion;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.execution.RuntimeInformation;
 import org.apache.maven.lifecycle.LifecycleExecutor;
@@ -122,13 +123,18 @@ public final class SonarMojo extends AbstractMojo {
    * @component
    * @required
    * @readonly
+   * @VisibleForTesting
    */
-  private RuntimeInformation runtimeInformation;
+  RuntimeInformation runtimeInformation;
 
   public void execute() throws MojoExecutionException, MojoFailureException {
+    ArtifactVersion mavenVersion = getMavenVersion();
+    if (mavenVersion.getMajorVersion() == 2 && mavenVersion.getMinorVersion() < 2) {
+      throw new MojoExecutionException("Please use at least Maven 2.2.x to perform SonarQube analysis (current version is " + mavenVersion.toString() + ")");
+    }
 
     EmbeddedRunner runner = EmbeddedRunner.create()
-        .setApp("Maven", getMavenVersion())
+        .setApp("Maven", mavenVersion.toString())
         .addProperties(session.getExecutionProperties())
         .addProperties(project.getModel().getProperties())
         // Add user properties (ie command line arguments -Dsonar.xxx=yyyy) in last position to override all other
@@ -159,15 +165,15 @@ public final class SonarMojo extends AbstractMojo {
         // Include everything else
         .unmask("");
     runner.addExtensions(session, getLog(), lifecycleExecutor, artifactFactory, localRepository, artifactMetadataSource, artifactCollector,
-            dependencyTreeBuilder, projectBuilder);
+        dependencyTreeBuilder, projectBuilder);
     if (getLog().isDebugEnabled()) {
       runner.setProperty("sonar.verbose", "true");
     }
     runner.execute();
   }
 
-  private String getMavenVersion() {
-    return runtimeInformation.getApplicationVersion().toString();
+  private ArtifactVersion getMavenVersion() {
+    return runtimeInformation.getApplicationVersion();
   }
 
   public static String toString(Object obj) {
diff --git a/sonar-maven-plugin/src/test/java/org/sonar/maven/SonarMojoTest.java b/sonar-maven-plugin/src/test/java/org/sonar/maven/SonarMojoTest.java
new file mode 100644 (file)
index 0000000..83a52b4
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.maven;
+
+import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
+import org.apache.maven.execution.RuntimeInformation;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class SonarMojoTest {
+
+  @Rule
+  public ExpectedException thrown = ExpectedException.none();
+
+  @Test
+  public void shouldFailWithOldMavenVersion() throws Exception {
+    SonarMojo mojo = new SonarMojo();
+    mojo.runtimeInformation = mock(RuntimeInformation.class);
+    when(mojo.runtimeInformation.getApplicationVersion()).thenReturn(new DefaultArtifactVersion("2.0.11"));
+    thrown.expect(MojoExecutionException.class);
+    thrown.expectMessage("Please use at least Maven 2.2.x to perform SonarQube analysis (current version is 2.0.11)");
+    mojo.execute();
+  }
+}