From 6405f2be6b0a75879dc1ec800ccc41e4f552f2bd Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Mon, 18 Jun 2007 00:54:16 +0000 Subject: [PATCH] [MRM-388] Unable to configure archiva if configuration file did not already exist 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 | 9 +++-- .../configuration/ConfigurationUpgrade.java | 35 +++++++------------ .../DefaultArchivaConfiguration.java | 31 ++++++++++++---- .../ArchivaConfigurationTest.xml | 29 +++++++++++++++ .../lucene/IndexArtifactConsumer.java | 17 ++++----- .../RepositoryContentConsumerUtilTest.xml | 4 +++ .../updater/DatabaseConsumersTest.xml | 4 +++ .../database/updater/DatabaseUpdaterTest.xml | 4 +++ .../ArchivaDatabaseUpdateTaskExecutorTest.xml | 4 +++ ...hivaRepositoryScanningTaskExecutorTest.xml | 4 +++ 10 files changed, 99 insertions(+), 42 deletions(-) diff --git a/archiva-base/archiva-configuration/pom.xml b/archiva-base/archiva-configuration/pom.xml index 80c3855ad..974795cc4 100644 --- a/archiva-base/archiva-configuration/pom.xml +++ b/archiva-base/archiva-configuration/pom.xml @@ -64,16 +64,15 @@ org.codehaus.plexus.registry plexus-registry-api + + org.codehaus.plexus.registry + plexus-registry-commons + org.codehaus.plexus plexus-container-default - - org.codehaus.plexus.registry - plexus-registry-commons - test - easymock easymock diff --git a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/ConfigurationUpgrade.java b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/ConfigurationUpgrade.java index d2e2e3f2f..8ae458516 100644 --- a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/ConfigurationUpgrade.java +++ b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/ConfigurationUpgrade.java @@ -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 Joakim Erdfelt * @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; } - } diff --git a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java index 66f4c7230..3472acdf7 100644 --- a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java +++ b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java @@ -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 ) diff --git a/archiva-base/archiva-configuration/src/test/resources/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.xml b/archiva-base/archiva-configuration/src/test/resources/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.xml index 00c6fceb1..bf757a0d1 100644 --- a/archiva-base/archiva-configuration/src/test/resources/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.xml +++ b/archiva-base/archiva-configuration/src/test/resources/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.xml @@ -29,8 +29,13 @@ org.codehaus.plexus.registry.Registry empty + + org.apache.maven.archiva.configuration.ConfigurationUpgrade + upgrader + + org.codehaus.plexus.registry.Registry empty @@ -48,6 +53,10 @@ org.codehaus.plexus.registry.Registry configured + + org.apache.maven.archiva.configuration.ConfigurationUpgrade + upgrader + @@ -72,6 +81,10 @@ org.codehaus.plexus.registry.Registry save + + org.apache.maven.archiva.configuration.ConfigurationUpgrade + upgrader + @@ -95,6 +108,10 @@ org.codehaus.plexus.registry.Registry save-user + + org.apache.maven.archiva.configuration.ConfigurationUpgrade + upgrader + @@ -120,6 +137,10 @@ org.codehaus.plexus.registry.Registry read-saved + + org.apache.maven.archiva.configuration.ConfigurationUpgrade + upgrader + @@ -143,6 +164,10 @@ org.codehaus.plexus.registry.Registry read-remove-proxied-repo + + org.apache.maven.archiva.configuration.ConfigurationUpgrade + upgrader + @@ -165,6 +190,10 @@ org.codehaus.plexus.registry.Registry read-back-remove-proxied-repo + + org.apache.maven.archiva.configuration.ConfigurationUpgrade + upgrader + diff --git a/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexArtifactConsumer.java b/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexArtifactConsumer.java index 6f9ecff45..467c460d6 100644 --- a/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexArtifactConsumer.java +++ b/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexArtifactConsumer.java @@ -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; } } diff --git a/archiva-base/archiva-repository-layer/src/test/resources/org/apache/maven/archiva/repository/scanner/RepositoryContentConsumerUtilTest.xml b/archiva-base/archiva-repository-layer/src/test/resources/org/apache/maven/archiva/repository/scanner/RepositoryContentConsumerUtilTest.xml index 98b210894..013e5767e 100644 --- a/archiva-base/archiva-repository-layer/src/test/resources/org/apache/maven/archiva/repository/scanner/RepositoryContentConsumerUtilTest.xml +++ b/archiva-base/archiva-repository-layer/src/test/resources/org/apache/maven/archiva/repository/scanner/RepositoryContentConsumerUtilTest.xml @@ -28,6 +28,10 @@ org.codehaus.plexus.registry.Registry configured + + org.apache.maven.archiva.configuration.ConfigurationUpgrade + upgrader + diff --git a/archiva-database/src/test/resources/org/apache/maven/archiva/database/updater/DatabaseConsumersTest.xml b/archiva-database/src/test/resources/org/apache/maven/archiva/database/updater/DatabaseConsumersTest.xml index 07ff811a5..6a3a0be16 100644 --- a/archiva-database/src/test/resources/org/apache/maven/archiva/database/updater/DatabaseConsumersTest.xml +++ b/archiva-database/src/test/resources/org/apache/maven/archiva/database/updater/DatabaseConsumersTest.xml @@ -10,6 +10,10 @@ org.codehaus.plexus.registry.Registry configured + + org.apache.maven.archiva.configuration.ConfigurationUpgrade + upgrader + diff --git a/archiva-database/src/test/resources/org/apache/maven/archiva/database/updater/DatabaseUpdaterTest.xml b/archiva-database/src/test/resources/org/apache/maven/archiva/database/updater/DatabaseUpdaterTest.xml index 07ff811a5..6a3a0be16 100644 --- a/archiva-database/src/test/resources/org/apache/maven/archiva/database/updater/DatabaseUpdaterTest.xml +++ b/archiva-database/src/test/resources/org/apache/maven/archiva/database/updater/DatabaseUpdaterTest.xml @@ -10,6 +10,10 @@ org.codehaus.plexus.registry.Registry configured + + org.apache.maven.archiva.configuration.ConfigurationUpgrade + upgrader + diff --git a/archiva-scheduled/src/test/resources/org/apache/maven/archiva/scheduled/executors/ArchivaDatabaseUpdateTaskExecutorTest.xml b/archiva-scheduled/src/test/resources/org/apache/maven/archiva/scheduled/executors/ArchivaDatabaseUpdateTaskExecutorTest.xml index 8e20ed7ab..0692ad70f 100644 --- a/archiva-scheduled/src/test/resources/org/apache/maven/archiva/scheduled/executors/ArchivaDatabaseUpdateTaskExecutorTest.xml +++ b/archiva-scheduled/src/test/resources/org/apache/maven/archiva/scheduled/executors/ArchivaDatabaseUpdateTaskExecutorTest.xml @@ -42,6 +42,10 @@ org.codehaus.plexus.registry.Registry configured + + org.apache.maven.archiva.configuration.ConfigurationUpgrade + upgrader + diff --git a/archiva-scheduled/src/test/resources/org/apache/maven/archiva/scheduled/executors/ArchivaRepositoryScanningTaskExecutorTest.xml b/archiva-scheduled/src/test/resources/org/apache/maven/archiva/scheduled/executors/ArchivaRepositoryScanningTaskExecutorTest.xml index 1d8e829cc..66141d375 100644 --- a/archiva-scheduled/src/test/resources/org/apache/maven/archiva/scheduled/executors/ArchivaRepositoryScanningTaskExecutorTest.xml +++ b/archiva-scheduled/src/test/resources/org/apache/maven/archiva/scheduled/executors/ArchivaRepositoryScanningTaskExecutorTest.xml @@ -51,6 +51,10 @@ org.codehaus.plexus.registry.Registry configured + + org.apache.maven.archiva.configuration.ConfigurationUpgrade + upgrader + -- 2.39.5