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;
*/
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() );
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 )
+ {
+ showFatalError( "Cannot find properties file which describes the conversion.", e, true );
+ }
+
+ 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 )
{
- System.out.println(
- "You need to specify both a repository to convert and the path for the repository that will be created." );
+ blacklistedPatterns = Arrays.asList( StringUtils.split( s, "," ) );
+ }
- cliManager.displayHelp();
+ 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 );
}
}
}
private static int showFatalError( String message,
- Exception e,
- boolean show )
+ Exception e,
+ boolean show )
{
System.err.println( "FATAL ERROR: " + message );
{
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.
// ----------------------------------------------------------------------------
{
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 )