]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1393] Commons configuration bug causes build to fail on Windows 7
authorOlivier Lamy <olamy@apache.org>
Wed, 28 Sep 2011 09:06:32 +0000 (09:06 +0000)
committerOlivier Lamy <olamy@apache.org>
Wed, 28 Sep 2011 09:06:32 +0000 (09:06 +0000)
I have changed a unit which IMHO was wrong as didn't take care about managed repo coming from old configuration format: ArchivaConfigurationTest#testConfigurationUpgradeFrom09

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1176791 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java
archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo
archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/archiva/configuration/ArchivaConfigurationTest.java
archiva-modules/archiva-web/archiva-webapp/pom.xml
pom.xml

index 33f52d17a8bcec8a74a83aebc5ca7dcff2fe3b9e..a639782eec071cb8cf993392362a0ab281bae917 100644 (file)
@@ -19,11 +19,6 @@ package org.apache.archiva.configuration;
  * under the License.
  */
 
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.collections.MapUtils;
-import org.apache.commons.configuration.BaseConfiguration;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang.StringUtils;
 import org.apache.archiva.configuration.functors.ProxyConnectorConfigurationOrderComparator;
 import org.apache.archiva.configuration.io.registry.ConfigurationRegistryReader;
 import org.apache.archiva.configuration.io.registry.ConfigurationRegistryWriter;
@@ -33,6 +28,11 @@ import org.apache.archiva.policies.ChecksumPolicy;
 import org.apache.archiva.policies.Policy;
 import org.apache.archiva.policies.PostDownloadPolicy;
 import org.apache.archiva.policies.PreDownloadPolicy;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.MapUtils;
+import org.apache.commons.configuration.BaseConfiguration;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.StringUtils;
 import org.codehaus.plexus.evaluator.DefaultExpressionEvaluator;
 import org.codehaus.plexus.evaluator.EvaluatorException;
 import org.codehaus.plexus.evaluator.ExpressionEvaluator;
@@ -197,16 +197,27 @@ public class DefaultArchivaConfiguration
                 V1RepositoryConfiguration r = i.next();
                 r.setScanned( r.isIndexed() );
 
-                if ( r.getUrl().startsWith( "file://" ) )
+                if ( StringUtils.startsWith( r.getUrl(), "file://" ) )
                 {
                     r.setLocation( r.getUrl().substring( 7 ) );
                     config.addManagedRepository( r );
                 }
-                else if ( r.getUrl().startsWith( "file:" ) )
+                else if ( StringUtils.startsWith( r.getUrl(), "file:" ) )
                 {
                     r.setLocation( r.getUrl().substring( 5 ) );
                     config.addManagedRepository( r );
                 }
+                else if ( StringUtils.isEmpty( r.getUrl() ) )
+                {
+                    // in case of empty url we can consider it as a managed one
+                    // check if location is null
+                    //file://${appserver.base}/repositories/${id}
+                    if ( StringUtils.isEmpty( r.getLocation() ) )
+                    {
+                        r.setLocation( "file://${appserver.base}/repositories/" + r.getId() );
+                    }
+                    config.addManagedRepository( r );
+                }
                 else
                 {
                     RemoteRepositoryConfiguration repo = new RemoteRepositoryConfiguration();
index 9dd0dc679546c5921ee3d4a3832d9ca15aaff8c4..763e5ee6fa4778a8d89abbc1e538da2d03fa9cc3 100644 (file)
           <defaultValue>300</defaultValue>
         </field>
       </fields>
+      <codeSegments>
+        <codeSegment>
+          <version>1.0.0+</version>
+            <code><![CDATA[
+            public String toString()
+            {
+                return "RemoteRepositoryConfiguration id:'" + getId() + "',name:'" + getName() +"'";
+            }
+
+
+       ]]></code>
+        </codeSegment>
+      </codeSegments>
     </class>
     <class>
       <name>ManagedRepositoryConfiguration</name>
index 6866218da354624b6cafa85f2d5e6f4bd547e46d..7c027290d7bcb51f2dca12a546fb4d99616b12a7 100644 (file)
@@ -20,9 +20,9 @@ package org.apache.archiva.configuration;
  */
 
 import junit.framework.TestCase;
+import org.apache.archiva.common.utils.FileUtil;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.StringUtils;
-import org.apache.archiva.common.utils.FileUtil;
 import org.codehaus.plexus.registry.RegistryException;
 import org.codehaus.redback.components.springutils.ComponentContainer;
 import org.custommonkey.xmlunit.XMLAssert;
@@ -41,7 +41,7 @@ import java.util.Map;
  * Test the configuration store.
  */
 @RunWith( SpringJUnit4ClassRunner.class )
-@ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml","classpath:/spring-context.xml"} )
+@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
 public class ArchivaConfigurationTest
     extends TestCase
 {
@@ -62,12 +62,12 @@ public class ArchivaConfigurationTest
         return "org/apache/maven/archiva/configuration/spring-context.xml";
     }
 
-    protected <T> T lookup(Class<T> clazz, String hint)
+    protected <T> T lookup( Class<T> clazz, String hint )
     {
         return componentContainer.getComponent( clazz, hint );
     }
 
-    protected <T> T lookup(Class<T> clazz)
+    protected <T> T lookup( Class<T> clazz )
     {
         return componentContainer.getComponent( clazz );
     }
@@ -132,14 +132,14 @@ public class ArchivaConfigurationTest
         existingTestDefaultArchivaConfigFile =
             StringUtils.replace( existingTestDefaultArchivaConfigFile, "${appserver.base}", FileUtil.getBasedir() );
 
-        File generatedTestDefaultArchivaConfigFile =
-            new File( FileUtil.getBasedir(), "target/test-classes/org/apache/archiva/configuration/default-archiva.xml" );
+        File generatedTestDefaultArchivaConfigFile = new File( FileUtil.getBasedir(),
+                                                               "target/test-classes/org/apache/archiva/configuration/default-archiva.xml" );
 
         FileUtils.writeStringToFile( generatedTestDefaultArchivaConfigFile, existingTestDefaultArchivaConfigFile,
                                      null );
 
-        ArchivaConfiguration archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class,
-                                                                                   "test-defaults-default-repo-location-exists" );
+        ArchivaConfiguration archivaConfiguration =
+            (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-defaults-default-repo-location-exists" );
 
         Configuration configuration = archivaConfiguration.getConfiguration();
         assertConfiguration( configuration );
@@ -152,17 +152,26 @@ public class ArchivaConfigurationTest
         assertFalse( generatedTestDefaultArchivaConfigFile.exists() );
     }
 
+    private void assertConfiguration( Configuration configuration )
+        throws Exception
+    {
+        assertConfiguration( configuration, 2 );
+    }
+
     /**
      * Ensures that the provided configuration matches the details present in the archiva-default.xml file.
      */
