org.codehaus.plexus.classworlds.realm.ClassRealm Java Examples

The following examples show how to use org.codehaus.plexus.classworlds.realm.ClassRealm. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IncludeProjectDependenciesComponentConfigurator.java    From protostuff-compiler with Apache License 2.0 6 votes vote down vote up
private void addProjectDependenciesToClassRealm(ExpressionEvaluator expressionEvaluator, ClassRealm realm)
        throws ComponentConfigurationException {
    List<String> runtimeClasspathElements;
    try {
        // noinspection unchecked
        runtimeClasspathElements = (List<String>) expressionEvaluator
                .evaluate("${project.runtimeClasspathElements}");
    } catch (ExpressionEvaluationException e) {
        throw new ComponentConfigurationException(
                "There was a problem evaluating: ${project.runtimeClasspathElements}", e);
    }

    // Add the project dependencies to the ClassRealm
    final URL[] urls = buildUrls(runtimeClasspathElements);
    for (URL url : urls) {
        realm.addURL(url);
    }
}
 
Example #2
Source File: SpringMvcEndpointGeneratorMojo.java    From springmvc-raml-plugin with Apache License 2.0 6 votes vote down vote up
private ClassRealm getClassRealm() throws DependencyResolutionRequiredException, MalformedURLException {
	if (classRealm == null) {
		List<String> runtimeClasspathElements = project.getRuntimeClasspathElements();

		classRealm = descriptor.getClassRealm();

		if (classRealm == null) {
			classRealm = project.getClassRealm();
		}

		for (String element : runtimeClasspathElements) {
			File elementFile = new File(element);
			classRealm.addURL(elementFile.toURI().toURL());
		}
	}
	return classRealm;
}
 
Example #3
Source File: DMNMojoComponentConfigurator.java    From jdmn with Apache License 2.0 5 votes vote down vote up
@Override
public void configureComponent(final Object component, final PlexusConfiguration configuration,
                               final ExpressionEvaluator evaluator, final ClassRealm realm,
                               final ConfigurationListener listener) throws ComponentConfigurationException {

    // Register custom type conversion for optionally-configurable types, i.e. those which can be specified as a
    // simple string or as a components with a name and configuration
    converterLookup.registerConverter(new OptionallyConfigurableComponentConverter());

    super.configureComponent(component, configuration, evaluator, realm, listener);
}
 
Example #4
Source File: NexusRepositoryIndexerImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void initIndexer () {
    if (!inited) {
        try {
            ContainerConfiguration config = new DefaultContainerConfiguration();
            //#154755 - start
            ClassLoader indexerLoader = NexusRepositoryIndexerImpl.class.getClassLoader();
            ClassWorld classWorld = new ClassWorld();
            ClassRealm plexusRealm = classWorld.newRealm("plexus.core", EmbedderFactory.class.getClassLoader()); //NOI18N
            plexusRealm.importFrom(indexerLoader, "META-INF/sisu"); //NOI18N
            plexusRealm.importFrom(indexerLoader, "org.apache.maven.index"); //NOI18N
            plexusRealm.importFrom(indexerLoader, "org.netbeans.modules.maven.indexer"); //NOI18N
            config.setClassWorld(classWorld);
            config.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
            //#154755 - end
            embedder = new DefaultPlexusContainer(config);

            ComponentDescriptor<ArtifactContextProducer> desc = new ComponentDescriptor<ArtifactContextProducer>();
            desc.setRoleClass(ArtifactContextProducer.class);
            desc.setImplementationClass(CustomArtifactContextProducer.class);
            ComponentRequirement req = new ComponentRequirement(); // XXX why is this not automatic?
            req.setFieldName("mapper");
            req.setRole(ArtifactPackagingMapper.class.getName());
            desc.addRequirement(req);
            embedder.addComponentDescriptor(desc);
            indexer = embedder.lookup(Indexer.class);
            searcher = embedder.lookup(SearchEngine.class);
            remoteIndexUpdater = embedder.lookup(IndexUpdater.class);
            contextProducer = embedder.lookup(ArtifactContextProducer.class);
            scanner = new FastScanner(contextProducer);
            inited = true;
        } catch (Exception x) {
            Exceptions.printStackTrace(x);
        }
    }
}
 
