Skip to content
Permalink
Browse files
use a more standard svn layout to be able to use a git mirror
git-svn-id: https://svn.apache.org/repos/asf/archiva/sandbox/trunk@1187785 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
olamy committed Oct 22, 2011
0 parents commit f8bb0483fd0f2c7a91fd54f99f1dfe3b5fad0241
Showing 188 changed files with 23,375 additions and 0 deletions.
@@ -0,0 +1,105 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2005-2006 The Apache Software Foundation.
~
~ Licensed 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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache</groupId>
<artifactId>apache</artifactId>
<version>4</version>
</parent>

<groupId>org.apache.archiva</groupId>
<artifactId>archiva-artifact-downloader-cli</artifactId>
<version>1.2-SNAPSHOT</version>
<name>Archiva Artifact Downloader Client</name>
<packaging>jar</packaging>

<description>
This is an example client for the commons-transfer lib.
</description>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>org.apache.archiva.artifact.downloader.CLI</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>lib</classpathPrefix>
</manifest>
<addMavenDescriptor>true</addMavenDescriptor>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>create-lib-dir</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.apache.archiva.commons.transfer</groupId>
<artifactId>commons-transfer-http</artifactId>
<version>1.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.archiva.commons.transfer</groupId>
<artifactId>commons-transfer-file</artifactId>
<version>1.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
@@ -0,0 +1,91 @@
package org.apache.archiva.artifact.downloader;

/*
* 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.
*/

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* ArtifactKey
*
* @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
* @version $Id$
*/
public class ArtifactKey
{
private String groupId;

private String artifactId;

private String version;

public ArtifactKey()
{
/* default constructor */
}

public ArtifactKey( String mergedKey )
{
Pattern pat = Pattern.compile( "^([^:]*):([^:]*):(.*)$" );
Matcher mat = pat.matcher( mergedKey );
if ( mat.matches() )
{
this.groupId = mat.group( 1 );
this.artifactId = mat.group( 2 );
this.version = mat.group( 3 );
}
else
{
throw new IllegalArgumentException( "Key \"" + mergedKey
+ "\" is not a merged key in the format \"groupId:artifactId:version\"." );
}
}

public String getArtifactId()
{
return artifactId;
}

public String getGroupId()
{
return groupId;
}

public String getVersion()
{
return version;
}

public void setArtifactId( String artifactId )
{
this.artifactId = artifactId;
}

public void setGroupId( String groupId )
{
this.groupId = groupId;
}

public void setVersion( String version )
{
this.version = version;
}

}
@@ -0,0 +1,196 @@
package org.apache.archiva.artifact.downloader;

/*
* 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.
*/

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import javax.swing.SwingUtilities;

import org.apache.archiva.artifact.downloader.config.Config;
import org.apache.archiva.artifact.downloader.config.ConfigParser;
import org.apache.archiva.commons.transfer.interactive.NetworkProxyDialog;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.MissingOptionException;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.xml.sax.SAXException;

/**
* CLI
*
* @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
* @version $Id$
*/
public class CLI
{
private static final String OPT_PROXY_CONFIG = "proxy-config";

private static final String OPT_HELP = "?";

private static final String OPT_REPO_DIR = "o";

private static final String OPT_CONFIG = "c";

public static void main( String[] args )
{
( new CLI() ).execute( args );
}

private Options options;

private void execute( String[] args )
{
CommandLineParser parser = new GnuParser();
try
{
CommandLine cmdline = parser.parse( getOptions(), args );

if ( cmdline.hasOption( OPT_HELP ) )
{
showHelp( getOptions() );
return;
}

if ( cmdline.hasOption( OPT_PROXY_CONFIG ) )
{
SwingUtilities.invokeLater( new Runnable()
{
public void run()
{
NetworkProxyDialog.collectAndSave();
System.exit( -1 );
}
} );
return;
}

List<ArtifactKey> artifactKeys = new ArrayList<ArtifactKey>();
for ( String arg : cmdline.getArgs() )
{
artifactKeys.add( new ArtifactKey( arg ) );
}

if ( artifactKeys.isEmpty() )
{
System.err
.println( "ERROR: You must specify at least 1 Artifact Key in format groupId:artifactId:version" );
showHelp( getOptions() );
return;
}

Config config = loadDefaultConfig();

if ( cmdline.hasOption( OPT_CONFIG ) )
{
String configPath = cmdline.getOptionValue( OPT_CONFIG );
File configFile = new File( configPath );
if ( configFile.exists() == false )
{
System.err.println( "Unable to find config file: " + configFile.getAbsolutePath() );
return;
}
FileReader reader = new FileReader( configFile );
config = ConfigParser.parseConfig( reader );
}

String outputDir = cmdline.getOptionValue( OPT_REPO_DIR );
if ( outputDir == null )
{
outputDir = System.getProperty( "user.dir" );
}

File repoDir = new File( outputDir );
System.out.println( ".\\ Archiva Artifact Downloader \\._______________" );

Downloader downloader = new Downloader();
downloader.setArtifactKeys( artifactKeys );
downloader.setRepositoryDir( repoDir );
downloader.setConfig( config );
downloader.download();
}
catch ( MissingOptionException e )
{
System.err.println( "ERROR: " + e.getMessage() );
showHelp( options );
}
catch ( ParseException e )
{
showHelp( options );
e.printStackTrace( System.err );
}
catch ( Throwable t )
{
t.printStackTrace( System.err );
}
}

private Options getOptions()
{
if ( options != null )
{
return options;
}

Option repoDir = new Option( OPT_REPO_DIR, "repoDir", true, "Repository Root Directory." );
repoDir.setArgName( "dir" );
repoDir.setRequired( false );

Option configFile = new Option( OPT_CONFIG, "configFile", true, "Config File." );
configFile.setArgName( "file" );
configFile.setRequired( false );

Option proxyConfig = OptionBuilder.withLongOpt( OPT_PROXY_CONFIG )
.withDescription( "Network Proxy Configuration UI" )
.isRequired( false ).create();

Option help = new Option( OPT_HELP, "help", false, "Help" );
help.setRequired( false );

options = new Options();
options.addOption( repoDir );
options.addOption( configFile );
options.addOption( proxyConfig );
options.addOption( help );

return options;
}

private Config loadDefaultConfig()
throws IOException, SAXException
{
// Find the config in the jar.
URL url = this.getClass().getClassLoader().getResource( "artifact-downloader.xml" );
InputStreamReader reader = new InputStreamReader( url.openStream() );
return ConfigParser.parseConfig( reader );
}

private void showHelp( Options options )
{
HelpFormatter help = new HelpFormatter();
help.printHelp( "ArtifactDownloader.jar [options] [ [groupId:artifactId:version] ... ]", options );
}
}

0 comments on commit f8bb048

Please sign in to comment.