From 9889093ccd4e7615c9c0feb9c565551b28bca1a1 Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Sat, 4 Nov 2006 10:17:41 +0000 Subject: [PATCH] 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 --- .../org/apache/maven/archiva/cli/Cli.java | 75 +++++++++++-------- .../apache/maven/archiva/cli/CliManager.java | 21 +----- 2 files changed, 46 insertions(+), 50 deletions(-) diff --git a/archiva-cli/src/main/java/org/apache/maven/archiva/cli/Cli.java b/archiva-cli/src/main/java/org/apache/maven/archiva/cli/Cli.java index 57788c4b4..54fd456d1 100644 --- a/archiva-cli/src/main/java/org/apache/maven/archiva/cli/Cli.java +++ b/archiva-cli/src/main/java/org/apache/maven/archiva/cli/Cli.java @@ -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 ) + { + 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 ); } } @@ -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 ); diff --git a/archiva-cli/src/main/java/org/apache/maven/archiva/cli/CliManager.java b/archiva-cli/src/main/java/org/apache/maven/archiva/cli/CliManager.java index 5b4d2b83f..f4dd59226 100644 --- a/archiva-cli/src/main/java/org/apache/maven/archiva/cli/CliManager.java +++ b/archiva-cli/src/main/java/org/apache/maven/archiva/cli/CliManager.java @@ -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 ) -- 2.39.5