Example #5
Source File: IncludeProjectDependenciesComponentConfigurator.java    From protostuff-compiler with Apache License 2.0 5 votes vote down vote up
@Override
public void configureComponent(Object component, PlexusConfiguration configuration,
                               ExpressionEvaluator evaluator, ClassRealm realm, ConfigurationListener listener) throws ComponentConfigurationException {
    addProjectDependenciesToClassRealm(evaluator, realm);
    converterLookup.registerConverter(new ClassRealmConverter(realm));
    ObjectWithFieldsConverter converter = new ObjectWithFieldsConverter();
    converter.processConfiguration(converterLookup, component, realm.getParentClassLoader(), configuration,
            evaluator, listener);
}
 
Example #6
Source File: PojoGenerationConfigTest.java    From springmvc-raml-plugin with Apache License 2.0 5 votes vote down vote up
private MavenProject getMavenProject(final String pomDir) throws Exception {
	final File pom = getPomDir(pomDir);

	final MavenProject mavenProject = mojoRule.readMavenProject(pom);
	final ClassWorld classWorld = new ClassWorld();
	final ClassRealm realm = classWorld.newRealm("test", getClass().getClassLoader());
	mavenProject.setClassRealm(realm);

	return mavenProject;
}
 
Example #7
Source File: MojoConfigurator.java    From takari-lifecycle with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void configureComponent(final Object mojoInstance, //
    final PlexusConfiguration pluginConfigurationFromMaven, //
    final ExpressionEvaluator evaluator, //
    final ClassRealm realm, //
    final ConfigurationListener listener) throws ComponentConfigurationException {

  super.configureComponent(mojoInstance, pluginConfigurationFromMaven, evaluator, realm, listener);
}
 
Example #8
Source File: MockitoComponentTestCase.java    From hermes with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public Object newInstance(ComponentDescriptor desc, ClassRealm classRealm, PlexusContainer container)
      throws ComponentInstantiationException {
	return instances.get(new Pair<>(desc.getRoleClass(), desc.getRoleHint()));
}
 
Example #9
Source File: PlexusSisuBridge.java    From archiva with Apache License 2.0 4 votes vote down vote up
@PostConstruct
public void initialize()
    throws PlexusSisuBridgeException
{
    DefaultContainerConfiguration conf = new DefaultContainerConfiguration();

    conf.setAutoWiring( containerAutoWiring );
    conf.setClassPathScanning( containerClassPathScanning );
    conf.setComponentVisibility( containerComponentVisibility );

    conf.setContainerConfigurationURL( overridingComponentsXml );

    ClassWorld classWorld = new ClassWorld();

    ClassLoader tccl = Thread.currentThread().getContextClassLoader();

    containerRealm = new ClassRealm( classWorld, "maven", tccl );

    // olamy hackhish but plexus-sisu need a URLClassLoader with URL filled

    if ( tccl instanceof URLClassLoader )
    {
        URL[] urls = ( (URLClassLoader) tccl ).getURLs();
        for ( URL url : urls )
        {
            containerRealm.addURL( url );
            log.debug("Added url {}", url);
        }
    }

    conf.setRealm( containerRealm );

    //conf.setClassWorld( classWorld );

    ClassLoader ori = Thread.currentThread().getContextClassLoader();

    try
    {
        Thread.currentThread().setContextClassLoader( containerRealm );
        InternalBinder binder = new InternalBinder( );
        plexusContainer = new DefaultPlexusContainer( conf, binder );

    }
    catch ( PlexusContainerException e )
    {
        throw new PlexusSisuBridgeException( e.getMessage(), e );
    } catch (Throwable ex) {
        log.error("PlexusSisuBridge initialization failed {}", ex.getMessage(), ex);
        throw new PlexusSisuBridgeException( ex.getMessage(), ex );
    }
    finally
    {
        Thread.currentThread().setContextClassLoader( ori );
    }
}
 
Example #10
Source File: ActiveJdbcInstrumentationPlugin.java    From javalite with Apache License 2.0 4 votes vote down vote up
private void addUrlToPluginClasspath(URL url) {
    //Nice API, Maven :(
    PluginDescriptor pluginDescriptor = (PluginDescriptor) getPluginContext().get("pluginDescriptor");
    ClassRealm realm = pluginDescriptor.getClassRealm();
    realm.addURL(url);
}