]> source.dussan.org Git - archiva.git/commitdiff
[MRM-388] Unable to configure archiva if configuration file did not already exist
authorJoakim Erdfelt <joakime@apache.org>
Mon, 18 Jun 2007 00:54:16 +0000 (00:54 +0000)
committerJoakim Erdfelt <joakime@apache.org>
Mon, 18 Jun 2007 00:54:16 +0000 (00:54 +0000)
Correcting DatabaseUpgrade process that was causing the problem.

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

archiva-base/archiva-configuration/pom.xml
archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/ConfigurationUpgrade.java
archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java
archiva-base/archiva-configuration/src/test/resources/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.xml
archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexArtifactConsumer.java
archiva-base/archiva-repository-layer/src/test/resources/org/apache/maven/archiva/repository/scanner/RepositoryContentConsumerUtilTest.xml
archiva-database/src/test/resources/org/apache/maven/archiva/database/updater/DatabaseConsumersTest.xml
archiva-database/src/test/resources/org/apache/maven/archiva/database/updater/DatabaseUpdaterTest.xml
archiva-scheduled/src/test/resources/org/apache/maven/archiva/scheduled/executors/ArchivaDatabaseUpdateTaskExecutorTest.xml
archiva-scheduled/src/test/resources/org/apache/maven/archiva/scheduled/executors/ArchivaRepositoryScanningTaskExecutorTest.xml

index 80c3855ad6acc4d2122578354c93343989fd7d3f..974795cc43ed3e34b32cde71be008a6e37b3df5a 100644 (file)
       <groupId>org.codehaus.plexus.registry</groupId>
       <artifactId>plexus-registry-api</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.codehaus.plexus.registry</groupId>
+      <artifactId>plexus-registry-commons</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-container-default</artifactId>
     </dependency>
     <!-- Test Deps -->
-    <dependency>
-      <groupId>org.codehaus.plexus.registry</groupId>
-      <artifactId>plexus-registry-commons</artifactId>
-      <scope>test</scope>
-    </dependency>
     <dependency>
       <groupId>easymock</groupId>
       <artifactId>easymock</artifactId>
index d2e2e3f2f1ca6d1fb094c645c050e7c2689d4791..8ae458516794278eee0154333195ca9ed99aa14e 100644 (file)
@@ -25,8 +25,7 @@ import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.math.NumberUtils;
 import org.apache.maven.archiva.xml.XMLException;
 import org.apache.maven.archiva.xml.XMLReader;
-import org.codehaus.plexus.logging.Logger;
-import org.codehaus.plexus.logging.console.ConsoleLogger;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
 
 import java.io.File;
 import java.io.FileOutputStream;
@@ -41,28 +40,30 @@ import java.net.URL;
  *
  * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
  * @version $Id$
+ * 
+ * @plexus.component role="org.apache.maven.archiva.configuration.ConfigurationUpgrade"
  */
 public class ConfigurationUpgrade
+    extends AbstractLogEnabled
 {
     public static final int CURRENT_CONFIG_VERSION = 1;
 
-    private Logger logger;
+    private boolean performed = false;
 
     /**
      * Perform the upgrade (if needed).
      * 
      * NOTE: This component should *NOT USE* the configuration api to do it's upgrade
-     * 
-     * @return true if the upgrade modified the archiva.xml file. false otherwise.
      */
-    public boolean perform()
+    public void performUpgrade()
     {
+        performed = true;
         File userConfigFile = new File( System.getProperty( "user.home" ), ".m2/archiva.xml" );
 
         if ( !userConfigFile.exists() )
         {
             writeDefaultConfigFile( userConfigFile );
-            return true;
+            return;
         }
 
         boolean configOk = false;
@@ -85,7 +86,7 @@ public class ConfigurationUpgrade
         catch ( XMLException e )
         {
             getLogger().warn( "Unable to read user configuration XML: " + e.getMessage(), e );
-            return false;
+            return;
         }
 
         if ( !configOk )
@@ -94,7 +95,7 @@ public class ConfigurationUpgrade
             {
                 FileUtils.copyFile( userConfigFile, new File( userConfigFile.getAbsolutePath() + ".bak" ) );
                 writeDefaultConfigFile( userConfigFile );
-                return true;
+                return;
             }
             catch ( IOException e )
             {
@@ -102,7 +103,7 @@ public class ConfigurationUpgrade
             }
         }
 
-        return false;
+        return;
     }
 
     private void upgradeVersion( File userConfigFile, XMLReader xml )
@@ -148,18 +149,8 @@ public class ConfigurationUpgrade
         }
     }
 
-    public Logger getLogger()
-    {
-        if ( logger == null )
-        {
-            logger = new ConsoleLogger( ConsoleLogger.LEVEL_INFO, this.getClass().getName() );
-        }
-        return logger;
-    }
-
-    public void setLogger( Logger logger )
+    public boolean hasPerformed()
     {
-        this.logger = logger;
+        return this.performed;
     }
-
 }
index 66f4c7230e8fb216d303fb96ca1c83dda1c392fa..3472acdf79ee0a018bef16015cc3928edb2c0fcc 100644 (file)
@@ -27,6 +27,7 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationExce
 import org.codehaus.plexus.registry.Registry;
 import org.codehaus.plexus.registry.RegistryException;
 import org.codehaus.plexus.registry.RegistryListener;
+import org.codehaus.plexus.registry.commons.CommonsConfigurationRegistry;
 import org.codehaus.plexus.util.StringUtils;
 
 import java.util.Iterator;
@@ -47,6 +48,11 @@ public class DefaultArchivaConfiguration
      */
     private Registry registry;
 
+    /**
+     * @plexus.requirement
+     */
+    private ConfigurationUpgrade upgrader;
+
     /**
      * The configuration that has been converted.
      */
@@ -65,6 +71,24 @@ public class DefaultArchivaConfiguration
 
     private Configuration load()
     {
+        if ( !upgrader.hasPerformed() )
+        {
+            upgrader.performUpgrade();
+            
+            // HACK: This would be so much easier with a registry.reload() method.
+            if ( registry instanceof CommonsConfigurationRegistry )
+            {
+                try
+                {
+                    ( (CommonsConfigurationRegistry) registry ).initialize();
+                }
+                catch ( InitializationException e )
+                {
+                    getLogger().error( "Unable to reinitialize the registry: " + e.getMessage(), e );
+                }
+            }
+        }
+
         // TODO: should this be the same as section? make sure unnamed sections still work (eg, sys properties)
         Configuration config = new ConfigurationRegistryReader().read( registry.getSubset( KEY ) );
 
@@ -110,13 +134,6 @@ public class DefaultArchivaConfiguration
         throws InitializationException
     {
         registry.addChangeListener( this );
-
-        ConfigurationUpgrade upgrade = new ConfigurationUpgrade();
-        upgrade.setLogger( getLogger() );
-        if ( upgrade.perform() )
-        {
-            this.configuration = load();
-        }
     }
 
     public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
index 00c6fceb1393c1ac040d34f2935209ca65bd6733..bf757a0d1245bd491b4db48dc072e6b64df730b9 100644 (file)
           <role>org.codehaus.plexus.registry.Registry</role>
           <role-hint>empty</role-hint>
         </requirement>
+        <requirement>
+          <role>org.apache.maven.archiva.configuration.ConfigurationUpgrade</role>
+          <field-name>upgrader</field-name>
+        </requirement>
       </requirements>
     </component>
+    
     <component>
       <role>org.codehaus.plexus.registry.Registry</role>
       <role-hint>empty</role-hint>
           <role>org.codehaus.plexus.registry.Registry</role>
           <role-hint>configured</role-hint>
         </requirement>
+        <requirement>
+          <role>org.apache.maven.archiva.configuration.ConfigurationUpgrade</role>
+          <field-name>upgrader</field-name>
+        </requirement>
       </requirements>
     </component>
     <component>
           <role>org.codehaus.plexus.registry.Registry</role>
           <role-hint>save</role-hint>
         </requirement>
+        <requirement>
+          <role>org.apache.maven.archiva.configuration.ConfigurationUpgrade</role>
+          <field-name>upgrader</field-name>
+        </requirement>
       </requirements>
     </component>
     <component>
           <role>org.codehaus.plexus.registry.Registry</role>
           <role-hint>save-user</role-hint>
         </requirement>
+        <requirement>
+          <role>org.apache.maven.archiva.configuration.ConfigurationUpgrade</role>
+          <field-name>upgrader</field-name>
+        </requirement>
       </requirements>
     </component>
     <component>
           <role>org.codehaus.plexus.registry.Registry</role>
           <role-hint>read-saved</role-hint>
         </requirement>
+        <requirement>
+          <role>org.apache.maven.archiva.configuration.ConfigurationUpgrade</role>
+          <field-name>upgrader</field-name>
+        </requirement>
       </requirements>
     </component>
     <component>
           <role>org.codehaus.plexus.registry.Registry</role>
           <role-hint>read-remove-proxied-repo</role-hint>
         </requirement>
+        <requirement>
+          <role>org.apache.maven.archiva.configuration.ConfigurationUpgrade</role>
+          <field-name>upgrader</field-name>
+        </requirement>
       </requirements>
     </component>
     <component>
           <role>org.codehaus.plexus.registry.Registry</role>
           <role-hint>read-back-remove-proxied-repo</role-hint>
         </requirement>
+        <requirement>
+          <role>org.apache.maven.archiva.configuration.ConfigurationUpgrade</role>
+          <field-name>upgrader</field-name>
+        </requirement>
       </requirements>
     </component>
     <component>
index 6f9ecff456c50911998a2d1e86527ab7dbb8fca8..467c460d66d61dc9a1429650d9f9a229de111022 100644 (file)
@@ -59,7 +59,7 @@ public class IndexArtifactConsumer
     implements DatabaseUnprocessedArtifactConsumer, RegistryListener, Initializable
 {
     private static final String INDEX_ERROR = "indexing_error";
-    
+
     /**
      * @plexus.configuration default-value="index-artifact"
      */
@@ -69,7 +69,7 @@ public class IndexArtifactConsumer
      * @plexus.configuration default-value="Index the artifact checksums for Find functionality."
      */
     private String description;
-    
+
     /**
      * @plexus.requirement
      */
@@ -79,12 +79,12 @@ public class IndexArtifactConsumer
      * @plexus.requirement role="org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout"
      */
     private Map bidirectionalLayoutMap;
-    
+
     /**
      * @plexus.requirement role-hint="lucene"
      */
     private RepositoryContentIndexFactory indexFactory;
-    
+
     private Map repositoryMap = new HashMap();
 
     public void beginScan()
@@ -108,11 +108,12 @@ public class IndexArtifactConsumer
         HashcodesRecord record = new HashcodesRecord();
         record.setRepositoryId( artifact.getModel().getRepositoryId() );
         record.setArtifact( artifact );
-        
+
         IndexedRepositoryDetails pnl = getIndexedRepositoryDetails( artifact );
+
         String artifactPath = pnl.layout.toPath( artifact );
         record.setFilename( artifactPath );
-        
+
         try
         {
             pnl.index.modifyRecord( record );
@@ -195,7 +196,7 @@ public class IndexArtifactConsumer
 
                 pnl.path = repository.getUrl().getPath();
                 pnl.layout = (BidirectionalRepositoryLayout) this.bidirectionalLayoutMap.get( repoconfig.getLayout() );
-                
+
                 pnl.index = indexFactory.createHashcodeIndex( repository );
 
                 this.repositoryMap.put( repoconfig.getId(), pnl );
@@ -208,7 +209,7 @@ public class IndexArtifactConsumer
         public String path;
 
         public BidirectionalRepositoryLayout layout;
-        
+
         public RepositoryContentIndex index;
     }
 }
index 98b21089484407da2c58c9e4aee84dcdfc55b1b5..013e5767e68b6df0c0ef9bd0cbb855b7d1ffe0f4 100644 (file)
           <role>org.codehaus.plexus.registry.Registry</role>
           <role-hint>configured</role-hint>
         </requirement>
+        <requirement>
+          <role>org.apache.maven.archiva.configuration.ConfigurationUpgrade</role>
+          <field-name>upgrader</field-name>
+        </requirement>
       </requirements>
     </component>
     <component>
index 07ff811a59251099ca6903b0d7e46e5e5174c7a7..6a3a0be16b31dece93cdc5bde76ff270fa88a69d 100644 (file)
           <role>org.codehaus.plexus.registry.Registry</role>
           <role-hint>configured</role-hint>
         </requirement>
+        <requirement>
+          <role>org.apache.maven.archiva.configuration.ConfigurationUpgrade</role>
+          <field-name>upgrader</field-name>
+        </requirement>
       </requirements>
     </component>
     <component>
index 07ff811a59251099ca6903b0d7e46e5e5174c7a7..6a3a0be16b31dece93cdc5bde76ff270fa88a69d 100644 (file)
           <role>org.codehaus.plexus.registry.Registry</role>
           <role-hint>configured</role-hint>
         </requirement>
+        <requirement>
+          <role>org.apache.maven.archiva.configuration.ConfigurationUpgrade</role>
+          <field-name>upgrader</field-name>
+        </requirement>
       </requirements>
     </component>
     <component>
index 8e20ed7abac04929ab7c52fab4cdfb1d8bb14b41..0692ad70f77ae3aeab079f525de173d0e060adf2 100644 (file)
           <role>org.codehaus.plexus.registry.Registry</role>
           <role-hint>configured</role-hint>
         </requirement>
+        <requirement>
+          <role>org.apache.maven.archiva.configuration.ConfigurationUpgrade</role>
+          <field-name>upgrader</field-name>
+        </requirement>
       </requirements>
     </component>
     
index 1d8e829cccf00e55b2070c0abf50423d4653cbe6..66141d375c7299c66e27f53bc4a6ab3e61ea7602 100644 (file)
           <role>org.codehaus.plexus.registry.Registry</role>
           <role-hint>configured</role-hint>
         </requirement>
+        <requirement>
+          <role>org.apache.maven.archiva.configuration.ConfigurationUpgrade</role>
+          <field-name>upgrader</field-name>
+        </requirement>
       </requirements>
     </component>