o use a properties file for the repository conversion

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@471157 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2006-11-04 10:17:41 +00:00
parent 55dd88e382
commit 9889093ccd
2 changed files with 46 additions and 50 deletions

View File

@ -31,6 +31,7 @@ import org.codehaus.plexus.component.repository.exception.ComponentLookupExcepti
import java.io.IOException;
import java.io.InputStream;
import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;
import java.util.List;
import java.util.Arrays;
@ -44,6 +45,12 @@ import java.util.Arrays;
*/
public class Cli
{
public static final String SOURCE_REPO_PATH = "sourceRepositoryPath";
public static final String TARGET_REPO_PATH = "targetRepositoryPath";
public static final String BLACKLISTED_PATTERNS = "blacklistPatterns";
public static void main( String[] args )
{
ClassWorld classWorld = new ClassWorld( "plexus.core", Thread.currentThread().getContextClassLoader() );
@ -154,41 +161,43 @@ public class Cli
if ( cli.hasOption( CliManager.CONVERT ) )
{
if ( cli.hasOption( CliManager.OLD_REPOSITORY_PATH ) &&
cli.hasOption( CliManager.NEW_REPOSITORY_PATH ) )
Properties p = new Properties();
try
{
File oldRepositoryPath = new File( cli.getOptionValue( CliManager.OLD_REPOSITORY_PATH ) );
File newRepositoryPath = new File( cli.getOptionValue( CliManager.NEW_REPOSITORY_PATH ) );
System.out.println( "Converting " + oldRepositoryPath + " to " + newRepositoryPath );
List blacklistedPatterns = null;
if ( cli.hasOption( CliManager.BLACKLISTED_PATTERNS ) )
{
blacklistedPatterns = Arrays.asList( StringUtils.split( cli.getOptionValue( CliManager.BLACKLISTED_PATTERNS ), "," ) );
}
try
{
archiva.convertLegacyRepository( oldRepositoryPath, newRepositoryPath, blacklistedPatterns, true );
}
catch ( RepositoryConversionException e )
{
showFatalError( "", e, true );
}
catch ( DiscovererException e )
{
showFatalError( "", e, true );
}
p.load( new FileInputStream( cli.getOptionValue( CliManager.CONVERT ) ) );
}
else
catch ( IOException e )
{
System.out.println(
"You need to specify both a repository to convert and the path for the repository that will be created." );
showFatalError( "Cannot find properties file which describes the conversion.", e, true );
}
cliManager.displayHelp();
File oldRepositoryPath = new File( p.getProperty( SOURCE_REPO_PATH ) );
File newRepositoryPath = new File( p.getProperty( TARGET_REPO_PATH ) );
System.out.println( "Converting " + oldRepositoryPath + " to " + newRepositoryPath );
List blacklistedPatterns = null;
String s = p.getProperty( BLACKLISTED_PATTERNS );
if ( s != null )
{
blacklistedPatterns = Arrays.asList( StringUtils.split( s, "," ) );
}
try
{
archiva.convertLegacyRepository( oldRepositoryPath, newRepositoryPath, blacklistedPatterns, true );
}
catch ( RepositoryConversionException e )
{
showFatalError( "Error converting repository.", e, true );
}
catch ( DiscovererException e )
{
showFatalError( "Error discovery artifacts to convert.", e, true );
}
}
@ -206,8 +215,8 @@ public class Cli
}
private static int showFatalError( String message,
Exception e,
boolean show )
Exception e,
boolean show )
{
System.err.println( "FATAL ERROR: " + message );

View File

@ -19,12 +19,6 @@ public class CliManager
{
public static char CONVERT = 'c';
public static final char OLD_REPOSITORY_PATH = 'o';
public static final char NEW_REPOSITORY_PATH = 'n';
public static final char BLACKLISTED_PATTERNS = 'b';
// ----------------------------------------------------------------------------
// These are standard options that we would want to use for all our projects.
// ----------------------------------------------------------------------------
@ -47,17 +41,10 @@ public class CliManager
{
options = new Options();
options.addOption( OptionBuilder.withLongOpt( "convert" ).withDescription(
"Convert a legacy Maven 1.x repository to a Maven 2.x repository." ).create( CONVERT ) );
options.addOption( OptionBuilder.withLongOpt( "old-repo" ).hasArg().withDescription(
"Path to Maven 1.x legacy repository to convert." ).create( OLD_REPOSITORY_PATH ) );
options.addOption( OptionBuilder.withLongOpt( "new-repo" ).hasArg().withDescription(
"Path to newly created Maven 2.x repository." ).create( NEW_REPOSITORY_PATH ) );
options.addOption( OptionBuilder.withLongOpt( "new-repo" ).hasArg().withDescription(
"Path to newly created Maven 2.x repository." ).create( BLACKLISTED_PATTERNS ) );
options.addOption(
OptionBuilder.withLongOpt( "convert" ).hasArg().withDescription(
"Convert a legacy Maven 1.x repository to a Maven 2.x repository using a properties file to describe the conversion." )
.create( CONVERT ) );
}
public CommandLine parse( String[] args )