ant-ivy-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rob Gordon" <...@rgordon.co.uk>
Subject Settings include optional not working with absolute file paths
Date Mon, 09 Nov 2015 19:43:28 GMT
Hi, I’m trying to allow a user defined settings file to override the default 
one if it exists

<include file="${ivy.default.ivy.user.dir}/ivysettings.xml"
        optional="true" />

But I'm getting:

Caused by: java.io.FileNotFoundException: C:\Users\rob\.ivy2\ivysettings.xml
    at 
org.apache.ivy.core.settings.XmlSettingsParser.urlFromFileAttribute(XmlSettingsParser.java:457)
    at 
org.apache.ivy.core.settings.XmlSettingsParser.includeStarted(XmlSettingsParser.java:415)
    at 
org.apache.ivy.core.settings.XmlSettingsParser.startElement(XmlSettingsParser.java:211)
    ... 39 more

I think the problem is in the XmlSettingsParser urlFromFileAttrubte method 
in that it does a file exists check for absolute files:

if (incFile.isAbsolute()) {
    if (!incFile.exists()) {
        throw new FileNotFoundException(incFile.getAbsolutePath());
    }


but this happens before the optional check in the calling code:

settingsURL = urlFromFileAttribute(propFilePath);
Message.verbose("including file: " + settingsURL);
if ("file".equals(settingsURL.getProtocol())) {
    try {
        File settingsFile = new File(new URI(settingsURL.toExternalForm()));
        String optional = (String) attributes.get("optional");
        if ("true".equals(optional) && !settingsFile.exists()) {
            return;
        }

So I'm guessing this is a bug...

Please can you advise a workaround, or is there an alternative recommended 
way for having an optional user settings file?

Many thanks,
Rob




Mime
View raw message