protected Reader getInterpolationConfigurationReader( Reader reader ) { return new InterpolationFilterReader( reader, new ContextMapAdapter( containerContext ) ); }
InterpolationFilterReader interpolationFilterReader = new InterpolationFilterReader( reader, new ContextMapAdapter( context ) );
protected void setUp() throws Exception { assertTrue( "Maven 3.2.4 or better is required", MAVEN_VERSION == null || new DefaultArtifactVersion( "3.2.3" ).compareTo( MAVEN_VERSION ) < 0 ); configurator = getContainer().lookup( ComponentConfigurator.class, "basic" ); InputStream is = getClass().getResourceAsStream( "/" + getPluginDescriptorLocation() ); XmlStreamReader reader = new XmlStreamReader( is ); InterpolationFilterReader interpolationFilterReader = new InterpolationFilterReader( new BufferedReader( reader ), container.getContext().getContextData() ); PluginDescriptor pluginDescriptor = new PluginDescriptorBuilder().build( interpolationFilterReader ); Artifact artifact = lookup( RepositorySystem.class ).createArtifact( pluginDescriptor.getGroupId(), pluginDescriptor.getArtifactId(), pluginDescriptor.getVersion(), ".jar" ); artifact.setFile( getPluginArtifactFile() ); pluginDescriptor.setPluginArtifact( artifact ); pluginDescriptor.setArtifacts( Arrays.asList( artifact ) ); for ( ComponentDescriptor<?> desc : pluginDescriptor.getComponents() ) { getContainer().addComponentDescriptor( desc ); } mojoDescriptors = new HashMap<String, MojoDescriptor>(); for ( MojoDescriptor mojoDescriptor : pluginDescriptor.getMojos() ) { mojoDescriptors.put( mojoDescriptor.getGoal(), mojoDescriptor ); } }
public Reader getReader(Reader fileReader, Map filterProperties) { return new InterpolationFilterReader( fileReader, filterProperties, "${", "}" ); } },
public Reader getReader(Reader fileReader, Map filterProperties) { return new InterpolationFilterReader( fileReader, filterProperties, "@", "@" ); } }
public Reader getReader(Reader fileReader, Properties filterProperties) { return new InterpolationFilterReader(fileReader, filterProperties, "${", "}"); } },
public Reader getReader(Reader fileReader, Properties filterProperties) { return new InterpolationFilterReader(fileReader, filterProperties, "@", "@"); } }};
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 ); }
public static String read(URL location, Map<String, String> properties) throws IOException { Reader reader = new InterpolationFilterReader(new BufferedReader(new InputStreamReader(location.openStream())), properties); try { return IOUtil.toString(reader); } finally { reader.close(); } }
protected void filterCopy( Reader in, File out, Map map ) throws IOException { InterpolationFilterReader reader = new InterpolationFilterReader( in, map, "@", "@" ); Writer writer = new FileWriter( out ); IOUtil.copy( reader, writer ); writer.close(); }
public static String read(URL location, String encoding, Map<String, String> properties) throws IOException { Reader reader = new InterpolationFilterReader(new BufferedReader(new InputStreamReader(location.openStream(), encoding)), properties); try { return IOUtil.toString(reader); } finally { reader.close(); } }
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 ); }
/** * Wraps the given {@link InputStream} as a {@link Reader} with XML encoding detection and optional interpolation. * * @param in The input stream * @param variables The filter variables * @return Reader that can automatically detect XML encodings and optionally interpolate variables */ private static Reader filteredXmlReader( final InputStream in, final Map<?, ?> variables ) throws IOException { final Reader reader = ReaderFactory.newXmlReader( in ); if ( null != variables ) { return new InterpolationFilterReader( reader, variables ); } return reader; }
/** * Wraps the given {@link InputStream} as a {@link Reader} with XML encoding detection and optional interpolation. * * @param in The input stream * @param variables The filter variables * @return Reader that can automatically detect XML encodings and optionally interpolate variables */ private static Reader filteredXmlReader( final InputStream in, @SuppressWarnings( "rawtypes" ) final Map variables ) throws IOException { final Reader reader = ReaderFactory.newXmlReader( in ); if ( null != variables ) { return new InterpolationFilterReader( reader, variables ); } return reader; }
public static void interpolationFileCopy(File from, File dest, Map<String, String> variables) throws IOException { // we may also need to create any parent directories if (dest.getParentFile() != null && !dest.getParentFile().exists()) { dest.getParentFile().mkdirs(); } FileReader fileReader = new FileReader(from); InterpolationFilterReader filterReader = new InterpolationFilterReader(fileReader, ImmutableMap.<String, Object>copyOf(variables)); FileWriter fos = new FileWriter(dest); int readChar = -1; while ((readChar = filterReader.read()) != -1) { fos.write(readChar); } // close everything fileReader.close(); fos.close(); }
public static void interpolationFileCopy( File from, File dest, Map<String, String> variables ) throws IOException { // we may also need to create any parent directories if ( dest.getParentFile() != null && !dest.getParentFile().exists() ) { dest.getParentFile().mkdirs(); } FileReader fileReader = new FileReader( from ); InterpolationFilterReader filterReader = new InterpolationFilterReader( fileReader, variables ); FileWriter fos = new FileWriter( dest ); int readChar = -1; while ( ( readChar = (int) filterReader.read() ) != -1 ) { fos.write( readChar ); } // close everything fileReader.close(); fos.close(); }
private String interpolate( final String text ) { if ( null == text || !text.contains( "${" ) ) { return text; } // use same interpolation method as XML for sake of consistency final Reader r = new InterpolationFilterReader( new StringReader( text ), variables ); try { return IOUtil.toString( r ); } catch ( final IOException e ) { return text; // should never actually happen, as no actual I/O involved } finally { IOUtil.close( r ); } } }
protected Reader getInterpolationConfigurationReader( Reader reader ) { return new InterpolationFilterReader( reader, new ContextMapAdapter( containerContext ) ); }
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(); }
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(); }