You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2017/12/20 09:35:08 UTC
[maven-help-plugin] 15/37: Working on: MNG-786
This is an automated email from the ASF dual-hosted git repository.
hboutemy pushed a commit to annotated tag maven-help-plugin-2.0
in repository https://gitbox.apache.org/repos/asf/maven-help-plugin.git
commit d22ade172998b237faa5202c8471c1eaaf7316f6
Author: John Dennis Casey <jd...@apache.org>
AuthorDate: Fri Sep 30 15:45:20 2005 +0000
Working on: MNG-786
o Changed the profile activation in it0075 to use a system property which is not always present
o Added projecthelp:active-profiles, package, and clean:clean to the goals list, in case it was only happening with the clean plugin
o Fixed the projecthelp mojos to be aggregators where appropriate
o Changed the ordering of modules in the profile injector (used to be that profile modules were prepended; now, they're appended)
NOTE: I still cannot reproduce the described behavior. Dan: Am I missing something WRT the test setup? I changed the activation trigger to be non-inherent, and I'm not using a boolean string to trigger the profile. What am I doing wrong??
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk/maven-plugins/maven-projecthelp-plugin@292781 13f79535-47bb-0310-9956-ffa450edef68
---
.../plugins/projecthelp/ActiveProfilesPlugin.java | 107 +++++++++++++++++---
.../maven/plugins/projecthelp/DescribeMojo.java | 1 +
.../plugins/projecthelp/EffectivePomPlugin.java | 109 ++++++++++++---------
3 files changed, 157 insertions(+), 60 deletions(-)
diff --git a/src/main/java/org/apache/maven/plugins/projecthelp/ActiveProfilesPlugin.java b/src/main/java/org/apache/maven/plugins/projecthelp/ActiveProfilesPlugin.java
index a538b1b..7da2175 100644
--- a/src/main/java/org/apache/maven/plugins/projecthelp/ActiveProfilesPlugin.java
+++ b/src/main/java/org/apache/maven/plugins/projecthelp/ActiveProfilesPlugin.java
@@ -4,7 +4,13 @@ import org.apache.maven.model.Profile;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Date;
import java.util.Iterator;
import java.util.List;
@@ -27,31 +33,110 @@ import java.util.List;
/** Lists the profiles which are currently active for this build.
*
* @goal active-profiles
+ * @aggregator
*/
public class ActiveProfilesPlugin extends AbstractMojo
{
/**
- * @parameter expression="${project.activeProfiles}"
+ * This is the list of projects currently slated to be built by Maven.
+ *
+ * @parameter expression="${reactorProjects}"
* @required
* @readonly
*/
- private List profiles;
+ private List projects;
+
+ /**
+ * This is an optional parameter for a file destination for the output
+ * of this mojo...the listing of active profiles per project.
+ *
+ * @parameter expression="${output}"
+ */
+ private File output;
public void execute()
throws MojoExecutionException
{
StringBuffer message = new StringBuffer();
+ for ( Iterator it = projects.iterator(); it.hasNext(); )
+ {
+ MavenProject project = (MavenProject) it.next();
+
+ getActiveProfileStatement( project, message );
+
+ message.append( "\n\n" );
+ }
+
+ if ( output != null )
+ {
+ writeFile( message );
+ }
+ else
+ {
+ Log log = getLog();
+ log.info( message );
+ }
+ }
+
+ private void writeFile( StringBuffer message )
+ throws MojoExecutionException
+ {
+ Writer writer = null;
+ try
+ {
+ File dir = output.getParentFile();
+
+ if( !dir.exists() )
+ {
+ dir.mkdirs();
+ }
+
+ writer = new FileWriter( output );
+
+ writer.write( "Created by: " + getClass().getName() + "\n" );
+ writer.write( "Created on: " + new Date() + "\n\n" );
+ writer.write( message.toString() );
+ writer.flush();
+
+ getLog().info( "Active profile report written to: " + output );
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( "Cannot write output to file: " + output, e );
+ }
+ finally
+ {
+ if ( writer != null )
+ {
+ try
+ {
+ writer.close();
+ }
+ catch ( IOException e )
+ {
+ getLog().debug( "Failed to close output file writer.", e );
+ }
+ }
+ }
+ }
+
+ private void getActiveProfileStatement( MavenProject project, StringBuffer message )
+ {
+ List profiles = project.getActiveProfiles();
+
message.append( "\n" );
+ message.append( "Active Profiles for Project \'" + project.getId() + "\': \n\n" );
+
if( profiles == null || profiles.isEmpty() )
{
message.append( "There are no active profiles." );
}
else
{
- message.append( "The following profiles are active:\n\n" );
+ message.append( "The following profiles are active:\n" );
for ( Iterator it = profiles.iterator(); it.hasNext(); )
{
@@ -65,22 +150,12 @@ public class ActiveProfilesPlugin extends AbstractMojo
}
- message.append( "\n\n" );
-
- Log log = getLog();
-
- log.info( message );
-
- }
-
- protected final List getProfiles()
- {
- return profiles;
+ message.append( "\n" );
}
- protected final void setProfiles( List profiles )
+ public final void setProjects( List projects )
{
- this.profiles = profiles;
+ this.projects = projects;
}
}
diff --git a/src/main/java/org/apache/maven/plugins/projecthelp/DescribeMojo.java b/src/main/java/org/apache/maven/plugins/projecthelp/DescribeMojo.java
index 62a7e4e..7532b87 100644
--- a/src/main/java/org/apache/maven/plugins/projecthelp/DescribeMojo.java
+++ b/src/main/java/org/apache/maven/plugins/projecthelp/DescribeMojo.java
@@ -21,6 +21,7 @@ import java.util.Iterator;
/**
* @goal describe
+ * @aggregator
*/
public class DescribeMojo
extends AbstractMojo
diff --git a/src/main/java/org/apache/maven/plugins/projecthelp/EffectivePomPlugin.java b/src/main/java/org/apache/maven/plugins/projecthelp/EffectivePomPlugin.java
index 8ad1e63..5cab84c 100644
--- a/src/main/java/org/apache/maven/plugins/projecthelp/EffectivePomPlugin.java
+++ b/src/main/java/org/apache/maven/plugins/projecthelp/EffectivePomPlugin.java
@@ -4,11 +4,15 @@ import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringWriter;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
/*
* Copyright 2001-2005 The Apache Software Foundation.
@@ -29,58 +33,58 @@ import java.io.StringWriter;
/** Display the effective POM for this build, with the active profiles factored in.
*
* @goal effective-pom
+ * @aggregator
*/
public class EffectivePomPlugin
extends AbstractMojo
{
-
+
/**
- * @parameter expression="${project.model}"
+ * @parameter expression="${reactorProjects}"
* @required
* @readonly
*/
- private Model pom;
-
+ private List projects;
+
/**
- * @parameter
+ * @parameter expression="${output}"
*/
- private String output;
+ private File output;
public void execute()
throws MojoExecutionException
{
- StringWriter sWriter = new StringWriter();
+ StringBuffer message = new StringBuffer();
- MavenXpp3Writer pomWriter = new MavenXpp3Writer();
-
- try
+ for ( Iterator it = projects.iterator(); it.hasNext(); )
{
- pomWriter.write( sWriter, pom );
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Cannot serialize POM to XML.", e );
+ MavenProject project = (MavenProject) it.next();
+
+ getEffectivePom( project, message );
+
+ message.append( "\n\n" );
}
- if( output != null && output.trim().length() > 0 )
+ if ( output != null )
{
FileWriter fWriter = null;
try
{
- File outFile = new File( output ).getAbsoluteFile();
-
- File dir = outFile.getParentFile();
-
- if( !dir.exists() )
+ File dir = output.getParentFile();
+
+ if ( !dir.exists() )
{
dir.mkdirs();
}
+
+ getLog().info( "Writing effective-POM to: " + output );
+
+ fWriter = new FileWriter( output );
+
+ fWriter.write( "Created by: " + getClass().getName() + "\n" );
+ fWriter.write( "Created on: " + new Date() + "\n\n" );
- getLog().info( "Writing effective-POM to: " + outFile );
-
- fWriter = new FileWriter( outFile );
-
- fWriter.write( sWriter.toString() );
+ fWriter.write( message.toString() );
}
catch ( IOException e )
{
@@ -88,13 +92,13 @@ public class EffectivePomPlugin
}
finally
{
- if( fWriter != null )
+ if ( fWriter != null )
{
try
{
fWriter.close();
}
- catch( IOException e )
+ catch ( IOException e )
{
getLog().debug( "Cannot close FileWriter to output location: " + output, e );
}
@@ -103,34 +107,51 @@ public class EffectivePomPlugin
}
else
{
- StringBuffer message = new StringBuffer();
-
- message.append( "\nEffective POM, after all profiles are factored in:\n\n" );
- message.append( sWriter.toString() );
- message.append( "\n\n" );
-
+ StringBuffer formatted = new StringBuffer();
+
+ formatted.append( "\nEffective POMs, after inheritance, interpolation, and profiles are applied:\n\n" );
+ formatted.append( message.toString() );
+ formatted.append( "\n" );
+
getLog().info( message );
}
}
- protected final String getOutput()
+ private void getEffectivePom( MavenProject project, StringBuffer message )
+ throws MojoExecutionException
{
- return output;
- }
+ Model pom = project.getModel();
+
+ StringWriter sWriter = new StringWriter();
+
+ MavenXpp3Writer pomWriter = new MavenXpp3Writer();
+
+ try
+ {
+ pomWriter.write( sWriter, pom );
+
+ message.append( "\n************************************************************************************" );
+ message.append( "\nEffective POM for project \'" + project.getId() + "\'" );
+ message.append( "\n************************************************************************************" );
+ message.append( "\n" );
+ message.append( sWriter.toString() );
+ message.append( "\n************************************************************************************" );
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( "Cannot serialize POM to XML.", e );
+ }
- protected final void setOutput( String output )
- {
- this.output = output;
}
- protected final Model getPom()
+ protected final void setOutput( File output )
{
- return pom;
+ this.output = output;
}
- protected final void setPom( Model pom )
+ protected final void setProjects( List projects )
{
- this.pom = pom;
+ this.projects = projects;
}
}
--
To stop receiving notification emails like this one, please contact
"commits@maven.apache.org" <co...@maven.apache.org>.