From e10f025310a609cc94736e78d175611967cc0d08 Mon Sep 17 00:00:00 2001 From: Milos Kleint Date: Sun, 13 Jan 2008 18:19:35 +0000 Subject: [PATCH] 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 --- .../execution/DefaultMavenRealmManager.java | 23 +++++++++++++-- .../apache/maven/execution/RealmUtils.java | 28 +++++++++++++++++-- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenRealmManager.java b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenRealmManager.java index 17d8c2771d..e1fe17da40 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenRealmManager.java +++ b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenRealmManager.java @@ -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 diff --git a/maven-core/src/main/java/org/apache/maven/execution/RealmUtils.java b/maven-core/src/main/java/org/apache/maven/execution/RealmUtils.java index 0340620d4d..79a482f5b5 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/RealmUtils.java +++ b/maven-core/src/main/java/org/apache/maven/execution/RealmUtils.java @@ -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(); }