<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>
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;
*
* @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;
catch ( XMLException e )
{
getLogger().warn( "Unable to read user configuration XML: " + e.getMessage(), e );
- return false;
+ return;
}
if ( !configOk )
{
FileUtils.copyFile( userConfigFile, new File( userConfigFile.getAbsolutePath() + ".bak" ) );
writeDefaultConfigFile( userConfigFile );
- return true;
+ return;
}
catch ( IOException e )
{
}
}
- return false;
+ return;
}
private void upgradeVersion( File userConfigFile, XMLReader xml )
}
}
- 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;
}
-
}
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;
*/
private Registry registry;
+ /**
+ * @plexus.requirement
+ */
+ private ConfigurationUpgrade upgrader;
+
/**
* The configuration that has been converted.
*/
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 ) );
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 )
<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>
implements DatabaseUnprocessedArtifactConsumer, RegistryListener, Initializable
{
private static final String INDEX_ERROR = "indexing_error";
-
+
/**
* @plexus.configuration default-value="index-artifact"
*/
* @plexus.configuration default-value="Index the artifact checksums for Find functionality."
*/
private String description;
-
+
/**
* @plexus.requirement
*/
* @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()
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 );
pnl.path = repository.getUrl().getPath();
pnl.layout = (BidirectionalRepositoryLayout) this.bidirectionalLayoutMap.get( repoconfig.getLayout() );
-
+
pnl.index = indexFactory.createHashcodeIndex( repository );
this.repositoryMap.put( repoconfig.getId(), pnl );
public String path;
public BidirectionalRepositoryLayout layout;
-
+
public RepositoryContentIndex index;
}
}
<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>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>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>configured</role-hint>
</requirement>
+ <requirement>
+ <role>org.apache.maven.archiva.configuration.ConfigurationUpgrade</role>
+ <field-name>upgrader</field-name>
+ </requirement>
</requirements>
</component>
<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>