Implemented list items #2 and #3 from the main issue (scope from m1, and plugin entry translation in POMs). Tests included.

PR: MNG-309


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163974 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-04-19 20:05:15 +00:00
parent 33f0431b59
commit d7e66db253
18 changed files with 753 additions and 302 deletions

View File

@ -49,31 +49,40 @@ public class Main
System.exit( 0 );
}
Embedder embedder = new Embedder();
try
{
embedder.start( new ClassWorld() );
RepositoryCleanerConfiguration config = buildConfig( args[0] );
RepositoryCleaner cleaner = null;
try
{
cleaner = (RepositoryCleaner) embedder.lookup( RepositoryCleaner.ROLE );
cleaner.cleanRepository( config );
}
finally
{
if ( cleaner != null )
{
embedder.release( cleaner );
}
}
launch( config );
System.exit( 0 );
}
catch ( Throwable e )
catch ( Exception e )
{
e.printStackTrace();
System.exit( 1 );
}
}
public static void launch( RepositoryCleanerConfiguration config ) throws Exception
{
Embedder embedder = new Embedder();
embedder.start( new ClassWorld() );
RepositoryCleaner cleaner = null;
try
{
cleaner = (RepositoryCleaner) embedder.lookup( RepositoryCleaner.ROLE );
cleaner.cleanRepository( config );
}
finally
{
if ( cleaner != null )
{
embedder.release( cleaner );
}
}
}
@ -104,7 +113,6 @@ public class Main
config.setMailErrorReport( Boolean.valueOf( props.getProperty( "errorReport.mailOnError", "false") ).booleanValue() );
config.setErrorReportFromAddress( props.getProperty( "errorReport.fromAddress" ) );
config.setErrorReportFromName( props.getProperty( "errorReport.fromName" ) );
config.setErrorReportSmtpHost( props.getProperty( "errorReport.smtpHost", "localhost" ) );
config.setErrorReportSubject( props.getProperty( "errorReport.subject" ) );
config.setErrorReportToAddress( props.getProperty( "errorReport.toAddress" ) );
config.setErrorReportToName( props.getProperty( "errorReport.toName" ) );

View File

