]> source.dussan.org Git - archiva.git/commitdiff
Reorganization of model for policy maps and archiva-policies
authorJoakim Erdfelt <joakime@apache.org>
Fri, 13 Apr 2007 15:58:55 +0000 (15:58 +0000)
committerJoakim Erdfelt <joakime@apache.org>
Fri, 13 Apr 2007 15:58:55 +0000 (15:58 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches@528539 13f79535-47bb-0310-9956-ffa450edef68

archiva-jpox-database-refactor/archiva-base/archiva-configuration/pom.xml
archiva-jpox-database-refactor/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/MavenProxyPropertyLoader.java
archiva-jpox-database-refactor/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo

index 346fffe5a0c532bc0f6965f59bae8655ec420057..4b0d815c2ed1dd3a614a31862ad36d552136c2f2 100644 (file)
   <artifactId>archiva-configuration</artifactId>
   <name>Archiva Base :: Configuration</name>
   <dependencies>
+    <dependency>
+      <groupId>org.apache.maven.archiva</groupId>
+      <artifactId>archiva-common</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.archiva</groupId>
+      <artifactId>archiva-policies</artifactId>
+      <version>1.0-SNAPSHOT</version>
+    </dependency>
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-component-api</artifactId>
index 599e36ac72ae2271b760fb32a208d2a45cb72f17..a44911e5db6d6f35569e2b9abdc3a2aa4cb06540 100644 (file)
@@ -20,11 +20,12 @@ package org.apache.maven.archiva.configuration;
  */
 
 import org.apache.commons.lang.StringUtils;
+import org.apache.maven.archiva.common.utils.PathUtil;
+import org.apache.maven.archiva.policies.ReleasesPolicy;
+import org.apache.maven.archiva.policies.SnapshotsPolicy;
 
-import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
-import java.net.MalformedURLException;
 import java.util.Enumeration;
 import java.util.Properties;
 import java.util.StringTokenizer;
@@ -41,13 +42,14 @@ public class MavenProxyPropertyLoader
 
     private static final String REPO_LIST = "repo.list";
 
-    public void load( Properties props, Configuration configuration ) throws InvalidConfigurationException
+    public void load( Properties props, Configuration configuration )
+        throws InvalidConfigurationException
     {
         // set up the managed repository
         String localCachePath = getMandatoryProperty( props, REPO_LOCAL_STORE );
 
         RepositoryConfiguration config = new RepositoryConfiguration();
-        config.setUrl( toURL( localCachePath ) );
+        config.setUrl( PathUtil.toUrl( localCachePath ) );
         config.setName( "Imported Maven-Proxy Cache" );
         config.setId( "maven-proxy" );
         configuration.addRepository( config );
@@ -97,31 +99,20 @@ public class MavenProxyPropertyLoader
             repository.setIndexed( false );
             repository.setReleases( true );
             repository.setSnapshots( false );
-            
+
             configuration.addRepository( repository );
 
-            RepositoryProxyConnectorConfiguration proxyConnector = new RepositoryProxyConnectorConfiguration();
+            ProxyConnectorConfiguration proxyConnector = new ProxyConnectorConfiguration();
             proxyConnector.setSourceRepoId( "maven-proxy" );
             proxyConnector.setTargetRepoId( key );
             proxyConnector.setProxyId( proxyKey );
             // TODO: convert cachePeriod to closest "daily" or "hourly"
-            proxyConnector.setSnapshotsPolicy( "daily" );
-            proxyConnector.setReleasesPolicy( "never" );
-            
-            configuration.addProxyConnector( proxyConnector );
-        }
-    }
+            proxyConnector.addPolicy( ProxyConnectorConfiguration.POLICY_SNAPSHOTS, 
+                                      SnapshotsPolicy.DAILY );
+            proxyConnector.addPolicy( ProxyConnectorConfiguration.POLICY_RELEASES, 
+                                      ReleasesPolicy.IGNORED );
 
