void build(boolean refresh, boolean reload) { if (!is_open) { open(); return; } Set<IFileData> oldfiles = null; if (refresh) { oldfiles = new HashSet<IFileData>(all_files); if (reload) { all_files.clear(); parse_data.clear(); } } for (IPathSpec ps : project_paths) { File dir = ps.getOSFile(base_directory); loadFiles(null, dir, reload); } if (oldfiles != null) { handleRefresh(oldfiles); } }
void outputProject(boolean files, boolean paths, boolean clss, boolean opts, IvyXmlWriter xw) { if (xw == null) return; xw.begin("PROJECT"); xw.field("NAME", project_name); xw.field("PATH", base_directory.getPath()); xw.field("WORKSPACE", project_manager.getWorkSpaceDirectory().getPath()); if (python_interpreter != null) { xw.textElement("EXE", python_interpreter.getExecutable().getPath()); } if (paths) { for (IPathSpec ps : project_paths) { ps.outputXml(xw); } } if (files) { for (IFileSpec fs : project_files) { fs.outputXml(xw); } } if (opts) pybase_prefs.outputXml(xw, true); xw.end("PROJECT"); }
String getProjectSourcePath() { String rslt = ""; for (IPathSpec ps : project_paths) { if (rslt.length() > 0) rslt += "|"; rslt += ps.getOSFile(base_directory); } return rslt; }
/** ***************************************************************************** */ void open() { if (is_open) return; for (IPathSpec ps : project_paths) { File dir = ps.getOSFile(base_directory); loadFiles(null, dir, false); } is_open = true; saveProject(); }
void outputXml(IvyXmlWriter xw) { xw.begin("PROJECT"); xw.field("NAME", project_name); xw.field("BASE", base_directory.getPath()); if (python_interpreter != null) { xw.textElement("EXE", python_interpreter.getExecutable().getPath()); } for (IPathSpec ps : project_paths) { ps.outputXml(xw); } for (IFileSpec fs : project_files) { fs.outputXml(xw); } pybase_prefs.outputXml(xw, false); xw.end("PROJECT"); }
public File findModuleFile(String name) throws PybaseException { File dir = null; String[] comps = name.split("\\."); for (IPathSpec ps : project_paths) { if (!ps.isUser()) continue; File f = ps.getOSFile(base_directory); if (!f.exists()) continue; for (int i = 0; i < comps.length - 1; ++i) { f = new File(f, comps[i]); } if (f.exists()) { dir = f; break; } } if (dir == null) throw new PybaseException("Can't find package for new module " + name); File fil = new File(dir, comps[comps.length - 1] + ".py"); return fil; }
/** ***************************************************************************** */ void findPackage(String name, IvyXmlWriter xw) { File dir = null; String[] comps = name.split("\\."); for (IPathSpec ps : project_paths) { if (!ps.isUser()) continue; File f = ps.getOSFile(base_directory); if (!f.exists()) continue; for (int i = 0; i < comps.length; ++i) { f = new File(f, comps[i]); } if (f.exists()) { dir = new File(f, comps[comps.length - 1]); break; } } if (dir != null && xw != null) { xw.begin("PACKAGE"); xw.field("NAME", name); xw.field("PATH", dir.getAbsolutePath()); xw.end("PACKAGE"); } }
/** ***************************************************************************** */ void editProject(Element pxml) { for (Element oelt : IvyXml.children(pxml, "OPTION")) { String k = IvyXml.getAttrString(oelt, "KEY"); String v = IvyXml.getAttrString(oelt, "VALUE"); pybase_prefs.setProperty(k, v); } Set<IPathSpec> done = new HashSet<IPathSpec>(); boolean havepath = false; for (Element pelt : IvyXml.children(pxml, "PATH")) { havepath = true; File f1 = new File(IvyXml.getAttrString(pelt, "DIRECTORY")); try { f1 = f1.getCanonicalFile(); } catch (IOException e) { f1 = f1.getAbsoluteFile(); } boolean fnd = false; for (IPathSpec ps : project_paths) { if (done.contains(ps)) continue; File p1 = ps.getOSFile(base_directory); if (f1.equals(p1)) { done.add(ps); fnd = true; // handle changes to ps at this point break; } } if (!fnd) { String fp1 = f1.getPath(); String fp2 = base_directory.getPath(); boolean rel = false; if (fp1.startsWith(fp2)) { String fp3 = fp1.substring(fp2.length()); StringTokenizer tok = new StringTokenizer(fp3, File.separator); File fd = null; while (tok.hasMoreTokens()) { String nm0 = tok.nextToken(); if (fd == null) fd = new File(nm0); else fd = new File(fd, nm0); } f1 = fd; rel = true; } boolean usr = IvyXml.getAttrBool(pelt, "USER"); IPathSpec ps = project_manager.createPathSpec(f1, usr, true, rel); done.add(ps); project_paths.add(ps); } } if (havepath) { for (Iterator<IPathSpec> it = project_paths.iterator(); it.hasNext(); ) { IPathSpec ps = it.next(); if (!done.contains(ps)) it.remove(); } } project_nature.rebuildPath(); saveProject(); }