You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Chris Molozian (Created) (JIRA)" <ji...@apache.org> on 2012/02/24 12:27:48 UTC

[jira] [Created] (CONFIGURATION-480) Reading Manifest files using PropertiesConfiguration

Reading Manifest files using PropertiesConfiguration
----------------------------------------------------

                 Key: CONFIGURATION-480
                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-480
             Project: Commons Configuration
          Issue Type: Bug
    Affects Versions: 1.7
            Reporter: Chris Molozian


I've searched through the documentation and online with Google. The documentation for PropertiesConfiguration explains that it can parse files with '=' or ':' or ' ' as delimiters. I have a MANIFEST.MF file with the following format:

{code:title=MANIFEST.MF|borderStyle=solid}
Manifest-Version: 1.0
Implementation-Title: webapp
Implementation-Version: 0.0.1
Created-By: Gradle 1.0-milestone-6
Build-Jdk: 1.6.0_26


{code}

I've tried to use the PropertiesConfiguration to parse this file, assuming that the ' ' delimiter would be used to divide key-value pairs. Instead I get the following error:

{code}
java.lang.IllegalArgumentException: Key for add operation must be defined!
	at org.apache.commons.configuration.tree.DefaultExpressionEngine.prepareAdd(DefaultExpressionEngine.java:420)
	at org.apache.commons.configuration.HierarchicalConfiguration.addPropertyDirect(HierarchicalConfiguration.java:383)
	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.addPropertyDirect(AbstractHierarchicalFileConfiguration.java:147)
	at org.apache.commons.configuration.AbstractConfiguration.addPropertyValues(AbstractConfiguration.java:423)
	at org.apache.commons.configuration.AbstractConfiguration.append(AbstractConfiguration.java:1271)
{code}

At the moment I've created a (very rough) custom PropertiesReader as suggested by the User Guide for handling "unconventional formats".

{code}
private static class ManifestPropertiesReader
            extends PropertiesConfiguration.PropertiesReader {
    public ManifestPropertiesReader(final Reader in, final char delimiter) {
        super(in, delimiter);
    }

    @Override
    protected void parseProperty(final String line) {
        final int pos = line.indexOf(':');
        final String key = line.substring(0, pos).trim();
        final String value = line.substring(pos + 1).trim();

        initPropertyName(key);
        initPropertyValue(value);
    }
}
{code}

And:

{code}
private static class ManifestIOFactory
        extends PropertiesConfiguration.DefaultIOFactory {
    /** Use a custom {@code PropertiesReader} for Manifest files. */
    @Override
    public PropertiesReader createPropertiesReader(final Reader in,
            final char delimiter) {
        return new ManifestPropertiesReader(in, delimiter);
    }
}
{code}

Should all this be necessary to parse MANIFEST.MF files or have I missed something?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CONFIGURATION-480) Reading Manifest files using PropertiesConfiguration

Posted by "Oliver Heger (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CONFIGURATION-480?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13217549#comment-13217549 ] 

Oliver Heger commented on CONFIGURATION-480:
--------------------------------------------

If your use case is just splitting key value pairs separated by a colon, then this should be possible with PropertiesConfiguration out of the box. Our unit test suite contains tests with files using the colon as alternative separator. So I have no idea why this does not work in your case. As I pointed out, the exception you posted indicates that PropertiesConfiguration is not used at all.

However, manifest files can become more complex, e.g. there is a hard limit for the line length and automatic line wrapping, or a special syntax for directives or properties with multiple values intoduced by the OSGi specification. Commons Configuration does not contain a class which supports these features or is specialized on parsing manifest files.
                
> Reading Manifest files using PropertiesConfiguration
> ----------------------------------------------------
>
>                 Key: CONFIGURATION-480
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-480
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.7
>            Reporter: Chris Molozian
>
> I've searched through the documentation and online with Google. The documentation for PropertiesConfiguration explains that it can parse files with '=' or ':' or ' ' as delimiters. I have a MANIFEST.MF file with the following format:
> {code:title=MANIFEST.MF|borderStyle=solid}
> Manifest-Version: 1.0
> Implementation-Title: webapp
> Implementation-Version: 0.0.1
> Created-By: Gradle 1.0-milestone-6
> Build-Jdk: 1.6.0_26
> {code}
> I've tried to use the PropertiesConfiguration to parse this file, assuming that the ' ' delimiter would be used to divide key-value pairs. Instead I get the following error:
> {code}
> java.lang.IllegalArgumentException: Key for add operation must be defined!
> 	at org.apache.commons.configuration.tree.DefaultExpressionEngine.prepareAdd(DefaultExpressionEngine.java:420)
> 	at org.apache.commons.configuration.HierarchicalConfiguration.addPropertyDirect(HierarchicalConfiguration.java:383)
> 	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.addPropertyDirect(AbstractHierarchicalFileConfiguration.java:147)
> 	at org.apache.commons.configuration.AbstractConfiguration.addPropertyValues(AbstractConfiguration.java:423)
> 	at org.apache.commons.configuration.AbstractConfiguration.append(AbstractConfiguration.java:1271)
> {code}
> At the moment I've created a (very rough) custom PropertiesReader as suggested by the User Guide for handling "unconventional formats".
> {code}
> private static class ManifestPropertiesReader
>             extends PropertiesConfiguration.PropertiesReader {
>     public ManifestPropertiesReader(final Reader in, final char delimiter) {
>         super(in, delimiter);
>     }
>     @Override
>     protected void parseProperty(final String line) {
>         final int pos = line.indexOf(':');
>         final String key = line.substring(0, pos).trim();
>         final String value = line.substring(pos + 1).trim();
>         initPropertyName(key);
>         initPropertyValue(value);
>     }
> }
> {code}
> And:
> {code}
> private static class ManifestIOFactory
>         extends PropertiesConfiguration.DefaultIOFactory {
>     /** Use a custom {@code PropertiesReader} for Manifest files. */
>     @Override
>     public PropertiesReader createPropertiesReader(final Reader in,
>             final char delimiter) {
>         return new ManifestPropertiesReader(in, delimiter);
>     }
> }
> {code}
> Should all this be necessary to parse MANIFEST.MF files or have I missed something?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CONFIGURATION-480) Reading Manifest files using PropertiesConfiguration

Posted by "Oliver Heger (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CONFIGURATION-480?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13215884#comment-13215884 ] 

Oliver Heger commented on CONFIGURATION-480:
--------------------------------------------

This is strange. The exception stack trace you provided seems to indicate that a hierarchical configuration is used rather than PropertiesConfiguration (which is not hierarchical). Can you post the code which tries to load the manifest file?
                
> Reading Manifest files using PropertiesConfiguration
> ----------------------------------------------------
>
>                 Key: CONFIGURATION-480
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-480
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.7
>            Reporter: Chris Molozian
>
> I've searched through the documentation and online with Google. The documentation for PropertiesConfiguration explains that it can parse files with '=' or ':' or ' ' as delimiters. I have a MANIFEST.MF file with the following format:
> {code:title=MANIFEST.MF|borderStyle=solid}
> Manifest-Version: 1.0
> Implementation-Title: webapp
> Implementation-Version: 0.0.1
> Created-By: Gradle 1.0-milestone-6
> Build-Jdk: 1.6.0_26
> {code}
> I've tried to use the PropertiesConfiguration to parse this file, assuming that the ' ' delimiter would be used to divide key-value pairs. Instead I get the following error:
> {code}
> java.lang.IllegalArgumentException: Key for add operation must be defined!
> 	at org.apache.commons.configuration.tree.DefaultExpressionEngine.prepareAdd(DefaultExpressionEngine.java:420)
> 	at org.apache.commons.configuration.HierarchicalConfiguration.addPropertyDirect(HierarchicalConfiguration.java:383)
> 	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.addPropertyDirect(AbstractHierarchicalFileConfiguration.java:147)
> 	at org.apache.commons.configuration.AbstractConfiguration.addPropertyValues(AbstractConfiguration.java:423)
> 	at org.apache.commons.configuration.AbstractConfiguration.append(AbstractConfiguration.java:1271)
> {code}
> At the moment I've created a (very rough) custom PropertiesReader as suggested by the User Guide for handling "unconventional formats".
> {code}
> private static class ManifestPropertiesReader
>             extends PropertiesConfiguration.PropertiesReader {
>     public ManifestPropertiesReader(final Reader in, final char delimiter) {
>         super(in, delimiter);
>     }
>     @Override
>     protected void parseProperty(final String line) {
>         final int pos = line.indexOf(':');
>         final String key = line.substring(0, pos).trim();
>         final String value = line.substring(pos + 1).trim();
>         initPropertyName(key);
>         initPropertyValue(value);
>     }
> }
> {code}
> And:
> {code}
> private static class ManifestIOFactory
>         extends PropertiesConfiguration.DefaultIOFactory {
>     /** Use a custom {@code PropertiesReader} for Manifest files. */
>     @Override
>     public PropertiesReader createPropertiesReader(final Reader in,
>             final char delimiter) {
>         return new ManifestPropertiesReader(in, delimiter);
>     }
> }
> {code}
> Should all this be necessary to parse MANIFEST.MF files or have I missed something?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CONFIGURATION-480) Reading Manifest files using PropertiesConfiguration

