mirror of https://github.com/apache/maven.git
Add listeners to the converter
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@425873 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bf2a316d91
commit
6a24473970
|
@ -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 );
|
||||
}
|
|
@ -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 <id> and <groupId> is set, using <groupId>." );
|
||||
sendWarnMessage( "Both <id> and <groupId> is set, using <groupId>." );
|
||||
|
||||
model.setGroupId( groupId );
|
||||
}
|
||||
|
||||
if ( !isEmpty( artifactId ) )
|
||||
{
|
||||
getLogger().warn( "Both <id> and <artifactId> is set, using <artifactId>." );
|
||||
sendWarnMessage( "Both <id> and <artifactId> is set, using <artifactId>." );
|
||||
|
||||
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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 <code>PluginRelocator</code> 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 <code>null</code> 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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue