org.codehaus.plexus.PlexusContainer Java Examples

The following examples show how to use org.codehaus.plexus.PlexusContainer. 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: ProjectComparatorTest.java    From pom-manipulation-ext with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings( "deprecation" )
private ManipulationSession createUpdateSession() throws Exception
{
    ManipulationSession session = new ManipulationSession();

    final Properties p = new Properties();
    p.setProperty( "strictAlignment", "true" );
    p.setProperty( "strictViolationFails", "true" );
    p.setProperty( "versionSuffix", "redhat-1" );
    p.setProperty( "scanActiveProfiles", "true" );
    session.setState( new DependencyState( p ) );
    session.setState( new VersioningState( p ) );
    session.setState( new CommonState( p ) );

    final MavenExecutionRequest req =
                    new DefaultMavenExecutionRequest().setUserProperties( p ).setRemoteRepositories( Collections.emptyList() );

    final PlexusContainer container = new DefaultPlexusContainer();
    final MavenSession mavenSession = new MavenSession( container, null, req, new DefaultMavenExecutionResult() );

    session.setMavenSession( mavenSession );

    return session;
}
 
Example #2
Source File: PropertiesUtilsTest.java    From pom-manipulation-ext with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings( "deprecation" )
private ManipulationSession createUpdateSession() throws Exception
{
    ManipulationSession session = new ManipulationSession();

    session.setState( new DependencyState( p ) );
    session.setState( new VersioningState( p ) );
    session.setState( new CommonState( p ) );

    final MavenExecutionRequest req =
                    new DefaultMavenExecutionRequest().setUserProperties( p ).setRemoteRepositories( Collections.emptyList() );

    final PlexusContainer container = new DefaultPlexusContainer();
    final MavenSession mavenSession = new MavenSession( container, null, req, new DefaultMavenExecutionResult() );

    session.setMavenSession( mavenSession );

    return session;
}
 
Example #3
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 #4
Source File: StramTestSupport.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
@Override
protected void customizeContainer(PlexusContainer container)
{
  ((DefaultPlexusContainer)container).setLoggerManager(
      new BaseLoggerManager()
      {
        @Override
        protected org.codehaus.plexus.logging.Logger createLogger(String s)
        {
          return new Slf4jLogger(LOG);
        }
      }
  );
}
 
Example #5
Source File: GroovyFunctionsTest.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
@Test
public void testOverrideWithTemp() throws Exception
{
    final File base = TestUtils.resolveFileResource( "groovy-project-removal", "" );
    final File root = temporaryFolder.newFolder();
    FileUtils.copyDirectory( base, root);
    final DefaultContainerConfiguration config = new DefaultContainerConfiguration();

    config.setClassPathScanning( PlexusConstants.SCANNING_ON );
    config.setComponentVisibility( PlexusConstants.GLOBAL_VISIBILITY );
    config.setName( "PME-CLI" );

    final PlexusContainer container = new DefaultPlexusContainer( config);
    final PomIO pomIO = container.lookup( PomIO.class );
    final List<Project> projects = pomIO.parseProject( new File( root, "pom.xml" ) );

    assertThat( projects.size(), equalTo(3) );

    BaseScriptImplTest impl = new BaseScriptImplTest();
    Properties p = new Properties(  );
    p.setProperty( "versionIncrementalSuffix", "temporary-redhat" );
    p.setProperty( "restRepositoryGroup", "GroovyWithTemporary" );
    p.setProperty( "restURL", mockServer.getUrl() );

    impl.setValues(pomIO, null, null, TestUtils.createSession( p ), projects, projects.get( 0 ), InvocationStage.FIRST );

    impl.overrideProjectVersion( SimpleProjectVersionRef.parse( "org.goots:sample:1.0.0" ) );
}
 
Example #6
Source File: GroovyFunctionsTest.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
@Test
public void testTempOverrideWithNonTemp() throws Exception
{
    final File base = TestUtils.resolveFileResource( "profile.pom", "" );
    final File root = temporaryFolder.newFolder();
    final File target = new File ( root, "profile.xml");
    FileUtils.copyFile( base, target);
    final DefaultContainerConfiguration config = new DefaultContainerConfiguration();

    config.setClassPathScanning( PlexusConstants.SCANNING_ON );
    config.setComponentVisibility( PlexusConstants.GLOBAL_VISIBILITY );
    config.setName( "PME-CLI" );

    final PlexusContainer container = new DefaultPlexusContainer( config);
    final PomIO pomIO = container.lookup( PomIO.class );
    final List<Project> projects = pomIO.parseProject( target );

    assertThat( projects.size(), equalTo(1) );

    BaseScriptImplTest impl = new BaseScriptImplTest();
    Properties p = new Properties(  );
    p.setProperty( "versionIncrementalSuffix", "temporary-redhat" );
    p.setProperty( "restRepositoryGroup", "GroovyWithTemporary" );
    p.setProperty( "restURL", mockServer.getUrl() );

    impl.setValues(pomIO, null, null, TestUtils.createSession( p ), projects, projects.get( 0 ), InvocationStage.FIRST );

    impl.overrideProjectVersion( SimpleProjectVersionRef.parse( "org.goots:testTempOverrideWithNonTemp:1.0.0" ) );

    assertEquals( "redhat-5",
                  impl.getUserProperties().getProperty( VersioningState.VERSION_SUFFIX_SYSPROP ) );
}
 
Example #7
Source File: EmbedderConfiguration.java    From netbeans with Apache License 2.0 5 votes vote down vote up
EmbedderConfiguration(PlexusContainer cont, Properties props, Properties userprops, boolean offline, File settingsXml) {
    this.cont = cont;
    this.props = props;
    this.offline = offline;
    this.settingsXml = settingsXml;
    this.userprops = userprops;
}
 
Example #8
Source File: GatewayAbstractMojo.java    From apigee-deploy-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void contextualize(Context context) throws ContextException {
	container = (PlexusContainer) context.get(PlexusConstants.PLEXUS_KEY);
	if (container.hasComponent(SettingsDecrypter.class)) {
		try {
			settingsDecrypter = container.lookup(SettingsDecrypter.class);
		} catch (ComponentLookupException e) {
			getLog().warn("Failed to lookup build in maven component session decrypter.", e);
		}
	}
}
 
Example #9
Source File: InitialGroovyManipulatorTest.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRemoveProjectInGroovyScript() throws Exception
{
    final File groovy = TestUtils.resolveFileResource( "groovy-project-removal", "manipulation.groovy" );
    final File base = TestUtils.resolveFileResource( "groovy-project-removal", "" );
    final File root = tf.newFolder();
    FileUtils.copyDirectory( base, root );
    final File projectroot = new File ( root, "pom.xml");

    final DefaultContainerConfiguration config = new DefaultContainerConfiguration();
    config.setClassPathScanning( PlexusConstants.SCANNING_ON );
    config.setComponentVisibility( PlexusConstants.GLOBAL_VISIBILITY );
    config.setName( "PME-CLI" );
    PlexusContainer container = new DefaultPlexusContainer( config );

    PomIO pomIO = container.lookup( PomIO.class );

    List<Project> projects = pomIO.parseProject( projectroot );

    assertThat( projects.size(), equalTo( 3 ) );

    Properties userProperties = new Properties();
    userProperties.setProperty( "versionIncrementalSuffix", "rebuild" );
    userProperties.setProperty( "groovyScripts", groovy.toURI().toString() );

    TestUtils.SMContainer smc = TestUtils.createSessionAndManager( userProperties );
    smc.getRequest().setPom( projectroot );
    smc.getManager().scanAndApply( smc.getSession() );

    // re-read the projects:
    projects = pomIO.parseProject( projectroot );
    assertThat( projects.size(), equalTo( 3 ) );

    assertEquals( 1, projectForArtifactId( projects, "groovy-project-removal").getModel().getProfiles().size() );
    assertThat( projectForArtifactId( projects, "groovy-project-removal" ).getVersion(), containsString( "rebuild" ) );
    assertThat( projectForArtifactId( projects, "groovy-project-removal-moduleA" ).getVersion(),
                containsString( "rebuild" ) );
    // moduleB was removed from projects by the groovy script and therefore should not be reversioned:
    assertThat( projectForArtifactId( projects, "groovy-project-removal-moduleB" ).getVersion(), equalTo( "1.0.0" ) );
}
 
Example #10
Source File: DistributionEnforcingManipulatorTest.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
private void setMavenSession()
    throws Exception
{
    final MavenExecutionRequest req =
        new DefaultMavenExecutionRequest().setUserProperties( userCliProperties )
                                          .setRemoteRepositories( Collections.emptyList() );

    final PlexusContainer container = new DefaultPlexusContainer();
    final MavenSession mavenSession = new MavenSession( container, null, req, new DefaultMavenExecutionResult() );

    session.setMavenSession( mavenSession );

}
 
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: 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 #13
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 #14
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 #15
Source File: DefaultJnlpDependencyRequestBuilder.java    From webstart with MIT License 4 votes vote down vote up
protected void setContainer( final PlexusContainer container )
{
    this.container = container;
}
 
Example #16
Source File: AbstractDockerMojo.java    From docker-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void contextualize(Context context) throws ContextException {
    authConfigFactory = new AuthConfigFactory((PlexusContainer) context.get(PlexusConstants.PLEXUS_KEY));
}
 
Example #17
Source File: CustomDeployTask.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public synchronized PlexusContainer getContainer() {
    return super.getContainer();
}
 
Example #18
Source File: VersioningCalculatorTest.java    From pom-manipulation-ext with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings( "deprecation" )
private VersioningState setupSession( final Properties properties, final Map<ProjectRef, String[]> versionMap )
    throws Exception
{
    // Originally the default used to be 0, this was changed to be 5 but this affects this test suite so revert
    // just for these tests.
    if ( ! properties.containsKey( VersioningState.INCREMENT_SERIAL_SUFFIX_PADDING_SYSPROP ) )
    {
        properties.setProperty( VersioningState.INCREMENT_SERIAL_SUFFIX_PADDING_SYSPROP, "0" );
    }

    final ArtifactRepository ar =
        new MavenArtifactRepository( "test", TestUtils.MVN_CENTRAL, new DefaultRepositoryLayout(),
                                     new ArtifactRepositoryPolicy(), new ArtifactRepositoryPolicy() );

    final MavenExecutionRequest req =
        new DefaultMavenExecutionRequest().setUserProperties( properties )
                                          .setRemoteRepositories( Collections.singletonList( 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;
}
 
Example #19
Source File: AbstractDeployMojo.java    From opoopress with Apache License 2.0 4 votes vote down vote up
@Override
public void contextualize(Context context) throws ContextException {
    container = (PlexusContainer) context.get(PlexusConstants.PLEXUS_KEY);
}
 
Example #20
Source File: BuildMojo.java    From opoopress with Apache License 2.0 4 votes vote down vote up
@Override
public void contextualize(Context context) throws ContextException {
    container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}
 
Example #21
Source File: InternalRunMojo.java    From wisdom with Apache License 2.0 4 votes vote down vote up
@Override
public void contextualize(Context context) throws ContextException {
    container = (PlexusContainer) context.get(PlexusConstants.PLEXUS_KEY);
}
 
Example #22
Source File: MdPageGeneratorMojo.java    From markdown-page-generator-plugin with MIT License 4 votes vote down vote up
public void contextualize(Context context) throws ContextException {
    plexusContainer = (PlexusContainer) context.get(PlexusConstants.PLEXUS_KEY);
}
 
Example #23
Source File: EmbedderConfiguration.java    From netbeans with Apache License 2.0 4 votes vote down vote up
PlexusContainer getContainer() {
    return cont;
}
 
Example #24
Source File: TarsBuildMojo.java    From TarsJava with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void contextualize(Context context) throws ContextException {
    container = (PlexusContainer) context.get(PlexusConstants.PLEXUS_KEY);
}
 
Example #25
Source File: CustomDeployTask.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public synchronized PlexusContainer getContainer() {
    return super.getContainer();
}
 
Example #26
Source File: CustomDeployTask.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public synchronized PlexusContainer getContainer() {
    return super.getContainer();
}
 
Example #27
Source File: MavenExecutionUtils.java    From vertx-maven-plugin with Apache License 2.0 4 votes vote down vote up
public static void execute(String phase, MavenProject project, MavenSession session, LifecycleExecutor executor,
                           PlexusContainer container) {
    MavenExecutionRequest request = getMavenExecutionRequest(session, phase);
    MavenSession newSession = getMavenSession(session, project, request, container);
    executor.execute(newSession);
}
 
Example #28
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 #29
Source File: MavenEmbedder.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public PlexusContainer getPlexus() {
    return plexus;
}
 
Example #30
Source File: DefaultJnlpDependencyRequestBuilder.java    From webstart with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void contextualize( final Context context )
        throws ContextException
{
    container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}