You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by jo...@apache.org on 2008/05/02 22:34:36 UTC

svn commit: r652898 - in /archiva/sandbox/archiva-artifact-downloader-cli: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/archiva/ src/main/java/org/apache/archiva/artifact/ src/main/java/org/apac...

Author: joakime
Date: Fri May  2 13:34:35 2008
New Revision: 652898

URL: http://svn.apache.org/viewvc?rev=652898&view=rev
Log:
Importing utility for downloading content from remote repos, used as an example client for the commons-transfer libs.

Added:
    archiva/sandbox/archiva-artifact-downloader-cli/   (with props)
    archiva/sandbox/archiva-artifact-downloader-cli/pom.xml
    archiva/sandbox/archiva-artifact-downloader-cli/src/
    archiva/sandbox/archiva-artifact-downloader-cli/src/main/
    archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/
    archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/
    archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/
    archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/
    archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/
    archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/
    archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/ArtifactKey.java   (with props)
    archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/CLI.java   (with props)
    archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/Downloader.java   (with props)
    archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/LayoutUtil.java   (with props)
    archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/Repository.java   (with props)
    archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/config/
    archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/config/Config.java   (with props)
    archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/config/ConfigParser.java   (with props)
    archiva/sandbox/archiva-artifact-downloader-cli/src/main/resources/
    archiva/sandbox/archiva-artifact-downloader-cli/src/main/resources/artifact-downloader.xml
    archiva/sandbox/archiva-artifact-downloader-cli/src/test/
    archiva/sandbox/archiva-artifact-downloader-cli/src/test/java/
    archiva/sandbox/archiva-artifact-downloader-cli/src/test/java/org/
    archiva/sandbox/archiva-artifact-downloader-cli/src/test/java/org/apache/
    archiva/sandbox/archiva-artifact-downloader-cli/src/test/java/org/apache/archiva/
    archiva/sandbox/archiva-artifact-downloader-cli/src/test/java/org/apache/archiva/artifact/
    archiva/sandbox/archiva-artifact-downloader-cli/src/test/java/org/apache/archiva/artifact/downloader/
    archiva/sandbox/archiva-artifact-downloader-cli/src/test/java/org/apache/archiva/artifact/downloader/ArtifactKeyTest.java   (with props)
    archiva/sandbox/archiva-artifact-downloader-cli/src/test/java/org/apache/archiva/artifact/downloader/LayoutUtilTest.java   (with props)
    archiva/sandbox/archiva-artifact-downloader-cli/src/test/java/org/apache/archiva/artifact/downloader/config/
    archiva/sandbox/archiva-artifact-downloader-cli/src/test/java/org/apache/archiva/artifact/downloader/config/ConfigParserTest.java   (with props)
    archiva/sandbox/archiva-artifact-downloader-cli/src/test/resources/
    archiva/sandbox/archiva-artifact-downloader-cli/src/test/resources/config/
    archiva/sandbox/archiva-artifact-downloader-cli/src/test/resources/config/artifact-downloader.xml

Propchange: archiva/sandbox/archiva-artifact-downloader-cli/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri May  2 13:34:35 2008
@@ -0,0 +1,4 @@
+target
+.project
+.settings
+.classpath

Added: archiva/sandbox/archiva-artifact-downloader-cli/pom.xml
URL: http://svn.apache.org/viewvc/archiva/sandbox/archiva-artifact-downloader-cli/pom.xml?rev=652898&view=auto
==============================================================================
--- archiva/sandbox/archiva-artifact-downloader-cli/pom.xml (added)
+++ archiva/sandbox/archiva-artifact-downloader-cli/pom.xml Fri May  2 13:34:35 2008
@@ -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.0-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.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.archiva.commons.transfer</groupId>
+      <artifactId>commons-transfer-file</artifactId>
+      <version>1.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+</project>

Added: archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/ArtifactKey.java
URL: http://svn.apache.org/viewvc/archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/ArtifactKey.java?rev=652898&view=auto
==============================================================================
--- archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/ArtifactKey.java (added)
+++ archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/ArtifactKey.java Fri May  2 13:34:35 2008
@@ -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;
+    }
+
+}

Propchange: archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/ArtifactKey.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/ArtifactKey.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/CLI.java
URL: http://svn.apache.org/viewvc/archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/CLI.java?rev=652898&view=auto
==============================================================================
--- archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/CLI.java (added)
+++ archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/CLI.java Fri May  2 13:34:35 2008
@@ -0,0 +1,194 @@
+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.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 );
+    }
+}

Propchange: archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/CLI.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/CLI.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/Downloader.java
URL: http://svn.apache.org/viewvc/archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/Downloader.java?rev=652898&view=auto
==============================================================================
--- archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/Downloader.java (added)
+++ archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/Downloader.java Fri May  2 13:34:35 2008
@@ -0,0 +1,187 @@
+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.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.archiva.artifact.downloader.config.Config;
+import org.apache.archiva.commons.transfer.Transfer;
+import org.apache.archiva.commons.transfer.TransferDownloader;
+import org.apache.archiva.commons.transfer.TransferException;
+import org.apache.archiva.commons.transfer.TransferFactory;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Downloader
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class Downloader
+{
+    class DownloadTask
+    {
+        public URI remoteRepoRelURI;
+
+        public File localFile;
+
+        public DownloadTask checkfile( String ext )
+            throws URISyntaxException
+        {
+            DownloadTask checktask = new DownloadTask();
+            checktask.remoteRepoRelURI = new URI( this.remoteRepoRelURI.toASCIIString() + ext );
+            checktask.localFile = new File( this.localFile.getAbsolutePath() + ext );
+            return checktask;
+        }
+    }
+
+    private File repositoryDir;
+
+    private List<ArtifactKey> artifactKeys = new ArrayList<ArtifactKey>();
+
+    private Config config;
+
+    private List<DownloadTask> createDownloadTasks( LayoutUtil layout, Repository repository, ArtifactKey key )
+        throws URISyntaxException
+    {
+        List<DownloadTask> tasks = new ArrayList<DownloadTask>();
+
+        // Jar
+        DownloadTask jarTask = createTask( layout, repository, key, null, "jar" );
+        tasks.add( jarTask );
+        tasks.add( jarTask.checkfile( ".sha1" ) );
+        tasks.add( jarTask.checkfile( ".md5" ) );
+        // Pom
+        DownloadTask pomTask = createTask( layout, repository, key, null, "pom" );
+        tasks.add( pomTask );
+        tasks.add( pomTask.checkfile( ".sha1" ) );
+        tasks.add( pomTask.checkfile( ".md5" ) );
+        // Sources
+        DownloadTask sourcesTask = createTask( layout, repository, key, "sources", "jar" );
+        tasks.add( sourcesTask );
+        tasks.add( sourcesTask.checkfile( ".sha1" ) );
+        tasks.add( sourcesTask.checkfile( ".md5" ) );
+        // Javadoc
+        DownloadTask javadocTask = createTask( layout, repository, key, "javadoc", "jar" );
+        tasks.add( javadocTask );
+        tasks.add( javadocTask.checkfile( ".sha1" ) );
+        tasks.add( javadocTask.checkfile( ".md5" ) );
+
+        return tasks;
+    }
+
+    private DownloadTask createTask( LayoutUtil layout, Repository repository, ArtifactKey key, String classifier,
+                                     String type )
+        throws URISyntaxException
+    {
+        DownloadTask task = new DownloadTask();
+        String format = layout.format( repository.getLayout(), key.getGroupId(), key.getArtifactId(), key.getVersion(),
+                                       classifier, type );
+        task.remoteRepoRelURI = new URI( format );
+        task.localFile = new File( this.repositoryDir, layout.format( "default", key.getGroupId(), key.getArtifactId(),
+                                                                      key.getVersion(), classifier, type ) );
+        return task;
+    }
+
+    public void download()
+        throws TransferException, IOException, URISyntaxException
+    {
+        for ( ArtifactKey key : artifactKeys )
+        {
+            downloadFromAllRepos( key );
+        }
+    }
+
+    private void downloadFromAllRepos( ArtifactKey key )
+        throws TransferException, IOException, URISyntaxException
+    {
+        LayoutUtil layout = new LayoutUtil( this.config );
+        List<DownloadTask> downloadTasks;
+        Transfer transfer;
+        TransferDownloader transferDownloader;
+        for ( Repository repository : config.getRepositories() )
+        {
+            transfer = TransferFactory.getTransfer( repository.getRootUri() );
+            System.out.println( "URI: " + repository.getRootUri().toASCIIString() );
+            transferDownloader = transfer.getDownloader( repository.getRootUri() );
+
+            downloadTasks = createDownloadTasks( layout, repository, key );
+
+            for ( DownloadTask task : downloadTasks )
+            {
+                if ( task.localFile.exists() )
+                {
+                    System.out.println( "Task Skipped (local file exists): " + task.localFile.getAbsolutePath() );
+                    continue;
+                }
+
+                File tmpFile = File.createTempFile( "artifact-download.", ".dat" );
+                try
+                {
+                    transferDownloader.download( task.remoteRepoRelURI, tmpFile );
+                    if ( tmpFile.exists() && tmpFile.length() > 0 )
+                    {
+                        System.out.println( "Successful Transfer: " + task.localFile );
+                        FileUtils.copyFile( tmpFile, task.localFile );
+                    }
+                }
+                catch ( TransferException e )
+                {
+                    System.out.println( "Transfer Warning: " + e.getMessage() );
+                }
+                finally
+                {
+                    tmpFile.delete();
+                }
+            }
+        }
+    }
+
+    public List<ArtifactKey> getArtifactKeys()
+    {
+        return artifactKeys;
+    }
+
+    public Config getConfig()
+    {
+        return config;
+    }
+
+    public File getRepositoryDir()
+    {
+        return repositoryDir;
+    }
+
+    public void setArtifactKeys( List<ArtifactKey> artifactKeys )
+    {
+        this.artifactKeys = artifactKeys;
+    }
+
+    public void setConfig( Config config )
+    {
+        this.config = config;
+    }
+
+    public void setRepositoryDir( File repositoryDir )
+    {
+        this.repositoryDir = repositoryDir;
+    }
+}

Propchange: archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/Downloader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/Downloader.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/LayoutUtil.java
URL: http://svn.apache.org/viewvc/archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/LayoutUtil.java?rev=652898&view=auto
==============================================================================
--- archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/LayoutUtil.java (added)
+++ archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/LayoutUtil.java Fri May  2 13:34:35 2008
@@ -0,0 +1,61 @@
+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 org.apache.archiva.artifact.downloader.config.Config;
+
+/**
+ * LayoutUtil
+ * 
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class LayoutUtil
+{
+    private Config config;
+
+    public LayoutUtil( Config config )
+    {
+        this.config = config;
+    }
+
+    public String format( String layoutId, String groupId, String artifactId, String version )
+    {
+        return format( layoutId, groupId, artifactId, version, null, "jar" );
+    }
+
+    public String format( String layoutId, String groupId, String artifactId, String version, String classifier,
+                          String type )
+    {
+        String pattern = config.getLayoutPattern( layoutId );
+
+        pattern = pattern.replace( "${groupId}", groupId );
+        pattern = pattern.replace( "${groupIdPath}", groupId.replace( ".", "/" ) );
+        pattern = pattern.replace( "${artifactId}", artifactId );
+        pattern = pattern.replace( "${version}", version );
+        if ( classifier != null )
+        {
+            pattern = pattern.replace( "${classifier}", "-" + classifier );
+        }
+        else
+        {
+            pattern = pattern.replace( "${classifier}", "" );
+        }
+        pattern = pattern.replace( "${type}", type );
+
+        return pattern;
+    }
+}

Propchange: archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/LayoutUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/LayoutUtil.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/Repository.java
URL: http://svn.apache.org/viewvc/archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/Repository.java?rev=652898&view=auto
==============================================================================
--- archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/Repository.java (added)
+++ archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/Repository.java Fri May  2 13:34:35 2008
@@ -0,0 +1,62 @@
+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.net.URI;
+import java.net.URISyntaxException;
+
+/**
+ * Repository
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class Repository
+{
+    private String layout;
+
+    private URI rootUri;
+
+    public String getLayout()
+    {
+        return layout;
+    }
+
+    public URI getRootUri()
+    {
+        return rootUri;
+    }
+
+    public void setLayout( String layout )
+    {
+        this.layout = layout;
+    }
+
+    public void setRootUri( String uri )
+        throws URISyntaxException
+    {
+        this.rootUri = new URI( uri );
+    }
+
+    public void setRootUri( URI rootUri )
+    {
+        this.rootUri = rootUri;
+    }
+}

Propchange: archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/Repository.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/Repository.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/config/Config.java
URL: http://svn.apache.org/viewvc/archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/config/Config.java?rev=652898&view=auto
==============================================================================
--- archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/config/Config.java (added)
+++ archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/config/Config.java Fri May  2 13:34:35 2008
@@ -0,0 +1,75 @@
+package org.apache.archiva.artifact.downloader.config;
+
+/*
+ * 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.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.archiva.artifact.downloader.Repository;
+
+/**
+ * Config
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class Config
+{
+    private Map<String, String> layoutPatterns = new HashMap<String, String>();
+
+    private List<Repository> repositories = new ArrayList<Repository>();
+
+    public void addRepository( Repository repository )
+    {
+        this.repositories.add( repository );
+    }
+
+    public List<Repository> getRepositories()
+    {
+        return repositories;
+    }
+
+    public void setRepositories( List<Repository> repositories )
+    {
+        this.repositories = repositories;
+    }
+
+    public void addLayoutPattern( String key, String pattern )
+    {
+        this.layoutPatterns.put( key, pattern );
+    }
+
+    public String getLayoutPattern( String key )
+    {
+        return this.layoutPatterns.get( key );
+    }
+
+    public Map<String, String> getLayoutPatterns()
+    {
+        return layoutPatterns;
+    }
+
+    public void setLayoutPatterns( Map<String, String> layoutPatterns )
+    {
+        this.layoutPatterns = layoutPatterns;
+    }
+}

Propchange: archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/config/Config.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/config/Config.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/config/ConfigParser.java
URL: http://svn.apache.org/viewvc/archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/config/ConfigParser.java?rev=652898&view=auto
==============================================================================
--- archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/config/ConfigParser.java (added)
+++ archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/config/ConfigParser.java Fri May  2 13:34:35 2008
@@ -0,0 +1,60 @@
+package org.apache.archiva.artifact.downloader.config;
+
+/*
+ * 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.IOException;
+import java.io.Reader;
+
+import org.apache.archiva.artifact.downloader.Repository;
+import org.apache.commons.digester.Digester;
+import org.xml.sax.SAXException;
+
+/**
+ * ConfigParser
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class ConfigParser
+{
+    public static Config parseConfig( Reader reader )
+        throws IOException, SAXException
+    {
+        Digester digester = new Digester();
+
+        digester.setValidating( false );
+        digester.setNamespaceAware( true );
+
+        digester.addObjectCreate( "configuration", Config.class );
+        digester.addSetProperties( "configuration" );
+
+        digester.addCallMethod( "configuration/layouts/layout", "addLayoutPattern", 2 );
+        digester.addCallParam( "configuration/layouts/layout", 0, "id" );
+        digester.addCallParam( "configuration/layouts/layout", 1 );
+
+        digester.addObjectCreate( "configuration/repositories/repository", Repository.class );
+        digester.addSetProperties( "configuration/repositories/repository" );
+        digester.addCallMethod( "configuration/repositories/repository", "setRootUri", 1 );
+        digester.addCallParam( "configuration/repositories/repository", 0 );
+        digester.addSetNext( "configuration/repositories/repository", "addRepository", Repository.class.getName() );
+
+        return (Config) digester.parse( reader );
+    }
+}

Propchange: archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/config/ConfigParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/sandbox/archiva-artifact-downloader-cli/src/main/java/org/apache/archiva/artifact/downloader/config/ConfigParser.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: archiva/sandbox/archiva-artifact-downloader-cli/src/main/resources/artifact-downloader.xml
URL: http://svn.apache.org/viewvc/archiva/sandbox/archiva-artifact-downloader-cli/src/main/resources/artifact-downloader.xml?rev=652898&view=auto
==============================================================================
--- archiva/sandbox/archiva-artifact-downloader-cli/src/main/resources/artifact-downloader.xml (added)
+++ archiva/sandbox/archiva-artifact-downloader-cli/src/main/resources/artifact-downloader.xml Fri May  2 13:34:35 2008
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<configuration>
+  <layouts>
+    <layout id="default">${groupIdPath}/${artifactId}/${version}/${artifactId}-${version}${classifier}.${type}</layout>
+    <layout id="legacy">${groupId}/${type}s/${artifactId}-${version}${classifier}.${type}</layout>
+  </layouts>
+  <repositories>
+    <repository layout="default">http://download.java.net/maven/2/</repository>
+    <repository layout="legacy">http://download.java.net/maven/1/</repository>
+    <repository layout="default">http://repo1.maven.org/maven2/</repository>
+  </repositories>
+</configuration>
\ No newline at end of file

Added: archiva/sandbox/archiva-artifact-downloader-cli/src/test/java/org/apache/archiva/artifact/downloader/ArtifactKeyTest.java
URL: http://svn.apache.org/viewvc/archiva/sandbox/archiva-artifact-downloader-cli/src/test/java/org/apache/archiva/artifact/downloader/ArtifactKeyTest.java?rev=652898&view=auto
==============================================================================
--- archiva/sandbox/archiva-artifact-downloader-cli/src/test/java/org/apache/archiva/artifact/downloader/ArtifactKeyTest.java (added)
+++ archiva/sandbox/archiva-artifact-downloader-cli/src/test/java/org/apache/archiva/artifact/downloader/ArtifactKeyTest.java Fri May  2 13:34:35 2008
@@ -0,0 +1,49 @@
+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 junit.framework.TestCase;
+
+/**
+ * ArtifactKeyTest
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class ArtifactKeyTest
+    extends TestCase
+{
+    public void assertArtifactKey( String merged, String groupId, String artifactId, String version )
+    {
+        ArtifactKey key = new ArtifactKey( merged );
+        assertNotNull( "ArtifactKey should never be null", key );
+        assertEquals( "ArtifactKey.groupId", groupId, key.getGroupId() );
+        assertEquals( "ArtifactKey.artifactId", artifactId, key.getArtifactId() );
+        assertEquals( "ArtifactKey.version", version, key.getVersion() );
+    }
+
+    public void testConstructFromMergedKey()
+    {
+        assertArtifactKey( "commons-io:commons-io:1.0", "commons-io", "commons-io", "1.0" );
+
+        assertArtifactKey( "org.apache.commons:commons-lang:3.0-SNAPSHOT", "org.apache.commons", "commons-lang",
+                           "3.0-SNAPSHOT" );
+    }
+}

Propchange: archiva/sandbox/archiva-artifact-downloader-cli/src/test/java/org/apache/archiva/artifact/downloader/ArtifactKeyTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/sandbox/archiva-artifact-downloader-cli/src/test/java/org/apache/archiva/artifact/downloader/ArtifactKeyTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: archiva/sandbox/archiva-artifact-downloader-cli/src/test/java/org/apache/archiva/artifact/downloader/LayoutUtilTest.java
URL: http://svn.apache.org/viewvc/archiva/sandbox/archiva-artifact-downloader-cli/src/test/java/org/apache/archiva/artifact/downloader/LayoutUtilTest.java?rev=652898&view=auto
==============================================================================
--- archiva/sandbox/archiva-artifact-downloader-cli/src/test/java/org/apache/archiva/artifact/downloader/LayoutUtilTest.java (added)
+++ archiva/sandbox/archiva-artifact-downloader-cli/src/test/java/org/apache/archiva/artifact/downloader/LayoutUtilTest.java Fri May  2 13:34:35 2008
@@ -0,0 +1,76 @@
+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 junit.framework.TestCase;
+
+import org.apache.archiva.artifact.downloader.config.Config;
+
+/**
+ * LayoutUtilTest
+ * 
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class LayoutUtilTest
+    extends TestCase
+{
+    private void assertLayout( LayoutUtil layout, String layoutId, String expectedFormat, String artifactKey )
+    {
+        ArtifactKey key = new ArtifactKey( artifactKey );
+        String actual = layout.format( layoutId, key.getGroupId(), key.getArtifactId(), key.getVersion() );
+        assertEquals( "Layout.format()", expectedFormat, actual );
+    }
+
+    private void assertLayout( LayoutUtil layout, String layoutId, String expectedFormat, String artifactKey,
+                               String classifier, String type )
+    {
+        ArtifactKey key = new ArtifactKey( artifactKey );
+        String actual = layout.format( layoutId, key.getGroupId(), key.getArtifactId(), key.getVersion(), classifier,
+                                       type );
+        assertEquals( "Layout.format()", expectedFormat, actual );
+    }
+
+    public void testFormatDefault()
+    {
+        Config config = new Config();
+        config
+            .addLayoutPattern( "default",
+                               "${groupIdPath}/${artifactId}/${version}/${artifactId}-${version}${classifier}.${type}" );
+
+        LayoutUtil layout = new LayoutUtil( config );
+
+        assertLayout( layout, "default", "commons-io/commons-io/1.0/commons-io-1.0.jar", "commons-io:commons-io:1.0" );
+        assertLayout( layout, "default", "commons-io/commons-io/1.0/commons-io-1.0-site.pom",
+                      "commons-io:commons-io:1.0", "site", "pom" );
+        assertLayout( layout, "default", "org/apache/archiva/archiva-parent/4-SNAPSHOT/archiva-parent-4-SNAPSHOT.jar",
+                      "org.apache.archiva:archiva-parent:4-SNAPSHOT" );
+    }
+
+    public void testFormatLegacy()
+    {
+        Config config = new Config();
+        config.addLayoutPattern( "legacy", "${groupId}/${type}s/${artifactId}-${version}${classifier}.${type}" );
+
+        LayoutUtil layout = new LayoutUtil( config );
+
+        assertLayout( layout, "legacy", "commons-io/jars/commons-io-1.0.jar", "commons-io:commons-io:1.0" );
+        assertLayout( layout, "legacy", "commons-io/poms/commons-io-1.0-site.pom", "commons-io:commons-io:1.0", "site",
+                      "pom" );
+        assertLayout( layout, "legacy", "org.apache.archiva/jars/archiva-parent-4-SNAPSHOT.jar",
+                      "org.apache.archiva:archiva-parent:4-SNAPSHOT" );
+    }
+}

Propchange: archiva/sandbox/archiva-artifact-downloader-cli/src/test/java/org/apache/archiva/artifact/downloader/LayoutUtilTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/sandbox/archiva-artifact-downloader-cli/src/test/java/org/apache/archiva/artifact/downloader/LayoutUtilTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: archiva/sandbox/archiva-artifact-downloader-cli/src/test/java/org/apache/archiva/artifact/downloader/config/ConfigParserTest.java
URL: http://svn.apache.org/viewvc/archiva/sandbox/archiva-artifact-downloader-cli/src/test/java/org/apache/archiva/artifact/downloader/config/ConfigParserTest.java?rev=652898&view=auto
==============================================================================
--- archiva/sandbox/archiva-artifact-downloader-cli/src/test/java/org/apache/archiva/artifact/downloader/config/ConfigParserTest.java (added)
+++ archiva/sandbox/archiva-artifact-downloader-cli/src/test/java/org/apache/archiva/artifact/downloader/config/ConfigParserTest.java Fri May  2 13:34:35 2008
@@ -0,0 +1,106 @@
+package org.apache.archiva.artifact.downloader.config;
+
+/*
+ * 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.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.archiva.artifact.downloader.Repository;
+import org.xml.sax.SAXException;
+
+/**
+ * ConfigParserTest
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class ConfigParserTest
+    extends TestCase
+{
+    private File basedir;
+
+    public File getBasedir()
+    {
+        if ( basedir == null )
+        {
+            String dirprop = System.getProperty( "basedir" );
+            if ( dirprop == null )
+            {
+                dirprop = System.getProperty( "user.dir" );
+            }
+            basedir = new File( dirprop );
+        }
+
+        return basedir;
+    }
+
+    public File getTestFile( String filename )
+    {
+        return new File( getTestResourcesDir(), filename );
+    }
+
+    public File getTestResourcesDir()
+    {
+        return new File( getBasedir(), "src/test/resources" );
+    }
+
+    public void testParseConfig()
+        throws IOException, SAXException
+    {
+        File configXml = getTestFile( "config/artifact-downloader.xml" );
+        FileReader reader = new FileReader( configXml );
+
+        Config config = ConfigParser.parseConfig( reader );
+        assertNotNull( "Config should never be null", config );
+
+        assertEquals( "Config layouts count", 2, config.getLayoutPatterns().size() );
+        assertEquals( "Config repositories count", 3, config.getRepositories().size() );
+
+        List<String> expectedUris = new ArrayList<String>();
+        expectedUris.add( "http://download.java.net/maven/2/" );
+        expectedUris.add( "http://download.java.net/maven/1/" );
+        expectedUris.add( "http://repo1.maven.org/maven2/" );
+
+        List<String> actualUris = new ArrayList<String>();
+        for ( Repository repository : config.getRepositories() )
+        {
+            String rooturi = repository.getRootUri().toASCIIString();
+            actualUris.add( rooturi );
+            assertNotNull( "URI should not be null", rooturi );
+        }
+
+        Collections.sort( expectedUris );
+        Collections.sort( actualUris );
+
+        // Compare actual vs expected
+        for ( int i = 0; i < expectedUris.size(); i++ )
+        {
+            String expected = expectedUris.get( i );
+            String actual = actualUris.get( i );
+            assertEquals( "URI[" + i + "]", expected, actual );
+        }
+    }
+}

Propchange: archiva/sandbox/archiva-artifact-downloader-cli/src/test/java/org/apache/archiva/artifact/downloader/config/ConfigParserTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/sandbox/archiva-artifact-downloader-cli/src/test/java/org/apache/archiva/artifact/downloader/config/ConfigParserTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: archiva/sandbox/archiva-artifact-downloader-cli/src/test/resources/config/artifact-downloader.xml
URL: http://svn.apache.org/viewvc/archiva/sandbox/archiva-artifact-downloader-cli/src/test/resources/config/artifact-downloader.xml?rev=652898&view=auto
==============================================================================
--- archiva/sandbox/archiva-artifact-downloader-cli/src/test/resources/config/artifact-downloader.xml (added)
+++ archiva/sandbox/archiva-artifact-downloader-cli/src/test/resources/config/artifact-downloader.xml Fri May  2 13:34:35 2008
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<configuration>
+  <layouts>
+    <layout id="default">${groupIdPath}/${artifactId}/${version}/${artifactId}-${version}${classifier}.${type}</layout>
+    <layout id="legacy">${groupId}/${type}s/${artifactId}-${version}${classifier}.${type}</layout>
+  </layouts>
+  <repositories>
+    <repository layout="default">http://download.java.net/maven/2/</repository>
+    <repository layout="legacy">http://download.java.net/maven/1/</repository>
+    <repository layout="default">http://repo1.maven.org/maven2/</repository>
+  </repositories>
+</configuration>
\ No newline at end of file