]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5705 Restore internal mojo to have clean failure
authorJulien HENRY <julien.henry@sonarsource.com>
Tue, 6 Jan 2015 10:40:39 +0000 (11:40 +0100)
committerJulien HENRY <julien.henry@sonarsource.com>
Tue, 6 Jan 2015 10:59:49 +0000 (11:59 +0100)
pom.xml
sonar-maven-plugin/pom.xml [new file with mode: 0644]
sonar-maven-plugin/src/main/java/org/sonar/maven/SonarMojo.java [new file with mode: 0644]
sonar-maven-plugin/src/test/java/org/sonar/maven/SonarMojoTest.java [new file with mode: 0644]
sonar-maven3-plugin/pom.xml [new file with mode: 0644]

diff --git a/pom.xml b/pom.xml
index 934f5957e83df2dae9feda111619fbae89130dc3..cae7627b5f35b79e6262a879aaeda46251ffb949 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -24,6 +24,8 @@
     <module>sonar-home</module>
     <module>sonar-java-api</module>
     <module>sonar-markdown</module>
+    <module>sonar-maven-plugin</module>
+    <module>sonar-maven3-plugin</module>
     <module>sonar-plugin-api</module>
     <module>server</module>
     <module>sonar-testing-harness</module>
diff --git a/sonar-maven-plugin/pom.xml b/sonar-maven-plugin/pom.xml
new file mode 100644 (file)
index 0000000..8d3efef
--- /dev/null
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.codehaus.sonar</groupId>
+    <artifactId>sonar</artifactId>
+    <version>5.0-SNAPSHOT</version>
+  </parent>
+  <artifactId>sonar-maven-plugin</artifactId>
+  <packaging>maven-plugin</packaging>
+  <name>SonarQube :: Maven2 Plugin</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-api</artifactId>
+      <version>2.2.0</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-artifact</artifactId>
+      <version>2.2.0</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-core</artifactId>
+      <version>2.2.0</version>
+      <scope>provided</scope>
+    </dependency>
+
+    <!-- Test -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.hamcrest</groupId>
+      <artifactId>hamcrest-all</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.easytesting</groupId>
+      <artifactId>fest-assert</artifactId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <skipTests>${skipBatchTests}</skipTests>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
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
new file mode 100644 (file)
index 0000000..aab0a41
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 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.ArtifactVersion;
+import org.apache.maven.execution.RuntimeInformation;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+
+/**
+ * @goal sonar
+ * @aggregator
+ */
+public final class SonarMojo extends AbstractMojo {
+
+  /**
+   * @component
+   * @required
+   * @readonly
+   * @VisibleForTesting
+   */
+  RuntimeInformation runtimeInformation;
+
+  @Override
+  public void execute() throws MojoExecutionException {
+    ArtifactVersion mavenVersion = getMavenVersion();
+    if (mavenVersion.getMajorVersion() < 3) {
+      throw new MojoExecutionException("Please use at least Maven 3.x to perform SonarQube analysis");
+    }
+    throw new MojoExecutionException("Please update sonar-maven-plugin to at least version 2.3");
+  }
+
+  private ArtifactVersion getMavenVersion() {
+    return runtimeInformation.getApplicationVersion();
+  }
+
+}
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..eb8cc4d
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 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.ArtifactVersion;
+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;
+
+public class SonarMojoTest {
+
+  @Rule
+  public ExpectedException thrown = ExpectedException.none();
+
+  @Test
+  public void testFailureWithMaven2() throws MojoExecutionException {
+    SonarMojo mojo = new SonarMojo();
+    mojo.runtimeInformation = new RuntimeInformation() {
+
+      @Override
+      public ArtifactVersion getApplicationVersion() {
+        return new DefaultArtifactVersion("2.2.1");
+      }
+    };
+    thrown.expect(MojoExecutionException.class);
+    thrown.expectMessage("Please use at least Maven 3.x to perform SonarQube analysis");
+    mojo.execute();
+  }
+
+  @Test
+  public void testFailureWithMaven3() throws MojoExecutionException {
+    SonarMojo mojo = new SonarMojo();
+    mojo.runtimeInformation = new RuntimeInformation() {
+
+      @Override
+      public ArtifactVersion getApplicationVersion() {
+        return new DefaultArtifactVersion("3.0.5");
+      }
+    };
+    thrown.expect(MojoExecutionException.class);
+    thrown.expectMessage("Please update sonar-maven-plugin to at least version 2.3");
+    mojo.execute();
+  }
+
+}
diff --git a/sonar-maven3-plugin/pom.xml b/sonar-maven3-plugin/pom.xml
new file mode 100644 (file)
index 0000000..5863d5b
--- /dev/null
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.codehaus.sonar</groupId>
+    <artifactId>sonar</artifactId>
+    <version>5.0-SNAPSHOT</version>
+  </parent>
+  <artifactId>sonar-maven3-plugin</artifactId>
+  <packaging>pom</packaging>
+  <name>SonarQube :: Maven3 Plugin</name>
+  <!-- Since Sonar 3.7 there is no more difference between Maven 2 and Maven 3 so relocate to Maven 2 plugin to avoid duplication -->
+  <distributionManagement>
+    <relocation>
+      <artifactId>sonar-maven-plugin</artifactId>
+    </relocation>
+  </distributionManagement>
+
+</project>