--- C:\download\ivy\ivy-1.4.1-src\ivy-1.4.1\src\java\fr\jayasoft\ivy\xml\XmlIvyConfigurationParser.java 2006-11-09 16:52:40.000000000 +-1000 +++ C:\development\uncontrolled\ivy-1.4.1\src\java\fr\jayasoft\ivy\xml\XmlIvyConfigurationParser.java 2007-07-12 15:44:00.000000000 +-1000 @@ -1,16 +1,19 @@ /* * This file is subject to the license found in LICENCE.TXT in the root directory of the project. - * + * * #SNAPSHOT# */ package fr.jayasoft.ivy.xml; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.text.ParseException; import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -46,29 +49,33 @@ private String _defaultResolver; private String _defaultCM; private String _defaultLatest; private String _defaultCircular; private String _currentConfiguratorTag; + private URL ivyconfUrl; + public XmlIvyConfigurationParser(Ivy ivy) { _ivy = ivy; } public void parse(URL configuration) throws ParseException, IOException { _configurator = new Configurator(); // put every type definition from ivy to configurator Map typeDefs = _ivy.getTypeDefs(); for (Iterator iter = typeDefs.keySet().iterator(); iter.hasNext();) { String name = (String) iter.next(); _configurator.typeDef(name, (Class)typeDefs.get(name)); } - + doParse(configuration); } private void doParse(URL configuration) throws IOException, ParseException { + Message.verbose("Setting ivyconfUrl [configuration="+configuration+"]"); + ivyconfUrl = configuration; InputStream stream = null; try { stream = URLHandlerRegistry.getDefault().openStream(configuration); SAXParserFactory.newInstance().newSAXParser().parse( stream, this); @@ -87,22 +94,22 @@ } } } private void parse(Configurator configurator, URL configuration) throws IOException, ParseException { _configurator = configurator; - doParse(configuration); + doParse(configuration); } public void startElement(String uri, String localName, String qName, Attributes att) throws SAXException { // we first copy attributes in a Map to be able to modify them Map attributes = new HashMap(); for (int i=0; i 0) { + propertiesUrl = new File(propFilePath).toURL(); + Message.debug("properties file is not on a path relative to remote ivyconf [propertiesUrl=" + propertiesUrl + + ", ivyconfUrl=" + ivyconfUrl + "]"); + break; + } + + // try to resolve our properties file relative to a local ivyconf file + + // remove the protocol and convert to our platform + + URI ivyconfUri = ivyconfUrl.toURI().normalize(); + File ivyconfFile = new File(ivyconfUri.getPath()); + + // does our properties file resolve to a file relative to our ivyconf file + + propertiesFile = new File(ivyconfFile.getParentFile(), propertiesPath); + + if(propertiesFile.exists()) { + propertiesUrl = propertiesFile.toURL(); + Message.debug("resolved properties file relative to ivyconf file [propertiesUrl=" + propertiesUrl + "]"); + break; + } + + // use our original properties file path + + propertiesUrl = new File(propFilePath).toURL(); + Message.debug("leaving properties file as is [propertiesUrl=" + propertiesUrl + "]"); + + break; + + } // for + + Message.info("Loading properties from " + propertiesUrl + " (resolved from " + propFilePath + ")"); + + try { + _ivy.loadProperties(propertiesUrl, override == null ? true : Boolean.valueOf(override).booleanValue()); + } + catch(Exception e) { + Message.error("Failed to load properties from " + propertiesUrl); + throw new IllegalArgumentException("Unable to load properties from " + propertiesUrl, e); + } } else if ("include".equals(qName)) { Map variables = new HashMap(_ivy.getVariables()); try { String propFilePath = _ivy.substitute((String)attributes.get("file")); - URL ivyconfURL = null; + URL ivyconfURL = null; if (propFilePath == null) { propFilePath = _ivy.substitute((String)attributes.get("url")); if (propFilePath == null) { Message.error("bad include tag: specify file or url to include"); return; } else { @@ -302,13 +428,13 @@ _currentConfiguratorTag = null; } else { _configurator.endCreateChild(); } } } - + public void endDocument() throws SAXException { if (_defaultResolver != null) { _ivy.setDefaultResolver(_ivy.substitute(_defaultResolver)); } if (_defaultCM != null) { ConflictManager conflictManager = _ivy.getConflictManager(_ivy.substitute(_defaultCM));