use of org.eclipse.wst.jsdt.core.JavaScriptModelException in project ow by vtst.
the class ClosureCompiler method getJavaScriptFilesOfProject.
/**
* Get the JavaScript files from a project, according to the class path entries of the project.
* @param project
* @return The set of JavaScript files, may be empty but not null.
* @throws CoreException
*/
// Inspired from org.eclipse.wst.jsdt.internal.core.builder.AbstractImageBuilder.addAllSourceFiles
public static Set<IFile> getJavaScriptFilesOfProject(IProject project) throws CoreException {
final JavaProject javaProject = (JavaProject) JavaScriptCore.create(project);
final Set<IFile> result = new HashSet<IFile>();
boolean hasClasspathEntry = false;
try {
final IIncludePathEntry[] expandedClassPath = javaProject.getExpandedClasspath();
for (IIncludePathEntry includePathEntry : expandedClassPath) {
if (!(includePathEntry instanceof ClasspathEntry))
continue;
final ClasspathEntry entry = (ClasspathEntry) includePathEntry;
int entryKind = entry.getEntryKind();
if (entryKind != IIncludePathEntry.CPE_SOURCE && entryKind != IIncludePathEntry.CPE_LIBRARY)
continue;
IResource includeResource = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath());
if (includeResource == null)
continue;
switch(entryKind) {
case IIncludePathEntry.CPE_SOURCE:
hasClasspathEntry = true;
includeResource.accept(new IResourceVisitor() {
public boolean visit(IResource resource) throws CoreException {
if (resource instanceof IFile) {
IFile file = (IFile) resource;
if (ClosureCompiler.isJavaScriptFile(file) && !Util.isExcluded(file.getFullPath(), entry.fullInclusionPatternChars(), entry.fullExclusionPatternChars(), false)) {
result.add(file);
}
return false;
} else if (resource instanceof IContainer) {
try {
IContainer container = (IContainer) resource;
if (container instanceof IFolder && isExcludedFromProject(javaProject, expandedClassPath, container.getFullPath())) {
return false;
}
return (!Util.isExcluded(container.getFullPath(), entry.fullInclusionPatternChars(), entry.fullExclusionPatternChars(), false) || entry.fullInclusionPatternChars() != null);
} catch (Exception e) {
e.printStackTrace();
return false;
}
} else
return false;
}
});
break;
case IIncludePathEntry.CPE_LIBRARY:
if (includeResource instanceof IFile && project.equals(includeResource.getProject())) {
hasClasspathEntry = true;
result.add((IFile) includeResource);
}
break;
}
}
if (!hasClasspathEntry) {
// If there was no class path entry, we add all JavaScript files from the project.
project.accept(new IResourceVisitor() {
public boolean visit(IResource resource) throws CoreException {
if (resource instanceof IFile) {
IFile file = (IFile) resource;
if (ClosureCompiler.isJavaScriptFile(file))
result.add(file);
}
return true;
}
});
}
return result;
} catch (JavaScriptModelException e) {
e.printStackTrace();
return Collections.emptySet();
}
}
Aggregations