You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "John Franey (JIRA)" <ji...@codehaus.org> on 2007/02/20 19:47:27 UTC

[jira] Commented: (MASSEMBLY-167) Property Expansion/Filtering does not always work for System.properties

    [ http://jira.codehaus.org/browse/MASSEMBLY-167?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_88075 ] 

John Franey commented on MASSEMBLY-167:
---------------------------------------

Here is a unit test for this fix.


{code:title=A test in FormatFileTest.java|borderStyle=solid}
    public void testShouldFilterSystemPropertyInFile()
        throws IOException, AssemblyFormattingException
    {
        File basedir = fileManager.createTempDir();

        enableBasicFilteringConfiguration( basedir, Collections.EMPTY_LIST );

        File file = fileManager.createFile( basedir, "one.txt", "This is a test for project: ${java.version}." );

        String version = System.getProperty("java.version");
        mockManager.replayAll();

        File result = new FileFormatter( configSource, logger ).format( file, true, null );

        assertEquals( "This is a test for project: " + version + ".", fileManager.getFileContents( result ) );

        mockManager.verifyAll();
    }
{code}

> Property Expansion/Filtering does not always work for System.properties
> -----------------------------------------------------------------------
>
>                 Key: MASSEMBLY-167
>                 URL: http://jira.codehaus.org/browse/MASSEMBLY-167
>             Project: Maven 2.x Assembly Plugin
>          Issue Type: Bug
>    Affects Versions: 2.2
>         Environment: JDK 1.5.0_10, Maven 2.1-SNAPSHOT, Linux 2.6.18
>            Reporter: Daniel Krisher
>            Priority: Minor
>
> When using filtering for a file element in an assembly descriptor, System properties (e.g. java.version) are not always available (and do not get replaced in the filtered file).
> For example, my assembly descriptor contains:
> {noformat} 
>  <file>
>             <source>src/main/files/config/splash.xml</source>
>             <outputDirectory>/config</outputDirectory>
>             <filtered>true</filtered>
>  </file>
> {noformat} 
> and splash.xml (pre-filtering): 
> {noformat} 
> <properties>
>     <entry key="title">${project.name}</entry>
>     <entry key="Version">${project.version}</entry>
>     <entry key="Compiled with Java ">${java.version}</entry>
> </properties>
> {noformat} 
> Which results in a post-filtered splash.xml:
> {noformat} 
> <properties>
>     <entry key="title">ACES Viewer</entry>
>     <entry key="Version">0.7-SNAPSHOT</entry>
>     <entry key="Compiled with Java ">${java.version}</entry>
> </properties>
> {noformat} 
> The problem appears to be in the 'initializeFiltering()' method of the FileFormatter class.  The filter properties are initialized using:
> filterProperties = new Properties(System.getProperties());
> Changing this to:
> filterProperties = new Properties();
> filterProperties.putAll(System.getProperties());
> Seems to fix the problem.
> The Properties javadocs are a little vague on the constructor parameter:
> public Properties(Properties defaults)
>     Creates an empty property list with the specified defaults.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira