* under the License.
*/
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.collections.MapUtils;
-import org.apache.commons.configuration.BaseConfiguration;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang.StringUtils;
import org.apache.archiva.configuration.functors.ProxyConnectorConfigurationOrderComparator;
import org.apache.archiva.configuration.io.registry.ConfigurationRegistryReader;
import org.apache.archiva.configuration.io.registry.ConfigurationRegistryWriter;
import org.apache.archiva.policies.Policy;
import org.apache.archiva.policies.PostDownloadPolicy;
import org.apache.archiva.policies.PreDownloadPolicy;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.MapUtils;
+import org.apache.commons.configuration.BaseConfiguration;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.StringUtils;
import org.codehaus.plexus.evaluator.DefaultExpressionEvaluator;
import org.codehaus.plexus.evaluator.EvaluatorException;
import org.codehaus.plexus.evaluator.ExpressionEvaluator;
V1RepositoryConfiguration r = i.next();
r.setScanned( r.isIndexed() );
- if ( r.getUrl().startsWith( "file://" ) )
+ if ( StringUtils.startsWith( r.getUrl(), "file://" ) )
{
r.setLocation( r.getUrl().substring( 7 ) );
config.addManagedRepository( r );
}
- else if ( r.getUrl().startsWith( "file:" ) )
+ 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();
*/
import junit.framework.TestCase;
+import org.apache.archiva.common.utils.FileUtil;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
-import org.apache.archiva.common.utils.FileUtil;
import org.codehaus.plexus.registry.RegistryException;
import org.codehaus.redback.components.springutils.ComponentContainer;
import org.custommonkey.xmlunit.XMLAssert;
* Test the configuration store.
*/
@RunWith( SpringJUnit4ClassRunner.class )
-@ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml","classpath:/spring-context.xml"} )
+@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
public class ArchivaConfigurationTest
extends TestCase
{
return "org/apache/maven/archiva/configuration/spring-context.xml";
}
- protected <T> T lookup(Class<T> clazz, String hint)
+ protected <T> T lookup( Class<T> clazz, String hint )
{
return componentContainer.getComponent( clazz, hint );
}
- protected <T> T lookup(Class<T> clazz)
+ protected <T> T lookup( Class<T> clazz )
{
return componentContainer.getComponent( clazz );
}
existingTestDefaultArchivaConfigFile =
StringUtils.replace( existingTestDefaultArchivaConfigFile, "${appserver.base}", FileUtil.getBasedir() );
- File generatedTestDefaultArchivaConfigFile =
- new File( FileUtil.getBasedir(), "target/test-classes/org/apache/archiva/configuration/default-archiva.xml" );
+ File generatedTestDefaultArchivaConfigFile = new File( FileUtil.getBasedir(),
+ "target/test-classes/org/apache/archiva/configuration/default-archiva.xml" );
FileUtils.writeStringToFile( generatedTestDefaultArchivaConfigFile, existingTestDefaultArchivaConfigFile,
null );
- ArchivaConfiguration archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class,
- "test-defaults-default-repo-location-exists" );
+ ArchivaConfiguration archivaConfiguration =
+ (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-defaults-default-repo-location-exists" );
Configuration configuration = archivaConfiguration.getConfiguration();
assertConfiguration( configuration );
assertFalse( generatedTestDefaultArchivaConfigFile.exists() );
}
+ private void assertConfiguration( Configuration configuration )
+ throws Exception
+ {
+ assertConfiguration( configuration, 2 );
+ }
+
/**
* Ensures that the provided configuration matches the details present in the archiva-default.xml file.
*/
- private void assertConfiguration( Configuration configuration )
+ private void assertConfiguration( Configuration configuration, int managedExpected )
throws Exception
{
- FileTypes filetypes = (FileTypes) lookup( FileTypes.class );
+ FileTypes filetypes = lookup( FileTypes.class );
- assertEquals( "check repositories", 2, configuration.getManagedRepositories().size() );
- assertEquals( "check repositories", 2, configuration.getRemoteRepositories().size() );
- assertEquals( "check proxy connectors", 2, configuration.getProxyConnectors().size() );
+ assertEquals( "check managed repositories: " + configuration.getManagedRepositories(), managedExpected,
+ configuration.getManagedRepositories().size() );
+ assertEquals( "check remote repositories: " + configuration.getRemoteRepositories(), 2,
+ configuration.getRemoteRepositories().size() );
+ assertEquals( "check proxy connectors:" + configuration.getProxyConnectors(), 2,
+ configuration.getProxyConnectors().size() );
RepositoryScanningConfiguration repoScanning = configuration.getRepositoryScanning();
assertNotNull( "check repository scanning", repoScanning );
assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
// read it back
- archivaConfiguration =
- (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-read-saved" );
+ archivaConfiguration = (DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-read-saved" );
archivaConfiguration.reload();
configuration = archivaConfiguration.getConfiguration();
assertTrue( "Check file exists", baseFile.exists() );
assertFalse( "Check file not created", userFile.exists() );
-
// check it
configuration = archivaConfiguration.getConfiguration();
assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
public void testConfigurationUpgradeFrom09()
throws Exception
{
- ArchivaConfiguration archivaConfiguration =
- (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-upgrade-09" );
+ 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();
- assertConfiguration( configuration );
+ // test-upgrade-09 contains a managed with id: local so it's 3 managed
+ assertConfiguration( configuration, 3 );
assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
- ManagedRepositoryConfiguration repository =
- (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
+ ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal",
repository.getLocation() );
FileUtils.copyFile( getTestFile( "src/test/conf/autodetect-v1.xml" ), userFile );
// Load the original (unconverted) archiva.xml
- ArchivaConfiguration archivaConfiguration =
- (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
+ ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
archivaConfiguration.reload();
assertConfiguration( configuration );
assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
- ManagedRepositoryConfiguration repository =
- (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
+ ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
assertEquals( "check managed repositories", "${appserver.base}/repositories/internal",
repository.getLocation() );
//release( archivaConfiguration );
// Reload.
- archivaConfiguration =
- (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
+ archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "test-autodetect-v1" );
configuration = archivaConfiguration.getConfiguration();
// Test that only 1 set of repositories exist.
userFile.getParentFile().mkdirs();
FileUtils.writeStringToFile( userFile, "<configuration/>", null );
- final ArchivaConfiguration archivaConfiguration =
- lookup( ArchivaConfiguration.class, "test-cron-expressions" );
+ final ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-cron-expressions" );
archivaConfiguration.reload();
assertEquals( "check cron expression", "0 0,30 * * * ?", repository.getRefreshCronExpression().trim() );
-
// add a test listener to confirm it doesn't see the escaped format. We don't need to test the number of calls,
// etc. as it's done in other tests
archivaConfiguration.addListener( new ConfigurationListener()