org.apache.maven.profiles.DefaultProfileManager Java Examples

The following examples show how to use org.apache.maven.profiles.DefaultProfileManager. 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: AbstractJnlpMojoTest.java    From webstart with MIT License 6 votes vote down vote up
private void setUpProject( File pomFile, AbstractMojo mojo )
    throws Exception
{
    MavenProjectBuilder projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );

    ArtifactRepositoryFactory artifactRepositoryFactory =
        (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );

    ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy( true, "never", "never" );

    String localRepoUrl = "file://" + System.getProperty( "user.home" ) + "/.m2/repository";

    ArtifactRepository localRepository =
        artifactRepositoryFactory.createArtifactRepository( "local", localRepoUrl, new DefaultRepositoryLayout(),
                                                            policy, policy );

    ProfileManager profileManager = new DefaultProfileManager( getContainer() );

    MavenProject project = projectBuilder.buildWithDependencies( pomFile, localRepository, profileManager );

    //this gets the classes for these tests of this mojo (exec plugin) onto the project classpath for the test
    project.getBuild().setOutputDirectory( new File( "target/test-classes" ).getAbsolutePath() );
    setVariableValueToObject( mojo, "project", project );
}
 
Example #2
Source File: ManipulationManager.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings( {"unchecked", "deprecation" } )
private Set<String> parseActiveProfiles( ManipulationSession session, List<Project> projects ) throws ManipulationException
{
    final Set<String> activeProfiles = new HashSet<>();
    final DefaultProfileManager dpm = new DefaultProfileManager( session.getSession().getContainer(), session.getUserProperties() );

    logger.debug("Explicitly activating {}", session.getActiveProfiles());
    dpm.explicitlyActivate( session.getActiveProfiles() );

    for ( Project p : projects )
    {
        // We clone the original profile here to prevent the DefaultProfileManager affecting the original list
        // during its activation calculation.
        p.getModel().getProfiles().stream().filter( newProfile -> ! dpm.getProfilesById().containsKey( newProfile.getId() ) ).
                        forEach( newProfile -> dpm.addProfile( newProfile.clone() ) );

        try
        {
            List<org.apache.maven.model.Profile> ap = dpm.getActiveProfiles();
            activeProfiles.addAll( ap.stream().map( org.apache.maven.model.Profile::getId ).collect( Collectors.toList() ) );
        }
        catch ( ProfileActivationException e )
        {
            throw new ManipulationException( "Activation detection failure", e );
        }
    }


    if (logger.isDebugEnabled())
    {
        logger.debug("Will {}scan all profiles and returning active profiles of {} ",
                Boolean.parseBoolean(session.getUserProperties().getProperty(PROFILE_SCANNING, PROFILE_SCANNING_DEFAULT)) ? "not " : "",
                activeProfiles);
    }

    return activeProfiles;
}
 
Example #3
Source File: AbstractDaemonGeneratorTest.java    From appassembler with MIT License 2 votes vote down vote up
public void runTest( String generatorId, String pom, String descriptor, String outputPath )
    throws Exception
{
    File outputDir = getTestFile( outputPath );

    DaemonGenerator generator = (DaemonGenerator) lookup( DaemonGenerator.ROLE, generatorId );

    // -----------------------------------------------------------------------
    // Build the MavenProject instance
    // -----------------------------------------------------------------------

    MavenProjectBuilder projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );

    MavenSettingsBuilder settingsBuilder = (MavenSettingsBuilder) lookup( MavenSettingsBuilder.ROLE );
    Settings settings = settingsBuilder.buildSettings();

    ArtifactRepositoryFactory artifactRepositoryFactory =
        (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );

    String localRepoUrl = new File( settings.getLocalRepository() ).toURL().toExternalForm();

    ArtifactRepository localRepository =
        artifactRepositoryFactory.createDeploymentArtifactRepository( "local", localRepoUrl,
                                                                      new DefaultRepositoryLayout(), false );

    ProfileManager profileManager = new DefaultProfileManager( getContainer() );

    File tempPom = createFilteredFile( pom );

    MavenProject project = projectBuilder.buildWithDependencies( tempPom, localRepository, profileManager );

    // -----------------------------------------------------------------------
    // Clean the output directory
    // -----------------------------------------------------------------------

    FileUtils.deleteDirectory( outputDir );
    FileUtils.forceMkdir( outputDir );

    // -----------------------------------------------------------------------
    //
    // -----------------------------------------------------------------------

    DaemonGeneratorService daemonGeneratorService = (DaemonGeneratorService) lookup( DaemonGeneratorService.ROLE );

    Daemon model = daemonGeneratorService.loadModel( getTestFile( descriptor ) );

    generator.generate( new DaemonGenerationRequest( model, project, localRepository, outputDir, "bin" ) );
}