Search in sources :

Example 6 with DefaultPlexusContainer

use of org.codehaus.plexus.DefaultPlexusContainer in project pom-manipulation-ext by release-engineering.

the class VersioningCalculatorTest method setupSession.

private VersioningState setupSession(final Properties properties, final Map<ProjectRef, String[]> versionMap) throws Exception {
    final ArtifactRepository ar = new MavenArtifactRepository("test", "http://repo.maven.apache.org/maven2", new DefaultRepositoryLayout(), new ArtifactRepositoryPolicy(), new ArtifactRepositoryPolicy());
    final MavenExecutionRequest req = new DefaultMavenExecutionRequest().setUserProperties(properties).setRemoteRepositories(Arrays.asList(ar));
    final PlexusContainer container = new DefaultPlexusContainer();
    final MavenSession mavenSession = new MavenSession(container, null, req, new DefaultMavenExecutionResult());
    session = new ManipulationSession();
    session.setMavenSession(mavenSession);
    final VersioningState state = new VersioningState(properties);
    session.setState(state);
    final Map<String, byte[]> dataMap = new HashMap<>();
    if (versionMap != null && !versionMap.isEmpty()) {
        for (final Map.Entry<ProjectRef, String[]> entry : versionMap.entrySet()) {
            final String path = toMetadataPath(entry.getKey());
            final byte[] data = setupMetadataVersions(entry.getValue());
            dataMap.put(path, data);
        }
    }
    final Location mdLoc = MavenLocationExpander.EXPANSION_TARGET;
    final Transport mdTrans = new StubTransport(dataMap);
    modder = new TestVersionCalculator(new ManipulationSession(), mdLoc, mdTrans, temp.newFolder("galley-cache"));
    return state;
}
Also used : DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) PlexusContainer(org.codehaus.plexus.PlexusContainer) HashMap(java.util.HashMap) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultRepositoryLayout(org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout) StubTransport(org.commonjava.maven.ext.core.fixture.StubTransport) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) MavenSession(org.apache.maven.execution.MavenSession) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) ManipulationSession(org.commonjava.maven.ext.core.ManipulationSession) VersioningState(org.commonjava.maven.ext.core.state.VersioningState) SimpleProjectRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectRef) ProjectRef(org.commonjava.maven.atlas.ident.ref.ProjectRef) Transport(org.commonjava.maven.galley.spi.transport.Transport) StubTransport(org.commonjava.maven.ext.core.fixture.StubTransport) HashMap(java.util.HashMap) Map(java.util.Map) Location(org.commonjava.maven.galley.model.Location)

Example 7 with DefaultPlexusContainer

use of org.codehaus.plexus.DefaultPlexusContainer in project gradle by gradle.

the class AbstractMavenPublishAction method newPlexusContainer.

