while fixing 221201 I discovered that the lifecycle methods were not always running at the right times
diff --git a/plugins/org.eclipse.wst.validation/.options b/plugins/org.eclipse.wst.validation/.options
index 3d7608c..a5fb429 100644
--- a/plugins/org.eclipse.wst.validation/.options
+++ b/plugins/org.eclipse.wst.validation/.options
@@ -3,6 +3,9 @@
# Set this to true if you wish performance information to be logged
org.eclipse.wst.validation/timings=false
+# set this to true if you want version 1 validator tracing
+org.eclipse.wst.validation/v1=false
+
# Set this to a file name, if you wish the results to be logged to a file, otherwise
# they will be written to stderr. When logged to a file the results are in a
# CSV (comma separated values) form. When logged to stderr they are in a more
diff --git a/plugins/org.eclipse.wst.validation/META-INF/MANIFEST.MF b/plugins/org.eclipse.wst.validation/META-INF/MANIFEST.MF
index 4cecdbe..d620abc 100644
--- a/plugins/org.eclipse.wst.validation/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.wst.validation/META-INF/MANIFEST.MF
@@ -7,14 +7,14 @@
Bundle-Vendor: %Bundle-Vendor.0
Bundle-Localization: plugin
Export-Package: org.eclipse.wst.validation,
- org.eclipse.wst.validation.internal;x-friends:="org.eclipse.jst.validation.test",
- org.eclipse.wst.validation.internal.core;x-friends:="org.eclipse.jst.validation.test",
+ org.eclipse.wst.validation.internal;x-friends:="org.eclipse.wst.common.tests.validation",
+ org.eclipse.wst.validation.internal.core;x-friends:="org.eclipse.wst.common.tests.validation",
org.eclipse.wst.validation.internal.delegates;x-internal:=true,
org.eclipse.wst.validation.internal.model;x-internal:=true,
- org.eclipse.wst.validation.internal.operations;x-friends:="org.eclipse.jst.validation.test",
- org.eclipse.wst.validation.internal.plugin;x-friends:="org.eclipse.jst.validation.test",
+ org.eclipse.wst.validation.internal.operations;x-friends:="org.eclipse.wst.common.tests.validation",
+ org.eclipse.wst.validation.internal.plugin;x-friends:="org.eclipse.wst.common.tests.validation",
org.eclipse.wst.validation.internal.provisional;x-internal:=true,
- org.eclipse.wst.validation.internal.provisional.core;x-friends:="org.eclipse.jst.validation.test"
+ org.eclipse.wst.validation.internal.provisional.core;x-friends:="org.eclipse.wst.common.tests.validation"
Require-Bundle: org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
org.eclipse.wst.common.frameworks;bundle-version="[1.1.0,1.2.0)",
org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
diff --git a/plugins/org.eclipse.wst.validation/property_files/org/eclipse/wst/validation/internal/messages.properties b/plugins/org.eclipse.wst.validation/property_files/org/eclipse/wst/validation/internal/messages.properties
index dc773d6..12fe826 100644
--- a/plugins/org.eclipse.wst.validation/property_files/org/eclipse/wst/validation/internal/messages.properties
+++ b/plugins/org.eclipse.wst.validation/property_files/org/eclipse/wst/validation/internal/messages.properties
@@ -23,6 +23,7 @@
TypeExclude=exclude
JobName=Validation
+JobNameMonitor=Validation Monitor
JobIndexSave=Index Save
MigrationJobName=Validation Setup
diff --git a/plugins/org.eclipse.wst.validation/validate/org/eclipse/wst/validation/internal/FilterUtil.java b/plugins/org.eclipse.wst.validation/validate/org/eclipse/wst/validation/internal/FilterUtil.java
index 20c63a9..f0b433c 100644
--- a/plugins/org.eclipse.wst.validation/validate/org/eclipse/wst/validation/internal/FilterUtil.java
+++ b/plugins/org.eclipse.wst.validation/validate/org/eclipse/wst/validation/internal/FilterUtil.java
@@ -609,13 +609,13 @@
IResource resource = subdelta.getResource();
if (Tracing.isLogging()) {
- StringBuffer buffer = new StringBuffer("subdelta of "); //$NON-NLS-1$
+ StringBuffer buffer = new StringBuffer("VMDDeltaVisitor: subdelta of "); //$NON-NLS-1$
buffer.append(resource.getName());
- buffer.append(" is "); //$NON-NLS-1$
+ buffer.append(" has resource delta kind: "); //$NON-NLS-1$
buffer.append(subdelta.getKind());
- buffer.append(" resource exists? "); //$NON-NLS-1$
+ buffer.append(" Does the resource exist? "); //$NON-NLS-1$
buffer.append(resource.exists());
- buffer.append(" resource.isPhantom?"); //$NON-NLS-1$
+ buffer.append(" Is it a phantom? "); //$NON-NLS-1$
buffer.append(resource.isPhantom());
Tracing.log(buffer);
}
diff --git a/plugins/org.eclipse.wst.validation/validate/org/eclipse/wst/validation/internal/ValidationRegistryReader.java b/plugins/org.eclipse.wst.validation/validate/org/eclipse/wst/validation/internal/ValidationRegistryReader.java
index 517352b..aae97a4 100644
--- a/plugins/org.eclipse.wst.validation/validate/org/eclipse/wst/validation/internal/ValidationRegistryReader.java
+++ b/plugins/org.eclipse.wst.validation/validate/org/eclipse/wst/validation/internal/ValidationRegistryReader.java
@@ -137,7 +137,7 @@
// projects have been added to the project natures which they don't exclude.
_validators.remove(EXCLUDED_PROJECT);
- if (Tracing.isLogging()) {
+ if (Tracing.isTraceV1()) {
Tracing.log(debug());
}
}
@@ -494,7 +494,7 @@
}
if (validator == null) {
- if (Tracing.isLogging()) {
+ if (Tracing.isTraceV1()) {
Tracing.log(NLS.bind(ValMessages.VbfExcSyntaxNoValNull, validatorClassName));
}
return null;
@@ -739,7 +739,7 @@
if (extensionPoint == null) {
// If this happens it means that someone removed the "validator" extension point
// declaration from our plugin.xml file.
- if (Tracing.isLogging()) {
+ if (Tracing.isTraceV1()) {
String result = MessageFormat.format(ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_EXC_MISSING_VALIDATOR_EP),
new Object[]{ValidationPlugin.PLUGIN_ID + "." + VALIDATOR_EXT_PT_ID}); //$NON-NLS-1$
Tracing.log(result);
@@ -802,7 +802,7 @@
vmds.clear();
int executionMap = 0x0;
try {
- if (Tracing.isLogging()) {
+ if (Tracing.isTraceV1()) {
Tracing.log("IProject is " + String.valueOf(project)); //$NON-NLS-1$
}
if (project == null) {
@@ -852,7 +852,7 @@
} else {
executionMap |= 0x8;
- if (Tracing.isLogging()) {
+ if (Tracing.isTraceV1()) {
Tracing.log(projectNatures.toString());
}
calculateVmdsForNatureAndFacets(vmds, projectNatures,project);
@@ -864,7 +864,7 @@
}
}
} finally {
- if (Tracing.isLogging()) {
+ if (Tracing.isTraceV1()) {
StringBuffer buffer = new StringBuffer();
for (ValidatorMetaData vmd : vmds) {
buffer.append(vmd.getValidatorUniqueName());
@@ -953,13 +953,13 @@
* by the J2EE nature. The AValidator would have to be removed from the set.
*/
private void removeExcludedProjects(IProject project, Set<ValidatorMetaData> vmds) {
- if (Tracing.isLogging()) {
+ if (Tracing.isTraceV1()) {
StringBuffer buffer = new StringBuffer("\nBefore:\n"); //$NON-NLS-1$
for (ValidatorMetaData vmd : vmds) {
buffer.append(vmd.getValidatorUniqueName());
buffer.append("\n"); //$NON-NLS-1$
}
- Tracing.log(buffer.toString());
+ Tracing.log(buffer);
}
String[] projectNatures = null;
@@ -994,7 +994,7 @@
}
}
- if (Tracing.isLogging()) {
+ if (Tracing.isTraceV1()) {
StringBuffer buffer = new StringBuffer("\nAfter:\n"); //$NON-NLS-1$
for (ValidatorMetaData vmd : vmds) {
buffer.append(vmd.getValidatorUniqueName());
@@ -1237,7 +1237,7 @@
vmd.setContentTypeIds(getContentTypeBindings(element));
initializeValidatorCustomMarkers(element, pluginId, vmd);
- if (Tracing.isLogging()) {
+ if (Tracing.isTraceV1()) {
Tracing.log("validator loaded: " + validatorImplName); //$NON-NLS-1$
}
@@ -1306,7 +1306,7 @@
String label = extension.getLabel();
if (label == null || label.equals("")) { //$NON-NLS-1$
- if (Tracing.isLogging()) {
+ if (Tracing.isTraceV1()) {
String[] msgParm = {extension.getUniqueIdentifier()};
String result = MessageFormat.format(ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_EXC_VALIDATORNAME_IS_NULL),
(Object[])msgParm);
diff --git a/plugins/org.eclipse.wst.validation/validate/org/eclipse/wst/validation/internal/ValidatorTypeFilter.java b/plugins/org.eclipse.wst.validation/validate/org/eclipse/wst/validation/internal/ValidatorTypeFilter.java
index 633207a..bdb461c 100644
--- a/plugins/org.eclipse.wst.validation/validate/org/eclipse/wst/validation/internal/ValidatorTypeFilter.java
+++ b/plugins/org.eclipse.wst.validation/validate/org/eclipse/wst/validation/internal/ValidatorTypeFilter.java
@@ -127,7 +127,9 @@
} catch (ClassNotFoundException exc) {
_typeFilterClass = null;
if (Tracing.isLogging()) {
- Tracing.log("The class named " + filter + " cannot be instantiated because it does not exist. Check the spelling of the name, in the validator's plugin.xml contribution, and try restarting eclipse again."); //$NON-NLS-1$ //$NON-NLS-2$
+ Tracing.log("The class named " + filter + //$NON-NLS-1$
+ " cannot be instantiated because it does not exist. Check the spelling of the name, " + //$NON-NLS-1$
+ "in the validator's plugin.xml contribution, and try restarting eclipse again."); //$NON-NLS-1$
}
return;
}
diff --git a/plugins/org.eclipse.wst.validation/validate/org/eclipse/wst/validation/internal/operations/ValidationBuilder.java b/plugins/org.eclipse.wst.validation/validate/org/eclipse/wst/validation/internal/operations/ValidationBuilder.java
index 201ce51..c2db6af 100644
--- a/plugins/org.eclipse.wst.validation/validate/org/eclipse/wst/validation/internal/operations/ValidationBuilder.java
+++ b/plugins/org.eclipse.wst.validation/validate/org/eclipse/wst/validation/internal/operations/ValidationBuilder.java
@@ -41,6 +41,13 @@
* This builder is configured on J2EE IProjects automatically, and can be added to other types of
* projects through the Properties page. It launches validation on the project if the project has
* build validation enabled.
+ * </p>
+ * <p>
+ * This launches a Job for the new V2 validators and also a Job for each of the Job based V1
+ * validators. If there are any "in-line" V1 validations they are done as part of this builder.
+ * Because of all the jobs that this builder spawns, the build will usually be finished long before
+ * all the validation has finished.
+ * </p>
*/
public class ValidationBuilder extends IncrementalProjectBuilder {
public static final int NO_DELTA_CHANGE = -1;
@@ -227,8 +234,7 @@
break;
}
- Job job = new ValBuilderJob(project, delta, kind, ValOperationManager.getDefault().getOperation());
-
+ Job job = new ValBuilderJob(project, delta, kind, ValOperationManager.getDefault().getOperation());
job.schedule();
}
diff --git a/plugins/org.eclipse.wst.validation/validate/org/eclipse/wst/validation/internal/operations/ValidationOperation.java b/plugins/org.eclipse.wst.validation/validate/org/eclipse/wst/validation/internal/operations/ValidationOperation.java
index 22d4286..9f29350 100644
--- a/plugins/org.eclipse.wst.validation/validate/org/eclipse/wst/validation/internal/operations/ValidationOperation.java
+++ b/plugins/org.eclipse.wst.validation/validate/org/eclipse/wst/validation/internal/operations/ValidationOperation.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2001, 2007 IBM Corporation and others.
+ * Copyright (c) 2001, 2008 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
@@ -838,13 +838,13 @@
// Validation will run either if this operation forces regardless
// of need, or if the validator was not run automatically.
// If validation is not about to be run, then don't activate
- // the plugin
+ // the plug-in
try {
delta = getFileDeltas(reporter.getProgressMonitor(), vmd);
boolean willRun = (isForce() || isValidationNecessary(vmd, delta));
- if (Tracing.isLogging()) {
+ if (Tracing.isTraceV1()) {
StringBuffer buffer = new StringBuffer();
- buffer.append("will run? "); //$NON-NLS-1$
+ buffer.append("ValidationOperation: will run? "); //$NON-NLS-1$
buffer.append(willRun);
buffer.append(" "); //$NON-NLS-1$
buffer.append("is force? "); //$NON-NLS-1$
diff --git a/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/ReporterHelper.java b/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/ReporterHelper.java
index 5ddaf17..2a845cf 100644
--- a/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/ReporterHelper.java
+++ b/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/ReporterHelper.java
@@ -3,12 +3,8 @@
import java.util.LinkedList;
import java.util.List;
-import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.wst.validation.internal.ConfigurationConstants;
-import org.eclipse.wst.validation.internal.plugin.ValidationPlugin;
+import org.eclipse.wst.validation.internal.MarkerManager;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
import org.eclipse.wst.validation.internal.provisional.core.IValidator;
@@ -58,26 +54,7 @@
}
public void makeMarkers(){
- for (IMessage message : _list){
- Object target = message.getTargetObject();
- if (target != null){
- if (target instanceof IResource){
- IResource res = (IResource)target;
- try {
- IMarker marker = res.createMarker(ConfigurationConstants.VALIDATION_MARKER);
- marker.setAttribute(IMarker.MESSAGE, message.getText());
- int markerSeverity = IMarker.SEVERITY_INFO;
- int sev = message.getSeverity();
- if ((sev & IMessage.HIGH_SEVERITY) != 0)markerSeverity = IMarker.SEVERITY_ERROR;
- else if ((sev & IMessage.NORMAL_SEVERITY) != 0)markerSeverity = IMarker.SEVERITY_WARNING;
- marker.setAttribute(IMarker.SEVERITY, markerSeverity);
- marker.setAttribute(IMarker.LINE_NUMBER, message.getLineNumber());
- }
- catch (CoreException e){
- ValidationPlugin.getPlugin().handleException(e);
- }
- }
- }
- }
+ MarkerManager.getDefault().makeMarkers(_list);
}
+
}
diff --git a/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/ValidationFramework.java b/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/ValidationFramework.java
index d43c9ac..30465a6 100644
--- a/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/ValidationFramework.java
+++ b/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/ValidationFramework.java
@@ -8,7 +8,6 @@
import java.util.Map;
import java.util.Set;
-import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceVisitor;
@@ -22,9 +21,9 @@
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.wst.validation.internal.DebugConstants;
import org.eclipse.wst.validation.internal.DependencyIndex;
+import org.eclipse.wst.validation.internal.MarkerManager;
import org.eclipse.wst.validation.internal.Misc;
import org.eclipse.wst.validation.internal.PerformanceMonitor;
-import org.eclipse.wst.validation.internal.ValConstants;
import org.eclipse.wst.validation.internal.ValManager;
import org.eclipse.wst.validation.internal.ValOperation;
import org.eclipse.wst.validation.internal.ValidationRunner;
@@ -68,12 +67,7 @@
* @param validatorId the id of validator that created the marker
*/
public void clearMessages(IResource resource, String validatorId) throws CoreException {
- if (resource == null)return;
- IMarker[] markers = resource.findMarkers(ValConstants.ProblemMarker, false, IResource.DEPTH_ZERO);
- for (IMarker marker : markers){
- String id = marker.getAttribute(ValidatorMessage.ValidationId, null);
- if (validatorId.equals(id))marker.delete();
- }
+ MarkerManager.getDefault().clearMarker(resource, validatorId);
}
/**
diff --git a/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/Validator.java b/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/Validator.java
index f509781..8e88222 100644
--- a/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/Validator.java
+++ b/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/Validator.java
@@ -9,7 +9,6 @@
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
@@ -17,7 +16,7 @@
import org.eclipse.core.runtime.Platform;
import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.validation.internal.ConfigurationManager;
-import org.eclipse.wst.validation.internal.ResourceUnavailableError;
+import org.eclipse.wst.validation.internal.MarkerManager;
import org.eclipse.wst.validation.internal.SummaryReporter;
import org.eclipse.wst.validation.internal.ValManager;
import org.eclipse.wst.validation.internal.ValMessages;
@@ -560,8 +559,10 @@
_project = project;
base.setParent(this);
try {
- setDelegatingId(ConfigurationManager.getManager().getConfiguration(project)
- .getDelegateForTarget(getValidatorClassname()));
+ String target = getValidatorClassname();
+ String id = ConfigurationManager.getManager().getConfiguration(project).getDelegateForTarget(target);
+ if (id == null) id = ValidatorDelegatesRegistry.getInstance().getDefaultDelegate(target);
+ setDelegatingId(id);
}
catch (InvocationTargetException e){
ValidationPlugin.getPlugin().handleException(e);
@@ -709,7 +710,6 @@
_name = name;
}
- @SuppressWarnings("unchecked")
@Override
public ValidationResult validate(IResource resource, int kind, ValOperation operation, IProgressMonitor monitor) {
ValidationResult vr = null;
@@ -739,18 +739,9 @@
ValidatorMessage[] msgs = vr.getMessages();
if (sanityTest(msgs.length, resource)){
+ MarkerManager mm = MarkerManager.getDefault();
for (ValidatorMessage m : msgs){
- try {
- IMarker marker = m.getResource().createMarker(m.getType());
- Map map = m.getAttributes();
- if (map.get(ValidatorMessage.ValidationId) == null)
- map.put(ValidatorMessage.ValidationId, getId());
- marker.setAttributes(map);
- }
- catch (CoreException e){
- if (!m.getResource().exists())throw new ResourceUnavailableError(m.getResource());
- ValidationPlugin.getPlugin().handleException(e);
- }
+ mm.createMarker(m, getId());
}
}
else {
diff --git a/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/ValidatorMessage.java b/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/ValidatorMessage.java
index bb73265..faaa9c5 100644
--- a/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/ValidatorMessage.java
+++ b/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/ValidatorMessage.java
@@ -53,7 +53,8 @@
ValidatorMessage msg = new ValidatorMessage();
msg._type = ValConstants.ProblemMarker;
msg._resource = resource;
- msg.setAttribute(IMarker.MESSAGE, ValidationPlugin.getPlugin().isDebugging() ? Tracing.timestampIt(message): message);
+ msg.setAttribute(IMarker.MESSAGE, ValidationPlugin.getPlugin().isDebugging() ?
+ Tracing.timestampIt(message): message);
return msg;
}
diff --git a/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/DebugConstants.java b/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/DebugConstants.java
index 0f68123..6fb6d91 100644
--- a/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/DebugConstants.java
+++ b/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/DebugConstants.java
@@ -10,6 +10,9 @@
/** timings - trace the times of the validators. */
String TraceTimes = ValidationPlugin.PLUGIN_ID+"/timings"; //$NON-NLS-1$
+ /** v1 - trace the v1 validators. */
+ String TraceV1 = ValidationPlugin.PLUGIN_ID+"/v1"; //$NON-NLS-1$
+
/** timings/tracefile - file that stores the trace events */
String TraceTimesFile = ValidationPlugin.PLUGIN_ID+"/timings/tracefile"; //$NON-NLS-1$
diff --git a/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/MarkerManager.java b/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/MarkerManager.java
new file mode 100644
index 0000000..1b01ebb
--- /dev/null
+++ b/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/MarkerManager.java
@@ -0,0 +1,108 @@
+package org.eclipse.wst.validation.internal;
+
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.wst.validation.ValidatorMessage;
+import org.eclipse.wst.validation.internal.plugin.ValidationPlugin;
+import org.eclipse.wst.validation.internal.provisional.core.IMessage;
+
+/**
+ * A central place to manage all of the V2 validation markers.
+ * @author karasiuk
+ *
+ */
+public class MarkerManager {
+
+ private static MarkerManager _me;
+
+ public static MarkerManager getDefault(){
+ if (_me == null)_me = new MarkerManager();
+ return _me;
+ }
+
+ /**
+ * Clear any validation markers that may have been set by this validator.
+ *
+ * @param resource the resource that may have it's markers cleared. It can be null, in which case
+ * the operation is a no-op.
+ * @param validatorId the id of validator that created the marker
+ */
+ public void clearMarker(IResource resource, String validatorId) throws CoreException {
+ if (resource == null)return;
+ IMarker[] markers = resource.findMarkers(ValConstants.ProblemMarker, false, IResource.DEPTH_ZERO);
+ for (IMarker marker : markers){
+ String id = marker.getAttribute(ValidatorMessage.ValidationId, null);
+ if (validatorId.equals(id))marker.delete();
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public void createMarker(ValidatorMessage m, String id){
+ try {
+ IMarker marker = m.getResource().createMarker(m.getType());
+ Map map = m.getAttributes();
+ if (map.get(ValidatorMessage.ValidationId) == null)
+ map.put(ValidatorMessage.ValidationId, id);
+ marker.setAttributes(map);
+ }
+ catch (CoreException e){
+ if (!m.getResource().exists())throw new ResourceUnavailableError(m.getResource());
+ ValidationPlugin.getPlugin().handleException(e);
+ }
+
+ }
+
+ /**
+ * Delete all the markers on this resource that were created before the operation start time.
+ * @param resource
+ * @param operationStartTime
+ */
+ public void deleteMarkers(IResource resource, long operationStartTime){
+ try {
+ IMarker[] markers = resource.findMarkers(ValConstants.ProblemMarker, false, IResource.DEPTH_ZERO);
+ for (IMarker marker : markers){
+ long createTime = marker.getCreationTime();
+// long diff = createTime - operationStartTime;
+ if (createTime < operationStartTime)marker.delete();
+ }
+
+ resource.deleteMarkers(ConfigurationConstants.VALIDATION_MARKER, false, IResource.DEPTH_ZERO);
+ }
+ catch (CoreException e){
+ IProject project = resource.getProject();
+ if (!project.exists() || !project.isOpen())throw new ProjectUnavailableError(project);
+ if (!resource.exists())throw new ResourceUnavailableError(resource);
+ ValidationPlugin.getPlugin().handleException(e);
+ }
+ }
+ public void makeMarkers(List<IMessage> list){
+ for (IMessage message : list){
+ Object target = message.getTargetObject();
+ if (target != null){
+ if (target instanceof IResource){
+ IResource res = (IResource)target;
+ try {
+ IMarker marker = res.createMarker(ConfigurationConstants.VALIDATION_MARKER);
+ marker.setAttribute(IMarker.MESSAGE, message.getText());
+ int markerSeverity = IMarker.SEVERITY_INFO;
+ int sev = message.getSeverity();
+ if ((sev & IMessage.HIGH_SEVERITY) != 0)markerSeverity = IMarker.SEVERITY_ERROR;
+ else if ((sev & IMessage.NORMAL_SEVERITY) != 0)markerSeverity = IMarker.SEVERITY_WARNING;
+ marker.setAttribute(IMarker.SEVERITY, markerSeverity);
+ marker.setAttribute(IMarker.LINE_NUMBER, message.getLineNumber());
+ }
+ catch (CoreException e){
+ ValidationPlugin.getPlugin().handleException(e);
+ }
+ }
+ }
+ }
+ }
+
+
+}
diff --git a/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/Misc.java b/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/Misc.java
index ba13bcc..41dcf77 100644
--- a/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/Misc.java
+++ b/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/Misc.java
@@ -17,7 +17,10 @@
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.osgi.util.NLS;
@@ -91,6 +94,32 @@
return NLS.bind(ValMessages.TimeMin, time/60000);
}
+ /**
+ * Used in debugging so we can see what types of markers there are.
+ * @param resource
+ */
+ public static String listMarkers(IResource resource){
+ StringBuffer b = new StringBuffer(2000);
+ try {
+ IMarker[] markers = resource.findMarkers(null, true, IResource.DEPTH_ZERO);
+ for (IMarker m : markers){
+ Object o = m.getAttribute(IMarker.MESSAGE);
+ if (o != null){
+ b.append(o);
+ }
+ o = m.getAttribute(IMarker.SEVERITY);
+ if (o != null){
+ b.append(", Severity="); //$NON-NLS-1$
+ b.append(o);
+ }
+ b.append("; "); //$NON-NLS-1$
+ }
+ }
+ catch (CoreException e){
+
+ }
+ return b.toString();
+ }
public static void niy(String msg){
if (msg == null)msg = "Sorry, this function is not implemented yet"; //$NON-NLS-1$
diff --git a/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/Tracing.java b/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/Tracing.java
index 6d9b886..e0b993b 100644
--- a/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/Tracing.java
+++ b/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/Tracing.java
@@ -16,6 +16,7 @@
private static DateFormat _df = new SimpleDateFormat("HH:mm:ss.SSSS"); //$NON-NLS-1$
private static boolean _forceLogging;
private static Boolean _traceMatches;
+ private static Boolean _traceV1;
/**
* Are we in logging/debugging mode?
@@ -30,6 +31,13 @@
}
return _traceMatches;
}
+
+ public static boolean isTraceV1(){
+ if (_traceV1 == null){
+ _traceV1 = Misc.debugOptionAsBoolean(DebugConstants.TraceV1);
+ }
+ return _traceV1;
+ }
/**
* Write a line to the console for debugging, if in debugging mode.
diff --git a/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/ValBuilderJob.java b/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/ValBuilderJob.java
index 80e5abf..4577ae8 100644
--- a/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/ValBuilderJob.java
+++ b/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/ValBuilderJob.java
@@ -84,6 +84,7 @@
}
public IStatus runInWorkspace(IProgressMonitor monitor) {
+ Tracing.log("ValBuilderJob Starting"); //$NON-NLS-1$
_monitor = monitor;
try {
@@ -101,6 +102,7 @@
ValidationPlugin.getPlugin().handleException(e);
}
+ Tracing.log("ValBuilderJob Finished"); //$NON-NLS-1$
return Status.OK_STATUS;
}
diff --git a/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/ValManager.java b/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/ValManager.java
index 84e2570..d4e9e59 100644
--- a/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/ValManager.java
+++ b/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/ValManager.java
@@ -389,7 +389,7 @@
public void validate(IProject project, final IResource resource, final int kind, boolean isManual,
boolean isBuild, int buildKind, ValOperation operation, final IProgressMonitor monitor) {
- deleteMarkers(resource);
+ MarkerManager.getDefault().deleteMarkers(resource, operation.getStarted());
IValidatorVisitor visitor = new IValidatorVisitor(){
@@ -404,7 +404,15 @@
IResource[] dependencies = ValidationFramework.getDefault()
.getDependencyIndex().get(validator.getDependencyId(), resource);
if (dependencies != null){
+ MarkerManager mm = MarkerManager.getDefault();
+ String id = validator.getId();
for (IResource resource : dependencies){
+ try {
+ mm.clearMarker(resource, id);
+ }
+ catch (CoreException e){
+ //eat this one
+ }
validate(validator, operation, resource, IResourceDelta.NO_CHANGE, monitor);
operation.addValidated(validator.getId(), resource);
}
@@ -454,7 +462,7 @@
num, System.currentTimeMillis()-time, cpuTime);
pm.add(pc);
}
- if (ValidationPlugin.getPlugin().isDebugging()){
+ if (ValidationPlugin.getPlugin().isDebugging() && !pm.isCollecting()){
String msg = time != 0 ?
NLS.bind(ValMessages.LogValEndTime, new Object[]{validator.getName(),
validator.getId(), resource, Misc.getTimeMS(System.currentTimeMillis()-time)}) :
@@ -467,20 +475,6 @@
}
}
- private void deleteMarkers(IResource resource){
- try {
- resource.deleteMarkers(ValConstants.ProblemMarker, false, IResource.DEPTH_ZERO);
- resource.deleteMarkers(ConfigurationConstants.VALIDATION_MARKER, false, IResource.DEPTH_ZERO);
- }
- catch (CoreException e){
- IProject project = resource.getProject();
- if (!project.exists() || !project.isOpen())throw new ProjectUnavailableError(project);
- if (!resource.exists())throw new ResourceUnavailableError(resource);
- ValidationPlugin.getPlugin().handleException(e);
- }
-
- }
-
/**
* Accept a visitor for all the validators that are enabled for the given project.
*
diff --git a/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/ValMessages.java b/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/ValMessages.java
index 1e7ce98..a8ebcb7 100644
--- a/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/ValMessages.java
+++ b/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/ValMessages.java
@@ -29,6 +29,7 @@
public static String GroupExclude;
public static String JobName;
+ public static String JobNameMonitor;
public static String JobIndexSave;
diff --git a/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/ValOperation.java b/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/ValOperation.java
index e26f7db..5a507d1 100644
--- a/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/ValOperation.java
+++ b/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/ValOperation.java
@@ -33,13 +33,23 @@
private Map<IProject, Set<Validator>> _excludeCache =
Collections.synchronizedMap(new HashMap<IProject, Set<Validator>>(40));
+ /** The time that the operation started. */
+ private long _started = System.currentTimeMillis();
+
+ /**
+ * Are we in a multi project validation? This can be triggered by either clean all or
+ * if auto build is turned off, a build all.
+ */
+ private boolean _multiProject;
+
/**
* Holds all the resources that have been validated as a side-effect of running other validations.
* The key is the validator id and the value is a Set of IResources.
*/
private Map<String, Set<IResource>> _validated = new HashMap<String, Set<IResource>>(20);
- public ValOperation(){}
+ public ValOperation(){
+ }
public ValidationState getState() {
return _state;
@@ -140,5 +150,22 @@
void suspendValidation(IProject project, Validator validator) {
if (project == null)return;
getExcludeSet(project).add(validator);
+ }
+
+ public long getStarted() {
+ return _started;
+ }
+
+ public boolean isMultiProject() {
+ return _multiProject;
+ }
+
+ /**
+ * Are we in a multi project validation? That is, could we be validating several
+ * projects at the same time? This can be triggered by either clean all or
+ * if auto build is turned off, a build all.
+ */
+ public void setMultiProject(boolean multiProject) {
+ _multiProject = multiProject;
}
}
diff --git a/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/ValOperationJob.java b/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/ValOperationJob.java
new file mode 100644
index 0000000..d773bf5
--- /dev/null
+++ b/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/ValOperationJob.java
@@ -0,0 +1,53 @@
+package org.eclipse.wst.validation.internal;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.wst.validation.ValidationFramework;
+import org.eclipse.wst.validation.Validator;
+import org.eclipse.wst.validation.internal.model.IValidatorVisitor;
+
+/**
+ * This is used to signal when the entire validation operation is complete. This needs to be done in a job
+ * because the operation isn't done, until all the validation jobs have finished.
+ * @author karasiuk
+ *
+ */
+public class ValOperationJob extends Job {
+
+ private ValOperation _operation;
+
+ public ValOperationJob(ValOperation operation){
+ super(ValMessages.JobNameMonitor);
+ _operation = operation;
+ }
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ boolean ok = true;
+ try {
+ ValidationFramework.getDefault().join(monitor);
+ }
+ catch (InterruptedException e){
+ ok = false;
+ }
+ finished(monitor);
+ return ok ? Status.OK_STATUS : Status.CANCEL_STATUS;
+ }
+
+ private void finished(IProgressMonitor monitor){
+ IValidatorVisitor visitor = new IValidatorVisitor(){
+
+ public void visit(Validator validator, IProject project, boolean isManual,
+ boolean isBuild, ValOperation operation, IProgressMonitor monitor) {
+
+ validator.validationFinishing(project, operation.getState(), monitor);
+ }
+
+ };
+ ValManager.getDefault().accept(visitor, null, false, true, _operation, monitor);
+ }
+
+}
diff --git a/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/ValOperationManager.java b/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/ValOperationManager.java
index df902ce..cda02b0 100644
--- a/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/ValOperationManager.java
+++ b/plugins/org.eclipse.wst.validation/vf2/org/eclipse/wst/validation/internal/ValOperationManager.java
@@ -20,44 +20,110 @@
*/
public class ValOperationManager implements IResourceChangeListener {
+ /*
+ * I tried various tests to see what sort of change events I would get. This is what I
+ * observed using Eclipse 3.4:
+ *
+ * Auto Build On
+ *
+ * Clean All
+ * - workspace, clean, pre
+ * - workspace, clean post
+ * - workspace, auto, post
+ *
+ * Clean Some
+ * - project1, clean, pre
+ * - project1, clean, post
+ * - project2, clean, pre
+ * - project2, clean, post
+ * - workspace, Auto, post
+ *
+ * Build Working Set - NA
+ * Build Project - NA
+ * Build All - NA
+ *
+ * Ctrl-S
+ * - workspace, auto, pre
+ * - workspace, auto, post
+ *
+ * Auto build Off
+ *
+ * Clean All
+ * - same as (auto build on), but no workspace,auto,post event
+ *
+ * Clean Some
+ * - same as (auto build on), but no workspace,auto,post event
+ *
+ * Build Working Set
+ * - project1, incremental, pre
+ * - project1, incremental, post
+ * - project2, incremental, pre
+ * - project2, incremental, post
+ *
+ * Build Project
+ * - same as above
+ *
+ * Build All
+ * - workspace, incremental, pre
+ * - workspace, incremental, post
+ *
+ * Ctrl-S - NA
+ *
+ * For the case where a subset of the projects are built there is no way to guess whether they are part of the
+ * same operation or not. Eclipse threats them as independent events, and so will the validation framework.
+ *
+ * So for example, if the user selected two projects (p1 and p2) and built them, the framework would call the
+ * validators like this:
+ *
+ * validation starting on null
+ * validation starting on P1
+ * - individual events per resource
+ * validation finished on P1
+ * validation finished on null
+ *
+ * validation starting on null
+ * validation starting on P2
+ * - individual events per resource
+ * validation finished on P2
+ * validation finished on null
+ */
+
private static ValOperationManager _me;
/**
- * This operation is in affect for a build cycle. At the end of the build it is
- * reinitialized.
+ * This operation is in affect for a build cycle. At the end of the build it is reinitialized.
*/
private ValOperation _operation;
+
+
+ /**
+ * In the very common case of doing a clean all (with auto build turned on), Eclipse signals two
+ * workspace, auto build, post events. One at the end of the clean and one at the end of the
+ * real build.
+ *
+ * If we are doing a clean all, with auto build turned on, we increment this by one,
+ * so that we know to throw away the first workspace, auto build, post event.
+ */
+ private int _discardAutoPost;
public static synchronized ValOperationManager getDefault(){
if (_me == null)_me = new ValOperationManager();
return _me;
}
- private ValOperationManager(){
- init();
- }
+ private ValOperationManager(){}
- /**
- * Initialize yourself for a new validation operation.
- */
- private void init(){
- _operation = new ValOperation();
- }
-
public void resourceChanged(IResourceChangeEvent event) {
int type = event.getType();
int kind = event.getBuildKind();
- IProject project = null;
- if (event.getSource() instanceof IProject) {
- project = (IProject) event.getSource();
- }
-
if (kind == IncrementalProjectBuilder.CLEAN_BUILD && ((type & IResourceChangeEvent.PRE_BUILD) != 0)){
processClean(event);
}
if (isBuildStarting(event)){
+ _operation = new ValOperation();
+ _operation.setMultiProject(true);
IValidatorVisitor visitor = new IValidatorVisitor(){
public void visit(Validator validator, IProject project, boolean isManual,
@@ -66,27 +132,17 @@
validator.validationStarting(project, operation.getState(), monitor);
}
};
- ValManager.getDefault().accept(visitor, project, false, true, _operation, new NullProgressMonitor());
+ ValManager.getDefault().accept(visitor, null, false, true, _operation, new NullProgressMonitor());
}
if (isBuildFinished(event)){
- IValidatorVisitor visitor = new IValidatorVisitor(){
-
- public void visit(Validator validator, IProject project, boolean isManual,
- boolean isBuild, ValOperation operation, IProgressMonitor monitor) {
-
- validator.validationFinishing(project, operation.getState(), monitor);
- }
-
- };
- ValManager.getDefault().accept(visitor, project, false, true, _operation, new NullProgressMonitor());
- //TODO this may prove to be a mistake, I may be clearing the validation result too soon.
- init();
+ ValOperationJob finished = new ValOperationJob(getOperation());
+ finished.schedule();
+ _operation = null;
}
- //TODO remove this
if (Tracing.isLogging()){
String kindName = null;
if (kind == IncrementalProjectBuilder.AUTO_BUILD)kindName = "Auto"; //$NON-NLS-1$
@@ -105,11 +161,12 @@
else if (event.getSource() instanceof IWorkspace) {
sourceName = "Workspace"; //$NON-NLS-1$
}
- b.append("Source="+sourceName+", kind="+kindName+", type="+type); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ b.append("ValOperationManager: A resource has changed, source="+sourceName+", kind="+kindName+", event type=("+type); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
if ((type & IResourceChangeEvent.POST_BUILD) != 0)b.append(", post build"); //$NON-NLS-1$
if ((type & IResourceChangeEvent.PRE_BUILD) != 0){
b.append(", pre build"); //$NON-NLS-1$
}
+ b.append(')');
IResourceDelta rd = event.getDelta();
if (rd == null)b.append(", there was no resource delta"); //$NON-NLS-1$
@@ -126,25 +183,21 @@
private boolean isBuildStarting(IResourceChangeEvent event) {
int type = event.getType();
int kind = event.getBuildKind();
+ boolean isWorkspace = event.getSource() instanceof IWorkspace;
+ boolean preBuild = (type & IResourceChangeEvent.PRE_BUILD) != 0;
if (ResourcesPlugin.getWorkspace().isAutoBuilding()){
- if (((type & IResourceChangeEvent.PRE_BUILD) != 0) &&
- (kind == IncrementalProjectBuilder.AUTO_BUILD ||
- kind == IncrementalProjectBuilder.INCREMENTAL_BUILD ||
- kind == IncrementalProjectBuilder.FULL_BUILD))return true;
+ if (isWorkspace && preBuild && kind == IncrementalProjectBuilder.CLEAN_BUILD){
+ _discardAutoPost = 1;
+ return true;
+ }
- if (((type & IResourceChangeEvent.POST_BUILD) != 0) &&
- (kind == IncrementalProjectBuilder.CLEAN_BUILD))return true;
-
- return false;
+ if (isWorkspace && preBuild && kind == IncrementalProjectBuilder.AUTO_BUILD)return true;
}
else {
- if (kind == IncrementalProjectBuilder.AUTO_BUILD )return false;
- if (((type & IResourceChangeEvent.PRE_BUILD) != 0) &&
- (kind == IncrementalProjectBuilder.INCREMENTAL_BUILD ||
- kind == IncrementalProjectBuilder.FULL_BUILD))return true;
- return false;
+ if (isWorkspace && preBuild && kind == IncrementalProjectBuilder.INCREMENTAL_BUILD)return true;
}
+ return false;
}
/**
@@ -155,31 +208,23 @@
* @return return true if we are just finishing a build.
*/
private boolean isBuildFinished(IResourceChangeEvent event) {
- /*
- * I discovered these conditions empirically, by running running different types of builds
- * and noticing which events were signaled.
- *
- * When auto build is enabled, it seemed like all the cases ended with an AutoBuild build type, a
- * POST_BUILD and a target of WorkSpace.
- *
- * When auto build is not enabled, the AUTO BUILD events are signaled, so they should be ignored.
- * Anything other than a clean POST_BUILD seemed to indicate the end of a build cycle. (In some cases
- * this might be a little too aggressive, but since the end result is just the deleting of some
- * caches, it is better to be aggressive than to leave the caches around too long).
- */
+
+ if (_operation == null)return false;
+
int type = event.getType();
int kind = event.getBuildKind();
+ boolean isWorkspace = event.getSource() instanceof IWorkspace;
+ boolean postBuild = (type & IResourceChangeEvent.POST_BUILD) != 0;
+
if (ResourcesPlugin.getWorkspace().isAutoBuilding()){
- if (((type & IResourceChangeEvent.POST_BUILD) != 0) && kind == IncrementalProjectBuilder.AUTO_BUILD
- && event.getSource() instanceof IWorkspace){
- return true;
- }
+ if (isWorkspace && postBuild && kind == IncrementalProjectBuilder.AUTO_BUILD){
+ if (_discardAutoPost == 1)_discardAutoPost = 0;
+ else return true;
+ }
}
else {
- if (kind != IncrementalProjectBuilder.AUTO_BUILD && ((type & IResourceChangeEvent.POST_BUILD) != 0)){
- return true;
- }
+ if (isWorkspace && postBuild && kind == IncrementalProjectBuilder.INCREMENTAL_BUILD)return true;
}
return false;
@@ -191,15 +236,21 @@
IProgressMonitor monitor = new NullProgressMonitor();
Object source = event.getSource();
if (source instanceof IWorkspace) {
- ValManager.getDefault().clean(null, _operation, monitor);
+ ValManager.getDefault().clean(null, getOperation(), monitor);
}
}
/**
- * Answer the current validation operation.
+ * Answer the current validation operation. If we are not in a multiple project validation
+ * we will return a new one.
*/
public ValOperation getOperation() {
+ /*
+ * If we don't have a current operation, we create a new one. The only time we save
+ * the operation is when we are sure that we are in a multi project validation.
+ */
+ if (_operation == null)return new ValOperation();
return _operation;
}