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 7e513a9ac60d28383cfdc88af93f0e4b5eb48341 Author: John Dennis Casey <jdca...@apache.org> AuthorDate: Wed Jun 8 17:54:11 2005 +0000 o Started maven-projecthelp-plugin to help with build analysis (this helped me to visualize profile stuff) current goals: projecthelp:active-profiles projecthelp:effective-pom o Added source attribute to the Profile model class in maven-model, along with code in the normalization utilities (converters from profiles.xml and settings.xml models to maven-model instances) to identify the source of a particular profile. o Added a activeProfiles cache of the Profiles in effect for the current project, on the MavenProject class git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk/maven-plugins/maven-projecthelp-plugin@189612 13f79535-47bb-0310-9956-ffa450edef68 --- pom.xml | 30 ++++++ .../plugins/projecthelp/ActiveProfilesPlugin.java | 76 ++++++++++++++ .../plugins/projecthelp/EffectivePomPlugin.java | 116 +++++++++++++++++++++ 3 files changed, 222 insertions(+) diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..bbf7525 --- /dev/null +++ b/pom.xml @@ -0,0 +1,30 @@ +<model> + <parent> + <artifactId>maven-plugin-parent</artifactId> + <groupId>org.apache.maven.plugins</groupId> + <version>2.0-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <artifactId>maven-projecthelp-plugin</artifactId> + <packaging>maven-plugin</packaging> + <name>Maven Project-Help Plugin</name> + <version>2.0-alpha-3-SNAPSHOT</version> + <inceptionYear>2001</inceptionYear> + <dependencies> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-tools-api</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-model</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-project</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> + </dependencies> +</model> diff --git a/src/main/java/org/apache/maven/plugins/projecthelp/ActiveProfilesPlugin.java b/src/main/java/org/apache/maven/plugins/projecthelp/ActiveProfilesPlugin.java new file mode 100644 index 0000000..7fc3229 --- /dev/null +++ b/src/main/java/org/apache/maven/plugins/projecthelp/ActiveProfilesPlugin.java @@ -0,0 +1,76 @@ +package org.apache.maven.plugins.projecthelp; + +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 java.util.Iterator; +import java.util.List; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed 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. + */ + +/** Lists the profiles which are currently active for this build. + * + * @goal active-profiles + */ +public class ActiveProfilesPlugin extends AbstractMojo +{ + + /** + * @parameter expression="${project.activeProfiles}" + * @required + * @readonly + */ + private List profiles; + + public void execute() + throws MojoExecutionException + { + StringBuffer message = new StringBuffer(); + + message.append( "\n" ); + + if( profiles == null || profiles.isEmpty() ) + { + message.append( "There are no active profiles." ); + } + else + { + message.append( "The following profiles are active:\n\n" ); + + for ( Iterator it = profiles.iterator(); it.hasNext(); ) + { + Profile profile = (Profile) it.next(); + + message.append( "\n - " ) + .append( profile.getId() ) + .append(" (source: " ) + .append( profile.getSource() ).append( ")" ); + } + + } + + message.append( "\n\n" ); + + Log log = getLog(); + + log.info( message ); + + } + +} diff --git a/src/main/java/org/apache/maven/plugins/projecthelp/EffectivePomPlugin.java b/src/main/java/org/apache/maven/plugins/projecthelp/EffectivePomPlugin.java new file mode 100644 index 0000000..52754bd --- /dev/null +++ b/src/main/java/org/apache/maven/plugins/projecthelp/EffectivePomPlugin.java @@ -0,0 +1,116 @@ +package org.apache.maven.plugins.projecthelp; + +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 java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.StringWriter; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed 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. + */ + +/** Display the effective POM for this build, with the active profiles factored in. + * + * @goal effective-pom + */ +public class EffectivePomPlugin + extends AbstractMojo +{ + + /** + * @parameter expression="${project.model}" + * @required + * @readonly + */ + private Model pom; + + /** + * @parameter + */ + private String output; + + public void execute() + throws MojoExecutionException + { + StringWriter sWriter = new StringWriter(); + + MavenXpp3Writer pomWriter = new MavenXpp3Writer(); + + try + { + pomWriter.write( sWriter, pom ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Cannot serialize POM to XML.", e ); + } + + if( output != null && output.trim().length() > 0 ) + { + FileWriter fWriter = null; + try + { + File outFile = new File( output ).getAbsoluteFile(); + + File dir = outFile.getParentFile(); + + if( !dir.exists() ) + { + dir.mkdirs(); + } + + getLog().info( "Writing effective-POM to: " + outFile ); + + fWriter = new FileWriter( outFile ); + + fWriter.write( sWriter.toString() ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Cannot write effective-POM to output: " + output, e ); + } + finally + { + if( fWriter != null ) + { + try + { + fWriter.close(); + } + catch( IOException e ) + { + getLog().debug( "Cannot close FileWriter to output location: " + output, e ); + } + } + } + } + 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" ); + + getLog().info( message ); + } + } + +} -- To stop receiving notification emails like this one, please contact "commits@maven.apache.org" <commits@maven.apache.org>.