-    private void assertConfiguration( Configuration configuration )
+    private void assertConfiguration( Configuration configuration, int managedExpected )
         throws Exception
     {
-        FileTypes filetypes = (FileTypes) lookup( FileTypes.class );
+        FileTypes filetypes = lookup( FileTypes.class );
 
-        assertEquals( "check repositories", 2, configuration.getManagedRepositories().size() );
-        assertEquals( "check repositories", 2, configuration.getRemoteRepositories().size() );
-        assertEquals( "check proxy connectors", 2, configuration.getProxyConnectors().size() );
+        assertEquals( "check managed repositories: " + configuration.getManagedRepositories(), managedExpected,
+                      configuration.getManagedRepositories().size() );
+        assertEquals( "check remote repositories: " + configuration.getRemoteRepositories(), 2,
+                      configuration.getRemoteRepositories().size() );
+        assertEquals( "check proxy connectors:" + configuration.getProxyConnectors(), 2,
+                      configuration.getProxyConnectors().size() );
 
         RepositoryScanningConfiguration repoScanning = configuration.getRepositoryScanning();
         assertNotNull( "check repository scanning", repoScanning );
@@ -277,8 +286,7 @@ public class ArchivaConfigurationTest
         assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
 
         // read it back
-        archivaConfiguration =
-            (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-read-saved" );
+        archivaConfiguration = (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-read-saved" );
 
         archivaConfiguration.reload();
         configuration = archivaConfiguration.getConfiguration();
@@ -413,7 +421,6 @@ public class ArchivaConfigurationTest
         assertTrue( "Check file exists", baseFile.exists() );
         assertFalse( "Check file not created", userFile.exists() );
 
-
         // check it
         configuration = archivaConfiguration.getConfiguration();
         assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
@@ -582,16 +589,15 @@ public class ArchivaConfigurationTest
     public void testConfigurationUpgradeFrom09()
         throws Exception
     {
-        ArchivaConfiguration archivaConfiguration =
-            (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-upgrade-09" );
+        ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-upgrade-09" );
 
         // we just use the defaults when upgrading from 0.9 at this point.
         Configuration configuration = archivaConfiguration.getConfiguration();
-        assertConfiguration( configuration );
+        // test-upgrade-09 contains a managed with id: local so it's 3 managed
+        assertConfiguration( configuration, 3 );
         assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
 
-        ManagedRepositoryConfiguration repository =
-            (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
+        ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
 
         assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal",
                       repository.getLocation() );
@@ -614,8 +620,7 @@ public class ArchivaConfigurationTest
         FileUtils.copyFile( getTestFile( "src/test/conf/autodetect-v1.xml" ), userFile );
 
         // Load the original (unconverted) archiva.xml
-        ArchivaConfiguration archivaConfiguration =
-            (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
+        ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
 
         archivaConfiguration.reload();
 
@@ -623,8 +628,7 @@ public class ArchivaConfigurationTest
         assertConfiguration( configuration );
         assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
 
-        ManagedRepositoryConfiguration repository =
-            (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
+        ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
 
         assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
                       repository.getLocation() );
@@ -645,8 +649,7 @@ public class ArchivaConfigurationTest
         //release( archivaConfiguration );
 
         // Reload.
-        archivaConfiguration =
-            (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
+        archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
         configuration = archivaConfiguration.getConfiguration();
 
         // Test that only 1 set of repositories exist.
@@ -714,8 +717,7 @@ public class ArchivaConfigurationTest
         userFile.getParentFile().mkdirs();
         FileUtils.writeStringToFile( userFile, "<configuration/>", null );
 
-        final ArchivaConfiguration archivaConfiguration =
-            lookup( ArchivaConfiguration.class, "test-cron-expressions" );
+        final ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-cron-expressions" );
 
         archivaConfiguration.reload();
 
@@ -726,7 +728,6 @@ public class ArchivaConfigurationTest
 
         assertEquals( "check cron expression", "0 0,30 * * * ?", repository.getRefreshCronExpression().trim() );
 
-
         // add a test listener to confirm it doesn't see the escaped format. We don't need to test the number of calls,
         // etc. as it's done in other tests
         archivaConfiguration.addListener( new ConfigurationListener()
index 838d8cd05cb96a2909924dc3496f2c6369863670..bd0cd8aa99fec159f0282878ca0a143fec158f95 100644 (file)
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-compress</artifactId>
     </dependency>
+    <dependency>
+      <groupId>commons-configuration</groupId>
+      <artifactId>commons-configuration</artifactId>
+      <exclusions>
+        <exclusion>
+          <groupId>commons-logging</groupId>
+          <artifactId>commons-logging</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
     <dependency>
       <groupId>org.apache.cxf</groupId>
       <artifactId>cxf-bundle-jaxrs</artifactId>
diff --git a/pom.xml b/pom.xml
index 11dea20341b68a29677b12e9241aa594bf99206d..15b1354fc2d67f9621f3022d5d14b128049bd1be 100644 (file)
--- a/pom.xml
+++ b/pom.xml
       <dependency>
         <groupId>commons-configuration</groupId>
         <artifactId>commons-configuration</artifactId>
-        <version>1.6</version>
+        <version>1.7</version>
         <exclusions>
           <exclusion>
             <groupId>commons-beanutils</groupId>