Bug 125367 - [patch] An ant script without targets or default target is not recognized as an ant file
diff --git a/ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/contentDescriber/AntBuildfileContentDescriber.java b/ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/contentDescriber/AntBuildfileContentDescriber.java
index 5dca53e..ab86daf 100644
--- a/ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/contentDescriber/AntBuildfileContentDescriber.java
+++ b/ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/contentDescriber/AntBuildfileContentDescriber.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2005 IBM Corporation and others.
+ * Copyright (c) 2004, 2006 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
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Philippe Ombredanne (pombredanne@nexb.com) - bug 125367
*******************************************************************************/
package org.eclipse.ant.internal.core.contentDescriber;
@@ -25,12 +26,13 @@
import org.xml.sax.SAXException;
/**
- * A content describer for detecting the name of the top-level project element.
+ * A content describer for Ant buildfiles.
* <p>
* If project top level element is found
* then if:
- * target subelements are found returns VALID
+ * target sub-elements are found returns VALID
* default attribute is found returns VALID
+ * some other likely Ant element is found (classpath, import, macrodef, path, property, taskdef, typedef) returns VALID
* else:
* returns INDETERMINATE
* else
@@ -68,8 +70,9 @@
}
// Check to see if we matched our criteria.
if (antHandler.hasRootProjectElement()) {
- if (antHandler.hasProjectDefaultAttribute() || antHandler.hasTargetElement()) {
- //project and default attribute or project and target element(s)
+ if (antHandler.hasProjectDefaultAttribute() || antHandler.hasTargetElement() || antHandler.hasAntElement()) {
+ //project and default attribute or project and target element(s)
+ //or project and top level ant element(s) (classpath, import, macrodef, path, property, taskdef, typedef)
return VALID;
}
//only a top level project element...maybe an Ant buildfile
diff --git a/ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/contentDescriber/AntHandler.java b/ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/contentDescriber/AntHandler.java
index 5615e2d..22d5b4b 100644
--- a/ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/contentDescriber/AntHandler.java
+++ b/ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/contentDescriber/AntHandler.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2005 IBM Corporation and others.
+ * Copyright (c) 2004, 2006 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
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Philippe Ombredanne (pombredanne@nexb.com) - bug 125367
*******************************************************************************/
package org.eclipse.ant.internal.core.contentDescriber;
@@ -28,7 +29,8 @@
/**
* An xml event handler for detecting the project top-level element in an Ant buildfile.
* Also records whether a default attribute is present for the project and if any target
- * elements are present.
+ * or some other typical ant elements are present. There are still cases where we could
+ * ignore a valid ant buildfile though.
*
* @since 3.1
*/
@@ -56,6 +58,13 @@
private static final String DEFAULT_ATTRIBUTE= "default"; //$NON-NLS-1$
private static final String PROJECT = "project"; //$NON-NLS-1$
private static final String TARGET= "target"; //$NON-NLS-1$
+ private static final String MACRODEF= "macrodef"; //$NON-NLS-1$
+ private static final String TASKDEF= "taskdef"; //$NON-NLS-1$
+ private static final String TYPEDEF= "typedef"; //$NON-NLS-1$
+ private static final String PROPERTY= "property"; //$NON-NLS-1$
+ private static final String CLASSPATH= "classpath"; //$NON-NLS-1$
+ private static final String PATH= "path"; //$NON-NLS-1$
+ private static final String IMPORT= "import"; //$NON-NLS-1$
/**
* This is the name of the top-level element found in the XML file. This
@@ -67,7 +76,8 @@
private boolean fDefaultAttributeFound= false;
private boolean fTargetFound = false;
-
+ private boolean fAntElementFound = false;
+
private int fLevel= -1;
/**
@@ -158,8 +168,17 @@
fTargetFound= true;
throw new StopParsingException();
}
+
+ //top level Ant elements
+ if (fLevel == 1 && (MACRODEF.equals(elementName)
+ || TASKDEF.equals(elementName) || TYPEDEF.equals(elementName)
+ || PROPERTY.equals(elementName)|| CLASSPATH.equals(elementName)
+ || PATH.equals(elementName) || IMPORT.equals(elementName))) {
+ fAntElementFound= true;
+ throw new StopParsingException();
+ }
}
-
+
/* (non-Javadoc)
* @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
*/
@@ -177,6 +196,10 @@
}
protected boolean hasTargetElement() {
- return fTargetFound;
- }
+ return fTargetFound;
+ }
+
+ protected boolean hasAntElement() {
+ return fAntElementFound;
+ }
}
\ No newline at end of file