peterreilly 2003/09/19 02:36:23
Modified: src/main/org/apache/tools/ant/taskdefs ImportTask.java
src/testcases/org/apache/tools/ant/taskdefs ImportTest.java
Added: src/etc/testcases/taskdefs/import/subdir
importinsequential-inner.xml importinsequential.xml
Log:
Dissallow <import> within targets
remove some commented out code in ImportTask
Revision Changes Path
1.1
ant/src/etc/testcases/taskdefs/import/subdir/importinsequential-inner.xml
Index: importinsequential-inner.xml
===================================================================
<project>
<target name="within-imported">
<property name="foo" value="bar"/>
<path id="baz">
<pathelement location="."/>
</path>
</target>
</project>
1.1
ant/src/etc/testcases/taskdefs/import/subdir/importinsequential.xml
Index: importinsequential.xml
===================================================================
<project>
<sequential>
<import file="importinsequential-inner.xml"/>
</sequential>
</project>
1.16 +7 -27
ant/src/main/org/apache/tools/ant/taskdefs/ImportTask.java
Index: ImportTask.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/ImportTask.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- ImportTask.java 17 Jul 2003 10:39:07 -0000 1.15
+++ ImportTask.java 19 Sep 2003 09:36:22 -0000 1.16
@@ -116,20 +116,20 @@
if (file == null) {
throw new BuildException("import requires file attribute");
}
-
+ if (getOwningTarget() == null
+ || !"".equals(getOwningTarget().getName())) {
+ throw new BuildException("import only allowed as a top-level
task");
+ }
+
ProjectHelper helper =
(ProjectHelper)
getProject().getReference("ant.projectHelper");
Vector importStack = helper.getImportStack();
+
if (importStack.size() == 0) {
// this happens if ant is used with a project
// helper that doesn't set the import.
throw new BuildException("import requires support in
ProjectHelper");
}
-// ProjectHelper2.AntXmlContext context;
-//
context=(ProjectHelper2.AntXmlContext)project.getReference("ant.parsing.context");
-
-// File buildFile=context.buildFile;
-// File buildFileParent=context.buildFileParent;
if (getLocation() == null || getLocation().getFileName() == null) {
throw new BuildException("Unable to get location of import
task");
@@ -137,7 +137,7 @@
File buildFile = new File(getLocation().getFileName());
buildFile = new File(buildFile.getAbsolutePath());
- //System.out.println("Importing from " + currentSource);
+
File buildFileParent = new File(buildFile.getParent());
getProject().log("Importing file " + file + " from "
@@ -164,26 +164,6 @@
+ importedFile + "\n", Project.MSG_WARN);
return;
}
-
-// // Add parent build file to the map to avoid cycles...
-// String parentFilename = getPath(buildFile);
-// if (!context.importedFiles.containsKey(parentFilename)) {
-// context.importedFiles.put(parentFilename, buildFile);
-// }
-//
-// // Make sure we import the file only once
-// String importedFilename = getPath(importedFile);
-// if (context.importedFiles.containsKey(importedFilename)) {
-// project.log("\nSkipped already imported file:\n "+
-// importedFilename+"\n",Project.MSG_WARN);
-// return;
-// } else {
-// context.importedFiles.put(importedFilename, importedFile);
-// }
-
-// context.ignoreProjectTag=true;
-// context.helper.parse(project, importedFile,
-// new ProjectHelper2.RootHandler(context));
helper.parse(getProject(), importedFile);
}
1.6 +18 -1
ant/src/testcases/org/apache/tools/ant/taskdefs/ImportTest.java
Index: ImportTest.java
===================================================================
RCS file:
/home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/ImportTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ImportTest.java 18 Sep 2003 09:02:23 -0000 1.5
+++ ImportTest.java 19 Sep 2003 09:36:22 -0000 1.6
@@ -91,15 +91,32 @@
"Unnamed2.xmlUnnamed1.xmlSkipped already imported file");
}
+ // allow this as imported in targets are only tested when a target is run
public void testImportInTargetNoEffect() {
configureProject("src/etc/testcases/taskdefs/import/subdir/importintarget.xml");
expectPropertyUnset("no-import", "foo");
assertTrue(null == getProject().getReference("baz"));
}
- public void testImportInTargetWithEffect() {
+ // deactivate this test as imports within targets are not allowed
+ public void notTestImportInTargetWithEffect() {
configureProject("src/etc/testcases/taskdefs/import/subdir/importintarget.xml");
expectPropertySet("do-import", "foo", "bar");
+ assertNotNull(getProject().getReference("baz"));
+ }
+
+ public void testImportInTargetNotAllowed() {
+ configureProject(
+ "src/etc/testcases/taskdefs/import/subdir/importintarget.xml");
+ expectBuildExceptionContaining(
+ "do-import", "not a top level task",
+ "import only allowed as a top-level task");
+ }
+
+ public void testImportInSequential() {
+ configureProject(
+
"src/etc/testcases/taskdefs/import/subdir/importinsequential.xml");
+ expectPropertySet("within-imported", "foo", "bar");
assertNotNull(getProject().getReference("baz"));
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]