Author: scabanovich
Date: 2010-10-13 10:21:53 -0400 (Wed, 13 Oct 2010)
New Revision: 25789
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/WebKbPlugin.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/KbBuilder.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/KbProject.java
Log:
JBIDE-7319
https://jira.jboss.org/browse/JBIDE-7319
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/WebKbPlugin.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/WebKbPlugin.java 2010-10-13
14:10:07 UTC (rev 25788)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/WebKbPlugin.java 2010-10-13
14:21:53 UTC (rev 25789)
@@ -1,6 +1,18 @@
package org.jboss.tools.jst.web.kb;
+import java.io.File;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ISaveContext;
+import org.eclipse.core.resources.ISaveParticipant;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.jboss.tools.common.log.BaseUIPlugin;
+import org.jboss.tools.jst.web.kb.internal.KbProject;
import org.osgi.framework.BundleContext;
/**
@@ -27,8 +39,76 @@
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
+
+ ResourcesPlugin.getWorkspace().addSaveParticipant(PLUGIN_ID, new ISaveParticipant() {
+
+ public void saving(ISaveContext context)
+ throws CoreException {
+ switch (context.getKind()) {
+ case ISaveContext.SNAPSHOT:
+ case ISaveContext.FULL_SAVE:
+ IProject[] ps = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ for (IProject p: ps) {
+ KbProject sp = (KbProject)KbProjectFactory.getKbProject(p, false);
+ if(sp != null && sp.getModificationsSinceLastStore() > 0) {
+// sp.printModifications();
+ try {
+ sp.store();
+ } catch (IOException e) {
+ WebKbPlugin.getDefault().logError(e);
+ }
+ }
+ }
+ break;
+ case ISaveContext.PROJECT_SAVE:
+ KbProject sp = (KbProject)KbProjectFactory.getKbProject(context.getProject(),
false);
+ try {
+ if(sp != null && sp.getModificationsSinceLastStore() > 0) {
+// sp.printModifications();
+ //Not any project is a seam project
+ sp.store();
+ }
+ } catch (IOException e) {
+ WebKbPlugin.getDefault().logError(e);
+ }
+ break;
+ }
+
+ cleanObsoleteFiles();
+ }
+
+ public void rollback(ISaveContext context) {
+
+ }
+
+ public void prepareToSave(ISaveContext context) throws CoreException {
+ }
+
+ public void doneSaving(ISaveContext context) {
+ }
+ });
}
+ private void cleanObsoleteFiles() {
+ IProject[] ps = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ Set<String> projectNames = new HashSet<String>();
+ for (IProject p: ps) projectNames.add(p.getName());
+ IPath path = WebKbPlugin.getDefault().getStateLocation();
+ File file = new File(path.toFile(), "projects"); //$NON-NLS-1$
+ if(!file.isDirectory()) return;
+ File[] fs = file.listFiles();
+ if(fs != null) for (File f: fs) {
+ String name = f.getName();
+ if(name.endsWith(".xml")) { //$NON-NLS-1$
+ name = name.substring(0, name.length() - 4);
+ if(!projectNames.contains(name)) {
+ f.delete();
+ }
+ }
+ }
+
+ }
+
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/KbBuilder.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/KbBuilder.java 2010-10-13
14:10:07 UTC (rev 25788)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/KbBuilder.java 2010-10-13
14:21:53 UTC (rev 25789)
@@ -114,11 +114,11 @@
}
long end = System.currentTimeMillis();
sp.fullBuildTime += end - begin;
- try {
- sp.store();
- } catch (IOException e) {
- WebModelPlugin.getPluginLog().logError(e);
- }
+// try {
+// sp.store();
+// } catch (IOException e) {
+// WebModelPlugin.getPluginLog().logError(e);
+// }
// sp.postBuild();
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 2010-10-13
14:10:07 UTC (rev 25788)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/KbProject.java 2010-10-13
14:21:53 UTC (rev 25789)
@@ -81,6 +81,8 @@
LibraryStorage libraries = new LibraryStorage();
ProjectValidationContext validationContext;
+
+ int modifications = 0;
public KbProject() {}
@@ -229,6 +231,7 @@
*/
public void removeKbProject(KbProject p) {
if(!dependsOn.contains(p)) return;
+ modifications++;
p.removeDependentKbProject(this);
removeUsedKbProject(p);
IPath[] ps = null;
@@ -309,6 +312,8 @@
} finally {
fireChanges();
+
+ modifications = 0;
}
}
@@ -369,6 +374,11 @@
return end - begin;
}
+ public int getModificationsSinceLastStore() {
+ return modifications +
+ (validationContext == null ? 0 : validationContext.getModificationsSinceLastStore());
+ }
+
/**
* Stores results of last build, so that on exit/enter Eclipse
* load them without rebuilding project
@@ -391,6 +401,8 @@
if(validationContext != null) validationContext.store(root);
XMLUtilities.serialize(root, file.getAbsolutePath());
+
+ modifications = 0;
}
/*
@@ -527,6 +539,8 @@
System.out.println("--->" + statistics.size() + " " + (t2 -
t1)); //$NON-NLS-1$ //$NON-NLS-2$
System.out.println("stop"); //$NON-NLS-1$
}
+ } else {
+ System.out.println((t2 - t1));
}
}
}
@@ -657,6 +671,7 @@
* @param source
*/
public void registerComponents(LoadedDeclarations ds, IPath source) {
+ boolean isThisProject = pathCheck.isThisProject(source);
ITagLibrary[] libraries = ds.getLibraries().toArray(new ITagLibrary[0]);
if(libraries.length == 0) {
@@ -695,7 +710,7 @@
if(uriChanged) {
this.libraries.addLibrary(current);
}
- fireChanges(changes);
+ fireChanges(changes, isThisProject);
continue;
}
if(((KbObject)library).getParent() == null) {
@@ -704,7 +719,7 @@
this.libraries.addLibrary(library);
addedLibraries = Change.addChange(addedLibraries, new Change(this, null, null,
loaded));
}
- fireChanges(addedLibraries);
+ fireChanges(addedLibraries, isThisProject);
libraryDeclarationsRemoved(currentLibraries);
@@ -771,8 +786,9 @@
Set<ITagLibrary> ls = libraries.removePath(source);
if(ls != null) for (ITagLibrary l: ls) {
changes = Change.addChange(changes, new Change(this, null, l, null));
+ if(l.getResource() != null && l.getResource().getProject() == project)
modifications++;
}
- fireChanges(changes);
+ fireChanges(changes, false);
firePathRemovedToDependentProjects(source);
}
@@ -816,7 +832,7 @@
libraries.removeLibrary(c);
changes = Change.addChange(changes, new Change(this, null, c, null));
}
- fireChanges(changes);
+ fireChanges(changes, false);
}
List<Change> postponedChanges = null;
@@ -831,15 +847,16 @@
if(postponedChanges == null) return;
List<Change> changes = postponedChanges;
postponedChanges = null;
- fireChanges(changes);
+ fireChanges(changes, false);
}
/**
*
* @param changes
*/
- void fireChanges(List<Change> changes) {
+ void fireChanges(List<Change> changes, boolean increaseModification) {
if(changes == null || changes.isEmpty()) return;
+ if(increaseModification) modifications++;
if(postponedChanges != null) {
postponedChanges.addAll(changes);
return;
@@ -954,4 +971,33 @@
m.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_NORMAL);
return m;
}
+
+ PathCheck pathCheck = new PathCheck();
+
+ class PathCheck {
+ Map<IPath, Boolean> paths = new HashMap<IPath, Boolean>();
+
+ public boolean isThisProject(IPath path) {
+ Boolean b = paths.get(path);
+ if(b == null) {
+ if(path != null && path.toString().endsWith(".jar")) {
//$NON-NLS-1$
+ b = true;
+ } else {
+ IFile f = path.segmentCount() < 2 ? null :
ResourcesPlugin.getWorkspace().getRoot().getFile(path);
+ b = !(f != null && f.exists() && f.getProject() != project);
+ }
+ paths.put(path, b);
+ }
+ return b.booleanValue();
+ }
+
+ }
+
+ public void printModifications() {
+ System.out.println(project.getName());
+ System.out.println("" + modifications);
+ if(validationContext != null)
+ System.out.println("validationContext " +
validationContext.getModificationsSinceLastStore());
+ }
+
}
\ No newline at end of file