]> source.dussan.org Git - archiva.git/commitdiff
o use a properties file for the repository conversion
authorJason van Zyl <jvanzyl@apache.org>
Sat, 4 Nov 2006 10:17:41 +0000 (10:17 +0000)
committerJason van Zyl <jvanzyl@apache.org>
Sat, 4 Nov 2006 10:17:41 +0000 (10:17 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@471157 13f79535-47bb-0310-9956-ffa450edef68

archiva-cli/src/main/java/org/apache/maven/archiva/cli/Cli.java
archiva-cli/src/main/java/org/apache/maven/archiva/cli/CliManager.java

index 57788c4b4c142dafa33d09580cc08c848973be97..54fd456d1dbf67f46635c0086f4bad498128b624 100644 (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 )
+                {
+                    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 );
 
index 5b4d2b83fa70b46fc891d12e175e17e3c7d3c13a..f4dd5922615a4cbf745c4c1d200ac76e2ad4d447 100644 (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 )