Adding configuration entry and removing old v1 repositories

This commit is contained in:
Martin Stockhammer 2017-10-21 14:41:59 +02:00
parent 5416993a99
commit 2c12980a3a
4 changed files with 34 additions and 190 deletions

View File

@ -215,50 +215,6 @@ public class DefaultArchivaConfiguration
config.getRepositoryGroups();
config.getRepositoryGroupsAsMap();
if ( !config.getRepositories().isEmpty() )
{
for ( V1RepositoryConfiguration r : config.getRepositories() )
{
r.setScanned( r.isIndexed() );
if ( StringUtils.startsWith( r.getUrl(), "file://" ) )
{
r.setLocation( r.getUrl().substring( 7 ) );
config.addManagedRepository( r );
}
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();
repo.setId( r.getId() );
repo.setLayout( r.getLayout() );
repo.setName( r.getName() );
repo.setUrl( r.getUrl() );
config.addRemoteRepository( repo );
}
}
// Prevent duplicate repositories from showing up.
config.getRepositories().clear();
registry.removeSubset( KEY + ".repositories" );
}
if ( !CollectionUtils.isEmpty( config.getRemoteRepositories() ) )
{
List<RemoteRepositoryConfiguration> remoteRepos = config.getRemoteRepositories();

View File

@ -19,6 +19,7 @@
-->
<model>
<!-- Current configuration version: 3.0.0 -->
<id>configuration</id>
<name>Configuration</name>
<description>
@ -47,17 +48,12 @@
<description>This is the version of the configuration format.</description>
</field>
<field>
<description>
@deprecated use managedRepositories or remoteRepositories instead.
</description>
<name>repositories</name>
<version>1.0.0+</version>
<association java.generate-add="false"
java.generate-remove="false"
java.adder="false">
<type>V1RepositoryConfiguration</type>
<multiplicity>*</multiplicity>
</association>
<name>metadataStore</name>
<version>3.0.0+</version>
<type>String</type>
<required>true</required>
<defaultValue>jcr</defaultValue>
<description>The type of the metadata storage. Allowed values: jcr, file, cassandra.</description>
</field>
<field>
<name>repositoryGroups</name>

View File

@ -527,27 +527,6 @@ public class ArchivaConfigurationTest
// Expected Path is: Should not have thrown an exception.
}
@Test
public void testConfigurationUpgradeFrom09()
throws Exception
{
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();
// test-upgrade-09 contains a managed with id: local so it's 3 managed
assertConfiguration( configuration, 3, 1, 1 );
assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
repository.getLocation() );
assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
assertEquals( "check managed repositories", "internal", repository.getId() );
assertEquals( "check managed repositories", "default", repository.getLayout() );
assertTrue( "check managed repositories", repository.isScanned() );
}
@Test
public void testConfigurationUpgradeFrom13()
@ -583,93 +562,6 @@ public class ArchivaConfigurationTest
configuration.getRepositoryScanning().getKnownContentConsumers().contains( "duplicate-artifacts" ) );
}
@Test
public void testAutoDetectV1()
throws Exception
{
// Setup the autodetect-v1.xml file in the target directory (so we can save/load it)
Path userFile = getTestFile( "target/test-autodetect-v1/archiva-user.xml" );
Files.deleteIfExists(userFile);
assertFalse( Files.exists(userFile) );
Files.createDirectories(userFile.getParent());
FileUtils.copyFile( getTestFile( "src/test/conf/autodetect-v1.xml" ).toFile(), userFile.toFile());
// Load the original (unconverted) archiva.xml
ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
archivaConfiguration.reload();
Configuration configuration = archivaConfiguration.getConfiguration();
assertConfiguration( configuration, 2, 2, 2 );
assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
repository.getLocation() );
assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
assertEquals( "check managed repositories", "internal", repository.getId() );
assertEquals( "check managed repositories", "default", repository.getLayout() );
assertTrue( "check managed repositories", repository.isScanned() );
// Test that only 1 set of repositories exist.
assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositories().size() );
assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositories().size() );
assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
// Save the file.
archivaConfiguration.save( configuration );
// Reload.
archivaConfiguration = lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
configuration = archivaConfiguration.getConfiguration();
// Test that only 1 set of repositories exist.
assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositories().size() );
assertEquals( "check managed repositories size.", 2, configuration.getManagedRepositoriesAsMap().size() );
assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositories().size() );
assertEquals( "check remote repositories size.", 2, configuration.getRemoteRepositoriesAsMap().size() );
assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
String actualXML = FileUtils.readFileToString( userFile.toFile(), Charset.forName( "UTF-8" ) );
XMLAssert.assertXpathNotExists( "//configuration/repositories/repository", actualXML );
XMLAssert.assertXpathNotExists( "//configuration/repositories", actualXML );
}
@Test
public void testArchivaV1()
throws Exception
{
ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-archiva-v1" );
Configuration configuration = archivaConfiguration.getConfiguration();
assertConfiguration( configuration, 2, 2, 2 );
assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
assertEquals( "check managed repositories", 2, configuration.getManagedRepositories().size() );
assertEquals( "check v1 repositories size.", 0, configuration.getRepositories().size() );
Map<String, ManagedRepositoryConfiguration> map = configuration.getManagedRepositoriesAsMap();
ManagedRepositoryConfiguration repository = map.get( "internal" );
assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
repository.getLocation() );
assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
assertEquals( "check managed repositories", "internal", repository.getId() );
assertEquals( "check managed repositories", "default", repository.getLayout() );
assertTrue( "check managed repositories", repository.isScanned() );
assertFalse( "check managed repositories", repository.isSnapshots() );
repository = map.get( "snapshots" );
assertEquals( "check managed repositories", "${appserver.base}/repositories/snapshots",
repository.getLocation() );
assertEquals( "check managed repositories", "Archiva Managed Snapshot Repository", repository.getName() );
assertEquals( "check managed repositories", "snapshots", repository.getId() );
assertEquals( "check managed repositories", "default", repository.getLayout() );
assertFalse( "check managed repositories", repository.isScanned() );
assertTrue( "check managed repositories", repository.isSnapshots() );
}
@Test
public void testCronExpressionsWithComma()

