org.codehaus.plexus.util.InterpolationFilterReader Java Examples

The following examples show how to use org.codehaus.plexus.util.InterpolationFilterReader. 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: MojoExtension.java    From helm-maven-plugin with MIT License 6 votes vote down vote up
@Override
public void beforeAll(ExtensionContext context) throws Exception {

    // get plugin descriptor

    InputStream inputStream = AbstractHelmMojo.class.getResourceAsStream("/META-INF/maven/plugin.xml");
    assertNotNull(inputStream, "Plugin descriptor not found.");
    plugin = new PluginDescriptorBuilder().build(new InterpolationFilterReader(new BufferedReader(new XmlStreamReader(inputStream)), new HashMap<>()));

    // get mojos

    mojoDescriptors = new HashMap<>();
    for (MojoDescriptor mojoDescriptor : plugin.getMojos()) {
        mojoDescriptors.put((Class<? extends AbstractHelmMojo>) Class.forName(mojoDescriptor.getImplementation()), mojoDescriptor);
    }
}
 
Example #2
Source File: Platform.java    From appassembler with MIT License 6 votes vote down vote up
private String interpolateBaseDirAndRepo( String content )
{
    StringReader sr = new StringReader( content );
    StringWriter result = new StringWriter();

    Map<Object, Object> context = new HashMap<Object, Object>();

    context.put( "BASEDIR", StringUtils.quoteAndEscape( getBasedir(), '"' ) );
    context.put( "REPO", StringUtils.quoteAndEscape( getRepo(), '"' ) );
    InterpolationFilterReader interpolationFilterReader = new InterpolationFilterReader( sr, context, "@", "@" );
    try
    {
        IOUtil.copy( interpolationFilterReader, result );
    }
    catch ( IOException e )
    {
        // shouldn't happen...
    }
    return result.toString();
}
 
Example #3
Source File: AppassemblerBooter.java    From appassembler with MIT License 5 votes vote down vote up
private static String interpolateBaseDirAndRepo( String content )
{
    StringReader sr = new StringReader( content );
    StringWriter result = new StringWriter();

    Map<Object, Object> context = new HashMap<Object, Object>();

    final String baseDir = System.getProperty( "basedir", System.getProperty( "app.home" ) );
    if ( baseDir != null && baseDir.length() > 0) {
        context.put( "BASEDIR", StringUtils.quoteAndEscape(baseDir, '"') );
    }

    final String repo = System.getProperty( "app.repo" );
    if ( repo != null && repo.length() > 0 ) {
        context.put("REPO", StringUtils.quoteAndEscape(repo, '"'));
    }

    InterpolationFilterReader interpolationFilterReader = new InterpolationFilterReader( sr, context, "@", "@" );
    try
    {
        IOUtil.copy( interpolationFilterReader, result );
    }
    catch ( IOException e )
    {
        // shouldn't happen...
    }
    return result.toString();
}
 
Example #4
Source File: JavaServiceWrapperDaemonGenerator.java    From appassembler with MIT License 5 votes vote down vote up
private static void writeFilteredFile( DaemonGenerationRequest request, Daemon daemon, Reader reader,
                                       File outputFile, Map context )
                                           throws DaemonGeneratorException
{
    InterpolationFilterReader interpolationFilterReader =
        new InterpolationFilterReader( reader, context, "@", "@" );

    writeFile( outputFile, interpolationFilterReader );
}
 
Example #5
Source File: AbstractDaemonGeneratorTest.java    From appassembler with MIT License 5 votes vote down vote up
protected File createFilteredFile( String file )
    throws IOException, FileNotFoundException, DaemonGeneratorException, XmlPullParserException
{
    String version = getAppAssemblerBooterVersion();
    Properties context = new Properties();
    context.setProperty( "appassembler.version", version );

    File tempPom = File.createTempFile( "appassembler", "tmp" );
    tempPom.deleteOnExit();

    InterpolationFilterReader reader =
        new InterpolationFilterReader( new FileReader( getTestFile( file ) ), context, "@", "@" );
    FileWriter out = null;

    try
    {
        out = new FileWriter( tempPom );

        IOUtil.copy( reader, out );
    }
    catch ( IOException e )
    {
        throw new DaemonGeneratorException( "Error writing output file: " + tempPom.getAbsolutePath(), e );
    }
    finally
    {
        IOUtil.close( reader );
        IOUtil.close( out );
    }
    return tempPom;
}
 
Example #6
Source File: DetectExtension.java    From os-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Nullable
private static String interpolate(Map<String, String> dict, String value) {
    if (value == null) {
        return null;
    }

    for (;;) {
        if (!value.contains("${")) {
            // Nothing to interpolate.
            break;
        }

        @SuppressWarnings({ "unchecked", "rawtypes" })
        final InterpolationFilterReader reader = new InterpolationFilterReader(
                new StringReader(value), (Map<String, Object>) (Map) dict);
        final StringWriter writer = new StringWriter(value.length());
        for (;;) {
            final int ch;
            try {
                ch = reader.read();
            } catch (IOException e) {
                // Should not reach here.
                throw (Error) new Error().initCause(e);
            }

            if (ch == -1) {
                break;
            }
            writer.write(ch);
        }

        final String newValue = writer.toString();
        if (value.equals(newValue)) {
            // No interpolatable properties left.
            break;
        }

        // Interpolated at least one variable.
        // Try again just in case the interpolation introduced another variable.
        value = newValue;
    }

    return value;
}