mirror of https://github.com/apache/archiva.git
[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
This commit is contained in:
parent
502b1c454d
commit
6405f2be6b
|
@ -64,16 +64,15 @@
|
||||||
<groupId>org.codehaus.plexus.registry</groupId>
|
<groupId>org.codehaus.plexus.registry</groupId>
|
||||||
<artifactId>plexus-registry-api</artifactId>
|
<artifactId>plexus-registry-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.plexus.registry</groupId>
|
||||||
|
<artifactId>plexus-registry-commons</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.codehaus.plexus</groupId>
|
<groupId>org.codehaus.plexus</groupId>
|
||||||
<artifactId>plexus-container-default</artifactId>
|
<artifactId>plexus-container-default</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Test Deps -->
|
<!-- Test Deps -->
|
||||||
<dependency>
|
|
||||||
<groupId>org.codehaus.plexus.registry</groupId>
|
|
||||||
<artifactId>plexus-registry-commons</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>easymock</groupId>
|
<groupId>easymock</groupId>
|
||||||
<artifactId>easymock</artifactId>
|
<artifactId>easymock</artifactId>
|
||||||
|
|
|
@ -25,8 +25,7 @@ import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.lang.math.NumberUtils;
|
import org.apache.commons.lang.math.NumberUtils;
|
||||||
import org.apache.maven.archiva.xml.XMLException;
|
import org.apache.maven.archiva.xml.XMLException;
|
||||||
import org.apache.maven.archiva.xml.XMLReader;
|
import org.apache.maven.archiva.xml.XMLReader;
|
||||||
import org.codehaus.plexus.logging.Logger;
|
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||||
import org.codehaus.plexus.logging.console.ConsoleLogger;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
@ -41,28 +40,30 @@ import java.net.URL;
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
|
*
|
||||||
|
* @plexus.component role="org.apache.maven.archiva.configuration.ConfigurationUpgrade"
|
||||||
*/
|
*/
|
||||||
public class ConfigurationUpgrade
|
public class ConfigurationUpgrade
|
||||||
|
extends AbstractLogEnabled
|
||||||
{
|
{
|
||||||
public static final int CURRENT_CONFIG_VERSION = 1;
|
public static final int CURRENT_CONFIG_VERSION = 1;
|
||||||
|
|
||||||
private Logger logger;
|
private boolean performed = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform the upgrade (if needed).
|
* Perform the upgrade (if needed).
|
||||||
*
|
*
|
||||||
* NOTE: This component should *NOT USE* the configuration api to do it's upgrade
|
* 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" );
|
File userConfigFile = new File( System.getProperty( "user.home" ), ".m2/archiva.xml" );
|
||||||
|
|
||||||
if ( !userConfigFile.exists() )
|
if ( !userConfigFile.exists() )
|
||||||
{
|
{
|
||||||
writeDefaultConfigFile( userConfigFile );
|
writeDefaultConfigFile( userConfigFile );
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean configOk = false;
|
boolean configOk = false;
|
||||||
|
@ -85,7 +86,7 @@ public class ConfigurationUpgrade
|
||||||
catch ( XMLException e )
|
catch ( XMLException e )
|
||||||
{
|
{
|
||||||
getLogger().warn( "Unable to read user configuration XML: " + e.getMessage(), e );
|
getLogger().warn( "Unable to read user configuration XML: " + e.getMessage(), e );
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !configOk )
|
if ( !configOk )
|
||||||
|
@ -94,7 +95,7 @@ public class ConfigurationUpgrade
|
||||||
{
|
{
|
||||||
FileUtils.copyFile( userConfigFile, new File( userConfigFile.getAbsolutePath() + ".bak" ) );
|
FileUtils.copyFile( userConfigFile, new File( userConfigFile.getAbsolutePath() + ".bak" ) );
|
||||||
writeDefaultConfigFile( userConfigFile );
|
writeDefaultConfigFile( userConfigFile );
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
catch ( IOException e )
|
catch ( IOException e )
|
||||||
{
|
{
|
||||||
|
@ -102,7 +103,7 @@ public class ConfigurationUpgrade
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void upgradeVersion( File userConfigFile, XMLReader xml )
|
private void upgradeVersion( File userConfigFile, XMLReader xml )
|
||||||
|
@ -148,18 +149,8 @@ public class ConfigurationUpgrade
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Logger getLogger()
|
public boolean hasPerformed()
|
||||||
{
|
{
|
||||||
if ( logger == null )
|
return this.performed;
|
||||||
{
|
|
||||||
logger = new ConsoleLogger( ConsoleLogger.LEVEL_INFO, this.getClass().getName() );
|
|
||||||
}
|
|
||||||
return logger;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLogger( Logger logger )
|
|
||||||
{
|
|
||||||
this.logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationExce
|
||||||
import org.codehaus.plexus.registry.Registry;
|
import org.codehaus.plexus.registry.Registry;
|
||||||
import org.codehaus.plexus.registry.RegistryException;
|
import org.codehaus.plexus.registry.RegistryException;
|
||||||
import org.codehaus.plexus.registry.RegistryListener;
|
import org.codehaus.plexus.registry.RegistryListener;
|
||||||
|
import org.codehaus.plexus.registry.commons.CommonsConfigurationRegistry;
|
||||||
import org.codehaus.plexus.util.StringUtils;
|
import org.codehaus.plexus.util.StringUtils;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -47,6 +48,11 @@ public class DefaultArchivaConfiguration
|
||||||
*/
|
*/
|
||||||
private Registry registry;
|
private Registry registry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @plexus.requirement
|
||||||
|
*/
|
||||||
|
private ConfigurationUpgrade upgrader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The configuration that has been converted.
|
* The configuration that has been converted.
|
||||||
*/
|
*/
|
||||||
|
@ -65,6 +71,24 @@ public class DefaultArchivaConfiguration
|
||||||
|
|
||||||
private Configuration load()
|
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)
|
// 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 ) );
|
Configuration config = new ConfigurationRegistryReader().read( registry.getSubset( KEY ) );
|
||||||
|
|
||||||
|
@ -110,13 +134,6 @@ public class DefaultArchivaConfiguration
|
||||||
throws InitializationException
|
throws InitializationException
|
||||||
{
|
{
|
||||||
registry.addChangeListener( this );
|
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 )
|
public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
|
||||||
|
|
|
@ -29,8 +29,13 @@
|
||||||
<role>org.codehaus.plexus.registry.Registry</role>
|
<role>org.codehaus.plexus.registry.Registry</role>
|
||||||
<role-hint>empty</role-hint>
|
<role-hint>empty</role-hint>
|
||||||
</requirement>
|
</requirement>
|
||||||
|
<requirement>
|
||||||
|
<role>org.apache.maven.archiva.configuration.ConfigurationUpgrade</role>
|
||||||
|
<field-name>upgrader</field-name>
|
||||||
|
</requirement>
|
||||||
</requirements>
|
</requirements>
|
||||||
</component>
|
</component>
|
||||||
|
|
||||||
<component>
|
<component>
|
||||||
<role>org.codehaus.plexus.registry.Registry</role>
|
<role>org.codehaus.plexus.registry.Registry</role>
|
||||||
<role-hint>empty</role-hint>
|
<role-hint>empty</role-hint>
|
||||||
|
@ -48,6 +53,10 @@
|
||||||
<role>org.codehaus.plexus.registry.Registry</role>
|
<role>org.codehaus.plexus.registry.Registry</role>
|
||||||
<role-hint>configured</role-hint>
|
<role-hint>configured</role-hint>
|
||||||
</requirement>
|
</requirement>
|
||||||
|
<requirement>
|
||||||
|
<role>org.apache.maven.archiva.configuration.ConfigurationUpgrade</role>
|
||||||
|
<field-name>upgrader</field-name>
|
||||||
|
</requirement>
|
||||||
</requirements>
|
</requirements>
|
||||||
</component>
|
</component>
|
||||||
<component>
|
<component>
|
||||||
|
@ -72,6 +81,10 @@
|
||||||
<role>org.codehaus.plexus.registry.Registry</role>
|
<role>org.codehaus.plexus.registry.Registry</role>
|
||||||
<role-hint>save</role-hint>
|
<role-hint>save</role-hint>
|
||||||
</requirement>
|
</requirement>
|
||||||
|
<requirement>
|
||||||
|
<role>org.apache.maven.archiva.configuration.ConfigurationUpgrade</role>
|
||||||
|
<field-name>upgrader</field-name>
|
||||||
|
</requirement>
|
||||||
</requirements>
|
</requirements>
|
||||||
</component>
|
</component>
|
||||||
<component>
|
<component>
|
||||||
|
@ -95,6 +108,10 @@
|
||||||
<role>org.codehaus.plexus.registry.Registry</role>
|
<role>org.codehaus.plexus.registry.Registry</role>
|
||||||
<role-hint>save-user</role-hint>
|
<role-hint>save-user</role-hint>
|
||||||
</requirement>
|
</requirement>
|
||||||
|
<requirement>
|
||||||
|
<role>org.apache.maven.archiva.configuration.ConfigurationUpgrade</role>
|
||||||
|
<field-name>upgrader</field-name>
|
||||||
|
</requirement>
|
||||||
</requirements>
|
</requirements>
|
||||||
</component>
|
</component>
|
||||||
<component>
|
<component>
|
||||||
|
@ -120,6 +137,10 @@
|
||||||
<role>org.codehaus.plexus.registry.Registry</role>
|
<role>org.codehaus.plexus.registry.Registry</role>
|
||||||
<role-hint>read-saved</role-hint>
|
<role-hint>read-saved</role-hint>
|
||||||
</requirement>
|
</requirement>
|
||||||
|
<requirement>
|
||||||
|
<role>org.apache.maven.archiva.configuration.ConfigurationUpgrade</role>
|
||||||
|
<field-name>upgrader</field-name>
|
||||||
|
</requirement>
|
||||||
</requirements>
|
</requirements>
|
||||||
</component>
|
</component>
|
||||||
<component>
|
<component>
|
||||||
|
@ -143,6 +164,10 @@
|
||||||
<role>org.codehaus.plexus.registry.Registry</role>
|
<role>org.codehaus.plexus.registry.Registry</role>
|
||||||
<role-hint>read-remove-proxied-repo</role-hint>
|
<role-hint>read-remove-proxied-repo</role-hint>
|
||||||
</requirement>
|
</requirement>
|
||||||
|
<requirement>
|
||||||
|
<role>org.apache.maven.archiva.configuration.ConfigurationUpgrade</role>
|
||||||
|
<field-name>upgrader</field-name>
|
||||||
|
</requirement>
|
||||||
</requirements>
|
</requirements>
|
||||||
</component>
|
</component>
|
||||||
<component>
|
<component>
|
||||||
|
@ -165,6 +190,10 @@
|
||||||
<role>org.codehaus.plexus.registry.Registry</role>
|
<role>org.codehaus.plexus.registry.Registry</role>
|
||||||
<role-hint>read-back-remove-proxied-repo</role-hint>
|
<role-hint>read-back-remove-proxied-repo</role-hint>
|
||||||
</requirement>
|
</requirement>
|
||||||
|
<requirement>
|
||||||
|
<role>org.apache.maven.archiva.configuration.ConfigurationUpgrade</role>
|
||||||
|
<field-name>upgrader</field-name>
|
||||||
|
</requirement>
|
||||||
</requirements>
|
</requirements>
|
||||||
</component>
|
</component>
|
||||||
<component>
|
<component>
|
||||||
|
|
|
@ -110,6 +110,7 @@ public class IndexArtifactConsumer
|
||||||
record.setArtifact( artifact );
|
record.setArtifact( artifact );
|
||||||
|
|
||||||
IndexedRepositoryDetails pnl = getIndexedRepositoryDetails( artifact );
|
IndexedRepositoryDetails pnl = getIndexedRepositoryDetails( artifact );
|
||||||
|
|
||||||
String artifactPath = pnl.layout.toPath( artifact );
|
String artifactPath = pnl.layout.toPath( artifact );
|
||||||
record.setFilename( artifactPath );
|
record.setFilename( artifactPath );
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,10 @@
|
||||||
<role>org.codehaus.plexus.registry.Registry</role>
|
<role>org.codehaus.plexus.registry.Registry</role>
|
||||||
<role-hint>configured</role-hint>
|
<role-hint>configured</role-hint>
|
||||||
</requirement>
|
</requirement>
|
||||||
|
<requirement>
|
||||||
|
<role>org.apache.maven.archiva.configuration.ConfigurationUpgrade</role>
|
||||||
|
<field-name>upgrader</field-name>
|
||||||
|
</requirement>
|
||||||
</requirements>
|
</requirements>
|
||||||
</component>
|
</component>
|
||||||
<component>
|
<component>
|
||||||
|
|
|
@ -10,6 +10,10 @@
|
||||||
<role>org.codehaus.plexus.registry.Registry</role>
|
<role>org.codehaus.plexus.registry.Registry</role>
|
||||||
<role-hint>configured</role-hint>
|
<role-hint>configured</role-hint>
|
||||||
</requirement>
|
</requirement>
|
||||||
|
<requirement>
|
||||||
|
<role>org.apache.maven.archiva.configuration.ConfigurationUpgrade</role>
|
||||||
|
<field-name>upgrader</field-name>
|
||||||
|
</requirement>
|
||||||
</requirements>
|
</requirements>
|
||||||
</component>
|
</component>
|
||||||
<component>
|
<component>
|
||||||
|
|
|
@ -10,6 +10,10 @@
|
||||||
<role>org.codehaus.plexus.registry.Registry</role>
|
<role>org.codehaus.plexus.registry.Registry</role>
|
||||||
<role-hint>configured</role-hint>
|
<role-hint>configured</role-hint>
|
||||||
</requirement>
|
</requirement>
|
||||||
|
<requirement>
|
||||||
|
<role>org.apache.maven.archiva.configuration.ConfigurationUpgrade</role>
|
||||||
|
<field-name>upgrader</field-name>
|
||||||
|
</requirement>
|
||||||
</requirements>
|
</requirements>
|
||||||
</component>
|
</component>
|
||||||
<component>
|
<component>
|
||||||
|
|
|
@ -42,6 +42,10 @@
|
||||||
<role>org.codehaus.plexus.registry.Registry</role>
|
<role>org.codehaus.plexus.registry.Registry</role>
|
||||||
<role-hint>configured</role-hint>
|
<role-hint>configured</role-hint>
|
||||||
</requirement>
|
</requirement>
|
||||||
|
<requirement>
|
||||||
|
<role>org.apache.maven.archiva.configuration.ConfigurationUpgrade</role>
|
||||||
|
<field-name>upgrader</field-name>
|
||||||
|
</requirement>
|
||||||
</requirements>
|
</requirements>
|
||||||
</component>
|
</component>
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,10 @@
|
||||||
<role>org.codehaus.plexus.registry.Registry</role>
|
<role>org.codehaus.plexus.registry.Registry</role>
|
||||||
<role-hint>configured</role-hint>
|
<role-hint>configured</role-hint>
|
||||||
</requirement>
|
</requirement>
|
||||||
|
<requirement>
|
||||||
|
<role>org.apache.maven.archiva.configuration.ConfigurationUpgrade</role>
|
||||||
|
<field-name>upgrader</field-name>
|
||||||
|
</requirement>
|
||||||
</requirements>
|
</requirements>
|
||||||
</component>
|
</component>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue