mirror of
https://github.com/apache/archiva.git
synced 2025-02-12 04:56:02 +00:00
experimental Spring support
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches@629309 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0d2d677476
commit
53bc8d5360
@ -50,6 +50,12 @@
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-container-default</artifactId>
|
||||
</dependency>
|
||||
<!-- TODO: temporary spring dependencies for migration -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-beans</artifactId>
|
||||
<version>2.5.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
@ -0,0 +1,49 @@
|
||||
package org.apache.maven.archiva.common.spring;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||
|
||||
public class PlexusFactory
|
||||
{
|
||||
private PlexusContainer container;
|
||||
|
||||
private String role;
|
||||
|
||||
private String roleHint;
|
||||
|
||||
public PlexusFactory( String role, String roleHint )
|
||||
{
|
||||
this.role = role;
|
||||
this.roleHint = roleHint;
|
||||
}
|
||||
|
||||
public Object createInstance()
|
||||
throws ComponentLookupException
|
||||
{
|
||||
return container.lookup( role, roleHint );
|
||||
}
|
||||
|
||||
public void setContainer( PlexusContainer container )
|
||||
{
|
||||
this.container = container;
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package org.apache.maven.archiva.common.spring;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import org.codehaus.plexus.context.Context;
|
||||
import org.codehaus.plexus.context.ContextException;
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
|
||||
/**
|
||||
* @plexus.component role="org.apache.maven.archiva.common.spring.SpringFactory" role-hint="default"
|
||||
*/
|
||||
public class SpringFactory
|
||||
implements Contextualizable
|
||||
{
|
||||
private BeanFactory factory;
|
||||
|
||||
public void contextualize( Context context )
|
||||
throws ContextException
|
||||
{
|
||||
// Grab a Spring component - TODO: should be injected!
|
||||
if ( context.contains( BeanFactory.class ) )
|
||||
{
|
||||
factory = (BeanFactory) context.get( BeanFactory.class );
|
||||
}
|
||||
}
|
||||
|
||||
public Object lookup( String id )
|
||||
{
|
||||
if ( factory != null )
|
||||
{
|
||||
return factory.getBean( id );
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -53,8 +53,8 @@
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -100,11 +100,13 @@ public class DefaultArchivaConfiguration
|
||||
|
||||
/**
|
||||
* @plexus.requirement role="org.apache.maven.archiva.policies.PreDownloadPolicy"
|
||||
* @todo these don't strictly belong in here
|
||||
*/
|
||||
private Map<String, PreDownloadPolicy> prePolicies;
|
||||
|
||||
/**
|
||||
* @plexus.requirement role="org.apache.maven.archiva.policies.PostDownloadPolicy"
|
||||
* @todo these don't strictly belong in here
|
||||
*/
|
||||
private Map<String, PostDownloadPolicy> postPolicies;
|
||||
|
||||
|
@ -20,8 +20,11 @@
|
||||
*/
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.maven.archiva.common.spring.SpringFactory;
|
||||
import org.apache.maven.archiva.policies.urlcache.UrlFailureCache;
|
||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@ -38,27 +41,29 @@
|
||||
*/
|
||||
public class CachedFailuresPolicy
|
||||
extends AbstractLogEnabled
|
||||
implements PreDownloadPolicy
|
||||
implements PreDownloadPolicy, Initializable
|
||||
{
|
||||
/**
|
||||
* The NO policy setting means that the the existence of old failures is <strong>not</strong> checked.
|
||||
* All resource requests are allowed thru to the remote repo.
|
||||
*/
|
||||
public static final String NO = "no";
|
||||
|
||||
|
||||
/**
|
||||
* The YES policy setting means that the existence of old failures is checked, and will
|
||||
* prevent the request from being performed against the remote repo.
|
||||
*/
|
||||
public static final String YES = "yes";
|
||||
|
||||
/**
|
||||
* @plexus.requirement role-hint="default"
|
||||
*/
|
||||
private UrlFailureCache urlFailureCache;
|
||||
|
||||
private List<String> options = new ArrayList<String>();
|
||||
|
||||
/**
|
||||
* @plexus.requirement
|
||||
*/
|
||||
private SpringFactory springFactory;
|
||||
|
||||
public CachedFailuresPolicy()
|
||||
{
|
||||
options.add( NO );
|
||||
@ -70,9 +75,9 @@ public void applyPolicy( String policySetting, Properties request, File localFil
|
||||
{
|
||||
if ( !options.contains( policySetting ) )
|
||||
{
|
||||
// Not a valid code.
|
||||
throw new PolicyConfigurationException( "Unknown cache-failues policy setting [" + policySetting
|
||||
+ "], valid settings are [" + StringUtils.join( options.iterator(), "," ) + "]" );
|
||||
// Not a valid code.
|
||||
throw new PolicyConfigurationException( "Unknown cache-failues policy setting [" + policySetting +
|
||||
"], valid settings are [" + StringUtils.join( options.iterator(), "," ) + "]" );
|
||||
}
|
||||
|
||||
if ( NO.equals( policySetting ) )
|
||||
@ -88,7 +93,8 @@ public void applyPolicy( String policySetting, Properties request, File localFil
|
||||
{
|
||||
if ( urlFailureCache.hasFailedBefore( url ) )
|
||||
{
|
||||
throw new PolicyViolationException( "NO to fetch, check-failures detected previous failure on url: " + url );
|
||||
throw new PolicyViolationException(
|
||||
"NO to fetch, check-failures detected previous failure on url: " + url );
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,4 +115,10 @@ public List<String> getOptions()
|
||||
{
|
||||
return options;
|
||||
}
|
||||
|
||||
public void initialize()
|
||||
throws InitializationException
|
||||
{
|
||||
urlFailureCache = (UrlFailureCache) springFactory.lookup( "urlFailureCache" );
|
||||
}
|
||||
}
|
||||
|
@ -28,18 +28,20 @@
|
||||
*
|
||||
* @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
|
||||
* @version $Id$
|
||||
*
|
||||
* @plexus.component role="org.apache.maven.archiva.policies.urlcache.UrlFailureCache"
|
||||
* role-hint="default"
|
||||
*/
|
||||
public class DefaultUrlFailureCache
|
||||
implements UrlFailureCache
|
||||
{
|
||||
/**
|
||||
* @plexus.requirement role-hint="url-failures-cache"
|
||||
* @todo spring cache instead
|
||||
*/
|
||||
private Cache urlCache;
|
||||
|
||||
public DefaultUrlFailureCache( Cache urlCache )
|
||||
{
|
||||
this.urlCache = urlCache;
|
||||
}
|
||||
|
||||
public void cacheFailure( String url )
|
||||
{
|
||||
urlCache.register( url, new Date() );
|
||||
|
@ -19,14 +19,18 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.archiva.common.spring.PlexusFactory;
|
||||
import org.apache.maven.archiva.policies.urlcache.UrlFailureCache;
|
||||
import org.codehaus.plexus.PlexusTestCase;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* CachedFailuresPolicyTest
|
||||
* CachedFailuresPolicyTest
|
||||
*
|
||||
* @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
|
||||
* @version $Id$
|
||||
@ -34,18 +38,14 @@
|
||||
public class CachedFailuresPolicyTest
|
||||
extends PlexusTestCase
|
||||
{
|
||||
private BeanFactory factory;
|
||||
|
||||
private DownloadPolicy lookupPolicy()
|
||||
throws Exception
|
||||
{
|
||||
return (DownloadPolicy) lookup( PreDownloadPolicy.class.getName(), "cache-failures" );
|
||||
}
|
||||
|
||||
private UrlFailureCache lookupUrlFailureCache()
|
||||
throws Exception
|
||||
{
|
||||
return (UrlFailureCache) lookup( UrlFailureCache.class.getName(), "default" );
|
||||
}
|
||||
|
||||
private File getFile()
|
||||
{
|
||||
return new File( "target/cache-failures/" + getName() + ".txt" );
|
||||
@ -85,14 +85,13 @@ public void testPolicyYesNotInCache()
|
||||
public void testPolicyYesInCache()
|
||||
throws Exception
|
||||
{
|
||||
UrlFailureCache urlFailureCache = lookupUrlFailureCache();
|
||||
|
||||
DownloadPolicy policy = lookupPolicy();
|
||||
File localFile = getFile();
|
||||
Properties request = createRequest();
|
||||
|
||||
String url = "http://a.bad.hostname.maven.org/path/to/resource.txt";
|
||||
|
||||
UrlFailureCache urlFailureCache = (UrlFailureCache) factory.getBean( "urlFailureCache" );
|
||||
urlFailureCache.cacheFailure( url );
|
||||
|
||||
request.setProperty( "url", url );
|
||||
@ -107,4 +106,15 @@ public void testPolicyYesInCache()
|
||||
// expected path.
|
||||
}
|
||||
}
|
||||
|
||||
protected void setUp()
|
||||
throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
factory = new XmlBeanFactory(
|
||||
new ClassPathResource( "/org/apache/maven/archiva/policies/CachedFailuresPolicyTest-context.xml" ) );
|
||||
getContainer().getContext().put( BeanFactory.class, factory );
|
||||
PlexusFactory plexusFactory = (PlexusFactory) factory.getBean( "plexusCacheFactory" );
|
||||
plexusFactory.setContainer( container );
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
|
||||
|
||||
<bean id="urlFailureCache" class="org.apache.maven.archiva.policies.urlcache.DefaultUrlFailureCache">
|
||||
<!-- collaborators and configuration for this bean go here -->
|
||||
<constructor-arg ref="urlCache" type="org.codehaus.plexus.cache.Cache"/>
|
||||
</bean>
|
||||
<bean id="urlCache" factory-bean="plexusCacheFactory" factory-method="createInstance"/>
|
||||
<bean id="plexusCacheFactory" class="org.apache.maven.archiva.common.spring.PlexusFactory">
|
||||
<constructor-arg index="0" value="org.codehaus.plexus.cache.Cache"/>
|
||||
<constructor-arg index="1" value="url-failures-cache"/>
|
||||
</bean>
|
||||
</beans>
|
@ -21,8 +21,8 @@
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.maven.archiva.common.spring.SpringFactory;
|
||||
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||
import org.apache.maven.archiva.configuration.ConfigurationNames;
|
||||
import org.apache.maven.archiva.configuration.NetworkProxyConfiguration;
|
||||
@ -65,8 +65,6 @@
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URLClassLoader;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@ -116,11 +114,13 @@ public class DefaultRepositoryProxyConnectors
|
||||
*/
|
||||
private Map<String, PostDownloadPolicy> postDownloadPolicies;
|
||||
|
||||
/**
|
||||
* @plexus.requirement role-hint="default"
|
||||
*/
|
||||
private UrlFailureCache urlFailureCache;
|
||||
|
||||
/**
|
||||
* @plexus.requirement
|
||||
*/
|
||||
private SpringFactory springFactory;
|
||||
|
||||
private Map<String, List<ProxyConnector>> proxyConnectorMap = new HashMap<String, List<ProxyConnector>>();
|
||||
|
||||
private Map<String, ProxyInfo> networkProxyMap = new HashMap<String, ProxyInfo>();
|
||||
@ -527,10 +527,10 @@ private File transferFile( ProxyConnector connector, RemoteRepositoryContent rem
|
||||
getLogger().info( emsg );
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Wagon wagon = null;
|
||||
try
|
||||
{
|
||||
{
|
||||
RepositoryURL repoUrl = remoteRepository.getURL();
|
||||
String protocol = repoUrl.getProtocol();
|
||||
wagon = (Wagon) wagons.get( protocol );
|
||||
@ -834,7 +834,7 @@ private boolean connectToRepository( ProxyConnector connector, Wagon wagon, Remo
|
||||
|
||||
//Convert seconds to milliseconds
|
||||
int timeoutInMilliseconds = remoteRepository.getRepository().getTimeout() * 1000;
|
||||
|
||||
|
||||
//Set timeout
|
||||
wagon.setTimeout(timeoutInMilliseconds);
|
||||
|
||||
@ -1026,5 +1026,7 @@ public void initialize()
|
||||
{
|
||||
initConnectorsAndNetworkProxies();
|
||||
archivaConfiguration.addChangeListener( this );
|
||||
|
||||
urlFailureCache = (UrlFailureCache) springFactory.lookup( "urlFailureCache" );
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.maven.archiva.common.spring.PlexusFactory;
|
||||
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
|
||||
import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
|
||||
@ -28,11 +29,13 @@
|
||||
import org.apache.maven.archiva.policies.ChecksumPolicy;
|
||||
import org.apache.maven.archiva.policies.ReleasesPolicy;
|
||||
import org.apache.maven.archiva.policies.SnapshotsPolicy;
|
||||
import org.apache.maven.archiva.policies.urlcache.UrlFailureCache;
|
||||
import org.apache.maven.archiva.repository.ManagedRepositoryContent;
|
||||
import org.apache.maven.wagon.Wagon;
|
||||
import org.codehaus.plexus.PlexusTestCase;
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
@ -102,6 +105,8 @@ public abstract class AbstractProxyTestCase
|
||||
|
||||
protected MockConfiguration config;
|
||||
|
||||
protected BeanFactory factory;
|
||||
|
||||
protected void assertChecksums( File expectedFile, String expectedSha1Contents, String expectedMd5Contents )
|
||||
throws Exception
|
||||
{
|
||||
@ -259,14 +264,6 @@ protected ManagedRepositoryContent createRepository( String id, String name, Str
|
||||
return repoContent;
|
||||
}
|
||||
|
||||
protected UrlFailureCache lookupUrlFailureCache()
|
||||
throws Exception
|
||||
{
|
||||
UrlFailureCache failurlCache = (UrlFailureCache) lookup( UrlFailureCache.class.getName(), "default" );
|
||||
assertNotNull( "URL Failure Cache cannot be null.", failurlCache );
|
||||
return failurlCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the first line from the checksum file, and return it (trimmed).
|
||||
*/
|
||||
@ -384,6 +381,12 @@ protected void setUp()
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
factory = new XmlBeanFactory(
|
||||
new ClassPathResource( "/org/apache/maven/archiva/proxy/spring-context.xml" ) );
|
||||
getContainer().getContext().put( BeanFactory.class, factory );
|
||||
PlexusFactory plexusFactory = (PlexusFactory) factory.getBean( "plexusCacheFactory" );
|
||||
plexusFactory.setContainer( container );
|
||||
|
||||
config = (MockConfiguration) lookup( ArchivaConfiguration.class.getName(), "mock" );
|
||||
|
||||
// Setup source repository (using default layout)
|
||||
|
@ -156,4 +156,12 @@ public void testGetWhenInBothProxiedButFirstCacheFailure()
|
||||
assertFileEquals( expectedFile, downloadedFile, proxied2File );
|
||||
assertNoTempFiles( expectedFile );
|
||||
}
|
||||
|
||||
protected UrlFailureCache lookupUrlFailureCache()
|
||||
throws Exception
|
||||
{
|
||||
UrlFailureCache urlFailureCache = (UrlFailureCache) factory.getBean( "urlFailureCache" );
|
||||
assertNotNull( "URL Failure Cache cannot be null.", urlFailureCache );
|
||||
return urlFailureCache;
|
||||
}
|
||||
}
|
||||
|
@ -73,9 +73,8 @@
|
||||
<field-name>postDownloadPolicies</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.archiva.policies.urlcache.UrlFailureCache</role>
|
||||
<role>org.apache.maven.archiva.common.spring.SpringFactory</role>
|
||||
<role-hint>default</role-hint>
|
||||
<field-name>urlFailureCache</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers</role>
|
||||
|
@ -73,9 +73,8 @@
|
||||
<field-name>postDownloadPolicies</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.archiva.policies.urlcache.UrlFailureCache</role>
|
||||
<role>org.apache.maven.archiva.common.spring.SpringFactory</role>
|
||||
<role-hint>default</role-hint>
|
||||
<field-name>urlFailureCache</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers</role>
|
||||
|
@ -73,9 +73,8 @@
|
||||
<field-name>postDownloadPolicies</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.archiva.policies.urlcache.UrlFailureCache</role>
|
||||
<role>org.apache.maven.archiva.common.spring.SpringFactory</role>
|
||||
<role-hint>default</role-hint>
|
||||
<field-name>urlFailureCache</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers</role>
|
||||
|
@ -73,9 +73,8 @@
|
||||
<field-name>postDownloadPolicies</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.archiva.policies.urlcache.UrlFailureCache</role>
|
||||
<role>org.apache.maven.archiva.common.spring.SpringFactory</role>
|
||||
<role-hint>default</role-hint>
|
||||
<field-name>urlFailureCache</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers</role>
|
||||
|
@ -96,9 +96,8 @@
|
||||
<field-name>postDownloadPolicies</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.archiva.policies.urlcache.UrlFailureCache</role>
|
||||
<role>org.apache.maven.archiva.common.spring.SpringFactory</role>
|
||||
<role-hint>default</role-hint>
|
||||
<field-name>urlFailureCache</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers</role>
|
||||
|
@ -73,9 +73,8 @@
|
||||
<field-name>postDownloadPolicies</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.archiva.policies.urlcache.UrlFailureCache</role>
|
||||
<role>org.apache.maven.archiva.common.spring.SpringFactory</role>
|
||||
<role-hint>default</role-hint>
|
||||
<field-name>urlFailureCache</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers</role>
|
||||
|
@ -73,9 +73,8 @@
|
||||
<field-name>postDownloadPolicies</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.archiva.policies.urlcache.UrlFailureCache</role>
|
||||
<role>org.apache.maven.archiva.common.spring.SpringFactory</role>
|
||||
<role-hint>default</role-hint>
|
||||
<field-name>urlFailureCache</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers</role>
|
||||
|
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
|
||||
|
||||
<bean id="urlFailureCache" class="org.apache.maven.archiva.policies.urlcache.DefaultUrlFailureCache">
|
||||
<!-- collaborators and configuration for this bean go here -->
|
||||
<constructor-arg ref="urlCache" type="org.codehaus.plexus.cache.Cache"/>
|
||||
</bean>
|
||||
<bean id="urlCache" factory-bean="plexusCacheFactory" factory-method="createInstance"/>
|
||||
<bean id="plexusCacheFactory" class="org.apache.maven.archiva.common.spring.PlexusFactory">
|
||||
<constructor-arg index="0" value="org.codehaus.plexus.cache.Cache"/>
|
||||
<constructor-arg index="1" value="url-failures-cache"/>
|
||||
</bean>
|
||||
</beans>
|
@ -187,6 +187,11 @@
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-xwork-integration</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<version>2.5.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.derby</groupId>
|
||||
<artifactId>derby</artifactId>
|
||||
|
@ -0,0 +1,50 @@
|
||||
package org.apache.maven.archiva.web.startup;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.archiva.common.spring.PlexusFactory;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
import org.codehaus.plexus.xwork.PlexusLifecycleListener;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
|
||||
public class PlexusSpringListener
|
||||
implements ServletContextListener
|
||||
{
|
||||
public void contextInitialized( ServletContextEvent event )
|
||||
{
|
||||
BeanFactory factory = WebApplicationContextUtils.getRequiredWebApplicationContext( event.getServletContext() );
|
||||
|
||||
PlexusContainer container =
|
||||
(PlexusContainer) event.getServletContext().getAttribute( PlexusLifecycleListener.KEY );
|
||||
|
||||
container.getContext().put( BeanFactory.class, factory );
|
||||
PlexusFactory plexusFactory = (PlexusFactory) factory.getBean( "plexusCacheFactory" );
|
||||
plexusFactory.setContainer( container );
|
||||
}
|
||||
|
||||
public void contextDestroyed( ServletContextEvent event )
|
||||
{
|
||||
// This space left intentionally blank
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"
|
||||
default-lazy-init="true">
|
||||
<!-- default-lazy-init is required by the plexusCacheFactory -->
|
||||
|
||||
<bean id="urlFailureCache" class="org.apache.maven.archiva.policies.urlcache.DefaultUrlFailureCache">
|
||||
<!-- collaborators and configuration for this bean go here -->
|
||||
<constructor-arg ref="urlCache" type="org.codehaus.plexus.cache.Cache"/>
|
||||
</bean>
|
||||
<bean id="urlCache" factory-bean="plexusCacheFactory" factory-method="createInstance" />
|
||||
<bean id="plexusCacheFactory" class="org.apache.maven.archiva.common.spring.PlexusFactory">
|
||||
<constructor-arg index="0" value="org.codehaus.plexus.cache.Cache"/>
|
||||
<constructor-arg index="1" value="url-failures-cache"/>
|
||||
</bean>
|
||||
</beans>
|
@ -59,6 +59,14 @@
|
||||
<listener-class>org.codehaus.plexus.xwork.PlexusLifecycleListener</listener-class>
|
||||
</listener>
|
||||
|
||||
<listener>
|
||||
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
|
||||
</listener>
|
||||
|
||||
<listener>
|
||||
<listener-class>org.apache.maven.archiva.web.startup.PlexusSpringListener</listener-class>
|
||||
</listener>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>RepositoryServlet</servlet-name>
|
||||
<servlet-class>org.apache.maven.archiva.web.repository.RepositoryServlet</servlet-class>
|
||||
@ -72,22 +80,22 @@
|
||||
</servlet-mapping>
|
||||
|
||||
<resource-ref>
|
||||
<res-ref-name>jdbc/users</res-ref-name>
|
||||
<res-type>javax.sql.DataSource</res-type>
|
||||
<res-auth>Container</res-auth>
|
||||
<res-sharing-scope>Shareable</res-sharing-scope>
|
||||
<res-ref-name>jdbc/users</res-ref-name>
|
||||
<res-type>javax.sql.DataSource</res-type>
|
||||
<res-auth>Container</res-auth>
|
||||
<res-sharing-scope>Shareable</res-sharing-scope>
|
||||
</resource-ref>
|
||||
<resource-ref>
|
||||
<res-ref-name>jdbc/archiva</res-ref-name>
|
||||
<res-type>javax.sql.DataSource</res-type>
|
||||
<res-auth>Container</res-auth>
|
||||
<res-sharing-scope>Shareable</res-sharing-scope>
|
||||
<res-ref-name>jdbc/archiva</res-ref-name>
|
||||
<res-type>javax.sql.DataSource</res-type>
|
||||
<res-auth>Container</res-auth>
|
||||
<res-sharing-scope>Shareable</res-sharing-scope>
|
||||
</resource-ref>
|
||||
<resource-ref>
|
||||
<res-ref-name>mail/Session</res-ref-name>
|
||||
<res-type>javax.mail.Session</res-type>
|
||||
<res-auth>Container</res-auth>
|
||||
<res-sharing-scope>Shareable</res-sharing-scope>
|
||||
<res-ref-name>mail/Session</res-ref-name>
|
||||
<res-type>javax.mail.Session</res-type>
|
||||
<res-auth>Container</res-auth>
|
||||
<res-sharing-scope>Shareable</res-sharing-scope>
|
||||
</resource-ref>
|
||||
|
||||
</web-app>
|
||||
|
@ -22,21 +22,23 @@
|
||||
import com.meterware.httpunit.WebResponse;
|
||||
import com.meterware.servletunit.ServletRunner;
|
||||
import com.meterware.servletunit.ServletUnitClient;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.maven.archiva.common.spring.PlexusFactory;
|
||||
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||
import org.apache.maven.archiva.configuration.Configuration;
|
||||
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
|
||||
import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
|
||||
import org.codehaus.plexus.PlexusConstants;
|
||||
import org.codehaus.plexus.PlexusTestCase;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* AbstractRepositoryServletTestCase
|
||||
@ -151,6 +153,12 @@ protected void setUp()
|
||||
File testConfDest = new File( appserverBase, "conf/archiva.xml" );
|
||||
FileUtils.copyFile( testConf, testConfDest );
|
||||
|
||||
BeanFactory factory = new XmlBeanFactory(
|
||||
new ClassPathResource( "/org/apache/maven/archiva/web/repository/spring-context.xml" ) );
|
||||
getContainer().getContext().put( BeanFactory.class, factory );
|
||||
PlexusFactory plexusFactory = (PlexusFactory) factory.getBean( "plexusCacheFactory" );
|
||||
plexusFactory.setContainer( container );
|
||||
|
||||
archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class );
|
||||
repoRootInternal = new File( appserverBase, "data/repositories/internal" );
|
||||
Configuration config = archivaConfiguration.getConfiguration();
|
||||
|
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
|
||||
|
||||
<bean id="urlFailureCache" class="org.apache.maven.archiva.policies.urlcache.DefaultUrlFailureCache">
|
||||
<!-- collaborators and configuration for this bean go here -->
|
||||
<constructor-arg ref="urlCache" type="org.codehaus.plexus.cache.Cache"/>
|
||||
</bean>
|
||||
<bean id="urlCache" factory-bean="plexusCacheFactory" factory-method="createInstance"/>
|
||||
<bean id="plexusCacheFactory" class="org.apache.maven.archiva.common.spring.PlexusFactory">
|
||||
<constructor-arg index="0" value="org.codehaus.plexus.cache.Cache"/>
|
||||
<constructor-arg index="1" value="url-failures-cache"/>
|
||||
</bean>
|
||||
</beans>
|
Loading…
x
Reference in New Issue
Block a user