View File

@ -19,29 +19,43 @@
-->
<configuration>
<version>1</version>
<repositories>
<repository>
<version>3.0.0</version>
<managedRepositories>
<managedRepository>
<id>internal</id>
<name>Archiva Managed Internal Repository</name>
<url>file://${appserver.base}/repositories/internal</url>
<location>file://${appserver.base}/repositories/internal</location>
<indexDir>${appserver.base}/repositories/internal/.indexer</indexDir>
<layout>default</layout>
<releases>true</releases>
<snapshots>false</snapshots>
<indexed>true</indexed>
<refreshCronExpression>0 0 * * * ?</refreshCronExpression>
</repository>
<repository>
</managedRepository>
<managedRepository>
<id>snapshots</id>
<name>Archiva Managed Snapshot Repository</name>
<url>file://${appserver.base}/repositories/snapshots</url>
<location>file://${appserver.base}/repositories/snapshots</location>
<indexDir>.indexer</indexDir>
<layout>default</layout>
<releases>false</releases>
<snapshots>true</snapshots>
<indexed>true</indexed>
<refreshCronExpression>0 0,30 * * * ?</refreshCronExpression>
</repository>
<repository>
</managedRepository>
<managedRepository>
<id>test-repo</id>
<name>Test Repository</name>
<location>file://${appserver.base}/test-repo</location>
<layout>default</layout>
<releases>true</releases>
<snapshots>true</snapshots>
<indexed>true</indexed>
<refreshCronExpression>0 0 * * * ?</refreshCronExpression>
</managedRepository>
</managedRepositories>
<remoteRepositories>
<remoteRepository>
<id>central</id>
<name>Central Repository</name>
<url>http://repo1.maven.org/maven2</url>
@ -49,29 +63,15 @@
<releases>true</releases>
<snapshots>false</snapshots>
<indexed>false</indexed>
</repository>
<repository>
</remoteRepository>
<remoteRepository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net Repository for Maven 2</name>
<url>https://maven2-repository.dev.java.net/nonav/repository</url>
<layout>default</layout>
<releases>true</releases>
<snapshots>false</snapshots>
<indexed>false</indexed>
</repository>
<repository>
<id>test-repo</id>
<name>Test Repository</name>
<url>file://${appserver.base}/test-repo</url>
<layout>default</layout>
<releases>true</releases>
<snapshots>true</snapshots>
<indexed>true</indexed>
<refreshCronExpression>0 0 * * * ?</refreshCronExpression>
<retentionTime>0</retentionTime>
<retentionCount>2</retentionCount>
</repository>
</repositories>
</remoteRepository>
</remoteRepositories>
<proxyConnectors>
<proxyConnector>