Java Code Examples for org.codehaus.plexus.util.StringOutputStream

The following examples show how to use org.codehaus.plexus.util.StringOutputStream. These examples are extracted from open source projects. 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 Project: appassembler   Source File: FormattedPropertiesTest.java    License: MIT License 6 votes vote down vote up
private void saveAndCompare( String expectedResource )
    throws IOException
{
    StringOutputStream string = new StringOutputStream();
    formattedProperties.save( string );

    StringOutputStream expected = new StringOutputStream();
    InputStream asStream = getClass().getResourceAsStream( expectedResource );
    try
    {
        IOUtil.copy( asStream, expected );
    }
    finally
    {
        IOUtil.close( asStream );
    }

    String unified = StringUtils.unifyLineSeparators( expected.toString() );
    assertEquals( unified, string.toString() );
}
 
Example 2
Source Project: javafx-maven-plugin   Source File: JavaFXRunMojoTestCase.java    License: Apache License 2.0 5 votes vote down vote up
private String execute(AbstractMojo mojo) throws MojoFailureException, MojoExecutionException, InterruptedException {
    PrintStream out = System.out;
    StringOutputStream stringOutputStream = new StringOutputStream();
    System.setOut(new PrintStream(stringOutputStream));
    mojo.setLog(new DefaultLog(new ConsoleLogger(Logger.LEVEL_ERROR, "javafx:run")));

    try {
        mojo.execute();
    } finally {
        Thread.sleep(300);
        System.setOut(out);
    }

    return stringOutputStream.toString();
}
 
Example 3
Source Project: netbeans   Source File: ModelTest.java    License: Apache License 2.0 5 votes vote down vote up
private ModelSource createModelSource(String templateName) throws FileNotFoundException, IOException, URISyntaxException {
    URL url = getClass().getClassLoader().getResource(templateName);
    File templateFile = org.openide.util.Utilities.toFile(url.toURI());
    assertTrue(templateFile.exists());
    FileObject fo = FileUtil.toFileObject(templateFile);
    FileInputStream str = new FileInputStream(templateFile);
    StringOutputStream out = new StringOutputStream();
    FileUtil.copy(str, out);
    String dir = System.getProperty("java.io.tmpdir");
    File sourceFile = new File(dir, templateName);
    ModelSource source = Utilities.createModelSourceForMissingFile(sourceFile, true, out.toString(), "text/xml");
    assertTrue(source.isEditable());
    return source;
}
 
Example 4
Source Project: exec-maven-plugin   Source File: ExecMojoTest.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 
 * @param pom the pom file
 * @param goal the goal to execute
 * @return output from System.out during mojo execution
 * @throws Exception if any exception occurs
 */
protected String execute( File pom, String goal )
    throws Exception
{

    ExecMojo mojo;
    mojo = (ExecMojo) lookupMojo( goal, pom );

    setUpProject( pom, mojo );

    MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );

    // why isn't this set up by the harness based on the default-value? TODO get to bottom of this!
    // setVariableValueToObject( mojo, "includeProjectDependencies", Boolean.TRUE );
    // setVariableValueToObject( mojo, "killAfter", new Long( -1 ) );

    assertNotNull( mojo );
    assertNotNull( project );

    // trap System.out
    PrintStream out = System.out;
    StringOutputStream stringOutputStream = new StringOutputStream();
    System.setOut( new PrintStream( stringOutputStream ) );
    // ensure we don't log unnecessary stuff which would interfere with assessing success of tests
    mojo.setLog( new DefaultLog( new ConsoleLogger( Logger.LEVEL_ERROR, "exec:exec" ) ) );

    try
    {
        mojo.execute();
    }
    catch ( Throwable e )
    {
        e.printStackTrace( System.err );
        fail( e.getMessage() );
    }
    finally
    {
        System.setOut( out );
    }

    return stringOutputStream.toString();
}
 
Example 5
Source Project: exec-maven-plugin   Source File: ExecJavaMojoTest.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @return output from System.out during mojo execution
 */
private String execute( File pom, String goal )
    throws Exception
{

    ExecJavaMojo mojo;
    mojo = (ExecJavaMojo) lookupMojo( goal, pom );

    setUpProject( pom, mojo );

    MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );

    // why isn't this set up by the harness based on the default-value? TODO get to bottom of this!
    setVariableValueToObject( mojo, "includeProjectDependencies", Boolean.TRUE );
    setVariableValueToObject( mojo, "killAfter", (long) -1 );
    setVariableValueToObject( mojo, "cleanupDaemonThreads", Boolean.TRUE );
    setVariableValueToObject( mojo, "classpathScope", "compile" );

    assertNotNull( mojo );
    assertNotNull( project );

    // trap System.out
    PrintStream out = System.out;
    StringOutputStream stringOutputStream = new StringOutputStream();
    System.setOut( new PrintStream( stringOutputStream ) );
    // ensure we don't log unnecessary stuff which would interfere with assessing success of tests
    mojo.setLog( new DefaultLog( new ConsoleLogger( Logger.LEVEL_ERROR, "exec:java" ) ) );

    try
    {
        mojo.execute();
    }
    finally
    {
        // see testUncooperativeThread() for explaination
        Thread.sleep( 300 ); // time seems about right
        System.setOut( out );
    }

    return stringOutputStream.toString();
}