maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From denn...@apache.org
Subject svn commit: r884563 - in /maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement: AbstractAnnouncementMojo.java AnnouncementMailMojo.java AnnouncementMojo.java
Date Thu, 26 Nov 2009 14:25:48 GMT
Author: dennisl
Date: Thu Nov 26 14:25:48 2009
New Revision: 884563

URL: http://svn.apache.org/viewvc?rev=884563&view=rev
Log:
[MCHANGES-145] Make it possible to run the announcement goals only once for a multi-module
project

Added:
    maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AbstractAnnouncementMojo.java
  (with props)
Modified:
    maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AnnouncementMailMojo.java
    maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AnnouncementMojo.java

Added: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AbstractAnnouncementMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AbstractAnnouncementMojo.java?rev=884563&view=auto
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AbstractAnnouncementMojo.java
(added)
+++ maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AbstractAnnouncementMojo.java
Thu Nov 26 14:25:48 2009
@@ -0,0 +1,63 @@
+package org.apache.maven.plugin.announcement;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.execution.MavenSession;
+
+/**
+ * Abstract superclass for announcement mojos.
+ *
+ * @version $Id$
+ * @since 2.3
+ */
+public abstract class AbstractAnnouncementMojo extends AbstractMojo {
+    /**
+     * The current project base directory.
+     *
+     * @parameter expression="${basedir}"
+     * @required
+     * @since 2.1
+     */
+    protected String basedir;
+
+    /**
+     * The Maven Session.
+     *
+     * @parameter expression="${session}"
+     * @readonly
+     * @required
+     * @since 2.3
+     */
+    protected MavenSession mavenSession;
+
+    /**
+     * This will cause the execution to be run only at the top of a given module
+     * tree. That is, run in the project contained in the same folder where the
+     * mvn execution was launched.
+     *
+     * @parameter expression="${announcement.runOnlyAtExecutionRoot}" default-value="false"
+     * @since 2.3
+     */
+    protected boolean runOnlyAtExecutionRoot;
+
+    /**
+     * Returns <code>true</code> if the current project is located at the
+     * Execution Root Directory (where mvn was launched).
+     *
+     * @return <code>true</code> if the current project is at the Execution Root
+     */
+    protected boolean isThisTheExecutionRoot()
+    {
+        getLog().debug( "Root Folder:" + mavenSession.getExecutionRootDirectory() );
+        getLog().debug( "Current Folder:" + basedir );
+        boolean result = mavenSession.getExecutionRootDirectory().equalsIgnoreCase( basedir.toString()
);
+        if ( result )
+        {
+            getLog().debug( "This is the execution root." );
+        }
+        else
+        {
+            getLog().debug( "This is NOT the execution root." );
+        }
+        return result;
+    }
+}

Propchange: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AbstractAnnouncementMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AbstractAnnouncementMojo.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author Id

Modified: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AnnouncementMailMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AnnouncementMailMojo.java?rev=884563&r1=884562&r2=884563&view=diff
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AnnouncementMailMojo.java
(original)
+++ maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AnnouncementMailMojo.java
Thu Nov 26 14:25:48 2009
@@ -27,7 +27,6 @@
 import java.util.List;
 
 import org.apache.maven.model.Developer;
-import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.announcement.mailsender.ProjectJavamailMailSender;
 import org.apache.maven.project.MavenProject;
@@ -46,7 +45,7 @@
  * @execute goal="announcement-generate"
  */
 public class AnnouncementMailMojo
