Author: scabanovich
Date: 2010-03-31 10:01:35 -0400 (Wed, 31 Mar 2010)
New Revision: 21150
Added:
trunk/common/plugins/org.jboss.tools.common.verification/src/org/jboss/tools/common/verification/vrules/core/resources/CommonValidator.java
Modified:
trunk/common/plugins/org.jboss.tools.common.verification/src/org/jboss/tools/common/verification/vrules/core/resources/VerifyBuilder.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-5827
Added:
trunk/common/plugins/org.jboss.tools.common.verification/src/org/jboss/tools/common/verification/vrules/core/resources/CommonValidator.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.verification/src/org/jboss/tools/common/verification/vrules/core/resources/CommonValidator.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.verification/src/org/jboss/tools/common/verification/vrules/core/resources/CommonValidator.java 2010-03-31
14:01:35 UTC (rev 21150)
@@ -0,0 +1,158 @@
+ /*******************************************************************************
+ * Copyright (c) 2007 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.verification.vrules.core.resources;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.eclipse.wst.validation.internal.core.ValidationException;
+import org.eclipse.wst.validation.internal.operations.IWorkbenchContext;
+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.model.XModel;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.filesystems.FileSystemsHelper;
+import org.jboss.tools.common.model.project.IModelNature;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.common.verification.vrules.VHelper;
+import org.jboss.tools.common.verification.vrules.VModel;
+import org.jboss.tools.common.verification.vrules.VObject;
+import org.jboss.tools.common.verification.vrules.VRule;
+import org.jboss.tools.common.verification.vrules.VTask;
+import org.jboss.tools.common.verification.vrules.layer.VModelFactory;
+
+/**
+ * This Manager invokes all dependent validators that should be invoked in one job.
+ * We need this one because wst validation framework does not let us invoke
+ * dependent validators in the same job.
+ * @author Alexey Kazakov
+ */
+public class CommonValidator implements IValidatorJob {
+
+ private static Set<IProject> validatingProjects = new HashSet<IProject>();
+
+ public CommonValidator() {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.wst.validation.internal.provisional.core.IValidatorJob#getSchedulingRule(org.eclipse.wst.validation.internal.provisional.core.IValidationContext)
+ */
+ public ISchedulingRule getSchedulingRule(IValidationContext helper) {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.eclipse.wst.validation.internal.provisional.core.IValidatorJob#validateInJob(org.eclipse.wst.validation.internal.provisional.core.IValidationContext,
org.eclipse.wst.validation.internal.provisional.core.IReporter)
+ */
+ public IStatus validateInJob(IValidationContext helper, IReporter reporter) throws
ValidationException {
+ IWorkbenchContext validationHelper = (IWorkbenchContext)helper;
+ IProject project = validationHelper.getProject();
+ String[] uris = validationHelper.getURIs();
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ if(project == null && uris != null && uris.length != 0) {
+ for (String s: uris) {
+ IProject f = root.getProject(new Path(s).segment(0));
+ if(f != null && f.exists()) {
+ project = f;
+ break;
+ }
+ }
+ }
+
+ if(project == null) {
+ return OK_STATUS;
+ }
+ IModelNature n = EclipseResourceUtil.getModelNature(project);
+ XModel model = n == null ? null : n.getModel();
+ if(model == null || VHelper.getManager() == null) {
+ return OK_STATUS;
+ }
+ VModel vmodel = VModelFactory.getModel(model);
+ if(vmodel == null) {
+ return OK_STATUS;
+ }
+ if(uris == null || uris.length == 0) {
+ XModelObject object = FileSystemsHelper.getWebInf(model);
+ if(object == null) {
+ return OK_STATUS;
+ }
+ VObject vobject = vmodel.getObjectByPath(object.getPath());
+ VRule[] rules = VHelper.getRules(VHelper.getManager(), vobject);
+ if(rules == null) return OK_STATUS;
+ VTask task = VHelper.getManager().createTask(vobject);
+ VTaskListenerImpl listener = new VTaskListenerImpl();
+ listener.setModel(model);
+ listener.setTask(task);
+ listener.setSignificance(VHelper.getManager().getMinSignificance());
+ task.addTaskListener(listener);
+ task.run();
+ task.removeTaskListener(listener);
+ return OK_STATUS;
+ }
+ List<IFile> files = new ArrayList<IFile>();
+ for (String uri: uris) {
+ IFile f = root.getFile(new Path(uri));
+ if(f != null && f.exists() && f.getProject() == project) {
+ files.add(f);
+ }
+ }
+ if(files.isEmpty()) {
+ return OK_STATUS;
+ }
+ IStatus status = OK_STATUS;
+ for (IFile file: files) {
+ XModelObject object = EclipseResourceUtil.getObjectByResource(file);
+ if(object == null) continue;
+ VObject vobject = vmodel.getObjectByPath(object.getPath());
+ if(vobject == null) continue;
+ VRule[] rules = VHelper.getRules(VHelper.getManager(), vobject);
+ if(rules == null) continue;
+ VTask task = VHelper.getManager().createTask(vobject);
+ VTaskListenerImpl listener = new VTaskListenerImpl();
+ listener.setModel(model);
+ listener.setTask(task);
+ listener.setSignificance(VHelper.getManager().getMinSignificance());
+ task.addTaskListener(listener);
+ task.run();
+ task.removeTaskListener(listener);
+ }
+ return status;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.eclipse.wst.validation.internal.provisional.core.IValidator#cleanup(org.eclipse.wst.validation.internal.provisional.core.IReporter)
+ */
+ public void cleanup(IReporter reporter) {
+ reporter = null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.eclipse.wst.validation.internal.provisional.core.IValidator#validate(org.eclipse.wst.validation.internal.provisional.core.IValidationContext,
org.eclipse.wst.validation.internal.provisional.core.IReporter)
+ */
+ public void validate(IValidationContext helper, IReporter reporter) throws
ValidationException {
+ validateInJob(helper, reporter);
+ }
+}
\ No newline at end of file
Property changes on:
trunk/common/plugins/org.jboss.tools.common.verification/src/org/jboss/tools/common/verification/vrules/core/resources/CommonValidator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/common/plugins/org.jboss.tools.common.verification/src/org/jboss/tools/common/verification/vrules/core/resources/VerifyBuilder.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.verification/src/org/jboss/tools/common/verification/vrules/core/resources/VerifyBuilder.java 2010-03-31
13:53:56 UTC (rev 21149)
+++
trunk/common/plugins/org.jboss.tools.common.verification/src/org/jboss/tools/common/verification/vrules/core/resources/VerifyBuilder.java 2010-03-31
14:01:35 UTC (rev 21150)
@@ -17,27 +17,27 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.jboss.tools.common.model.project.IModelNature;
-import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.common.verification.vrules.plugin.VerificationPlugin;
+//This builder is obsolete. It's functionality is moved to WTP's Validation
framework.
+//The builder is preserved for backward compatibility.
public class VerifyBuilder extends IncrementalProjectBuilder
{
public static final String BUILDER_ID = VerificationPlugin.PLUGIN_ID +
".verifybuilder"; //$NON-NLS-1$
- GlobalBuilderImpl builderImpl = null;
+// GlobalBuilderImpl builderImpl = null;
protected IProject[] build(int kind, Map args, IProgressMonitor monitor)
throws CoreException
{
- IProject currentProject = getProject();
- IModelNature n = EclipseResourceUtil.getModelNature(currentProject);
- if (n != null) {
- if(builderImpl == null) {
- builderImpl = new GlobalBuilderImpl();
- builderImpl.setModel(n.getModel());
- }
- builderImpl.execute(null);
- }
+// IProject currentProject = getProject();
+// IModelNature n = EclipseResourceUtil.getModelNature(currentProject);
+// if (n != null) {
+// if(builderImpl == null) {
+// builderImpl = new GlobalBuilderImpl();
+// builderImpl.setModel(n.getModel());
+// }
+// builderImpl.execute(null);
+// }
return null;
}