Browse Source

refreshed the CLI


git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@645493 13f79535-47bb-0310-9956-ffa450edef68
tags/archiva-r676265
Brett Porter 16 years ago
parent
commit
28d9a2384a

+ 41
- 41
archiva-cli/pom.xml View File

@@ -35,44 +35,63 @@
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-core-consumers</artifactId>
<artifactId>archiva-dependency-tree-consumer</artifactId>
<version>1.1-SNAPSHOT</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-converter</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-digest</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-api</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
<artifactId>archiva-xml-tools</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-cli</artifactId>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-converter</artifactId>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<groupId>com.google.code.cli-parser</groupId>
<artifactId>cli</artifactId>
<version>7</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus.registry</groupId>
<artifactId>plexus-registry-commons</artifactId>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.0</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>apache-archiva-cli-${project.version}</finalName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ComponentsXmlResourceTransformer" />
</transformers>
<artifactSet>
<excludes>
<exclude>xml-apis:xml-apis</exclude>
<exclude>xalan:xalan</exclude>
<exclude>commons-beanutils:commons-beanutils</exclude>
</excludes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.1</version>
<configuration>
<descriptor>src/main/assembly/archiva-cli-assembly.xml</descriptor>
<archive>
<manifest>
<mainClass>org.apache.maven.archiva.cli.ArchivaCli</mainClass>
@@ -80,25 +99,6 @@
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-maven-plugin</artifactId>
<version>1.3.5</version>
<executions>
<execution>
<id>merge</id>
<goals>
<goal>merge-descriptors</goal>
</goals>
<configuration>
<descriptors>
<descriptor>${basedir}/src/main/resources/META-INF/plexus/components.xml</descriptor>
<descriptor>${project.build.directory}/generated-resources/plexus/META-INF/plexus/components.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

+ 4
- 0
archiva-cli/src/main/assembly/archiva-cli-assembly.xml View File

@@ -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>

+ 116
- 134
archiva-cli/src/main/java/org/apache/maven/archiva/cli/ArchivaCli.java View File

@@ -19,59 +19,48 @@ 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;
}
}

+ 4
- 4
archiva-cli/src/main/java/org/apache/maven/archiva/cli/ArtifactCountConsumer.java View File

@@ -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"

+ 7
- 7
archiva-cli/src/main/java/org/apache/maven/archiva/cli/ProjectReaderConsumer.java View File

@@ -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"

+ 0
- 50
archiva-cli/src/main/resources/META-INF/plexus/components.xml View File

@@ -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>

+ 2
- 2
archiva-cli/src/main/resources/log4j.properties View File

@@ -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


Loading…
Cancel
Save