diff --git a/CHANGES.txt b/CHANGES.txt index 57cafba0..08a71419 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -5,6 +5,7 @@ - NEW: it is now possible to reference existing resolver in resolver containers (IVY-35) - NEW: overwrite attribute in the publish task now let force overwrite of read only files (IVY-83) - NEW: add a conflict manager ("strict") making build fail when a diamond conflict is found (thanks to Christer Jonsson) (IVY-118) +- IMPROVE: add possibility to avoid overwrite of an ivy variable when setting them in ivyconf.xml (IVY-127) - IMPROVE: ability to exclude the root project from the buildlist (thanks to Constantine Vetoshev) (IVY-124) - IMPROVE: exclusion of artifacts now works on transitive artifacts, and exclusion can specify organisation and/or module (IVY-116) - IMPROVE: now dynamic revisions replacement by deliver task can be turned off (IVY-120) diff --git a/src/java/fr/jayasoft/ivy/Ivy.java b/src/java/fr/jayasoft/ivy/Ivy.java index 2a501a9d..8d706baf 100644 --- a/src/java/fr/jayasoft/ivy/Ivy.java +++ b/src/java/fr/jayasoft/ivy/Ivy.java @@ -41,11 +41,9 @@ import org.xml.sax.SAXException; import fr.jayasoft.ivy.conflict.LatestConflictManager; import fr.jayasoft.ivy.conflict.NoConflictManager; import fr.jayasoft.ivy.conflict.StrictConflictManager; -import fr.jayasoft.ivy.event.EndDownloadEvent; import fr.jayasoft.ivy.event.IvyEvent; import fr.jayasoft.ivy.event.IvyListener; import fr.jayasoft.ivy.event.PrepareDownloadEvent; -import fr.jayasoft.ivy.event.StartDownloadEvent; import fr.jayasoft.ivy.filter.Filter; import fr.jayasoft.ivy.filter.FilterHelper; import fr.jayasoft.ivy.latest.LatestLexicographicStrategy; @@ -299,19 +297,34 @@ public class Ivy implements TransferListener { } public void loadProperties(URL url) throws IOException { + loadProperties(url, true); + } + public void loadProperties(URL url, boolean overwrite) throws IOException { Properties properties = new Properties(); properties.load(url.openStream()); - addAllVariables(properties); + addAllVariables(properties, overwrite); } public void loadProperties(File file) throws IOException { + loadProperties(file, true); + } + + public void loadProperties(File file, boolean overwrite) throws IOException { Properties properties = new Properties(); properties.load(new FileInputStream(file)); - addAllVariables(properties); + addAllVariables(properties, overwrite); } public void setVariable(String varName, String value) { - Message.debug("setting '"+varName+"' to '"+value+"'"); - _variables.put(varName, substitute(value)); + setVariable(varName, value, true); + } + + public void setVariable(String varName, String value, boolean overwrite) { + if (overwrite || !_variables.containsKey(varName)) { + Message.debug("setting '"+varName+"' to '"+value+"'"); + _variables.put(varName, substitute(value)); + } else { + Message.debug("'"+varName+"' already set: discarding '"+value+"'"); + } } public void addAllVariables(Map variables) { @@ -321,10 +334,8 @@ public class Ivy implements TransferListener { public void addAllVariables(Map variables, boolean overwrite) { for (Iterator iter = variables.keySet().iterator(); iter.hasNext();) { String key = (String)iter.next(); - if (overwrite || !_variables.containsKey(key)) { - String val = (String)variables.get(key); - setVariable(key, val); - } + String val = (String)variables.get(key); + setVariable(key, val, overwrite); } } diff --git a/src/java/fr/jayasoft/ivy/xml/XmlIvyConfigurationParser.java b/src/java/fr/jayasoft/ivy/xml/XmlIvyConfigurationParser.java index e61f08c8..d580257c 100644 --- a/src/java/fr/jayasoft/ivy/xml/XmlIvyConfigurationParser.java +++ b/src/java/fr/jayasoft/ivy/xml/XmlIvyConfigurationParser.java @@ -145,12 +145,13 @@ public class XmlIvyConfigurationParser extends DefaultHandler { _ivy.setVariable(name, value); } else if ("properties".equals(qName)) { String propFilePath = _ivy.substitute((String)attributes.get("file")); + String overwrite = _ivy.substitute((String)attributes.get("overwrite")); try { Message.verbose("loading properties: "+propFilePath); - _ivy.loadProperties(new File(propFilePath)); + _ivy.loadProperties(new File(propFilePath), overwrite == null ? true : Boolean.valueOf(overwrite).booleanValue()); } catch (Exception ex) { Message.verbose("failed to load properties as file: trying as url: "+propFilePath); - _ivy.loadProperties(new URL(propFilePath)); + _ivy.loadProperties(new URL(propFilePath), overwrite == null ? true : Boolean.valueOf(overwrite).booleanValue()); } } else if ("include".equals(qName)) { String propFilePath = _ivy.substitute((String)attributes.get("file"));