org.codehaus.plexus.PlexusContainerException Java Examples

The following examples show how to use org.codehaus.plexus.PlexusContainerException. 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: InitializeMojoTest.java    From vertx-maven-plugin with Apache License 2.0 6 votes vote down vote up
private InitializeMojo createMojoInstance() throws PlexusContainerException {
    InitializeMojo mojo = new InitializeMojo();
    mojo.project = new MavenProject();
    mojo.repositorySystem = new DefaultRepositorySystem();
    mojo.repositorySystemSession = new DefaultRepositorySystemSession();
    mojo.buildPluginManager = new DefaultBuildPluginManager();
    mojo.container = new DefaultPlexusContainer(new DefaultContainerConfiguration());
    mojo.mavenSession = new MavenSession(mojo.container, mojo.repositorySystemSession, new DefaultMavenExecutionRequest(),
        new DefaultMavenExecutionResult());

    mojo.lifecycleExecutor = new DefaultLifecycleExecutor();
    mojo.scmManager = new DefaultScmManager();
    mojo.remoteRepositories = Collections.emptyList();
    mojo.projectBuildDir = OUT.getAbsolutePath();

    Build build = new Build();
    build.setOutputDirectory(OUT.getAbsolutePath());
    mojo.project.setBuild(build);

    return mojo;
}
 
Example #2
Source File: EmbedderFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static @NonNull MavenEmbedder createProjectLikeEmbedder() throws PlexusContainerException {
        final String mavenCoreRealmId = "plexus.core";
        ContainerConfiguration dpcreq = new DefaultContainerConfiguration()
            .setClassWorld( new ClassWorld(mavenCoreRealmId, EmbedderFactory.class.getClassLoader()) )
            .setClassPathScanning( PlexusConstants.SCANNING_INDEX )
            .setName("maven");
        
        DefaultPlexusContainer pc = new DefaultPlexusContainer(dpcreq, new ExtensionModule());
        pc.setLoggerManager(new NbLoggerManager());

        Properties userprops = new Properties();
        userprops.putAll(getCustomGlobalUserProperties());
        EmbedderConfiguration configuration = new EmbedderConfiguration(pc, cloneStaticProps(), userprops, true, getSettingsXml());
        
        try {
            return new MavenEmbedder(configuration);
            //MEVENIDE-634 make all instances non-interactive
//            WagonManager wagonManager = (WagonManager) embedder.getPlexusContainer().lookup(WagonManager.ROLE);
//            wagonManager.setInteractive(false);
        } catch (ComponentLookupException ex) {
            throw new PlexusContainerException(ex.toString(), ex);
        }
    }
 
Example #3
Source File: MavenJarUtil.java    From alchemy with Apache License 2.0 5 votes vote down vote up
private List<Artifact> collectDependenciesIntoArtifacts(CollectRequest collectRequest)
    throws PlexusContainerException, ComponentLookupException, DependencyCollectionException,
    ArtifactResolutionException {
    RepositorySystem repositorySystem = this.newRepositorySystem();
    RepositorySystemSession session = this.newSession(repositorySystem);
    DependencyNode node = repositorySystem.collectDependencies(session, collectRequest).getRoot();
    repositorySystem.resolveDependencies(session, node, null);
    PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
    node.accept(nlg);
    return nlg.getArtifacts(false);
}
 
Example #4
Source File: BaseMavenDeployer.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void addProtocolProvider(CustomDeployTask deployTask) {
    PlexusContainer plexusContainer = deployTask.getContainer();
    for (File wagonProviderJar : getJars()) {
        try {
            plexusContainer.addJarResource(wagonProviderJar);
        } catch (PlexusContainerException e) {
            throw new RuntimeException(e);
        }
    }
}
 
Example #5
Source File: BaseMavenDeployer.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void addProtocolProvider(CustomDeployTask deployTask) {
    PlexusContainer plexusContainer = deployTask.getContainer();
    for (File wagonProviderJar : getJars()) {
        try {
            plexusContainer.addJarResource(wagonProviderJar);
        } catch (PlexusContainerException e) {
            throw new RuntimeException(e);
        }
    }
}
 
Example #6
Source File: RepositoryUtility.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
static MavenProject createMavenProject(Path pomFile, RepositorySystemSession session)
    throws MavenRepositoryException {
  // MavenCli's way to instantiate PlexusContainer
  ClassWorld classWorld =
      new ClassWorld("plexus.core", Thread.currentThread().getContextClassLoader());
  ContainerConfiguration containerConfiguration =
      new DefaultContainerConfiguration()
          .setClassWorld(classWorld)
          .setRealm(classWorld.getClassRealm("plexus.core"))
          .setClassPathScanning(PlexusConstants.SCANNING_INDEX)
          .setAutoWiring(true)
          .setJSR250Lifecycle(true)
          .setName("linkage-checker");
  try {
    PlexusContainer container = new DefaultPlexusContainer(containerConfiguration);

    MavenExecutionRequest mavenExecutionRequest = new DefaultMavenExecutionRequest();
    ProjectBuildingRequest projectBuildingRequest =
        mavenExecutionRequest.getProjectBuildingRequest();

    projectBuildingRequest.setRepositorySession(session);

    // Profile activation needs properties such as JDK version
    Properties properties = new Properties(); // allowing duplicate entries
    properties.putAll(projectBuildingRequest.getSystemProperties());
    properties.putAll(OsProperties.detectOsProperties());
    properties.putAll(System.getProperties());
    projectBuildingRequest.setSystemProperties(properties);

    ProjectBuilder projectBuilder = container.lookup(ProjectBuilder.class);
    ProjectBuildingResult projectBuildingResult =
        projectBuilder.build(pomFile.toFile(), projectBuildingRequest);
    return projectBuildingResult.getProject();
  } catch (PlexusContainerException | ComponentLookupException | ProjectBuildingException ex) {
    throw new MavenRepositoryException(ex);
  }
}
 