-    extends AbstractMojo
+    extends AbstractAnnouncementMojo
 {
     //=========================================
     // announcement-mail goal fields
@@ -154,9 +153,9 @@
      * @required
      */
     private String template;
-    
+
     /**
-     * Mail content type to use. 
+     * Mail content type to use.
      * @parameter default-value="text/plain"
      * @required
      * @since 2.1
@@ -168,49 +167,57 @@
     public void execute()
         throws MojoExecutionException
     {
-        File templateFile = new File( templateOutputDirectory, template );
-       
-        ConsoleLogger logger = new ConsoleLogger( Logger.LEVEL_INFO, "base" );
-        
-        if ( getLog().isDebugEnabled() )
+        // Run only at the execution root
+        if ( runOnlyAtExecutionRoot && !isThisTheExecutionRoot() )
         {
-            logger.setThreshold( Logger.LEVEL_DEBUG );
+            getLog().info( "Skipping the announcement mail in this project because it's not
the Execution Root" );
         }
+        else
+        {
+            File templateFile = new File( templateOutputDirectory, template );
 
-        mailer.enableLogging( logger );
+            ConsoleLogger logger = new ConsoleLogger( Logger.LEVEL_INFO, "base" );
 
-        mailer.setSmtpHost( getSmtpHost() );
+            if ( getLog().isDebugEnabled() )
+            {
+                logger.setThreshold( Logger.LEVEL_DEBUG );
+            }
 
-        mailer.setSmtpPort( getSmtpPort() );
+            mailer.enableLogging( logger );
 
-        mailer.setSslMode( sslMode );
+            mailer.setSmtpHost( getSmtpHost() );
 
-        if ( username != null )
-        {
-            mailer.setUsername( username );
-        }
+            mailer.setSmtpPort( getSmtpPort() );
 
-        if ( password != null )
-        {
-            mailer.setPassword( password );
-        }
-        
-        mailer.initialize();
-        
-        if ( getLog().isDebugEnabled() )
-        {
-            getLog().debug( "fromDeveloperId: " + getFromDeveloperId() );
-        }
+            mailer.setSslMode( sslMode );
 
-        if ( templateFile.isFile() )
-        {
-            getLog().info( "Connecting to Host: " + getSmtpHost() + ":" + getSmtpPort() );
+            if ( username != null )
+            {
+                mailer.setUsername( username );
+            }
 
-            sendMessage();
-        }
-        else
-        {
-            throw new MojoExecutionException( "Announcement template " + templateFile + "
not found..." );
+            if ( password != null )
+            {
+                mailer.setPassword( password );
+            }
+
+            mailer.initialize();
+
+            if ( getLog().isDebugEnabled() )
+            {
+                getLog().debug( "fromDeveloperId: " + getFromDeveloperId() );
+            }
+
+            if ( templateFile.isFile() )
+            {
+                getLog().info( "Connecting to Host: " + getSmtpHost() + ":" + getSmtpPort()
);
+
+                sendMessage();
+            }
+            else
+            {
+                throw new MojoExecutionException( "Announcement template " + templateFile
+ " not found..." );
+            }
         }
     }
 
@@ -238,7 +245,7 @@
             mailMsg.setSubject( getSubject() );
             mailMsg.setContent( IOUtil.toString( readAnnouncement( templateFile ) ) );
             mailMsg.setContentType( this.mailContentType );
-            mailMsg.setFrom( fromAddress, fromName );            
+            mailMsg.setFrom( fromAddress, fromName );
             final Iterator it = getToAddresses().iterator();
             while ( it.hasNext() )
             {
@@ -248,7 +255,7 @@
 
             }
             mailer.send( mailMsg );
-            getLog().info( "Sent..." );            
+            getLog().info( "Sent..." );
         }
         catch ( IOException ioe )
         {

Modified: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AnnouncementMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AnnouncementMojo.java?rev=884563&r1=884562&r2=884563&view=diff
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AnnouncementMojo.java
(original)
+++ maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AnnouncementMojo.java
Thu Nov 26 14:25:48 2009
@@ -28,7 +28,6 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.changes.ChangesXML;
 import org.apache.maven.plugin.jira.JiraXML;
@@ -55,7 +54,7 @@
  * @version $Id$
  */
 public class AnnouncementMojo
-    extends AbstractMojo
+    extends AbstractAnnouncementMojo
 {
     private static final String SNAPSHOT_SUFFIX = "-SNAPSHOT";
 
@@ -173,15 +172,6 @@
      */
     private String templateDirectory;
 
-    /**
-     * The current project base directory.
-     *
-     * @parameter expression="${basedir}"
-     * @required
-     * @since 2.1
-     */
-    private String basedir;
-
     private ChangesXML xml;
 
     //=======================================//
@@ -313,35 +303,43 @@
     public void execute()
         throws MojoExecutionException
     {
-        if ( this.jiraMerge )
+        // Run only at the execution root
+        if ( runOnlyAtExecutionRoot && !isThisTheExecutionRoot() )
         {
-            ChangesXML changesXML =  new ChangesXML( getXmlPath(), getLog() );
-            List changesReleases = changesXML.getReleaseList();
-            List jiraReleases = getJiraReleases();
-            List mergedReleases = mergeReleases( changesReleases, jiraReleases );
-            doGenerate( mergedReleases );
+            getLog().info( "Skipping the announcement generation in this project because
it's not the Execution Root" );
         }
         else
         {
-            if ( !generateJiraAnnouncement )
+            if ( this.jiraMerge )
+            {
+                ChangesXML changesXML =  new ChangesXML( getXmlPath(), getLog() );
+                List changesReleases = changesXML.getReleaseList();
+                List jiraReleases = getJiraReleases();
+                List mergedReleases = mergeReleases( changesReleases, jiraReleases );
+                doGenerate( mergedReleases );
+            }
+            else
             {
-                if ( getXmlPath().exists() )
+                if ( !generateJiraAnnouncement )
                 {
-                    setXml( new ChangesXML( getXmlPath(), getLog() ) );
-
-                    getLog().info( "Creating announcement file from " + getXmlPath() + "..."
);
-
-                    doGenerate( getXml().getReleaseList() );
+                    if ( getXmlPath().exists() )
+                    {
+                        setXml( new ChangesXML( getXmlPath(), getLog() ) );
+
+                        getLog().info( "Creating announcement file from " + getXmlPath()
+ "..." );
+
+                        doGenerate( getXml().getReleaseList() );
+                    }
+                    else
+                    {
+                        getLog().warn( "changes.xml file " + getXmlPath().getAbsolutePath()
+ " does not exist." );
+                    }
                 }
                 else
                 {
-                    getLog().warn( "changes.xml file " + getXmlPath().getAbsolutePath() +
" does not exist." );
+                    doJiraGenerate();
                 }
             }
-            else
-            {
-                doJiraGenerate();
-            }
         }
     }
 



Mime
View raw message