private PlexusContainer newPlexusContainer(List<File> wagonJars) {
    try {
        ClassWorld world = new ClassWorld("plexus.core", ClassWorld.class.getClassLoader());
        ClassRealm classRealm = new ClassRealm(world, "plexus.core", ClassWorld.class.getClassLoader());
        if (wagonJars != null) {
            for (File jar : wagonJars) {
                classRealm.addURL(jar.toURI().toURL());
            }
        }
        return new DefaultPlexusContainer(new DefaultContainerConfiguration().setRealm(classRealm));
    } catch (PlexusContainerException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    } catch (MalformedURLException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
Also used : PlexusContainerException(org.codehaus.plexus.PlexusContainerException) ClassRealm(org.codehaus.plexus.classworlds.realm.ClassRealm) MalformedURLException(java.net.MalformedURLException) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) DefaultContainerConfiguration(org.codehaus.plexus.DefaultContainerConfiguration) ClassWorld(org.codehaus.plexus.classworlds.ClassWorld) File(java.io.File)

Example 8 with DefaultPlexusContainer

use of org.codehaus.plexus.DefaultPlexusContainer in project pom-manipulation-ext by release-engineering.

the class Cli method parseSettings.

private Settings parseSettings(File settings) throws PlexusContainerException, ComponentLookupException, SettingsBuildingException {
    PlexusContainer container = new DefaultPlexusContainer();
    DefaultSettingsBuildingRequest settingsRequest = new DefaultSettingsBuildingRequest();
    settingsRequest.setUserSettingsFile(settings);
    settingsRequest.setGlobalSettingsFile(DEFAULT_GLOBAL_SETTINGS_FILE);
    settingsRequest.setUserProperties(session.getUserProperties());
    settingsRequest.setSystemProperties(System.getProperties());
    SettingsBuilder settingsBuilder = container.lookup(SettingsBuilder.class);
    SettingsBuildingResult settingsResult = settingsBuilder.build(settingsRequest);
    Settings effectiveSettings = settingsResult.getEffectiveSettings();
    ProfileSelector profileSelector = container.lookup(ProfileSelector.class);
    ProfileActivationContext profileActivationContext = new DefaultProfileActivationContext().setActiveProfileIds(effectiveSettings.getActiveProfiles());
    List<org.apache.maven.model.Profile> modelProfiles = new ArrayList<>();
    for (Profile profile : effectiveSettings.getProfiles()) {
        modelProfiles.add(SettingsUtils.convertFromSettingsProfile(profile));
    }
    List<org.apache.maven.model.Profile> activeModelProfiles = profileSelector.getActiveProfiles(modelProfiles, profileActivationContext, new ModelProblemCollector() {

        @Override
        public void add(ModelProblem.Severity severity, String message, InputLocation location, Exception cause) {
        // do nothing
        }
    });
    List<String> activeProfiles = new ArrayList<>();
    for (org.apache.maven.model.Profile profile : activeModelProfiles) {
        activeProfiles.add(profile.getId());
    }
    effectiveSettings.setActiveProfiles(activeProfiles);
    return effectiveSettings;
}
Also used : InputLocation(org.apache.maven.model.InputLocation) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) PlexusContainer(org.codehaus.plexus.PlexusContainer) SettingsBuildingResult(org.apache.maven.settings.building.SettingsBuildingResult) ArrayList(java.util.ArrayList) Profile(org.apache.maven.settings.Profile) SettingsBuilder(org.apache.maven.settings.building.SettingsBuilder) ModelProblem(org.apache.maven.model.building.ModelProblem) ProfileSelector(org.apache.maven.model.profile.ProfileSelector) Settings(org.apache.maven.settings.Settings) DefaultProfileActivationContext(org.apache.maven.model.profile.DefaultProfileActivationContext) ProfileActivationContext(org.apache.maven.model.profile.ProfileActivationContext) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) PlexusContainerException(org.codehaus.plexus.PlexusContainerException) RestException(org.commonjava.maven.ext.io.rest.exception.RestException) ManipulationException(org.commonjava.maven.ext.common.ManipulationException) ParseException(org.apache.commons.cli.ParseException) SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) MavenExecutionRequestPopulationException(org.apache.maven.execution.MavenExecutionRequestPopulationException) ModelProblemCollector(org.apache.maven.model.building.ModelProblemCollector) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) DefaultProfileActivationContext(org.apache.maven.model.profile.DefaultProfileActivationContext)

Example 9 with DefaultPlexusContainer

use of org.codehaus.plexus.DefaultPlexusContainer in project pom-manipulation-ext by release-engineering.

the class Cli method createSession.

private void createSession(File target, File settings) {
    try {
        PlexusContainer container = new DefaultPlexusContainer();
        pomIO = container.lookup(PomIO.class);
        session = container.lookup(ManipulationSession.class);
        manipulationManager = container.lookup(ManipulationManager.class);
        final MavenExecutionRequest req = new DefaultMavenExecutionRequest().setUserProperties(System.getProperties()).setUserProperties(userProps).setRemoteRepositories(Collections.<ArtifactRepository>emptyList());
        ArtifactRepository ar = null;
        if (settings == null) {
            // No, this is not a typo. If current default is null, supply new local and global.
            // This function passes in settings to make it easier to test.
            this.settings = settings = new File(System.getProperty("user.home"), ".m2/settings.xml");
            ar = new MavenArtifactRepository();
            ar.setUrl("file://" + System.getProperty("user.home") + "/.m2/repository");
            req.setLocalRepository(ar);
        }
        req.setUserSettingsFile(settings);
        req.setGlobalSettingsFile(settings);
        MavenExecutionRequestPopulator executionRequestPopulator = container.lookup(MavenExecutionRequestPopulator.class);
        executionRequestPopulator.populateFromSettings(req, parseSettings(settings));
        executionRequestPopulator.populateDefaults(req);
        if (ar != null) {
            ar.setUrl("file://" + req.getLocalRepositoryPath());
        }
        if (userProps != null && userProps.containsKey("maven.repo.local")) {
            if (ar == null) {
                ar = new MavenArtifactRepository();
            }
            ar.setUrl("file://" + userProps.getProperty("maven.repo.local"));
            req.setLocalRepository(ar);
        }
        final MavenSession mavenSession = new MavenSession(container, null, req, new DefaultMavenExecutionResult());
        mavenSession.getRequest().setPom(target);
        session.setMavenSession(mavenSession);
    } catch (ComponentLookupException e) {
        logger.debug("Caught problem instantiating ", e);
        System.err.println("Unable to start Cli subsystem");
        System.exit(100);
    } catch (PlexusContainerException e) {
        logger.debug("Caught problem instantiating ", e);
        System.err.println("Unable to start Cli subsystem");
        System.exit(100);
    } catch (SettingsBuildingException e) {
        logger.debug("Caught problem parsing settings file ", e);
        System.err.println("Unable to parse settings.xml file");
        System.exit(100);
    } catch (MavenExecutionRequestPopulationException e) {
        logger.debug("Caught problem populating maven request from settings file ", e);
        System.err.println("Unable to create maven execution request from settings.xml file");
        System.exit(100);
    }
}
Also used : PlexusContainerException(org.codehaus.plexus.PlexusContainerException) SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) PlexusContainer(org.codehaus.plexus.PlexusContainer) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) MavenExecutionRequestPopulationException(org.apache.maven.execution.MavenExecutionRequestPopulationException) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) ManipulationManager(org.commonjava.maven.ext.core.ManipulationManager) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) PomIO(org.commonjava.maven.ext.io.PomIO) MavenSession(org.apache.maven.execution.MavenSession) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) ManipulationSession(org.commonjava.maven.ext.core.ManipulationSession) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) File(java.io.File) MavenExecutionRequestPopulator(org.apache.maven.execution.MavenExecutionRequestPopulator)

Example 10 with DefaultPlexusContainer

use of org.codehaus.plexus.DefaultPlexusContainer in project pom-manipulation-ext by release-engineering.

the class PlexusTestRunner method createTest.

@Override
protected Object createTest() throws Exception {
    final TestClass testClass = getTestClass();
    final DefaultContainerConfiguration config = new DefaultContainerConfiguration();
    config.setAutoWiring(true);
    config.setClassPathScanning(PlexusConstants.SCANNING_ON);
    config.setComponentVisibility(PlexusConstants.GLOBAL_VISIBILITY);
    config.setName(testClass.getName());
    final DefaultPlexusContainer container = new DefaultPlexusContainer(config);
    final ClassSpace cs = new URLClassSpace(Thread.currentThread().getContextClassLoader());
    container.addPlexusInjector(Arrays.<PlexusBeanModule>asList(new PlexusAnnotatedBeanModule(cs, Collections.emptyMap())));
    return container.lookup(testClass.getJavaClass());
}
Also used : DefaultContainerConfiguration(org.codehaus.plexus.DefaultContainerConfiguration) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) ClassSpace(org.sonatype.guice.bean.reflect.ClassSpace) URLClassSpace(org.sonatype.guice.bean.reflect.URLClassSpace) TestClass(org.junit.runners.model.TestClass) URLClassSpace(org.sonatype.guice.bean.reflect.URLClassSpace) PlexusAnnotatedBeanModule(org.sonatype.guice.plexus.binders.PlexusAnnotatedBeanModule)

Aggregations

DefaultPlexusContainer (org.codehaus.plexus.DefaultPlexusContainer)16 DefaultContainerConfiguration (org.codehaus.plexus.DefaultContainerConfiguration)8 PlexusContainer (org.codehaus.plexus.PlexusContainer)6 PlexusContainerException (org.codehaus.plexus.PlexusContainerException)6 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)5 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)5 ContainerConfiguration (org.codehaus.plexus.ContainerConfiguration)5 ClassWorld (org.codehaus.plexus.classworlds.ClassWorld)5 File (java.io.File)4 DefaultMavenExecutionResult (org.apache.maven.execution.DefaultMavenExecutionResult)4 MavenSession (org.apache.maven.execution.MavenSession)4 ClassRealm (org.codehaus.plexus.classworlds.realm.ClassRealm)4 AbstractModule (com.google.inject.AbstractModule)3 MavenExecutionRequestPopulationException (org.apache.maven.execution.MavenExecutionRequestPopulationException)3 MavenExecutionRequestPopulator (org.apache.maven.execution.MavenExecutionRequestPopulator)3 IOException (java.io.IOException)2 ParseException (org.apache.commons.cli.ParseException)2 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)2 MavenArtifactRepository (org.apache.maven.artifact.repository.MavenArtifactRepository)2 CoreExports (org.apache.maven.extension.internal.CoreExports)2