Skip to content

Commit

Permalink
Merge pull request #148 from phantomjinx/performance-bottlenecks
Browse files Browse the repository at this point in the history
Performance bottlenecks when building projects
  • Loading branch information
blafond committed May 2, 2013
2 parents 948a688 + 301b01b commit 0db9812
Show file tree
Hide file tree
Showing 35 changed files with 1,920 additions and 1,993 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
Expand Down Expand Up @@ -318,14 +317,8 @@ private IResource[] getResourcesForCurrentProject() throws CoreException {
}
}
// Check for VDBs

Collection<IFile> vdbs = WorkspaceResourceFinderUtil.getAllWorkspaceResources(WorkspaceResourceFinderUtil.VDB_RESOURCE_FILTER);
for( IFile vdb : vdbs ) {
if( vdb.getProject().equals(currentProject) ) {
resources.add(vdb);
}
}

Collection<IFile> vdbs = WorkspaceResourceFinderUtil.getProjectFileResources(currentProject, WorkspaceResourceFinderUtil.VDB_RESOURCE_FILTER);
resources.addAll(vdbs);

if (resources.isEmpty()) {
return new IResource[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
import org.teiid.designer.core.util.StartupLogger;
import org.teiid.designer.core.util.WorkspaceUriPathConverter;
import org.teiid.designer.core.validation.ValidationRuleManager;
import org.teiid.designer.core.workspace.DotProjectUtils;
import org.teiid.designer.core.workspace.ModelProject;
import org.teiid.designer.core.workspace.ModelResource;
import org.teiid.designer.core.workspace.ModelStatusImpl;
Expand Down Expand Up @@ -1299,30 +1300,7 @@ public static DatatypeManager getWorkspaceDatatypeManager() {
* @since 4.0
*/
public static boolean hasModelNature( final IProject project ) {
CoreArgCheck.isNotNull(project);
try {
return project.hasNature(NATURE_ID);
} catch (final CoreException e) {
// project does not exist or is not open
}
return false;
}

/**
* Returns true if the given project is accessible and it has a java nature, otherwise false.
*
* @since 4.0
*/
public static boolean hasNature( final IProject project,
final String nature ) {
CoreArgCheck.isNotNull(project);
CoreArgCheck.isNotEmpty(nature);
try {
return project.hasNature(nature);
} catch (final CoreException e) {
// project does not exist or is not open
}
return false;
return DotProjectUtils.isModelerProject(project);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
Expand Down Expand Up @@ -107,7 +106,7 @@ public static void buildResources( final IProgressMonitor monitor,

for (final Iterator resourceIter = projectIResources.iterator(); resourceIter.hasNext();) {
IResource resource = (IResource)resourceIter.next();
Collection models = WorkspaceResourceFinderUtil.getResourcesThatUse(resource);
Collection models = WorkspaceResourceFinderUtil.getResourcesThatUse(resource, IResource.DEPTH_ZERO);
models.removeAll(projectIResources);
dependentModels.addAll(models);
}
Expand Down Expand Up @@ -148,7 +147,7 @@ public static void buildResources( final IProgressMonitor monitor,

for (final Iterator resourceIter = projectIResources.iterator(); resourceIter.hasNext();) {
IResource resource = (IResource)resourceIter.next();
Collection models = WorkspaceResourceFinderUtil.getResourcesThatUse(resource);
Collection models = WorkspaceResourceFinderUtil.getResourcesThatUse(resource, IResource.DEPTH_ZERO);
models.removeAll(projectIResources);
dependentModels.addAll(models);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
Expand Down Expand Up @@ -212,9 +212,8 @@ public Object run( final UnitOfWork uow ) throws ModelerCoreException {
// Add to the iResources collection any VDB IResource that references one of
// the entries in iResourcs. We want to revalidate VDBs that reference modified
// resources in the workspace (defect 15779)
IResource[] vdbResources = WorkspaceResourceFinderUtil.getVdbResourcesThatContain(iResources);
for (int i = 0; i != vdbResources.length; ++i) {
IResource vdbResource = vdbResources[i];
Collection<IFile> vdbResources = WorkspaceResourceFinderUtil.getVdbResourcesThatContain(iResources);
for (IFile vdbResource : vdbResources) {
if (!iResources.contains(vdbResource)) {
iResources.add(vdbResource);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
Expand Down Expand Up @@ -183,25 +184,25 @@ protected IResource findResourceInProjectByName( final String name ) {
}

IResource iResource = null;
IResource[] iResources = WorkspaceResourceFinderUtil.findIResourceByName(name);
Collection<IFile> iResources = WorkspaceResourceFinderUtil.findIResourceByName(name);

if (iResources.length == 0) {
if (iResources.size() == 0) {
return null;
} else if (iResources.length == 1) {
iResource = iResources[0];
} else if (iResources.size() == 1) {
iResource = iResources.iterator().next();
} else {
// Find the IResource with this name in the same IProject as the IResource being operated on
IResource iRes = WorkspaceResourceFinderUtil.findIResource(this.resource.getURI());
IProject project = iRes.getProject();
for (int idx = 0; idx < iResources.length; idx++) {
if (iResources[idx].getProject() == project) {
iResource = iResources[idx];
for (IFile fileResource : iResources) {
if (fileResource.getProject().equals(project)) {
iResource = fileResource;
break;
}
}
// If no IResource exists in this project then pick the first on in the array
if (iResource == null) {
iResource = iResources[0];
iResource = iResources.iterator().next();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public RelatedResourceFinder(IResource sourceResource) {
*/
private Collection<IFile> findDependentResources(IResource resource) {

Collection<IFile> dependentResources = new HashSet<IFile>();
Collection<IFile> dependentResources = Collections.emptyList();

try {
if (resource instanceof IContainer) {
Expand All @@ -55,17 +55,17 @@ private Collection<IFile> findDependentResources(IResource resource) {
if (resource.exists()) {
IContainer folder = (IContainer) resource;
IResource[] resources = folder.members();
dependentResources = new HashSet<IFile>();

for (int idx = 0; idx < resources.length; idx++) {
dependentResources.addAll(findDependentResources(resources[idx]));
}
} // endif
} else {
WorkspaceResourceFinderUtil.getResourcesThatUseRecursive(resource, RESOURCE_FILTER, dependentResources);
dependentResources = WorkspaceResourceFinderUtil.getResourcesThatUse(resource, RESOURCE_FILTER, IResource.DEPTH_INFINITE);
}
} catch (CoreException ce) {
ModelerCore.Util.log(ce);
dependentResources = Collections.EMPTY_LIST;
}

return dependentResources;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,9 @@ private Collection dependentResources( final boolean isUndo ) {
* @return Collection
* @since 4.3
*/
private static Collection dependentResources( IResource res ) {
private static Collection<IFile> dependentResources( IResource res ) {

Collection dependentResources = new ArrayList();
Collection<IFile> dependentResources = null;

try {
if (res instanceof IContainer) {
Expand All @@ -342,14 +342,14 @@ private static Collection dependentResources( IResource res ) {
if (res.exists()) {
IContainer folder = (IContainer)res;
IResource[] resources = folder.members();
dependentResources = new LinkedList();
dependentResources = new LinkedList<IFile>();

for (int idx = 0; idx < resources.length; idx++) {
dependentResources.addAll(dependentResources(resources[idx]));
}
} // endif
} else {
WorkspaceResourceFinderUtil.getResourcesThatUseRecursive(res, RESOURCE_FILTER, dependentResources);
dependentResources = WorkspaceResourceFinderUtil.getResourcesThatUse(res, RESOURCE_FILTER, IResource.DEPTH_INFINITE);
}
} catch (CoreException ce) {
ModelerCore.Util.log(ce);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectNature;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.teiid.core.designer.util.CoreArgCheck;
import org.teiid.designer.common.xml.JdomHelper;
import org.teiid.designer.core.ModelerCore;

Expand Down Expand Up @@ -69,7 +69,7 @@ public static IFile getDotProjectFile( IContainer container ) {

public static int getDotProjectCount( String fileName,
boolean recurse,
boolean onlyModelerProjects ) throws IOException, JDOMException {
boolean onlyModelerProjects ) throws Exception {
File file = new File(fileName);
return getDotProjectCount(file, recurse, onlyModelerProjects);
}
Expand All @@ -86,7 +86,7 @@ public static int getDotProjectCount( String fileName,
*/
public static int getDotProjectCount( File file,
boolean recurse,
boolean onlyModelerProjects ) throws IOException, JDOMException {
boolean onlyModelerProjects ) throws Exception {
int dotProjectCount = 0;
int depth = 0;
List<File> resources = new ArrayList<File>();
Expand Down Expand Up @@ -122,7 +122,7 @@ public static int getDotProjectCount( File file,
*/

public static boolean isDotProject( String file,
boolean onlyModelerProject ) throws IOException, JDOMException {
boolean onlyModelerProject ) throws Exception {
return isDotProject(new File(file), onlyModelerProject);
}

Expand All @@ -135,7 +135,7 @@ public static boolean isDotProject( String file,
* @return
*/
public static boolean isDotProject( File file,
boolean onlyModelerProject ) throws IOException, JDOMException {
boolean onlyModelerProject ) throws Exception {
if (file.getName().equals(DOT_PROJECT)) {
if (onlyModelerProject) {
Document doc = JdomHelper.buildDocument(file);
Expand Down Expand Up @@ -165,7 +165,7 @@ public static boolean isDotProject( File file,
*/
public static int getDotProjectCount( IResource targetResource,
boolean recurse,
boolean onlyModelerProjects ) throws CoreException, IOException, JDOMException {
boolean onlyModelerProjects ) throws Exception {
int dotProjectCount = 0;
int depth = 0;
List<IResource> resources = new ArrayList<IResource>();
Expand Down Expand Up @@ -201,13 +201,12 @@ public static int getDotProjectCount( IResource targetResource,
* @return
*/
public static boolean isDotProject( IResource resource,
boolean onlyModelerProject ) throws CoreException, IOException, JDOMException {
boolean onlyModelerProject ) throws Exception {
if (resource.getName().equals(DOT_PROJECT) && resource.getType() == IResource.FILE) {
if (onlyModelerProject) {
if (resource.isAccessible()) {
if (resource.getProject().isOpen()) {
IProjectNature nature = resource.getProject().getNature(ModelerCore.NATURE_ID);
return nature != null;
return resource.getProject().hasNature(ModelerCore.NATURE_ID);
}

return isModelNature(resource);
Expand Down Expand Up @@ -291,30 +290,38 @@ public static boolean isModelerProject( IProject iProject ) {
return result;
}

/**
* Returns true if the given project is accessible and it has a java nature, otherwise false.
*
* @since 4.0
*/
public static boolean hasNature( final IProject project, final String nature ) {
CoreArgCheck.isNotNull(project);
CoreArgCheck.isNotEmpty(nature);
try {
return project.hasNature(nature);
} catch (final CoreException e) {
// project does not exist or is not open
}
return false;
}

/**
* Returns a list of open Model Projects within the workspace
*
* @return array of Modeler <code>IProject</code>s
* @return collection of Modeler <code>IProject</code>s
*/
public static IProject[] getOpenModelProjects() {
public static Collection<IProject> getOpenModelProjects() {
IProject[] allProjects = ModelerCore.getWorkspace().getRoot().getProjects();

List<IProject> openModelProjectList = new ArrayList<IProject>(allProjects.length);

for (IProject proj : allProjects) {
if (proj.isOpen() && isModelerProject(proj) && !ModelerCore.hasNature(proj, ModelerCore.HIDDEN_PROJECT_NATURE_ID)) {
if (proj.isOpen() && isModelerProject(proj) && !hasNature(proj, ModelerCore.HIDDEN_PROJECT_NATURE_ID)) {
openModelProjectList.add(proj);
}
}

IProject[] projArray = new IProject[openModelProjectList.size()];
int i = 0;
for (IProject mProj : openModelProjectList) {
projArray[i++] = mProj;
}

return projArray;
return openModelProjectList;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,6 @@ ModelProject createModelProject(String name, IPath path, IProgressMonitor monito
* @exception ModelWorkspaceException if this request fails.
*/
ModelProject[] getModelProjects() throws ModelWorkspaceException;

/**
* Returns an array of non-model resources (that is, non-Modeling projects) in
* the workspace.
* <p>
* Non-Modeling projects include all projects that are closed (even if they have the
* Modeling nature).
* </p>
*
* @return an array of non-modeling projects contained in the workspace.
* @throws ModelWorkspaceException if this element does not exist or if an
* exception occurs while accessing its corresponding resource
*/
Object[] getNonModelingResources() throws ModelWorkspaceException;

/**
* Obtains all the {@link ModelResource}s found in open model projects in the workspace.
Expand Down

0 comments on commit 0db9812

Please sign in to comment.