Example #7
Source File: EmbedderFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static @NonNull MavenEmbedder getProjectEmbedder() {
    synchronized (PROJECT_LOCK) {
        if (project == null) {
            try {
                project = createProjectLikeEmbedder();
            } catch (PlexusContainerException ex) {
                rethrowThreadDeath(ex);
                throw new IllegalStateException(ex);
            }
            projectLoaded.set(true);
        }
        return project;
    }
}
 
Example #8
Source File: EmbedderFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static @NonNull MavenEmbedder getOnlineEmbedder() {
    synchronized (ONLINE_LOCK) {
        if (online == null) {
            try {
                online = createOnlineEmbedder();
            } catch (PlexusContainerException ex) {
                rethrowThreadDeath(ex);
                throw new IllegalStateException(ex);
            }
        }
        return online;
    }
}
 
Example #9
Source File: IndexQuerier.java    From sling-whiteboard with Apache License 2.0 5 votes vote down vote up
public IndexQuerier() throws PlexusContainerException, ComponentLookupException {

        DefaultContainerConfiguration config = new DefaultContainerConfiguration();
        config.setClassPathScanning(PlexusConstants.SCANNING_INDEX);

        this.plexusContainer = new DefaultPlexusContainer(config);

        // lookup the indexer components from plexus
        this.indexer = plexusContainer.lookup(Indexer.class);
        this.indexUpdater = plexusContainer.lookup(IndexUpdater.class);
        // lookup wagon used to remotely fetch index
        this.httpWagon = plexusContainer.lookup(Wagon.class, "https");
    }
 
Example #10
Source File: BaseMavenDeployer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void addProtocolProvider(CustomDeployTask deployTask) {
    PlexusContainer plexusContainer = deployTask.getContainer();
    for (File wagonProviderJar : getJars()) {
        try {
            plexusContainer.addJarResource(wagonProviderJar);
        } catch (PlexusContainerException e) {
            throw new RuntimeException(e);
        }
    }
}
 
Example #11
Source File: BaseMavenDeployer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void addProtocolProvider(CustomDeployTask deployTask) {
    PlexusContainer plexusContainer = deployTask.getContainer();
    for (File wagonProviderJar : getJars()) {
        try {
            plexusContainer.addJarResource(wagonProviderJar);
        } catch (PlexusContainerException e) {
            throw new RuntimeException(e);
        }
    }
}
 
Example #12
Source File: MavenJarUtil.java    From alchemy with Apache License 2.0 4 votes vote down vote up
private RepositorySystem newRepositorySystem() throws PlexusContainerException, ComponentLookupException {
    return new DefaultPlexusContainer().lookup(RepositorySystem.class);
}
 
Example #13
Source File: EmbedderFactory.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@NonNull static MavenEmbedder createOnlineEmbedder() throws PlexusContainerException {
        final String mavenCoreRealmId = "plexus.core";
        ContainerConfiguration dpcreq = new DefaultContainerConfiguration()
            .setClassWorld( new ClassWorld(mavenCoreRealmId, EmbedderFactory.class.getClassLoader()) )
            .setClassPathScanning( PlexusConstants.SCANNING_INDEX )
            .setName("maven");

        DefaultPlexusContainer pc = new DefaultPlexusContainer(dpcreq);
        pc.setLoggerManager(new NbLoggerManager());

        Properties userprops = new Properties();
        userprops.putAll(getCustomGlobalUserProperties());
        EmbedderConfiguration req = new EmbedderConfiguration(pc, cloneStaticProps(), userprops, false, getSettingsXml());

//        //TODO remove explicit activation
//        req.addActiveProfile("netbeans-public").addActiveProfile("netbeans-private"); //NOI18N


//        req.setConfigurationCustomizer(new ContainerCustomizer() {
//
//            public void customize(PlexusContainer plexusContainer) {
//                    //MEVENIDE-634
//                    ComponentDescriptor desc = plexusContainer.getComponentDescriptor(KnownHostsProvider.ROLE, "file"); //NOI18N
//                    desc.getConfiguration().getChild("hostKeyChecking").setValue("no"); //NOI18N
//
//                    //MEVENIDE-634
//                    desc = plexusContainer.getComponentDescriptor(KnownHostsProvider.ROLE, "null"); //NOI18N
//                    desc.getConfiguration().getChild("hostKeyChecking").setValue("no"); //NOI18N
//            }
//        });

        try {
            return new MavenEmbedder(req);
            //MEVENIDE-634 make all instances non-interactive
//            WagonManager wagonManager = (WagonManager) embedder.getPlexusContainer().lookup(WagonManager.ROLE);
//            wagonManager.setInteractive(false);
        } catch (ComponentLookupException ex) {
            throw new PlexusContainerException(ex.toString(), ex);
        }
//            try {
//                //MEVENIDE-634 make all instances non-interactive
//                WagonManager wagonManager = (WagonManager) embedder.getPlexusContainer().lookup(WagonManager.ROLE);
//                wagonManager.setInteractive( false );
//                wagonManager.setDownloadMonitor(new ProgressTransferListener());
//            } catch (ComponentLookupException ex) {
//                ErrorManager.getDefault().notify(ex);
//            }
    }
 
Example #14
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 );
    }
}