Author: scabanovich
Date: 2007-07-13 04:29:44 -0400 (Fri, 13 Jul 2007)
New Revision: 2421
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamCoreBuilder.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidationContext.java
Log:
EXIN-217 Seam model serialization to xml implemented; validation context stored/loaded
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamCoreBuilder.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamCoreBuilder.java 2007-07-13
07:19:17 UTC (rev 2420)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamCoreBuilder.java 2007-07-13
08:29:44 UTC (rev 2421)
@@ -97,7 +97,11 @@
incrementalBuild(delta, monitor);
}
}
- sp.store();
+ try {
+ sp.store();
+ } catch (Exception e) {
+ SeamCorePlugin.getPluginLog().logError("Error storing build results");
+ }
return null;
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java 2007-07-13
07:19:17 UTC (rev 2420)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java 2007-07-13
08:29:44 UTC (rev 2421)
@@ -29,7 +29,7 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
-import org.jboss.tools.common.util.FileUtil;
+import org.jboss.tools.common.xml.XMLUtilities;
import org.jboss.tools.seam.core.IBijectedAttribute;
import org.jboss.tools.seam.core.ISeamComponent;
import org.jboss.tools.seam.core.ISeamComponentDeclaration;
@@ -49,6 +49,7 @@
import org.jboss.tools.seam.internal.core.scanner.LoadedDeclarations;
import org.jboss.tools.seam.internal.core.scanner.lib.ClassPath;
import org.jboss.tools.seam.internal.core.validation.SeamValidationContext;
+import org.w3c.dom.Element;
/**
* @author Viacheslav Kabanovich
@@ -130,7 +131,11 @@
public void resolveStorage(boolean load) {
if(isStorageResolved) return;
if(load) {
- load();
+ try {
+ load();
+ } catch (Exception e) {
+ SeamCorePlugin.getPluginLog().logError(e);
+ }
} else {
isStorageResolved = true;
}
@@ -155,15 +160,10 @@
}
File file = getStorageFile();
if(file == null || !file.isFile()) return;
- String s = FileUtil.readFile(file);
- String[] ps = s.split("\n");
- for (int i = 0; i < ps.length; i++) {
- IPath path = new Path(ps[i].trim());
- if(sourcePaths.contains(path)) continue;
- IFile f = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
- if(f == null || !f.exists() || !f.isSynchronized(IResource.DEPTH_ZERO)) continue;
- SeamResourceVisitor b = new SeamResourceVisitor(this);
- b.visit(f);
+ Element root = XMLUtilities.getElement(file, null);
+ if(root != null) {
+ loadSourcePaths(root);
+ getValidationContext().load(root);
}
long e = System.currentTimeMillis();
@@ -175,16 +175,41 @@
* Stores results of last build, so that on exit/enter Eclipse
* load them without rebuilding project
*/
- public void store() {
+ public void store() throws Exception {
File file = getStorageFile();
file.getParentFile().mkdirs();
- StringBuffer sb = new StringBuffer();
+
+ Element root = XMLUtilities.createDocumentElement("seam-project");
+ storeSourcePaths(root);
+ if(validationContext != null) validationContext.store(root);
+
+ XMLUtilities.serialize(root, file.getAbsolutePath());
+ }
+
+ private void storeSourcePaths(Element root) {
+ Element sourcePathsElement = XMLUtilities.createElement(root,
"source-paths");
for (IPath path : sourcePaths) {
- sb.append(path.toString()).append('\n');
- }
- FileUtil.writeFile(file, sb.toString());
+ Element pathElement = XMLUtilities.createElement(sourcePathsElement,
"path");
+ pathElement.setAttribute("value", path.toString());
+ }
}
+ private void loadSourcePaths(Element root) {
+ Element sourcePathsElement = XMLUtilities.getUniqueChild(root,
"source-paths");
+ if(sourcePathsElement == null) return;
+ Element[] paths = XMLUtilities.getChildren(sourcePathsElement, "path");
+ if(paths != null) for (int i = 0; i < paths.length; i++) {
+ String p = paths[i].getAttribute("value");
+ if(p == null || p.trim().length() == 0) continue;
+ IPath path = new Path(p.trim());
+ if(sourcePaths.contains(path)) continue;
+ IFile f = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
+ if(f == null || !f.exists() || !f.isSynchronized(IResource.DEPTH_ZERO)) continue;
+ SeamResourceVisitor b = new SeamResourceVisitor(this);
+ b.visit(f);
+ }
+ }
+
private File getStorageFile() {
IPath path = SeamCorePlugin.getDefault().getStateLocation();
File file = new File(path.toFile(), "projects/" + project.getName());
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidationContext.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidationContext.java 2007-07-13
07:19:17 UTC (rev 2420)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidationContext.java 2007-07-13
08:29:44 UTC (rev 2421)
@@ -16,6 +16,10 @@
import java.util.Set;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.jboss.tools.common.xml.XMLUtilities;
+import org.jboss.tools.seam.core.SeamCorePlugin;
+import org.w3c.dom.Element;
/**
* Contains information for seam validators that must be saved between
@@ -80,4 +84,37 @@
resourcesByVariableName.clear();
variableNamesByResource.clear();
}
+
+ public void store(Element root) {
+ Element validation = XMLUtilities.createElement(root, "validation");
+ Set<String> variables = resourcesByVariableName.keySet();
+ for (String name: variables) {
+ Set<IPath> paths = resourcesByVariableName.get(name);
+ if(paths == null) continue;
+ for (IPath path: paths) {
+ Element linkedResource = XMLUtilities.createElement(validation,
"linked-resource");
+ linkedResource.setAttribute("name", name);
+ linkedResource.setAttribute("path", path.toString());
+ }
+ }
+ }
+
+ public void load(Element root) {
+ Element validation = XMLUtilities.getUniqueChild(root, "validation");
+ if(validation == null) return;
+ Element[] linkedResources = XMLUtilities.getChildren(validation,
"inked-resource");
+ if(linkedResources != null) for (int i = 0; i < linkedResources.length; i++) {
+ String name = linkedResources[i].getAttribute("name");
+ if(name == null || name.trim().length() == 0) continue;
+ String path = linkedResources[i].getAttribute("path");
+ if(path == null || path.trim().length() == 0) continue;
+ IPath pathObject = null;
+ try {
+ pathObject = new Path(path);
+ } catch (Exception e) {
+ SeamCorePlugin.getPluginLog().logError(e);
+ }
+ addLinkedResource(name, pathObject);
+ }
+ }
}
\ No newline at end of file