-    private String toURL( String path )
-    {
-        File file = new File( path );
-        try
-        {
-            return file.toURL().toExternalForm();
-        }
-        catch ( MalformedURLException e )
-        {
-            return "file://" + StringUtils.replaceChars( file.getAbsolutePath(), '\\', '/' );
+            configuration.addProxyConnector( proxyConnector );
         }
     }
 
@@ -142,14 +133,16 @@ public class MavenProxyPropertyLoader
         return result;
     }
 
-    public void load( InputStream is, Configuration configuration ) throws IOException, InvalidConfigurationException
+    public void load( InputStream is, Configuration configuration )
+        throws IOException, InvalidConfigurationException
     {
         Properties props = new Properties();
         props.load( is );
         load( props, configuration );
     }
 
-    private String getMandatoryProperty( Properties props, String key ) throws InvalidConfigurationException
+    private String getMandatoryProperty( Properties props, String key )
+        throws InvalidConfigurationException
     {
         String value = props.getProperty( key );
 
index ccac6d6e61ebc60d49b8ce543f87c461629003e9..fe8cddee30ac0c2b96bdbdd15d8c349251c7525b 100644 (file)
@@ -47,7 +47,7 @@
           <name>proxyConnectors</name>
           <version>1.0.0+</version>
           <association>
-            <type>RepositoryProxyConnectorConfiguration</type>
+            <type>ProxyConnectorConfiguration</type>
             <multiplicity>*</multiplicity>
           </association>
           <description>The list of proxy connectors for this archiva instance.</description>
@@ -57,7 +57,7 @@
           <name>syncConnectors</name>
           <version>1.0.0+</version>
           <association>
-            <type>RepositorySyncConnectorConfiguration</type>
+            <type>SyncConnectorConfiguration</type>
             <multiplicity>*</multiplicity>
           </association>
           <description>The list of sync connectors for this archiva instance.</description>
             The list of whitelisted patterns for this connector.
           </description>
         </field>
+        <field>
+          <name>policies</name>
+          <version>1.0.0+</version>
+          <type>Properties</type>
+          <description>Policy configuration for the connector.</description>
+          <association xml.mapStyle="inline">
+            <type>String</type>
+            <multiplicity>*</multiplicity>
+          </association>
+        </field>        
+        <field>
+          <name>properties</name>
+          <version>1.0.0+</version>
+          <type>Properties</type>
+          <description>Configuration for the connector.</description>
+          <association xml.mapStyle="inline">
+            <type>String</type>
+            <multiplicity>*</multiplicity>
+          </association>
+        </field>
       </fields>
+      <codeSegments>
+        <codeSegment>
+          <version>1.0.0+</version>
+          <code><![CDATA[
+    /**
+     * Obtain a specific policy from the underlying connector.
+     * 
+     * @param policyId the policy id to fetch.
+     * @param defaultValue the default value for the policy id.
+     * @return the configured policy value (or default value if not found).
+     */
+    public String getPolicy( String policyId, String defaultValue )
+    {
+        if ( this.getPolicies() == null )
+        {
+            return null;
+        }
+
+        return this.getPolicies().getProperty( policyId, defaultValue );
+    }          
+          ]]></code>
+        </codeSegment>
+      </codeSegments>
     </class>
     \r
     <class>\r
       <superClass>AbstractRepositoryConnectorConfiguration</superClass>\r
-      <name>RepositoryProxyConnectorConfiguration</name>\r
+      <name>ProxyConnectorConfiguration</name>\r
       <version>1.0.0+</version>\r
       <fields>
-        <field>\r
-          <name>snapshotsPolicy</name>\r
-          <version>1.0.0+</version>\r
-          <type>String</type>\r
-          <defaultValue>disabled</defaultValue>\r
-          <description>
-            <![CDATA[
-            <p>
-            The policy for snapshots, one of the following:
-              {@link org.apache.maven.archiva.proxy.policy.ArtifactUpdatePolicy#DISABLED disabled},
-              {@link org.apache.maven.archiva.proxy.policy.ArtifactUpdatePolicy#DAILY daily},
-              {@link org.apache.maven.archiva.proxy.policy.ArtifactUpdatePolicy#HOURLY hourly},
-              {@link org.apache.maven.archiva.proxy.policy.ArtifactUpdatePolicy#ONCE once}
-            </p>
+      </fields>
+      <codeSegments>
+        <codeSegment>
+          <version>1.0.0+</version>
+          <code><![CDATA[
+    /**
+     * The policy key {@link #getPolicies()} for snapshot handling.
+     * See {@link org.apache.maven.archiva.policies.SnapshotsPolicy} 
+     * for details on potential values to this policy key.
+     */
+    public static final String POLICY_SNAPSHOTS = "snapshots";
 
-            @see org.apache.maven.archiva.proxy.policy.ArtifactUpdatePolicy
-            ]]>
-          </description>
-        </field>\r
-        <field>\r
-          <name>releasesPolicy</name>\r
-          <version>1.0.0+</version>\r
-          <type>String</type>\r
-          <defaultValue>never</defaultValue>\r
-          <description>
-            <![CDATA[
-            <p>
-            The policy for releases, one of the following:
-              {@link org.apache.maven.archiva.proxy.policy.ArtifactUpdatePolicy#DISABLED disabled},
-              {@link org.apache.maven.archiva.proxy.policy.ArtifactUpdatePolicy#DAILY daily},
-              {@link org.apache.maven.archiva.proxy.policy.ArtifactUpdatePolicy#HOURLY hourly},
-              {@link org.apache.maven.archiva.proxy.policy.ArtifactUpdatePolicy#ONCE once}
-            </p>\r
+    /**
+     * The policy key {@link #getPolicies()} for releases handling.
+     * See {@link org.apache.maven.archiva.policies.ReleasesPolicy}
+     * for details on potential values to this policy key.
+     */
+    public static final String POLICY_RELEASES = "releases";
 
-            @see org.apache.maven.archiva.proxy.policy.ArtifactUpdatePolicy
-            ]]>
-          </description>\r
-        </field>\r
-        <field>
-          <name>checksumPolicy</name>
-          <version>1.0.0+</version>
-          <type>String</type>
-          <defaultValue>fail</defaultValue>
-          <description>
-            <![CDATA[
-            <p>
-            The policy for dealing with checksums, one of the following: 
-              {@link org.apache.maven.archiva.proxy.policy.ChecksumPolicy#FAIL fail}, 
-              {@link org.apache.maven.archiva.proxy.policy.ChecksumPolicy#FIX fix}, or
-              {@link org.apache.maven.archiva.proxy.policy.ChecksumPolicy#IGNORE ignore}
-            </p>
-            
-            @see org.apache.maven.archiva.proxy.policy.ChecksumPolicy
-            ]]>
-          </description>
-        </field>
-      </fields>
+    /**
+     * The policy key {@link #getPolicies()} for checksum handling.
+     * See {@link org.apache.maven.archiva.policies.ChecksumPolicy}
+     * for details on potential values to this policy key.
+     */
+    public static final String POLICY_CHECKSUM = "checksum";
+
+    /**
+     * The policy key {@link #getPolicies()} for cache-failures handling.
+     * See {@link org.apache.maven.archiva.policies.CachedFailuresPolicy}
+     * for details on potential values to this policy key.
+     */
+    public static final String POLICY_CACHE_FAILURES = "cache-failures";
+          ]]></code>
+        </codeSegment>
+      </codeSegments>
     </class>
     \r
     <class>\r
       <superClass>AbstractRepositoryConnectorConfiguration</superClass>\r
-      <name>RepositorySynchConnectorConfiguration</name>\r
+      <name>SyncConnectorConfiguration</name>\r
       <abstract>true</abstract>\r
       <version>1.0.0+</version>\r
       <fields>\r
           <description>The type of synchronization to use.</description>\r
           <defaultValue>rsync</defaultValue>\r
         </field>\r
-        <field>\r
-          <name>properties</name>\r
-          <version>1.0.0+</version>\r
-          <type>Properties</type>\r
-          <description>Configuration for the repository synchronization.</description>\r
-          <association xml.mapStyle="inline">\r
-            <type>String</type>\r
-            <multiplicity>*</multiplicity>\r
-          </association>\r
-        </field>\r
       </fields>\r
     </class>