Author: scabanovich
Date: 2011-05-31 17:57:37 -0400 (Tue, 31 May 2011)
New Revision: 31700
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/BuilderOrderResolutionGenerator.java
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/plugin.properties
trunk/jst/plugins/org.jboss.tools.jst.web.kb/plugin.xml
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/ELValidator.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/ValidatorManager.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/preferences/ELPreferenceInitializer.java
Log:
JBIDE-9028
https://issues.jboss.org/browse/JBIDE-9028
Modified: trunk/jst/plugins/org.jboss.tools.jst.web.kb/plugin.properties
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.kb/plugin.properties 2011-05-31 21:53:27 UTC
(rev 31699)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/plugin.properties 2011-05-31 21:57:37 UTC
(rev 31700)
@@ -4,4 +4,5 @@
# END NON-TRANSLATABLE
KBProblemName=EL Knowledge Base Problem
-KBBuilderProblemName=Knowledge Base Builder Problem
\ No newline at end of file
+KBBuilderProblemName=Knowledge Base Builder Problem
+BuilderOrderProblemName=Builders Order Problem
\ No newline at end of file
Modified: trunk/jst/plugins/org.jboss.tools.jst.web.kb/plugin.xml
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.kb/plugin.xml 2011-05-31 21:53:27 UTC (rev
31699)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/plugin.xml 2011-05-31 21:57:37 UTC (rev
31700)
@@ -135,6 +135,15 @@
</persistent>
</extension>
+ <extension id="builderOrderProblem"
name="%BuilderOrderProblemName"
point="org.eclipse.core.resources.markers">
+ <super type="org.eclipse.core.resources.problemmarker">
+ </super>
+ <persistent value="true">
+ </persistent>
+ <attribute name="validator">
+ </attribute>
+ </extension>
+
<extension id="kbproblemmarker" name="%KBProblemName"
point="org.eclipse.core.resources.markers">
<super type="org.eclipse.wst.validation.problemmarker">
</super>
@@ -149,6 +158,12 @@
</markerResolutionGenerator>
</extension>
+ <extension point="org.eclipse.ui.ide.markerResolution">
+ <markerResolutionGenerator
+ markerType="org.jboss.tools.jst.web.kb.builderOrderProblem"
+ class="org.jboss.tools.jst.web.kb.internal.validation.BuilderOrderResolutionGenerator"/>
+ </extension>
+
<extension
point="org.eclipse.wst.validation.validator"
id="cd"
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/BuilderOrderResolutionGenerator.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/BuilderOrderResolutionGenerator.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/BuilderOrderResolutionGenerator.java 2011-05-31
21:57:37 UTC (rev 31700)
@@ -0,0 +1,78 @@
+package org.jboss.tools.jst.web.kb.internal.validation;
+
+import org.eclipse.core.resources.ICommand;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.IMarkerResolution;
+import org.eclipse.ui.IMarkerResolution2;
+import org.eclipse.ui.IMarkerResolutionGenerator2;
+import org.jboss.tools.jst.web.kb.WebKbPlugin;
+
+public class BuilderOrderResolutionGenerator implements IMarkerResolutionGenerator2 {
+
+ public IMarkerResolution[] getResolutions(IMarker marker) {
+ try {
+ if(ValidatorManager.ORDER_PROBLEM_MARKER_TYPE.equals(marker.getType())) {
+ return new IMarkerResolution[]{new BuilderOrderResolution()};
+ }
+ } catch (CoreException e) {
+ WebKbPlugin.getDefault().logError(e);
+ }
+ return new IMarkerResolution[0];
+ }
+
+ public boolean hasResolutions(IMarker marker) {
+ try {
+ return ValidatorManager.ORDER_PROBLEM_MARKER_TYPE.equals(marker.getType());
+ } catch (CoreException e) {
+ WebKbPlugin.getDefault().logError(e);
+ }
+ return false;
+ }
+
+}
+
+class BuilderOrderResolution implements IMarkerResolution2 {
+
+ public String getLabel() {
+ return "Change Order of Builders."; //$NON-NLS-1$
+ }
+
+ public void run(IMarker marker) {
+ IProject project = marker.getResource().getProject();
+
+ try {
+ IProjectDescription d = project.getDescription();
+ ICommand[] bs = d.getBuildSpec();
+ ICommand v = null;
+ for (int i = 0; i < bs.length; i++) {
+ if(ValidatorManager.WTP_VALIDATOR_ID.equals(bs[i].getBuilderName())) {
+ v = bs[i];
+ }
+ if(v != null) {
+ bs[i] = (i + 1 < bs.length) ? bs[i + 1] : v;
+ }
+ }
+ d.setBuildSpec(bs);
+ project.setDescription(d, IProject.FORCE, new NullProgressMonitor());
+ project.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
+ } catch (CoreException e) {
+ WebKbPlugin.getDefault().logError(e);
+ }
+
+ }
+
+ public String getDescription() {
+ return null;
+ }
+
+ public Image getImage() {
+ return null;
+ }
+
+}
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/BuilderOrderResolutionGenerator.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/ELValidator.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/ELValidator.java 2011-05-31
21:53:27 UTC (rev 31699)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/ELValidator.java 2011-05-31
21:57:37 UTC (rev 31700)
@@ -535,13 +535,22 @@
* @see
org.jboss.tools.jst.web.kb.validation.IValidator#shouldValidate(org.eclipse.core.resources.IProject)
*/
public boolean shouldValidate(IProject project) {
- if(isEnabled(project)) {
- for (IELValidationDelegate delegate : DELEGATES) {
- if(delegate.shouldValidate(project)) {
- return true;
+ try {
+ if(validateBuilderOrder(project) && isEnabled(project)) {
+ for (IELValidationDelegate delegate : DELEGATES) {
+ if(delegate.shouldValidate(project)) {
+ return true;
+ }
}
}
+ } catch (CoreException e) {
+ WebKbPlugin.getDefault().logError(e);
}
return false;
}
-}
\ No newline at end of file
+
+ private boolean validateBuilderOrder(IProject project) throws CoreException {
+ return ValidatorManager.validateBuilderOrder(project, getBuilderId(), getId(),
ELSeverityPreferences.getInstance());
+ }
+
+}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/ValidatorManager.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/ValidatorManager.java 2011-05-31
21:53:27 UTC (rev 31699)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/ValidatorManager.java 2011-05-31
21:57:37 UTC (rev 31700)
@@ -16,8 +16,10 @@
import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
@@ -26,6 +28,7 @@
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
import org.eclipse.wst.validation.internal.provisional.core.IValidationContext;
import org.eclipse.wst.validation.internal.provisional.core.IValidatorJob;
+import org.jboss.tools.common.preferences.SeverityPreferences;
import org.jboss.tools.jst.web.kb.KbMessages;
import org.jboss.tools.jst.web.kb.WebKbPlugin;
import org.jboss.tools.jst.web.kb.validation.IValidatingProjectSet;
@@ -76,12 +79,6 @@
if(validatingProjects.contains(rootProject)) {
return OK_STATUS;
}
- if(!checkBuilderOrder(validationHelper, rootProject)) {
- //TODO activate this return after duly testing
- // it would be too dangerous to abort validation now
- // while some test project have wrong builder order.
-// return OK_STATUS;
- }
validatingProjects.add(rootProject);
}
}
@@ -111,40 +108,79 @@
}
}
- private static String WTP_VALIDATOR_ID =
"org.eclipse.wst.validation.validationbuilder"; //$NON-NLS-1$
+ static String WTP_VALIDATOR_ID =
"org.eclipse.wst.validation.validationbuilder"; //$NON-NLS-1$
+ static String ORDER_PROBLEM_MARKER_TYPE =
"org.jboss.tools.jst.web.kb.builderOrderProblem"; //$NON-NLS-1$
+ private static String ATTR_VALIDATOR = "validator"; //$NON-NLS-1$
- private boolean checkBuilderOrder(ContextValidationHelper validationHelper, IProject
project) {
- IValidationContextManager validationContextManager =
validationHelper.getValidationContextManager();
- List<IValidator> validators = validationContextManager.getValidators();
- Set<String> requiredBuilders = new HashSet<String>();
- for (IValidator v: validators) {
- String builderId = v.getBuilderId();
- if(builderId != null) {
- requiredBuilders.add(builderId);
- }
- }
+ public static boolean isCorrectOrder(IProject project, String builderId) {
try {
- boolean validationFound = false;
- ICommand[] cs = project.getDescription().getBuildSpec();
+ ICommand[] cs = project.getDescription().getBuildSpec();
+ boolean validationFound = false;
for (ICommand c: cs) {
String name = c.getBuilderName();
if(WTP_VALIDATOR_ID.equals(name)) {
validationFound = true;
}
- if(requiredBuilders.contains(name) && validationFound) {
- String message = NLS.bind(KbMessages.WRONG_BUILDER_ORDER, project.getName(), name);
- WebKbPlugin.getDefault().logError(message);
- return false;
+ if(builderId.equals(name)) {
+ return !validationFound;
}
- }
-
+ }
} catch (CoreException e) {
WebKbPlugin.getDefault().logError(e);
}
-
return true;
}
+ public static IMarker findBuilderOrderMarker(IProject project, String validator) {
+ IMarker result = null;
+ try {
+ IMarker[] ms = project.findMarkers(ORDER_PROBLEM_MARKER_TYPE, false,
IResource.DEPTH_ZERO);
+ for (IMarker m: ms) {
+ if(validator.equals(m.getAttribute(ATTR_VALIDATOR, null))) {
+ result = m;
+ }
+ }
+ } catch (CoreException e) {
+ WebKbPlugin.getDefault().logError(e);
+ }
+ return result;
+ }
+
+ public static boolean validateBuilderOrder(IProject project, String builderId, String
validator, SeverityPreferences preferences) throws CoreException {
+ String severityPreferenceValue = preferences.getBuilderOrderPreference(project);
+ int severity = getSeverity(severityPreferenceValue);
+ boolean isCorrect = isCorrectOrder(project, builderId);
+ IMarker marker = findBuilderOrderMarker(project, validator);
+ if(isCorrect || severity <= IMarker.SEVERITY_INFO) {
+ if(marker != null) {
+ ResourcesPlugin.getWorkspace().deleteMarkers(new IMarker[]{marker});
+ }
+ } else {
+ if(marker != null) {
+ if(marker.getAttribute(IMarker.SEVERITY, -1) != severity) {
+ marker.setAttribute(IMarker.SEVERITY, severity);
+ }
+ } else {
+ marker = project.createMarker(ORDER_PROBLEM_MARKER_TYPE);
+ marker.setAttribute(ATTR_VALIDATOR, validator);
+ marker.setAttribute(IMarker.SEVERITY, severity);
+ String message = NLS.bind(KbMessages.WRONG_BUILDER_ORDER, project.getName(),
builderId);
+ marker.setAttribute(IMarker.MESSAGE, message);
+ //Temporary to debug
+ WebKbPlugin.getDefault().logError(message);
+ }
+ }
+ return isCorrect || severity <= IMarker.SEVERITY_INFO;
+ }
+
+ public static int getSeverity(String severityPreferenceValue) {
+ return (SeverityPreferences.IGNORE.equals(severityPreferenceValue))
+ ? IMarker.SEVERITY_INFO
+ : SeverityPreferences.WARNING.equals(severityPreferenceValue)
+ ? IMarker.SEVERITY_WARNING
+ : IMarker.SEVERITY_ERROR;
+ }
+
private IStatus validate(Set<IFile> changedFiles, ContextValidationHelper
validationHelper, IReporter reporter) throws ValidationException {
IValidationContextManager validationContextManager =
validationHelper.getValidationContextManager();
List<IValidator> validators = validationContextManager.getValidators();
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/preferences/ELPreferenceInitializer.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/preferences/ELPreferenceInitializer.java 2011-05-31
21:53:27 UTC (rev 31699)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/preferences/ELPreferenceInitializer.java 2011-05-31
21:57:37 UTC (rev 31700)
@@ -29,6 +29,7 @@
IEclipsePreferences defaultPreferences = ((IScopeContext) new
DefaultScope()).getNode(WebKbPlugin.PLUGIN_ID);
defaultPreferences.putBoolean(SeverityPreferences.ENABLE_BLOCK_PREFERENCE_NAME, true);
+ defaultPreferences.put(SeverityPreferences.WRONG_BUILDER_ORDER_PREFERENCE_NAME,
ELSeverityPreferences.ERROR);
for (String name : ELSeverityPreferences.SEVERITY_OPTION_NAMES) {
defaultPreferences.put(name, ELSeverityPreferences.ERROR);
}