From 685ba3412b6b9af39ec6c311c9dd9a706c32fba9 Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Tue, 14 Jun 2005 15:26:43 +0000 Subject: [PATCH] Added projecthelp:effective-settings mojo git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@190615 13f79535-47bb-0310-9956-ffa450edef68 --- .../maven-projecthelp-plugin/pom.xml | 5 + .../projecthelp/EffectiveSettingsMojo.java | 118 ++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 maven-plugins/maven-projecthelp-plugin/src/main/java/org/apache/maven/plugins/projecthelp/EffectiveSettingsMojo.java diff --git a/maven-plugins/maven-projecthelp-plugin/pom.xml b/maven-plugins/maven-projecthelp-plugin/pom.xml index bbf752598f..3e2374579a 100644 --- a/maven-plugins/maven-projecthelp-plugin/pom.xml +++ b/maven-plugins/maven-projecthelp-plugin/pom.xml @@ -21,6 +21,11 @@ maven-model 2.0-SNAPSHOT + + org.apache.maven + maven-settings + 2.0-SNAPSHOT + org.apache.maven maven-project diff --git a/maven-plugins/maven-projecthelp-plugin/src/main/java/org/apache/maven/plugins/projecthelp/EffectiveSettingsMojo.java b/maven-plugins/maven-projecthelp-plugin/src/main/java/org/apache/maven/plugins/projecthelp/EffectiveSettingsMojo.java new file mode 100644 index 0000000000..e247165e8d --- /dev/null +++ b/maven-plugins/maven-projecthelp-plugin/src/main/java/org/apache/maven/plugins/projecthelp/EffectiveSettingsMojo.java @@ -0,0 +1,118 @@ +package org.apache.maven.plugins.projecthelp; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.settings.Settings; +import org.apache.maven.settings.io.xpp3.SettingsXpp3Writer; + +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. + */ + +/** Print out the calculated settings for this project, given any profile enhancement and + * the inheritance of the global settings into the user-level settings. + * + * @goal effective-settings + * + */ +public class EffectiveSettingsMojo + extends AbstractMojo +{ + + /** + * @parameter expression="${settings}" + * @readonly + * @required + */ + private Settings settings; + + /** + * @parameter + */ + private String output; + + public void execute() + throws MojoExecutionException + { + StringWriter sWriter = new StringWriter(); + + SettingsXpp3Writer settingsWriter = new SettingsXpp3Writer(); + + try + { + settingsWriter.write( sWriter, settings ); + } + 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-settings to: " + outFile ); + + fWriter = new FileWriter( outFile ); + + fWriter.write( sWriter.toString() ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Cannot write effective-settings 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 settings:\n\n" ); + message.append( sWriter.toString() ); + message.append( "\n\n" ); + + getLog().info( message ); + } + } + +}