Bug 84307 - Need more control on build file error checking
diff --git a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/model/AntModel.java b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/model/AntModel.java
index a418f12..fd2d496 100644
--- a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/model/AntModel.java
+++ b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/model/AntModel.java
@@ -47,6 +47,7 @@
 import org.eclipse.ant.internal.core.AntSecurityManager;
 import org.eclipse.ant.internal.core.IAntCoreConstants;
 import org.eclipse.ant.internal.ui.AntUIPlugin;
+import org.eclipse.ant.internal.ui.AntUtil;
 import org.eclipse.ant.internal.ui.editor.DecayCodeCompletionDataStructuresThread;
 import org.eclipse.ant.internal.ui.editor.outline.AntEditorMarkerUpdater;
 import org.eclipse.ant.internal.ui.editor.utils.ProjectHelper;
@@ -151,6 +152,8 @@
 					AntUIPlugin.getDefault().getPluginPreferences().addPropertyChangeListener(fUIPropertyChangeListener);
 				} else if (property.equals(AntEditorPreferenceConstants.CODEASSIST_USER_DEFINED_TASKS)) {
 					reconcileForPropertyChange(false);
+				} else if (property.equals(AntEditorPreferenceConstants.BUILDFILE_NAMES_TO_IGNORE) || property.equals(AntEditorPreferenceConstants.BUILDFILE_IGNORE_ALL)) {
+					reconcileForPropertyChange(false);
 				}
 			}
 		};
@@ -487,7 +490,7 @@
 	 * target dependencies exist. 
 	 */
 	private void checkTargets() {
-		if (fProjectNode == null) {
+		if (fProjectNode == null || doNotReportProblems()) {
 			return;
 		}
 		String defaultTargetName= fProjectNode.getDefaultTargetName();
@@ -531,7 +534,28 @@
         }
     }
 
-    private void checkCircularDependencies(AntElementNode node) {
+    private boolean doNotReportProblems() {
+		if (AntUIPlugin.getDefault().getCombinedPreferenceStore().getBoolean(AntEditorPreferenceConstants.BUILDFILE_IGNORE_ALL)) {
+			return true;
+		}
+		String buildFileNames= AntUIPlugin.getDefault().getCombinedPreferenceStore().getString(AntEditorPreferenceConstants.BUILDFILE_NAMES_TO_IGNORE);
+		if (buildFileNames.length() == 0) {
+			//the user has not specified any names to not report problems for
+			return false;
+		}
+		String[] names= AntUtil.parseString(buildFileNames, ","); //$NON-NLS-1$
+		for (int i = 0; i < names.length; i++) {
+			String string = names[i];
+			File editedFile= getEditedFile();
+			if (string.equals(editedFile.getName())) {
+				return true;
+			}
+		}
+		
+		return false;
+	}
+
+	private void checkCircularDependencies(AntElementNode node) {
         Target target= ((AntTargetNode)node).getTarget();
         String name= target.getName();
         if (name == null) {
@@ -980,7 +1004,7 @@
 		}
 	}
 	
-	public void acceptProblem(IProblem problem) {
+	private void acceptProblem(IProblem problem) {
 		if (fProblemRequestor != null) {
 			fProblemRequestor.acceptProblem(problem);
 		}
@@ -1028,6 +1052,9 @@
 	}
 
 	private void notifyProblemRequestor(Exception exception, AntElementNode element, int severity) {
+		if (doNotReportProblems()) {
+			return;
+		}
 		AntElementNode importNode= element.getImportNode();
 		if (importNode != null) {
 			element= importNode;
@@ -1038,6 +1065,9 @@
 	}
 	
 	private void notifyProblemRequestor(Exception exception, int offset, int length, int severity) {
+		if (doNotReportProblems()) {
+			return;
+		}
 		if (fProblemRequestor != null) {
 			IProblem problem= createProblem(exception, offset, length, severity);
 			acceptProblem(problem);
@@ -1072,6 +1102,9 @@
 			return;
 		}
 		computeEndLocationForErrorNode(node, start, count);
+		if (doNotReportProblems()) {
+			return;
+		}
 		notifyProblemRequestor(exception, start, count, AntModelProblem.SEVERITY_ERROR);
 		markHierarchy(fLastNode, AntModelProblem.SEVERITY_ERROR, exception.getMessage());
 	} 
@@ -1088,6 +1121,9 @@
 			}
 		}
 		computeEndLocationForErrorNode(node, lineNumber, column);
+		if (doNotReportProblems()) {
+			return;
+		}
 		notifyProblemRequestor(exception, node, AntModelProblem.SEVERITY_ERROR);
 		markHierarchy(node, AntModelProblem.SEVERITY_ERROR, exception.getMessage());
 	}
@@ -1518,6 +1554,9 @@
     	fIsDirty= true;
     	reconcile();
     	AntModelCore.getDefault().notifyAntModelListeners(new AntModelChangeEvent(this, true));
+		if (doNotReportProblems()) {
+			return;
+		}
     	fMarkerUpdater.updateMarkers();
     }
 
diff --git a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntEditorPreferenceConstants.java b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntEditorPreferenceConstants.java
index 2547ebb..a21acbc 100644
--- a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntEditorPreferenceConstants.java
+++ b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntEditorPreferenceConstants.java
@@ -64,7 +64,7 @@
 	 * </p>
 	 * @since 3.0
 	 */
-	public final static String CODEASSIST_USER_DEFINED_TASKS= "content_assist_userDefinedTasks"; //$NON-NLS-1$	
+	public final static String CODEASSIST_USER_DEFINED_TASKS= "content_assist_userDefinedTasks"; //$NON-NLS-1$
 	
 	/**
 	 * The symbolic names for colors for displaying code assist proposals
@@ -187,6 +187,26 @@
 	public static final String BUILDFILE_IGNORE = "ignore"; //$NON-NLS-1$
 	
 	/**
+	 * A named preference that controls whether problem reporting is enabled in the Ant editor.
+	 * <p>
+	 * Value is of type <code>Boolean</code>.
+	 * </p>
+	 * 
+	 * @since 3.1
+	 */
+	public static String BUILDFILE_IGNORE_ALL = "ignoreAll"; //$NON-NLS-1$
+	
+	/**
+	 * A named preference that lists the names of buildfiles to not do problem reporting for
+	 * <p>
+	 * Value is of type <code>String</code>.
+	 * </p>
+	 * 
+	 * @since 3.1
+	 */
+	public static String BUILDFILE_NAMES_TO_IGNORE = "ignoreNames"; //$NON-NLS-1$
+	
+	/**
 	 * A named preference that controls whether folding is enabled in the Ant editor.
 	 * <p>
 	 * Value is of type <code>Boolean</code>.
@@ -307,5 +327,6 @@
 		store.setDefault(EDITOR_MARK_OCCURRENCES, false);
 		store.setDefault(EDITOR_STICKY_OCCURRENCES, true);
 		
+		store.setDefault(BUILDFILE_IGNORE_ALL, false);
 	}
 }
diff --git a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntEditorPreferencePage.java b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntEditorPreferencePage.java
index c6a76dd..8c71987 100644
--- a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntEditorPreferencePage.java
+++ b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntEditorPreferencePage.java
@@ -13,8 +13,11 @@
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
+
 import org.eclipse.ant.internal.ui.AntSourceViewerConfiguration;
+import org.eclipse.ant.internal.ui.AntUIPlugin;
 import org.eclipse.ant.internal.ui.IAntUIHelpContextIds;
 import org.eclipse.ant.internal.ui.editor.text.AntDocumentSetupParticipant;
 import org.eclipse.ant.internal.ui.editor.text.IAntEditorColorConstants;
@@ -50,6 +53,7 @@
 import org.eclipse.swt.widgets.Link;
 import org.eclipse.swt.widgets.TabFolder;
 import org.eclipse.swt.widgets.TabItem;
+import org.eclipse.swt.widgets.Text;
 import org.eclipse.swt.widgets.Widget;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.dialogs.PreferencesUtil;
@@ -245,7 +249,17 @@
 	
 	private SelectionListener fSelectionListener;
 	protected Map fWorkingValues;
-	protected ArrayList fComboBoxes;
+	protected List fComboBoxes;
+	private List fProblemLabels;
+
+	private Button fIgnoreAllProblems;
+
+	private Text fBuildFilesToIgnoreProblems;
+	private Label fBuildFilesToIgnoreProblemsLabel;
+
+	private Label fSeverityLabel;
+
+	private Label fBuildFilesToIgnoreProblemsDescription;
 	
 	public AntEditorPreferencePage() {
 		super();
@@ -283,6 +297,10 @@
 		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.EDITOR_MARK_OCCURRENCES));
 		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.EDITOR_STICKY_OCCURRENCES));
 		
+		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.BUILDFILE_IGNORE_ALL));
+		
+		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AntEditorPreferenceConstants.BUILDFILE_NAMES_TO_IGNORE));
+		
 		for (int i= 0; i < fSyntaxColorListModel.length; i++) {
 			String colorKey= fSyntaxColorListModel[i][1];
 			addTextKeyToCover(overlayKeys, colorKey);
@@ -561,6 +579,7 @@
 	
 	private Composite createProblemsTabContent(TabFolder folder) {
 		fComboBoxes= new ArrayList();
+		fProblemLabels= new ArrayList();
 		initializeWorkingValues();
 		
 		String[] errorWarningIgnoreLabels= new String[] {
@@ -578,11 +597,26 @@
 		Composite othersComposite= new Composite(folder, SWT.NULL);
 		othersComposite.setLayout(layout);
 		
-		Label description= new Label(othersComposite, SWT.WRAP);
-		description.setText(AntPreferencesMessages.getString("AntEditorPreferencePage.14")); //$NON-NLS-1$
+		String labelText= AntPreferencesMessages.getString("AntEditorPreferencePage.28"); //$NON-NLS-1$
+		fIgnoreAllProblems= addCheckBox(othersComposite, labelText, AntEditorPreferenceConstants.BUILDFILE_IGNORE_ALL, 0);
+		
+		fIgnoreAllProblems.addSelectionListener(getSelectionListener());
+		
+		fBuildFilesToIgnoreProblemsDescription = new Label(othersComposite, SWT.WRAP);
+		fBuildFilesToIgnoreProblemsDescription.setText(AntPreferencesMessages.getString("AntEditorPreferencePage.29")); //$NON-NLS-1$
 		GridData gd= new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
 		gd.horizontalSpan= nColumns;
-		description.setLayoutData(gd);
+		fBuildFilesToIgnoreProblemsDescription.setLayoutData(gd);
+		
+		Control[] controls= addLabelledTextField(othersComposite, AntPreferencesMessages.getString("AntEditorPreferencePage.30"), AntEditorPreferenceConstants.BUILDFILE_NAMES_TO_IGNORE, 50, 0, null); //$NON-NLS-1$
+		fBuildFilesToIgnoreProblems= getTextControl(controls); 
+		fBuildFilesToIgnoreProblemsLabel= getLabelControl(controls);
+		
+		fSeverityLabel= new Label(othersComposite, SWT.WRAP);
+		fSeverityLabel.setText(AntPreferencesMessages.getString("AntEditorPreferencePage.14")); //$NON-NLS-1$
+		gd= new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
+		gd.horizontalSpan= nColumns;
+		fSeverityLabel.setLayoutData(gd);
 				
 		String label= AntPreferencesMessages.getString("AntEditorPreferencePage.18"); //$NON-NLS-1$
 		addComboBox(othersComposite, label, AntEditorPreferenceConstants.PROBLEM_TASKS, errorWarningIgnore, errorWarningIgnoreLabels, 0);
@@ -599,6 +633,7 @@
         label= AntPreferencesMessages.getString("AntEditorPreferencePage.27"); //$NON-NLS-1$
         addComboBox(othersComposite, label, AntEditorPreferenceConstants.PROBLEM_SECURITY, errorWarningIgnore, errorWarningIgnoreLabels, 0);
 		
+		updateControlsForProblemReporting(!AntUIPlugin.getDefault().getCombinedPreferenceStore().getBoolean(AntEditorPreferenceConstants.BUILDFILE_IGNORE_ALL));
 		return othersComposite;
 	}
 	
@@ -641,6 +676,7 @@
 		String currValue= (String)fWorkingValues.get(key);	
 		comboBox.select(data.getSelection(currValue));
 		
+		fProblemLabels.add(labelControl);
 		fComboBoxes.add(comboBox);
 		return comboBox;
 	}
@@ -662,6 +698,10 @@
 		ControlData data= (ControlData) widget.getData();
 		String newValue= null;
 		if (widget instanceof Button) {
+			if (widget == fIgnoreAllProblems) {
+				updateControlsForProblemReporting(!((Button)widget).getSelection());
+				return;
+			}
 			newValue= data.getValue(((Button)widget).getSelection());			
 		} else if (widget instanceof Combo) {
 			newValue= data.getValue(((Combo)widget).getSelectionIndex());
@@ -671,6 +711,17 @@
 		fWorkingValues.put(data.getKey(), newValue);
 	}
 	
+	private void updateControlsForProblemReporting(boolean reportProblems) {
+		for (int i= fComboBoxes.size() - 1; i >= 0; i--) {
+			((Control) fComboBoxes.get(i)).setEnabled(reportProblems);
+			((Control) fProblemLabels.get(i)).setEnabled(reportProblems);
+		}
+		fSeverityLabel.setEnabled(reportProblems);
+		fBuildFilesToIgnoreProblems.setEnabled(reportProblems);
+		fBuildFilesToIgnoreProblemsDescription.setEnabled(reportProblems);
+		fBuildFilesToIgnoreProblemsLabel.setEnabled(reportProblems);
+	}
+
 	protected void updateControls() {
 		// update the UI
 		for (int i= fComboBoxes.size() - 1; i >= 0; i--) {
diff --git a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntPreferencesMessages.properties b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntPreferencesMessages.properties
index 91a13d8..9a50e01 100644
--- a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntPreferencesMessages.properties
+++ b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntPreferencesMessages.properties
@@ -122,6 +122,7 @@
 AntEditorPreferencePage.Ant_editor_tags_4=Tags
 AntEditorPreferencePage.Ant_editor_comments_5=Comments
 AntEditorPreferencePage.32=&Show affordance in hover on how to make it sticky
+AntEditorPreferencePage.30=Na&mes:
 AntEditorPreferencePage.40=&Insert spaces for tabs when typing
 AntEditorPreferencePage.1=Synta&x
 AntEditorPreferencePage.10=&Problems
@@ -131,7 +132,7 @@
 AntEditorPreferencePage.14=Select the severity level for the following buildfile problems:
 AntEditorPreferencePage.15=Incomplete &classpath:
 AntEditorPreferencePage.16=Property &setting tasks:
-AntEditorPreferencePage.17=&Import tasks:
+AntEditorPreferencePage.17=Import tas&ks:
 AntEditorPreferencePage.18=&Task configuration:
 AntEditorPreferencePage.19=&Folding
 AntEditorPreferencePage.20=&Enable folding when opening a new editor
@@ -142,6 +143,8 @@
 AntEditorPreferencePage.25=&Targets
 AntEditorPreferencePage.26=DTD Declarations
 AntEditorPreferencePage.27=Sec&urity Problems
+AntEditorPreferencePage.28=&Ignore all buildfile problems
+AntEditorPreferencePage.29=Set the names of files that will not be checked for problems in the Ant Editor. List is comma separated:
 AntEditorPreferencePage.5=Fore&ground:
 AntEditorPreferencePage.7=&Bold
 AntEditorPreferencePage.8=I&talic