/** {@inheritDoc} */ @Override public boolean accept(File f) { if (f.isDirectory()) return this.acceptDirectories; for (FileFilter ff : this.filters) { if (ff.accept(f)) return true; } return false; }
@Override public String[] getExtensions() { List<String> extensions = new ArrayList<String>(); for (FileFilter ff : this.filters) { extensions.addAll(Arrays.asList(ff.getExtensions())); } String[] tab = new String[extensions.size()]; extensions.toArray(tab); return tab; }
public static void copyDir( @NotNull File fromDir, @NotNull File toDir, @Nullable final FileFilter filter) throws IOException { ensureExists(toDir); if (isAncestor(fromDir, toDir, true)) { LOG.error(fromDir.getAbsolutePath() + " is ancestor of " + toDir + ". Can't copy to itself."); return; } File[] files = fromDir.listFiles(); if (files == null) throw new IOException( CommonBundle.message("exception.directory.is.invalid", fromDir.getPath())); if (!fromDir.canRead()) throw new IOException( CommonBundle.message("exception.directory.is.not.readable", fromDir.getPath())); for (File file : files) { if (filter != null && !filter.accept(file)) { continue; } if (file.isDirectory()) { copyDir(file, new File(toDir, file.getName()), filter); } else { copy(file, new File(toDir, file.getName())); } } }
public static boolean isFilePathAcceptable(@NotNull File root, @Nullable FileFilter fileFilter) { File file = root; do { if (fileFilter != null && !fileFilter.accept(file)) return false; file = file.getParentFile(); } while (file != null); return true; }
/** * Determines whether the file should be selected. * * @param fileInfo The file selection information. * @return true if the file should be selected, false otherwise. */ public boolean accept(final FileSelectInfo fileInfo) { if (fileFilter != null) { return fileFilter.accept(fileInfo); } throw new IllegalArgumentException( Messages.getString("vfs.selectors/filefilter.missing.error")); }
public SloccountReport(SloccountReport old, FileFilter filter) { this(); for (File f : old.getFiles()) { if (filter.include(f)) { this.add(f.getName(), f.getLanguage(), f.getModule(), f.getLineCount()); } } }
public static void copy(File srcFile, File targetFile, boolean overwrite, FileFilter filter) throws FileNotFoundException, IOException { if (filter != null && !filter.accept(srcFile.getCanonicalFile())) return; if (!srcFile.exists()) throw new ConfigurationError("Source file not found: " + srcFile); if (!overwrite && targetFile.exists()) throw new ConfigurationError("Target file already exists: " + targetFile); if (srcFile.isFile()) copyFile(srcFile, targetFile); else copyDirectory(srcFile, targetFile, overwrite, filter); }
public static boolean selectInDirectory( List<String> list, File dir, int limit, FileFilter fileFilter) { String[] listDirectory = dir.list(); Arrays.sort(listDirectory); for (int i = 0; i < listDirectory.length; i++) { File f = new File(dir, listDirectory[i]); if (f.isFile() && fileFilter.accept(f)) { list.add(f.getAbsolutePath()); if (list.size() >= limit) return true; } } for (int i = 0; i < listDirectory.length; i++) { File f = new File(dir, listDirectory[i]); if (f.isDirectory() && selectInDirectory(list, f, limit, fileFilter)) return true; } return false; }
/* (non-Javadoc) * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) */ protected Control createDialogArea(Composite parent) { Composite result = (Composite) super.createDialogArea(parent); final Button button = new Button(result, SWT.CHECK); button.setText(fFilterMessage); button.setFont(parent.getFont()); IDialogSettings settings = PhingUi.getDefault().getDialogSettings(); fShowAll = settings.getBoolean(DIALOG_SETTING); String lastPath = settings.get(LAST_CONTAINER); if (lastPath != null) { IPath path = Path.fromPortableString(lastPath); IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path); setInitialSelection(resource); } fFilter.considerExtension(!fShowAll); getTreeViewer().addFilter(fFilter); if (!fShowAll) { button.setSelection(true); } button.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { if (button.getSelection()) { fShowAll = false; } else { fShowAll = true; } fFilter.considerExtension(!fShowAll); getTreeViewer().refresh(); } }); applyDialogFont(result); return result; }
public int compileJava() { try { // create new bin directory boolean createBin = new File(classPath).mkdir(); // create new javac ProcessBuilder // ProcessBuilder pb = // new ProcessBuilder("javac", "-d", classPath, "./" + studentPath + "/*.java"); ProcessBuilder pbDir = new ProcessBuilder("dir"); // Determine current working directory File srcAbsPath = new File(sourcePath); srcAbsPathName = srcAbsPath.getAbsolutePath(); System.out.println("Compiler.java line 69 source path: " + sourcePath); System.out.println("Compiler.java line 69 source absolute path: " + srcAbsPathName); File cwd = pbDir.directory(); // debug code - to confirm correct directory // TestTools.dir(cwd); // NB - ProcessBuilder default is to return a null // pointer for the abstract path to indicate that it // is using System.Properties "user.dir", i.e., the // current system working directory; hence the // critical need to handle a NullPointerException. // Also returns a null pointer if the directory // doesn't exist. // all this is doing is changing the dir, can we approach this in a different way using a // value in our Data Object? -mh File nwd = TestTools.cd(cwd, studentPath); System.out.println("(Compiler.java line 88)new working directory: " + nwd.toString()); String studentPathName = nwd.getAbsolutePath(); File nwdPath = new File(studentPath); System.out.println("(Compiler.java line 91)new working directory path: " + studentPathName); // debug code to test new working directory // TestTools.dir(nwd); FileFilter filter = new FileFilter() {}; String[] javaFileList = nwdPath.list(filter); // set up output file File outputFile = new File(outputFileName); // System.out.println(outputFileName); outputFile.delete(); for (int k = 0; k < javaFileList.length; k++) { try { if (filter.accept(nwdPath, javaFileList[k]) == true) { System.out.println("COMPILER.JAVA (line 111) Compiling: " + javaFileList[k]); String compilePath = "javac" + "-d" + classPath + ".\\" + studentPath + "\\" + javaFileList[k]; System.out.println("Compiler.java 117 compile path: " + compilePath); ProcessBuilder pb = // new ProcessBuilder("javac ", "-d", classPath, ".\\" + studentPath + "\\" + // javaFileList[k]); new ProcessBuilder(compilePath); // System.out.println(pb.environment().toString()); <-- THIS IS VERY INTERESTING // Create environment map and set environmental variables Map<String, String> env = pb.environment(); env.clear(); env.put("PATH", path); env.put("CLASSPATH", classPath); // env.put("SOURCEPATH", sourcePath); // env.remove("OTHERVAR"); pb.redirectErrorStream(true); pb.redirectOutput(Redirect.appendTo(outputFile)); // start javac process Process p = pb.start(); // need other processes to wait for compilation to finish // basically joins the thread to the javac process to force sequential // execution - need to be careful - if any process hangs, whole run hangs success = p .waitFor(); // Returns the exit value of the process. By convention, 0 indicates // normal termination. // http://docs.oracle.com/javase/6/docs/api/java/lang/Process.html#waitFor%28%29 assert pb.redirectInput() == Redirect.PIPE; assert pb.redirectOutput().file() == outputFile; assert p.getInputStream().read() == -1; System.out.println("COMPILER.JAVA (line 138) end of loop, success = " + success); } } catch (Exception e) { System.out.println(" Compiler.java FOR LOOP Compile Exception: " + javaFileList[k]); } } } catch (Exception e) { System.out.println("Compile Exception, PROBABLY DUE TO FILE PATH"); System.out.println("source absolute path: " + srcAbsPathName); } return success; }
@Override public boolean shouldHonorFileEncodingForCompilation(File file) { return JAVA_SOURCES_FILTER.accept(file); }