mirror of https://github.com/apache/maven.git
[MNG-8001] Expose CoreRealm internally (#1369)
Expose internally (not for plugin API) CoreRealm. --- https://issues.apache.org/jira/browse/MNG-8001
This commit is contained in:
parent
076b346c0c
commit
2c06637fb4
|
@ -36,10 +36,9 @@ import java.util.TreeMap;
|
|||
import org.apache.maven.artifact.ArtifactUtils;
|
||||
import org.apache.maven.classrealm.ClassRealmRequest.RealmType;
|
||||
import org.apache.maven.extension.internal.CoreExports;
|
||||
import org.apache.maven.internal.CoreRealm;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.codehaus.plexus.MutablePlexusContainer;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
import org.codehaus.plexus.classworlds.ClassWorld;
|
||||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||
import org.codehaus.plexus.classworlds.realm.DuplicateRealmException;
|
||||
|
@ -87,9 +86,9 @@ public class DefaultClassRealmManager implements ClassRealmManager {
|
|||
|
||||
@Inject
|
||||
public DefaultClassRealmManager(
|
||||
PlexusContainer container, List<ClassRealmManagerDelegate> delegates, CoreExports exports) {
|
||||
this.world = ((MutablePlexusContainer) container).getClassWorld();
|
||||
this.containerRealm = container.getContainerRealm();
|
||||
CoreRealm coreRealm, List<ClassRealmManagerDelegate> delegates, CoreExports exports) {
|
||||
this.world = coreRealm.getClassWorld();
|
||||
this.containerRealm = coreRealm.getRealm();
|
||||
this.delegates = delegates;
|
||||
|
||||
Map<String, ClassLoader> foreignImports = exports.getExportedPackages();
|
||||
|
|
|
@ -25,7 +25,7 @@ import javax.inject.Singleton;
|
|||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
import org.apache.maven.internal.CoreRealm;
|
||||
|
||||
/**
|
||||
* CoreExportsProvider
|
||||
|
@ -37,8 +37,8 @@ public class CoreExportsProvider implements Provider<CoreExports> {
|
|||
private final CoreExports exports;
|
||||
|
||||
@Inject
|
||||
public CoreExportsProvider(PlexusContainer container) {
|
||||
this(new CoreExports(CoreExtensionEntry.discoverFrom(container.getContainerRealm())));
|
||||
public CoreExportsProvider(CoreRealm coreRealm) {
|
||||
this(new CoreExports(CoreExtensionEntry.discoverFrom(coreRealm.getRealm())));
|
||||
}
|
||||
|
||||
public CoreExportsProvider(CoreExports exports) {
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
package org.apache.maven.internal;
|
||||
|
||||
import org.apache.maven.api.annotations.Experimental;
|
||||
import org.apache.maven.api.annotations.Nonnull;
|
||||
import org.codehaus.plexus.classworlds.ClassWorld;
|
||||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||
|
||||
/**
|
||||
* Access to core {@link ClassRealm}.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
@Experimental
|
||||
public interface CoreRealm {
|
||||
|
||||
/**
|
||||
* Obtain the {@link ClassRealm} used for Maven Core.
|
||||
*
|
||||
* @return the class realm of core.
|
||||
*/
|
||||
@Nonnull
|
||||
ClassRealm getRealm();
|
||||
|
||||
/**
|
||||
* Shorthand method to obtain the {@link ClassWorld} used for Maven Core.
|
||||
*
|
||||
* @return the class world in use.
|
||||
*/
|
||||
@Nonnull
|
||||
default ClassWorld getClassWorld() {
|
||||
return getRealm().getWorld();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
package org.apache.maven.internal.impl.internal;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.apache.maven.internal.CoreRealm;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||
|
||||
@Named
|
||||
@Singleton
|
||||
public class DefaultCoreRealm implements CoreRealm {
|
||||
|
||||
private final PlexusContainer container;
|
||||
|
||||
@Inject
|
||||
public DefaultCoreRealm(PlexusContainer container) {
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassRealm getRealm() {
|
||||
return container.getContainerRealm();
|
||||
}
|
||||
}
|
|
@ -24,6 +24,7 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
|
||||
import org.apache.maven.extension.internal.CoreExports;
|
||||
import org.apache.maven.internal.impl.internal.DefaultCoreRealm;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.codehaus.plexus.DefaultPlexusContainer;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
|
@ -56,7 +57,7 @@ class DefaultClassRealmManagerTest {
|
|||
exportedPackages.add("group1:artifact1");
|
||||
|
||||
return new DefaultClassRealmManager(
|
||||
container,
|
||||
new DefaultCoreRealm(container),
|
||||
new ArrayList<ClassRealmManagerDelegate>(),
|
||||
new CoreExports(new ClassRealm(null, "test", null), new HashSet<String>(), exportedPackages));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue