diff --git a/com.ibm.wala.core/src/com/ibm/wala/classLoader/SourceDirectoryTreeModule.java b/com.ibm.wala.core/src/com/ibm/wala/classLoader/SourceDirectoryTreeModule.java index e6bc27daf..fffe04098 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/classLoader/SourceDirectoryTreeModule.java +++ b/com.ibm.wala.core/src/com/ibm/wala/classLoader/SourceDirectoryTreeModule.java @@ -18,17 +18,30 @@ import com.ibm.wala.util.debug.Assertions; * a module representing a directory tree of source files. * * @author julian dolby (?) + * @author smarkstr (added file extension) * */ public class SourceDirectoryTreeModule extends DirectoryTreeModule { + /** + * file extension of source files in directory tree + * (defaults to "java" for Java source files) + */ + String fileExt = "java"; + public SourceDirectoryTreeModule(File root) { super(root); } + public SourceDirectoryTreeModule(File root, String fileExt) { + super(root); + if (fileExt != null) + this.fileExt = fileExt; + } + @Override protected boolean includeFile(File file) { - return file.getName().endsWith("java"); + return file.getName().endsWith(fileExt); } @Override diff --git a/com.ibm.wala.core/src/com/ibm/wala/eclipse/util/EclipseProjectPath.java b/com.ibm.wala.core/src/com/ibm/wala/eclipse/util/EclipseProjectPath.java index 633f3b6c2..2275f5944 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/eclipse/util/EclipseProjectPath.java +++ b/com.ibm.wala.core/src/com/ibm/wala/eclipse/util/EclipseProjectPath.java @@ -58,6 +58,7 @@ import com.ibm.wala.util.debug.Assertions; * * @author sjfink * @author jdolby (some code moved here from EclipseProjectAnalysisEngine) + * @author smarkstr (added support for language file extensions) * */ public class EclipseProjectPath { @@ -122,7 +123,7 @@ public class EclipseProjectPath { * of modules */ @SuppressWarnings("restriction") - private void resolveClasspathEntry(IClasspathEntry entry, Loader loader) throws JavaModelException, IOException { + private void resolveClasspathEntry(IClasspathEntry entry, Loader loader, String fileExtension) throws JavaModelException, IOException { IClasspathEntry e = JavaCore.getResolvedClasspathEntry(entry); if (alreadyResolved.contains(e)) { return; @@ -133,7 +134,7 @@ public class EclipseProjectPath { if (e.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IClasspathContainer cont = JavaCore.getClasspathContainer(entry.getPath(), project); IClasspathEntry[] entries = cont.getClasspathEntries(); - resolveClasspathEntries(entries, cont.getKind() == IClasspathContainer.K_APPLICATION ? loader : Loader.PRIMORDIAL); + resolveClasspathEntries(entries, cont.getKind() == IClasspathContainer.K_APPLICATION ? loader : Loader.PRIMORDIAL, fileExtension); } else if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { File file = makeAbsolute(e.getPath()).toFile(); JarFile j; @@ -148,7 +149,7 @@ public class EclipseProjectPath { } else if (e.getEntryKind() == IClasspathEntry.CPE_SOURCE) { File file = makeAbsolute(e.getPath()).toFile(); Set s = MapUtil.findOrCreateSet(sourceModules, Loader.SOURCE); - s.add(new SourceDirectoryTreeModule(file)); + s.add(new SourceDirectoryTreeModule(file, fileExtension)); if (e.getOutputLocation() != null) { File output = makeAbsolute(e.getOutputLocation()).toFile(); s = MapUtil.findOrCreateSet(binaryModules, loader); @@ -162,7 +163,7 @@ public class EclipseProjectPath { try { if (project.hasNature(JavaCore.NATURE_ID)) { IJavaProject javaProject = JavaCore.create(project); - resolveClasspathEntries(javaProject.getRawClasspath(), loader); + resolveClasspathEntries(javaProject.getRawClasspath(), loader, fileExtension); File output = makeAbsolute(javaProject.getOutputLocation()).toFile(); Set s = MapUtil.findOrCreateSet(binaryModules, loader); s.add(new BinaryDirectoryTreeModule(output)); @@ -176,9 +177,9 @@ public class EclipseProjectPath { } } - protected void resolveClasspathEntries(IClasspathEntry[] entries, Loader loader) throws JavaModelException, IOException { + protected void resolveClasspathEntries(IClasspathEntry[] entries, Loader loader, String fileExtension) throws JavaModelException, IOException { for (int i = 0; i < entries.length; i++) { - resolveClasspathEntry(entries[i], loader); + resolveClasspathEntry(entries[i], loader, fileExtension); } } @@ -189,8 +190,25 @@ public class EclipseProjectPath { return workspaceRootPath.append(p); } + /** + * If file extension is not provided, use system default + * + * @throws JavaModelException + * @throws IOException + */ public void resolveProjectClasspathEntries() throws JavaModelException, IOException { - resolveClasspathEntries(project.getRawClasspath(), Loader.EXTENSION); + resolveClasspathEntries(project.getRawClasspath(), Loader.EXTENSION, null); + } + + /** + * If file extension is provided, use that to resolve source files in the classpath + * + * @param fileExtension + * @throws JavaModelException + * @throws IOException + */ + public void resolveProjectClasspathEntries(String fileExtension) throws JavaModelException, IOException { + resolveClasspathEntries(project.getRawClasspath(), Loader.EXTENSION, fileExtension); } /**