Add Thread.getId() to the realm identification, a simple trick to make DefaultMavenRealmManager lifecycle safe for paralel execution.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@611615 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Milos Kleint 2008-01-13 18:19:35 +00:00
parent fc244926ca
commit e10f025310
2 changed files with 46 additions and 5 deletions

View File

@ -1,5 +1,24 @@
package org.apache.maven.execution;
/*
* 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.artifact.Artifact;
import org.apache.maven.model.Plugin;
import org.codehaus.plexus.PlexusContainer;
@ -35,7 +54,7 @@ public class DefaultMavenRealmManager
private Map pluginArtifacts = new HashMap();
private Set managedRealmIds = new HashSet();
private final ClassWorld world;
private final PlexusContainer container;
private final Logger logger;
@ -47,7 +66,7 @@ public class DefaultMavenRealmManager
this.container = container;
this.logger = logger;
}
//mkleint: the clearing is fine for sequenced operations. Even though the
// MavenRealmManager is associated with request, the paralel execution will
// eventualy fail as the ClassWorld and PlexusContainer are not meant for

View File

@ -1,5 +1,24 @@
package org.apache.maven.execution;
/*
* 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.artifact.Artifact;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Plugin;
@ -18,14 +37,16 @@ public final class RealmUtils
public static String createExtensionRealmId( Artifact extensionArtifact )
{
return "/extensions/" + extensionArtifact.getGroupId() + ":"
+ extensionArtifact.getArtifactId() + ":" + extensionArtifact.getVersion();
+ extensionArtifact.getArtifactId() + ":" + extensionArtifact.getVersion() +
"/thread:" + Thread.currentThread().getId(); //add thread to the mix to prevent clashes in paralel execution
}
public static String createProjectId( String projectGroupId,
String projectArtifactId,
String projectVersion )
{
return "/projects/" + projectGroupId + ":" + projectArtifactId + ":" + projectVersion;
return "/projects/" + projectGroupId + ":" + projectArtifactId + ":" + projectVersion +
"/thread:" + Thread.currentThread().getId(); //add thread to the mix to prevent clashes in paralel execution
}
public static String createPluginRealmId( Plugin plugin )
@ -65,7 +86,8 @@ public final class RealmUtils
depId.append( '0' );
}
id.append( '@' ).append( depId.toString().hashCode() );
id.append( '@' ).append( depId.toString().hashCode() )
.append( "/thread:" ).append( Thread.currentThread().getId() ); //add thread to the mix to prevent clashes in paralel execution
return id.toString();
}