From 6e302e26c914ec389491752a6f526d61956ab795 Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Thu, 13 Aug 2009 09:03:07 +0000 Subject: [PATCH] [MNG-4296] allow core extensions configure new classrealms Submitted by: Igor Fedorenko git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@803811 13f79535-47bb-0310-9956-ffa450edef68 --- .../classrealm/ClassRealmManagerDelegate.java | 34 +++++++++++++++++++ .../classrealm/DefaultClassRealmManager.java | 20 +++++++++++ 2 files changed, 54 insertions(+) create mode 100644 maven-core/src/main/java/org/apache/maven/classrealm/ClassRealmManagerDelegate.java diff --git a/maven-core/src/main/java/org/apache/maven/classrealm/ClassRealmManagerDelegate.java b/maven-core/src/main/java/org/apache/maven/classrealm/ClassRealmManagerDelegate.java new file mode 100644 index 0000000000..a7340cb775 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/classrealm/ClassRealmManagerDelegate.java @@ -0,0 +1,34 @@ +package org.apache.maven.classrealm; + +/* + * 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.classworlds.realm.ClassRealm; + +/** + * ClassRealmManagerDelegate is used to perform addition configuration of + * class realms created by ClassRealmManager. + * + * @author igor + */ +public interface ClassRealmManagerDelegate +{ + void setupRealm( ClassRealm classRealm ); +} diff --git a/maven-core/src/main/java/org/apache/maven/classrealm/DefaultClassRealmManager.java b/maven-core/src/main/java/org/apache/maven/classrealm/DefaultClassRealmManager.java index 758bbb086f..2681d92e66 100644 --- a/maven-core/src/main/java/org/apache/maven/classrealm/DefaultClassRealmManager.java +++ b/maven-core/src/main/java/org/apache/maven/classrealm/DefaultClassRealmManager.java @@ -19,6 +19,8 @@ * under the License. */ +import java.util.Collections; +import java.util.List; import java.util.Random; import org.apache.maven.artifact.ArtifactUtils; @@ -31,6 +33,7 @@ import org.codehaus.plexus.classworlds.realm.DuplicateRealmException; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.logging.Logger; /** @@ -93,6 +96,11 @@ private ClassRealm createRealm( String baseRealmId ) importMavenApi( classRealm ); + for ( ClassRealmManagerDelegate delegate : getDelegates() ) + { + delegate.setupRealm( classRealm ); + } + return classRealm; } } @@ -178,4 +186,16 @@ private String getKey( Plugin plugin ) return "plugin>" + plugin.getGroupId() + ":" + plugin.getArtifactId() + ":" + version; } + private List getDelegates() + { + try + { + return container.lookupList( ClassRealmManagerDelegate.class ); + } + catch ( ComponentLookupException e ) + { + return Collections.emptyList(); + } + } + }