@ -24,7 +24,7 @@ import org.apache.maven.tools.repoclean.artifact.metadata.ProjectMetadata;
import org.apache.maven.tools.repoclean.digest.ArtifactDigestVerifier;
import org.apache.maven.tools.repoclean.discover.ArtifactDiscoverer;
import org.apache.maven.tools.repoclean.index.ArtifactIndexer;
import org.apache.maven.tools.repoclean.report.Reporter;
import org.apache.maven.tools.repoclean.report.FileReporter;
import org.apache.maven.tools.repoclean.rewrite.ArtifactPomRewriter;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
@ -86,10 +86,10 @@ public class RepositoryCleaner
{
Logger logger = getLogger();
Reporter repoReporter = null;
FileReporter repoReporter = null;
try
{
repoReporter = new Reporter( reportsBase, "repository.report.txt" );
repoReporter = new FileReporter( reportsBase, "repository.report.txt" );
ArtifactDiscoverer artifactDiscoverer = null;
@ -197,13 +197,10 @@ public class RepositoryCleaner
MailMessage message = new MailMessage();
message.setContent( reportContents );
message.setSubject( configuration.getErrorReportSubject() );
message.setFromName( configuration.getErrorReportFromName() );
message.setFromAddress( configuration.getErrorReportFromAddress() );
message.setFrom( configuration.getErrorReportFromName(), configuration.getErrorReportFromAddress() );
message.setSendDate( new Date() );
message.addTo( configuration.getErrorReportToName(), configuration.getErrorReportToAddress() );
mailSender.setSmtpHost( configuration.getErrorReportSmtpHost() );
mailSender.send( message );
}
}
@ -237,7 +234,7 @@ public class RepositoryCleaner
private void rewriteArtifactsAndPoms( List artifacts, ArtifactRepository sourceRepo, ArtifactRepository targetRepo,
RepositoryCleanerConfiguration configuration, File reportsBase,
File sourceRepositoryBase, File targetRepositoryBase, Reporter repoReporter )
File sourceRepositoryBase, File targetRepositoryBase, FileReporter repoReporter )
throws Exception
{
Logger logger = getLogger();
@ -256,10 +253,10 @@ public class RepositoryCleaner
String artifactReportPath = buildArtifactReportPath( artifact );
Reporter artifactReporter = null;
FileReporter artifactReporter = null;
try
{
artifactReporter = new Reporter( reportsBase, artifactReportPath );
artifactReporter = new FileReporter( reportsBase, artifactReportPath );
boolean errorOccurred = false;
@ -398,7 +395,7 @@ public class RepositoryCleaner
+ "/" + ( ( classifier != null ) ? ( classifier + "-" ) : ( "" ) ) + artifact.getVersion() + ".report.txt";
}
private void copyArtifact( Artifact artifact, File artifactTarget, Reporter reporter )
private void copyArtifact( Artifact artifact, File artifactTarget, FileReporter reporter )
throws IOException
{
File artifactSource = artifact.getFile();

View File

@ -47,9 +47,9 @@ public class RepositoryCleanerConfiguration
private String errorReportToAddress;
private String errorReportSmtpHost;
private boolean mailErrorReport;
private boolean force;
public void setSourceRepositoryPath( String sourceRepositoryPath )
{
@ -151,16 +151,6 @@ public class RepositoryCleanerConfiguration
this.errorReportFromName = errorReportFromName;
}
public String getErrorReportSmtpHost()
{
return errorReportSmtpHost;
}
public void setErrorReportSmtpHost( String errorReportSmtpHost )
{
this.errorReportSmtpHost = errorReportSmtpHost;
}
public String getErrorReportToAddress()
{
return errorReportToAddress;
@ -190,4 +180,14 @@ public class RepositoryCleanerConfiguration
{
return mailErrorReport;
}
public boolean force()
{
return force;
}
public void setForce( boolean force )
{
this.force = force;
}
}

View File

@ -18,7 +18,7 @@ package org.apache.maven.tools.repoclean.digest;
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.tools.repoclean.report.Reporter;
import org.apache.maven.tools.repoclean.report.FileReporter;
import org.codehaus.plexus.util.FileUtils;
import java.io.File;
@ -34,7 +34,7 @@ public class ArtifactDigestVerifier
private ArtifactDigestor artifactDigestor;
public void verifyDigest( Artifact artifact, File artifactTarget, Reporter reporter, boolean reportOnly ) throws Exception
public void verifyDigest( Artifact artifact, File artifactTarget, FileReporter reporter, boolean reportOnly ) throws Exception
{
// create the digest source file from which to copy/verify.
File digestSourceFile = new File( artifact.getFile() + ".md5" );

View File

@ -1,6 +1,6 @@
package org.apache.maven.tools.repoclean.discover;
import org.apache.maven.tools.repoclean.report.Reporter;
import org.apache.maven.tools.repoclean.report.FileReporter;
import java.io.File;
import java.util.List;
@ -43,6 +43,6 @@ public interface ArtifactDiscoverer
"**/REPOSITORY-V*.txt"
};
List discoverArtifacts( File repositoryBase, Reporter reporter ) throws Exception;
List discoverArtifacts( File repositoryBase, FileReporter reporter ) throws Exception;
}

View File

@ -4,7 +4,7 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.construction.ArtifactConstructionSupport;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.tools.repoclean.report.Reporter;
import org.apache.maven.tools.repoclean.report.FileReporter;
import org.codehaus.plexus.util.DirectoryScanner;
import org.codehaus.plexus.util.IOUtil;
@ -36,7 +36,7 @@ public class DefaultArtifactDiscoverer
private ArtifactConstructionSupport artifactConstructionSupport = new ArtifactConstructionSupport();
public List discoverArtifacts( File repositoryBase, Reporter reporter )
public List discoverArtifacts( File repositoryBase, FileReporter reporter )
throws Exception
{
List artifacts = new ArrayList();
@ -64,7 +64,7 @@ public class DefaultArtifactDiscoverer
return artifacts;
}
private Artifact buildArtifact( File repositoryBase, String path, Reporter reporter )
private Artifact buildArtifact( File repositoryBase, String path, FileReporter reporter )
throws Exception
{
Artifact result = null;

View File

@ -16,7 +16,7 @@ package org.apache.maven.tools.repoclean.discover;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.construction.ArtifactConstructionSupport;
import org.apache.maven.tools.repoclean.report.Reporter;
import org.apache.maven.tools.repoclean.report.FileReporter;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.DirectoryScanner;
@ -38,7 +38,7 @@ public class LegacyArtifactDiscoverer
private ArtifactConstructionSupport artifactConstructionSupport = new ArtifactConstructionSupport();
public List discoverArtifacts( File repositoryBase, Reporter reporter )
public List discoverArtifacts( File repositoryBase, FileReporter reporter )
throws Exception
{
List artifacts = new ArrayList();
@ -65,7 +65,7 @@ public class LegacyArtifactDiscoverer
return artifacts;
}
private Artifact buildArtifact( String path, Reporter reporter )
private Artifact buildArtifact( String path, FileReporter reporter )
throws Exception
{
StringTokenizer tokens = new StringTokenizer( path, "/\\" );

View File

@ -0,0 +1,189 @@
package org.apache.maven.tools.repoclean.report;
/* ====================================================================
* Copyright 2001-2004 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.
* ====================================================================
*/
import org.codehaus.plexus.util.IOUtil;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* @author jdcasey
*/
public class FileReporter implements Reporter
{
private static final String WARN_LEVEL = "[WARNING] ";
private static final String ERROR_LEVEL = "[ERROR] ";
private File reportsFile;
private List messages = new ArrayList();
private boolean hasError = false;
private boolean hasWarning = false;
private Writer writer;
public FileReporter( File reportsBase, String reportPath )
{
this.reportsFile = new File( reportsBase, reportPath );
File parentDir = reportsFile.getParentFile();
if ( !parentDir.exists() )
{
parentDir.mkdirs();
}
if ( !parentDir.isDirectory() )
{
throw new IllegalArgumentException( "path: \'" + parentDir.getAbsolutePath()
+ "\' refers to a file, not a directory.\n" + "Cannot write report file: \'"
+ reportsFile.getAbsolutePath() + "\'." );
}
}
public File getReportFile()
{
return reportsFile;
}
private void open()
throws IOException
{
this.writer = new FileWriter( reportsFile );
}
public void close()
{
IOUtil.close( writer );
}
private void write( Object message )
throws ReportWriteException
{
try
{
if ( writer == null )
{
open();
}
if ( message instanceof List )
{
writer.write( format( (List) message ).toString() );
}
else
{
writer.write( String.valueOf( message ) );
}
writer.write( '\n' );
writer.flush();
}
catch ( IOException e )
{
throw new ReportWriteException( "Cannot write message: " + message + " due to an I/O error.", e );
}
}
public boolean hasWarning()
{
return hasWarning;
}
public boolean hasError()
{
return hasError;
}
public void warn( String message ) throws ReportWriteException
{
hasWarning = true;
write( new AppendingList( 2 ).append( WARN_LEVEL ).append( message ) );
}
public void error( String message, Throwable error ) throws ReportWriteException
{
hasError = true;
write( new AppendingList( 3 ).append( ERROR_LEVEL ).append( message ).append( error ) );
}
public void error( String message ) throws ReportWriteException
{
hasError = true;
write( new AppendingList( 2 ).append( ERROR_LEVEL ).append( message ) );
}
private CharSequence format( List messageParts )
{
StringBuffer buffer = new StringBuffer();
for ( Iterator it = messageParts.iterator(); it.hasNext(); )
{
Object part = it.next();
if ( part instanceof Throwable )
{
part = formatThrowable( (Throwable) part );
}
buffer.append( part );
}
return buffer;
}
private String formatThrowable( Throwable throwable )
{
StringWriter sWriter = new StringWriter();
PrintWriter pWriter = new PrintWriter( sWriter );
throwable.printStackTrace( pWriter );
return sWriter.toString();
}
private static class AppendingList
extends ArrayList
{
public AppendingList()
{
}
public AppendingList( int size )
{
super( size );
}
public AppendingList append( Object item )
{
super.add( item );
return this;
}
}
}

View File

@ -0,0 +1,38 @@
package org.apache.maven.tools.repoclean.report;
/*
* 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.
*/
public class ReportWriteException
extends Exception
{
public ReportWriteException( String message, Throwable cause )
{
super( message, cause );
}
public ReportWriteException( String message )
{
super( message );
}
public ReportWriteException( Throwable cause )
{
super( cause );
}
}

View File

@ -1,185 +1,37 @@
package org.apache.maven.tools.repoclean.report;
/* ====================================================================
* Copyright 2001-2004 The Apache Software Foundation.
/*
* 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
* 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
* 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.
* ====================================================================
* 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.
*/
import org.codehaus.plexus.util.IOUtil;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* @author jdcasey
*/
public class Reporter
public interface Reporter
{
private static final String WARN_LEVEL = "[WARNING] ";
public void close();
private static final String ERROR_LEVEL = "[ERROR] ";
public boolean hasWarning();
private File reportsFile;
private List messages = new ArrayList();
private boolean hasError = false;
private boolean hasWarning = false;
private Writer writer;
public Reporter( File reportsBase, String reportPath )
{
this.reportsFile = new File( reportsBase, reportPath );
File parentDir = reportsFile.getParentFile();
if ( !parentDir.exists() )
{
parentDir.mkdirs();
}
if ( !parentDir.isDirectory() )
{
throw new IllegalArgumentException( "path: \'" + parentDir.getAbsolutePath()
+ "\' refers to a file, not a directory.\n" + "Cannot write report file: \'"
+ reportsFile.getAbsolutePath() + "\'." );
}
}
public File getReportFile()
{
return reportsFile;
}
private void open()
throws IOException
{
this.writer = new FileWriter( reportsFile );
}
public void close()
{
IOUtil.close( writer );
}
private void write( Object message )
throws IOException
{
if ( writer == null )
{
open();
}
if ( message instanceof List )
{
writer.write( format( (List) message ).toString() );
}
else
{
writer.write( String.valueOf( message ) );
}
writer.write( '\n' );
writer.flush();
}
public boolean hasWarning()
{
return hasWarning;
}
public boolean hasError()
{
return hasError;
}
public boolean hasError();
public void warn( String message )
throws IOException
{
hasWarning = true;
write( new AppendingList( 2 ).append( WARN_LEVEL ).append( message ) );
}
throws ReportWriteException;
public void error( String message, Throwable error )
throws IOException
{
hasError = true;
write( new AppendingList( 3 ).append( ERROR_LEVEL ).append( message ).append( error ) );
}
throws ReportWriteException;
public void error( String message )
throws IOException
{
hasError = true;
write( new AppendingList( 2 ).append( ERROR_LEVEL ).append( message ) );
}
private CharSequence format( List messageParts )
{
StringBuffer buffer = new StringBuffer();
for ( Iterator it = messageParts.iterator(); it.hasNext(); )
{
Object part = it.next();
if ( part instanceof Throwable )
{
part = formatThrowable( (Throwable) part );
}
buffer.append( part );
}
return buffer;
}
private String formatThrowable( Throwable throwable )
{
StringWriter sWriter = new StringWriter();
PrintWriter pWriter = new PrintWriter( sWriter );
throwable.printStackTrace( pWriter );
return sWriter.toString();
}
private static class AppendingList
extends ArrayList
{
public AppendingList()
{
}
public AppendingList( int size )
{
super( size );
}
public AppendingList append( Object item )
{
super.add( item );
return this;
}
}
throws ReportWriteException;
}

View File

@ -1,7 +1,7 @@
package org.apache.maven.tools.repoclean.rewrite;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.tools.repoclean.report.Reporter;
import org.apache.maven.tools.repoclean.report.FileReporter;
import java.io.File;
@ -30,6 +30,6 @@ public interface ArtifactPomRewriter
public static final String ROLE = ArtifactPomRewriter.class.getName();
void rewrite( Artifact artifact, File from, File to, Reporter reporter, boolean reportOnly ) throws Exception;
void rewrite( Artifact artifact, File from, File to, FileReporter reporter, boolean reportOnly ) throws Exception;
}

View File

@ -4,7 +4,7 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader;
import org.apache.maven.tools.repoclean.report.Reporter;
import org.apache.maven.tools.repoclean.report.FileReporter;
import org.apache.maven.tools.repoclean.translate.PomV3ToV4Translator;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils;
@ -38,7 +38,7 @@ public class V3PomRewriter
{
private PomV3ToV4Translator translator;
public void rewrite( Artifact artifact, File from, File to, Reporter reporter, boolean reportOnly )
public void rewrite( Artifact artifact, File from, File to, FileReporter reporter, boolean reportOnly )
throws Exception
{
Model v4Model = null;
@ -107,7 +107,7 @@ public class V3PomRewriter
}
}
private void validateV4Basics( Model model, Artifact artifact, Reporter reporter )
private void validateV4Basics( Model model, Artifact artifact, FileReporter reporter )
throws Exception
{
if ( StringUtils.isEmpty( model.getModelVersion() ) )

View File

@ -21,7 +21,7 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.tools.repoclean.report.Reporter;
import org.apache.maven.tools.repoclean.report.FileReporter;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils;
@ -35,7 +35,7 @@ import java.io.FileWriter;
public class V4PomRewriter
implements ArtifactPomRewriter
{
public void rewrite( Artifact artifact, File from, File to, Reporter reporter, boolean reportOnly )
public void rewrite( Artifact artifact, File from, File to, FileReporter reporter, boolean reportOnly )
throws Exception
{
Model model = null;
@ -95,7 +95,7 @@ public class V4PomRewriter
}
}
private void validateBasics( Model model, Artifact artifact, Reporter reporter )
private void validateBasics( Model model, Artifact artifact, FileReporter reporter )
throws Exception
{
if ( StringUtils.isEmpty( model.getModelVersion() ) )

View File

@ -19,6 +19,7 @@ import org.apache.maven.model.Repository;
import org.apache.maven.model.Resource;
import org.apache.maven.model.Scm;
import org.apache.maven.model.Site;
import org.apache.maven.tools.repoclean.report.ReportWriteException;
import org.apache.maven.tools.repoclean.report.Reporter;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.StringUtils;
@ -54,74 +55,88 @@ public class PomV3ToV4Translator
{
public static final String ROLE = PomV3ToV4Translator.class.getName();
private transient List discoveredPlugins = new ArrayList();
public Model translate( org.apache.maven.model.v3_0_0.Model v3Model, Reporter reporter )
throws Exception
throws ReportWriteException
{
String groupId = v3Model.getGroupId();
String artifactId = v3Model.getArtifactId();
String id = v3Model.getId();
if ( StringUtils.isNotEmpty( id ) )
{
if ( StringUtils.isEmpty( groupId ) )
{
groupId = id;
}
if ( StringUtils.isEmpty( artifactId ) )
{
artifactId = id;
}
}
String version = v3Model.getCurrentVersion();
if ( version == null )
{
version = v3Model.getVersion();
}
PomKey pomKey = new PomKey( groupId, artifactId, version );
warnOfUnsupportedMainModelElements( v3Model, reporter );
Model model = null;
try
{
model = new Model();
model.setArtifactId( v3Model.getArtifactId() );
model.setBuild( translateBuild( v3Model.getBuild(), reporter ) );
model.setCiManagement( translateCiManagementInfo( v3Model.getBuild() ) );
model.setContributors( translateContributors( v3Model.getContributors() ) );
String groupId = v3Model.getGroupId();
String artifactId = v3Model.getArtifactId();
model.setDependencies( translateDependencies( v3Model.getDependencies() ) );
model.setDescription( v3Model.getDescription() );
model.setDevelopers( translateDevelopers( v3Model.getDevelopers() ) );
String id = v3Model.getId();
if ( StringUtils.isNotEmpty( id ) )
{
if ( StringUtils.isEmpty( groupId ) )
{
groupId = id;
}
model.setDistributionManagement( translateDistributionManagement( pomKey, v3Model ) );
if ( StringUtils.isEmpty( artifactId ) )
{
artifactId = id;
}
}
model.setGroupId( v3Model.getGroupId() );
model.setInceptionYear( v3Model.getInceptionYear() );
model.setIssueManagement( translateIssueManagement( v3Model ) );
String version = v3Model.getCurrentVersion();
if ( version == null )
{
version = v3Model.getVersion();
}
model.setLicenses( translateLicenses( v3Model.getLicenses() ) );
model.setMailingLists( translateMailingLists( v3Model.getMailingLists() ) );
model.setModelVersion( "4.0.0" );
model.setName( v3Model.getName() );
model.setOrganization( translateOrganization( v3Model.getOrganization(), reporter ) );
model.setPackaging( "jar" );
model.setReports( translateReports( v3Model.getReports(), reporter ) );
model.setScm( translateScm( v3Model ) );
model.setUrl( v3Model.getUrl() );
PomKey pomKey = new PomKey( groupId, artifactId, version );
model.setVersion( version );
warnOfUnsupportedMainModelElements( v3Model, reporter );
Model model = null;
try
{
model = new Model();
model.setArtifactId( v3Model.getArtifactId() );
// moved this above the translation of the build, to allow
// additional plugins to be defined in v3 poms via
// <dependency><type>plugin</type></dependency>
model.setDependencies( translateDependencies( v3Model.getDependencies() ) );
model.setBuild( translateBuild( v3Model.getBuild(), reporter ) );
model.setCiManagement( translateCiManagementInfo( v3Model.getBuild() ) );
model.setContributors( translateContributors( v3Model.getContributors() ) );
model.setDescription( v3Model.getDescription() );
model.setDevelopers( translateDevelopers( v3Model.getDevelopers() ) );
model.setDistributionManagement( translateDistributionManagement( pomKey, v3Model ) );
model.setGroupId( v3Model.getGroupId() );
model.setInceptionYear( v3Model.getInceptionYear() );
model.setIssueManagement( translateIssueManagement( v3Model ) );
model.setLicenses( translateLicenses( v3Model.getLicenses() ) );
model.setMailingLists( translateMailingLists( v3Model.getMailingLists() ) );
model.setModelVersion( "4.0.0" );
model.setName( v3Model.getName() );
model.setOrganization( translateOrganization( v3Model.getOrganization(), reporter ) );
model.setPackaging( "jar" );
model.setReports( translateReports( v3Model.getReports(), reporter ) );
model.setScm( translateScm( v3Model ) );
model.setUrl( v3Model.getUrl() );
model.setVersion( version );
}
catch ( PomTranslationException e )
{
reporter.error( "Invalid POM detected. Cannot translate.", e );
}
return model;
}
catch ( PomTranslationException e )
finally
{
reporter.error( "Invalid POM detected. Cannot translate.", e );
this.discoveredPlugins.clear();
}
return model;
}
private CiManagement translateCiManagementInfo( org.apache.maven.model.v3_0_0.Build v3Build )
@ -148,7 +163,7 @@ public class PomV3ToV4Translator
}
private void warnOfUnsupportedMainModelElements( org.apache.maven.model.v3_0_0.Model v3Model, Reporter reporter )
throws Exception
throws ReportWriteException
{
if ( StringUtils.isNotEmpty( v3Model.getExtend() ) )
{
@ -216,7 +231,7 @@ public class PomV3ToV4Translator
}
private Reports translateReports( List v3Reports, Reporter reporter )
throws Exception
throws ReportWriteException
{
Reports reports = null;
if ( v3Reports != null && !v3Reports.isEmpty() )
@ -280,7 +295,7 @@ public class PomV3ToV4Translator
private org.apache.maven.model.Organization translateOrganization(
org.apache.maven.model.v3_0_0.Organization v3Organization,
Reporter reporter )
throws Exception
throws ReportWriteException
{
Organization organization = null;
@ -486,26 +501,72 @@ public class PomV3ToV4Translator
{
org.apache.maven.model.v3_0_0.Dependency v3Dep = (org.apache.maven.model.v3_0_0.Dependency) it.next();
Dependency dep = new Dependency();
String artifactId = v3Dep.getArtifactId();
String groupId = v3Dep.getGroupId();
if(StringUtils.isNotEmpty(artifactId) && StringUtils.isNotEmpty(groupId))
String type = v3Dep.getType();
if( "plugin".equals( type ) )
{
dep.setGroupId(groupId);
dep.setArtifactId(artifactId);
String groupId = v3Dep.getGroupId();
if( "maven".equals( groupId ) )
{
groupId = "org.apache.maven.plugins";
}
Plugin plugin = new Plugin();
plugin.setGroupId( groupId );
plugin.setArtifactId( v3Dep.getArtifactId() );
plugin.setVersion( v3Dep.getVersion() );
Xpp3Dom config = new Xpp3Dom( "configuration" );
Properties props = v3Dep.getProperties();
if ( !props.isEmpty() )
{
for ( Iterator propertyIterator = props.keySet().iterator(); it.hasNext(); )
{
String key = (String) propertyIterator.next();
String value = props.getProperty( key );
Xpp3Dom child = new Xpp3Dom( key );
child.setValue( value );
config.addChild( child );
}
}
plugin.setConfiguration( config );
this.discoveredPlugins.add( plugin );
}
else
{
dep.setGroupId(v3Dep.getId());
dep.setArtifactId(v3Dep.getId());
Dependency dep = new Dependency();
String artifactId = v3Dep.getArtifactId();
String groupId = v3Dep.getGroupId();
if(StringUtils.isNotEmpty(artifactId) && StringUtils.isNotEmpty(groupId))
{
dep.setGroupId(groupId);
dep.setArtifactId(artifactId);
}
else
{
dep.setGroupId(v3Dep.getId());
dep.setArtifactId(v3Dep.getId());
}
dep.setVersion( v3Dep.getVersion() );
dep.setType( v3Dep.getType() );
String scope = v3Dep.getProperty( "scope" );
if( scope != null && scope.trim().length() > 0 )
{
dep.setScope( scope );
}
deps.add( dep );
}
dep.setVersion( v3Dep.getVersion() );
dep.setType( v3Dep.getType() );
deps.add( dep );
}
}
@ -539,7 +600,7 @@ public class PomV3ToV4Translator
}
private Build translateBuild( org.apache.maven.model.v3_0_0.Build v3Build, Reporter reporter )
throws Exception
throws ReportWriteException
{
Build build = null;
if ( v3Build != null )
@ -566,7 +627,7 @@ public class PomV3ToV4Translator
if ( notEmpty( testIncludes ) || notEmpty( testExcludes ) )
{
Plugin plugin = new Plugin();
plugin.setGroupId( "maven" );
plugin.setGroupId( "org.apache.maven.plugins" );
plugin.setArtifactId( "surefire" );
plugin.setVersion( "1.0-SNAPSHOT" );
@ -611,12 +672,27 @@ public class PomV3ToV4Translator
}
}
}
if(!this.discoveredPlugins.isEmpty())
{
if(build == null)
{
build = new Build();
}
for ( Iterator it = this.discoveredPlugins.iterator(); it.hasNext(); )
{
Plugin plugin = (Plugin) it.next();
build.addPlugin( plugin );
}
}
return build;
}
private void warnOfUnsupportedBuildElements( org.apache.maven.model.v3_0_0.Build v3Build, Reporter reporter )
throws Exception
throws ReportWriteException
{
if ( notEmpty( v3Build.getSourceModifications() ) )
{

View File

@ -0,0 +1,61 @@
---
Transitioning from Repository Conversion to Repository Management
---
John Casey
---
19-Apr-2005
---
Notes on Transitioning Repoclean from a Conversion Tool to a Management Tool
* Abstract
Repoclean was born a conversion tool, with the primary purpose of performing
the initial conversion between maven1 and maven2 repository formats. As such,
it has facilities for translating POMs, restructuring artifact directories,
repairing checksums, and more.
However, it has become exceedingly clear with the first alpha release of
maven2 that we need a tool to perform smart mirroring of artifacts and
metadata between m1 and m2 repositories. To that end, we must redesign and
refactor repoclean (the closest thing to a solution we currently have), and
transform it from a one-off project to an active part of the maven toolset.
* Execution Modes
While these execution modes are in various states of development, we need to
formalize these options in the configuration and repair any gaps in the
implementation.
** Support for m1-to-m1 synchronization
We need to support blacklisting and other features relevant to m1 repositories
in this feature. In the feature list below, I'll note which ones are
applicable to m1.
** Support for m2-to-m2 synchronization
We'll need to support normalization and blacklisting for synchronization of
a feeder m2 repository to our canonical m2 repository.
** Support for m2-to-m1 synchronization
We have to be able to do bidirectional synchronization, for the case where one
or more of our feeder repositories transitions to maven2 while we're still
supporting maven1 users. This really should only involve any normalization
that we'd normally do in a m2-to-m2 sync process, plus forced usage of the
legacy repository layout and translation of POMs.
** Support for m1-to-m2 synchronization
This one should be mostly complete, with only new features still needing
implementation.
* Features
* Required Modifications
** Add CLI for parsing command-line modifications to config files, and for
"--force".
** Add SHA-1 checksum file support.

View File

@ -0,0 +1,59 @@
package org.apache.maven.tools.repoclean;
import java.io.File;
import java.net.URL;
/*
* 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.
*/
public final class TestSupport
{
private static final String REPO_MARKER = "repo-marker.txt";
private static final int MY_PACKAGE_TRIM = TestSupport.class.getPackage().getName().length() + 1;
private TestSupport()
{
}
public static String getMyRepositoryPath(Object testInstance)
{
Class testClass = testInstance.getClass();
String myRepo = testClass.getName().substring(MY_PACKAGE_TRIM);
return getRepositoryPath(myRepo);
}
public static String getRepositoryPath( String relativePath )
{
String base = relativePath.replace('.', '/');
if(!base.endsWith("/"))
{
base += "/";
}
ClassLoader cloader = Thread.currentThread().getContextClassLoader();
URL repoMarkerResource = cloader.getResource(base + REPO_MARKER);
File repoMarker = new File(repoMarkerResource.getPath()).getAbsoluteFile();
return repoMarker.getParentFile().getPath();
}
}

View File

@ -0,0 +1,65 @@
package org.apache.maven.tools.repoclean.report;
/*
* 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.
*/
public class DummyReporter
implements Reporter
{
public void close()
{
}
public boolean hasWarning()
{
return false;
}
public boolean hasError()
{
return false;
}
public void warn( String message )
throws ReportWriteException
{
log( "[WARNING]", message, null );
}
public void error( String message, Throwable error )
throws ReportWriteException
{
log( "[ERROR]", message, error );
}
public void error( String message )
throws ReportWriteException
{
log( "[ERROR]", message, null );
}
private void log( String classifier, String message, Throwable error )
{
System.out.println( classifier + " " + message );
if ( error != null )
{
error.printStackTrace();
}
}
}

View File

@ -0,0 +1,106 @@
package org.apache.maven.tools.repoclean.translate;
import org.apache.maven.model.Build;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.tools.repoclean.report.DummyReporter;
import org.apache.maven.tools.repoclean.report.Reporter;
import org.codehaus.plexus.PlexusTestCase;
/*
* 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.
*/
public class PomV3ToV4TranslatorTest
extends PlexusTestCase
{
public void testShouldConvertScopePropertyToDependencyScope()
throws Exception
{
PomV3ToV4Translator translator = (PomV3ToV4Translator) lookup( PomV3ToV4Translator.ROLE );
Reporter reporter = new DummyReporter();
org.apache.maven.model.v3_0_0.Dependency v3Dep = new org.apache.maven.model.v3_0_0.Dependency();
v3Dep.setGroupId( "testGroup" );
v3Dep.setArtifactId( "testArtifact" );
v3Dep.setVersion( "1.0" );
v3Dep.addProperty( "scope", "test" );
org.apache.maven.model.v3_0_0.Model v3Model = new org.apache.maven.model.v3_0_0.Model();
v3Model.addDependency( v3Dep );
Model result = translator.translate( v3Model, reporter );
assertEquals( "test", ( (Dependency) result.getDependencies().get( 0 ) ).getScope() );
}
public void testShouldConvertDependencyWithTypePluginToBuildPluginEntry()
throws Exception
{
PomV3ToV4Translator translator = (PomV3ToV4Translator) lookup( PomV3ToV4Translator.ROLE );
Reporter reporter = new DummyReporter();
org.apache.maven.model.v3_0_0.Dependency v3Dep = new org.apache.maven.model.v3_0_0.Dependency();
v3Dep.setGroupId( "testGroup" );
v3Dep.setArtifactId( "testArtifact" );
v3Dep.setVersion( "1.0" );
v3Dep.setType( "plugin" );
org.apache.maven.model.v3_0_0.Model v3Model = new org.apache.maven.model.v3_0_0.Model();
v3Model.addDependency( v3Dep );
Model result = translator.translate( v3Model, reporter );
Build build = result.getBuild();
Plugin plugin = (Plugin) build.getPlugins().get( 0 );
assertEquals( "testGroup", plugin.getGroupId() );
assertEquals( "testArtifact", plugin.getArtifactId() );
assertEquals( "1.0", plugin.getVersion() );
}
public void testShouldConvertDependencyWithTypePluginAndGroupMavenToBuildPluginEntryWithOAMPluginsGroup()
throws Exception
{
PomV3ToV4Translator translator = (PomV3ToV4Translator) lookup( PomV3ToV4Translator.ROLE );
Reporter reporter = new DummyReporter();
org.apache.maven.model.v3_0_0.Dependency v3Dep = new org.apache.maven.model.v3_0_0.Dependency();
v3Dep.setGroupId( "maven" );
v3Dep.setArtifactId( "testArtifact" );
v3Dep.setVersion( "1.0" );
v3Dep.setType( "plugin" );
org.apache.maven.model.v3_0_0.Model v3Model = new org.apache.maven.model.v3_0_0.Model();
v3Model.addDependency( v3Dep );
Model result = translator.translate( v3Model, reporter );
Build build = result.getBuild();
Plugin plugin = (Plugin) build.getPlugins().get( 0 );
assertEquals( "org.apache.maven.plugins", plugin.getGroupId() );
assertEquals( "testArtifact", plugin.getArtifactId() );
assertEquals( "1.0", plugin.getVersion() );
}
}