Author: dgolovin
Date: 2010-05-28 15:40:10 -0400 (Fri, 28 May 2010)
New Revision: 22417
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/SeamCorePlugin.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/SeamResourceVisitor.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/JavaScanner.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/ClassPath.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/LibraryScanner.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/xml/PropertiesScanner.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/xml/XMLScanner.java
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/ScannerTest.java
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamBigProjectTest.java
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:
Performance fix for seam.
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 2010-05-28
19:17:47 UTC (rev 22416)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamCoreBuilder.java 2010-05-28
19:40:10 UTC (rev 22417)
@@ -10,17 +10,14 @@
******************************************************************************/
package org.jboss.tools.seam.core;
-import java.io.IOException;
import java.util.Map;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceDelta;
-import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.osgi.util.NLS;
import org.jboss.tools.common.el.core.resolver.TypeInfoCollector;
import org.jboss.tools.seam.internal.core.SeamProject;
import org.jboss.tools.seam.internal.core.SeamResourceVisitor;
@@ -30,123 +27,55 @@
import org.jboss.tools.seam.internal.core.scanner.xml.XMLScanner;
public class SeamCoreBuilder extends IncrementalProjectBuilder {
+
public static String BUILDER_ID = "org.jboss.tools.seam.core.seambuilder";
//$NON-NLS-1$
-
- SeamResourceVisitor resourceVisitor = null;
-
- SeamProject getSeamProject() {
- IProject p = getProject();
- if(p == null) return null;
- return (SeamProject)SeamCorePlugin.getSeamProject(p, false);
- }
-
- SeamResourceVisitor getResourceVisitor() {
- if(resourceVisitor == null) {
- SeamProject p = getSeamProject();
- resourceVisitor = new SeamResourceVisitor(p);
- }
- return resourceVisitor;
- }
-
- class SampleDeltaVisitor implements IResourceDeltaVisitor {
- /*
- * @see
org.eclipse.core.resources.IResourceDeltaVisitor#visit(org.eclipse.core.resources.IResourceDelta)
- */
- public boolean visit(IResourceDelta delta) throws CoreException {
- IResource resource = delta.getResource();
- switch (delta.getKind()) {
- case IResourceDelta.ADDED:
- return getResourceVisitor().getVisitor().visit(resource);
- case IResourceDelta.REMOVED:
- SeamProject p = getSeamProject();
- if(p != null) p.pathRemoved(resource.getFullPath());
- break;
- case IResourceDelta.CHANGED:
- return getResourceVisitor().getVisitor().visit(resource);
- }
- //return true to continue visiting children.
- return true;
- }
- }
-
+
/**
* @see org.eclipse.core.resource.InternalProjectBuilder#build(int,
* java.util.Map, org.eclipse.core.runtime.IProgressMonitor)
*/
protected IProject[] build(int kind, Map args, IProgressMonitor monitor)
throws CoreException {
- SeamProject sp = getSeamProject();
- if(sp == null) {
- return null;
- }
-
- if(sp.hasNoStorage()) {
- kind = FULL_BUILD;
- }
+ SeamProject seamProject = (SeamProject)SeamCorePlugin.getSeamProject(getProject(),
false);
+ SeamResourceVisitor resourceVisitor = new SeamResourceVisitor(seamProject);
long begin = System.currentTimeMillis();
- sp.postponeFiring();
-
+ seamProject.postponeFiring();
+
try {
-
- sp.resolveStorage(kind != FULL_BUILD);
-
- if(sp.getClassPath().update()) {
- sp.getClassPath().process();
- } else if(sp.getClassPath().hasToUpdateProjectDependencies()) {
- sp.getClassPath().validateProjectDependencies();
- }
+ seamProject.build();
TypeInfoCollector.cleanCache();
- if (kind == FULL_BUILD) {
- fullBuild(monitor);
- } else {
- IResourceDelta delta = getDelta(getProject());
- if (delta == null) {
- fullBuild(monitor);
- } else {
- incrementalBuild(delta, monitor);
+ IResourceDelta delta = getDelta(getProject());
+
+ if (seamProject.hasNoStorage() || delta == null ) {
+ IPath[] paths = resourceVisitor.getPathsToVisit();
+ for (IPath iPath : paths) {
+ getProject().findMember(iPath.removeFirstSegments(1)).accept(resourceVisitor);
}
+ } else {
+ delta.accept(resourceVisitor);
}
+
long end = System.currentTimeMillis();
- sp.fullBuildTime += end - begin;
- try {
- sp.store();
- } catch (IOException e) {
- SeamCorePlugin.getPluginLog().logError(NLS.bind(SeamCoreMessages.SeamCoreBuilder_1,sp.getProject().getName()),
e); //$NON-NLS-1$
- }
-
- sp.postBuild();
-
+ seamProject.fullBuildTime += end - begin;
+ seamProject.postBuild();
+
} finally {
- sp.fireChanges();
+ seamProject.fireChanges();
}
-
+ // Check if we need to return something here instead of null
return null;
}
- protected void fullBuild(final IProgressMonitor monitor)
- throws CoreException {
- try {
- getProject().accept(getResourceVisitor().getVisitor());
- } catch (CoreException e) {
- SeamCorePlugin.getPluginLog().logError(e);
- }
- }
-
- protected void incrementalBuild(IResourceDelta delta,
- IProgressMonitor monitor) throws CoreException {
- // the visitor does the work.
- delta.accept(new SampleDeltaVisitor());
- }
/**
* Access to xml scanner for test.
* @return
*/
- public static IFileScanner getXMLScanner() {
+ public static IFileScanner createXMLScanner() {
return new XMLScanner();
}
@@ -154,7 +83,7 @@
* Access to java scanner for test.
* @return
*/
- public static IFileScanner getJavaScanner() {
+ public static IFileScanner createJavaScanner() {
return new JavaScanner();
}
@@ -162,13 +91,12 @@
* Access to library scanner for test.
* @return
*/
- public static IFileScanner getLibraryScanner() {
+ public static IFileScanner createLibraryScanner() {
return new LibraryScanner();
}
protected void clean(IProgressMonitor monitor) throws CoreException {
- SeamProject sp = getSeamProject();
- if(sp != null) sp.clean();
+ ((SeamProject)SeamCorePlugin.getSeamProject(getProject(), false)).clean();
}
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamCorePlugin.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamCorePlugin.java 2010-05-28
19:17:47 UTC (rev 22416)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamCorePlugin.java 2010-05-28
19:40:10 UTC (rev 22417)
@@ -11,6 +11,7 @@
package org.jboss.tools.seam.core;
import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -18,6 +19,9 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.ISaveContext;
+import org.eclipse.core.resources.ISaveParticipant;
+import org.eclipse.core.resources.ISavedState;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
@@ -65,6 +69,37 @@
super.start(context);
cleanCachedProjects();
ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceChangeListener);
+ ISavedState lastState =
+ ResourcesPlugin.getWorkspace().addSaveParticipant(this, new ISaveParticipant() {
+
+ public void saving(ISaveContext context)
+ throws CoreException {
+ switch (context.getKind()) {
+ case ISaveContext.SNAPSHOT:
+ case ISaveContext.FULL_SAVE:
+ break;
+ case ISaveContext.PROJECT_SAVE:
+ SeamProject sp = (SeamProject)SeamCorePlugin.getSeamProject(context.getProject(),
false);
+ try {
+ sp.store();
+ } catch (IOException e) {
+ SeamCorePlugin.getPluginLog().logError(e);
+ }
+ break;
+ }
+ }
+
+ public void rollback(ISaveContext context) {
+
+ }
+
+ public void prepareToSave(ISaveContext context) throws CoreException {
+ }
+
+ public void doneSaving(ISaveContext context) {
+ }
+ });
+
}
static void cleanCachedProjects() {
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 2010-05-28
19:17:47 UTC (rev 22416)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java 2010-05-28
19:40:10 UTC (rev 22417)
@@ -357,6 +357,11 @@
}
}
+ public void build() {
+ resolveStorage(hasNoStorage());
+ getClassPath().build();
+ }
+
/**
*
*/
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamResourceVisitor.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamResourceVisitor.java 2010-05-28
19:17:47 UTC (rev 22416)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamResourceVisitor.java 2010-05-28
19:40:10 UTC (rev 22417)
@@ -17,6 +17,8 @@
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
@@ -39,7 +41,7 @@
/**
* @author Viacheslav Kabanovich
*/
-public class SeamResourceVisitor implements IResourceVisitor {
+public class SeamResourceVisitor implements IResourceVisitor, IResourceDeltaVisitor {
static IFileScanner[] FILE_SCANNERS = {
new JavaScanner(),
new XMLScanner(),
@@ -51,6 +53,15 @@
IPath[] srcs = new IPath[0];
IPath webinf = null;
+ public IPath[] getPathsToVisit() {
+ IPath[] dest = new IPath[srcs.length + (webinf==null?0:1)];
+ System.arraycopy(srcs, 0, dest, 0, srcs.length);
+ if(webinf!=null) {
+ dest[srcs.length] = webinf;
+ }
+ return dest;
+ }
+
public SeamResourceVisitor(SeamProject p) {
this.p = p;
@@ -69,19 +80,10 @@
}
}
}
-
- public IResourceVisitor getVisitor() {
- return this;
- }
public boolean visit(IResource resource) {
if(resource instanceof IFile) {
IFile f = (IFile)resource;
- for (int i = 0; i < outs.length; i++) {
- if(outs[i].isPrefixOf(resource.getFullPath())) {
- return false;
- }
- }
for (int i = 0; i < FILE_SCANNERS.length; i++) {
IFileScanner scanner = FILE_SCANNERS[i];
if(scanner.isRelevant(f)) {
@@ -103,29 +105,6 @@
}
}
}
- if(resource instanceof IFolder) {
- IPath path = resource.getFullPath();
- for (int i = 0; i < outs.length; i++) {
- if(outs[i].isPrefixOf(path)) {
- return false;
- }
- }
- for (int i = 0; i < srcs.length; i++) {
- if(srcs[i].isPrefixOf(path) || path.isPrefixOf(srcs[i])) {
- return true;
- }
- }
- if(webinf != null) {
- if(webinf.isPrefixOf(path) || path.isPrefixOf(webinf)) {
- return true;
- }
- }
- if(resource == resource.getProject()) {
- return true;
- }
- return false;
- }
- //return true to continue visiting children.
return true;
}
@@ -164,4 +143,68 @@
}
}
+ public boolean visit(IResourceDelta delta) throws CoreException {
+ IResource resource = delta.getResource();
+ switch (delta.getKind()) {
+ case IResourceDelta.ADDED:
+ case IResourceDelta.CHANGED:
+ if(resource instanceof IFile) {
+ IFile f = (IFile)resource;
+ for (int i = 0; i < outs.length; i++) {
+ if(outs[i].isPrefixOf(resource.getFullPath())) {
+ return false;
+ }
+ }
+ for (int i = 0; i < FILE_SCANNERS.length; i++) {
+ IFileScanner scanner = FILE_SCANNERS[i];
+ if(scanner.isRelevant(f)) {
+ long t = System.currentTimeMillis();
+ if(!scanner.isLikelyComponentSource(f)) {
+ p.pathRemoved(f.getFullPath());
+ return false;
+ }
+ LoadedDeclarations c = null;
+ try {
+ c = scanner.parse(f, p);
+ } catch (ScannerException e) {
+ SeamCorePlugin.getDefault().logError(e);
+ }
+ if(c != null) componentsLoaded(c, f);
+ long dt = System.currentTimeMillis() - t;
+ timeUsed += dt;
+// System.out.println("Time=" + timeUsed);
+ }
+ }
+ }
+ if(resource instanceof IFolder) {
+ IPath path = resource.getFullPath();
+ for (int i = 0; i < outs.length; i++) {
+ if(outs[i].isPrefixOf(path)) {
+ return false;
+ }
+ }
+ for (int i = 0; i < srcs.length; i++) {
+ if(srcs[i].isPrefixOf(path) || path.isPrefixOf(srcs[i])) {
+ return true;
+ }
+ }
+ if(webinf != null) {
+ if(webinf.isPrefixOf(path) || path.isPrefixOf(webinf)) {
+ return true;
+ }
+ }
+ if(resource == resource.getProject()) {
+ return true;
+ }
+ return false;
+ }
+ //return true to continue visiting children.
+ return true;
+ case IResourceDelta.REMOVED:
+ p.pathRemoved(resource.getFullPath());
+ break;
+ }
+ return true;
+ }
+
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/JavaScanner.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/JavaScanner.java 2010-05-28
19:17:47 UTC (rev 22416)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/JavaScanner.java 2010-05-28
19:40:10 UTC (rev 22417)
@@ -33,6 +33,7 @@
import org.jboss.tools.common.util.FileUtil;
import org.jboss.tools.seam.core.ISeamProject;
import org.jboss.tools.seam.core.SeamCoreMessages;
+import org.jboss.tools.seam.core.SeamCorePlugin;
import org.jboss.tools.seam.internal.core.scanner.IFileScanner;
import org.jboss.tools.seam.internal.core.scanner.LoadedDeclarations;
import org.jboss.tools.seam.internal.core.scanner.ScannerException;
@@ -52,8 +53,7 @@
* @return
*/
public boolean isRelevant(IFile resource) {
- if(resource.getName().endsWith(".java")) return true; //$NON-NLS-1$
- return false;
+ return resource.getName().endsWith(".java");
}
/**
@@ -76,6 +76,8 @@
return true;
}
+ private ASTParser p = ASTParser.newParser(AST.JLS3);
+
/**
* Returns component or list of component
* TODO change return type
@@ -93,7 +95,6 @@
}
if(u == null) return null;
ICompilationUnit[] us = new ICompilationUnit[]{u};
- ASTParser p = ASTParser.newParser(AST.JLS3);
p.setSource(u);
p.setResolveBindings(true);
if("package-info.java".equals(f.getFullPath().lastSegment())) {
@@ -150,7 +151,7 @@
try {
ts = source.getTypes();
} catch (JavaModelException e) {
- //ignore
+ SeamCorePlugin.getPluginLog().logError(e);
}
if(ts == null || ts.length == 0) return;
for (int i = 0; i < ts.length; i++) {
@@ -159,7 +160,7 @@
try {
f = ts[i].getFlags();
} catch (JavaModelException e) {
- //ignore
+ SeamCorePlugin.getPluginLog().logError(e);
continue;
}
if(Flags.isPublic(f)) {
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/ClassPath.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/ClassPath.java 2010-05-28
19:17:47 UTC (rev 22416)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/ClassPath.java 2010-05-28
19:40:10 UTC (rev 22417)
@@ -286,4 +286,11 @@
processedPaths.clear();
}
+ public void build() {
+ if(update()) {
+ process();
+ } else if(hasToUpdateProjectDependencies()) {
+ validateProjectDependencies();
+ }
+ }
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/LibraryScanner.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/LibraryScanner.java 2010-05-28
19:17:47 UTC (rev 22416)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/LibraryScanner.java 2010-05-28
19:40:10 UTC (rev 22417)
@@ -11,6 +11,7 @@
package org.jboss.tools.seam.internal.core.scanner.lib;
import java.io.ByteArrayInputStream;
+import java.io.IOException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IPath;
@@ -25,6 +26,7 @@
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
+import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
import org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation;
import org.jboss.tools.common.model.XModel;
import org.jboss.tools.common.model.XModelObject;
@@ -63,42 +65,52 @@
return false;
}
+ XModelObject o = null;
+ XModel model = null;
+
public boolean isLikelyComponentSource(IFile f) {
- XModel model = InnerModelHelper.createXModel(f.getProject());
- if(model == null) return false;
- XModelObject o = EclipseResourceUtil.getObjectByResource(model, f);
- if(o == null) return false;
- if(!o.getModelEntity().getName().equals("FileSystemJar")) { //$NON-NLS-1$
- ((FileSystemsImpl)o.getModel().getByPath("FileSystems")).updateOverlapped();
//$NON-NLS-1$
- o = EclipseResourceUtil.getObjectByResource(f);
- if(o == null || !o.getModelEntity().getName().equals("FileSystemJar"))
return false; //$NON-NLS-1$
+ cleanState();
+ boolean isComponent = false;
+ try {
+ model = InnerModelHelper.createXModel(f.getProject());
+ if(model != null) {
+ o = EclipseResourceUtil.getObjectByResource(model, f);
+ if(o != null &&
o.getModelEntity().getName().equals("FileSystemJar")) {
+ ((FileSystemsImpl)o.getModel().getByPath("FileSystems")).updateOverlapped();
//$NON-NLS-1$
+ o = EclipseResourceUtil.getObjectByResource(f);
+ if(o != null &&
o.getModelEntity().getName().equals("FileSystemJar")) {
+ isComponent = isLikelyComponentSource(o);
+ }
+ }
+ }
+ } finally {
+ if(!isComponent) {
+ cleanState();
+ }
}
- return isLikelyComponentSource(o);
+ return isComponent;
}
+ private void cleanState() {
+ model = null;
+ o = null;
+ }
+
public LoadedDeclarations parse(IFile f, ISeamProject sp) throws ScannerException {
- XModel model = InnerModelHelper.createXModel(f.getProject());
- if(model == null) return null;
- XModelObject o = EclipseResourceUtil.getObjectByResource(model, f);
- if(o == null) return null;
- if(!o.getModelEntity().getName().equals("FileSystemJar")) { //$NON-NLS-1$
- ((FileSystemsImpl)o.getModel().getByPath("FileSystems")).updateOverlapped();
//$NON-NLS-1$
- o = EclipseResourceUtil.getObjectByResource(f);
- if(o == null || !o.getModelEntity().getName().equals("FileSystemJar"))
return null; //$NON-NLS-1$
+ LoadedDeclarations decls = null;
+ if(o!=null) {
+ decls = parse(o, f.getFullPath(), sp);
}
- return parse(o, f.getFullPath(), sp);
+ return decls;
}
- public boolean isLikelyComponentSource(XModelObject o) {
- if(o == null) return false;
- if(o.getChildByPath("seam.properties") != null) return true; //$NON-NLS-1$
- if(o.getChildByPath("META-INF/seam.properties") != null) return true;
//$NON-NLS-1$
- if(o.getChildByPath("META-INF/components.xml") != null) return true;
//$NON-NLS-1$
- return false;
+ public static final boolean isLikelyComponentSource(XModelObject o) {
+ return o.getChildByPath("seam.properties") != null
+ || o.getChildByPath("META-INF/seam.properties") != null
+ || o.getChildByPath("META-INF/components.xml") != null;
}
public LoadedDeclarations parse(XModelObject o, IPath path, ISeamProject sp) throws
ScannerException {
- if(o == null) return null;
sourcePath = path;
XModelObject seamProperties = o.getChildByPath("META-INF/seam.properties");
//$NON-NLS-1$
if(seamProperties == null) seamProperties =
o.getChildByPath("seam.properties"); //$NON-NLS-1$
@@ -111,6 +123,10 @@
processJavaClasses(o, ds);
} catch (JavaModelException e) {
throw new
ScannerException(SeamCoreMessages.LIBRARY_SCANNER_CANNOT_PROCESS_JAVA_CLASSES, e);
+ } catch (ClassFormatException e) {
+ throw new
ScannerException(SeamCoreMessages.LIBRARY_SCANNER_CANNOT_PROCESS_JAVA_CLASSES, e);
+ } catch (IOException e) {
+ throw new
ScannerException(SeamCoreMessages.LIBRARY_SCANNER_CANNOT_PROCESS_JAVA_CLASSES, e);
}
if(componentsXML != null) {
@@ -126,25 +142,27 @@
return ds;
}
- protected void processJavaClasses(XModelObject o, LoadedDeclarations ds) throws
JavaModelException {
+ protected void processJavaClasses(XModelObject o, LoadedDeclarations ds) throws
JavaModelException, ClassFormatException, IOException {
IJavaProject javaProject = JavaCore.create(classPath.getProject().getProject());
String location = o.getAttributeValue("location"); //$NON-NLS-1$
location = XModelObjectUtil.expand(location, o.getModel(), null);
IFile[] fs = ModelPlugin.getWorkspace().getRoot().findFilesForLocation(new
Path(location));
IPackageFragmentRoot root = null;
- if(fs != null) for (int i = 0; i < fs.length && root == null; i++) {
- root = javaProject.findPackageFragmentRoot(fs[i].getFullPath());
- }
- if(root == null) {
- root = javaProject.findPackageFragmentRoot(new Path(location));
- }
- if(root == null) return;
- process(root, ds);
-
+ if(fs != null) {
+ for (int i = 0; i < fs.length && root == null; i++) {
+ root = javaProject.findPackageFragmentRoot(fs[i].getFullPath());
+ }
+ if(root == null) {
+ root = javaProject.findPackageFragmentRoot(new Path(location));
+ if(root != null) {
+ process(root, ds);
+ }
+ }
+ }
}
- protected void process(IParent element, LoadedDeclarations ds) throws JavaModelException
{
+ protected void process(IParent element, LoadedDeclarations ds) throws
JavaModelException, ClassFormatException, IOException {
if(element == null) return;
IJavaElement[] es = element.getChildren();
String prefix = null;
@@ -171,7 +189,7 @@
}
}
- void processWithClassReader(IClassFile typeRoot, LoadedDeclarations ds, String prefix)
{
+ void processWithClassReader(IClassFile typeRoot, LoadedDeclarations ds, String prefix)
throws JavaModelException, ClassFormatException, IOException {
IType type = typeRoot.getType();
ClassFileReader reader = getReader(type, typeRoot);
@@ -189,7 +207,7 @@
}
}
- String processPackageInfo(IClassFile typeRoot, LoadedDeclarations ds) {
+ String processPackageInfo(IClassFile typeRoot, LoadedDeclarations ds) throws
JavaModelException, ClassFormatException, IOException {
IType type = typeRoot.getType();
ClassFileReader reader = getReader(type, typeRoot);
@@ -218,33 +236,24 @@
}
static IBinaryAnnotation getNamespaceAnnotation(IBinaryAnnotation[] as) {
- if(as != null) for (int i = 0; i < as.length; i++) {
- String type = TypeScanner.getTypeName(as[i]);
- if(type != null && type.equals(SeamAnnotations.NAMESPACE_ANNOTATION_TYPE)) {
- return as[i];
+ if(as != null) {
+ for (int i = 0; i < as.length; i++) {
+ String type = TypeScanner.getTypeName(as[i]);
+ if(type != null && type.equals(SeamAnnotations.NAMESPACE_ANNOTATION_TYPE)) {
+ return as[i];
+ }
}
}
return null;
}
- private ClassFileReader getReader(IType type, IClassFile typeRoot) {
+ private ClassFileReader getReader(IType type, IClassFile typeRoot) throws
JavaModelException, ClassFormatException, IOException {
String className = type.getFullyQualifiedName();
-
+ ClassFileReader newReader = null;
byte[] bs = null;
- try {
bs = typeRoot.getBytes();
- } catch (JavaModelException e) {
- return null;
- }
-
- try {
return ClassFileReader.read(new ByteArrayInputStream(bs), className, false);
- } catch (Throwable t) {
- //ignore
- }
-
- return null;
}
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/xml/PropertiesScanner.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/xml/PropertiesScanner.java 2010-05-28
19:17:47 UTC (rev 22416)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/xml/PropertiesScanner.java 2010-05-28
19:40:10 UTC (rev 22417)
@@ -43,8 +43,7 @@
* @return
*/
public boolean isRelevant(IFile resource) {
- if(resource.getName().equals("seam.properties")) return true; //$NON-NLS-1$
- return false;
+ return resource.getName().equals("seam.properties");
}
/**
@@ -54,9 +53,7 @@
* @return
*/
public boolean isLikelyComponentSource(IFile f) {
- if(!f.isSynchronized(IFile.DEPTH_ZERO) || !f.exists()) return false;
- if(f.getName().equals("seam.properties")) return true; //$NON-NLS-1$
- return false;
+ return f.isSynchronized(IFile.DEPTH_ZERO) && f.exists() &&
f.getName().equals("seam.properties");
}
/**
@@ -67,53 +64,55 @@
*/
public LoadedDeclarations parse(IFile f, ISeamProject sp) throws ScannerException {
XModel model = InnerModelHelper.createXModel(f.getProject());
- if(model == null) return null;
XModelObject o = EclipseResourceUtil.getObjectByResource(model, f);
return parse(o, f.getFullPath());
}
public LoadedDeclarations parse(XModelObject o, IPath source) {
- if(o == null) return null;
+ LoadedDeclarations ds = null;
+
+ if(o != null) {
- if(o.getParent() instanceof FolderImpl) {
- IFile f = ResourcesPlugin.getWorkspace().getRoot().getFile(source);
- if(f != null && f.exists()) {
- try {
- ((FolderImpl)o.getParent()).updateChildFile(o, f.getLocation().toFile());
- } catch (XModelException e) {
- ModelPlugin.getPluginLog().logError(e);
+ if(o.getParent() instanceof FolderImpl) {
+ IFile f = ResourcesPlugin.getWorkspace().getRoot().getFile(source);
+ if(f != null && f.exists()) {
+ try {
+ ((FolderImpl)o.getParent()).updateChildFile(o, f.getLocation().toFile());
+ } catch (XModelException e) {
+ ModelPlugin.getPluginLog().logError(e);
+ }
}
}
- }
-
- LoadedDeclarations ds = new LoadedDeclarations();
-
- XModelObject[] properties = o.getChildren();
- Map<String, SeamPropertiesDeclaration> ds1 = new HashMap<String,
SeamPropertiesDeclaration>();
- for (int i = 0; i < properties.length; i++) {
- String name = properties[i].getAttributeValue("name"); //$NON-NLS-1$
- int q = name.lastIndexOf('.');
- if(q < 0) continue;
- String componentName = name.substring(0, q);
- String propertyName = name.substring(q + 1);
- SeamPropertiesDeclaration d = ds1.get(componentName);
- if(d == null) {
- d = new SeamPropertiesDeclaration();
- d.setId(properties[i]);
- d.setSourcePath(source);
- d.setName(componentName);
- ds1.put(componentName, d);
+
+ ds = new LoadedDeclarations();
+
+ XModelObject[] properties = o.getChildren();
+ Map<String, SeamPropertiesDeclaration> ds1 = new HashMap<String,
SeamPropertiesDeclaration>();
+ for (int i = 0; i < properties.length; i++) {
+ String name = properties[i].getAttributeValue("name"); //$NON-NLS-1$
+ int q = name.lastIndexOf('.');
+ if(q < 0) continue;
+ String componentName = name.substring(0, q);
+ String propertyName = name.substring(q + 1);
+ SeamPropertiesDeclaration d = ds1.get(componentName);
+ if(d == null) {
+ d = new SeamPropertiesDeclaration();
+ d.setId(properties[i]);
+ d.setSourcePath(source);
+ d.setName(componentName);
+ ds1.put(componentName, d);
+ }
+ SeamProperty p = new SeamProperty();
+ p.setId(properties[i]);
+ p.setName(new XMLValueInfo(properties[i], "name")); //$NON-NLS-1$
+ p.setName(propertyName);
+ SeamValueString v = new SeamValueString();
+ v.setValue(new XMLValueInfo(properties[i], "value")); //$NON-NLS-1$
+ p.setValue(v);
+ d.addProperty(p);
}
- SeamProperty p = new SeamProperty();
- p.setId(properties[i]);
- p.setName(new XMLValueInfo(properties[i], "name")); //$NON-NLS-1$
- p.setName(propertyName);
- SeamValueString v = new SeamValueString();
- v.setValue(new XMLValueInfo(properties[i], "value")); //$NON-NLS-1$
- p.setValue(v);
- d.addProperty(p);
+ ds.getComponents().addAll(ds1.values());
}
- ds.getComponents().addAll(ds1.values());
return ds;
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/xml/XMLScanner.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/xml/XMLScanner.java 2010-05-28
19:17:47 UTC (rev 22416)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/xml/XMLScanner.java 2010-05-28
19:40:10 UTC (rev 22417)
@@ -58,6 +58,9 @@
*/
public class XMLScanner implements IFileScanner {
+ private XModel model;
+ private XModelObject o;
+
public XMLScanner() {}
/**
@@ -67,9 +70,7 @@
* @return
*/
public boolean isRelevant(IFile resource) {
- if(resource.getName().equals("components.xml")) return true; //$NON-NLS-1$
- if(resource.getName().endsWith(".component.xml")) return true; //$NON-NLS-1$
- return false;
+ return resource.getName().equals("components.xml") ||
resource.getName().endsWith(".component.xml");
}
/**
@@ -79,15 +80,28 @@
* @return
*/
public boolean isLikelyComponentSource(IFile f) {
- if(!f.isSynchronized(IFile.DEPTH_ZERO) || !f.exists()) return false;
- XModel model = InnerModelHelper.createXModel(f.getProject());
- if(model == null) return false;
- XModelObject o = EclipseResourceUtil.getObjectByResource(model, f);
- if(o == null) return false;
- if(o.getModelEntity().getName().startsWith("FileSeamComponent")) return true;
//$NON-NLS-1$
- return false;
+ cleanState();
+ boolean isComponentSource = false;
+ if(f.isSynchronized(IFile.DEPTH_ZERO) && f.exists()) {
+ model = InnerModelHelper.createXModel(f.getProject());
+ if(model != null) {
+ o = EclipseResourceUtil.getObjectByResource(model, f);
+ if(o != null) {
+ isComponentSource =
o.getModelEntity().getName().startsWith("FileSeamComponent"); //$NON-NLS-1$
+ }
+ }
+ }
+ if(!isComponentSource) {
+ cleanState();
+ }
+ return isComponentSource;
}
+ private void cleanState() {
+ model = null;
+ o = null;
+ }
+
/**
* Returns list of components
* @param f
@@ -95,9 +109,8 @@
* @throws ScannerException
*/
public LoadedDeclarations parse(IFile f, ISeamProject sp) throws ScannerException {
- XModel model = InnerModelHelper.createXModel(f.getProject());
- if(model == null) return null;
- XModelObject o = EclipseResourceUtil.getObjectByResource(model, f);
+ model = InnerModelHelper.createXModel(f.getProject());
+ o = EclipseResourceUtil.getObjectByResource(model, f);
return parse(o, f.getFullPath(), sp);
}
@@ -121,8 +134,6 @@
}
public LoadedDeclarations parse(XModelObject o, IPath source, ISeamProject sp) {
- if(o == null) return null;
-
NamespaceMapping nm = NamespaceMapping.load(o);
if(o.getParent() instanceof FolderImpl) {
Modified:
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/ScannerTest.java
===================================================================
---
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/ScannerTest.java 2010-05-28
19:17:47 UTC (rev 22416)
+++
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/ScannerTest.java 2010-05-28
19:40:10 UTC (rev 22417)
@@ -88,7 +88,7 @@
IFile f = project.getFile("WebContent/WEB-INF/components.xml");
assertTrue("Cannot find components.xml in test project", f != null &&
f.exists());
- IFileScanner scanner = SeamCoreBuilder.getXMLScanner();
+ IFileScanner scanner = SeamCoreBuilder.createXMLScanner();
assertTrue("Scanner cannot recognise components.xml",
scanner.isRelevant(f));
assertTrue("Scanner cannot recognise components.xml content",
scanner.isLikelyComponentSource(f));
ISeamComponentDeclaration[] cs = null;
@@ -206,7 +206,7 @@
IFile f = project.getFile("JavaSource/demo/User.java");
assertTrue("Cannot find User.java in test project", f != null &&
f.exists());
- IFileScanner scanner = SeamCoreBuilder.getJavaScanner();
+ IFileScanner scanner = SeamCoreBuilder.createJavaScanner();
assertTrue("Scanner cannot recognise User.java", scanner.isRelevant(f));
assertTrue("Scanner cannot recognise User.java content",
scanner.isLikelyComponentSource(f));
ISeamComponentDeclaration[] cs = null;
@@ -291,7 +291,7 @@
IFile f = project.getFile("WebContent/WEB-INF/lib/jboss-seam.jar");
assertTrue("Cannot find User.java in test project", f != null &&
f.exists());
- LibraryScanner scanner =(LibraryScanner)SeamCoreBuilder.getLibraryScanner();
+ LibraryScanner scanner =(LibraryScanner)SeamCoreBuilder.createLibraryScanner();
ClassPath cp = ((SeamProject)seamProject).getClassPath();
scanner.setClassPath(cp);
cp.update();
Modified:
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamBigProjectTest.java
===================================================================
---
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamBigProjectTest.java 2010-05-28
19:17:47 UTC (rev 22416)
+++
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamBigProjectTest.java 2010-05-28
19:40:10 UTC (rev 22417)
@@ -79,7 +79,7 @@
return new File(location);
}
- public void testBigProject() {
+ public void testBigProject() throws IOException {
ISeamProject sp = getSeamProject();
ISeamComponent[] cs = sp.getComponents();
int components = cs.length;
@@ -88,6 +88,7 @@
}
SeamProject impl = (SeamProject)sp;
System.out.println("Full build of " + components + " components
completed in " + impl.fullBuildTime + "ms");
+ impl.store();
long time = impl.reload();
System.out.println("Reloaded " + sp.getComponents().length + "
components in " + time + "ms");
List<Long> statistics = impl.statistics;
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 2010-05-28
19:17:47 UTC (rev 22416)
+++
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/AbstractSeamFacetTest.java 2010-05-28
19:40:10 UTC (rev 22417)
@@ -108,10 +108,8 @@
return SEAM_EAP_121_HOME_PROPERY;
}
- protected void tearDown()
+ protected void tearDown() throws Exception
- throws Exception
-
{
// Wait until all jobs is finished to avoid delete project problems
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 2010-05-28
19:17:47 UTC (rev 22416)
+++
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/project/facet/Seam2FacetInstallDelegateTest.java 2010-05-28
19:40:10 UTC (rev 22417)
@@ -64,8 +64,6 @@
// ws.removeResourceChangeListener( ValManager.getDefault() );
// EventManager.getManager().shutdown();
- suspendXJobs = XJob.isSuspended();
- XJob.setSuspended(true);
assertSeamHomeAvailable();
seam2Facet = ProjectFacetsManager.getProjectFacet("jst.seam");
@@ -94,7 +92,6 @@
super.tearDown();
ValidationFramework.getDefault().suspendAllValidation(
suspendAllValidation);
- XJob.setSuspended(suspendXJobs);
ResourcesPlugin.getWorkspace().addResourceChangeListener(
EventManager.getManager(),