org.apache.maven.profiles.ProfileManager Java Examples

The following examples show how to use org.apache.maven.profiles.ProfileManager. 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: 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" ) );
}