Author: akazakov
Date: 2009-10-15 11:36:36 -0400 (Thu, 15 Oct 2009)
New Revision: 18113
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/action/
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/action/EnableKBOnProject.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/action/KBProblemMarkerResolutionGenerator.java
Removed:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/actions/
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/ELValidator.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF/MANIFEST.MF
trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.properties
trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AbstractXMLContentAssistProcessor.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/JstUIMessages.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/messages.properties
trunk/jst/plugins/org.jboss.tools.jst.web.kb/META-INF/MANIFEST.MF
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/KbMessages.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/KbMessages.properties
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/KbProject.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4978
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/ELValidator.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/ELValidator.java 2009-10-15
15:08:25 UTC (rev 18112)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/ELValidator.java 2009-10-15
15:36:36 UTC (rev 18113)
@@ -75,9 +75,12 @@
import org.jboss.tools.common.util.FileUtil;
import org.jboss.tools.jsf.JSFModelPlugin;
import org.jboss.tools.jsf.preferences.JSFSeverityPreferences;
+import org.jboss.tools.jsf.project.JSFNature;
import org.jboss.tools.jst.web.kb.IKbProject;
import org.jboss.tools.jst.web.kb.KbProjectFactory;
+import org.jboss.tools.jst.web.kb.internal.KbProject;
import org.jboss.tools.jst.web.kb.internal.validation.ContextValidationHelper;
+import org.jboss.tools.jst.web.kb.internal.validation.ValidatingProjectSet;
import org.jboss.tools.jst.web.kb.internal.validation.ValidationErrorManager;
import org.jboss.tools.jst.web.kb.internal.validation.ValidatorManager;
import org.jboss.tools.jst.web.kb.validation.ELReference;
@@ -93,6 +96,8 @@
*/
public class ELValidator extends ValidationErrorManager implements IValidator {
+ public static final String ID = "org.jboss.tools.jsf.ELValidator";
+
protected static final String UNKNOWN_EL_VARIABLE_NAME_MESSAGE_ID =
"UNKNOWN_EL_VARIABLE_NAME"; //$NON-NLS-1$
protected static final String UNKNOWN_EL_VARIABLE_PROPERTY_NAME_MESSAGE_ID =
"UNKNOWN_EL_VARIABLE_PROPERTY_NAME"; //$NON-NLS-1$
protected static final String UNPAIRED_GETTER_OR_SETTER_MESSAGE_ID =
"UNPAIRED_GETTER_OR_SETTER"; //$NON-NLS-1$
@@ -529,30 +534,48 @@
return names;
}
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.internal.validation.ValidationErrorManager#getPreference(org.eclipse.core.resources.IProject,
java.lang.String)
+ */
@Override
protected String getPreference(IProject project, String preferenceKey) {
- // TODO
- return null;
+ return JSFSeverityPreferences.getInstance().getProjectPreference(project,
preferenceKey);
}
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.validation.IValidator#getId()
+ */
public String getId() {
- // TODO
- return null;
+ return ID;
}
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.validation.IValidator#getValidatingProjects(org.eclipse.core.resources.IProject)
+ */
public IValidatingProjectSet getValidatingProjects(IProject project) {
List<IProject> projects = new ArrayList<IProject>();
projects.add(project);
IKbProject kbProject = KbProjectFactory.getKbProject(project, false);
if(kbProject!=null) {
- // IValidationContext context = kbProject.getValidationContext();
-
+ IValidationContext rootContext = null; // kbProject.getValidationContext();
+ return new ValidatingProjectSet(project, projects, rootContext);
}
return null;
}
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.validation.IValidator#shouldValidate(org.eclipse.core.resources.IProject)
+ */
public boolean shouldValidate(IProject project) {
- // TODO
+ try {
+ return project.hasNature(JSFNature.NATURE_ID) &&
KbProject.checkKBBuilderInstalled(project);
+ } catch (CoreException e) {
+ JSFModelPlugin.getDefault().logError(e);
+ }
return false;
}
}
\ No newline at end of file
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF/MANIFEST.MF
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF/MANIFEST.MF 2009-10-15 15:08:25 UTC
(rev 18112)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF/MANIFEST.MF 2009-10-15 15:36:36 UTC
(rev 18113)
@@ -8,7 +8,6 @@
Bundle-Localization: plugin
Export-Package: org.jboss.tools.jst.jsp,
org.jboss.tools.jst.jsp.contentassist,
- org.jboss.tools.jst.jsp.contentassist.actions,
org.jboss.tools.jst.jsp.contentassist.xpl,
org.jboss.tools.jst.jsp.drop.treeviewer.model,
org.jboss.tools.jst.jsp.drop.treeviewer.ui,
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.properties
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.properties 2009-10-15 15:08:25 UTC
(rev 18112)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.properties 2009-10-15 15:36:36 UTC
(rev 18113)
@@ -8,6 +8,4 @@
occurrenceStructureProvidersExtensionPoint= Occurrence Structure Providers
defaultOccurrenceStructureProviderName= Default Occurrence Provider
-Bundle-Name.0 = Jsp Editor Plug-in
-
-KBProblemName=KB Problem
\ No newline at end of file
+Bundle-Name.0 = Jsp Editor Plug-in
\ No newline at end of file
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml 2009-10-15 15:08:25 UTC (rev
18112)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml 2009-10-15 15:36:36 UTC (rev
18113)
@@ -575,25 +575,8 @@
</key>
</extension>
- <extension id="kbproblemmarker" name="%KBProblemName"
point="org.eclipse.core.resources.markers">
- <super type="org.eclipse.core.resources.problemmarker">
- </super>
- <persistent value="true">
- </persistent>
-
- </extension>
-
- <extension point="org.eclipse.ui.ide.markerResolution">
- <markerResolutionGenerator
- markerType="org.jboss.tools.jst.jsp.kbproblemmarker"
- class="org.jboss.tools.jst.jsp.contentassist.actions.KBProblemMarkerResolutionGenerator">
- </markerResolutionGenerator>
- </extension>
-
<extension
point="org.eclipse.core.runtime.preferences">
<initializer
class="org.jboss.tools.jst.jsp.preferences.VpePreferencesInitializer"/>
</extension>
-
-
-</plugin>
+</plugin>
\ No newline at end of file
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AbstractXMLContentAssistProcessor.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AbstractXMLContentAssistProcessor.java 2009-10-15
15:08:25 UTC (rev 18112)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AbstractXMLContentAssistProcessor.java 2009-10-15
15:36:36 UTC (rev 18113)
@@ -10,18 +10,12 @@
******************************************************************************/
package org.jboss.tools.jst.jsp.contentassist;
-import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.filebuffers.FileBuffers;
-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.IProjectDescription;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.text.IDocument;
@@ -58,13 +52,9 @@
import org.jboss.tools.common.el.core.resolver.ELResolver;
import org.jboss.tools.common.el.core.resolver.ELResolverFactoryManager;
import org.jboss.tools.common.text.TextProposal;
-import org.jboss.tools.jst.jsp.JspEditorPlugin;
-import org.jboss.tools.jst.jsp.messages.JstUIMessages;
-import org.jboss.tools.jst.web.kb.IKbProject;
-import org.jboss.tools.jst.web.kb.KbProjectFactory;
import org.jboss.tools.jst.web.kb.KbQuery;
import org.jboss.tools.jst.web.kb.KbQuery.Type;
-import org.jboss.tools.jst.web.kb.internal.KbBuilder;
+import org.jboss.tools.jst.web.kb.internal.KbProject;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -93,119 +83,12 @@
this.fDocument = (viewer == null ? null : viewer.getDocument());
this.fDocumentPosition = offset;
this.fContext = createContext();
-
- checkKBBuilderInstalled();
+
+ IFile resource = fContext == null ? null : fContext.getResource();
+ KbProject.checkKBBuilderInstalled(resource);
return super.computeCompletionProposals(viewer, offset);
}
-
- private void checkKBBuilderInstalled() {
- ELContext context = getContext();
- IFile resource = context == null ? null : context.getResource();
- IProject project = resource == null ? null : resource.getProject();
- if (project == null)
- return; // Cannot check anything
-
- boolean kbNatureFound = false;
- boolean kbBuilderFound = false;
- try {
- kbNatureFound = (project.getNature(IKbProject.NATURE_ID) != null);
-
- IProjectDescription description = project.getDescription();
- ICommand command = null;
- ICommand commands[] = description.getBuildSpec();
- for (int i = 0; i < commands.length && command == null; ++i) {
- if (commands[i].getBuilderName().equals(KbBuilder.BUILDER_ID)) {
- kbBuilderFound = true;
- break;
- }
- }
- } catch (CoreException ex) {
- JspEditorPlugin.getPluginLog().logError(ex);
- }
-
- if (kbNatureFound && kbBuilderFound) {
- // Find existing KBNATURE problem marker and kill it if exists
- IMarker[] markers = getOwnedMarkers(project);
- if (markers != null && markers.length > 0) {
- for (IMarker m : markers) {
- try {
- project.deleteMarkers(KB_PROBLEM_MARKER_TYPE, true, IResource.DEPTH_ONE);
- project.setPersistentProperty(KbProjectFactory.NATURE_MOCK, null);
- } catch (CoreException ex) {
- JspEditorPlugin.getPluginLog().logError(ex);
- }
- }
- }
- return;
- }
-
- // Find existing KBNATURE problem marker and install it if doesn't exist
- IMarker[] markers = getOwnedMarkers(project);
-
- if (markers == null || markers.length == 0) {
- try {
- IMarker m = createOrUpdateKbProblemMarker(null, project, !kbNatureFound,
!kbBuilderFound);
- } catch (CoreException ex) {
- JspEditorPlugin.getPluginLog().logError(ex);
- }
- } else {
- for (IMarker m : markers) {
- try {
- m = createOrUpdateKbProblemMarker(m, project, !kbNatureFound, !kbBuilderFound);
- } catch (CoreException ex) {
- JspEditorPlugin.getPluginLog().logError(ex);
- }
- }
- }
- return;
-
- }
-
- public static final String KB_PROBLEM_MARKER_TYPE =
"org.jboss.tools.jst.jsp.kbproblemmarker"; //$NON-NLS-1$
-
- private IMarker createOrUpdateKbProblemMarker(IMarker m, IResource r, boolean
kbNatureIsAbsent, boolean kbBuilderIsAbsent) throws CoreException {
- ArrayList<String> args = new ArrayList<String>();
- args.add(kbNatureIsAbsent ? JstUIMessages.KBNATURE_NOT_FOUND : "");
//$NON-NLS-1$
- args.add(kbBuilderIsAbsent ? JstUIMessages.KBBUILDER_NOT_FOUND : "");
//$NON-NLS-1$
-
- String message = MessageFormat.format(JstUIMessages.KBPROBLEM, args.toArray());
- if (m == null) {
- m = r.createMarker(KB_PROBLEM_MARKER_TYPE);
- r.setPersistentProperty(KbProjectFactory.NATURE_MOCK, "true");
- KbProjectFactory.getKbProject(r.getProject(), true);
- }
- m.setAttribute(IMarker.MESSAGE, message);
- m.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
- m.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_NORMAL);
- return m;
- }
-
- private IMarker[] getOwnedMarkers(IResource r) {
- ArrayList<IMarker> l = null;
- try {
- IMarker[] ms = r.findMarkers(null, false, 1);
- if(ms != null) {
- for (int i = 0; i < ms.length; i++) {
- if(ms[i] == null) continue;
-
- String _type = ms[i].getType();
- if(_type == null) continue;
- if(!_type.equals(KB_PROBLEM_MARKER_TYPE)) continue;
- if(!ms[i].isSubtypeOf(IMarker.PROBLEM)) continue;
-
- if(l == null)
- l = new ArrayList<IMarker>();
-
- l.add(ms[i]);
- }
- }
- } catch (CoreException e) {
- //ignore
- }
- return (l == null) ? null : l.toArray(new IMarker[0]);
- }
-
/**
* The reason of overriding is that the method returns wrong region in case of
incomplete tag (a tag with no '>'-closing char)
* In this case we have to return that previous incomplete tag instead of the current
tag)
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/JstUIMessages.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/JstUIMessages.java 2009-10-15
15:08:25 UTC (rev 18112)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/JstUIMessages.java 2009-10-15
15:36:36 UTC (rev 18113)
@@ -115,8 +115,4 @@
public static String JSPDialogContentProposalProvider_NewELExpression;
public static String PROPERTY_NAME_COLUMN;
public static String PROPERTY_VALUE_COLUMN;
- public static String KBNATURE_NOT_FOUND;
- public static String KBBUILDER_NOT_FOUND;
- public static String KBPROBLEM;
- public static String ENABLE_KB;
-}
+}
\ No newline at end of file
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/messages.properties
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/messages.properties 2009-10-15
15:08:25 UTC (rev 18112)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/messages.properties 2009-10-15
15:36:36 UTC (rev 18113)
@@ -91,9 +91,4 @@
JSPDialogContentProposalProvider_NewELExpression=New EL Expression
PROPERTY_NAME_COLUMN=Attribute
-PROPERTY_VALUE_COLUMN=Value
-
-KBNATURE_NOT_FOUND=KB Nature is not installed.
-KBBUILDER_NOT_FOUND=KB Builder is not installed.
-KBPROBLEM=KB Problem: {0} {1} Use Quick Fix to allow JSF Content Assistant.
-ENABLE_KB=Enable JSF CA on this project
+PROPERTY_VALUE_COLUMN=Value
\ No newline at end of file
Modified: trunk/jst/plugins/org.jboss.tools.jst.web.kb/META-INF/MANIFEST.MF
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.kb/META-INF/MANIFEST.MF 2009-10-15 15:08:25
UTC (rev 18112)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/META-INF/MANIFEST.MF 2009-10-15 15:36:36
UTC (rev 18113)
@@ -12,14 +12,16 @@
org.jboss.tools.common.el.core,
org.eclipse.jface.text,
org.eclipse.wst.sse.core,
- org.eclipse.wst.xml.ui;bundle-version="1.1.0",
- org.eclipse.jdt.ui;bundle-version="3.5.0",
- org.eclipse.wst.validation;bundle-version="1.2.102",
- org.eclipse.ui.editors;bundle-version="3.5.0"
+ org.eclipse.wst.xml.ui,
+ org.eclipse.jdt.ui,
+ org.eclipse.wst.validation,
+ org.eclipse.ui.editors,
+ org.eclipse.ui.ide
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-Vendor: %providerName
Export-Package: org.jboss.tools.jst.web.kb,
+ org.jboss.tools.jst.web.kb.action,
org.jboss.tools.jst.web.kb.el,
org.jboss.tools.jst.web.kb.internal,
org.jboss.tools.jst.web.kb.internal.scanner,
Modified: trunk/jst/plugins/org.jboss.tools.jst.web.kb/plugin.properties
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.kb/plugin.properties 2009-10-15 15:08:25 UTC
(rev 18112)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/plugin.properties 2009-10-15 15:36:36 UTC
(rev 18113)
@@ -1,4 +1,6 @@
providerName=JBoss by Red Hat
# START NON-TRANSLATABLE
Bundle-Name.0 = Web KB
-# END NON-TRANSLATABLE
\ No newline at end of file
+# END NON-TRANSLATABLE
+
+KBProblemName=KB 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 2009-10-15 15:08:25 UTC (rev
18112)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/plugin.xml 2009-10-15 15:36:36 UTC (rev
18113)
@@ -70,4 +70,17 @@
location="taglibs/componentExtension.xml"/>
</extension>
-</plugin>
+ <extension id="kbproblemmarker" name="%KBProblemName"
point="org.eclipse.core.resources.markers">
+ <super type="org.eclipse.core.resources.problemmarker">
+ </super>
+ <persistent value="true">
+ </persistent>
+ </extension>
+
+ <extension point="org.eclipse.ui.ide.markerResolution">
+ <markerResolutionGenerator
+ markerType="org.jboss.tools.jst.web.kb.kbproblemmarker"
+ class="org.jboss.tools.jst.web.kb.action.KBProblemMarkerResolutionGenerator">
+ </markerResolutionGenerator>
+ </extension>
+</plugin>
\ No newline at end of file
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/KbMessages.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/KbMessages.java 2009-10-15
15:08:25 UTC (rev 18112)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/KbMessages.java 2009-10-15
15:36:36 UTC (rev 18113)
@@ -24,4 +24,8 @@
public static String VALIDATION_CONTEXT_LINKED_RESOURCE_PATH_MUST_NOT_BE_NULL;
public static String VALIDATION_CONTEXT_VARIABLE_NAME_MUST_NOT_BE_NULL;
+ public static String KBNATURE_NOT_FOUND;
+ public static String KBBUILDER_NOT_FOUND;
+ public static String KBPROBLEM;
+ public static String ENABLE_KB;
}
\ No newline at end of file
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/KbMessages.properties
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/KbMessages.properties 2009-10-15
15:08:25 UTC (rev 18112)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/KbMessages.properties 2009-10-15
15:36:36 UTC (rev 18113)
@@ -1,2 +1,7 @@
VALIDATION_CONTEXT_LINKED_RESOURCE_PATH_MUST_NOT_BE_NULL=Linked resource path must not be
null\!
-VALIDATION_CONTEXT_VARIABLE_NAME_MUST_NOT_BE_NULL=Variable name must not be null\!
\ No newline at end of file
+VALIDATION_CONTEXT_VARIABLE_NAME_MUST_NOT_BE_NULL=Variable name must not be null\!
+
+KBNATURE_NOT_FOUND=KB Nature is not installed.
+KBBUILDER_NOT_FOUND=KB Builder is not installed.
+KBPROBLEM=KB Problem: {0} {1} Use Quick Fix to allow JSF Content Assistant and
Validation.
+ENABLE_KB=Enable JSF CA and validation on this project
\ No newline at end of file
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/action/EnableKBOnProject.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/action/EnableKBOnProject.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/action/EnableKBOnProject.java 2009-10-15
15:36:36 UTC (rev 18113)
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.web.kb.action;
+
+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.ui.IMarkerResolution;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.jst.web.kb.IKbProject;
+import org.jboss.tools.jst.web.kb.KbMessages;
+import org.jboss.tools.jst.web.kb.WebKbPlugin;
+import org.jboss.tools.jst.web.kb.internal.KbProject;
+
+/**
+ * The Marker Resolution that enables the KB Nature on the project
+ *
+ * @author Victor Rubezhny
+ *
+ */
+public class EnableKBOnProject implements IMarkerResolution{
+
+ public String getLabel() {
+ return KbMessages.ENABLE_KB;
+ }
+
+ public void run(IMarker marker) {
+ IResource resource = marker.getResource();
+ IProject project = resource instanceof IProject ? (IProject)resource :
+ resource != null ? resource.getProject() : null;
+
+ if (project == null)
+ return;
+
+ try {
+ EclipseResourceUtil.addNatureToProject(project, IKbProject.NATURE_ID);
+ // Find existing KBNATURE problem marker and kill it if exists
+ project.deleteMarkers(KbProject.KB_PROBLEM_MARKER_TYPE, true, IResource.DEPTH_ONE);
+ } catch (CoreException e) {
+ WebKbPlugin.getDefault().logError(e);
+ }
+ }
+}
\ No newline at end of file
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/action/EnableKBOnProject.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/action/KBProblemMarkerResolutionGenerator.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/action/KBProblemMarkerResolutionGenerator.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/action/KBProblemMarkerResolutionGenerator.java 2009-10-15
15:36:36 UTC (rev 18113)
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.web.kb.action;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.ui.IMarkerResolution;
+import org.eclipse.ui.IMarkerResolutionGenerator;
+
+/**
+ * Shows the Marker Resolutions for KB Problem Marker
+ *
+ * @author Victor Rubezhny
+ *
+ */
+public class KBProblemMarkerResolutionGenerator implements IMarkerResolutionGenerator {
+ public IMarkerResolution[] getResolutions(IMarker marker) {
+ return new IMarkerResolution[] {
+ new EnableKBOnProject()
+ };
+ }
+}
\ No newline at end of file
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/action/KBProblemMarkerResolutionGenerator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/KbProject.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/KbProject.java 2009-10-15
15:08:25 UTC (rev 18112)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/KbProject.java 2009-10-15
15:36:36 UTC (rev 18113)
@@ -12,6 +12,7 @@
import java.io.File;
import java.io.IOException;
+import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -24,6 +25,7 @@
import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
@@ -37,6 +39,7 @@
import org.jboss.tools.common.xml.XMLUtilities;
import org.jboss.tools.jst.web.WebModelPlugin;
import org.jboss.tools.jst.web.kb.IKbProject;
+import org.jboss.tools.jst.web.kb.KbMessages;
import org.jboss.tools.jst.web.kb.KbProjectFactory;
import org.jboss.tools.jst.web.kb.WebKbPlugin;
import org.jboss.tools.jst.web.kb.internal.scanner.ClassPathMonitor;
@@ -848,4 +851,111 @@
}
}
+ /**
+ * Check if KB builder is installed and add a warning with quick fix to the project if
it is not.
+ * @param resource
+ */
+ public static boolean checkKBBuilderInstalled(IResource resource) {
+ IProject project = resource == null ? null : resource.getProject();
+ if (project == null)
+ return false; // Cannot check anything
+
+ boolean kbNatureFound = false;
+ boolean kbBuilderFound = false;
+ try {
+ kbNatureFound = (project.getNature(IKbProject.NATURE_ID) != null);
+
+ IProjectDescription description = project.getDescription();
+ ICommand command = null;
+ ICommand commands[] = description.getBuildSpec();
+ for (int i = 0; i < commands.length && command == null; ++i) {
+ if (commands[i].getBuilderName().equals(KbBuilder.BUILDER_ID)) {
+ kbBuilderFound = true;
+ break;
+ }
+ }
+ } catch (CoreException ex) {
+ WebKbPlugin.getDefault().logError(ex);
+ }
+
+ if (kbNatureFound && kbBuilderFound) {
+ // Find existing KBNATURE problem marker and kill it if exists
+ IMarker[] markers = getOwnedMarkers(project);
+ if (markers != null && markers.length > 0) {
+ for (IMarker m : markers) {
+ try {
+ project.deleteMarkers(KB_PROBLEM_MARKER_TYPE, true, IResource.DEPTH_ONE);
+ project.setPersistentProperty(KbProjectFactory.NATURE_MOCK, null);
+ } catch (CoreException ex) {
+ WebKbPlugin.getDefault().logError(ex);
+ }
+ }
+ }
+ return true;
+ }
+
+ // Find existing KBNATURE problem marker and install it if doesn't exist
+ IMarker[] markers = getOwnedMarkers(project);
+
+ if (markers == null || markers.length == 0) {
+ try {
+ IMarker m = createOrUpdateKbProblemMarker(null, project, !kbNatureFound,
!kbBuilderFound);
+ } catch (CoreException ex) {
+ WebKbPlugin.getDefault().logError(ex);
+ }
+ } else {
+ for (IMarker m : markers) {
+ try {
+ m = createOrUpdateKbProblemMarker(m, project, !kbNatureFound, !kbBuilderFound);
+ } catch (CoreException ex) {
+ WebKbPlugin.getDefault().logError(ex);
+ }
+ }
+ }
+ return false;
+ }
+
+ public static final String KB_PROBLEM_MARKER_TYPE =
"org.jboss.tools.jst.web.kb.kbproblemmarker"; //$NON-NLS-1$
+
+ private static IMarker[] getOwnedMarkers(IResource r) {
+ ArrayList<IMarker> l = null;
+ try {
+ IMarker[] ms = r.findMarkers(null, false, 1);
+ if(ms != null) {
+ for (int i = 0; i < ms.length; i++) {
+ if(ms[i] == null) continue;
+
+ String _type = ms[i].getType();
+ if(_type == null) continue;
+ if(!_type.equals(KB_PROBLEM_MARKER_TYPE)) continue;
+ if(!ms[i].isSubtypeOf(IMarker.PROBLEM)) continue;
+
+ if(l == null)
+ l = new ArrayList<IMarker>();
+
+ l.add(ms[i]);
+ }
+ }
+ } catch (CoreException e) {
+ WebKbPlugin.getDefault().logError(e);
+ }
+ return (l == null) ? null : l.toArray(new IMarker[0]);
+ }
+
+ private static IMarker createOrUpdateKbProblemMarker(IMarker m, IResource r, boolean
kbNatureIsAbsent, boolean kbBuilderIsAbsent) throws CoreException {
+ ArrayList<String> args = new ArrayList<String>();
+ args.add(kbNatureIsAbsent ? KbMessages.KBNATURE_NOT_FOUND : "");
//$NON-NLS-1$
+ args.add(kbBuilderIsAbsent ? KbMessages.KBBUILDER_NOT_FOUND : "");
//$NON-NLS-1$
+
+ String message = MessageFormat.format(KbMessages.KBPROBLEM, args.toArray());
+ if (m == null) {
+ m = r.createMarker(KB_PROBLEM_MARKER_TYPE);
+ r.setPersistentProperty(KbProjectFactory.NATURE_MOCK, "true");
//$NON-NLS-1$
+ KbProjectFactory.getKbProject(r.getProject(), true);
+ }
+ m.setAttribute(IMarker.MESSAGE, message);
+ m.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
+ m.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_NORMAL);
+ return m;
+ }
}
\ No newline at end of file