diff options
author | Brett Porter <brett@apache.org> | 2008-04-07 13:13:06 +0000 |
---|---|---|
committer | Brett Porter <brett@apache.org> | 2008-04-07 13:13:06 +0000 |
commit | 28d9a2384a42236eef4274e163335ff3b32bbe0b (patch) | |
tree | 8e76bfcf1d610985ef7c95bc2bedcdef9326374e /archiva-cli/src | |
parent | 82f8c7d05f6346413591a0b5599342f1a7e775ec (diff) | |
download | archiva-28d9a2384a42236eef4274e163335ff3b32bbe0b.tar.gz archiva-28d9a2384a42236eef4274e163335ff3b32bbe0b.zip |
refreshed the CLI
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@645493 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-cli/src')
6 files changed, 133 insertions, 197 deletions
diff --git a/archiva-cli/src/main/assembly/archiva-cli-assembly.xml b/archiva-cli/src/main/assembly/archiva-cli-assembly.xml index 187b457ac..7b81464b4 100644 --- a/archiva-cli/src/main/assembly/archiva-cli-assembly.xml +++ b/archiva-cli/src/main/assembly/archiva-cli-assembly.xml @@ -38,6 +38,10 @@ <outputDirectory>/</outputDirectory> <unpack>true</unpack> <scope>runtime</scope> + <excludes> + <exclude>xml-apis:xml-apis</exclude> + <exclude>xalan:xalan</exclude> + </excludes> </dependencySet> </dependencySets> </assembly> diff --git a/archiva-cli/src/main/java/org/apache/maven/archiva/cli/ArchivaCli.java b/archiva-cli/src/main/java/org/apache/maven/archiva/cli/ArchivaCli.java index 815747701..c2e98049e 100644 --- a/archiva-cli/src/main/java/org/apache/maven/archiva/cli/ArchivaCli.java +++ b/archiva-cli/src/main/java/org/apache/maven/archiva/cli/ArchivaCli.java @@ -19,60 +19,49 @@ package org.apache.maven.archiva.cli; * under the License. */ -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.consumers.ConsumerException; +import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer; +import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; import org.apache.maven.archiva.consumers.RepositoryContentConsumer; import org.apache.maven.archiva.converter.RepositoryConversionException; import org.apache.maven.archiva.converter.legacy.LegacyRepositoryConverter; import org.apache.maven.archiva.repository.RepositoryException; import org.apache.maven.archiva.repository.scanner.RepositoryScanStatistics; import org.apache.maven.archiva.repository.scanner.RepositoryScanner; -import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; -import org.codehaus.plexus.tools.cli.AbstractCli; +import org.codehaus.plexus.spring.PlexusClassPathXmlApplicationContext; +import org.codehaus.plexus.spring.PlexusToSpringUtils; + +import com.sampullara.cli.Args; +import com.sampullara.cli.Argument; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; /** - * ArchivaCli - * + * ArchivaCli + * + * @todo add back reading of archiva.xml from a given location * @author Jason van Zyl * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> * @version $Id$ */ public class ArchivaCli - extends AbstractCli { // ---------------------------------------------------------------------------- - // Options - // ---------------------------------------------------------------------------- - - public static final char CONVERT = 'c'; - - public static final char SCAN = 's'; - - public static final char CONSUMERS = 'u'; - - public static final char LIST_CONSUMERS = 'l'; - - public static final char DUMP_CONFIGURATION = 'd'; - - // ---------------------------------------------------------------------------- // Properties controlling Repository conversion // ---------------------------------------------------------------------------- @@ -82,111 +71,102 @@ public class ArchivaCli public static final String BLACKLISTED_PATTERNS = "blacklistPatterns"; - /** - * Configuration store. - * - * @plexus.requirement - */ - private ArchivaConfiguration archivaConfiguration; - - public static void main( String[] args ) - throws Exception + private static String getVersion() + throws IOException { - new ArchivaCli().execute( args ); + Properties properties = new Properties(); + properties.load( ArchivaCli.class.getResourceAsStream( "/META-INF/maven/org.apache.archiva/archiva-cli/pom.properties" ) ); + return properties.getProperty( "version" ); } - public String getPomPropertiesPath() - { - return "META-INF/maven/org.apache.maven.archiva/archiva-cli/pom.properties"; - } + private PlexusClassPathXmlApplicationContext applicationContext; - private Option createOption( char shortOpt, String longOpt, int argCount, String description ) + public ArchivaCli() { - boolean hasArg = ( argCount > 0 ); - Option opt = new Option( String.valueOf( shortOpt ), hasArg, description ); - opt.setLongOpt( longOpt ); - if ( hasArg ) - { - opt.setArgs( argCount ); - } - return opt; + applicationContext = + new PlexusClassPathXmlApplicationContext( new String[] { "classpath*:/META-INF/spring-context.xml", + "classpath*:/META-INF/plexus/components.xml" } ); } - public Options buildCliOptions( Options options ) + public static void main( String[] args ) + throws Exception { - Option convertOption = createOption( CONVERT, "convert", 1, "Convert a legacy Maven 1.x repository to a " - + "Maven 2.x repository using a properties file to describe the conversion." ); - convertOption.setArgName( "conversion.properties" ); - options.addOption( convertOption ); - - Option scanOption = createOption( SCAN, "scan", 1, "Scan the specified repository." ); - scanOption.setArgName( "repository directory" ); - options.addOption( scanOption ); - - Option consumerOption = createOption( CONSUMERS, "consumers", 1, "The consumers to use. " - + "(comma delimited. default: 'count-artifacts')" ); - consumerOption.setArgName( "consumer list" ); - options.addOption( consumerOption ); - - Option listConsumersOption = createOption( LIST_CONSUMERS, "listconsumers", 0, "List available consumers." ); - options.addOption( listConsumersOption ); + Commands command = new Commands(); - Option dumpConfig = createOption( DUMP_CONFIGURATION, "dumpconfig", 0, "Dump Current Configuration." ); - options.addOption( dumpConfig ); + try + { + Args.parse( command, args ); + } + catch ( IllegalArgumentException e ) + { + System.err.println( e.getMessage() ); + Args.usage( command ); + return; + } - return options; + new ArchivaCli().execute( command ); } - public void invokePlexusComponent( CommandLine cli, PlexusContainer plexus ) + private void execute( Commands command ) throws Exception { - if ( cli.hasOption( CONVERT ) ) + if ( command.help ) + { + Args.usage( command ); + } + else if ( command.version ) { - doConversion( cli, plexus ); + System.out.print( "Version: " + getVersion() ); } - else if ( cli.hasOption( SCAN ) ) + else if ( command.convert ) { - doScan( cli, plexus ); + doConversion( command.properties ); } - else if ( cli.hasOption( LIST_CONSUMERS ) ) + else if ( command.scan ) { - dumpAvailableConsumers( plexus ); + if ( command.repository == null ) + { + System.err.println( "The repository must be specified." ); + Args.usage( command ); + return; + } + + doScan( command.repository, command.consumers.split( "," ) ); } - else if ( cli.hasOption( DUMP_CONFIGURATION ) ) + else if ( command.listConsumers ) { - dumpConfiguration( plexus ); + dumpAvailableConsumers(); } else { - displayHelp(); + Args.usage( command ); } } - private void doScan( CommandLine cli, PlexusContainer plexus ) - throws ConsumerException, ComponentLookupException + private void doScan( String path, String[] consumers ) + throws ConsumerException { - String path = cli.getOptionValue( SCAN ); - ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration(); repo.setId( "cliRepo" ); repo.setName( "Archiva CLI Provided Repo" ); repo.setLocation( path ); - List knownConsumerList = new ArrayList(); + List<KnownRepositoryContentConsumer> knownConsumerList = new ArrayList<KnownRepositoryContentConsumer>(); - knownConsumerList.addAll( getConsumerList( cli, plexus ) ); + knownConsumerList.addAll( getConsumerList( consumers ) ); - List invalidConsumerList = Collections.EMPTY_LIST; + List<InvalidRepositoryContentConsumer> invalidConsumerList = Collections.emptyList(); - List ignoredContent = new ArrayList(); + List<String> ignoredContent = new ArrayList<String>(); ignoredContent.addAll( Arrays.asList( RepositoryScanner.IGNORABLE_CONTENT ) ); - RepositoryScanner scanner = (RepositoryScanner) plexus.lookup( RepositoryScanner.class ); + RepositoryScanner scanner = (RepositoryScanner) lookup( RepositoryScanner.class ); try { - RepositoryScanStatistics stats = scanner.scan( repo, knownConsumerList, invalidConsumerList, - ignoredContent, RepositoryScanner.FRESH_SCAN ); + RepositoryScanStatistics stats = + scanner.scan( repo, knownConsumerList, invalidConsumerList, ignoredContent, + RepositoryScanner.FRESH_SCAN ); System.out.println( "\n" + stats.toDump( repo ) ); } @@ -196,29 +176,24 @@ public class ArchivaCli } } - private Collection getConsumerList( CommandLine cli, PlexusContainer plexus ) - throws ComponentLookupException, ConsumerException + private Object lookup( Class<?> clazz ) { - String specifiedConsumers = "count-artifacts"; - - if ( cli.hasOption( CONSUMERS ) ) - { - specifiedConsumers = cli.getOptionValue( CONSUMERS ); - } - - List consumerList = new ArrayList(); + return applicationContext.getBean( PlexusToSpringUtils.buildSpringId( clazz.getName(), null ) ); + } - Map availableConsumers = plexus.lookupMap( RepositoryContentConsumer.class ); + private List<KnownRepositoryContentConsumer> getConsumerList( String[] consumers ) + throws ConsumerException + { + List<KnownRepositoryContentConsumer> consumerList = new ArrayList<KnownRepositoryContentConsumer>(); - String consumerArray[] = StringUtils.split( specifiedConsumers, ',' ); + Map<String, KnownRepositoryContentConsumer> availableConsumers = getConsumers(); - for ( int i = 0; i < consumerArray.length; i++ ) + for ( String specifiedConsumer : consumers ) { - String specifiedConsumer = consumerArray[i]; if ( !availableConsumers.containsKey( specifiedConsumer ) ) { System.err.println( "Specified consumer [" + specifiedConsumer + "] not found." ); - dumpAvailableConsumers( plexus ); + dumpAvailableConsumers(); System.exit( 1 ); } @@ -228,16 +203,14 @@ public class ArchivaCli return consumerList; } - private void dumpAvailableConsumers( PlexusContainer plexus ) - throws ComponentLookupException + private void dumpAvailableConsumers() { - Map availableConsumers = plexus.lookupMap( RepositoryContentConsumer.class ); + Map<String, KnownRepositoryContentConsumer> availableConsumers = getConsumers(); System.out.println( ".\\ Available Consumer List \\.______________________________" ); - for ( Iterator iter = availableConsumers.entrySet().iterator(); iter.hasNext(); ) + for ( Map.Entry<String, KnownRepositoryContentConsumer> entry : availableConsumers.entrySet() ) { - Map.Entry entry = (Map.Entry) iter.next(); String consumerHint = (String) entry.getKey(); RepositoryContentConsumer consumer = (RepositoryContentConsumer) entry.getValue(); System.out.println( " " + consumerHint + ": " + consumer.getDescription() + " (" @@ -245,22 +218,21 @@ public class ArchivaCli } } - private void doConversion( CommandLine cli, PlexusContainer plexus ) - throws ComponentLookupException + @SuppressWarnings("unchecked") + private Map<String, KnownRepositoryContentConsumer> getConsumers() { - LegacyRepositoryConverter legacyRepositoryConverter = (LegacyRepositoryConverter) plexus - .lookup( LegacyRepositoryConverter.ROLE ); + return PlexusToSpringUtils.lookupMap( "knownRepositoryContentConsumer", applicationContext ); + } + + private void doConversion( String properties ) + throws FileNotFoundException, IOException, RepositoryConversionException + { + LegacyRepositoryConverter legacyRepositoryConverter = + (LegacyRepositoryConverter) lookup( LegacyRepositoryConverter.class ); Properties p = new Properties(); - try - { - p.load( new FileInputStream( cli.getOptionValue( CONVERT ) ) ); - } - catch ( IOException e ) - { - showFatalError( "Cannot find properties file which describes the conversion.", e, true ); - } + p.load( new FileInputStream( properties ) ); File oldRepositoryPath = new File( p.getProperty( SOURCE_REPO_PATH ) ); @@ -268,7 +240,7 @@ public class ArchivaCli System.out.println( "Converting " + oldRepositoryPath + " to " + newRepositoryPath ); - List fileExclusionPatterns = null; + List<String> fileExclusionPatterns = null; String s = p.getProperty( BLACKLISTED_PATTERNS ); @@ -277,23 +249,33 @@ public class ArchivaCli fileExclusionPatterns = Arrays.asList( StringUtils.split( s, "," ) ); } - try - { - legacyRepositoryConverter.convertLegacyRepository( oldRepositoryPath, newRepositoryPath, - fileExclusionPatterns ); - } - catch ( RepositoryConversionException e ) - { - showFatalError( "Error converting repository.", e, true ); - } + legacyRepositoryConverter.convertLegacyRepository( oldRepositoryPath, newRepositoryPath, fileExclusionPatterns ); } - private void dumpConfiguration( PlexusContainer plexus ) - throws ComponentLookupException + private static class Commands { - archivaConfiguration = (ArchivaConfiguration) plexus.lookup( ArchivaConfiguration.ROLE, "cli" ); + @Argument( description = "Display help information", value = "help", alias = "h" ) + private boolean help; + + @Argument( description = "Display version information", value = "version", alias = "v" ) + private boolean version; + + @Argument( description = "List available consumers", value = "listconsumers", alias = "l" ) + private boolean listConsumers; + + @Argument( description = "The consumers to use (comma delimited)", value = "consumers", alias = "u" ) + private String consumers = "count-artifacts"; + + @Argument( description = "Scan the specified repository", value = "scan", alias = "s" ) + private boolean scan; + + @Argument( description = "Convert a legacy Maven 1.x repository to a Maven 2.x repository using a properties file to describe the conversion", value = "convert", alias = "c" ) + private boolean convert; + + @Argument( description = "The properties file for the converstion", value = "properties" ) + private String properties = "conversion.properties"; - System.out.println( "File Type Count: " - + archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().size() ); + @Argument( description = "The repository to scan", value = "repository" ) + private String repository; } } diff --git a/archiva-cli/src/main/java/org/apache/maven/archiva/cli/ArtifactCountConsumer.java b/archiva-cli/src/main/java/org/apache/maven/archiva/cli/ArtifactCountConsumer.java index 7c9aa368f..37fc78020 100644 --- a/archiva-cli/src/main/java/org/apache/maven/archiva/cli/ArtifactCountConsumer.java +++ b/archiva-cli/src/main/java/org/apache/maven/archiva/cli/ArtifactCountConsumer.java @@ -19,24 +19,24 @@ package org.apache.maven.archiva.cli; * under the License. */ -import org.apache.maven.archiva.consumers.RepositoryContentConsumer; - import java.util.ArrayList; import java.util.List; +import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; + /** * ArtifactCountConsumer * * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> * @version $Id$ * - * @plexus.component role="org.apache.maven.archiva.consumers.RepositoryContentConsumer" + * @plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer" * role-hint="count-artifacts" * instantiation-strategy="per-lookup" */ public class ArtifactCountConsumer extends AbstractProgressConsumer - implements RepositoryContentConsumer + implements KnownRepositoryContentConsumer { /** * @plexus.configuration default-value="count-artifacts" diff --git a/archiva-cli/src/main/java/org/apache/maven/archiva/cli/ProjectReaderConsumer.java b/archiva-cli/src/main/java/org/apache/maven/archiva/cli/ProjectReaderConsumer.java index 1a6511270..04f52768d 100644 --- a/archiva-cli/src/main/java/org/apache/maven/archiva/cli/ProjectReaderConsumer.java +++ b/archiva-cli/src/main/java/org/apache/maven/archiva/cli/ProjectReaderConsumer.java @@ -19,31 +19,31 @@ package org.apache.maven.archiva.cli; * under the License. */ +import java.io.File; +import java.util.ArrayList; +import java.util.List; + import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.consumers.ConsumerException; -import org.apache.maven.archiva.consumers.RepositoryContentConsumer; +import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; import org.apache.maven.archiva.model.ArchivaProjectModel; import org.apache.maven.archiva.repository.project.ProjectModelException; import org.apache.maven.archiva.repository.project.ProjectModelReader; import org.apache.maven.archiva.repository.project.readers.ProjectModel400Reader; -import java.io.File; -import java.util.ArrayList; -import java.util.List; - /** * ProjectReaderConsumer * * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> * @version $Id$ * - * @plexus.component role="org.apache.maven.archiva.consumers.RepositoryContentConsumer" + * @plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer" * role-hint="read-poms" * instantiation-strategy="per-lookup" */ public class ProjectReaderConsumer extends AbstractProgressConsumer - implements RepositoryContentConsumer + implements KnownRepositoryContentConsumer { /** * @plexus.configuration default-value="read-poms" diff --git a/archiva-cli/src/main/resources/META-INF/plexus/components.xml b/archiva-cli/src/main/resources/META-INF/plexus/components.xml deleted file mode 100644 index ad355c655..000000000 --- a/archiva-cli/src/main/resources/META-INF/plexus/components.xml +++ /dev/null @@ -1,50 +0,0 @@ -<?xml version="1.0" encoding="ISO-8859-1"?> -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one - ~ or more contributor license agreements. See the NOTICE file - ~ distributed with this work for additional information - ~ regarding copyright ownership. The ASF licenses this file - ~ to you 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. ---> -<component-set> - <components> - <component> - <role>org.codehaus.plexus.registry.Registry</role> - <implementation> - org.codehaus.plexus.registry.commons.CommonsConfigurationRegistry - </implementation> - <role-hint>commons-configuration</role-hint> - <configuration> - <properties> - <system /> - <xml fileName="${appserver.base}/conf/archiva.xml" - config-optional="true" - config-name="org.apache.maven.archiva.base" - config-at="org.apache.maven.archiva" /> - <xml fileName="${appserver.home}/conf/archiva.xml" - config-optional="true" - config-at="org.apache.maven.archiva" /> - <xml fileName="${user.home}/.m2/archiva.xml" - config-optional="true" - config-name="org.apache.maven.archiva.user" - config-at="org.apache.maven.archiva" /> - <xml - fileName="org/apache/maven/archiva/configuration/default-archiva.xml" - config-optional="true" - config-at="org.apache.maven.archiva" /> - </properties> - </configuration> - </component> - </components> -</component-set>
\ No newline at end of file diff --git a/archiva-cli/src/main/resources/log4j.properties b/archiva-cli/src/main/resources/log4j.properties index 6d107570b..ff5b14c77 100644 --- a/archiva-cli/src/main/resources/log4j.properties +++ b/archiva-cli/src/main/resources/log4j.properties @@ -1,10 +1,10 @@ # Set root logger level to DEBUG and its only appender to A1. -log4j.rootLogger=INFO, A1 +log4j.rootLogger=ERROR, A1 # A1 is set to be a ConsoleAppender. log4j.appender.A1=org.apache.log4j.ConsoleAppender # A1 uses PatternLayout. log4j.appender.A1.layout=org.apache.log4j.PatternLayout -log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n +log4j.appender.A1.layout.ConversionPattern=[%t] %-5p %c %x - %m%n |