Java Code Examples for org.codehaus.plexus.util.IOUtil#toString()

The following examples show how to use org.codehaus.plexus.util.IOUtil#toString() . 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: PomHelper.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Reads a file into a String.
 *
 * @param outFile The file to read.
 * @return String The content of the file.
 * @throws java.io.IOException when things go wrong.
 */
public static StringBuilder readXmlFile( File outFile )
    throws IOException
{
    try( Reader reader = ReaderFactory.newXmlReader( outFile ) )
    {
        return new StringBuilder( IOUtil.toString( reader ) );
    }
}
 
Example 2
Source File: AbstractDockerComposeMojo.java    From docker-compose-maven-plugin with MIT License 4 votes vote down vote up
void execute(List<String> args) throws MojoExecutionException {

        ProcessBuilder pb = buildProcess(args);

        getLog().info("Running: " + StringUtils.join(pb.command().iterator(), " "));

        try {
            Process p = pb.start();

            BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));

            String line;

            while ((line = br.readLine()) != null)
                getLog().info(line);

            int ec = p.waitFor();

            if (ec != 0)
                throw new DockerComposeException(IOUtil.toString(p.getErrorStream()));

        } catch (Exception e) {
            throw new MojoExecutionException(e.getMessage());
        }
    }
 
Example 3
Source File: PomTidyTest.java    From tidy-maven-plugin with Apache License 2.0 4 votes vote down vote up
private String readPom( String filename )
    throws IOException
{
    InputStream is = getClass().getResourceAsStream( name + "/" + filename );
    return IOUtil.toString( is );
}
 
Example 4
Source File: SqlExecMojo.java    From sql-maven-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * read in lines and execute them
 * 
 * @param reader the reader
 * @param out the outputstream
 * @throws SQLException
 * @throws IOException
 */
private void runStatements( Reader reader, PrintStream out )
    throws SQLException, IOException
{
    String line;

    // TODO: Check if this equivalent with if (enableBlockMode) {..
    if ( delimiterType.equals( DelimiterType.ROW ) )
    {
        // no need to parse the content, ship it directly to jdbc in one sql statement
        line = IOUtil.toString( reader );
        execSQL( line, out );
        return;
    }

    StringBuffer sql = new StringBuffer();

    BufferedReader in = new BufferedReader( reader );

    int overflow = SqlSplitter.NO_END;

    while ( ( line = in.readLine() ) != null )
    {
        if ( !keepFormat )
        {
            line = line.trim();
        }

        if ( !keepFormat )
        {
            if ( line.startsWith( "//" ) )
            {
                continue;
            }
            if ( line.startsWith( "--" ) )
            {
                continue;
            }
            StringTokenizer st = new StringTokenizer( line );
            if ( st.hasMoreTokens() )
            {
                String token = st.nextToken();
                if ( "REM".equalsIgnoreCase( token ) )
                {
                    continue;
                }
            }
        }

        if ( !keepFormat )
        {
            sql.append( " " ).append( line );
        }
        else
        {
            sql.append( "\n" ).append( line );
        }

        overflow = SqlSplitter.containsSqlEnd( line, delimiter, overflow );

        // SQL defines "--" as a comment to EOL
        // and in Oracle it may contain a hint
        // so we cannot just remove it, instead we must end it
        if ( !keepFormat && overflow == SqlSplitter.NO_END )
        {
            sql.append( "\n" );
        }

        if ( ( delimiterType.equals( DelimiterType.NORMAL ) && overflow > 0 )
            || ( delimiterType.equals( DelimiterType.ROW ) && line.trim().equals( delimiter ) ) )
        {
            execSQL( sql.substring( 0, sql.length() - delimiter.length() ), out );
            sql.setLength( 0 ); // clean buffer
            overflow = SqlSplitter.NO_END;
        }
    }

    // Catch any statements not followed by ;
    if ( sql.length() > 0 )
    {
        execSQL( sql.toString(), out );
    }
}
 
Example 5
Source File: AsciidoctorDoxiaParser.java    From asciidoctor-maven-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void parse(Reader reader, Sink sink) throws ParseException {
    String source;
    try {
        if ((source = IOUtil.toString(reader)) == null) {
            source = "";
        }
    } catch (IOException ex) {
        getLog().error("Could not read AsciiDoc source: " + ex.getLocalizedMessage());
        return;
    }

    final MavenProject project = mavenProjectProvider.get();
    final Xpp3Dom siteConfig = getSiteConfig(project);
    final File siteDirectory = resolveSiteDirectory(project, siteConfig);

    // Doxia handles a single instance of this class and invokes it multiple times.
    // We need to ensure certain elements are initialized only once to avoid errors.
    // Note, this cannot be done in the constructor because mavenProjectProvider in set after construction.
    // And overriding init and other methods form parent classes does not work.
    final Asciidoctor asciidoctor = Asciidoctor.Factory.create();

    SiteConversionConfiguration conversionConfig = new SiteConversionConfigurationParser(project)
            .processAsciiDocConfig(siteConfig, defaultOptions(siteDirectory), defaultAttributes());
    for (String require : conversionConfig.getRequires()) {
        requireLibrary(asciidoctor, require);
    }

    final LogHandler logHandler = getLogHandlerConfig(siteConfig);
    final MemoryLogHandler memoryLogHandler = asciidoctorLoggingSetup(asciidoctor, logHandler, siteDirectory);

    // QUESTION should we keep OptionsBuilder & AttributesBuilder separate for call to convertAsciiDoc?
    String asciidocHtml = convertAsciiDoc(asciidoctor, source, conversionConfig.getOptions());
    try {
        // process log messages according to mojo configuration
        new LogRecordsProcessors(logHandler, siteDirectory, errorMessage -> getLog().error(errorMessage))
                .processLogRecords(memoryLogHandler);
    } catch (Exception exception) {
        throw new ParseException(exception.getMessage(), exception);
    }

    sink.rawText(asciidocHtml);
}
 
Example 6
Source File: PomMergeDriver.java    From pomutils with Apache License 2.0 2 votes vote down vote up
private void consumeGitOutput(final Process p) throws IOException {

		String output = IOUtil.toString(new BufferedInputStream(p.getInputStream(), 256));

		logger.debug("Git merge output:\n{}", output);
	}