diff --git a/maven-model-converter/src/main/java/org/apache/maven/model/converter/ConverterListener.java b/maven-model-converter/src/main/java/org/apache/maven/model/converter/ConverterListener.java new file mode 100644 index 0000000000..afb0af38db --- /dev/null +++ b/maven-model-converter/src/main/java/org/apache/maven/model/converter/ConverterListener.java @@ -0,0 +1,36 @@ +package org.apache.maven.model.converter; + +/* + * Copyright 2001-2006 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. + */ + +public interface ConverterListener +{ + void debug( String message ); + + void debug( String message, Throwable throwable ); + + void info( String message ); + + void info( String message, Throwable throwable ); + + void warn( String message ); + + void warn( String message, Throwable throwable ); + + void error( String message); + + void error( String message, Throwable throwable ); +} diff --git a/maven-model-converter/src/main/java/org/apache/maven/model/converter/Maven1Converter.java b/maven-model-converter/src/main/java/org/apache/maven/model/converter/Maven1Converter.java index 6819fe6e4d..670caa4b65 100644 --- a/maven-model-converter/src/main/java/org/apache/maven/model/converter/Maven1Converter.java +++ b/maven-model-converter/src/main/java/org/apache/maven/model/converter/Maven1Converter.java @@ -35,8 +35,10 @@ import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.Writer; +import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; +import java.util.ArrayList; import java.util.List; import java.util.Properties; @@ -71,6 +73,8 @@ public class Maven1Converter private String fileName = "project.xml"; + private List listeners = new ArrayList(); + public void execute() throws ProjectConverterException { @@ -123,7 +127,7 @@ public class Maven1Converter // @todo Should this be run before or after the configuration converters? Collection pluginRelocators = pluginRelocatorManager.getPluginRelocators(); - getLogger().info( "There are " + pluginRelocators.size() + " plugin relocators available" ); + sendInfoMessage( "There are " + pluginRelocators.size() + " plugin relocators available" ); PluginRelocator pluginRelocator; Iterator iterator = pluginRelocators.iterator(); while ( iterator.hasNext() ) @@ -152,7 +156,7 @@ public class Maven1Converter } catch ( IOException e ) { - getLogger().warn( "Unable to read " + propertiesFile.getAbsolutePath() + ", ignoring." ); + sendWarnMessage( "Unable to read " + propertiesFile.getAbsolutePath() + ", ignoring." ); } finally { @@ -217,14 +221,14 @@ public class Maven1Converter if ( !isEmpty( groupId ) ) { - getLogger().warn( "Both and is set, using ." ); + sendWarnMessage( "Both and is set, using ." ); model.setGroupId( groupId ); } if ( !isEmpty( artifactId ) ) { - getLogger().warn( "Both and is set, using ." ); + sendWarnMessage( "Both and is set, using ." ); model.setArtifactId( artifactId ); } @@ -267,13 +271,13 @@ public class Maven1Converter if ( pomxml.exists() ) { - getLogger().warn( "pom.xml in " + outputdir.getAbsolutePath() + " already exists, overwriting" ); + sendWarnMessage( "pom.xml in " + outputdir.getAbsolutePath() + " already exists, overwriting" ); } MavenXpp3Writer v4Writer = new MavenXpp3Writer(); // write the new pom.xml - getLogger().info( "Writing new pom to: " + pomxml.getAbsolutePath() ); + sendInfoMessage( "Writing new pom to: " + pomxml.getAbsolutePath() ); Writer output = null; try @@ -330,4 +334,34 @@ public class Maven1Converter { this.outputdir = outputdir; } + + public void addListener( ConverterListener listener ) + { + if ( !listeners.contains( listener ) ) + { + listeners.add( listener ); + } + } + + private void sendInfoMessage( String message ) + { + getLogger().info( message ); + + for ( Iterator i = listeners.iterator(); i.hasNext(); ) + { + ConverterListener listener = (ConverterListener) i.next(); + listener.info( message ); + } + } + + private void sendWarnMessage( String message ) + { + getLogger().warn( message ); + + for ( Iterator i = listeners.iterator(); i.hasNext(); ) + { + ConverterListener listener = (ConverterListener) i.next(); + listener.warn( message ); + } + } } diff --git a/maven-model-converter/src/main/java/org/apache/maven/model/converter/relocators/AbstractPluginRelocator.java b/maven-model-converter/src/main/java/org/apache/maven/model/converter/relocators/AbstractPluginRelocator.java index b9602da73f..5499e050ac 100644 --- a/maven-model-converter/src/main/java/org/apache/maven/model/converter/relocators/AbstractPluginRelocator.java +++ b/maven-model-converter/src/main/java/org/apache/maven/model/converter/relocators/AbstractPluginRelocator.java @@ -19,9 +19,14 @@ package org.apache.maven.model.converter.relocators; import org.apache.maven.model.Model; import org.apache.maven.model.Plugin; import org.apache.maven.model.ReportPlugin; +import org.apache.maven.model.converter.ConverterListener; import org.apache.maven.model.converter.ModelUtils; import org.codehaus.plexus.logging.AbstractLogEnabled; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + /** * A general implementation of the PluginRelocator interface. * @@ -32,6 +37,8 @@ public abstract class AbstractPluginRelocator extends AbstractLogEnabled implements PluginRelocator { + private List listeners = new ArrayList(); + /** * If there is no replacement for this plugin, you can have the plugin * removed from the v4 pom by returning null from this method @@ -89,7 +96,7 @@ public abstract class AbstractPluginRelocator { // Remove the old plugin v4Model.getBuild().getPlugins().remove( oldBuildPlugin ); - getLogger().info( "Removing build plugin " + getOldGroupId() + ":" + getOldArtifactId() ); + sendInfoMessage( "Removing build plugin " + getOldGroupId() + ":" + getOldArtifactId() ); } else { @@ -99,13 +106,13 @@ public abstract class AbstractPluginRelocator // The new plugin does not exist, relocate the old one oldBuildPlugin.setArtifactId( getNewArtifactId() ); oldBuildPlugin.setGroupId( getNewGroupId() ); - getLogger().info( "Relocating build plugin " + getOldGroupId() + ":" + getOldArtifactId() ); + sendInfoMessage( "Relocating build plugin " + getOldGroupId() + ":" + getOldArtifactId() ); } else { // The new plugin already exist, remove the old one v4Model.getBuild().getPlugins().remove( oldBuildPlugin ); - getLogger().info( "Removing old build plugin " + getOldGroupId() + ":" + getOldArtifactId() + + sendInfoMessage( "Removing old build plugin " + getOldGroupId() + ":" + getOldArtifactId() + " because the new one already exist" ); } } @@ -119,7 +126,7 @@ public abstract class AbstractPluginRelocator { // Remove the old plugin v4Model.getReporting().getPlugins().remove( oldReportPlugin ); - getLogger().info( "Removing report plugin " + getOldGroupId() + ":" + getOldArtifactId() ); + sendInfoMessage( "Removing report plugin " + getOldGroupId() + ":" + getOldArtifactId() ); } else { @@ -129,16 +136,44 @@ public abstract class AbstractPluginRelocator // The new plugin does not exist, relocate the old one oldReportPlugin.setArtifactId( getNewArtifactId() ); oldReportPlugin.setGroupId( getNewGroupId() ); - getLogger().info( "Relocating report plugin " + getOldGroupId() + ":" + getOldArtifactId() ); + sendInfoMessage( "Relocating report plugin " + getOldGroupId() + ":" + getOldArtifactId() ); } else { // The new plugin already exist, remove the old one v4Model.getReporting().getPlugins().remove( oldReportPlugin ); - getLogger().info( "Removing old report plugin " + getOldGroupId() + ":" + getOldArtifactId() + + sendInfoMessage( "Removing old report plugin " + getOldGroupId() + ":" + getOldArtifactId() + " because the new one already exist" ); } } } } + + public void addListener( ConverterListener listener ) + { + if ( !listeners.contains( listener ) ) + { + listeners.add( listener ); + } + } + + public void addListeners( List listeners ) + { + for ( Iterator i = listeners.iterator(); i.hasNext(); ) + { + ConverterListener listener = (ConverterListener) i.next(); + addListener( listener ); + } + } + + private void sendInfoMessage( String message ) + { + getLogger().info( message ); + + for ( Iterator i = listeners.iterator(); i.hasNext(); ) + { + ConverterListener listener = (ConverterListener) i.next(); + listener.info( message ); + } + } } diff --git a/maven-model-converter/src/main/java/org/apache/maven/model/converter/relocators/PluginRelocator.java b/maven-model-converter/src/main/java/org/apache/maven/model/converter/relocators/PluginRelocator.java index e439d2afcf..b8e4fe312c 100644 --- a/maven-model-converter/src/main/java/org/apache/maven/model/converter/relocators/PluginRelocator.java +++ b/maven-model-converter/src/main/java/org/apache/maven/model/converter/relocators/PluginRelocator.java @@ -17,6 +17,9 @@ package org.apache.maven.model.converter.relocators; */ import org.apache.maven.model.Model; +import org.apache.maven.model.converter.ConverterListener; + +import java.util.List; /** * A plugin relocator handles a plugin that has changed its groupId and/or @@ -36,4 +39,18 @@ public interface PluginRelocator * @param v4Model The model where we look for the plugin */ void relocate( Model v4Model ); + + /** + * Add a listener for all messages sended by the relocator. + * + * @param listener The listener that will receive messages + */ + void addListener( ConverterListener listener ); + + /** + * Add a listeners list for all messages sended by the relocator. + * + * @param listeners The listeners list that will receive messages + */ + void addListeners( List listeners ); }