Author: bodewig
Date: Tue Jun 15 15:46:16 2010
New Revision: 954939
URL: http://svn.apache.org/viewvc?rev=954939&view=rev
Log:
resolve properties defined via -propertyfile against each other. PR 18732
Added:
ant/core/trunk/src/tests/junit/org/apache/tools/ant/PropertyFileCLITest.java
(with props)
Modified:
ant/core/trunk/WHATSNEW
ant/core/trunk/src/main/org/apache/tools/ant/Main.java
Modified: ant/core/trunk/WHATSNEW
URL:
http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=954939&r1=954938&r2=954939&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Tue Jun 15 15:46:16 2010
@@ -78,6 +78,12 @@ Other changes:
* You can now specify a list of methods to run in a JUnit test case.
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
===================================
Modified: ant/core/trunk/src/main/org/apache/tools/ant/Main.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/Main.java?rev=954939&r1=954938&r2=954939&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/Main.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/Main.java Tue Jun 15 15:46:16
2010
@@ -37,6 +37,7 @@ import java.util.Vector;
import org.apache.tools.ant.input.DefaultInputHandler;
import org.apache.tools.ant.input.InputHandler;
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.FileUtils;
import org.apache.tools.ant.util.ProxySetup;
@@ -762,12 +763,20 @@ public class Main implements AntMain {
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
- 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,
Added:
ant/core/trunk/src/tests/junit/org/apache/tools/ant/PropertyFileCLITest.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/PropertyFileCLITest.java?rev=954939&view=auto
==============================================================================
---
ant/core/trunk/src/tests/junit/org/apache/tools/ant/PropertyFileCLITest.java
(added)
+++
ant/core/trunk/src/tests/junit/org/apache/tools/ant/PropertyFileCLITest.java
Tue Jun 15 15:46:16 2010
@@ -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) {
+ }
+ }
+}
Propchange:
ant/core/trunk/src/tests/junit/org/apache/tools/ant/PropertyFileCLITest.java
------------------------------------------------------------------------------
svn:eol-style = native