Bug 294502 - Handling of unknown arguments/targets
diff --git a/ant/org.eclipse.ant.core/src_ant/org/eclipse/ant/internal/core/ant/InternalAntRunner.java b/ant/org.eclipse.ant.core/src_ant/org/eclipse/ant/internal/core/ant/InternalAntRunner.java
index 73d21ec..4b69c48 100644
--- a/ant/org.eclipse.ant.core/src_ant/org/eclipse/ant/internal/core/ant/InternalAntRunner.java
+++ b/ant/org.eclipse.ant.core/src_ant/org/eclipse/ant/internal/core/ant/InternalAntRunner.java
@@ -24,13 +24,11 @@
import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Properties;
-import java.util.Set;
import java.util.Vector;
import org.apache.tools.ant.AntTypeDefinition;
@@ -426,6 +424,45 @@
processAntHome(true);
}
}
+
+ /**
+ * Returns a list of target names in the build script.
+ *
+ * @return a list of target names
+ */
+ private List getTargetNames() {
+ try {
+ setJavaClassPath();
+ Project antProject;
+
+ antProject = getProject();
+ processAntHome(false);
+ antProject.init();
+ setTypes(antProject);
+ processProperties(AntCoreUtil.getArrayList(extraArguments));
+
+ setProperties(antProject, false);
+ if (isVersionCompatible("1.5")) { //$NON-NLS-1$
+ new InputHandlerSetter().setInputHandler(antProject, "org.eclipse.ant.internal.core.ant.NullInputHandler"); //$NON-NLS-1$
+ }
+ parseBuildFile(antProject);
+ Enumeration projectTargets = antProject.getTargets().elements();
+ List names = new ArrayList();
+ Target target;
+ while (projectTargets.hasMoreElements()) {
+ target = (Target) projectTargets.nextElement();
+ String name= target.getName();
+ if (name.length() == 0) {
+ //"no name" implicit target of Ant 1.6
+ continue;
+ }
+ names.add(name);
+ }
+ return names;
+ } finally {
+ processAntHome(true);
+ }
+ }
private Project getProject() {
Project antProject;
@@ -1089,18 +1126,7 @@
* @since 3.6
*/
private void processUnrecognizedTargets(List commands) {
- List list = getTargets();
- Set names = new HashSet();
- Iterator it = list.iterator();
- while (it.hasNext()) {
- Object element = it.next();
- if (element instanceof List) {
- List target = (List)element;
- if (!target.isEmpty()) {
- names.add(target.get(0));
- }
- }
- }
+ List names = getTargetNames();
ListIterator iterator = commands.listIterator();
while (iterator.hasNext()) {
diff --git a/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/FrameworkTests.java b/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/FrameworkTests.java
index c395e54..cb4075e 100644
--- a/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/FrameworkTests.java
+++ b/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/FrameworkTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -126,6 +126,17 @@
run("NoDefault.xml");
assertSuccessful();
}
+
+ /**
+ * Regression test for running a specific target from a script that has no default target.
+ * Associated with bug 294502.
+ *
+ * @throws CoreException
+ */
+ public void testSpecificTargetWithNoDefaultTarget() throws CoreException {
+ run("NoDefault.xml", new String[]{"test"});
+ assertSuccessful();
+ }
/**
* Ensures that tasks like javac work when includeAntRuntime is specified