Author: dgolovin
Date: 2008-09-29 13:50:09 -0400 (Mon, 29 Sep 2008)
New Revision: 10545
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/XJob.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/AbstractExtendedXMLFileImpl.java
trunk/seam/tests/org.jboss.tools.seam.core.test/META-INF/MANIFEST.MF
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/AbstractSeamFacetTest.java
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/Seam2FacetInstallDelegateTest.java
Log:
fix JUnit test errors. Patch from Snjezana was applied for:
1) deleting projects
The waitForIdle() method must be called after the r.delete() method in the
AbstractSeamFacetTest.tearDown() method.
2) possible deadlock in the AbstractExtendedXMLFileImpl.runCheckerOnLoad() method
This method executes some workspace operations using the Display.getDefault().asyncExec()
method what causes a deadlock. Eclipse tries to solve this deadlock by deleting all locks
in the UI (main) thread and sometimes doesn't succeed.
The solution is to execute these operations using the WorkspaceJob job.
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/XJob.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/XJob.java 2008-09-29
17:43:14 UTC (rev 10544)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/XJob.java 2008-09-29
17:50:09 UTC (rev 10545)
@@ -1,154 +1,174 @@
-/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and 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:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.common.model;
-
-import java.util.*;
-
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.resources.WorkspaceJob;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.ui.internal.decorators.DecoratorManager;
-import org.eclipse.ui.progress.UIJob;
-import org.jboss.tools.common.model.plugin.ModelPlugin;
-import org.osgi.framework.Bundle;
-
-public class XJob extends WorkspaceJob {
- public static Object FAMILY_XJOB = new Object();
-
- public interface XRunnable extends Runnable {
- public String getId();
- }
-
- static XJob JOB = new XJob();
-
- public static void addRunnable(XRunnable runnable) {
- JOB.addRunnableInternal(runnable);
- }
-
- public static void addRunnableWithPriority(XRunnable runnable) {
- JOB.addRunnableInternalWithPriority(runnable);
- }
-
- public static void waitForJob() throws InterruptedException {
- Object[] o = {
- XJob.FAMILY_XJOB, ResourcesPlugin.FAMILY_AUTO_REFRESH,
ResourcesPlugin.FAMILY_AUTO_BUILD
- };
- while(true) {
- boolean stop = true;
- for (int i = 0; i < o.length; i++) {
- Job[] js = Platform.getJobManager().find(o[i]);
- if(js != null && js.length > 0) {
- Platform.getJobManager().join(o[i], new NullProgressMonitor());
- stop = false;
- }
- }
- if(stop) {
- Job running = getJobRunning(10);
- if(running != null) {
- running.join();
- stop = false;
- }
- }
- if(stop) break;
- }
- }
-
- public static Job getJobRunning(int iterationLimit) {
- Job[] js = Platform.getJobManager().find(null);
- Job dm = null;
- if(js != null) for (int i = 0; i < js.length; i++) {
- if(js[i].getState() == Job.RUNNING && js[i].getThread() !=
Thread.currentThread()) {
- if(js[i] instanceof UIJob) continue;
- if(js[i].belongsTo(DecoratorManager.FAMILY_DECORATE)) {
- dm = js[i];
- continue;
- }
- //TODO keep watching
- return js[i];
- }
- }
- if(dm != null) {
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- //ignore
- }
- if(iterationLimit > 0)
- return getJobRunning(iterationLimit - 1);
- }
- return null;
-
- }
-
- Set<String> ids = new HashSet<String>();
- List<XRunnable> list = new ArrayList<XRunnable>();
-
- public XJob() {
- super("JBoss Tools Model Update");
- setSystem(true);
- }
-
- public boolean belongsTo(Object family) {
- return family == FAMILY_XJOB;
- }
-
- void addRunnableInternal(XRunnable runnable) {
- synchronized (this) {
- if(ids.contains(runnable.getId())) return;
- ids.add(runnable.getId());
- list.add(runnable);
- }
- if(getState() == Job.NONE) {
- schedule(1000);
- }
- }
-
- void addRunnableInternalWithPriority(XRunnable runnable) {
- synchronized (this) {
- if(ids.contains(runnable.getId())) return;
- ids.add(runnable.getId());
- list.add(0, runnable);
- }
- if(getState() == Job.NONE) {
- schedule(0);
- }
- }
-
- @Override
- public IStatus runInWorkspace(IProgressMonitor monitor)
- throws CoreException {
- while(true) {
- XRunnable r = null;
- synchronized (this) {
- if(list.size() == 0) break;
- r = list.remove(0);
- }
- monitor.subTask(r.getId());
- int state = 0;
- Bundle b = Platform.getBundle("org.jboss.tools.common.model");
- state = b==null ? -1 : b.getState();
- if(state == Bundle.ACTIVE) {
- r.run();
- }
- synchronized (this) {
- ids.remove(r.getId());
- }
- }
- return Status.OK_STATUS;
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and 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:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.model;
+
+import java.util.*;
+
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.resources.WorkspaceJob;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.ui.internal.decorators.DecoratorManager;
+import org.eclipse.ui.progress.UIJob;
+import org.jboss.tools.common.model.plugin.ModelPlugin;
+import org.osgi.framework.Bundle;
+
+public class XJob extends WorkspaceJob {
+ public static Object FAMILY_XJOB = new Object();
+
+ private static boolean suspended = false;
+
+ public interface XRunnable extends Runnable {
+ public String getId();
+ }
+
+ static XJob JOB = new XJob();
+
+ public static void addRunnable(XRunnable runnable) {
+ JOB.addRunnableInternal(runnable);
+ }
+
+ public static void addRunnableWithPriority(XRunnable runnable) {
+ JOB.addRunnableInternalWithPriority(runnable);
+ }
+
+ public static void waitForJob() throws InterruptedException {
+ Object[] o = {
+ XJob.FAMILY_XJOB, ResourcesPlugin.FAMILY_AUTO_REFRESH,
ResourcesPlugin.FAMILY_AUTO_BUILD
+ };
+ while(true) {
+ boolean stop = true;
+ for (int i = 0; i < o.length; i++) {
+ Job[] js = Platform.getJobManager().find(o[i]);
+ if(js != null && js.length > 0) {
+ Platform.getJobManager().join(o[i], new NullProgressMonitor());
+ stop = false;
+ }
+ }
+ if(stop) {
+ Job running = getJobRunning(10);
+ if(running != null) {
+ running.join();
+ stop = false;
+ }
+ }
+ if(stop) break;
+ }
+ }
+
+ public static Job getJobRunning(int iterationLimit) {
+ Job[] js = Platform.getJobManager().find(null);
+ Job dm = null;
+ if(js != null) for (int i = 0; i < js.length; i++) {
+ if(js[i].getState() == Job.RUNNING && js[i].getThread() !=
Thread.currentThread()) {
+ if(js[i] instanceof UIJob) continue;
+ if(js[i].belongsTo(DecoratorManager.FAMILY_DECORATE)) {
+ dm = js[i];
+ continue;
+ }
+ //TODO keep watching
+ return js[i];
+ }
+ }
+ if(dm != null) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ //ignore
+ }
+ if(iterationLimit > 0)
+ return getJobRunning(iterationLimit - 1);
+ }
+ return null;
+
+ }
+
+ Set<String> ids = new HashSet<String>();
+ List<XRunnable> list = new ArrayList<XRunnable>();
+
+ public XJob() {
+ super("JBoss Tools Model Update");
+ setSystem(true);
+ }
+
+ public boolean belongsTo(Object family) {
+ return family == FAMILY_XJOB;
+ }
+
+ void addRunnableInternal(XRunnable runnable) {
+ if (!isSuspended()) {
+ synchronized (this) {
+ if (ids.contains(runnable.getId()))
+ return;
+ ids.add(runnable.getId());
+ list.add(runnable);
+ }
+ if (getState() == Job.NONE) {
+ schedule(1000);
+ }
+ }
+ }
+
+ void addRunnableInternalWithPriority(XRunnable runnable) {
+ if (!isSuspended()) {
+ synchronized (this) {
+ if (ids.contains(runnable.getId()))
+ return;
+ ids.add(runnable.getId());
+ list.add(0, runnable);
+ }
+ if (getState() == Job.NONE) {
+ schedule(0);
+ }
+ }
+ }
+
+ @Override
+ public IStatus runInWorkspace(IProgressMonitor monitor)
+ throws CoreException {
+ while(true) {
+ XRunnable r = null;
+ synchronized (this) {
+ if(list.size() == 0) break;
+ r = list.remove(0);
+ }
+ // monitor.subTask(r.getId()) is irrelevant for system jobs
+ //monitor.subTask(r.getId());
+ // XJob is a class from the org.jboss.tools.common.model plugin. This plugin must be
active
+ //int state = 0;
+ //Bundle b = Platform.getBundle("org.jboss.tools.common.model");
+ //state = b==null ? -1 : b.getState();
+ //if(state == Bundle.ACTIVE) {
+ if (!isSuspended()) {
+ r.run();
+ }
+ //}
+ synchronized (this) {
+ ids.remove(r.getId());
+ }
+ }
+ return Status.OK_STATUS;
+ }
+
+ public static boolean isSuspended() {
+ return suspended;
+ }
+
+ public static void setSuspended(boolean suspended) {
+ XJob.suspended = suspended;
+ }
+
+}
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/AbstractExtendedXMLFileImpl.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/AbstractExtendedXMLFileImpl.java 2008-09-29
17:43:14 UTC (rev 10544)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/AbstractExtendedXMLFileImpl.java 2008-09-29
17:50:09 UTC (rev 10545)
@@ -1,345 +1,361 @@
-/*
- * Created on February 20, 2003, 4:02 PM
- */
-
-package org.jboss.tools.common.model.filesystems.impl;
-
-import java.io.StringReader;
-import java.util.*;
-
-import org.eclipse.swt.widgets.Display;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-import org.jboss.tools.common.meta.XAttribute;
-import org.jboss.tools.common.model.*;
-import org.jboss.tools.common.model.engines.impl.EnginesLoader;
-import org.jboss.tools.common.model.filesystems.BodySource;
-import org.jboss.tools.common.model.filesystems.impl.AbstractXMLFileImpl;
-import org.jboss.tools.common.model.loaders.*;
-import org.jboss.tools.common.model.markers.ConstraintChecker;
-import org.jboss.tools.common.model.plugin.ModelPlugin;
-import org.jboss.tools.common.model.impl.*;
-import org.jboss.tools.common.model.util.*;
-
-/**
- *
- * @author valera & glory
- */
-public class AbstractExtendedXMLFileImpl extends AbstractXMLFileImpl {
- private static final long serialVersionUID = 7942041044569562286L;
- ConstraintChecker constraintChecker = new ConstraintChecker(this);
-
- public AbstractExtendedXMLFileImpl() {}
-
- public boolean hasChildren() {
- return true;
- }
-
- private static String ns =
".NAME.EXTENSION.overlapped.expanded._body_.actualBodyTimeStamp.correctBody.forceLoad.";
-
- public String get(String name) {
- if(name.equals("_hasErrors_")) {
- return super.get("isIncorrect");
- }
- if (getParent() != null && ns.indexOf("." + name +
".") < 0) {
- if(loadAttributeSeparately(name)) return super.get(name);
- loadChildren();
-
- }
- return super.get(name);
- }
-
- /**
- * Used to avoid file loading when only one attribute is required.
- * This must be used with caution. Now only uri attribute in tld
- * is processed as most critical.
- * @param xmlname
- * @return
- */
- protected boolean shouldLoadAttributeSeparately(String xmlname) {
- return false;
- }
-
- /**
- * @see shouldLoadAttributeSeparately.
- * @param xmlname
- * @return
- */
- private boolean loadAttributeSeparately(String xmlname) {
- BodySource source = getBodySource();
- if(source == null) return true;
- if(!shouldLoadAttributeSeparately(xmlname)) return false;
- if(xmlname == null || xmlname.length() == 0) return false;
- String oldvalue = super.get(xmlname);
- if(oldvalue != null && oldvalue.length() > 0) return true;
- String body = source.get();
- Document doc = XMLUtil.getDocument(new StringReader(body));
- if(doc == null) return false;
- Element element = doc.getDocumentElement();
- if(element == null) return false;
- XModelObjectLoaderUtil util = new XModelObjectLoaderUtil();
- util.setSaveEntity(false);
- String value = util.getAttribute(element, xmlname);
- if(value == null || value.length() == 0) return false;
- super.set(xmlname, value);
- return true;
- }
-
- public boolean isObjectEditable() {
- return super.isObjectEditable() &&
(!"yes".equals(get("_hasErrors_")));
- }
-
- protected void loadChildren() {
- BodySource source = getBodySource();
- if (source == null) return;
- super.setBodySource(null);
- XObjectLoader loader = XModelObjectLoaderUtil.getObjectLoader(this);
- String body = source.get();
- XModelObjectLoaderUtil.setTempBody(this, body);
- loader.load(this);
- if(!isIncorrect() && !isOverlapped()) {
- runCheckerOnLoad();
- }
- }
-
- void runCheckerOnLoad() {
- if(!isActive()) return;
- XModelObject s = getParent();
- while(s != null && s.getFileType() != XModelObject.SYSTEM) s =
s.getParent();
- if(s == null || !s.getModelEntity().getName().equals("FileSystemFolder"))
{
- return;
- }
- Runnable r = new Runnable() {
- public void run() {
- getResourceMarkers().clear();
- constraintChecker.check();
- }
- };
- Display.getDefault().asyncExec(r);
- }
-
- public void set(String name, String value) {
- super.set(name, value);
- if("incorrectBody".equals(name) && value.length() > 0) {
- set("isIncorrect", "yes");
-// setErrors(value, hasDTD(), !hasDTD()); //never validate dtd
- int resolution =
EntityXMLRegistration.getInstance().resolve(getModelEntity());
- if(EntityXMLRegistration.isSystemId(value)) resolution =
EntityXMLRegistration.UNRESOLVED;
- setErrors(value, resolution == EntityXMLRegistration.DTD, resolution ==
EntityXMLRegistration.SCHEMA);
- }
- }
-
- public String getAsText() {
- return get("body");
- }
-
- public void edit(String body) throws XModelException {
- edit(body, false);
- }
-
- protected boolean isForceLoadOn() {
- return "true".equals(get("forceLoad"));
- }
-
- public void edit(String body, boolean update) throws XModelException {
- if(body == null) return;
- if(!isForceLoadOn() && body.equals(getAsText())) return;
-
- String entity =
getModel().getEntityRecognizer().getEntityName(getAttributeValue("extension"),
body);
- if(!entity.equals(getModelEntity().getName())) {
- String[] errors = (body.length() == 0) ? null : XMLUtil.getXMLErrors(new
java.io.StringReader(body), false);
- if(errors == null || errors.length == 0) errors = new String[]{"Doctype has been
changed. Please save file for the change to take effect in object model. :0:0"};
- setErrors(body, errors);
- XModelImpl m = (XModelImpl)getModel();
- m.fireStructureChanged(this);
- if(!isOverlapped()) getResourceMarkers().update();
- return;
- }
-
- boolean errors1 = ("yes".equals(get("_hasErrors_")));
- AbstractExtendedXMLFileImpl f = getUpdatedFile(body, true);
- if(f == null) return;
- f.getChildren();
-
- XModelObjectImpl p = (XModelObjectImpl)getParent();
- XModelImpl m = (XModelImpl)getModel();
- boolean isOverlapped = isOverlapped();
- if(!isOverlapped) getResourceMarkers().clear();
- if(f.isIncorrect()) {
- getChildren();
- boolean fire = this.loaderError == null && f.loaderError != null;
- this.loaderError = f.loaderError;
- super.set("incorrectBody", f.get("incorrectBody"));
- super.set("isIncorrect", "yes");
- if(f.get("errors") != null) super.set("errors",
f.get("errors"));
-
- if(fire) changeTimeStamp();
- if(f.get("actualBodyTimeStamp") != null &&
!"-1".equals(f.get("actualBodyTimeStamp"))) {
- mergeAll(f, update);
- }
- m.fireStructureChanged(this);
- if(!isOverlapped) getResourceMarkers().update();
- } else if(isMergingChanges()) {
- set("correctBody", body);
- set("actualBodyTimeStamp", "0");
- mergeAll(f, update);
- set("actualBodyTimeStamp", "" + getTimeStamp());
- if(errors1) m.fireStructureChanged(this);
- if(!isOverlapped) constraintChecker.check();
- } else {
- //old edit by replace
- p.removeChild_0(this);
- p.addChild_0(f);
- m.fireStructureChanged(p);
- f.setModified(true);
- if(!isOverlapped) f.getResourceMarkers().update();
- }
- }
-
- protected void safeChangeTimeStamp() {
- boolean b = ("" +
getTimeStamp()).equals(get("actualBodyTimeStamp"));
- changeTimeStamp();
- if(b) set("actualBodyTimeStamp", "" + getTimeStamp());
- }
- protected void mergeAll(XModelObject f, boolean update) throws XModelException {
- merge(f, !update);
- }
-
- protected boolean isMergingChanges() {
- return true;
- }
-
- protected String getProcessEntity() {
- return null;
- }
-
- protected boolean hasDTD() {
- return true;
- }
-
- private AbstractExtendedXMLFileImpl getUpdatedFile(String body, boolean fire) {
- boolean errors1 = ("yes".equals(get("_hasErrors_")));
- loaderError = null;
-// setErrors(body, hasDTD(), !hasDTD()); //never validate dtd
- int resolution = EntityXMLRegistration.getInstance().resolve(getModelEntity());
- if(EntityXMLRegistration.isSystemId(body)) resolution =
EntityXMLRegistration.UNRESOLVED;
- setErrors(body, resolution == EntityXMLRegistration.DTD, resolution ==
EntityXMLRegistration.SCHEMA);
- boolean errors2 = (get("errors") != null &&
get("errors").length() > 0);
- if(errors1 && errors2) {
- super.set("incorrectBody".intern(), body);
- if(fire) {
- changeTimeStamp();
- if(isActive()) ((XModelImpl)getModel()).fireNodeChanged(this,
getPath());
- setModified(true);
- }
- }
- AbstractExtendedXMLFileImpl f =
(AbstractExtendedXMLFileImpl)getModel().createModelObject(getModelEntity().getName(),
null);
- f.setAttributeValue("name", getAttributeValue("name"));
- f.setAttributeValue("extension",
getAttributeValue("extension"));
- if(errors2) {
- f.set("incorrectBody", body);
- f.set("errors", super.get("errors"));
- }
- f.setBodySource(new SFBodySource(body));
- return f;
- }
-
- protected final void merge(XModelObject update, boolean fire) throws XModelException
{
- if(!"yes".equals(update.get("isIncorrect"))) {
- super.set("incorrectBody", "");
- super.set("isIncorrect","no");
- super.set("errors", "");
- loaderError = null;
- }
- if(update instanceof AbstractExtendedXMLFileImpl) {
- loaderError = ((AbstractExtendedXMLFileImpl)update).loaderError;
- }
- Map<String,XModelObject> map = getChildrenForSaveAsMap();
- Set<String> set = null;
- XModelObject[] cs = update.getChildren();
- String entity = getProcessEntity();
- for (int i = 0; i < cs.length; i++) {
- if(entity != null && entity.equals(cs[i].getModelEntity().getName()))
continue;
- XModelObject c = getChildByPath(cs[i].getPathPart());
- if(c == null) {
- if(set == null) set = EnginesLoader.getChildrenToRemove(map, update);
- c = EnginesLoader.findAppropriateChild(set, cs[i], map);
- if(c == null) {
- c = cs[i].copy();
- addChild(c);
- } else {
- EnginesLoader.merge(c, cs[i], fire);
- }
- } else
if(c.getModelEntity().getName().equals(cs[i].getModelEntity().getName())) {
- EnginesLoader.merge(c, cs[i], fire);
- } else {
- removeChild(c);
- addChild(cs[i].copy());
- }
- map.remove(c.getPathPart());
- }
- Iterator<XModelObject> it = map.values().iterator();
- while(it.hasNext()) {
- ((XModelObject)it.next()).removeFromParent();
- }
- boolean doFire = false;
- for (int i = 0; i < cs.length; i++) {
- XModelObject c = getChildByPath(cs[i].getPathPart());
- if(c == null) continue;
- int ci = getIndexOfChild(c);
- if(ci == i) continue;
- doFire = true;
- move(ci, i, false);
- }
- if(fire && doFire) ((XModelImpl)getModel()).fireStructureChanged(this);
- mergeAttributes(update, fire);
- }
-
- static String NO_MERGE_ATTRIBUTES =
".name.extension._lateload.isIncorrect.incorrectBody.expand.";
- void mergeAttributes(XModelObject update, boolean fire) throws XModelException {
- XAttribute[] as = update.getModelEntity().getAttributes();
- for (int i = 0; i < as.length; i++) {
- String n = as[i].getName();
- if(NO_MERGE_ATTRIBUTES.indexOf("." + n + ".") >= 0) continue;
- XModelObjectLoaderUtil.mergeAttributeComment(this, update, as[i], fire);
- String ov = getAttributeValue(n);
- String nv = update.getAttributeValue(n);
- if(ov == null || ov.equals(nv)) continue;
- if(fire) {
- getModel().changeObjectAttribute(this, n, nv);
- } else {
- setAttributeValue(n, nv);
- }
- }
- XModelObjectLoaderUtil.mergeFinalComment(this, update, fire);
- }
-
- private Map<String,XModelObject> getChildrenForSaveAsMap() {
- String entity = getProcessEntity();
- XModelObject[] cs = getChildrenForSave();
- Map<String,XModelObject> map = new HashMap<String,XModelObject>();
- for (int i = 0; i < cs.length; i++) {
- if(entity != null && entity.equals(cs[i].getModelEntity().getName()))
continue;
- map.put(cs[i].getPathPart(), cs[i]);
- }
- return map;
- }
-
-}
-
-class SFBodySource implements BodySource {
- String body;
-
- public SFBodySource(String body) {
- this.body = body;
- }
-
- public String get() {
- return body;
- }
-
- public boolean write(Object object) {
- return true;
- }
-}
+/*
+ * Created on February 20, 2003, 4:02 PM
+ */
+
+package org.jboss.tools.common.model.filesystems.impl;
+
+import java.io.StringReader;
+import java.util.*;
+
+import org.eclipse.core.resources.WorkspaceJob;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.swt.widgets.Display;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.jboss.tools.common.meta.XAttribute;
+import org.jboss.tools.common.model.*;
+import org.jboss.tools.common.model.engines.impl.EnginesLoader;
+import org.jboss.tools.common.model.filesystems.BodySource;
+import org.jboss.tools.common.model.filesystems.impl.AbstractXMLFileImpl;
+import org.jboss.tools.common.model.loaders.*;
+import org.jboss.tools.common.model.markers.ConstraintChecker;
+import org.jboss.tools.common.model.plugin.ModelPlugin;
+import org.jboss.tools.common.model.impl.*;
+import org.jboss.tools.common.model.util.*;
+
+/**
+ *
+ * @author valera & glory
+ */
+public class AbstractExtendedXMLFileImpl extends AbstractXMLFileImpl {
+ private static final long serialVersionUID = 7942041044569562286L;
+ ConstraintChecker constraintChecker = new ConstraintChecker(this);
+
+ public AbstractExtendedXMLFileImpl() {}
+
+ public boolean hasChildren() {
+ return true;
+ }
+
+ private static String ns =
".NAME.EXTENSION.overlapped.expanded._body_.actualBodyTimeStamp.correctBody.forceLoad.";
+
+ public String get(String name) {
+ if(name.equals("_hasErrors_")) {
+ return super.get("isIncorrect");
+ }
+ if (getParent() != null && ns.indexOf("." + name +
".") < 0) {
+ if(loadAttributeSeparately(name)) return super.get(name);
+ loadChildren();
+
+ }
+ return super.get(name);
+ }
+
+ /**
+ * Used to avoid file loading when only one attribute is required.
+ * This must be used with caution. Now only uri attribute in tld
+ * is processed as most critical.
+ * @param xmlname
+ * @return
+ */
+ protected boolean shouldLoadAttributeSeparately(String xmlname) {
+ return false;
+ }
+
+ /**
+ * @see shouldLoadAttributeSeparately.
+ * @param xmlname
+ * @return
+ */
+ private boolean loadAttributeSeparately(String xmlname) {
+ BodySource source = getBodySource();
+ if(source == null) return true;
+ if(!shouldLoadAttributeSeparately(xmlname)) return false;
+ if(xmlname == null || xmlname.length() == 0) return false;
+ String oldvalue = super.get(xmlname);
+ if(oldvalue != null && oldvalue.length() > 0) return true;
+ String body = source.get();
+ Document doc = XMLUtil.getDocument(new StringReader(body));
+ if(doc == null) return false;
+ Element element = doc.getDocumentElement();
+ if(element == null) return false;
+ XModelObjectLoaderUtil util = new XModelObjectLoaderUtil();
+ util.setSaveEntity(false);
+ String value = util.getAttribute(element, xmlname);
+ if(value == null || value.length() == 0) return false;
+ super.set(xmlname, value);
+ return true;
+ }
+
+ public boolean isObjectEditable() {
+ return super.isObjectEditable() &&
(!"yes".equals(get("_hasErrors_")));
+ }
+
+ protected void loadChildren() {
+ BodySource source = getBodySource();
+ if (source == null) return;
+ super.setBodySource(null);
+ XObjectLoader loader = XModelObjectLoaderUtil.getObjectLoader(this);
+ String body = source.get();
+ XModelObjectLoaderUtil.setTempBody(this, body);
+ loader.load(this);
+ if(!isIncorrect() && !isOverlapped()) {
+ runCheckerOnLoad();
+ }
+ }
+ WorkspaceJob checkerOnLoad = new WorkspaceJob("Checking on load...") {
+
+ @Override
+ public IStatus runInWorkspace(IProgressMonitor monitor)
+ throws CoreException {
+ getResourceMarkers().clear();
+ constraintChecker.check();
+ return Status.OK_STATUS;
+ }
+
+ };
+ void runCheckerOnLoad() {
+ if(!isActive()) return;
+ XModelObject s = getParent();
+ while(s != null && s.getFileType() != XModelObject.SYSTEM) s =
s.getParent();
+ if(s == null || !s.getModelEntity().getName().equals("FileSystemFolder"))
{
+ return;
+ }
+ /*Runnable r = new Runnable() {
+ public void run() {
+ getResourceMarkers().clear();
+ constraintChecker.check();
+ }
+ };
+ Display.getDefault().asyncExec(r);*/
+ checkerOnLoad.schedule();
+ }
+
+ public void set(String name, String value) {
+ super.set(name, value);
+ if("incorrectBody".equals(name) && value.length() > 0) {
+ set("isIncorrect", "yes");
+// setErrors(value, hasDTD(), !hasDTD()); //never validate dtd
+ int resolution =
EntityXMLRegistration.getInstance().resolve(getModelEntity());
+ if(EntityXMLRegistration.isSystemId(value)) resolution =
EntityXMLRegistration.UNRESOLVED;
+ setErrors(value, resolution == EntityXMLRegistration.DTD, resolution ==
EntityXMLRegistration.SCHEMA);
+ }
+ }
+
+ public String getAsText() {
+ return get("body");
+ }
+
+ public void edit(String body) throws XModelException {
+ edit(body, false);
+ }
+
+ protected boolean isForceLoadOn() {
+ return "true".equals(get("forceLoad"));
+ }
+
+ public void edit(String body, boolean update) throws XModelException {
+ if(body == null) return;
+ if(!isForceLoadOn() && body.equals(getAsText())) return;
+
+ String entity =
getModel().getEntityRecognizer().getEntityName(getAttributeValue("extension"),
body);
+ if(!entity.equals(getModelEntity().getName())) {
+ String[] errors = (body.length() == 0) ? null : XMLUtil.getXMLErrors(new
java.io.StringReader(body), false);
+ if(errors == null || errors.length == 0) errors = new String[]{"Doctype has been
changed. Please save file for the change to take effect in object model. :0:0"};
+ setErrors(body, errors);
+ XModelImpl m = (XModelImpl)getModel();
+ m.fireStructureChanged(this);
+ if(!isOverlapped()) getResourceMarkers().update();
+ return;
+ }
+
+ boolean errors1 = ("yes".equals(get("_hasErrors_")));
+ AbstractExtendedXMLFileImpl f = getUpdatedFile(body, true);
+ if(f == null) return;
+ f.getChildren();
+
+ XModelObjectImpl p = (XModelObjectImpl)getParent();
+ XModelImpl m = (XModelImpl)getModel();
+ boolean isOverlapped = isOverlapped();
+ if(!isOverlapped) getResourceMarkers().clear();
+ if(f.isIncorrect()) {
+ getChildren();
+ boolean fire = this.loaderError == null && f.loaderError != null;
+ this.loaderError = f.loaderError;
+ super.set("incorrectBody", f.get("incorrectBody"));
+ super.set("isIncorrect", "yes");
+ if(f.get("errors") != null) super.set("errors",
f.get("errors"));
+
+ if(fire) changeTimeStamp();
+ if(f.get("actualBodyTimeStamp") != null &&
!"-1".equals(f.get("actualBodyTimeStamp"))) {
+ mergeAll(f, update);
+ }
+ m.fireStructureChanged(this);
+ if(!isOverlapped) getResourceMarkers().update();
+ } else if(isMergingChanges()) {
+ set("correctBody", body);
+ set("actualBodyTimeStamp", "0");
+ mergeAll(f, update);
+ set("actualBodyTimeStamp", "" + getTimeStamp());
+ if(errors1) m.fireStructureChanged(this);
+ if(!isOverlapped) constraintChecker.check();
+ } else {
+ //old edit by replace
+ p.removeChild_0(this);
+ p.addChild_0(f);
+ m.fireStructureChanged(p);
+ f.setModified(true);
+ if(!isOverlapped) f.getResourceMarkers().update();
+ }
+ }
+
+ protected void safeChangeTimeStamp() {
+ boolean b = ("" +
getTimeStamp()).equals(get("actualBodyTimeStamp"));
+ changeTimeStamp();
+ if(b) set("actualBodyTimeStamp", "" + getTimeStamp());
+ }
+ protected void mergeAll(XModelObject f, boolean update) throws XModelException {
+ merge(f, !update);
+ }
+
+ protected boolean isMergingChanges() {
+ return true;
+ }
+
+ protected String getProcessEntity() {
+ return null;
+ }
+
+ protected boolean hasDTD() {
+ return true;
+ }
+
+ private AbstractExtendedXMLFileImpl getUpdatedFile(String body, boolean fire) {
+ boolean errors1 = ("yes".equals(get("_hasErrors_")));
+ loaderError = null;
+// setErrors(body, hasDTD(), !hasDTD()); //never validate dtd
+ int resolution = EntityXMLRegistration.getInstance().resolve(getModelEntity());
+ if(EntityXMLRegistration.isSystemId(body)) resolution =
EntityXMLRegistration.UNRESOLVED;
+ setErrors(body, resolution == EntityXMLRegistration.DTD, resolution ==
EntityXMLRegistration.SCHEMA);
+ boolean errors2 = (get("errors") != null &&
get("errors").length() > 0);
+ if(errors1 && errors2) {
+ super.set("incorrectBody".intern(), body);
+ if(fire) {
+ changeTimeStamp();
+ if(isActive()) ((XModelImpl)getModel()).fireNodeChanged(this,
getPath());
+ setModified(true);
+ }
+ }
+ AbstractExtendedXMLFileImpl f =
(AbstractExtendedXMLFileImpl)getModel().createModelObject(getModelEntity().getName(),
null);
+ f.setAttributeValue("name", getAttributeValue("name"));
+ f.setAttributeValue("extension",
getAttributeValue("extension"));
+ if(errors2) {
+ f.set("incorrectBody", body);
+ f.set("errors", super.get("errors"));
+ }
+ f.setBodySource(new SFBodySource(body));
+ return f;
+ }
+
+ protected final void merge(XModelObject update, boolean fire) throws XModelException
{
+ if(!"yes".equals(update.get("isIncorrect"))) {
+ super.set("incorrectBody", "");
+ super.set("isIncorrect","no");
+ super.set("errors", "");
+ loaderError = null;
+ }
+ if(update instanceof AbstractExtendedXMLFileImpl) {
+ loaderError = ((AbstractExtendedXMLFileImpl)update).loaderError;
+ }
+ Map<String,XModelObject> map = getChildrenForSaveAsMap();
+ Set<String> set = null;
+ XModelObject[] cs = update.getChildren();
+ String entity = getProcessEntity();
+ for (int i = 0; i < cs.length; i++) {
+ if(entity != null && entity.equals(cs[i].getModelEntity().getName()))
continue;
+ XModelObject c = getChildByPath(cs[i].getPathPart());
+ if(c == null) {
+ if(set == null) set = EnginesLoader.getChildrenToRemove(map, update);
+ c = EnginesLoader.findAppropriateChild(set, cs[i], map);
+ if(c == null) {
+ c = cs[i].copy();
+ addChild(c);
+ } else {
+ EnginesLoader.merge(c, cs[i], fire);
+ }
+ } else
if(c.getModelEntity().getName().equals(cs[i].getModelEntity().getName())) {
+ EnginesLoader.merge(c, cs[i], fire);
+ } else {
+ removeChild(c);
+ addChild(cs[i].copy());
+ }
+ map.remove(c.getPathPart());
+ }
+ Iterator<XModelObject> it = map.values().iterator();
+ while(it.hasNext()) {
+ ((XModelObject)it.next()).removeFromParent();
+ }
+ boolean doFire = false;
+ for (int i = 0; i < cs.length; i++) {
+ XModelObject c = getChildByPath(cs[i].getPathPart());
+ if(c == null) continue;
+ int ci = getIndexOfChild(c);
+ if(ci == i) continue;
+ doFire = true;
+ move(ci, i, false);
+ }
+ if(fire && doFire) ((XModelImpl)getModel()).fireStructureChanged(this);
+ mergeAttributes(update, fire);
+ }
+
+ static String NO_MERGE_ATTRIBUTES =
".name.extension._lateload.isIncorrect.incorrectBody.expand.";
+ void mergeAttributes(XModelObject update, boolean fire) throws XModelException {
+ XAttribute[] as = update.getModelEntity().getAttributes();
+ for (int i = 0; i < as.length; i++) {
+ String n = as[i].getName();
+ if(NO_MERGE_ATTRIBUTES.indexOf("." + n + ".") >= 0) continue;
+ XModelObjectLoaderUtil.mergeAttributeComment(this, update, as[i], fire);
+ String ov = getAttributeValue(n);
+ String nv = update.getAttributeValue(n);
+ if(ov == null || ov.equals(nv)) continue;
+ if(fire) {
+ getModel().changeObjectAttribute(this, n, nv);
+ } else {
+ setAttributeValue(n, nv);
+ }
+ }
+ XModelObjectLoaderUtil.mergeFinalComment(this, update, fire);
+ }
+
+ private Map<String,XModelObject> getChildrenForSaveAsMap() {
+ String entity = getProcessEntity();
+ XModelObject[] cs = getChildrenForSave();
+ Map<String,XModelObject> map = new HashMap<String,XModelObject>();
+ for (int i = 0; i < cs.length; i++) {
+ if(entity != null && entity.equals(cs[i].getModelEntity().getName()))
continue;
+ map.put(cs[i].getPathPart(), cs[i]);
+ }
+ return map;
+ }
+
+}
+
+class SFBodySource implements BodySource {
+ String body;
+
+ public SFBodySource(String body) {
+ this.body = body;
+ }
+
+ public String get() {
+ return body;
+ }
+
+ public boolean write(Object object) {
+ return true;
+ }
+}
Modified: trunk/seam/tests/org.jboss.tools.seam.core.test/META-INF/MANIFEST.MF
===================================================================
--- trunk/seam/tests/org.jboss.tools.seam.core.test/META-INF/MANIFEST.MF 2008-09-29
17:43:14 UTC (rev 10544)
+++ trunk/seam/tests/org.jboss.tools.seam.core.test/META-INF/MANIFEST.MF 2008-09-29
17:50:09 UTC (rev 10545)
@@ -1,37 +1,38 @@
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-Name: Seam Core Tests Plug-in
-Bundle-SymbolicName: org.jboss.tools.seam.core.test;singleton:=true
-Bundle-Version: 2.0.0
-Bundle-ClassPath: seam-core-tests.jar
-Bundle-Vendor: Red Hat, Inc.
-Export-Package: org.jboss.tools.seam.core.test,
- org.jboss.tools.seam.core.test.project.facet,
- org.jboss.tools.seam.core.test.refactoring
-Require-Bundle:
- org.junit,
- org.eclipse.core.runtime,
- org.eclipse.core.resources,
- org.jboss.tools.common.model,
- org.jboss.tools.seam.core,
- org.jboss.tools.seam.xml,
- org.jboss.tools.common.test,
- org.jboss.tools.jsf,
- org.eclipse.wst.common.project.facet.core,
- org.jboss.tools.tests,
- org.eclipse.ui.workbench,
- org.eclipse.wst.common.modulecore,
- org.eclipse.wst.common.frameworks,
- org.eclipse.jface,
- org.jboss.tools.jst.firstrun,
- org.eclipse.wst.server.core,
- org.eclipse.datatools.connectivity,
- org.eclipse.ltk.core.refactoring,
- org.eclipse.ltk.ui.refactoring,
- org.eclipse.jdt.core,
- org.eclipse.jdt.ui,
- org.eclipse.ui.ide,
- org.eclipse.jface,
- org.eclipse.jdt.core.manipulation,
- org.eclipse.jst.jsf.core
-Provide-Package: org.jboss.tools.seam.core.test
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Seam Core Tests Plug-in
+Bundle-SymbolicName: org.jboss.tools.seam.core.test;singleton:=true
+Bundle-Version: 2.0.0
+Bundle-ClassPath: seam-core-tests.jar
+Bundle-Vendor: Red Hat, Inc.
+Export-Package: org.jboss.tools.seam.core.test,
+ org.jboss.tools.seam.core.test.project.facet,
+ org.jboss.tools.seam.core.test.refactoring
+Require-Bundle:
+ org.junit,
+ org.eclipse.core.runtime,
+ org.eclipse.core.resources,
+ org.jboss.tools.common.model,
+ org.jboss.tools.seam.core,
+ org.jboss.tools.seam.xml,
+ org.jboss.tools.common.test,
+ org.jboss.tools.jsf,
+ org.eclipse.wst.common.project.facet.core,
+ org.jboss.tools.tests,
+ org.eclipse.ui.workbench,
+ org.eclipse.wst.common.modulecore,
+ org.eclipse.wst.common.frameworks,
+ org.eclipse.jface,
+ org.jboss.tools.jst.firstrun,
+ org.eclipse.wst.server.core,
+ org.eclipse.datatools.connectivity,
+ org.eclipse.ltk.core.refactoring,
+ org.eclipse.ltk.ui.refactoring,
+ org.eclipse.jdt.core,
+ org.eclipse.jdt.ui,
+ org.eclipse.ui.ide,
+ org.eclipse.jface,
+ org.eclipse.jdt.core.manipulation,
+ org.eclipse.jst.jsf.core,
+ org.eclipse.wst.validation
+Provide-Package: org.jboss.tools.seam.core.test
Modified:
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/AbstractSeamFacetTest.java
===================================================================
---
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/AbstractSeamFacetTest.java 2008-09-29
17:43:14 UTC (rev 10544)
+++
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/AbstractSeamFacetTest.java 2008-09-29
17:50:09 UTC (rev 10545)
@@ -102,17 +102,18 @@
// Wait until all jobs is finished to avoid delete project problems
- ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
- waitForIdle();
boolean oldAutoBuilding = true;
Exception last = null;
try {
- oldAutoBuilding = ResourcesUtils.setBuildAutomatically(false);
+ oldAutoBuilding = ResourcesUtils.setBuildAutomatically(false);
+ ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE,
null);
+ waitForIdle();
for (IResource r : this.resourcesToCleanup) {
try {
- System.out.println("Deleting " + r);
- r.getProject().close(null);
+ //System.out.println("Deleting " + r);
+ //r.getProject().close(null);
r.delete(true, null);
+ waitForIdle();
} catch(Exception e) {
System.out.println("Error deleting " + r);
e.printStackTrace();
@@ -132,7 +133,11 @@
public static void waitForIdle() {
long start = System.currentTimeMillis();
- while (!EditorTestHelper.allJobsQuiet()) {
+ // Job.getJobManager().isIdle() is more efficient than EditorTestHelper.allJobsQuiet()
+ // EditorTestHelper.allJobsQuiet() isn't thread-safe
+ //
https://bugs.eclipse.org/bugs/show_bug.cgi?id=198241 is fixed
+ //while (!EditorTestHelper.allJobsQuiet()) {
+ while (!Job.getJobManager().isIdle()) {
delay(500);
if ( (System.currentTimeMillis()-start) > MAX_IDLE )
throw new RuntimeException("A long running task detected"); //$NON-NLS-1$
@@ -245,22 +250,22 @@
assertNotNull("seam home folder was null!", folder);
assertTrue(folder.getAbsolutePath() + " does not exist", folder.exists());
- System.out.println("Listing " + folder);
+ //System.out.println("Listing " + folder);
File[] list = folder.listFiles();
for (int i = 0; i < list.length; i++) {
File string = list[i];
- System.out.println(i + ": " + string.getName() +(string.isDirectory()?"
(dir)":""));
+ //System.out.println(i + ": " + string.getName()
+(string.isDirectory()?" (dir)":""));
}
File seamgen = new File(folder, "seam-gen");
assertNotNull("seam gen folder was null!", seamgen);
assertTrue(seamgen.getName() + " seamgen does not exist", seamgen.exists());
- System.out.println("Listing seamgen " + seamgen);
+ //System.out.println("Listing seamgen " + seamgen);
list = seamgen.listFiles();
for (int i = 0; i < list.length; i++) {
File string = list[i];
- System.out.println(i + ": " + string.getName() +(string.isDirectory()?"
(dir)":""));
+ //System.out.println(i + ": " + string.getName()
+(string.isDirectory()?" (dir)":""));
}
}
Modified:
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/Seam2FacetInstallDelegateTest.java
===================================================================
---
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/Seam2FacetInstallDelegateTest.java 2008-09-29
17:43:14 UTC (rev 10544)
+++
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/Seam2FacetInstallDelegateTest.java 2008-09-29
17:50:09 UTC (rev 10545)
@@ -1,299 +1,330 @@
-/*******************************************************************************
- * 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
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.seam.core.test.project.facet;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IResourceProxy;
-import org.eclipse.core.resources.IResourceProxyVisitor;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
-import org.eclipse.wst.common.project.facet.core.IFacetedProject;
-import org.eclipse.wst.common.project.facet.core.IProjectFacet;
-import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
-import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
-import org.jboss.tools.seam.core.SeamProjectsSet;
-import org.jboss.tools.seam.core.project.facet.SeamRuntimeManager;
-import org.jboss.tools.seam.core.project.facet.SeamVersion;
-import org.jboss.tools.seam.internal.core.project.facet.ISeamFacetDataModelProperties;
-
-public class Seam2FacetInstallDelegateTest extends AbstractSeamFacetTest {
-
- protected static final String SEAM_2_0_0 = "Seam 2.0.0";
- IFacetedProject warProject;
- IFacetedProject earProject;
-
- private IProjectFacet seam2Facet;
- private IProjectFacetVersion seam2FacetVersion;
-
- public Seam2FacetInstallDelegateTest(String name) {
- super(name);
- }
-
- @Override
- protected void setUp() throws Exception {
- assertSeamHomeAvailable();
-
- seam2Facet = ProjectFacetsManager.getProjectFacet("jst.seam");
- seam2FacetVersion = seam2Facet.getVersion("2.0");
-
-
- File folder = getSeamHomeFolder();
-
- SeamRuntimeManager.getInstance().addRuntime(SEAM_2_0_0, folder.getAbsolutePath(),
SeamVersion.SEAM_2_0, true);
- SeamRuntimeManager.getInstance().findRuntimeByName(SEAM_2_0_0);
-
- warProject = createSeamWarProject("warprj");
- earProject = createSeamEarProject("earprj");
-
- warProject.getProject().getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE,
null);
-
-
-
- super.setUp();
- }
-
- @Override
- protected File getSeamHomeFolder() {
- return new File(System.getProperty("jbosstools.test.seam.2.0.1.GA.home",
- "E:\\Java\\JBoss\\Seam\\jboss-seam-2.0.1.GA"));
- }
-
- @Override
- protected IDataModel createSeamDataModel(String deployType) {
-
- IDataModel dataModel = super.createSeamDataModel(deployType);
- dataModel.setStringProperty(ISeamFacetDataModelProperties.SEAM_RUNTIME_NAME,
SEAM_2_0_0);
-
- return dataModel;
- }
-
-
- public void testWarLibs() throws CoreException {
-
- Set<String> seamgenlibs = new HashSet<String>();
-
-
- seamgenlibs.add("antlr-runtime.jar");
- seamgenlibs.add("commons-beanutils.jar");
- seamgenlibs.add("commons-digester.jar");
- seamgenlibs.add("drools-compiler.jar");
- seamgenlibs.add("drools-core.jar");
- seamgenlibs.add("core.jar");
- seamgenlibs.add("jboss-el.jar");
- seamgenlibs.add("jboss-seam-debug.jar");
- seamgenlibs.add("jboss-seam-ioc.jar");
- seamgenlibs.add("jboss-seam.jar");
- seamgenlibs.add("jboss-seam-mail.jar");
- seamgenlibs.add("jboss-seam-pdf.jar");
- seamgenlibs.add("jboss-seam-remoting.jar");
- seamgenlibs.add("jboss-seam-ui.jar");
- seamgenlibs.add("jbpm-jpdl.jar");
- seamgenlibs.add("jsf-facelets.jar");
- seamgenlibs.add("mvel14.jar");
- seamgenlibs.add("richfaces-api.jar");
- seamgenlibs.add("richfaces-impl.jar");
- seamgenlibs.add("richfaces-ui.jar");
-
- final IContainer warLibs = (IContainer)
warProject.getProject().findMember("WebContent/WEB-INF/lib").getAdapter(IContainer.class);
- assertOnlyContainsTheseFiles(seamgenlibs, warLibs);
-
-
- }
-
- public void testEarLibs() throws CoreException {
-
- IProject war = earProject.getProject();
-
- SeamProjectsSet seamProjectsSet = new SeamProjectsSet(earProject.getProject());
-
- IProject ear = seamProjectsSet.getEarProject();
-
- Set<String> onlyInWar = new HashSet<String>();
- Set<String> onlyInEar = new HashSet<String>();
- Set<String> onlyInEjbSrc = new HashSet<String>();
-
- onlyInEar.add("jboss-seam.jar");
- onlyInEar.add("antlr-runtime.jar");
- onlyInEar.add("drools-compiler.jar");
- onlyInEar.add("drools-core.jar");
- onlyInEar.add("jboss-el.jar");
- onlyInEar.add("mvel14.jar");
- onlyInEar.add("richfaces-api.jar");
- onlyInEar.add("jbpm-jpdl.jar");
- onlyInEar.add("META-INF");
-
- onlyInWar.add("commons-beanutils.jar");
- onlyInWar.add("commons-digester.jar");
- onlyInWar.add("jboss-seam-debug.jar");
- onlyInWar.add("jboss-seam-ioc.jar");
- onlyInWar.add("jboss-seam-mail.jar");
- onlyInWar.add("jboss-seam-pdf.jar");
- onlyInWar.add("jboss-seam-remoting.jar");
- onlyInWar.add("jboss-seam-ui.jar");
- onlyInWar.add("jsf-facelets.jar");
- onlyInWar.add("richfaces-impl.jar");
- onlyInWar.add("richfaces-ui.jar");
-
- final IContainer earLibs = (IContainer)
ear.findMember("EarContent").getAdapter(IContainer.class);
-
- assertOnlyContainsTheseFiles(onlyInEar, earLibs);
-
- final IContainer earMeta = (IContainer)
ear.findMember("EarContent/META-INF").getAdapter(IContainer.class);
-
- Set onlyInEarMeta = new HashSet();
-
- onlyInEarMeta.add("jboss-app.xml");
- onlyInEarMeta.add("application.xml");
-
- assertOnlyContainsTheseFiles(onlyInEarMeta, earMeta);
-
- assertOnlyContainsTheseFiles(onlyInWar,
(IContainer)war.findMember("WebContent/WEB-INF/lib").getAdapter(IContainer.class));
-
- IProject ejb = seamProjectsSet.getEjbProject();
-
- onlyInEjbSrc.add("security.drl");
- onlyInEjbSrc.add("seam.properties");
- onlyInEjbSrc.add("import.sql");
- onlyInEjbSrc.add("components.properties");
- onlyInEjbSrc.add("META-INF"); // JBIDE-2431: META-INF dir is always
created by Seam 2.0 seamgen
- onlyInEjbSrc.add("org"); // JBIDE-2431: org dir is always created by Seam
2.0 seamgen
-
- assertOnlyContainsTheseFiles(onlyInEjbSrc,
(IContainer)ejb.findMember("ejbModule").getAdapter(IContainer.class));
- }
-
-
- /**
- * Fails if set of fileNames is not found in dir or some other filename is found in
dir.
- * @param fileNames set of strings
- * @param dir directory to scan
- * @throws CoreException
- */
- protected void assertOnlyContainsTheseFiles(Set<String> fileNames,
- final IResource dir) throws CoreException {
-
- final Set<String> foundFiles = new HashSet<String>();
- dir.accept(new IResourceProxyVisitor() {
-
- public boolean visit(IResourceProxy proxy) throws CoreException {
- if(dir.getName().equals(proxy.getName())) return true;
- foundFiles.add(proxy.getName());
- return false;
- }
-
- }, IResource.DEPTH_ZERO);
-
- if(!foundFiles.containsAll(fileNames)) {
- fileNames.removeAll(foundFiles);
- fail("Did not find " + fileNames + " in " + dir);
- }
-
- foundFiles.removeAll(fileNames);
-
- assertTrue("Found additional files (" + foundFiles + " in " + dir +
" at " + dir.getLocation(), foundFiles.isEmpty());
- }
-
- public void testBootstrapDirPresent() throws CoreException, IOException {
-
- SeamProjectsSet warPs = new SeamProjectsSet(warProject.getProject());
-
- IProject testProject = warPs.getTestProject();
- assertTrue(testProject.exists());
-
- assertNotNull(testProject.findMember("bootstrap"));
- assertNotNull(testProject.findMember("bootstrap/data"));
-
- assertNull("embedded-ejb should not be installed for seam2",
testProject.findMember("embedded-ejb"));
-
- }
-
- public void testTestLibs() throws CoreException, IOException {
-
- SeamProjectsSet warPs = new SeamProjectsSet(warProject.getProject());
-
- IProject testProject = warPs.getTestProject();
- assertTrue(testProject.exists());
-
- Set<String> libs = new HashSet<String>();
- libs.add("testng.jar");
- libs.add("hibernate-all.jar");
-// libs.add("jboss-deployers.jar"); // JBIDE-2431: There is no such jar
created by Seam 2.0 seamgen
- libs.add("jboss-embedded-all.jar");
- libs.add("thirdparty-all.jar");
- libs.add("jboss-embedded-api.jar");
- libs.add("core.jar");
-
- assertOnlyContainsTheseFiles(libs, testProject.findMember("lib"));
-
- // JBIDE-2431: The following block is commented because it duplicates the call to
assertOnlyContainsTheseFiles()
-/*
- assertNotNull(testProject.findMember("lib/testng.jar"));
- assertNotNull(testProject.findMember("lib/hibernate-all.jar"));
-// assertNotNull(testProject.findMember("lib/jboss-deployers.jar")); //
JBIDE-2431: There is no such jar created by Seam 2.0 seamgen
- assertNotNull(testProject.findMember("lib/jboss-embedded-all.jar"));
- assertNotNull(testProject.findMember("lib/thirdparty-all.jar"));
- assertNotNull(testProject.findMember("lib/core.jar")); // JBIDE-2431:
lib/core.jar file is always created by Seam 2.0 seamgen
-*/
- }
-
- public void testSeamProperties() {
- SeamProjectsSet warPs = new SeamProjectsSet(warProject.getProject());
-
- IProject warProject = warPs.getWarProject();
- assertTrue(warProject.exists());
-
- assertNotNull(warProject.findMember("src/model/seam.properties"));
- IResource findMember = warProject.findMember("src/action/seam.properties");
- assertNotNull(findMember);
- assertTrue(findMember instanceof IFile);
-
- }
-
- public void testJbpmPresent() throws CoreException, IOException {
-
- SeamProjectsSet earPs = new SeamProjectsSet(earProject.getProject());
-
- IProject project = earPs.getEarProject();
- assertTrue(project.exists());
-
- assertNotNull(project.findMember("EarContent/jbpm-jpdl.jar"));
-
- }
-
- public void testDroolsPresent() throws CoreException, IOException {
-
-
- IProject earRoot = earProject.getProject();
- SeamProjectsSet seamProjectsSet = new SeamProjectsSet(earRoot);
-
- // JBIDE-2431: security.drl is always created in <EJBProject>/ejbModule directory
by Seam 2.0 seamgen
- IProject ejbProject = seamProjectsSet.getEjbProject();
- assertNotNull(ejbProject.findMember("ejbModule/security.drl"));
-
- }
-
- public void testCreateEar() throws CoreException, IOException {
-
-
- }
-
- @Override
- protected IProjectFacetVersion getSeamFacetVersion() {
- return seam2FacetVersion;
- }
-}
+/*******************************************************************************
+ * 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
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.core.test.project.facet;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceProxy;
+import org.eclipse.core.resources.IResourceProxyVisitor;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.IProjectFacet;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
+import org.eclipse.wst.validation.ValidationFramework;
+import org.eclipse.wst.validation.internal.EventManager;
+import org.eclipse.wst.validation.internal.ValOperationManager;
+import org.jboss.tools.common.model.XJob;
+import org.jboss.tools.seam.core.SeamProjectsSet;
+import org.jboss.tools.seam.core.project.facet.SeamRuntimeManager;
+import org.jboss.tools.seam.core.project.facet.SeamVersion;
+import org.jboss.tools.seam.internal.core.project.facet.ISeamFacetDataModelProperties;
+
+public class Seam2FacetInstallDelegateTest extends AbstractSeamFacetTest {
+
+ protected static final String SEAM_2_0_0 = "Seam 2.0.0";
+ IFacetedProject warProject;
+ IFacetedProject earProject;
+
+ private IProjectFacet seam2Facet;
+ private IProjectFacetVersion seam2FacetVersion;
+ private boolean suspendAllValidation;
+ private boolean suspendXJobs;
+
+ public Seam2FacetInstallDelegateTest(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ suspendAllValidation = ValidationFramework.getDefault().isSuspended();
+ ValidationFramework.getDefault().suspendAllValidation(true);
+
+ ws.removeResourceChangeListener( EventManager.getManager() );
+ ws.removeResourceChangeListener( ValOperationManager.getDefault() );
+ //EventManager.getManager().shutdown();
+
+ suspendXJobs = XJob.isSuspended();
+ XJob.setSuspended(true);
+ assertSeamHomeAvailable();
+
+ seam2Facet = ProjectFacetsManager.getProjectFacet("jst.seam");
+ seam2FacetVersion = seam2Facet.getVersion("2.0");
+
+
+ File folder = getSeamHomeFolder();
+
+ SeamRuntimeManager.getInstance().addRuntime(SEAM_2_0_0, folder.getAbsolutePath(),
SeamVersion.SEAM_2_0, true);
+ SeamRuntimeManager.getInstance().findRuntimeByName(SEAM_2_0_0);
+
+ warProject = createSeamWarProject("warprj");
+ earProject = createSeamEarProject("earprj");
+
+ warProject.getProject().getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE,
null);
+
+
+
+ super.setUp();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ ValidationFramework.getDefault().suspendAllValidation(suspendAllValidation);
+ XJob.setSuspended(suspendXJobs);
+
+ ws.addResourceChangeListener(EventManager.getManager(),
+ IResourceChangeEvent.PRE_CLOSE | IResourceChangeEvent.PRE_DELETE |
+ IResourceChangeEvent.POST_BUILD | IResourceChangeEvent.PRE_BUILD |
IResourceChangeEvent.POST_CHANGE);
+ ws.addResourceChangeListener(ValOperationManager.getDefault(),
+ IResourceChangeEvent.POST_BUILD | IResourceChangeEvent.PRE_BUILD);
+
+ }
+
+ @Override
+ protected File getSeamHomeFolder() {
+ return new File(System.getProperty("jbosstools.test.seam.2.0.1.GA.home",
+ "E:\\Java\\JBoss\\Seam\\jboss-seam-2.0.1.GA"));
+ }
+
+ @Override
+ protected IDataModel createSeamDataModel(String deployType) {
+
+ IDataModel dataModel = super.createSeamDataModel(deployType);
+ dataModel.setStringProperty(ISeamFacetDataModelProperties.SEAM_RUNTIME_NAME,
SEAM_2_0_0);
+
+ return dataModel;
+ }
+
+
+ public void testWarLibs() throws CoreException {
+
+ Set<String> seamgenlibs = new HashSet<String>();
+
+
+ seamgenlibs.add("antlr-runtime.jar");
+ seamgenlibs.add("commons-beanutils.jar");
+ seamgenlibs.add("commons-digester.jar");
+ seamgenlibs.add("drools-compiler.jar");
+ seamgenlibs.add("drools-core.jar");
+ seamgenlibs.add("core.jar");
+ seamgenlibs.add("jboss-el.jar");
+ seamgenlibs.add("jboss-seam-debug.jar");
+ seamgenlibs.add("jboss-seam-ioc.jar");
+ seamgenlibs.add("jboss-seam.jar");
+ seamgenlibs.add("jboss-seam-mail.jar");
+ seamgenlibs.add("jboss-seam-pdf.jar");
+ seamgenlibs.add("jboss-seam-remoting.jar");
+ seamgenlibs.add("jboss-seam-ui.jar");
+ seamgenlibs.add("jbpm-jpdl.jar");
+ seamgenlibs.add("jsf-facelets.jar");
+ seamgenlibs.add("mvel14.jar");
+ seamgenlibs.add("richfaces-api.jar");
+ seamgenlibs.add("richfaces-impl.jar");
+ seamgenlibs.add("richfaces-ui.jar");
+
+ final IContainer warLibs = (IContainer)
warProject.getProject().findMember("WebContent/WEB-INF/lib").getAdapter(IContainer.class);
+ assertOnlyContainsTheseFiles(seamgenlibs, warLibs);
+
+
+ }
+
+ public void testEarLibs() throws CoreException {
+
+ IProject war = earProject.getProject();
+
+ SeamProjectsSet seamProjectsSet = new SeamProjectsSet(earProject.getProject());
+
+ IProject ear = seamProjectsSet.getEarProject();
+
+ Set<String> onlyInWar = new HashSet<String>();
+ Set<String> onlyInEar = new HashSet<String>();
+ Set<String> onlyInEjbSrc = new HashSet<String>();
+
+ onlyInEar.add("jboss-seam.jar");
+ onlyInEar.add("antlr-runtime.jar");
+ onlyInEar.add("drools-compiler.jar");
+ onlyInEar.add("drools-core.jar");
+ onlyInEar.add("jboss-el.jar");
+ onlyInEar.add("mvel14.jar");
+ onlyInEar.add("richfaces-api.jar");
+ onlyInEar.add("jbpm-jpdl.jar");
+ onlyInEar.add("META-INF");
+
+ onlyInWar.add("commons-beanutils.jar");
+ onlyInWar.add("commons-digester.jar");
+ onlyInWar.add("jboss-seam-debug.jar");
+ onlyInWar.add("jboss-seam-ioc.jar");
+ onlyInWar.add("jboss-seam-mail.jar");
+ onlyInWar.add("jboss-seam-pdf.jar");
+ onlyInWar.add("jboss-seam-remoting.jar");
+ onlyInWar.add("jboss-seam-ui.jar");
+ onlyInWar.add("jsf-facelets.jar");
+ onlyInWar.add("richfaces-impl.jar");
+ onlyInWar.add("richfaces-ui.jar");
+
+ final IContainer earLibs = (IContainer)
ear.findMember("EarContent").getAdapter(IContainer.class);
+
+ assertOnlyContainsTheseFiles(onlyInEar, earLibs);
+
+ final IContainer earMeta = (IContainer)
ear.findMember("EarContent/META-INF").getAdapter(IContainer.class);
+
+ Set onlyInEarMeta = new HashSet();
+
+ onlyInEarMeta.add("jboss-app.xml");
+ onlyInEarMeta.add("application.xml");
+
+ assertOnlyContainsTheseFiles(onlyInEarMeta, earMeta);
+
+ assertOnlyContainsTheseFiles(onlyInWar,
(IContainer)war.findMember("WebContent/WEB-INF/lib").getAdapter(IContainer.class));
+
+ IProject ejb = seamProjectsSet.getEjbProject();
+
+ onlyInEjbSrc.add("security.drl");
+ onlyInEjbSrc.add("seam.properties");
+ onlyInEjbSrc.add("import.sql");
+ onlyInEjbSrc.add("components.properties");
+ onlyInEjbSrc.add("META-INF"); // JBIDE-2431: META-INF dir is always
created by Seam 2.0 seamgen
+ onlyInEjbSrc.add("org"); // JBIDE-2431: org dir is always created by Seam
2.0 seamgen
+
+ assertOnlyContainsTheseFiles(onlyInEjbSrc,
(IContainer)ejb.findMember("ejbModule").getAdapter(IContainer.class));
+ }
+
+
+ /**
+ * Fails if set of fileNames is not found in dir or some other filename is found in
dir.
+ * @param fileNames set of strings
+ * @param dir directory to scan
+ * @throws CoreException
+ */
+ protected void assertOnlyContainsTheseFiles(Set<String> fileNames,
+ final IResource dir) throws CoreException {
+
+ final Set<String> foundFiles = new HashSet<String>();
+ dir.accept(new IResourceProxyVisitor() {
+
+ public boolean visit(IResourceProxy proxy) throws CoreException {
+ if(dir.getName().equals(proxy.getName())) return true;
+ foundFiles.add(proxy.getName());
+ return false;
+ }
+
+ }, IResource.DEPTH_ZERO);
+
+ if(!foundFiles.containsAll(fileNames)) {
+ fileNames.removeAll(foundFiles);
+ fail("Did not find " + fileNames + " in " + dir);
+ }
+
+ foundFiles.removeAll(fileNames);
+
+ assertTrue("Found additional files (" + foundFiles + " in " + dir +
" at " + dir.getLocation(), foundFiles.isEmpty());
+ }
+
+ public void testBootstrapDirPresent() throws CoreException, IOException {
+
+ SeamProjectsSet warPs = new SeamProjectsSet(warProject.getProject());
+
+ IProject testProject = warPs.getTestProject();
+ assertTrue(testProject.exists());
+
+ assertNotNull(testProject.findMember("bootstrap"));
+ assertNotNull(testProject.findMember("bootstrap/data"));
+
+ assertNull("embedded-ejb should not be installed for seam2",
testProject.findMember("embedded-ejb"));
+
+ }
+
+ public void testTestLibs() throws CoreException, IOException {
+
+ SeamProjectsSet warPs = new SeamProjectsSet(warProject.getProject());
+
+ IProject testProject = warPs.getTestProject();
+ assertTrue(testProject.exists());
+
+ Set<String> libs = new HashSet<String>();
+ libs.add("testng.jar");
+ libs.add("hibernate-all.jar");
+// libs.add("jboss-deployers.jar"); // JBIDE-2431: There is no such jar
created by Seam 2.0 seamgen
+ libs.add("jboss-embedded-all.jar");
+ libs.add("thirdparty-all.jar");
+ libs.add("jboss-embedded-api.jar");
+ libs.add("core.jar");
+
+ assertOnlyContainsTheseFiles(libs, testProject.findMember("lib"));
+
+ // JBIDE-2431: The following block is commented because it duplicates the call to
assertOnlyContainsTheseFiles()
+/*
+ assertNotNull(testProject.findMember("lib/testng.jar"));
+ assertNotNull(testProject.findMember("lib/hibernate-all.jar"));
+// assertNotNull(testProject.findMember("lib/jboss-deployers.jar")); //
JBIDE-2431: There is no such jar created by Seam 2.0 seamgen
+ assertNotNull(testProject.findMember("lib/jboss-embedded-all.jar"));
+ assertNotNull(testProject.findMember("lib/thirdparty-all.jar"));
+ assertNotNull(testProject.findMember("lib/core.jar")); // JBIDE-2431:
lib/core.jar file is always created by Seam 2.0 seamgen
+*/
+ }
+
+ public void testSeamProperties() {
+ SeamProjectsSet warPs = new SeamProjectsSet(warProject.getProject());
+
+ IProject warProject = warPs.getWarProject();
+ assertTrue(warProject.exists());
+
+ assertNotNull(warProject.findMember("src/model/seam.properties"));
+ IResource findMember = warProject.findMember("src/action/seam.properties");
+ assertNotNull(findMember);
+ assertTrue(findMember instanceof IFile);
+
+ }
+
+ public void testJbpmPresent() throws CoreException, IOException {
+
+ SeamProjectsSet earPs = new SeamProjectsSet(earProject.getProject());
+
+ IProject project = earPs.getEarProject();
+ assertTrue(project.exists());
+
+ assertNotNull(project.findMember("EarContent/jbpm-jpdl.jar"));
+
+ }
+
+ public void testDroolsPresent() throws CoreException, IOException {
+
+
+ IProject earRoot = earProject.getProject();
+ SeamProjectsSet seamProjectsSet = new SeamProjectsSet(earRoot);
+
+ // JBIDE-2431: security.drl is always created in <EJBProject>/ejbModule directory
by Seam 2.0 seamgen
+ IProject ejbProject = seamProjectsSet.getEjbProject();
+ assertNotNull(ejbProject.findMember("ejbModule/security.drl"));
+
+ }
+
+ public void testCreateEar() throws CoreException, IOException {
+
+
+ }
+
+ @Override
+ protected IProjectFacetVersion getSeamFacetVersion() {
+ return seam2FacetVersion;
+ }
+}