Author: scabanovich
Date: 2011-07-01 18:17:29 -0400 (Fri, 01 Jul 2011)
New Revision: 32536
Added:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/build/
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/build/JSF2ProjectBuilder.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/IJSF2ManagedBean.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/IJSF2Project.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/JSF2Constants.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/JSF2ProjectFactory.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/impl/
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/impl/AbstractMemberDefinition.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/impl/AbstractTypeDefinition.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/impl/DefinitionContext.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/impl/JSF2Project.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/impl/TypeDefinition.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/scanner/
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/scanner/FileSet.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/scanner/lib/
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/scanner/lib/ClassPathMonitor.java
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/META-INF/MANIFEST.MF
Log:
JBIDE-5046
https://issues.jboss.org/browse/JBIDE-5046
Modified: trunk/jsf/plugins/org.jboss.tools.jsf/META-INF/MANIFEST.MF
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf/META-INF/MANIFEST.MF 2011-07-01 22:15:04 UTC
(rev 32535)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/META-INF/MANIFEST.MF 2011-07-01 22:17:29 UTC
(rev 32536)
@@ -8,6 +8,7 @@
Export-Package: org.jboss.tools.jsf,
org.jboss.tools.jsf.el.refactoring,
org.jboss.tools.jsf.facelet.model,
+ org.jboss.tools.jsf.jsf2.bean.build,
org.jboss.tools.jsf.jsf2.model,
org.jboss.tools.jsf.jsf2.refactoring,
org.jboss.tools.jsf.jsf2.refactoring.action.rename,
Added:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/build/JSF2ProjectBuilder.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/build/JSF2ProjectBuilder.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/build/JSF2ProjectBuilder.java 2011-07-01
22:17:29 UTC (rev 32536)
@@ -0,0 +1,357 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.jsf.jsf2.bean.build;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+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.resources.IncrementalProjectBuilder;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.IClassFile;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageDeclaration;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.IType;
+import org.jboss.tools.common.EclipseUtil;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.plugin.ModelPlugin;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.jsf.JSFModelPlugin;
+import org.jboss.tools.jsf.jsf2.bean.model.JSF2ProjectFactory;
+import org.jboss.tools.jsf.jsf2.bean.model.impl.DefinitionContext;
+import org.jboss.tools.jsf.jsf2.bean.model.impl.JSF2Project;
+import org.jboss.tools.jsf.jsf2.bean.model.impl.TypeDefinition;
+import org.jboss.tools.jsf.jsf2.bean.scanner.FileSet;
+import org.jboss.tools.jst.web.kb.internal.IIncrementalProjectBuilderExtension;
+
+public class JSF2ProjectBuilder extends IncrementalProjectBuilder implements
IIncrementalProjectBuilderExtension {
+
+ JSF2ResourceVisitor resourceVisitor = null;
+
+ public JSF2ProjectBuilder() {}
+
+ protected JSF2Project getJSF2Project() {
+ IProject p = getProject();
+ if(p == null) return null;
+ return (JSF2Project)JSF2ProjectFactory.getJSF2Project(p, false);
+ }
+
+ JSF2ResourceVisitor getResourceVisitor() {
+ if(resourceVisitor == null) {
+ resourceVisitor = new JSF2ResourceVisitor();
+ }
+ return resourceVisitor;
+ }
+
+ @Override
+ public IProject[] build(int kind, Map<String, String> args,
+ IProgressMonitor monitor) throws CoreException {
+ resourceVisitor = null;
+
+ JSF2Project n = getJSF2Project();
+ if(n == null) {
+ return null;
+ }
+
+ if(n.hasNoStorage()) {
+ kind = FULL_BUILD;
+ }
+
+ n.postponeFiring();
+
+ try {
+ n.resolveStorage(kind != FULL_BUILD);
+
+ //1. Check class path.
+ boolean isClassPathUpdated = n.getClassPath().update();
+
+ Map<String, XModelObject> newJars = new HashMap<String, XModelObject>();
+ if(isClassPathUpdated) {
+ //2. Update class path. Removed paths will be cached to be applied to working copy of
context.
+ n.getClassPath().setSrcs(getResourceVisitor().srcs);
+ newJars = n.getClassPath().process();
+
+ }
+
+ //4. Create working copy of context.
+ n.getDefinitions().newWorkingCopy(kind == FULL_BUILD);
+
+ //5. Modify working copy of context.
+ //5.1 Apply Removed paths.
+ if(isClassPathUpdated) {
+ n.getClassPath().applyRemovedPaths();
+ }
+
+ //5.2 Discover sources and build definitions.
+ if(isClassPathUpdated) {
+ buildJars(newJars);
+
+ n.getClassPath().validateProjectDependencies();
+
+ kind = FULL_BUILD;
+ } else if(n.getClassPath().hasToUpdateProjectDependencies()) {
+ n.getClassPath().validateProjectDependencies();
+ }
+
+ if (kind == FULL_BUILD) {
+ fullBuild(monitor);
+ } else {
+ IResourceDelta delta = getDelta(getProject());
+ if (delta == null) {
+ fullBuild(monitor);
+ } else {
+ incrementalBuild(delta, monitor);
+ }
+ }
+
+ // 6. Save created definitions to project context and build beans.
+ getJSF2Project().getDefinitions().applyWorkingCopy();
+
+ try {
+ n.store();
+ } catch (IOException e) {
+ JSFModelPlugin.getDefault().logError(e); //$NON-NLS-1$
+ }
+ } finally {
+ n.fireChanges();
+ }
+
+ return null;
+ }
+
+ protected void fullBuild(final IProgressMonitor monitor)
+ throws CoreException {
+ try {
+ JSF2ResourceVisitor rv = getResourceVisitor();
+ rv.incremental = false;
+ getProject().accept(rv);
+ FileSet fs = rv.fileSet;
+ build(fs, getJSF2Project());
+
+ } catch (CoreException e) {
+ JSFModelPlugin.getDefault().logError(e);
+ }
+ }
+
+ protected void incrementalBuild(IResourceDelta delta,
+ IProgressMonitor monitor) throws CoreException {
+ JSF2ResourceVisitor rv = getResourceVisitor();
+ rv.incremental = true;
+ delta.accept(new SampleDeltaVisitor());
+ FileSet fs = rv.fileSet;
+ build(fs, getJSF2Project());
+ }
+
+ protected void buildJars(Map<String, XModelObject> newJars) throws CoreException
{
+ IJavaProject jp = EclipseResourceUtil.getJavaProject(getJSF2Project().getProject());
+ if(jp == null) return;
+ FileSet fileSet = new FileSet();
+
+ for (String jar: newJars.keySet()) {
+ Path path = new Path(jar);
+ IPackageFragmentRoot root = jp.getPackageFragmentRoot(jar);
+ if(root == null) continue;
+ if(!root.exists()) {
+ IFile f = EclipseResourceUtil.getFile(jar);
+ if(f != null && f.exists()) {
+ root = jp.getPackageFragmentRoot(f);
+ } else {
+ f = EclipseResourceUtil.getFile(jar + "/META-INF/web-fragment.xml");
+ if(f != null && f.exists()) {
+ root = jp.getPackageFragmentRoot(f.getParent().getParent());
+ }
+ }
+ }
+ if (root == null || !root.exists())
+ continue;
+ IJavaElement[] es = root.getChildren();
+ for (IJavaElement e : es) {
+ if (e instanceof IPackageFragment) {
+ IPackageFragment pf = (IPackageFragment) e;
+ IClassFile[] cs = pf.getClassFiles();
+ for (IClassFile c : cs) {
+ fileSet.add(path, c.getType());
+ }
+ }
+ }
+ }
+ build(fileSet, getJSF2Project());
+ }
+
+ void build(FileSet fs, JSF2Project project) {
+ DefinitionContext context = getJSF2Project().getDefinitions().getWorkingCopy();
+ Map<IPath, Set<IType>> cs = fs.getClasses();
+ for (IPath f: cs.keySet()) {
+ Set<IType> ts = cs.get(f);
+ for (IType type: ts) {
+ TypeDefinition def = new TypeDefinition();
+ def.setType(type, context, TypeDefinition.FLAG_ALL_MEMBERS);
+ context.addType(f, type.getFullyQualifiedName(), def);
+ }
+ }
+ }
+
+ 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().visit(resource);
+ case IResourceDelta.REMOVED:
+ JSF2Project p = getJSF2Project();
+ if(p != null) {
+ p.getDefinitions().getWorkingCopy().clean(resource.getFullPath());
+ }
+ break;
+ case IResourceDelta.CHANGED:
+ return getResourceVisitor().visit(resource);
+ }
+ //return true to continue visiting children.
+ return true;
+ }
+ }
+
+ class JSF2ResourceVisitor implements IResourceVisitor {
+ boolean incremental = false;
+ FileSet fileSet = new FileSet();
+ IPath[] outs = new IPath[0];
+ IPath[] srcs = new IPath[0];
+ Set<IPath> visited = new HashSet<IPath>();
+
+ public JSF2ResourceVisitor() {
+ getJavaSourceRoots(getProject());
+ }
+
+ void getJavaSourceRoots(IProject project) {
+ IJavaProject javaProject = EclipseResourceUtil.getJavaProject(project);
+ if(javaProject == null) return;
+ List<IPath> ps = new ArrayList<IPath>();
+ List<IPath> os = new ArrayList<IPath>();
+ try {
+ IPath output = javaProject.getOutputLocation();
+ if(output != null) os.add(output);
+ IClasspathEntry[] es = javaProject.getResolvedClasspath(true);
+ for (int i = 0; i < es.length; i++) {
+ if(es[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
+ IResource findMember =
ModelPlugin.getWorkspace().getRoot().findMember(es[i].getPath());
+ if(findMember != null && findMember.exists()) {
+ ps.add(findMember.getFullPath());
+ }
+ IPath out = es[i].getOutputLocation();
+ if(out != null && !os.contains(out)) {
+ os.add(out);
+ }
+ }
+ }
+ srcs = ps.toArray(new IPath[0]);
+ outs = os.toArray(new IPath[0]);
+ } catch(CoreException ce) {
+ JSFModelPlugin.getDefault().logError("Error while locating java source roots for
" + project, ce);
+ }
+ }
+
+ @Override
+ public boolean visit(IResource resource) throws CoreException {
+ IPath path = resource.getFullPath();
+ if(resource instanceof IFile) {
+ if(visited.contains(path)) {
+ return false;
+ }
+ visited.add(path);
+ IFile f = (IFile)resource;
+ 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)) {
+ if(f.getName().endsWith(".java")) {
+ ICompilationUnit unit = EclipseUtil.getCompilationUnit(f);
+ if(unit!=null) {
+ if(f.getName().equals("package-info.java")) {
+ IPackageDeclaration[] pkg = unit.getPackageDeclarations();
+ if(pkg != null && pkg.length > 0) {
+ fileSet.add(f.getFullPath(), pkg[0]);
+ if(incremental) {
+ IResource[] ms = resource.getParent().members();
+ for (IResource m: ms) {
+ if(m instanceof IFile &&
!m.getName().equals("package-info.java")) {
+ visit(m);
+ }
+ }
+ }
+ }
+ } else {
+ IType[] ts = unit.getTypes();
+ fileSet.add(f.getFullPath(), ts);
+ }
+ }
+ }
+ Set<IFile> ds = getDependentFiles(path, visited);
+ if(ds != null) for (IFile d: ds) visit(d);
+ return false;
+ }
+ }
+ Set<IFile> ds = getDependentFiles(path, visited);
+ if(ds != null) for (IFile d: ds) visit(d);
+ }
+
+ if(resource instanceof IFolder) {
+ 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(resource == resource.getProject()) {
+ return true;
+ }
+ return false;
+ }
+ //return true to continue visiting children.
+ return true;
+ }
+
+ }
+
+ //In case if we will need that
+ Set<IFile> getDependentFiles(IPath path, Set<IPath> visited) {
+ return null;
+ }
+
+}
Property changes on:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/build/JSF2ProjectBuilder.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/IJSF2ManagedBean.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/IJSF2ManagedBean.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/IJSF2ManagedBean.java 2011-07-01
22:17:29 UTC (rev 32536)
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.jsf.jsf2.bean.model;
+
+public interface IJSF2ManagedBean {
+
+}
Property changes on:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/IJSF2ManagedBean.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/IJSF2Project.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/IJSF2Project.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/IJSF2Project.java 2011-07-01
22:17:29 UTC (rev 32536)
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.jsf.jsf2.bean.model;
+
+import java.util.Set;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+
+public interface IJSF2Project {
+
+ public IJSF2ManagedBean[] getManagedBeans();
+
+ public Set<IJSF2ManagedBean> getManagedBeans(IPath path);
+
+ public IProject getProject();
+
+ public Set<? extends IJSF2Project> getUsedProjects();
+
+ public void addUsedProject(IJSF2Project project);
+
+ public void addDependentProject(IJSF2Project project);
+
+ public void removeUsedProject(IJSF2Project project);
+
+ public void pathRemoved(IPath path);
+
+ public boolean isStorageResolved();
+ public void resolve();
+ public void update();
+
+}
Property changes on:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/IJSF2Project.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/JSF2Constants.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/JSF2Constants.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/JSF2Constants.java 2011-07-01
22:17:29 UTC (rev 32536)
@@ -0,0 +1,16 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.jsf.jsf2.bean.model;
+
+public interface JSF2Constants {
+ public String MANAGED_BEAN_ANNOTATION_TYPE_NAME =
"javax.faces.bean.ManagedBean";
+ public String MANAGED_PROPERTY_ANNOTATION_TYPE_NAME =
"javax.faces.bean.ManagedProperty";
+}
Property changes on:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/JSF2Constants.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/JSF2ProjectFactory.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/JSF2ProjectFactory.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/JSF2ProjectFactory.java 2011-07-01
22:17:29 UTC (rev 32536)
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.jsf.jsf2.bean.model;
+
+import org.eclipse.core.resources.IProject;
+import org.jboss.tools.jsf.jsf2.bean.model.impl.JSF2Project;
+import org.jboss.tools.jst.web.kb.KbProjectFactory;
+import org.jboss.tools.jst.web.kb.internal.KbProject;
+
+/**
+ *
+ * @author Viacheslav Kabanovich
+ *
+ */
+public class JSF2ProjectFactory {
+ private static final String MODEL_ID = "JSF2";
+
+ public static IJSF2Project getJSF2Project(IProject project, boolean resolve) {
+ JSF2Project result = null;
+ KbProject kb = (KbProject)KbProjectFactory.getKbProject(project, resolve);
+
+ if(kb != null) {
+ result = (JSF2Project)kb.getExtensionModel(MODEL_ID);
+ if(result == null) {
+ result = new JSF2Project();
+ result.setProject(project);
+ kb.setExtensionModel(MODEL_ID, result);
+ }
+ }
+ if(result != null && resolve) {
+ result.resolve();
+ }
+ return result;
+ }
+
+}
Property changes on:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/JSF2ProjectFactory.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/impl/AbstractMemberDefinition.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/impl/AbstractMemberDefinition.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/impl/AbstractMemberDefinition.java 2011-07-01
22:17:29 UTC (rev 32536)
@@ -0,0 +1,132 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.jsf.jsf2.bean.model.impl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IAnnotatable;
+import org.eclipse.jdt.core.IAnnotation;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IType;
+import org.jboss.tools.common.java.IAnnotated;
+import org.jboss.tools.common.java.IAnnotationDeclaration;
+import org.jboss.tools.common.java.IJavaAnnotation;
+import org.jboss.tools.common.java.impl.AnnotationDeclaration;
+import org.jboss.tools.common.java.impl.JavaAnnotation;
+import org.jboss.tools.common.text.ITextSourceReference;
+import org.jboss.tools.jsf.JSFModelPlugin;
+import org.jboss.tools.jsf.jsf2.bean.model.JSF2Constants;
+
+/**
+ *
+ * @author Viacheslav Kabanovich
+ *
+ */
+public abstract class AbstractMemberDefinition implements IAnnotated {
+ public static int FLAG_NO_ANNOTATIONS = 1;
+ public static int FLAG_ALL_MEMBERS = 2;
+
+ protected List<IAnnotationDeclaration> annotations = new
ArrayList<IAnnotationDeclaration>();
+ protected IAnnotatable member;
+ protected Map<String, AnnotationDeclaration> annotationsByType = new
HashMap<String, AnnotationDeclaration>();
+ protected IResource resource;
+
+ protected ITextSourceReference originalDefinition = null;
+
+ public AbstractMemberDefinition() {}
+
+ protected void setAnnotatable(IAnnotatable member, IType contextType, DefinitionContext
context, int flags) {
+ this.member = member;
+ try {
+ init(contextType, context, flags);
+ } catch (CoreException e) {
+ JSFModelPlugin.getDefault().logError(e);
+ }
+ }
+
+ public void setOriginalDefinition(ITextSourceReference def) {
+ originalDefinition = def;
+ }
+
+ public IAnnotatable getMember() {
+ return member;
+ }
+
+ public AbstractTypeDefinition getTypeDefinition() {
+ return null;
+ }
+
+ protected void init(IType contextType, DefinitionContext context, int flags) throws
CoreException {
+ resource = ((IJavaElement)member).getResource();
+ if((flags & FLAG_NO_ANNOTATIONS) == 0) {
+ IAnnotation[] ts = member.getAnnotations();
+ for (int i = 0; i < ts.length; i++) {
+ IJavaAnnotation ja = new JavaAnnotation(ts[i], contextType);
+ addAnnotation(ja, context);
+ }
+ }
+ }
+
+ public void addAnnotation(IJavaAnnotation ja, DefinitionContext context) {
+ AnnotationDeclaration a = new AnnotationDeclaration();
+ a.setDeclaration(ja);
+ addAnnotation(a, context);
+ }
+
+ private void addAnnotation(AnnotationDeclaration a, DefinitionContext context) {
+ annotations.add(a);
+ if(a.getTypeName() != null) {
+ annotationsByType.put(a.getTypeName(), a);
+ }
+ }
+
+ public void removeAnnotation(IAnnotationDeclaration a) {
+ String name = ((AnnotationDeclaration)a).getTypeName();
+ IAnnotationDeclaration b = annotationsByType.get(name);
+ if(a == b) {
+ annotationsByType.remove(name);
+ annotations.remove(a);
+ }
+ }
+
+ public List<IAnnotationDeclaration> getAnnotations() {
+ return annotations;
+ }
+
+ public AnnotationDeclaration getAnnotation(String typeName) {
+ return annotationsByType.get(typeName);
+ }
+
+ public ITextSourceReference getAnnotationPosition(String annotationTypeName) {
+ return getAnnotation(annotationTypeName);
+ }
+
+ public boolean isAnnotationPresent(String annotationTypeName) {
+ return getAnnotation(annotationTypeName)!=null;
+ }
+
+ public AnnotationDeclaration getManagedBeanAnnotation() {
+ return annotationsByType.get(JSF2Constants.MANAGED_BEAN_ANNOTATION_TYPE_NAME);
+ }
+
+ public IResource getResource() {
+ return resource;
+ }
+
+ public ITextSourceReference getOriginalDefinition() {
+ return originalDefinition;
+ }
+}
\ No newline at end of file
Property changes on:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/impl/AbstractMemberDefinition.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/impl/AbstractTypeDefinition.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/impl/AbstractTypeDefinition.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/impl/AbstractTypeDefinition.java 2011-07-01
22:17:29 UTC (rev 32536)
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.jsf.jsf2.bean.model.impl;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IType;
+import org.jboss.tools.common.util.FileUtil;
+
+/**
+ *
+ * @author Viacheslav Kabanovich
+ *
+ */
+public class AbstractTypeDefinition extends AbstractMemberDefinition {
+ protected String qualifiedName;
+ protected IType type;
+
+ protected String content = null;
+
+ public AbstractTypeDefinition() {}
+
+ @Override
+ public AbstractTypeDefinition getTypeDefinition() {
+ return this;
+ }
+
+ public String getQualifiedName() {
+ return qualifiedName;
+ }
+
+ public IType getType() {
+ return type;
+ }
+
+ public void setType(IType type, DefinitionContext context, int flags) {
+ super.setAnnotatable(type, type, context, flags);
+ }
+
+ @Override
+ protected void init(IType contextType, DefinitionContext context, int flags) throws
CoreException {
+ this.type = contextType;
+ super.init(contextType, context, flags);
+ qualifiedName = getType().getFullyQualifiedName();
+ }
+
+ public String getContent() {
+ if(type == null || type.isBinary()) return null;
+ if(content == null && resource instanceof IFile &&
resource.getName().endsWith(".java")) {
+ content = FileUtil.getContentFromEditorOrFile((IFile)resource);
+ }
+ return content;
+ }
+
+}
Property changes on:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/impl/AbstractTypeDefinition.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/impl/DefinitionContext.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/impl/DefinitionContext.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/impl/DefinitionContext.java 2011-07-01
22:17:29 UTC (rev 32536)
@@ -0,0 +1,257 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.jsf.jsf2.bean.model.impl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IType;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.jsf.jsf2.bean.model.JSF2Constants;
+
+/**
+ *
+ * @author Viacheslav Kabanovich
+ *
+ */
+public class DefinitionContext {
+ protected JSF2Project project;
+ protected IJavaProject javaProject;
+
+ private Set<String> types = new HashSet<String>();
+ private Map<IPath, Set<IPath>> childPaths = new HashMap<IPath,
Set<IPath>>();
+ private Map<IPath, Set<String>> resources = new HashMap<IPath,
Set<String>>();
+ private Map<String, TypeDefinition> typeDefinitions = new HashMap<String,
TypeDefinition>();
+
+ private DefinitionContext workingCopy;
+ private DefinitionContext original;
+
+ public DefinitionContext() {}
+
+ private DefinitionContext copy(boolean clean) {
+ DefinitionContext copy = new DefinitionContext();
+ copy.project = project;
+ copy.javaProject = javaProject;
+ if(!clean) {
+ copy.types.addAll(types);
+ copy.typeDefinitions.putAll(typeDefinitions);
+
+ for (IPath p: resources.keySet()) {
+ Set<String> set = resources.get(p);
+ if(set != null) {
+ Set<String> s1 = new HashSet<String>();
+ s1.addAll(set);
+ copy.resources.put(p, s1);
+ }
+ }
+ for (IPath p: childPaths.keySet()) {
+ Set<IPath> set = childPaths.get(p);
+ if(set != null) {
+ Set<IPath> s1 = new HashSet<IPath>();
+ s1.addAll(set);
+ copy.childPaths.put(p, s1);
+ }
+ }
+ }
+
+ return copy;
+ }
+
+ public void setProject(JSF2Project project) {
+ this.project = project;
+ javaProject = EclipseResourceUtil.getJavaProject(project.getProject());
+ }
+
+ public JSF2Project getProject() {
+ return project;
+ }
+
+ public IJavaProject getJavaProject() {
+ return javaProject;
+ }
+
+ public void addType(IPath file, String typeName, TypeDefinition def) {
+ addType(file, typeName);
+ if(def != null) {
+ synchronized (typeDefinitions) {
+ typeDefinitions.put(def.getQualifiedName(), (TypeDefinition)def);
+ }
+ }
+ }
+
+ public void addType(IPath file, String typeName) {
+ if(file != null) {
+ Set<String> ts = resources.get(file);
+ if(ts == null) {
+ ts = new HashSet<String>();
+ resources.put(file, ts);
+ }
+ ts.add(typeName);
+ types.add(typeName);
+ addToParents(file);
+ }
+ }
+
+ public void addToParents(IPath file) {
+ if(file == null) return;
+ if(file.segmentCount() < 2) return;
+ IPath q = file;
+ while(q.segmentCount() >= 2) {
+ q = q.removeLastSegments(1);
+ Set<IPath> cs = childPaths.get(q);
+ if(cs == null) {
+ childPaths.put(q, cs = new HashSet<IPath>());
+ }
+ cs.add(file);
+ }
+ }
+
+ public void clean() {
+ childPaths.clear();
+ resources.clear();
+ types.clear();
+ synchronized (typeDefinitions) {
+ typeDefinitions.clear();
+ }
+
+ }
+
+ public void clean(IPath path) {
+ Set<String> ts = resources.remove(path);
+ if(ts != null) for (String t: ts) {
+ clean(t);
+ }
+
+ Set<IPath> cs = childPaths.get(path);
+ if(cs != null) {
+ IPath[] ps = cs.toArray(new IPath[0]);
+ for (IPath p: ps) {
+ clean(p);
+ }
+ } else {
+ removeFromParents(path);
+ }
+
+ }
+
+ public void clean(String typeName) {
+ types.remove(typeName);
+ synchronized (typeDefinitions) {
+ typeDefinitions.remove(typeName);
+ }
+ }
+
+ void removeFromParents(IPath file) {
+ if(file == null) return;
+ IPath q = file;
+ while(q.segmentCount() >= 2) {
+ q = q.removeLastSegments(1);
+ Set<IPath> cs = childPaths.get(q);
+ if(cs != null) {
+ cs.remove(file);
+ if(cs.isEmpty()) {
+ childPaths.remove(q);
+ }
+ }
+ }
+ }
+
+ public int getAnnotationKind(IType annotationType) {
+ if(annotationType == null) return -1;
+ if(!annotationType.exists()) return -1;
+ String name = annotationType.getFullyQualifiedName();
+ //? use cache for basic?
+ if(types.contains(name)) {
+ return 0;
+ }
+// if(AnnotationHelper.SCOPE_ANNOTATION_TYPES.contains(name)) {
+// return AnnotationDefinition.SCOPE;
+// }
+ if(JSF2Constants.MANAGED_BEAN_ANNOTATION_TYPE_NAME.equals(name)) {
+ return 1;
+ }
+ return 0;
+ }
+
+ public void newWorkingCopy(boolean forFullBuild) {
+ if(original != null) return;
+ workingCopy = copy(forFullBuild);
+ workingCopy.original = this;
+ }
+
+ public DefinitionContext getWorkingCopy() {
+ if(original != null) {
+ return this;
+ }
+ if(workingCopy != null) {
+ return workingCopy;
+ }
+ workingCopy = copy(false);
+ workingCopy.original = this;
+ return workingCopy;
+ }
+
+ public void applyWorkingCopy() {
+ if(original != null) {
+ original.applyWorkingCopy();
+ return;
+ }
+ if(workingCopy == null) {
+ return;
+ }
+
+ Set<TypeDefinition> newTypeDefinitions = new HashSet<TypeDefinition>();
+ for (String typeName: workingCopy.typeDefinitions.keySet()) {
+ TypeDefinition nd = workingCopy.typeDefinitions.get(typeName);
+ TypeDefinition od = typeDefinitions.get(typeName);
+ if(od != nd) {
+ newTypeDefinitions.add(nd);
+ }
+ }
+
+ types = workingCopy.types;
+ resources = workingCopy.resources;
+ childPaths = workingCopy.childPaths;
+ typeDefinitions = workingCopy.typeDefinitions;
+
+ project.update();
+
+ workingCopy = null;
+ }
+
+ public void dropWorkingCopy() {
+ if(original != null) {
+ original.dropWorkingCopy();
+ } else {
+ workingCopy = null;
+ }
+ }
+
+ public List<TypeDefinition> getTypeDefinitions() {
+ List<TypeDefinition> result = new ArrayList<TypeDefinition>();
+ synchronized (typeDefinitions) {
+ result.addAll(typeDefinitions.values());
+ }
+ return result;
+ }
+
+ public TypeDefinition getTypeDefinition(String fullyQualifiedName) {
+ return typeDefinitions.get(fullyQualifiedName);
+ }
+
+}
+
Property changes on:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/impl/DefinitionContext.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/impl/JSF2Project.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/impl/JSF2Project.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/impl/JSF2Project.java 2011-07-01
22:17:29 UTC (rev 32536)
@@ -0,0 +1,328 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.jsf.jsf2.bean.model.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.jboss.tools.common.model.XJob;
+import org.jboss.tools.common.model.XJob.XRunnable;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.common.util.EclipseJavaUtil;
+import org.jboss.tools.common.util.FileUtil;
+import org.jboss.tools.common.xml.XMLUtilities;
+import org.jboss.tools.jsf.JSFModelPlugin;
+import org.jboss.tools.jsf.jsf2.bean.model.IJSF2ManagedBean;
+import org.jboss.tools.jsf.jsf2.bean.model.IJSF2Project;
+import org.jboss.tools.jsf.jsf2.bean.model.JSF2ProjectFactory;
+import org.jboss.tools.jsf.jsf2.bean.scanner.lib.ClassPathMonitor;
+import org.jboss.tools.jst.web.kb.WebKbPlugin;
+import org.jboss.tools.jst.web.kb.internal.KbBuilder;
+import org.w3c.dom.Element;
+
+public class JSF2Project implements IJSF2Project {
+ IProject project = null;
+
+ ClassPathMonitor classPath = new ClassPathMonitor(this);
+ DefinitionContext definitions = new DefinitionContext();
+
+ boolean isBuilt = false;
+ private boolean isStorageResolved = false;
+
+ Set<JSF2Project> dependsOn = new HashSet<JSF2Project>();
+ Set<JSF2Project> usedBy = new HashSet<JSF2Project>();
+
+ private Map<IPath, Set<IJSF2ManagedBean>> beansByPath = new
HashMap<IPath, Set<IJSF2ManagedBean>>();
+ private Map<String, Set<IJSF2ManagedBean>> beansByName = new
HashMap<String, Set<IJSF2ManagedBean>>();
+ private Set<IJSF2ManagedBean> namedBeans = new HashSet<IJSF2ManagedBean>();
+
+ public JSF2Project() {
+ definitions.setProject(this);
+ }
+
+ @Override
+ public IJSF2ManagedBean[] getManagedBeans() {
+ return namedBeans.toArray(new IJSF2ManagedBean[0]);
+ }
+
+ @Override
+ public Set<IJSF2ManagedBean> getManagedBeans(IPath path) {
+ Set<IJSF2ManagedBean> result = new HashSet<IJSF2ManagedBean>();
+ Set<IJSF2ManagedBean> beans = beansByPath.get(path);
+ if(beans != null && !beans.isEmpty()) result.addAll(beans);
+ return result;
+ }
+
+ @Override
+ public IProject getProject() {
+ return project;
+ }
+
+ /**
+ * Convenience method.
+ *
+ * @param qualifiedName
+ * @return
+ */
+ public IType getType(String qualifiedName) {
+ IJavaProject jp = EclipseResourceUtil.getJavaProject(getProject());
+ if(jp == null) return null;
+ try {
+ return EclipseJavaUtil.findType(jp, qualifiedName);
+ } catch (JavaModelException e) {
+ JSFModelPlugin.getDefault().logError(e);
+ }
+ return null;
+ }
+
+ public void setProject(IProject project) {
+ this.project = project;
+ classPath.init();
+ }
+
+ @Override
+ public Set<JSF2Project> getUsedProjects() {
+ return dependsOn;
+ }
+
+ public Set<JSF2Project> getUsedProjects(boolean hierarchy) {
+ if(hierarchy) {
+ if(dependsOn.isEmpty()) return dependsOn;
+ Set<JSF2Project> result = new HashSet<JSF2Project>();
+ getAllUsedProjects(result);
+ return result;
+ } else {
+ return dependsOn;
+ }
+ }
+
+ void getAllUsedProjects(Set<JSF2Project> result) {
+ for (JSF2Project n: dependsOn) {
+ if(result.contains(n)) continue;
+ result.add(n);
+ n.getAllUsedProjects(result);
+ }
+ }
+
+ public Set<JSF2Project> getDependentProjects() {
+ return usedBy;
+ }
+
+ @Override
+ public void addUsedProject(final IJSF2Project project) {
+ if(dependsOn.contains(project)) return;
+ addUsedProjectInternal(project);
+ project.addDependentProject(this);
+ if(!project.isStorageResolved()) {
+ XJob.addRunnableWithPriority(new XRunnable() {
+ public void run() {
+ project.resolve();
+ project.update();
+ }
+ public String getId() {
+ return "Build JSF2 Project " + project.getProject().getName();
+ }
+ });
+ }
+ }
+
+ void addUsedProjectInternal(IJSF2Project project) {
+ synchronized (dependsOn) {
+ dependsOn.add((JSF2Project)project);
+ }
+ }
+
+ public void addDependentProject(IJSF2Project project) {
+ usedBy.add((JSF2Project)project);
+ }
+
+ @Override
+ public void removeUsedProject(IJSF2Project project) {
+ JSF2Project p = (JSF2Project)project;
+ if(!dependsOn.contains(p)) return;
+ p.usedBy.remove(this);
+ synchronized (dependsOn) {
+ dependsOn.remove(p);
+ }
+ }
+
+ public DefinitionContext getDefinitions() {
+ return definitions;
+ }
+
+ @Override
+ public void pathRemoved(IPath path) {
+ definitions.getWorkingCopy().clean(path);
+ }
+
+ public ClassPathMonitor getClassPath() {
+ return classPath;
+ }
+
+ @Override
+ public boolean isStorageResolved() {
+ return isStorageResolved;
+ }
+
+ public void resolveStorage(boolean load) {
+ if(isStorageResolved) return;
+ if(load) {
+ load();
+ } else {
+ isStorageResolved = true;
+ }
+ }
+
+ public void resolve() {
+ resolveStorage(true);
+ }
+
+ public void load() {
+ if(isStorageResolved) return;
+ isStorageResolved = true;
+ try {
+ getProject().build(IncrementalProjectBuilder.FULL_BUILD, KbBuilder.BUILDER_ID, new
HashMap(), new NullProgressMonitor());
+ } catch (CoreException e) {
+ JSFModelPlugin.getDefault().logError(e);
+ }
+
+ postponeFiring();
+
+ try {
+ //Use kb storage for dependent projects since cdi is not stored.
+ loadProjectDependenciesFromKBProject();
+ } finally {
+ fireChanges();
+ }
+ }
+
+ public void clean() {
+ File file = getStorageFile();
+ if(file != null && file.isFile()) {
+ file.delete();
+ }
+ isBuilt = false;
+ classPath.clean();
+ postponeFiring();
+
+ fireChanges();
+ }
+
+ public void update() {
+ //TODO
+ }
+
+ public void store() throws IOException {
+ isBuilt = true;
+// File file = getStorageFile();
+ }
+
+ private File getStorageFile() {
+ IPath path = JSFModelPlugin.getDefault().getStateLocation();
+ File file = new File(path.toFile(), "projects/" + project.getName());
//$NON-NLS-1$
+ return file;
+ }
+
+ public void clearStorage() {
+ File f = getStorageFile();
+ if(f == null || !f.exists()) return;
+ FileUtil.clear(f);
+ f.delete();
+ }
+
+ public boolean hasNoStorage() {
+ if(isBuilt) return false;
+ File f = getStorageFile();
+ return f == null || !f.exists();
+ }
+
+ public void postponeFiring() {
+ //TODO
+ }
+
+ public void fireChanges() {
+ //TODO
+ }
+
+ /**
+ * Test method.
+ */
+ public void reloadProjectDependencies() {
+ dependsOn.clear();
+ usedBy.clear();
+ loadProjectDependenciesFromKBProject();
+ }
+
+ private void loadProjectDependenciesFromKBProject() {
+ Element root = null;
+ File file = getKBStorageFile();
+ if(file != null && file.isFile()) {
+ root = XMLUtilities.getElement(file, null);
+ if(root != null) {
+ loadProjectDependencies(root);
+ }
+ }
+ }
+
+ private File getKBStorageFile() {
+ IPath path = WebKbPlugin.getDefault().getStateLocation();
+ File file = new File(path.toFile(), "projects/" + project.getName() +
".xml"); //$NON-NLS-1$ //$NON-NLS-2$
+ return file;
+ }
+
+ private void loadProjectDependencies(Element root) {
+ Element dependsOnElement = XMLUtilities.getUniqueChild(root,
"depends-on-projects"); //$NON-NLS-1$
+ if(dependsOnElement != null) {
+ Element[] paths = XMLUtilities.getChildren(dependsOnElement, "project");
//$NON-NLS-1$
+ for (int i = 0; i < paths.length; i++) {
+ String p = paths[i].getAttribute("name"); //$NON-NLS-1$
+ if(p == null || p.trim().length() == 0) continue;
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(p);
+ if(project == null || !project.isAccessible()) continue;
+ IJSF2Project sp = JSF2ProjectFactory.getJSF2Project(project, false);
+ if(sp != null) {
+ addUsedProjectInternal(sp);
+ sp.addDependentProject(this);
+ }
+ }
+ }
+
+ Element usedElement = XMLUtilities.getUniqueChild(root, "used-by-projects");
//$NON-NLS-1$
+ if(usedElement != null) {
+ Element[] paths = XMLUtilities.getChildren(usedElement, "project");
//$NON-NLS-1$
+ for (int i = 0; i < paths.length; i++) {
+ String p = paths[i].getAttribute("name"); //$NON-NLS-1$
+ if(p == null || p.trim().length() == 0) continue;
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(p);
+ if(project == null || !project.isAccessible()) continue;
+ IJSF2Project sp = JSF2ProjectFactory.getJSF2Project(project, false);
+ if(sp != null) {
+ addDependentProject(sp);
+ }
+ }
+ }
+
+ }
+
+}
Property changes on:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/impl/JSF2Project.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/impl/TypeDefinition.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/impl/TypeDefinition.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/impl/TypeDefinition.java 2011-07-01
22:17:29 UTC (rev 32536)
@@ -0,0 +1,17 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.jsf.jsf2.bean.model.impl;
+
+public class TypeDefinition extends AbstractTypeDefinition {
+
+ public TypeDefinition() {}
+
+}
Property changes on:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/model/impl/TypeDefinition.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/scanner/FileSet.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/scanner/FileSet.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/scanner/FileSet.java 2011-07-01
22:17:29 UTC (rev 32536)
@@ -0,0 +1,125 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.jsf.jsf2.bean.scanner;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.Flags;
+import org.eclipse.jdt.core.IPackageDeclaration;
+import org.eclipse.jdt.core.IType;
+import org.jboss.tools.jsf.JSFModelPlugin;
+
+public class FileSet {
+ private Set<IPath> allpaths = new HashSet<IPath>();
+ private Set<IPath> nonmodel = new HashSet<IPath>();
+ private Map<IPath, Set<IType>> annotations = new HashMap<IPath,
Set<IType>>();
+ private Map<IPath, Set<IType>> interfaces = new HashMap<IPath,
Set<IType>>();
+ private Map<IPath, Set<IType>> classes = new HashMap<IPath,
Set<IType>>();
+ private Map<IPath, IPackageDeclaration> packages = new HashMap<IPath,
IPackageDeclaration>();
+
+ public FileSet() {}
+
+ public void add(IPath path, IType[] types) throws CoreException {
+ allpaths.add(path);
+ if(types.length == 0) {
+ nonmodel.add(path);
+ } else {
+ for (IType type: types) {
+ add(path, type);
+ }
+ }
+ }
+ public void add(IPath path, IType type) throws CoreException {
+ allpaths.add(path);
+ if(!checkType(type, path)) {
+ //do nothing, bug JDT
+ } else if(type.isAnnotation()) {
+ add(annotations, path, type);
+ } else if(type.isInterface()) {
+ add(interfaces, path, type);
+ } else {
+ add(classes, path, type);
+ IType[] ts = type.getTypes();
+ for (IType t: ts) {
+ if(checkType(t, path) && Flags.isStatic(t.getFlags())) {
+ add(path, t);
+ }
+ }
+ }
+ }
+
+ private static Set<IPath> failedPaths = new HashSet<IPath>();
+
+ /**
+ * Workaround for
https://bugs.eclipse.org/bugs/show_bug.cgi?id=342757
+ * This method and field failedPaths should be removed as soon as the
+ * issue is fixed.
+ * @param type
+ * @param path
+ * @return
+ * @throws CoreException
+ */
+ private boolean checkType(IType type, IPath path) throws CoreException {
+ try {
+ type.isAnnotation();
+ } catch (ArrayIndexOutOfBoundsException e) {
+ if(failedPaths.contains(path)) return false; // Do not let's be too noisy.
+ failedPaths.add(path);
+ JSFModelPlugin.getDefault().logError("JDT failed to load " +
type.getFullyQualifiedName() + " from " + path + "\nSee
https://bugs.eclipse.org/bugs/show_bug.cgi?id=342757");
+ return false;
+ }
+ return true;
+ }
+
+ private void add(Map<IPath, Set<IType>> target, IPath path, IType type) {
+ Set<IType> ts = target.get(path);
+ if(ts == null) {
+ ts = new HashSet<IType>();
+ target.put(path, ts);
+ }
+ ts.add(type);
+ }
+
+ public void add(IPath path, IPackageDeclaration pkg) throws CoreException {
+ allpaths.add(path);
+ packages.put(path, pkg);
+ }
+
+ public Set<IPath> getAllPaths() {
+ return allpaths;
+ }
+
+ public Set<IPath> getNonModelFiles() {
+ return nonmodel;
+ }
+
+ public Map<IPath, Set<IType>> getAnnotations() {
+ return annotations;
+ }
+
+ public Map<IPath, Set<IType>> getInterfaces() {
+ return interfaces;
+ }
+
+ public Map<IPath, Set<IType>> getClasses() {
+ return classes;
+ }
+
+ public Map<IPath, IPackageDeclaration> getPackages() {
+ return packages;
+ }
+
+}
Property changes on:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/scanner/FileSet.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/scanner/lib/ClassPathMonitor.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/scanner/lib/ClassPathMonitor.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/scanner/lib/ClassPathMonitor.java 2011-07-01
22:17:29 UTC (rev 32536)
@@ -0,0 +1,168 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.jsf.jsf2.bean.scanner.lib;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.filesystems.FileSystemsHelper;
+import org.jboss.tools.common.model.project.ext.AbstractClassPathMonitor;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.jsf.JSFModelPlugin;
+import org.jboss.tools.jsf.jsf2.bean.model.IJSF2Project;
+import org.jboss.tools.jsf.jsf2.bean.model.JSF2ProjectFactory;
+
+public class ClassPathMonitor extends AbstractClassPathMonitor<IJSF2Project>{
+ IPath[] srcs = new IPath[0];
+
+ Set<IPath> removedPaths = new HashSet<IPath>();
+
+ public ClassPathMonitor(IJSF2Project project) {
+ this.project = project;
+ }
+
+ public void init() {
+ model = EclipseResourceUtil.createObjectForResource(getProjectResource()).getModel();
+ super.init();
+ }
+
+ public Map<String, XModelObject> process() {
+ Map<String, XModelObject> newJars = new HashMap<String, XModelObject>();
+ for (String p: syncProcessedPaths()) {
+ synchronized (removedPaths) {
+ removedPaths.add(new Path(p));
+ }
+ }
+ for (int i = 0; i < paths.size(); i++) {
+ String p = paths.get(i);
+ if(!requestForLoad(p)) continue;
+
+ String fileName = new File(p).getName();
+ if(EclipseResourceUtil.SYSTEM_JAR_SET.contains(fileName)) continue;
+
+ XModelObject o = FileSystemsHelper.getLibs(model).getLibrary(p);
+ if(o == null) continue;
+
+ XModelObject b = o.getChildByPath("META-INF/web-fragment.xml");
+ if(b != null) {
+ newJars.put(p, b);
+ }
+ }
+
+ validateProjectDependencies();
+ return newJars;
+ }
+
+ public void applyRemovedPaths() {
+ synchronized (removedPaths) {
+ for (IPath p: removedPaths) {
+ project.pathRemoved(p);
+ }
+ removedPaths.clear();
+ }
+ }
+
+ public IProject getProjectResource() {
+ return project.getProject();
+ }
+
+ public void setSrcs(IPath[] newSrcs) {
+ Set<IPath> ss = new HashSet<IPath>();
+ for (IPath s: newSrcs) {
+ ss.add(s);
+ }
+ for (IPath s: srcs) {
+ if(!ss.contains(s)) {
+ synchronized (removedPaths) {
+ removedPaths.add(s);
+ }
+ }
+ }
+ srcs = newSrcs;
+ }
+
+ public void validateProjectDependencies() {
+ List<IJSF2Project> ps = null;
+
+ try {
+ ps = getProjects(project.getProject());
+ } catch (CoreException e) {
+ JSFModelPlugin.getDefault().logError(e);
+ }
+ if(ps != null) {
+ Set<? extends IJSF2Project> set = project.getUsedProjects();
+ Set<IJSF2Project> removable = new HashSet<IJSF2Project>();
+ removable.addAll(set);
+ removable.removeAll(ps);
+ ps.removeAll(set);
+ for (IJSF2Project p : ps) {
+ project.addUsedProject(p);
+ }
+ for (IJSF2Project p : removable) {
+ project.removeUsedProject(p);
+ }
+ }
+ }
+
+ public boolean hasToUpdateProjectDependencies() {
+ List<IJSF2Project> ps = null;
+
+ try {
+ ps = getProjects(project.getProject());
+ } catch (CoreException e) {
+ JSFModelPlugin.getDefault().logError(e);
+ }
+ if(ps != null) {
+ Set<? extends IJSF2Project> set = project.getUsedProjects();
+ Set<IJSF2Project> removable = new HashSet<IJSF2Project>();
+ removable.addAll(set);
+ removable.removeAll(ps);
+ ps.removeAll(set);
+ for (IJSF2Project p : ps) {
+ return true;
+ }
+ for (IJSF2Project p : removable) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static List<IJSF2Project> getProjects(IProject project) throws
CoreException {
+ List<IJSF2Project> list = new ArrayList<IJSF2Project>();
+ IJavaProject javaProject = JavaCore.create(project);
+ IClasspathEntry[] es = javaProject.getResolvedClasspath(true);
+ for (int i = 0; i < es.length; i++) {
+ if(es[i].getEntryKind() == IClasspathEntry.CPE_PROJECT) {
+ IProject p =
ResourcesPlugin.getWorkspace().getRoot().getProject(es[i].getPath().lastSegment());
+ if(p == null || !p.isAccessible()) continue;
+ IJSF2Project sp = JSF2ProjectFactory.getJSF2Project(p, false);
+ if(sp != null) list.add(sp);
+ }
+ }
+ return list;
+ }
+
+}
\ No newline at end of file
Property changes on:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/bean/scanner/lib/ClassPathMonitor.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain