Hi,

why so complicated?
No need to use System.getProperty().
No need for setters.

Robert


On Wed, 17 Jul 2013 19:53:14 +0200, <[email protected]> wrote:

Revision:

18547
Author:

jieryn
Date:

2013-07-17 12:53:14 -0500 (Wed, 17 Jul 2013)

Log Message

[FIXED MBUILDNUM-103] provide a way to skip mojo execution

Modified Paths

trunk/mojo/buildnumber-maven-plugin/src/main/java/org/codehaus/mojo/build/CreateMojo.java

trunk/mojo/buildnumber-maven-plugin/src/main/java/org/codehaus/mojo/build/CreateTimestampMojo.java

trunk/mojo/buildnumber-maven-plugin/src/main/java/org/codehaus/mojo/build/HgChangeSetMojo.java

Added Paths

trunk/mojo/buildnumber-maven-plugin/src/it/skip-it/

trunk/mojo/buildnumber-maven-plugin/src/it/skip-it/goals.txt

trunk/mojo/buildnumber-maven-plugin/src/it/skip-it/pom.xml

trunk/mojo/buildnumber-maven-plugin/src/it/skip-it/verify.bsh

Diff

Property changes: trunk/mojo/buildnumber-maven-plugin/src/it/skip-it



Added: svn:ignore

target

Added: trunk/mojo/buildnumber-maven-plugin/src/it/skip-it/goals.txt (0 => 18547)



--- trunk/mojo/buildnumber-maven-plugin/src/it/skip-it/goals.txt                
                        (rev 0)
+++ trunk/mojo/buildnumber-maven-plugin/src/it/skip-it/goals.txt 2013-07-17 17:53:14 UTC (rev 18547)

@@ -0,0 +1 @@

+package

Added: trunk/mojo/buildnumber-maven-plugin/src/it/skip-it/pom.xml (0 => 18547)



--- trunk/mojo/buildnumber-maven-plugin/src/it/skip-it/pom.xml          
                        (rev 0)
+++ trunk/mojo/buildnumber-maven-plugin/src/it/skip-it/pom.xml 2013-07-17 17:53:14 UTC (rev 18547)

@@ -0,0 +1,54 @@

+<?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>
+
+  <groupId>org.codehaus.mojo.it</groupId>
+  <artifactId>buildnumber-maven-plugin-create-timestamp-it</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <build>
+
+    <defaultGoal>package</defaultGoal>
+
+    <plugins>
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>buildnumber-maven-plugin</artifactId>
+        <version>@pom.version@</version>
+        <executions>
+          <execution>
+            <id>useLastCommittedRevision</id>
+            <goals>
+              <goal>create-timestamp</goal>
+            </goals>
+            <configuration>
+              <skip>true</skip>
+              <timestampPropertyName>datetime</timestampPropertyName>
+              <timestampFormat>yyyy-MM-dd hh:mm:ss</timestampFormat>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <configuration>
+          <archive>
+            <manifest>
+              <addClasspath>true</addClasspath>
+ <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries> + <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
+            </manifest>
+            <manifestEntries>
+              <Build-Time>${datetime}</Build-Time>
+            </manifestEntries>
+          </archive>
+        </configuration>
+      </plugin>
+    </plugins>
+
+  </build>
+
+</project>

Added: trunk/mojo/buildnumber-maven-plugin/src/it/skip-it/verify.bsh (0 => 18547)



--- trunk/mojo/buildnumber-maven-plugin/src/it/skip-it/verify.bsh               
                        (rev 0)
+++ trunk/mojo/buildnumber-maven-plugin/src/it/skip-it/verify.bsh 2013-07-17 17:53:14 UTC (rev 18547)

@@ -0,0 +1,70 @@

+
+/*
+ * 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.
+ */
+
+import java.io.*;
+import java.util.*;
+import java.util.jar.*;
+import java.text.*;
+import org.codehaus.plexus.util.*;
+
+boolean result = true;
+
+try
+{
+    File target = new File( basedir, "target" );
+    if ( !target.exists() || !target.isDirectory() )
+    {
+ System.err.println( "target file is missing or not a directory." );
+        return false;
+    }
+
+ File artifact = new File ( target, "buildnumber-maven-plugin-create-timestamp-it-1.0-SNAPSHOT.jar" );
+    if ( !artifact.exists() || artifact.isDirectory() )
+    {
+ System.err.println( "artifact file is missing or a directory." );
+        return false;
+    }
+
+    JarFile jar = new JarFile( artifact );
+
+    Attributes manifest = jar.getManifest().getMainAttributes();
+
+    if ( manifest.get( new Attributes.Name( "Build-Time" ) ) == null )
+    {
+ System.err.println( "Could not find manifest entry Build-Time" );
+        return false;
+    }
+
+ String timestamp = manifest.get( new Attributes.Name( "Build-Time" ) );
+
+    if ( timestamp != null && !"".equals(timestamp.trim()) )
+    {
+ System.err.println( "The manifest entry Build-Time should have been null/empty" );
+        System.err.println( "Build-Time ='" + timestamp + "'" );
+        return false;
+    }
+}
+catch( Throwable e )
+{
+    e.printStackTrace();
+    result = false;
+}
+
+return result;

Modified: trunk/mojo/buildnumber-maven-plugin/src/main/java/org/codehaus/mojo/build/CreateMojo.java
(18546 => 18547)



--- trunk/mojo/buildnumber-maven-plugin/src/main/java/org/codehaus/mojo/build/CreateMojo.java
2013-07-17 13:03:10 UTC (rev 18546)
+++ trunk/mojo/buildnumber-maven-plugin/src/main/java/org/codehaus/mojo/build/CreateMojo.java
2013-07-17 17:53:14 UTC (rev 18547)

@@ -282,6 +282,14 @@

      */

     private String scmBranchPropertyName;


+    /**
+     * Whether to skip this execution.
+     *
+     * @parameter expression="${maven.buildNumber.skip}"
+     * default-value="false"
+     * @since 1.3
+     */
+    private boolean skip;


     /**

      * @parameter expression="${session}"

@@ -312,6 +320,12 @@

     public void execute()

         throws MojoExecutionException, MojoFailureException

     {

+        if ( skip )
+        {
+            getLog().info("Skipping execution.");
+            return;
+        }
+

         if ( providerImplementations != null )

         {

for ( Entry<String, String> entry : providerImplementations.entrySet() )

@@ -921,4 +935,18 @@

     {

         this.shortRevisionLength = shortRevision;

     }

+
+    public void setSkip( boolean skip )
+    {
+ String skipSystemProperty = System.getProperty( "maven.buildNumber.skip" );
+        if ( skipSystemProperty != null )
+        {
+            // well, this gets the final say
+ this.skip = Boolean.valueOf( skipSystemProperty ).booleanValue();
+        }
+        else
+        {
+            this.skip = skip;
+        }
+    }

 }

Modified: trunk/mojo/buildnumber-maven-plugin/src/main/java/org/codehaus/mojo/build/CreateTimestampMojo.java
(18546 => 18547)



--- trunk/mojo/buildnumber-maven-plugin/src/main/java/org/codehaus/mojo/build/CreateTimestampMojo.java
2013-07-17 13:03:10 UTC (rev 18546)
+++ trunk/mojo/buildnumber-maven-plugin/src/main/java/org/codehaus/mojo/build/CreateTimestampMojo.java
2013-07-17 17:53:14 UTC (rev 18547)

@@ -44,6 +44,14 @@

 public class CreateTimestampMojo

     extends AbstractMojo

 {

+    /**
+     * Whether to skip this execution.
+     *
+     * @parameter expression="${maven.buildNumber.skip}"
+     * default-value="false"
+     * @since 1.3
+     */
+    private boolean skip;


     /**

      * The maven project.

@@ -78,6 +86,12 @@


     public void execute()

     {

+        if ( skip )
+        {
+            getLog().info("Skipping execution.");
+            return;
+        }
+

String timestampString = project.getProperties().getProperty( timestampPropertyName );


         // Check if the plugin has already run in the current build.

@@ -111,4 +125,17 @@


     }


+    public void setSkip( boolean skip )
+    {
+ String skipSystemProperty = System.getProperty( "maven.buildNumber.skip" );
+        if ( skipSystemProperty != null )
+        {
+            // well, this gets the final say
+ this.skip = Boolean.valueOf( skipSystemProperty ).booleanValue();
+        }
+        else
+        {
+            this.skip = skip;
+        }
+    }

 }

Modified: trunk/mojo/buildnumber-maven-plugin/src/main/java/org/codehaus/mojo/build/HgChangeSetMojo.java
(18546 => 18547)



--- trunk/mojo/buildnumber-maven-plugin/src/main/java/org/codehaus/mojo/build/HgChangeSetMojo.java
2013-07-17 13:03:10 UTC (rev 18546)
+++ trunk/mojo/buildnumber-maven-plugin/src/main/java/org/codehaus/mojo/build/HgChangeSetMojo.java
2013-07-17 17:53:14 UTC (rev 18547)

@@ -43,6 +43,14 @@

 public class HgChangeSetMojo

     extends AbstractMojo

 {

+    /**
+     * Whether to skip this execution.
+     *
+     * @parameter expression="${maven.buildNumber.skip}"
+     * default-value="false"
+     * @since 1.3
+     */
+    private boolean skip;


     private ScmLogDispatcher logger = new ScmLogDispatcher();


@@ -79,6 +87,12 @@

     public void execute()

         throws MojoExecutionException

     {

+        if ( skip )
+        {
+            getLog().info("Skipping execution.");
+            return;
+        }
+

         try

         {

             String previousChangeSet = getChangeSetProperty();

@@ -152,6 +166,20 @@

         }

     }


+    public void setSkip( boolean skip )
+    {
+ String skipSystemProperty = System.getProperty( "maven.buildNumber.skip" );
+        if ( skipSystemProperty != null )
+        {
+            // well, this gets the final say
+ this.skip = Boolean.valueOf( skipSystemProperty ).booleanValue();
+        }
+        else
+        {
+            this.skip = skip;
+        }
+    }
+

     private static class HgOutputConsumer

         extends HgConsumer

     {

To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email


--
Using Opera's revolutionary email client: http://www.opera.com/mail/

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email


Reply via email to