You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by "Henning P. Schmiedehausen" <hp...@intermeta.de> on 2002/12/27 19:59:00 UTC

[PATCH] Add local read-only repositories

This patch adds the ability to add local "read-only" repositories to
Maven, which act just like maven.local.repo except that they're only
consulted when a jar is not in the local repository. This is used in a
shared installation to satisfy the dependencies of the plugins without
having to install all the jars needed for the plugins in every home.

You get a new property "maven.readonly.repo" which acts like
maven.remote.repo; you can add multiple repositories separated by ",".

diff -urb test/jakarta-turbine-maven/src/java/org/apache/maven/ArtifactListBuilder.java jakarta-turbine-maven/src/java/org/apache/maven/ArtifactListBuilder.java
--- test/jakarta-turbine-maven/src/java/org/apache/maven/ArtifactListBuilder.java	Wed Dec 11 07:30:01 2002
+++ jakarta-turbine-maven/src/java/org/apache/maven/ArtifactListBuilder.java	Fri Dec 27 16:43:35 2002
@@ -70,6 +70,7 @@
 /**
  *
  * @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
+ * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
  *
  * @version $Id: ArtifactListBuilder.java,v 1.3 2002/12/11 06:30:01 jvanzyl Exp $
  */
@@ -97,7 +98,11 @@
         {
             Dependency d = (Dependency) i.next();
             String mavenJarProperty = context.getMavenJarOverride( d.getId() );
+
             Artifact artifact = DefaultArtifactFactory.createArtifact( d );
+            String artifactPath = artifact.generatePath();
+
+            artifact.setPath( context.getMavenRepoLocal() + artifactPath );
 
             if ( mavenJarOverride
                 &&
@@ -113,7 +118,6 @@
                     // User is requesting a specific version of a dependency
                     // be used.
                     d.setVersion( mavenJarProperty );
-                    artifact.setPath( context.getMavenRepoLocal() + artifact.generatePath() );
                 }
                 else
                 {
@@ -124,7 +128,35 @@
             }
             else
             {
-                artifact.setPath( context.getMavenRepoLocal() + artifact.generatePath() );
+                // Do we have this artifact  the local repository? If yes,
+                // don't check the readonly repositories
+                //
+                File localFile = new File ( artifact.getPath() );
+                
+                if ( ! ( localFile.exists() && localFile.canRead() ) )
+                {
+                    List readonlyRepos = context.getMavenRepoReadonly();
+
+                    if ( readonlyRepos != null && readonlyRepos.size() > 0 )
+                    {
+                        for( Iterator it = readonlyRepos.iterator(); it.hasNext(); )
+                        {
+                            String readonlyRepo = (String) it.next();
+
+                            String readonlyArtifact = readonlyRepo + artifactPath;
+
+                            File artifactFile = new File( readonlyArtifact );
+
+                            // If we find an artifact in the readonly repositories,
+                            // we mark this to be used and bail out
+                            if ( artifactFile.exists() && artifactFile.canRead() )
+                            {
+                                artifact.setPath( artifactFile.getAbsolutePath() );
+                                break; // for(Iterator it ...
+                            }
+                        }
+                    }
+                }
             }
 
             projectArtifacts.add( artifact );
diff -urb test/jakarta-turbine-maven/src/java/org/apache/maven/MavenConstants.java jakarta-turbine-maven/src/java/org/apache/maven/MavenConstants.java
--- test/jakarta-turbine-maven/src/java/org/apache/maven/MavenConstants.java	Mon Dec  9 07:41:44 2002
+++ jakarta-turbine-maven/src/java/org/apache/maven/MavenConstants.java	Fri Dec 27 16:14:08 2002
@@ -96,6 +96,9 @@
     /** Local Repository tag. */
     public static final String REPO_LOCAL = "maven.repo.local";
 
+    /** Readonly Repository tag. */
+    public static final String REPO_READONLY = "maven.repo.readonly";
+
     /** Local Repository tag. */
     public static final String REPO_REMOTE = "maven.repo.remote";
 
diff -urb test/jakarta-turbine-maven/src/java/org/apache/maven/jelly/MavenJellyContext.java jakarta-turbine-maven/src/java/org/apache/maven/jelly/MavenJellyContext.java
--- test/jakarta-turbine-maven/src/java/org/apache/maven/jelly/MavenJellyContext.java	Wed Dec 18 18:11:02 2002
+++ jakarta-turbine-maven/src/java/org/apache/maven/jelly/MavenJellyContext.java	Fri Dec 27 16:18:25 2002
@@ -331,6 +331,37 @@
     }
 
     /**
+     * Add a readonly repository to the list of readonly repositories.
+     *
+     * @param mavenReadonlyRepo Readonly repository to add.
+     */
+    public void addMavenReadonlyRepo( String mavenReadonlyRepo )
+    {
+        ( (List) getVariable( MavenConstants.REPO_READONLY ) ).add( mavenReadonlyRepo );
+    }
+
+    /**
+     * Set the mavenRepoReadonly attribute.
+     *
+     * @param mavenRepoReadonly List of remove repositories.
+     */
+    public void setMavenRepoReadonlys( List mavenRepoReadonly )
+    {
+        setVariable( MavenConstants.REPO_READONLY, mavenRepoReadonly );
+    }
+
+    /**
+     * Get the mavenRepoReadonly attribute.
+     *
+     * @return The list of readonly repositories.
+     */
+    public List getMavenRepoReadonly()
+    {
+        // We might have CSV list of readonly repositories.
+        return convertCsvStringToList( (String) getVariable( MavenConstants.REPO_READONLY ) );
+    }
+
+    /**
      * Convert a CSV list of values into a List
      *
      * @param csvString CVS list of values.
@@ -350,7 +381,7 @@
     }
 
     /**
-     * Set the mavenRepoRemote attribute.
+     * Set the mavenRepoLocal attribute.
      *
      * @param mavenRepoLocal The local repository.
      */
@@ -360,7 +391,7 @@
     }
 
     /**
-     * Get the mavenRepoRemote attribute.
+     * Get the mavenRepoLocal attribute.
      *
      * @return The local repository.
      */
diff -urb test/jakarta-turbine-maven/src/conf/driver.properties jakarta-turbine-maven/src/conf/driver.properties
--- test/jakarta-turbine-maven/src/conf/driver.properties	Wed Dec 11 23:28:43 2002
+++ jakarta-turbine-maven/src/conf/driver.properties	Fri Dec 27 17:10:08 2002
@@ -30,6 +30,12 @@
 maven.plugin.dir = ${maven.home}/plugins
 
 # -------------------------------------------------------------------
+# M A V E N  R E A D - O N L Y  R E P O S
+# -------------------------------------------------------------------
+
+maven.repo.readonly = 
+
+# -------------------------------------------------------------------
 # M A V E N  R E M O T E  R E P O S
 # -------------------------------------------------------------------

	Regards
		Henning

-- 
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen       -- Geschaeftsfuehrer
INTERMETA - Gesellschaft fuer Mehrwertdienste mbH     hps@intermeta.de

Am Schwabachgrund 22  Fon.: 09131 / 50654-0   info@intermeta.de
D-91054 Buckenhof     Fax.: 09131 / 50654-20