String ls(String args[], boolean relative) { if (args.length < 2) throw new IllegalArgumentException( "the ${ls} macro must at least have a directory as parameter"); File dir = domain.getFile(args[1]); if (!dir.isAbsolute()) throw new IllegalArgumentException( "the ${ls} macro directory parameter is not absolute: " + dir); if (!dir.exists()) throw new IllegalArgumentException( "the ${ls} macro directory parameter does not exist: " + dir); if (!dir.isDirectory()) throw new IllegalArgumentException( "the ${ls} macro directory parameter points to a file instead of a directory: " + dir); Collection<File> files = new ArrayList<File>(new SortedList<File>(dir.listFiles())); for (int i = 2; i < args.length; i++) { Instructions filters = new Instructions(args[i]); files = filters.select(files, true); } List<String> result = new ArrayList<String>(); for (File file : files) result.add(relative ? file.getName() : file.getAbsolutePath()); return Processor.join(result, ","); }
public void init(Editor _editor) { this.m_editor = _editor; File toolRoot = null; try { toolRoot = new File( SequantoAutomationTool.class .getProtectionDomain() .getCodeSource() .getLocation() .toURI()) .getParentFile() .getParentFile(); } catch (java.net.URISyntaxException ex) { toolRoot = new File( SequantoAutomationTool.class .getProtectionDomain() .getCodeSource() .getLocation() .getPath()) .getParentFile() .getParentFile(); } m_generatorPy = new File(new File(toolRoot, "generator"), "generate_automation_defines.py") .getAbsolutePath(); m_isWindows = System.getProperty("os.name").toLowerCase().contains("win"); if (m_isWindows) { for (File root : File.listRoots()) { File[] files = root.listFiles( new FileFilter() { public boolean accept(File f) { return f.getName().toLowerCase().startsWith("python"); } }); if (files != null) { for (File directory : files) { m_pythonPath = new File(directory, "python.exe"); break; } } } if (m_pythonPath == null) { Base.showMessage( "ERROR", String.format( "Could not python interpreter - Generate Automation tool will not work.")); } } }
/** * Garbage collect repository * * @throws Exception */ public void gc() throws Exception { HashSet<byte[]> deps = new HashSet<byte[]>(); // deps.add(SERVICE_JAR_FILE); for (File cmd : commandDir.listFiles()) { CommandData data = getData(CommandData.class, cmd); addDependencies(deps, data); } for (File service : serviceDir.listFiles()) { File dataFile = new File(service, "data"); ServiceData data = getData(ServiceData.class, dataFile); addDependencies(deps, data); } int count = 0; for (File f : repoDir.listFiles()) { String name = f.getName(); if (!deps.contains(name)) { if (!name.endsWith(".json") || !deps.contains(name.substring(0, name.length() - ".json".length()))) { // Remove // json // files // only // if // the // bin // is // going // as // well f.delete(); count++; } else { } } } System.out.format("Garbage collection done (%d file(s) removed)%n", count); }
public List<CommandData> getCommands(File commandDir) throws Exception { List<CommandData> result = new ArrayList<CommandData>(); if (!commandDir.exists()) { return result; } for (File f : commandDir.listFiles()) { CommandData data = getData(CommandData.class, f); if (data != null) result.add(data); } return result; }
private ArrayList GetFolderTree(String s_Dir, String s_Flag, int n_Indent, int n_TreeIndex) { String s_List = ""; ArrayList aSubFolders = new ArrayList(); File file = new File(s_Dir); File[] filelist = file.listFiles(); if (filelist != null && filelist.length > 0) { for (int i = 0; i < filelist.length; i++) { if (filelist[i].isDirectory()) { aSubFolders.add(filelist[i].getName()); } } int n_Count = aSubFolders.size(); String s_LastFlag = ""; String s_Folder = ""; for (int i = 1; i <= n_Count; i++) { if (i < n_Count) { s_LastFlag = "0"; } else { s_LastFlag = "1"; } s_Folder = aSubFolders.get(i - 1).toString(); s_List = s_List + "arr" + s_Flag + "[" + String.valueOf(n_TreeIndex) + "]=new Array(\"" + s_Folder + "\"," + String.valueOf(n_Indent) + ", " + s_LastFlag + ");\n"; n_TreeIndex = n_TreeIndex + 1; ArrayList a_Temp = GetFolderTree(s_Dir + s_Folder + sFileSeparator, s_Flag, n_Indent + 1, n_TreeIndex); s_List = s_List + a_Temp.get(0).toString(); n_TreeIndex = Integer.valueOf(a_Temp.get(1).toString()).intValue(); } } ArrayList a_Return = new ArrayList(); a_Return.add(s_List); a_Return.add(String.valueOf(n_TreeIndex)); return a_Return; }
public List<ServiceData> getServices(File serviceDir) throws Exception { List<ServiceData> result = new ArrayList<ServiceData>(); if (!serviceDir.exists()) { return result; } for (File sdir : serviceDir.listFiles()) { File dataFile = new File(sdir, "data"); ServiceData data = getData(ServiceData.class, dataFile); result.add(data); } return result; }
static void listPath(File path, FileFilter filter) { File files[]; // list of files in a directory indentLevel++; // going down... // create list of files in this dir files = path.listFiles(filter); // Sort with help of Collections API Arrays.sort(files); for (int i = 0, n = files.length; i < n; i++) { for (int indent = 0; indent < indentLevel; indent++) { System.out.print(" "); } if (files[i].isDirectory()) { System.out.println(files[i].toString()); // recursively descend dir tree listPath(files[i], filter); } else { processFile(files[i]); } } indentLevel--; // and going up }
// remove temp files, the pipeline.jar operator isn't working. public void deleteTempFiles() { System.out.println("\nRemoving these temp files:"); File workingDir = new File(System.getProperty("user.dir")); File[] toExamine = workingDir.listFiles(); for (File f : toExamine) { boolean d = false; String n = f.getName(); if (n.startsWith("pipeinstancelog")) d = true; else if (n.contains(".DOC.sample")) d = true; else if (n.contains("allDepths.")) d = true; else if (n.startsWith("nocalls.")) d = true; else if (n.startsWith("snpeff.")) d = true; else if (n.contains("plice")) d = true; if (d) { System.out.println("\t" + n); f.deleteOnExit(); } } // delete the temp uncompressed vcf (required by Pipeline.jar) if (deleteTempVcf) System.out.println("\t" + finalVcf.getName()); }
private void InitUpload() throws ServletException, IOException { String sConfig = myUtil.ReadFile(myUtil.getConfigFileRealPath(m_request.getServletPath())); ArrayList aStyle = myUtil.getConfigArray("Style", sConfig); String sAllowExt, sUploadDir, sBaseUrl, sContentPath; String sCurrDir, sDir; int nAllowBrowse; String sPathShareImage, sPathShareFlash, sPathShareMedia, sPathShareOther; // param String sType = myUtil.dealNull(m_request.getParameter("type")).toUpperCase(); String sStyleName = myUtil.dealNull(m_request.getParameter("style")); String sCusDir = myUtil.dealNull(m_request.getParameter("cusdir")); String sAction = myUtil.dealNull(m_request.getParameter("action")).toUpperCase(); String s_SKey = myUtil.dealNull(m_request.getParameter("skey")); // InitUpload String[] aStyleConfig = new String[1]; boolean bValidStyle = false; for (int i = 0; i < aStyle.size(); i++) { aStyleConfig = myUtil.split(aStyle.get(i).toString(), "|||"); if (sStyleName.toLowerCase().equals(aStyleConfig[0].toLowerCase())) { bValidStyle = true; break; } } if (!bValidStyle) { out.print(getOutScript("alert('Invalid Style!')")); out.close(); return; } if (!aStyleConfig[61].equals("1")) { sCusDir = ""; } String ss_FileSize = "", ss_FileBrowse = "", ss_SpaceSize = "", ss_SpacePath = "", ss_PathMode = "", ss_PathUpload = "", ss_PathCusDir = "", ss_PathCode = "", ss_PathView = ""; if ((aStyleConfig[61].equals("2")) && (!s_SKey.equals(""))) { ss_FileSize = (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_FileSize")); ss_FileBrowse = (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_FileBrowse")); ss_SpaceSize = (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_SpaceSize")); ss_SpacePath = (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_SpacePath")); ss_PathMode = (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_PathMode")); ss_PathUpload = (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_PathUpload")); ss_PathCusDir = (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_PathCusDir")); ss_PathCode = (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_PathCode")); ss_PathView = (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_PathView")); if (myUtil.IsInt(ss_FileSize)) { aStyleConfig[11] = ss_FileSize; aStyleConfig[12] = ss_FileSize; aStyleConfig[13] = ss_FileSize; aStyleConfig[14] = ss_FileSize; aStyleConfig[15] = ss_FileSize; aStyleConfig[45] = ss_FileSize; } else { ss_FileSize = ""; } if (ss_FileBrowse.equals("0") || ss_FileBrowse.equals("1")) { aStyleConfig[43] = ss_FileBrowse; } else { ss_FileBrowse = ""; } if (myUtil.IsInt(ss_SpaceSize)) { aStyleConfig[78] = ss_SpaceSize; } else { ss_SpaceSize = ""; } if (!ss_PathMode.equals("")) { aStyleConfig[19] = ss_PathMode; } if (!ss_PathUpload.equals("")) { aStyleConfig[3] = ss_PathUpload; } if (!ss_PathCode.equals("")) { aStyleConfig[23] = ss_PathCode; } if (!ss_PathView.equals("")) { aStyleConfig[22] = ss_PathView; } sCusDir = ss_PathCusDir; } sBaseUrl = aStyleConfig[19]; nAllowBrowse = Integer.valueOf(aStyleConfig[43]).intValue(); if (nAllowBrowse != 1) { out.print(getOutScript("alert('Do not allow browse!')")); out.close(); return; } if (!sCusDir.equals("")) { sCusDir = myUtil.replace(sCusDir, "\\", "/"); if ((sCusDir.startsWith("/")) || (sCusDir.startsWith(".")) || (sCusDir.endsWith(".")) || (sCusDir.indexOf("./") >= 0) || (sCusDir.indexOf("/.") >= 0) || (sCusDir.indexOf("//") >= 0) || (sCusDir.indexOf("..") >= 0)) { sCusDir = ""; } else { if (!sCusDir.endsWith("/")) { sCusDir = sCusDir + "/"; } } } sUploadDir = aStyleConfig[3]; if (!sBaseUrl.equals("3")) { sUploadDir = myUtil.getRealPathFromRelative(m_request.getServletPath(), sUploadDir); } sUploadDir = GetSlashPath(sUploadDir); sUploadDir = sUploadDir + myUtil.replace(myUtil.replace(sCusDir, "/", sFileSeparator), "\\", sFileSeparator); if (sType.equals("FILE")) { sAllowExt = aStyleConfig[6]; } else if (sType.equals("MEDIA")) { sAllowExt = aStyleConfig[9]; } else if (sType.equals("FLASH")) { sAllowExt = aStyleConfig[7]; } else { sAllowExt = aStyleConfig[8]; } sPathShareImage = GetSlashPath( myUtil.getRealPathFromRelative(m_request.getServletPath(), "sharefile/image/")); sPathShareFlash = GetSlashPath( myUtil.getRealPathFromRelative(m_request.getServletPath(), "sharefile/flash/")); sPathShareMedia = GetSlashPath( myUtil.getRealPathFromRelative(m_request.getServletPath(), "sharefile/media/")); sPathShareOther = GetSlashPath( myUtil.getRealPathFromRelative(m_request.getServletPath(), "sharefile/other/")); String s_Out = ""; if (sAction.equals("FILE")) { String s_ReturnFlag = myUtil.dealNull(m_request.getParameter("returnflag")); String s_FolderType = myUtil.dealNull(m_request.getParameter("foldertype")); String s_Dir = myUtil.dealNull(m_request.getParameter("dir")); s_Dir = java.net.URLDecoder.decode(s_Dir, "UTF-" + "8"); String s_CurrDir = ""; if (s_FolderType.equals("upload")) { s_CurrDir = sUploadDir; } else if (s_FolderType.equals("shareimage")) { sAllowExt = ""; s_CurrDir = sPathShareImage; } else if (s_FolderType.equals("shareflash")) { sAllowExt = ""; s_CurrDir = sPathShareFlash; } else if (s_FolderType.equals("sharemedia")) { sAllowExt = ""; s_CurrDir = sPathShareMedia; } else { s_FolderType = "shareother"; sAllowExt = ""; s_CurrDir = sPathShareOther; } s_Dir = myUtil.replace(s_Dir, "\\", "/"); if ((s_Dir.startsWith("/")) || (s_Dir.startsWith(".")) || (s_Dir.endsWith(".")) || (s_Dir.indexOf("./") >= 0) || (s_Dir.indexOf("/.") >= 0) || (s_Dir.indexOf("//") >= 0) || (s_Dir.indexOf("..") >= 0)) { s_Dir = ""; } String s_Dir2 = myUtil.replace(s_Dir, "/", sFileSeparator); s_Dir2 = myUtil.replace(s_Dir2, "\\", sFileSeparator); if (!s_Dir.equals("")) { if (CheckValidDir(s_CurrDir + s_Dir2)) { s_CurrDir += s_Dir2; } else { s_Dir = ""; } } if (CheckValidDir(s_CurrDir)) { File file = new File(s_CurrDir); File[] filelist = file.listFiles(); if (filelist != null && filelist.length > 0) { int n = -1; for (int i = 0; i < filelist.length; i++) { if (filelist[i].isFile()) { String s_FileName = filelist[i].getName(); String s_FileExt = s_FileName.substring(s_FileName.lastIndexOf(".") + 1); s_FileExt = s_FileExt.toLowerCase(); if (CheckValidExt(sAllowExt, s_FileExt)) { n++; s_Out = s_Out + "arr[" + String.valueOf(n) + "]=new Array(\"" + s_FileName + "\", \"" + String.valueOf(convertFileSize(filelist[i].length())) + "\",\"" + formatDate(new Date(filelist[i].lastModified())) + "\");\n"; } } } } } s_Out = "var arr = new Array();\n" + s_Out + "parent.setFileList('" + s_ReturnFlag + "', '" + s_FolderType + "', '" + s_Dir + "', arr);"; out.print(getOutScript(s_Out)); } else { s_Out = "var arrUpload = new Array();\n"; s_Out += "var arrShareImage = new Array();\n"; s_Out += "var arrShareFlash = new Array();\n"; s_Out += "var arrShareMedia = new Array();\n"; s_Out += "var arrShareOther = new Array();\n"; s_Out += GetFolderTree(sUploadDir, "Upload", 1, 0).get(0).toString(); sAllowExt = ""; if (sType.equals("FILE")) { s_Out += GetFolderTree(sPathShareImage, "ShareImage", 1, 0).get(0).toString(); s_Out += GetFolderTree(sPathShareFlash, "ShareFlash", 1, 0).get(0).toString(); s_Out += GetFolderTree(sPathShareMedia, "ShareMedia", 1, 0).get(0).toString(); s_Out += GetFolderTree(sPathShareOther, "ShareOther", 1, 0).get(0).toString(); } else if (sType.equals("MEDIA")) { s_Out += GetFolderTree(sPathShareMedia, "ShareMedia", 1, 0).get(0).toString(); } else if (sType.equals("FLASH")) { s_Out += GetFolderTree(sPathShareFlash, "ShareFlash", 1, 0).get(0).toString(); } else { s_Out += GetFolderTree(sPathShareImage, "ShareImage", 1, 0).get(0).toString(); } s_Out += "parent.setFolderList(arrUpload, arrShareImage, arrShareFlash, arrShareMedia, arrShareOther);"; out.print(getOutScript(s_Out)); } }