private void handleRefresh(Set<IFileData> oldfiles) { IvyXmlWriter xw = pybase_main.beginMessage("RESOURCE"); int ctr = 0; for (IFileData fd : all_files) { IFileData old = null; for (IFileData ofd : oldfiles) { if (ofd.getFile().equals(fd.getFile())) { old = ofd; break; } } if (old == null) { outputDelta(xw, "ADDED", fd); ++ctr; } else if (old.getLastDateLastModified() != fd.getLastDateLastModified()) { oldfiles.remove(old); outputDelta(xw, "CHANGED", fd); ++ctr; } else { oldfiles.remove(old); } } for (IFileData fd : oldfiles) { outputDelta(xw, "REMOVED", fd); ++ctr; } if (ctr > 0) { pybase_main.finishMessage(xw); } }
void setupDefaults() { python_interpreter = project_manager.findInterpreter(null); if (python_interpreter == null) PybaseMain.logE("No interpreter found"); else PybaseMain.logD("Found interpreter " + python_interpreter.getName()); File src = new File(base_directory, "src"); if (src.isDirectory() || src.mkdir()) { File rsrc = new File("/src"); IPathSpec ps = project_manager.createPathSpec(rsrc, true, true, true); project_paths.add(ps); } }
/** ***************************************************************************** */ private void loadFiles(String pfx, File dir, boolean reload) { File[] fls = dir.listFiles(new SourceFilter()); if (fls != null) { for (File f : fls) { if (f.isDirectory()) { String nm = f.getName(); String opfx = pfx; if (pfx == null) pfx = nm; else pfx += "." + nm; loadFiles(pfx, f, reload); pfx = opfx; } else { String mnm = f.getName(); int idx = mnm.lastIndexOf("."); if (idx >= 0) mnm = mnm.substring(0, idx); if (pfx != null) mnm = pfx + "." + mnm; IFileData fd = PybaseFileManager.getFileManager().getNewFileData(f, mnm, this); ISemanticData isd = parse_data.get(fd); if (reload) { // fd.reload(); isd = null; } all_files.add(fd); if (isd == null) { ISemanticData sd = parseFile(fd); if (sd != null) { System.err.println("PYBASE: PARSE YIELDS: " + sd.getRootNode()); IvyXmlWriter xw = PybaseMain.getPybaseMain().beginMessage("FILEERROR"); xw.field("PROJECT", sd.getProject().getName()); xw.field("FILE", fd.getFile().getPath()); xw.begin("MESSAGES"); for (PybaseMessage m : sd.getMessages()) { try { System.err.println("PYBASE: PARSE ERROR: " + m); PybaseUtil.outputProblem(m, sd, xw); } catch (Throwable t) { PybaseMain.logE("Pybase error message: ", t); } } xw.end("MESSAGES"); PybaseMain.getPybaseMain().finishMessage(xw); } } } } } }
/** ***************************************************************************** */ void saveProject() { try { File f1 = new File(base_directory, ".pyproject"); IvyXmlWriter xw = new IvyXmlWriter(f1); outputXml(xw); xw.close(); } catch (IOException e) { PybaseMain.logE("Problem writing project file", e); } }
/** ***************************************************************************** */ PybaseProject(PybaseMain pm, String name, File base) { pybase_main = pm; project_manager = pm.getProjectManager(); base_directory = base.getAbsoluteFile(); try { base_directory = base_directory.getCanonicalFile(); } catch (IOException e) { } if (name == null) name = base.getName(); project_name = name; project_paths = new ArrayList<IPathSpec>(); project_files = new ArrayList<IFileSpec>(); pybase_prefs = new PybasePreferences(pm.getSystemPreferences()); all_files = new HashSet<IFileData>(); parse_data = new HashMap<IFileData, ISemanticData>(); File f = new File(base_directory, ".pybase"); if (!f.exists()) f.mkdir(); File f1 = new File(base_directory, ".pyproject"); Element xml = IvyXml.loadXmlFromFile(f1); if (xml == null) { setupDefaults(); } else { String bfile = IvyXml.getTextElement(xml, "EXE"); File bf = (bfile == null ? null : new File(bfile)); python_interpreter = project_manager.findInterpreter(bf); for (Element pe : IvyXml.children(xml, "PATH")) { IPathSpec ps = project_manager.createPathSpec(pe); project_paths.add(ps); } for (Element fe : IvyXml.children(xml, "FILE")) { IFileSpec fs = project_manager.createFileSpec(fe); project_files.add(fs); } pybase_prefs.loadXml(xml); } project_nature = new PybaseNature(pm, this); is_open = false; saveProject(); }