Search in sources :

Example 1 with Context

use of org.codehaus.plexus.context.Context in project maven-scm by apache.

the class MavenScmCli method createPlexusContainer.

private PlexusContainer createPlexusContainer() {
    final Context context = new DefaultContext();
    String path = System.getProperty("basedir");
    if (path == null) {
        path = new File("").getAbsolutePath();
    }
    context.put("basedir", path);
    ContainerConfiguration plexusConfiguration = new DefaultContainerConfiguration();
    plexusConfiguration.setName("maven-scm-cli").setContext(context.getContextData()).setClassPathScanning(PlexusConstants.SCANNING_CACHE).setAutoWiring(true);
    try {
        return new DefaultPlexusContainer(plexusConfiguration);
    } catch (PlexusContainerException e) {
        throw new IllegalStateException("Could not create Plexus container", e);
    }
}
Also used : DefaultContext(org.codehaus.plexus.context.DefaultContext) Context(org.codehaus.plexus.context.Context) PlexusContainerException(org.codehaus.plexus.PlexusContainerException) DefaultContainerConfiguration(org.codehaus.plexus.DefaultContainerConfiguration) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) DefaultContext(org.codehaus.plexus.context.DefaultContext) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ContainerConfiguration(org.codehaus.plexus.ContainerConfiguration) DefaultContainerConfiguration(org.codehaus.plexus.DefaultContainerConfiguration)

Example 2 with Context

use of org.codehaus.plexus.context.Context in project plexus-containers by codehaus-plexus.

the class ContextualizePhase method execute.

public void execute(Object object, ComponentManager manager, ClassRealm lookupRealm) throws PhaseExecutionException {
    if (object instanceof Contextualizable) {
        Context context = manager.getContainer().getContext();
        ClassRealm origRealm = manager.getContainer().setLookupRealm(lookupRealm);
        try {
            ((Contextualizable) object).contextualize(context);
        } catch (ContextException e) {
            throw new PhaseExecutionException("Unable to contextualize component", e);
        } finally {
            manager.getContainer().setLookupRealm(origRealm);
        }
    }
}
Also used : Context(org.codehaus.plexus.context.Context) ClassRealm(org.codehaus.plexus.classworlds.realm.ClassRealm) ContextException(org.codehaus.plexus.context.ContextException)

Aggregations

Context (org.codehaus.plexus.context.Context)2 File (java.io.File)1 ScmFile (org.apache.maven.scm.ScmFile)1 ContainerConfiguration (org.codehaus.plexus.ContainerConfiguration)1 DefaultContainerConfiguration (org.codehaus.plexus.DefaultContainerConfiguration)1 DefaultPlexusContainer (org.codehaus.plexus.DefaultPlexusContainer)1 PlexusContainerException (org.codehaus.plexus.PlexusContainerException)1 ClassRealm (org.codehaus.plexus.classworlds.realm.ClassRealm)1 ContextException (org.codehaus.plexus.context.ContextException)1 DefaultContext (org.codehaus.plexus.context.DefaultContext)1