Bug 355613 - Default target is selected when invalid targets are passed
diff --git a/ant/org.eclipse.ant.core/META-INF/MANIFEST.MF b/ant/org.eclipse.ant.core/META-INF/MANIFEST.MF
index b25056d..555784b 100644
--- a/ant/org.eclipse.ant.core/META-INF/MANIFEST.MF
+++ b/ant/org.eclipse.ant.core/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.ant.core; singleton:=true
-Bundle-Version: 3.2.300.qualifier
+Bundle-Version: 3.2.301.qualifier
 Bundle-Activator: org.eclipse.ant.core.AntCorePlugin
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin
diff --git a/ant/org.eclipse.ant.core/src_ant/org/eclipse/ant/internal/core/ant/InternalAntMessages.java b/ant/org.eclipse.ant.core/src_ant/org/eclipse/ant/internal/core/ant/InternalAntMessages.java
index e504e48..d39584c 100644
--- a/ant/org.eclipse.ant.core/src_ant/org/eclipse/ant/internal/core/ant/InternalAntMessages.java
+++ b/ant/org.eclipse.ant.core/src_ant/org/eclipse/ant/internal/core/ant/InternalAntMessages.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- *  Copyright (c) 2000, 2009 IBM Corporation and others.
+ *  Copyright (c) 2000, 2011 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
@@ -55,6 +55,8 @@
 	public static String InternalAntRunner_157;
 
 	public static String InternalAntRunner_unknown_target;
+
+	public static String InternalAntRunner_no_known_target;
 	
 	public static String ProgressBuildListener_Build_cancelled;
 
diff --git a/ant/org.eclipse.ant.core/src_ant/org/eclipse/ant/internal/core/ant/InternalAntMessages.properties b/ant/org.eclipse.ant.core/src_ant/org/eclipse/ant/internal/core/ant/InternalAntMessages.properties
index 70b885d..26a0b80 100644
--- a/ant/org.eclipse.ant.core/src_ant/org/eclipse/ant/internal/core/ant/InternalAntMessages.properties
+++ b/ant/org.eclipse.ant.core/src_ant/org/eclipse/ant/internal/core/ant/InternalAntMessages.properties
@@ -1,5 +1,5 @@
 ###############################################################################
-# Copyright (c) 2000, 2009 IBM Corporation and others.
+# Copyright (c) 2000, 2011 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
@@ -46,5 +46,6 @@
 InternalAntRunner_Missing_Class=Could not load a class required for parsing targets
 InternalAntRunner_157=-lib not supported\nConfigure the Ant runtime classpath using either the\nglobal Ant runtime classpath or the Ant runtime classpath\n for this particular build
 InternalAntRunner_unknown_target=Unknown target: {0}
+InternalAntRunner_no_known_target=No known target specified.
 ProgressBuildListener_Build_cancelled=Build cancelled.
 InternalProject_could_not_create_type=Could not create type {0} due to {1}
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 752c21a..d3c76d4 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
@@ -151,6 +151,8 @@
     private boolean allowInput = true;
     
     private String fEarlyErrorMessage= null;
+
+	private boolean unknownTargetsFound = false;
     
 	/**
 	 * Adds a build listener.
@@ -1117,6 +1119,12 @@
 			processTargets(commands);
 		}
 		
+		if (unknownTargetsFound && (targets == null  || targets.isEmpty())) {
+			// Some targets are specified but none of them are good. Hence quit
+			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=352536
+			logMessage(currentProject, InternalAntMessages.InternalAntRunner_no_known_target, Project.MSG_ERR);
+			return false;
+		}
 		return true;
 	}
 	
@@ -1135,7 +1143,8 @@
 			if (!names.contains(target)) {
 				iterator.remove();
 				String message = MessageFormat.format(InternalAntMessages.InternalAntRunner_unknown_target, new Object[]{target});
-				logMessage(currentProject, message, Project.MSG_WARN); 
+				logMessage(currentProject, message, Project.MSG_WARN);
+				unknownTargetsFound = true;
 			}
 		}
 	}
diff --git a/ant/org.eclipse.ant.tests.core/META-INF/MANIFEST.MF b/ant/org.eclipse.ant.tests.core/META-INF/MANIFEST.MF
index 0478fb3..5a549fa 100644
--- a/ant/org.eclipse.ant.tests.core/META-INF/MANIFEST.MF
+++ b/ant/org.eclipse.ant.tests.core/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.ant.tests.core; singleton:=true
-Bundle-Version: 3.2.200.qualifier
+Bundle-Version: 3.2.201.qualifier
 Bundle-ClassPath: anttestscore.jar
 Bundle-Activator: org.eclipse.ant.tests.core.testplugin.AntTestPlugin
 Bundle-Vendor: %providerName
diff --git a/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/OptionTests.java b/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/OptionTests.java
index 508c7de..a7f013d 100644
--- a/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/OptionTests.java
+++ b/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/OptionTests.java
@@ -290,13 +290,26 @@
 	/**
 	 * Tests specifying a target at the command line that does not exist.
 	 * 
-	 * @since 3.6  this will no longer fail - the default target will be run instead
+	 * @since 3.6  this will not fail - the default target will be run instead
+	 * @since 3.7.1  this will fail as there are no more known targets
 	 */
 	public void testSpecifyBadTargetAsArg() throws CoreException {
 		run("TestForEcho.xml", new String[]{"echo2"}, false);
+		assertTrue("Should be an unknown target message", AntTestChecker.getDefault().getLoggedMessage(1).indexOf("Unknown target") >= 0);
+		assertTrue("Should be an unknown target message", AntTestChecker.getDefault().getLoggedMessage(1).indexOf("echo2") >= 0);
+		assertTrue("Should be a no known target message", AntTestChecker.getDefault().getLoggedMessage(0).indexOf("No known target specified.") >= 0);
+		assertEquals("Should not have run any targets", 0, AntTestChecker.getDefault().getTargetsStartedCount());
+	}
+	
+	/**
+	 * Tests specifying both a non-existent target and an existent target in the command line 
+	 * 
+	 */
+	public void testSpecifyBothBadAndGoodTargetsAsArg() throws CoreException {
+		run("TestForEcho.xml", new String[]{"echo2", "Test for Echo"}, false);
 		assertTrue("Should be an unknown target message", AntTestChecker.getDefault().getLoggedMessage(5).indexOf("Unknown target") >= 0);
 		assertTrue("Should be an unknown target message", AntTestChecker.getDefault().getLoggedMessage(5).indexOf("echo2") >= 0);
-		assertEquals("Should have run the default target & dependents", 5, AntTestChecker.getDefault().getTargetsStartedCount());
+		assertEquals("Should have run the Test for Echo target", 5, AntTestChecker.getDefault().getTargetsStartedCount());
 	}
 	
 	/**