From 269c956ea6ed6cdfca26478b8f3743fe076894ce Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Tue, 1 Dec 2009 13:12:56 +0000 Subject: [PATCH] [MNG-4474] [regression] Wagon manager does not respect instantiation strategy of wagons git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@885758 13f79535-47bb-0310-9956-ffa450edef68 --- .../legacy/DefaultWagonManager.java | 15 +++++--- .../legacy/DefaultWagonManagerTest.java | 11 ++++++ .../repository/legacy/PerLookupWagon.java | 38 +++++++++++++++++++ pom.xml | 2 +- 4 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 maven-compat/src/test/java/org/apache/maven/repository/legacy/PerLookupWagon.java diff --git a/maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultWagonManager.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultWagonManager.java index 00e7f388a6..0b4f3aec73 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultWagonManager.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultWagonManager.java @@ -46,6 +46,7 @@ import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.FileUtils; @@ -67,9 +68,6 @@ public class DefaultWagonManager @Requirement private PlexusContainer container; - @Requirement(role = Wagon.class) - private Map wagons; - @Requirement private UpdateCheckManager updateCheckManager; @@ -686,11 +684,16 @@ public class DefaultWagonManager } String hint = protocol.toLowerCase( java.util.Locale.ENGLISH ); - Wagon wagon = (Wagon) wagons.get( hint ); - if ( wagon == null ) + Wagon wagon; + try { - throw new UnsupportedProtocolException( "Cannot find wagon which supports the requested protocol: " + protocol ); + wagon = container.lookup( Wagon.class, hint ); + } + catch ( ComponentLookupException e ) + { + throw new UnsupportedProtocolException( "Cannot find wagon which supports the requested protocol: " + + protocol, e ); } return wagon; diff --git a/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultWagonManagerTest.java b/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultWagonManagerTest.java index b9caef4382..82b67f7122 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultWagonManagerTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/legacy/DefaultWagonManagerTest.java @@ -383,6 +383,17 @@ public class DefaultWagonManagerTest } } + public void testPerLookupInstantiation() + throws Exception + { + String protocol = "perlookup"; + + Wagon one = wagonManager.getWagon( protocol ); + Wagon two = wagonManager.getWagon( protocol ); + + assertNotSame( one, two ); + } + private void assertWagon( String protocol ) throws Exception { diff --git a/maven-compat/src/test/java/org/apache/maven/repository/legacy/PerLookupWagon.java b/maven-compat/src/test/java/org/apache/maven/repository/legacy/PerLookupWagon.java new file mode 100644 index 0000000000..051f3e4689 --- /dev/null +++ b/maven-compat/src/test/java/org/apache/maven/repository/legacy/PerLookupWagon.java @@ -0,0 +1,38 @@ +package org.apache.maven.repository.legacy; + +/* + * 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.wagon.Wagon; +import org.codehaus.plexus.component.annotations.Component; + +/** + * Wagon with per-lookup instantiation strategy. + */ +@Component( role = Wagon.class, hint = "perlookup", instantiationStrategy = "per-lookup" ) +public class PerLookupWagon + extends WagonMock +{ + + public String[] getSupportedProtocols() + { + return new String[] { "perlookup" }; + } + +} diff --git a/pom.xml b/pom.xml index 0c9fffb103..e2d423d0b0 100644 --- a/pom.xml +++ b/pom.xml @@ -41,7 +41,7 @@ 1.2 1.2_Java1.3 3.8.2 - 1.5.1 + 1.5.2 1.11 1.0-alpha-1 2.0.1