Author: rfscholte
Date: Mon Feb 25 21:32:21 2013
New Revision: 1449907

URL: http://svn.apache.org/r1449907
Log:
[MINVOKER-151] Add failIfNoProjects

Added:
    
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-noprojects_integration-test/
    
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-noprojects_integration-test/pom.xml
    maven/plugins/trunk/maven-invoker-plugin/src/it/fail-noprojects_run/
    
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-noprojects_run/invoker.properties
    maven/plugins/trunk/maven-invoker-plugin/src/it/fail-noprojects_run/pom.xml
    maven/plugins/trunk/maven-invoker-plugin/src/it/fail-noprojects_verify/
    
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-noprojects_verify/invoker.properties
    
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-noprojects_verify/pom.xml
Modified:
    
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java
    
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java
    
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/VerifyMojo.java

Added: 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-noprojects_integration-test/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/fail-noprojects_integration-test/pom.xml?rev=1449907&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-noprojects_integration-test/pom.xml
 (added)
+++ 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-noprojects_integration-test/pom.xml
 Mon Feb 25 21:32:21 2013
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<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/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.invoker</groupId>
+  <artifactId>fail-noprojects_integration-test</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <description>Test to check that the build succeeds during integration-test 
even if there are no projects</description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-invoker-plugin</artifactId>
+        <version>@pom.version@</version>
+        <configuration>
+          <failIfNoProjects>true</failIfNoProjects>
+          <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
+          <goals>
+            <goal>validate</goal>
+          </goals>
+        </configuration>
+        <executions>
+          <execution>
+            <id>integration-test</id>
+            <phase>initialize</phase>
+            <goals>
+              <goal>integration-test</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>

Added: 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-noprojects_run/invoker.properties
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/fail-noprojects_run/invoker.properties?rev=1449907&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-noprojects_run/invoker.properties
 (added)
+++ 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-noprojects_run/invoker.properties
 Mon Feb 25 21:32:21 2013
@@ -0,0 +1 @@
+invoker.buildResult = failure

Added: 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-noprojects_run/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/fail-noprojects_run/pom.xml?rev=1449907&view=auto
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/it/fail-noprojects_run/pom.xml 
(added)
+++ maven/plugins/trunk/maven-invoker-plugin/src/it/fail-noprojects_run/pom.xml 
Mon Feb 25 21:32:21 2013
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<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/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.invoker</groupId>
+  <artifactId>fail-noprojects_run</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <description>Test to check that the build fails if there are no 
projects</description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-invoker-plugin</artifactId>
+        <version>@pom.version@</version>
+        <configuration>
+          <failIfNoProjects>true</failIfNoProjects>
+          <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
+          <goals>
+            <goal>validate</goal>
+          </goals>
+        </configuration>
+        <executions>
+          <execution>
+            <id>integration-test</id>
+            <phase>initialize</phase>
+            <goals>
+              <goal>run</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>

Added: 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-noprojects_verify/invoker.properties
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/fail-noprojects_verify/invoker.properties?rev=1449907&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-noprojects_verify/invoker.properties
 (added)
+++ 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-noprojects_verify/invoker.properties
 Mon Feb 25 21:32:21 2013
@@ -0,0 +1 @@
+invoker.buildResult = failure

Added: 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-noprojects_verify/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/fail-noprojects_verify/pom.xml?rev=1449907&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-noprojects_verify/pom.xml 
(added)
+++ 
maven/plugins/trunk/maven-invoker-plugin/src/it/fail-noprojects_verify/pom.xml 
Mon Feb 25 21:32:21 2013
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<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/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.invoker</groupId>
+  <artifactId>fail-noprojects_verify</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <description>Test to check that the build fails if there are no 
projects</description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-invoker-plugin</artifactId>
+        <version>@pom.version@</version>
+        <configuration>
+          <failIfNoProjects>true</failIfNoProjects>
+          <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
+          <goals>
+            <goal>validate</goal>
+          </goals>
+        </configuration>
+        <executions>
+          <execution>
+            <id>integration-test</id>
+            <phase>initialize</phase>
+            <goals>
+              <goal>integration-test</goal>
+              <goal>verify</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>

Modified: 
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java?rev=1449907&r1=1449906&r2=1449907&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java
 Mon Feb 25 21:32:21 2013
@@ -682,6 +682,8 @@ public abstract class AbstractInvokerMoj
 
         if ( ( buildJobs == null ) || ( buildJobs.length < 1 ) )
         {
+            doFailIfNoProjects();
+
             getLog().info( "No projects were selected for execution." );
             return;
         }
@@ -740,6 +742,12 @@ public abstract class AbstractInvokerMoj
         processResults( new InvokerSession( buildJobs ) );
     }
 
+    
+    protected void doFailIfNoProjects() throws MojoFailureException
+    {
+        // should only be used during run and verify
+    }
+
     /**
      * Processes the results of invoking the build jobs.
      *

Modified: 
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java?rev=1449907&r1=1449906&r2=1449907&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java
 Mon Feb 25 21:32:21 2013
@@ -50,6 +50,14 @@ public class InvokerMojo
     @Parameter( property = "maven.test.failure.ignore", defaultValue = "false" 
)
     private boolean ignoreFailures;
 
+    /**
+     * Set this to <code>true</code> to cause a failure if there are no 
projects to invoke.
+     *
+     * @since 1.9
+     */
+    @Parameter( property = "invoker.failIfNoProjects" )
+    private Boolean failIfNoProjects;
+    
     void processResults( InvokerSession invokerSession )
         throws MojoFailureException
     {
@@ -60,5 +68,15 @@ public class InvokerMojo
 
         invokerSession.handleFailures( getLog(), ignoreFailures );
     }
+    
+    @Override
+    protected void doFailIfNoProjects()
+        throws MojoFailureException
+    {
+        if( Boolean.TRUE.equals( failIfNoProjects ) )
+        {
+            throw new MojoFailureException( "No projects to invoke!" );
+        }
+    }
 
 }

Modified: 
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/VerifyMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/VerifyMojo.java?rev=1449907&r1=1449906&r2=1449907&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/VerifyMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/VerifyMojo.java
 Mon Feb 25 21:32:21 2013
@@ -75,6 +75,14 @@ public class VerifyMojo
      */
     @Parameter( defaultValue = "false" )
     private boolean suppressSummaries;
+    
+    /**
+     * Set this to <code>true</code> to cause a failure if there are no 
projects to invoke.
+     *
+     * @since 1.9
+     */
+    @Parameter( property = "invoker.failIfNoProjects" )
+    private Boolean failIfNoProjects;
 
     /**
      * Invokes Maven on the configured test projects.
@@ -95,6 +103,10 @@ public class VerifyMojo
         File[] reportFiles = ReportUtils.getReportFiles( reportsDirectory );
         if ( reportFiles.length <= 0 )
         {
+            if ( Boolean.TRUE.equals( failIfNoProjects ) )
+            {
+                throw new MojoFailureException( "No projects to invoke!" );
+            }
             getLog().info( "No invoker report files found, nothing to check." 
);
             return;
         }


Reply via email to