git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@954939 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -78,6 +78,12 @@ Other changes: | |||||
| * You can now specify a list of methods to run in a JUnit test case. | * You can now specify a list of methods to run in a JUnit test case. | ||||
| Bugzilla Report 34748. | Bugzilla Report 34748. | ||||
| * properties in files read because of the -propertyfile command line | |||||
| option will get now resolved against other properties that are | |||||
| defined before the project starts executing (those from the same or | |||||
| other propertfiles or defined via the -D option). | |||||
| Bugzilla Report 18732. | |||||
| Changes from Ant 1.8.0 TO Ant 1.8.1 | Changes from Ant 1.8.0 TO Ant 1.8.1 | ||||
| =================================== | =================================== | ||||
| @@ -37,6 +37,7 @@ import java.util.Vector; | |||||
| import org.apache.tools.ant.input.DefaultInputHandler; | import org.apache.tools.ant.input.DefaultInputHandler; | ||||
| import org.apache.tools.ant.input.InputHandler; | import org.apache.tools.ant.input.InputHandler; | ||||
| import org.apache.tools.ant.launch.AntMain; | import org.apache.tools.ant.launch.AntMain; | ||||
| import org.apache.tools.ant.property.ResolvePropertyMap; | |||||
| import org.apache.tools.ant.util.ClasspathUtils; | import org.apache.tools.ant.util.ClasspathUtils; | ||||
| import org.apache.tools.ant.util.FileUtils; | import org.apache.tools.ant.util.FileUtils; | ||||
| import org.apache.tools.ant.util.ProxySetup; | import org.apache.tools.ant.util.ProxySetup; | ||||
| @@ -762,12 +763,20 @@ public class Main implements AntMain { | |||||
| project.init(); | project.init(); | ||||
| // resolve properties | |||||
| PropertyHelper propertyHelper | |||||
| = (PropertyHelper) PropertyHelper.getPropertyHelper(project); | |||||
| HashMap props = new HashMap(definedProps); | |||||
| new ResolvePropertyMap(project, propertyHelper, | |||||
| propertyHelper.getExpanders()) | |||||
| .resolveAllProperties(props, null); | |||||
| // set user-define properties | // set user-define properties | ||||
| Enumeration e = definedProps.keys(); | |||||
| while (e.hasMoreElements()) { | |||||
| String arg = (String) e.nextElement(); | |||||
| String value = (String) definedProps.get(arg); | |||||
| project.setUserProperty(arg, value); | |||||
| for (Iterator e = props.entrySet().iterator(); e.hasNext(); ) { | |||||
| Map.Entry ent = (Map.Entry) e.next(); | |||||
| String arg = (String) ent.getKey(); | |||||
| Object value = ent.getValue(); | |||||
| project.setUserProperty(arg, String.valueOf(value)); | |||||
| } | } | ||||
| project.setUserProperty(MagicNames.ANT_FILE, | project.setUserProperty(MagicNames.ANT_FILE, | ||||
| @@ -0,0 +1,62 @@ | |||||
| /* | |||||
| * Licensed to the Apache Software Foundation (ASF) under one or more | |||||
| * contributor license agreements. See the NOTICE file distributed with | |||||
| * this work for additional information regarding copyright ownership. | |||||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | |||||
| * (the "License"); you may not use this file except in compliance with | |||||
| * the License. You may obtain a copy of the License at | |||||
| * | |||||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||||
| * | |||||
| * Unless required by applicable law or agreed to in writing, software | |||||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
| * See the License for the specific language governing permissions and | |||||
| * limitations under the License. | |||||
| * | |||||
| */ | |||||
| package org.apache.tools.ant; | |||||
| import java.io.File; | |||||
| import java.io.FileWriter; | |||||
| import java.io.PrintStream; | |||||
| import junit.framework.TestCase; | |||||
| public class PropertyFileCLITest extends TestCase { | |||||
| public void testPropertyResolution() throws Exception { | |||||
| File props = File.createTempFile("propertyfilecli", ".properties"); | |||||
| props.deleteOnExit(); | |||||
| FileWriter fw = new FileWriter(props); | |||||
| fw.write("w=world\nmessage=Hello, ${w}\n"); | |||||
| fw.close(); | |||||
| File build = File.createTempFile("propertyfilecli", ".xml"); | |||||
| build.deleteOnExit(); | |||||
| fw = new FileWriter(build); | |||||
| fw.write("<project><echo>${message}</echo></project>"); | |||||
| fw.close(); | |||||
| PrintStream sysOut = System.out; | |||||
| StringBuffer sb = new StringBuffer(); | |||||
| try { | |||||
| PrintStream out = | |||||
| new PrintStream(new BuildFileTest.AntOutputStream(sb)); | |||||
| System.setOut(out); | |||||
| Main m = new NoExitMain(); | |||||
| m.startAnt(new String[] { | |||||
| "-propertyfile", props.getAbsolutePath(), | |||||
| "-f", build.getAbsolutePath() | |||||
| }, null, null); | |||||
| } finally { | |||||
| System.setOut(sysOut); | |||||
| } | |||||
| String log = sb.toString(); | |||||
| assertTrue("expected log to contain 'Hello, world' but was " + log, | |||||
| log.indexOf("Hello, world") > -1); | |||||
| } | |||||
| private static class NoExitMain extends Main { | |||||
| protected void exit(int exitCode) { | |||||
| } | |||||
| } | |||||
| } | |||||