Posted by "Chris Molozian (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CONFIGURATION-480?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13217169#comment-13217169 ] 

Chris Molozian commented on CONFIGURATION-480:
----------------------------------------------

Apologies for the late response, I've embedded the code that's attempting to parse the MANIFEST.MF file:

{code}
PropertiesConfiguration manifestConf = new PropertiesConfiguration();
manifestConf.setIOFactory(new ManifestIOFactory());
manifestConf.setFileName("/META-INF/MANIFEST.MF");
manifestConf.load();
{code}

You didn't really answer my other question, is there anything within Apache Commons Configuration that supports the parsing of the MANIFEST.MF format?

Thanks.
                
> Reading Manifest files using PropertiesConfiguration
> ----------------------------------------------------
>
>                 Key: CONFIGURATION-480
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-480
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.7
>            Reporter: Chris Molozian
>
> I've searched through the documentation and online with Google. The documentation for PropertiesConfiguration explains that it can parse files with '=' or ':' or ' ' as delimiters. I have a MANIFEST.MF file with the following format:
> {code:title=MANIFEST.MF|borderStyle=solid}
> Manifest-Version: 1.0
> Implementation-Title: webapp
> Implementation-Version: 0.0.1
> Created-By: Gradle 1.0-milestone-6
> Build-Jdk: 1.6.0_26
> {code}
> I've tried to use the PropertiesConfiguration to parse this file, assuming that the ' ' delimiter would be used to divide key-value pairs. Instead I get the following error:
> {code}
> java.lang.IllegalArgumentException: Key for add operation must be defined!
> 	at org.apache.commons.configuration.tree.DefaultExpressionEngine.prepareAdd(DefaultExpressionEngine.java:420)
> 	at org.apache.commons.configuration.HierarchicalConfiguration.addPropertyDirect(HierarchicalConfiguration.java:383)
> 	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.addPropertyDirect(AbstractHierarchicalFileConfiguration.java:147)
> 	at org.apache.commons.configuration.AbstractConfiguration.addPropertyValues(AbstractConfiguration.java:423)
> 	at org.apache.commons.configuration.AbstractConfiguration.append(AbstractConfiguration.java:1271)
> {code}
> At the moment I've created a (very rough) custom PropertiesReader as suggested by the User Guide for handling "unconventional formats".
> {code}
> private static class ManifestPropertiesReader
>             extends PropertiesConfiguration.PropertiesReader {
>     public ManifestPropertiesReader(final Reader in, final char delimiter) {
>         super(in, delimiter);
>     }
>     @Override
>     protected void parseProperty(final String line) {
>         final int pos = line.indexOf(':');
>         final String key = line.substring(0, pos).trim();
>         final String value = line.substring(pos + 1).trim();
>         initPropertyName(key);
>         initPropertyValue(value);
>     }
> }
> {code}
> And:
> {code}
> private static class ManifestIOFactory
>         extends PropertiesConfiguration.DefaultIOFactory {
>     /** Use a custom {@code PropertiesReader} for Manifest files. */
>     @Override
>     public PropertiesReader createPropertiesReader(final Reader in,
>             final char delimiter) {
>         return new ManifestPropertiesReader(in, delimiter);
>     }
> }
> {code}
> Should all this be necessary to parse MANIFEST.MF files or have I missed something?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira