From 53bc8d5360f9645d1b79c14a6f4eccd2960de12d Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Wed, 20 Feb 2008 01:39:07 +0000 Subject: [PATCH] experimental Spring support git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches@629309 13f79535-47bb-0310-9956-ffa450edef68 --- springy/archiva-base/archiva-common/pom.xml | 6 ++ .../archiva/common/spring/PlexusFactory.java | 49 ++++++++++++++++ .../archiva/common/spring/SpringFactory.java | 56 +++++++++++++++++++ .../DefaultArchivaConfiguration.java | 4 +- .../policies/CachedFailuresPolicy.java | 30 +++++++--- .../urlcache/DefaultUrlFailureCache.java | 10 ++-- .../policies/CachedFailuresPolicyTest.java | 28 +++++++--- .../CachedFailuresPolicyTest-context.xml | 16 ++++++ .../DefaultRepositoryProxyConnectors.java | 18 +++--- .../archiva/proxy/AbstractProxyTestCase.java | 21 ++++--- .../proxy/CacheFailuresTransferTest.java | 8 +++ .../proxy/CacheFailuresTransferTest.xml | 3 +- .../archiva/proxy/ChecksumTransferTest.xml | 3 +- .../proxy/ManagedDefaultTransferTest.xml | 3 +- .../proxy/ManagedLegacyTransferTest.xml | 3 +- .../archiva/proxy/MetadataTransferTest.xml | 3 +- .../archiva/proxy/RelocateTransferTest.xml | 3 +- .../archiva/proxy/SnapshotTransferTest.xml | 3 +- .../maven/archiva/proxy/spring-context.xml | 16 ++++++ springy/archiva-web/archiva-webapp/pom.xml | 5 ++ .../web/startup/PlexusSpringListener.java | 50 +++++++++++++++++ .../webapp/WEB-INF/applicationContext.xml | 18 ++++++ .../src/main/webapp/WEB-INF/web.xml | 32 +++++++---- .../AbstractRepositoryServletTestCase.java | 16 ++++-- .../archiva/web/repository/spring-context.xml | 16 ++++++ 25 files changed, 350 insertions(+), 70 deletions(-) create mode 100644 springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/PlexusFactory.java create mode 100644 springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/SpringFactory.java create mode 100644 springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/CachedFailuresPolicyTest-context.xml create mode 100644 springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/spring-context.xml create mode 100644 springy/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/PlexusSpringListener.java create mode 100644 springy/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml create mode 100644 springy/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/repository/spring-context.xml diff --git a/springy/archiva-base/archiva-common/pom.xml b/springy/archiva-base/archiva-common/pom.xml index c91c18a53..db977b9a3 100644 --- a/springy/archiva-base/archiva-common/pom.xml +++ b/springy/archiva-base/archiva-common/pom.xml @@ -50,6 +50,12 @@ org.codehaus.plexus plexus-container-default + + + org.springframework + spring-beans + 2.5.1 + diff --git a/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/PlexusFactory.java b/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/PlexusFactory.java new file mode 100644 index 000000000..f2a196dd5 --- /dev/null +++ b/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/PlexusFactory.java @@ -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; + } +} diff --git a/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/SpringFactory.java b/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/SpringFactory.java new file mode 100644 index 000000000..0136a6886 --- /dev/null +++ b/springy/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/spring/SpringFactory.java @@ -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; + } + } +} diff --git a/springy/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java b/springy/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java index 4ca6f0229..c7cf4d3ef 100644 --- a/springy/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java +++ b/springy/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java @@ -53,8 +53,8 @@ import java.util.HashSet; 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; /** *

@@ -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 prePolicies; /** * @plexus.requirement role="org.apache.maven.archiva.policies.PostDownloadPolicy" + * @todo these don't strictly belong in here */ private Map postPolicies; diff --git a/springy/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/CachedFailuresPolicy.java b/springy/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/CachedFailuresPolicy.java index c7d44258c..140955ee4 100644 --- a/springy/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/CachedFailuresPolicy.java +++ b/springy/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/CachedFailuresPolicy.java @@ -20,8 +20,11 @@ package org.apache.maven.archiva.policies; */ 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 @@ import java.util.Properties; */ public class CachedFailuresPolicy extends AbstractLogEnabled - implements PreDownloadPolicy + implements PreDownloadPolicy, Initializable { /** * The NO policy setting means that the the existence of old failures is not 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 options = new ArrayList(); + /** + * @plexus.requirement + */ + private SpringFactory springFactory; + public CachedFailuresPolicy() { options.add( NO ); @@ -70,9 +75,9 @@ public class CachedFailuresPolicy { 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 class CachedFailuresPolicy { 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 class CachedFailuresPolicy { return options; } + + public void initialize() + throws InitializationException + { + urlFailureCache = (UrlFailureCache) springFactory.lookup( "urlFailureCache" ); + } } diff --git a/springy/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/urlcache/DefaultUrlFailureCache.java b/springy/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/urlcache/DefaultUrlFailureCache.java index a520a151c..cb2c66e71 100644 --- a/springy/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/urlcache/DefaultUrlFailureCache.java +++ b/springy/archiva-base/archiva-policies/src/main/java/org/apache/maven/archiva/policies/urlcache/DefaultUrlFailureCache.java @@ -28,18 +28,20 @@ import java.util.Date; * * @author Joakim Erdfelt * @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() ); diff --git a/springy/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/CachedFailuresPolicyTest.java b/springy/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/CachedFailuresPolicyTest.java index 61e89ab3e..edb85b8ab 100644 --- a/springy/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/CachedFailuresPolicyTest.java +++ b/springy/archiva-base/archiva-policies/src/test/java/org/apache/maven/archiva/policies/CachedFailuresPolicyTest.java @@ -19,14 +19,18 @@ package org.apache.maven.archiva.policies; * 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 Joakim Erdfelt * @version $Id$ @@ -34,18 +38,14 @@ import java.util.Properties; 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 class CachedFailuresPolicyTest 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 class CachedFailuresPolicyTest // 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 ); + } } diff --git a/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/CachedFailuresPolicyTest-context.xml b/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/CachedFailuresPolicyTest-context.xml new file mode 100644 index 000000000..055e8f93c --- /dev/null +++ b/springy/archiva-base/archiva-policies/src/test/resources/org/apache/maven/archiva/policies/CachedFailuresPolicyTest-context.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/springy/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java b/springy/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java index 208f822ef..5039d4fbe 100644 --- a/springy/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java +++ b/springy/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java @@ -21,8 +21,8 @@ package org.apache.maven.archiva.proxy; 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 org.codehaus.plexus.util.SelectorUtils; 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,10 +114,12 @@ public class DefaultRepositoryProxyConnectors */ private Map postDownloadPolicies; + private UrlFailureCache urlFailureCache; + /** - * @plexus.requirement role-hint="default" + * @plexus.requirement */ - private UrlFailureCache urlFailureCache; + private SpringFactory springFactory; private Map> proxyConnectorMap = new HashMap>(); @@ -527,10 +527,10 @@ public class DefaultRepositoryProxyConnectors 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 @@ public class DefaultRepositoryProxyConnectors //Convert seconds to milliseconds int timeoutInMilliseconds = remoteRepository.getRepository().getTimeout() * 1000; - + //Set timeout wagon.setTimeout(timeoutInMilliseconds); @@ -1026,5 +1026,7 @@ public class DefaultRepositoryProxyConnectors { initConnectorsAndNetworkProxies(); archivaConfiguration.addChangeListener( this ); + + urlFailureCache = (UrlFailureCache) springFactory.lookup( "urlFailureCache" ); } } diff --git a/springy/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java b/springy/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java index 8527ade4f..49e019bb7 100644 --- a/springy/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java +++ b/springy/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java @@ -20,6 +20,7 @@ package org.apache.maven.archiva.proxy; */ 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.CachedFailuresPolicy; 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 @@ public abstract class AbstractProxyTestCase 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 @@ public abstract class AbstractProxyTestCase { 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) diff --git a/springy/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.java b/springy/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.java index 73452adac..21504f48c 100644 --- a/springy/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.java +++ b/springy/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.java @@ -156,4 +156,12 @@ public class CacheFailuresTransferTest 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; + } } diff --git a/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.xml b/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.xml index d6b58680e..c686d6a93 100644 --- a/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.xml +++ b/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.xml @@ -73,9 +73,8 @@ postDownloadPolicies - org.apache.maven.archiva.policies.urlcache.UrlFailureCache + org.apache.maven.archiva.common.spring.SpringFactory default - urlFailureCache org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers diff --git a/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/ChecksumTransferTest.xml b/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/ChecksumTransferTest.xml index d678aaedc..efc12cd52 100644 --- a/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/ChecksumTransferTest.xml +++ b/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/ChecksumTransferTest.xml @@ -73,9 +73,8 @@ postDownloadPolicies - org.apache.maven.archiva.policies.urlcache.UrlFailureCache + org.apache.maven.archiva.common.spring.SpringFactory default - urlFailureCache org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers diff --git a/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.xml b/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.xml index d678aaedc..efc12cd52 100644 --- a/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.xml +++ b/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.xml @@ -73,9 +73,8 @@ postDownloadPolicies - org.apache.maven.archiva.policies.urlcache.UrlFailureCache + org.apache.maven.archiva.common.spring.SpringFactory default - urlFailureCache org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers diff --git a/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/ManagedLegacyTransferTest.xml b/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/ManagedLegacyTransferTest.xml index d678aaedc..efc12cd52 100644 --- a/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/ManagedLegacyTransferTest.xml +++ b/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/ManagedLegacyTransferTest.xml @@ -73,9 +73,8 @@ postDownloadPolicies - org.apache.maven.archiva.policies.urlcache.UrlFailureCache + org.apache.maven.archiva.common.spring.SpringFactory default - urlFailureCache org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers diff --git a/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/MetadataTransferTest.xml b/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/MetadataTransferTest.xml index d63f77c61..d9611461e 100644 --- a/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/MetadataTransferTest.xml +++ b/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/MetadataTransferTest.xml @@ -96,9 +96,8 @@ postDownloadPolicies - org.apache.maven.archiva.policies.urlcache.UrlFailureCache + org.apache.maven.archiva.common.spring.SpringFactory default - urlFailureCache org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers diff --git a/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/RelocateTransferTest.xml b/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/RelocateTransferTest.xml index d678aaedc..efc12cd52 100644 --- a/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/RelocateTransferTest.xml +++ b/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/RelocateTransferTest.xml @@ -73,9 +73,8 @@ postDownloadPolicies - org.apache.maven.archiva.policies.urlcache.UrlFailureCache + org.apache.maven.archiva.common.spring.SpringFactory default - urlFailureCache org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers diff --git a/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/SnapshotTransferTest.xml b/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/SnapshotTransferTest.xml index d678aaedc..efc12cd52 100644 --- a/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/SnapshotTransferTest.xml +++ b/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/SnapshotTransferTest.xml @@ -73,9 +73,8 @@ postDownloadPolicies - org.apache.maven.archiva.policies.urlcache.UrlFailureCache + org.apache.maven.archiva.common.spring.SpringFactory default - urlFailureCache org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers diff --git a/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/spring-context.xml b/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/spring-context.xml new file mode 100644 index 000000000..055e8f93c --- /dev/null +++ b/springy/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/spring-context.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/springy/archiva-web/archiva-webapp/pom.xml b/springy/archiva-web/archiva-webapp/pom.xml index e798ef016..d6898ccf0 100644 --- a/springy/archiva-web/archiva-webapp/pom.xml +++ b/springy/archiva-web/archiva-webapp/pom.xml @@ -187,6 +187,11 @@ org.codehaus.plexus plexus-xwork-integration + + org.springframework + spring-web + 2.5.1 + org.apache.derby derby diff --git a/springy/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/PlexusSpringListener.java b/springy/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/PlexusSpringListener.java new file mode 100644 index 000000000..6a4e5dc0c --- /dev/null +++ b/springy/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/PlexusSpringListener.java @@ -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 + } +} diff --git a/springy/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml b/springy/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml new file mode 100644 index 000000000..188d9d325 --- /dev/null +++ b/springy/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/applicationContext.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/springy/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/web.xml b/springy/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/web.xml index f47d6ebc1..ca7015806 100644 --- a/springy/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/web.xml +++ b/springy/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/web.xml @@ -59,6 +59,14 @@ org.codehaus.plexus.xwork.PlexusLifecycleListener + + org.springframework.web.context.ContextLoaderListener + + + + org.apache.maven.archiva.web.startup.PlexusSpringListener + + RepositoryServlet org.apache.maven.archiva.web.repository.RepositoryServlet @@ -72,22 +80,22 @@ - jdbc/users - javax.sql.DataSource - Container - Shareable + jdbc/users + javax.sql.DataSource + Container + Shareable - jdbc/archiva - javax.sql.DataSource - Container - Shareable + jdbc/archiva + javax.sql.DataSource + Container + Shareable - mail/Session - javax.mail.Session - Container - Shareable + mail/Session + javax.mail.Session + Container + Shareable diff --git a/springy/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletTestCase.java b/springy/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletTestCase.java index 7b79e7978..a72c99b9b 100644 --- a/springy/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletTestCase.java +++ b/springy/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletTestCase.java @@ -22,21 +22,23 @@ package org.apache.maven.archiva.web.repository; 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 @@ public abstract class AbstractRepositoryServletTestCase 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(); diff --git a/springy/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/repository/spring-context.xml b/springy/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/repository/spring-context.xml new file mode 100644 index 000000000..055e8f93c --- /dev/null +++ b/springy/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/repository/spring-context.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + \ No newline at end of file -- 2.39.5