Search in sources :

Example 6 with CoreExtensionEntry

use of org.apache.maven.extension.internal.CoreExtensionEntry in project kie-wb-common by kiegroup.

the class AFMavenCli method setupContainerRealm.

protected ClassRealm setupContainerRealm(ClassWorld classWorld, ClassRealm coreRealm, List<File> extClassPath, List<CoreExtensionEntry> extensions) throws Exception {
    if (!extClassPath.isEmpty() || !extensions.isEmpty()) {
        ClassRealm extRealm = classWorld.newRealm("maven.ext", null);
        extRealm.setParentRealm(coreRealm);
        slf4jLogger.debug("Populating class realm " + extRealm.getId());
        for (File file : extClassPath) {
            slf4jLogger.debug("  Included " + file);
            extRealm.addURL(file.toURI().toURL());
        }
        for (CoreExtensionEntry entry : reverse(extensions)) {
            Set<String> exportedPackages = entry.getExportedPackages();
            ClassRealm realm = entry.getClassRealm();
            for (String exportedPackage : exportedPackages) {
                extRealm.importFrom(realm, exportedPackage);
            }
            if (exportedPackages.isEmpty()) {
                // sisu uses realm imports to establish component visibility
                extRealm.importFrom(realm, realm.getId());
            }
        }
        return extRealm;
    }
    return coreRealm;
}
Also used : ClassRealm(org.codehaus.plexus.classworlds.realm.ClassRealm) CoreExtensionEntry(org.apache.maven.extension.internal.CoreExtensionEntry) File(java.io.File)

Example 7 with CoreExtensionEntry

use of org.apache.maven.extension.internal.CoreExtensionEntry in project sts4 by spring-projects.

the class MavenBridge method newPlexusContainer.

private static DefaultPlexusContainer newPlexusContainer() throws PlexusContainerException {
    final ClassWorld classWorld = new ClassWorld(MAVEN_CORE_REALM_ID, ClassWorld.class.getClassLoader());
    final ClassRealm realm;
    try {
        realm = classWorld.getRealm(MAVEN_CORE_REALM_ID);
    } catch (NoSuchRealmException e) {
        throw new PlexusContainerException("Could not lookup required class realm", e);
    }
    final ContainerConfiguration mavenCoreCC = // 
    new DefaultContainerConfiguration().setClassWorld(// 
    classWorld).setRealm(// 
    realm).setClassPathScanning(// 
    PlexusConstants.SCANNING_INDEX).setAutoWiring(// 
    true).setName(// $NON-NLS-1$
    "mavenCore");
    final Module logginModule = new AbstractModule() {

        protected void configure() {
            bind(ILoggerFactory.class).toInstance(LoggerFactory.getILoggerFactory());
        }
    };
    final Module coreExportsModule = new AbstractModule() {

        protected void configure() {
            ClassRealm realm = mavenCoreCC.getRealm();
            CoreExtensionEntry entry = CoreExtensionEntry.discoverFrom(realm);
            CoreExports exports = new CoreExports(entry);
            bind(CoreExports.class).toInstance(exports);
        }
    };
    return new DefaultPlexusContainer(mavenCoreCC, logginModule, coreExportsModule);
}
Also used : NoSuchRealmException(org.codehaus.plexus.classworlds.realm.NoSuchRealmException) PlexusContainerException(org.codehaus.plexus.PlexusContainerException) ClassRealm(org.codehaus.plexus.classworlds.realm.ClassRealm) DefaultContainerConfiguration(org.codehaus.plexus.DefaultContainerConfiguration) ILoggerFactory(org.slf4j.ILoggerFactory) CoreExports(org.apache.maven.extension.internal.CoreExports) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) CoreExtensionEntry(org.apache.maven.extension.internal.CoreExtensionEntry) ClassWorld(org.codehaus.plexus.classworlds.ClassWorld) Module(com.google.inject.Module) AbstractModule(com.google.inject.AbstractModule) ContainerConfiguration(org.codehaus.plexus.ContainerConfiguration) DefaultContainerConfiguration(org.codehaus.plexus.DefaultContainerConfiguration) AbstractModule(com.google.inject.AbstractModule)

Aggregations

CoreExtensionEntry (org.apache.maven.extension.internal.CoreExtensionEntry)7 ClassRealm (org.codehaus.plexus.classworlds.realm.ClassRealm)7 File (java.io.File)6 AbstractModule (com.google.inject.AbstractModule)4 CoreExports (org.apache.maven.extension.internal.CoreExports)4 ContainerConfiguration (org.codehaus.plexus.ContainerConfiguration)4 DefaultContainerConfiguration (org.codehaus.plexus.DefaultContainerConfiguration)4 DefaultPlexusContainer (org.codehaus.plexus.DefaultPlexusContainer)4 HashSet (java.util.HashSet)3 Maven (org.apache.maven.Maven)3 DefaultEventSpyContext (org.apache.maven.cli.event.DefaultEventSpyContext)3 EventSpyDispatcher (org.apache.maven.eventspy.internal.EventSpyDispatcher)3 MavenExecutionRequestPopulator (org.apache.maven.execution.MavenExecutionRequestPopulator)3 ToolchainsBuilder (org.apache.maven.toolchain.building.ToolchainsBuilder)3 Module (com.google.inject.Module)1 PlexusContainerException (org.codehaus.plexus.PlexusContainerException)1 ClassWorld (org.codehaus.plexus.classworlds.ClassWorld)1 NoSuchRealmException (org.codehaus.plexus.classworlds.realm.NoSuchRealmException)1 ILoggerFactory (org.slf4j.ILoggerFactory)1