You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2009/02/25 05:50:40 UTC
svn commit: r747653 - in
/maven/components/branches/maven-2.1.x/maven-artifact-manager: ./
src/main/java/org/apache/maven/artifact/manager/
src/main/resources/META-INF/plexus/
src/test/java/org/apache/maven/artifact/manager/
Author: brett
Date: Wed Feb 25 04:50:39 2009
New Revision: 747653
URL: http://svn.apache.org/viewvc?rev=747653&view=rev
Log:
[MNG-3739] add workaround for thread sync issue in Plexus
Added:
maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/WagonComponentConfigurator.java (with props)
Modified:
maven/components/branches/maven-2.1.x/maven-artifact-manager/pom.xml
maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java
maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/resources/META-INF/plexus/components.xml
maven/components/branches/maven-2.1.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java
Modified: maven/components/branches/maven-2.1.x/maven-artifact-manager/pom.xml
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-artifact-manager/pom.xml?rev=747653&r1=747652&r2=747653&view=diff
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-artifact-manager/pom.xml (original)
+++ maven/components/branches/maven-2.1.x/maven-artifact-manager/pom.xml Wed Feb 25 04:50:39 2009
@@ -36,6 +36,11 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.apache.maven.wagon</groupId>
+ <artifactId>wagon-http-lightweight</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
@@ -61,6 +66,12 @@
<version>1.2_Java1.3</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>edu.umd.cs.mtc</groupId>
+ <artifactId>multithreadedtc</artifactId>
+ <version>1.01</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
<pluginManagement>
Modified: maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java?rev=747653&r1=747652&r2=747653&view=diff
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java (original)
+++ maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java Wed Feb 25 04:50:39 2009
@@ -1038,9 +1038,7 @@
configureWagon( wagon, repository.getId(), repository.getProtocol() );
}
- private void configureWagon( Wagon wagon,
- String repositoryId,
- String protocol )
+ private void configureWagon( Wagon wagon, String repositoryId, String protocol )
throws WagonConfigurationException
{
PlexusConfiguration config = (PlexusConfiguration) serverConfigurationMap.get( repositoryId );
@@ -1054,7 +1052,7 @@
ComponentConfigurator componentConfigurator = null;
try
{
- componentConfigurator = (ComponentConfigurator) container.lookup( ComponentConfigurator.ROLE );
+ componentConfigurator = (ComponentConfigurator) container.lookup( ComponentConfigurator.ROLE, "wagon" );
componentConfigurator.configureComponent( wagon, config, container.getContainerRealm() );
}
catch ( final ComponentLookupException e )
Added: maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/WagonComponentConfigurator.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/WagonComponentConfigurator.java?rev=747653&view=auto
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/WagonComponentConfigurator.java (added)
+++ maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/WagonComponentConfigurator.java Wed Feb 25 04:50:39 2009
@@ -0,0 +1,47 @@
+package org.apache.maven.artifact.manager;
+
+/*
+ * 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.classworlds.ClassRealm;
+import org.codehaus.plexus.component.configurator.AbstractComponentConfigurator;
+import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
+import org.codehaus.plexus.component.configurator.ConfigurationListener;
+import org.codehaus.plexus.component.configurator.converters.composite.ObjectWithFieldsConverter;
+import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+
+/**
+ * Custom configurator that removes the unnecessary addition of a new converter that caused a thread synchronization
+ * issue. Once fixed in Plexus, this custom component can be removed.
+ */
+public class WagonComponentConfigurator
+ extends AbstractComponentConfigurator
+{
+ public void configureComponent( Object component, PlexusConfiguration configuration,
+ ExpressionEvaluator expressionEvaluator, ClassRealm containerRealm,
+ ConfigurationListener listener )
+ throws ComponentConfigurationException
+ {
+ ObjectWithFieldsConverter converter = new ObjectWithFieldsConverter();
+
+ converter.processConfiguration( converterLookup, component, containerRealm.getClassLoader(), configuration,
+ expressionEvaluator, listener );
+ }
+}
Propchange: maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/WagonComponentConfigurator.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/resources/META-INF/plexus/components.xml?rev=747653&r1=747652&r2=747653&view=diff
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/resources/META-INF/plexus/components.xml (original)
+++ maven/components/branches/maven-2.1.x/maven-artifact-manager/src/main/resources/META-INF/plexus/components.xml Wed Feb 25 04:50:39 2009
@@ -174,6 +174,11 @@
<role>org.apache.maven.artifact.repository.ArtifactRepositoryFactory</role>
<implementation>org.apache.maven.artifact.repository.DefaultArtifactRepositoryFactory</implementation>
</component>
+ <component>
+ <role>org.codehaus.plexus.component.configurator.ComponentConfigurator</role>
+ <implementation>org.apache.maven.artifact.manager.WagonComponentConfigurator</implementation>
+ <role-hint>wagon</role-hint>
+ </component>
</components>
</component-set>
Modified: maven/components/branches/maven-2.1.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java?rev=747653&r1=747652&r2=747653&view=diff
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java (original)
+++ maven/components/branches/maven-2.1.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java Wed Feb 25 04:50:39 2009
@@ -21,10 +21,8 @@
import java.io.File;
import java.io.IOException;
-import java.util.Date;
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -32,19 +30,18 @@
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
-import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException;
import org.apache.maven.wagon.UnsupportedProtocolException;
import org.apache.maven.wagon.Wagon;
-import org.apache.maven.wagon.authorization.AuthorizationException;
-import org.apache.maven.wagon.events.TransferListener;
-import org.apache.maven.wagon.observers.Debug;
+import org.apache.maven.wagon.providers.http.LightweightHttpWagon;
import org.apache.maven.wagon.repository.Repository;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.xml.Xpp3Dom;
-import org.easymock.MockControl;
+
+import edu.umd.cs.mtc.MultithreadedTestCase;
+import edu.umd.cs.mtc.TestFramework;
/**
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
@@ -53,9 +50,11 @@
public class DefaultWagonManagerTest
extends PlexusTestCase
{
- private WagonManager wagonManager;
+ private static final int NUM_EXECUTIONS = 1000;
- private TransferListener transferListener = new Debug();
+ private static final String TEST_USER_AGENT = "Test-Agent/1.0";
+
+ private WagonManager wagonManager;
private ArtifactFactory artifactFactory;
@@ -65,7 +64,7 @@
super.setUp();
wagonManager = (WagonManager) lookup( WagonManager.ROLE );
-
+
artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
}
@@ -81,7 +80,7 @@
assertFalse( artifact.getFile().exists() );
return artifact;
}
-
+
private Artifact createTestArtifact( String directory, String type )
throws IOException
{
@@ -94,12 +93,12 @@
assertFalse( artifact.getFile().exists() );
return artifact;
}
-
+
public void testAddMirrorWithNullRepositoryId()
{
wagonManager.addMirror( null, "test", "http://www.nowhere.com/" );
}
-
+
public void testGetArtifactSha1MissingMd5Present()
throws IOException, UnsupportedProtocolException, TransferFailedException, ResourceDoesNotExistException
{
@@ -110,7 +109,7 @@
StringWagon wagon = (StringWagon) wagonManager.getWagon( "string" );
wagon.addExpectedContent( repo.getLayout().pathOf( artifact ), "expected" );
wagon.addExpectedContent( repo.getLayout().pathOf( artifact ) + ".md5", "bad_checksum" );
-
+
wagonManager.getArtifact( artifact, repo );
assertTrue( artifact.getFile().exists() );
@@ -122,7 +121,7 @@
new DefaultArtifactRepository( "id", "string://url", new ArtifactRepositoryLayoutStub() );
return repo;
}
-
+
/**
* checks the handling of urls
*/
@@ -257,18 +256,16 @@
*/
public void testMirrorStopOnFirstMatch()
{
- //exact matches win first
+ // exact matches win first
wagonManager.addMirror( "a2", "a,b", "http://a2" );
wagonManager.addMirror( "a", "a", "http://a" );
- //make sure repeated entries are skipped
+ // make sure repeated entries are skipped
wagonManager.addMirror( "a", "a", "http://a3" );
-
+
wagonManager.addMirror( "b", "b", "http://b" );
wagonManager.addMirror( "c", "d,e", "http://de" );
wagonManager.addMirror( "c", "*", "http://wildcard" );
wagonManager.addMirror( "c", "e,f", "http://ef" );
-
-
ArtifactRepository repo = null;
repo = wagonManager.getMirrorRepository( getRepo( "a", "http://a.a" ) );
@@ -279,18 +276,18 @@
repo = wagonManager.getMirrorRepository( getRepo( "c", "http://c.c" ) );
assertEquals( "http://wildcard", repo.getUrl() );
-
+
repo = wagonManager.getMirrorRepository( getRepo( "d", "http://d" ) );
assertEquals( "http://de", repo.getUrl() );
-
+
repo = wagonManager.getMirrorRepository( getRepo( "e", "http://e" ) );
assertEquals( "http://de", repo.getUrl() );
-
+
repo = wagonManager.getMirrorRepository( getRepo( "f", "http://f" ) );
assertEquals( "http://wildcard", repo.getUrl() );
}
-
+
/**
* Build an ArtifactRepository object.
*
@@ -384,6 +381,52 @@
}
}
+ public void testGetWagonMultithreaded()
+ throws Throwable
+ {
+ DefaultWagonManager manager = (DefaultWagonManager) wagonManager;
+ manager.setHttpUserAgent( TEST_USER_AGENT );
+ assertNotNull( manager.getHttpUserAgent() );
+
+ TestFramework.runOnce( new MultithreadedTestCase()
+ {
+ private Repository repository;
+
+ public void initialize()
+ {
+ repository = new Repository();
+ repository.setProtocol( "http" );
+ repository.setId( "server" );
+ }
+
+ public void thread1()
+ throws Exception
+ {
+ for ( int i = 0; i < NUM_EXECUTIONS; i++ )
+ {
+ runThread();
+ }
+ }
+
+ public void thread2()
+ throws Exception
+ {
+ for ( int i = 0; i < NUM_EXECUTIONS; i++ )
+ {
+ runThread();
+ }
+ }
+
+ private void runThread()
+ throws Exception
+ {
+ LightweightHttpWagon wagon = (LightweightHttpWagon) wagonManager.getWagon( repository );
+ assertEquals( TEST_USER_AGENT, wagon.getHttpHeaders().getProperty( "User-Agent" ) );
+ container.release( wagon );
+ }
+ } );
+ }
+
/**
* Checks the verification of checksums.
*/
@@ -399,7 +442,7 @@
Artifact artifact = createTestArtifact( "target/test-data/sample-art", "jar" );
StringWagon wagon = (StringWagon) wagonManager.getWagon( "string" );
-
+
artifact.getFile().delete();
wagon.clearExpectedContent();
wagon.addExpectedContent( "path", "lower-case-checksum" );