Skip to content

Commit

Permalink
Fixed file search to search directories recursively
Browse files Browse the repository at this point in the history
  • Loading branch information
rsdunlapiv committed Jul 11, 2014
1 parent 793902e commit 265ca46
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
import org.earthsystemmodeling.psyche.ConceptDef;
import org.earthsystemmodeling.psyche.Language;
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.ProjectScope;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.photran.core.IFortranAST;
import org.eclipse.photran.internal.core.vpg.PhotranVPG;
Expand Down Expand Up @@ -50,7 +53,10 @@ public static FSM<?> reverseEngineer(Language lang, IProject project, PhotranVPG
Set<IFortranAST> asts = new HashSet<IFortranAST>();

try {
String fileList = project.getPersistentProperty(CupidPropertyPage.NUOPC_FILES_QN);
//String fileList = project.getPersistentProperty(CupidPropertyPage.NUOPC_FILES_QN);
IEclipsePreferences prefs = new ProjectScope(project).getNode("org.earthsystemmodeling.cupid");
String fileList = prefs.get(CupidPropertyPage.NUOPC_FILES_PROPERTY, null);

if (fileList != null && fileList.length() > 1) {
for (String path : fileList.split("\n")) {
IFile f = (IFile) project.findMember(path.trim());
Expand All @@ -72,34 +78,27 @@ public static FSM<?> reverseEngineer(Language lang, IProject project, PhotranVPG
}
}
else {
for (IResource r : project.members()) {
//TODO: deal with folders - recursive method
if (r instanceof IFile) {
//System.out.println("Full path: " + r.getFullPath());
//TODO: deal with these file extensions
if (r.getProjectRelativePath().getFileExtension() != null &&
(r.getProjectRelativePath().getFileExtension().equalsIgnoreCase("f") ||
r.getProjectRelativePath().getFileExtension().equalsIgnoreCase("f90"))) {
CupidActivator.log("ReverseEngineer2.reverseEngineer: adding file: " + r.getFullPath());
IFortranAST ast = vpg.acquireTransientAST((IFile) r);
if (ast == null) {
CupidActivator.log(Status.ERROR, "ReverseEngineer2.reverseEngineer - AST not found: " + r.getFullPath());
}
else {
asts.add(ast);
}
}

Set<IFile> files = getFiles(project.members());
for (IFile f : files) {
CupidActivator.log("ReverseEngineer2.reverseEngineer: adding file: " + f.getFullPath());
IFortranAST ast = vpg.acquireTransientAST(f);
if (ast == null) {
CupidActivator.log(Status.ERROR, "ReverseEngineer2.reverseEngineer - AST not found: " + f.getFullPath());
}
else {
asts.add(ast);
}
}
CupidActivator.log(files.size() + " total Fortran files found in project.");
}
}
catch (CoreException e1) {
CupidActivator.log(Status.ERROR, "ReverseEngineer2.reverseEngineer", e1);
//e1.printStackTrace();
return fsm;
}

CupidActivator.log("Found ASTs for " + asts.size() + " files.");

//root = reverse(fsm, asts, topConcept, root, fsm.getMappings(), eFactory);

fsm.reverse(asts);
Expand All @@ -109,6 +108,24 @@ public static FSM<?> reverseEngineer(Language lang, IProject project, PhotranVPG
return fsm;

}

private static Set<IFile> getFiles(IResource[] resources) throws CoreException {
Set<IFile> files = new HashSet<IFile>();
for (IResource r : resources) {
if (r instanceof IFile) {
if (r.getProjectRelativePath().getFileExtension() != null &&
(r.getProjectRelativePath().getFileExtension().equalsIgnoreCase("f") ||
r.getProjectRelativePath().getFileExtension().equalsIgnoreCase("f90"))) {
files.add((IFile) r);
}
}
else if (r instanceof IFolder) {
files.addAll( getFiles( ((IFolder) r).members() ) );
}
}
return files;

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.jface.preference.PreferencePage;
Expand All @@ -27,9 +26,9 @@ public class CupidPropertyPage extends PropertyPage {

private static final String PATH_TITLE = "Project:";
private static final String OWNER_TITLE = "NUOPC Resources:";
private static final String NUOPC_FILES_PROPERTY = "NUOPC_FILES";
public static final String NUOPC_FILES_PROPERTY = "NUOPC_FILES";

public static QualifiedName NUOPC_FILES_QN = new QualifiedName("", NUOPC_FILES_PROPERTY);
//public static QualifiedName NUOPC_FILES_QN = new QualifiedName("", NUOPC_FILES_PROPERTY);

private static final int TEXT_FIELD_WIDTH = 50;

Expand Down

0 comments on commit 265ca46

Please sign in to comment.