Browse Source

Don't fail if the file doesn't exist in <xmlproperty>

PR: 15674
Submitted by:	Nicola Ken Barozzi <nicolaken at apache dot org>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273784 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
c5fa091ce5
2 changed files with 31 additions and 20 deletions
  1. +2
    -0
      WHATSNEW
  2. +29
    -20
      src/main/org/apache/tools/ant/taskdefs/XmlProperty.java

+ 2
- 0
WHATSNEW View File

@@ -161,6 +161,8 @@ Other changes:
works for the code generated by the Sun java compiler. It may not work for works for the code generated by the Sun java compiler. It may not work for
all compilers. all compilers.


* <xmlproperty> will no longer fail if the file to be loaded doesn't exist.

Changes from Ant 1.5.1Beta1 to 1.5.1 Changes from Ant 1.5.1Beta1 to 1.5.1
==================================== ====================================




+ 29
- 20
src/main/org/apache/tools/ant/taskdefs/XmlProperty.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 2002 The Apache Software Foundation. All rights
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -266,32 +266,41 @@ public class XmlProperty extends org.apache.tools.ant.Task {
BufferedInputStream configurationStream = null; BufferedInputStream configurationStream = null;


try { try {
configurationStream =
new BufferedInputStream(new FileInputStream(src));
log("Loading " + src.getAbsolutePath(), Project.MSG_VERBOSE);
if (src.exists()) {


DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
configurationStream =
new BufferedInputStream(new FileInputStream(src));


factory.setValidating(validate);
factory.setNamespaceAware(false);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();


Element topElement = factory.newDocumentBuilder().parse(configurationStream).getDocumentElement();
factory.setValidating(validate);
factory.setNamespaceAware(false);


// Keep a hashtable of attributes added by this task.
// This task is allow to override its own properties
// but not other properties. So we need to keep track
// of which properties we've added.
addedAttributes = new Hashtable();
Element topElement = factory.newDocumentBuilder().parse(configurationStream).getDocumentElement();


if (keepRoot) {
addNodeRecursively(topElement, prefix, null);
} else {
NodeList topChildren = topElement.getChildNodes();
int numChildren = topChildren.getLength();
for (int i = 0; i < numChildren; i++) {
// Keep a hashtable of attributes added by this task.
// This task is allow to override its own properties
// but not other properties. So we need to keep track
// of which properties we've added.
addedAttributes = new Hashtable();

if (keepRoot) {
addNodeRecursively(topElement, prefix, null);
} else {
NodeList topChildren = topElement.getChildNodes();
int numChildren = topChildren.getLength();
for (int i = 0; i < numChildren; i++) {
addNodeRecursively(topChildren.item(i), prefix, null); addNodeRecursively(topChildren.item(i), prefix, null);
}
}
}
}


} else {
log("Unable to find property file: " + src.getAbsolutePath(),
Project.MSG_VERBOSE);
}
} catch (SAXException sxe) { } catch (SAXException sxe) {
// Error generated during parsing // Error generated during parsing
Exception x = sxe; Exception x = sxe;


Loading…
Cancel
Save