maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdca...@apache.org
Subject svn commit: r585553 - in /maven/artifact/trunk/src: main/java/org/apache/maven/artifact/ main/java/org/apache/maven/artifact/repository/ test/java/org/apache/maven/artifact/repository/
Date Wed, 17 Oct 2007 16:18:32 GMT
Author: jdcasey
Date: Wed Oct 17 09:18:29 2007
New Revision: 585553

URL: http://svn.apache.org/viewvc?rev=585553&view=rev
Log:
Adding methods to ArtifactRepositoryFactory to allow retrieval of ArtifactRepositoryLayout
by layoutId, and to allow creation of a new repository instance without having to supply the
layout instance (can use the layout id instead).

Added:
    maven/artifact/trunk/src/test/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactoryTest.java
  (with props)
Modified:
    maven/artifact/trunk/src/main/java/org/apache/maven/artifact/InvalidRepositoryException.java
    maven/artifact/trunk/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryFactory.java
    maven/artifact/trunk/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactory.java

Modified: maven/artifact/trunk/src/main/java/org/apache/maven/artifact/InvalidRepositoryException.java
URL: http://svn.apache.org/viewvc/maven/artifact/trunk/src/main/java/org/apache/maven/artifact/InvalidRepositoryException.java?rev=585553&r1=585552&r2=585553&view=diff
==============================================================================
--- maven/artifact/trunk/src/main/java/org/apache/maven/artifact/InvalidRepositoryException.java
(original)
+++ maven/artifact/trunk/src/main/java/org/apache/maven/artifact/InvalidRepositoryException.java
Wed Oct 17 09:18:29 2007
@@ -1,5 +1,9 @@
 package org.apache.maven.artifact;
 
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+
+import java.net.MalformedURLException;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -30,9 +34,19 @@
 {
     private final String repositoryId;
 
-    public InvalidRepositoryException( String message, String repositoryId, Throwable throwable
)
+    public InvalidRepositoryException( String message,
+                                       String repositoryId,
+                                       MalformedURLException cause )
+    {
+        super( message, cause );
+        this.repositoryId = repositoryId;
+    }
+
+    protected InvalidRepositoryException( String message,
+                                       String repositoryId,
+                                       ComponentLookupException cause )
     {
-        super( message, throwable );
+        super( message, cause );
         this.repositoryId = repositoryId;
     }
 

Modified: maven/artifact/trunk/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryFactory.java
URL: http://svn.apache.org/viewvc/maven/artifact/trunk/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryFactory.java?rev=585553&r1=585552&r2=585553&view=diff
==============================================================================
--- maven/artifact/trunk/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryFactory.java
(original)
+++ maven/artifact/trunk/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryFactory.java
Wed Oct 17 09:18:29 2007
@@ -19,15 +19,28 @@
  * under the License.
  */
 
+import org.apache.maven.artifact.InvalidRepositoryException;
 import org.apache.maven.artifact.UnknownRepositoryLayoutException;
 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
 
+import java.io.File;
+
 /**
  * @author jdcasey
  */
 public interface ArtifactRepositoryFactory
 {
     String ROLE = ArtifactRepositoryFactory.class.getName();
+
+    String DEFAULT_LAYOUT_ID = "default";
+
+    String LOCAL_REPOSITORY_ID = "local";
+
+    ArtifactRepository createLocalRepository( File localRepositoryDirectory )
+        throws InvalidRepositoryException;
+
+    ArtifactRepositoryLayout getLayout( String layoutId )
+        throws UnknownRepositoryLayoutException;
 
     ArtifactRepository createDeploymentArtifactRepository( String id,
                                                            String url,

Modified: maven/artifact/trunk/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactory.java
URL: http://svn.apache.org/viewvc/maven/artifact/trunk/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactory.java?rev=585553&r1=585552&r2=585553&view=diff
==============================================================================
--- maven/artifact/trunk/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactory.java
(original)
+++ maven/artifact/trunk/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactory.java
Wed Oct 17 09:18:29 2007
@@ -19,11 +19,14 @@
  * under the License.
  */
 
+import org.apache.maven.artifact.InvalidRepositoryException;
 import org.apache.maven.artifact.UnknownRepositoryLayoutException;
 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
 import org.codehaus.plexus.collections.ActiveMap;
 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
 
+import java.io.File;
+import java.net.MalformedURLException;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -43,6 +46,22 @@
 
     private ActiveMap repositoryLayouts;
 
+    public ArtifactRepositoryLayout getLayout( String layoutId )
+        throws UnknownRepositoryLayoutException
+    {
+        ArtifactRepositoryLayout layout;
+        try
+        {
+            layout = (ArtifactRepositoryLayout) repositoryLayouts.checkedGet( layoutId );
+        }
+        catch ( ComponentLookupException e )
+        {
+            throw new UnknownRepositoryLayoutException( "unknown", layoutId, e );
+        }
+
+        return layout;
+    }
+
     public ArtifactRepository createDeploymentArtifactRepository( String id, String url,
                                                         String layoutId,
                                                         boolean uniqueVersion )
@@ -142,5 +161,31 @@
     public void setGlobalChecksumPolicy( String checksumPolicy )
     {
         globalChecksumPolicy = checksumPolicy;
+    }
+
+    public ArtifactRepository createLocalRepository( File localRepositoryDirectory )
+        throws InvalidRepositoryException
+    {
+        ArtifactRepositoryLayout layout = getLayout( DEFAULT_LAYOUT_ID );
+        DefaultArtifactRepository repo;
+        try
+        {
+            repo = new DefaultArtifactRepository( LOCAL_REPOSITORY_ID,
+                                                  localRepositoryDirectory.toURI()
+                                                                          .toURL()
+                                                                          .toExternalForm(),
+                                                  layout, new ArtifactRepositoryPolicy(),
+                                                  new ArtifactRepositoryPolicy() );
+        }
+        catch ( MalformedURLException e )
+        {
+            throw new InvalidRepositoryException( "Invalid local repository directory: "
+                                                  + localRepositoryDirectory
+                                                  + ". Cannot render URL.", LOCAL_REPOSITORY_ID,
e );
+        }
+
+        repo.setBasedir( localRepositoryDirectory.getAbsolutePath() );
+
+        return repo;
     }
 }

Added: maven/artifact/trunk/src/test/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactoryTest.java
URL: http://svn.apache.org/viewvc/maven/artifact/trunk/src/test/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactoryTest.java?rev=585553&view=auto
==============================================================================
--- maven/artifact/trunk/src/test/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactoryTest.java
(added)
+++ maven/artifact/trunk/src/test/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactoryTest.java
Wed Oct 17 09:18:29 2007
@@ -0,0 +1,77 @@
+package org.apache.maven.artifact.repository;
+
+import org.apache.maven.artifact.InvalidRepositoryException;
+import org.apache.maven.artifact.UnknownRepositoryLayoutException;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
+import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.util.FileUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+public class DefaultArtifactRepositoryFactoryTest
+    extends PlexusTestCase
+{
+
+    private ArtifactRepositoryFactory repoFactory;
+
+    private Set toDelete = new HashSet();
+
+    public void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        repoFactory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE
);
+    }
+
+    public void tearDown()
+        throws Exception
+    {
+        for ( Iterator it = toDelete.iterator(); it.hasNext(); )
+        {
+            File f = (File) it.next();
+
+            if ( f.exists() )
+            {
+                FileUtils.forceDelete( f );
+            }
+        }
+    }
+
+    private File createTempDir()
+        throws IOException
+    {
+        File f = File.createTempFile( "DefaultArtifactRepositoryFactoryTest.", ".dir" );
+        FileUtils.forceDelete( f );
+
+        f.mkdirs();
+        toDelete.add( f );
+
+        return f;
+    }
+
+    public void test_createLocalRepository()
+        throws IOException, InvalidRepositoryException
+    {
+        File dir = createTempDir();
+        ArtifactRepository localRepo = repoFactory.createLocalRepository( dir );
+
+        assertEquals( dir.getAbsolutePath(), localRepo.getBasedir() );
+        assertEquals( ArtifactRepositoryFactory.LOCAL_REPOSITORY_ID, localRepo.getId() );
+        assertTrue( localRepo.getLayout() instanceof DefaultRepositoryLayout );
+    }
+
+    public void test_getLayout_ReturnDefaultLayout()
+        throws UnknownRepositoryLayoutException
+    {
+        ArtifactRepositoryLayout layout = repoFactory.getLayout( "default" );
+
+        assertTrue( layout instanceof DefaultRepositoryLayout );
+    }
+
+}

Propchange: maven/artifact/trunk/src/test/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactoryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/artifact/trunk/src/test/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactoryTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"



Mime
View raw message