List of usage examples for org.apache.commons.io.filefilter TrueFileFilter TRUE
IOFileFilter TRUE
To view the source code for org.apache.commons.io.filefilter TrueFileFilter TRUE.
Click Source Link
From source file:org.sonar.batch.scan.filesystem.LanguageFilters.java
public IOFileFilter forLang(String lang) { Language language = languages.get(lang); if (language == null) { return FalseFileFilter.FALSE; }//ww w. ja v a 2 s. c o m String[] suffixes = language.getFileSuffixes(); if (suffixes != null && suffixes.length > 0) { return new SuffixFileFilter(suffixes, IOCase.SENSITIVE); } return TrueFileFilter.TRUE; }
From source file:org.sonar.java.JavaClasspath.java
private List<File> getMatchingFiles(String pattern, File dir, boolean libraryProperty) { WilcardPatternFileFilter wilcardPatternFileFilter = new WilcardPatternFileFilter(dir, pattern); FileFilter fileFilter = wilcardPatternFileFilter; List<File> files = Lists.newArrayList(); if (libraryProperty) { if (pattern.endsWith("*")) { fileFilter = new AndFileFilter((IOFileFilter) fileFilter, new OrFileFilter(Lists.newArrayList(suffixFileFilter(".jar", IOCase.INSENSITIVE), suffixFileFilter(".zip", IOCase.INSENSITIVE)))); }//ww w.j a va2 s .co m //find jar and zip files files.addAll( Lists.newArrayList(FileUtils.listFiles(dir, (IOFileFilter) fileFilter, TrueFileFilter.TRUE))); } //find directories matching pattern. IOFileFilter subdirectories = pattern.isEmpty() ? FalseFileFilter.FALSE : TrueFileFilter.TRUE; Collection<File> dirs = FileUtils.listFilesAndDirs(dir, new AndFileFilter(wilcardPatternFileFilter, DirectoryFileFilter.DIRECTORY), subdirectories); //remove searching dir from matching as listFilesAndDirs always includes it in the list see https://issues.apache.org/jira/browse/IO-328 if (!pattern.isEmpty()) { dirs.remove(dir); //remove subdirectories that were included during search Iterator<File> iterator = dirs.iterator(); while (iterator.hasNext()) { File matchingDir = iterator.next(); if (!wilcardPatternFileFilter.accept(matchingDir)) { iterator.remove(); } } } if (libraryProperty) { for (File directory : dirs) { files.addAll(getMatchingFiles("**/*.jar", directory, true)); files.addAll(getMatchingFiles("**/*.zip", directory, true)); } } files.addAll(dirs); return files; }
From source file:org.sonatype.nexus.mock.SimpleTest.java
private void tamperPlexusProperties(File basedir) throws Exception { Collection<File> files = FileUtils.listFiles(basedir, new NameFileFilter("plexus.properties"), TrueFileFilter.TRUE); assertEquals(1, files.size());/* ww w.j a v a 2 s. com*/ File pp = files.iterator().next(); assertTrue(pp.exists()); Properties p = new Properties(); InputStream in = new FileInputStream(pp); p.load(in); IOUtil.close(in); p.setProperty("application-port", String.valueOf(port)); OutputStream out = new FileOutputStream(pp); p.store(out, ""); IOUtil.close(out); }
From source file:org.sonatype.nexus.test.booter.Jetty7NexusBooter.java
/** * This method just the "heavy lifting" for method {@link #tamperJarsForSharedClasspath(File)}. It traverses passed * in {@code basedir}, matches against {@code wildcard}, and matched JARs moves to {@code sharedLibs} folder while * keeping source files but overwriting them to 0 byte length "placeholders". The reason for this is, that in case * of plugin dependency, Nexus Plugin Manager would "scream" if dependency is declared by it's corresponding JAR * file is not found. Having the 0 byte "fake" file in place, we only make Nexus PM "happy", but effectively * removing classes from Nexus core or plugin's classloader, since they will be in the IT shared classloader and is * visible to them./*from ww w. j a va2s. c o m*/ * * @param basedir * @param sharedLibs * @param wildcard * @throws IOException */ protected void tamperJarsForSharedClasspath(final File basedir, final File sharedLibs, final String wildcard) throws IOException { @SuppressWarnings("unchecked") Collection<File> files = (Collection<File>) FileUtils.listFiles(basedir, new WildcardFileFilter(wildcard), TrueFileFilter.TRUE); for (File file : files) { // only if not in /shared folder and not zeroed already if (!file.getParentFile().equals(sharedLibs) && file.length() > 0) { // copy jar to /shared FileUtils.copyFile(file, new File(sharedLibs, file.getName())); // replace jar with dummies (to make Nexus Plugin Manager happy) and prevent it's classes to be // loaded from non-shared class loader FileUtils.writeStringToFile(file, ""); } } }
From source file:org.sonatype.nexus.testsuite.task.nexus2692.AbstractEvictTaskIt.java
@SuppressWarnings("unchecked") protected SortedSet<String> getFilePaths(File basedir) throws IOException { SortedSet<String> result = new TreeSet<String>(); Collection<File> files = FileUtils.listFiles(basedir, TrueFileFilter.TRUE, TrueFileFilter.TRUE); for (File file : files) { if (!file.equals(basedir)) { String path = file.getPath(); if (path.startsWith(basedir.getAbsolutePath())) { path = path.substring(basedir.getAbsolutePath().length() + 1); }//w w w. j ava 2 s .c om result.add(path.replaceAll(Pattern.quote("\\"), "/")); } } return result; }
From source file:org.sonatype.nexus.testsuite.task.nexus2692.AbstractEvictTaskIt.java
@SuppressWarnings("unchecked") protected SortedSet<String> getDirectoryPaths(File basedir) throws IOException { SortedSet<String> result = new TreeSet<String>(); Collection<File> files = FileUtils.listFilesAndDirs(basedir, FalseFileFilter.FALSE, TrueFileFilter.TRUE); for (File file : files) { if (!file.equals(basedir)) { String path = file.getPath(); if (path.startsWith(basedir.getAbsolutePath())) { path = path.substring(basedir.getAbsolutePath().length() + 1); }/* w w w. ja va 2 s . c om*/ result.add(path.replaceAll(Pattern.quote("\\"), "/")); } } return result; }
From source file:org.zgis.wps.swat.AnnotatedSwatRunnerAlgorithm.java
@Execute public void runSwatProcess() throws IOException { logger.info("Trying to run SWAT model"); //TODO make a list of needed directories and create in loop String tempDirStr = ExecutionContextFactory.getContext().getTempDirectoryPath(); File tempDir = new File(tempDirStr + System.getProperty("file.separator")); File swatModelDir = new File(tempDirStr + System.getProperty("file.separator") + "swatmodel" + System.getProperty("file.separator")); logger.info("Temp dir is: " + tempDirStr); logger.info("Temp file is: " + tempDir.getAbsolutePath()); try {/* w w w . j a v a 2 s . c o m*/ if (!tempDir.isDirectory() && !tempDir.mkdirs()) { throw new IOException("Could not create temp dir " + tempDir); } if (!swatModelDir.isDirectory() && !swatModelDir.mkdirs()) { throw new IOException("Could not create swatmodel dir " + tempDir); } //unpack swat model if (swatInputZip == null) { logger.info("SwatInputZip was NULL"); } else if (swatInputZip.size() != 1) { logger.info("SwatInputZip size != 1 - " + swatInputZip.size()); } else { logger.info("Unpacking swatInputZip " + swatInputZip.get(0).getBaseFile(false).getAbsolutePath() + " to " + swatModelDir.getAbsolutePath()); net.lingala.zip4j.core.ZipFile zipFile = new net.lingala.zip4j.core.ZipFile( swatInputZip.get(0).getBaseFile(false)); zipFile.extractAll(swatModelDir.getAbsolutePath()); } URI jarUri = this.getJarURI(); logger.debug("Jar-File URI " + jarUri); //FIXME this is bullshit, make own jar for every OS and provide executable this way. String exeFilename = "swat/swat_rel64"; if (System.getProperty("os.name").toLowerCase().startsWith("windows")) { exeFilename = exeFilename.concat("_win.exe"); } else if (System.getProperty("os.name").toLowerCase().startsWith("mac")) { exeFilename = exeFilename.concat("_osx"); } else if (System.getProperty("os.name").toLowerCase().startsWith("linux")) { exeFilename = exeFilename.concat("_linux"); } else { logger.warn("Could not determine OS, trying generic executable name"); } URI exeFile = getFile(jarUri, exeFilename); new File(exeFile).setExecutable(true); ProcessBuilder pb = new ProcessBuilder(new File(exeFile).toString()); pb.redirectErrorStream(true); pb.directory(swatModelDir); Process process = pb.start(); InputStream stdOutStream = process.getInputStream(); InputStreamReader isr = new InputStreamReader(stdOutStream); BufferedReader br = new BufferedReader(isr); String line; logger.info(String.format("Output of running %s is:\n", Arrays.toString(pb.command().toArray()))); while ((line = br.readLine()) != null) { logger.info(line); this.swatConsoleOutput = this.swatConsoleOutput.concat(line).concat("\n"); } int exitValue = process.waitFor(); if (exitValue != 0) { throw new IOException("SWAT didn't complete successfully"); } Collection<File> outFiles = FileUtils.listFiles(swatModelDir, new WildcardFileFilter("output.*"), TrueFileFilter.TRUE); File outFilesZippend = org.n52.wps.io.IOUtils.zip(outFiles.toArray(new File[outFiles.size()])); this.swatOutputZipped = new GenericFileData(outFilesZippend, "application/zip"); } catch (URISyntaxException e) { logger.error("Could not determine uri of jar. ", e); throw new IOException("Could not determine uri of jar. ", e); } catch (InterruptedException e) { logger.error("Exception on running SWAT process.", e); throw new IOException("Exception on running SWAT process.", e); } catch (net.lingala.zip4j.exception.ZipException e) { logger.error("Could not extract swat input model.", e); throw new IOException("Could not extract swat input model.", e); } finally { //TODO FIXME is that really necessary? The Execution context should delete this? /* if (tempDir.isDirectory()) { FileUtils.deleteDirectory(tempDir); } */ } }
From source file:org.zgis.wps.swat.WeatherFetchAlgorithm.java
@Execute public void run() throws IOException { logger.info("Fetching Weather"); //TODO make a list of needed directories and create in loop String tempDirStr = ExecutionContextFactory.getContext().getTempDirectoryPath(); File tempDir = new File(tempDirStr + System.getProperty("file.separator")); logger.info("Temp dir is: " + tempDirStr); logger.info("Temp file is: " + tempDir.getAbsolutePath()); try {//from ww w . j a va 2 s . co m if (!tempDir.isDirectory() && !tempDir.mkdirs()) { throw new IOException("Could not create temp dir " + tempDir); } //TODO fetch SOS String response = getObservations(this.sosUrl, sosProcedure, 3); //FIXME set file filter! Collection<File> outFiles = FileUtils.listFiles(tempDir, new WildcardFileFilter("output.*"), TrueFileFilter.TRUE); File outFilesZippend = org.n52.wps.io.IOUtils.zip(outFiles.toArray(new File[outFiles.size()])); this.weatherZipped = new GenericFileData(outFilesZippend, "application/zip"); } finally { //TODO FIXME is that really necessary? The Execution context should delete this? /* if (tempDir.isDirectory()) { FileUtils.deleteDirectory(tempDir); } */ } }
From source file:pt.webdetails.cpf.utils.PluginUtils.java
/** * Calls out for resources in the plugin, on the specified path * * @param elementPath Relative to the plugin directory * @param recursive Do we want to enable recursivity? * @param pattern regular expression to filter the files * @return Files found/*from w ww .j ava 2s .c o m*/ */ @Override public Collection<File> getPluginResources(String elementPath, Boolean recursive, String pattern) { IOFileFilter fileFilter = TrueFileFilter.TRUE; if (pattern != null && !pattern.equals("")) { fileFilter = new RegexFileFilter(pattern); } IOFileFilter dirFilter = recursive.equals(Boolean.TRUE) ? TrueFileFilter.TRUE : null; // TODO: why doesn't this use repository access? // Get directory name. We need to make sure we're not allowing this to fetch other resources String basePath = null; String elementFullPath = null; try { basePath = URLDecoder.decode(FilenameUtils.normalize(getPluginDirectory().getAbsolutePath()), CharsetHelper.getEncoding()); elementFullPath = URLDecoder.decode(FilenameUtils.normalize(basePath + File.separator + elementPath), CharsetHelper.getEncoding()); } catch (UnsupportedEncodingException e) { //CharseHelper.getEncoding() returns a valid encoding } if (!elementFullPath.startsWith(basePath)) { logger.warn("PluginUtils.getPluginResources is trying to access a parent path - denied : " + elementFullPath); return null; } File dir = new File(elementFullPath); if (!dir.exists() || !dir.isDirectory()) { return null; } return FileUtils.listFiles(dir, fileFilter, dirFilter); }
From source file:pt.webdetails.cpk.testUtils.PluginUtilsForTesting.java
/** * Calls out for resources in the plugin, on the specified path * * @param elementPath Relative to the plugin directory * @param recursive Do we want to enable recursivity? * @param pattern regular expression to filter the files * @return Files found// w w w . j ava 2s. c o m */ @Override public Collection<File> getPluginResources(String elementPath, Boolean recursive, String pattern) { IOFileFilter fileFilter = TrueFileFilter.TRUE; if (pattern != null && !pattern.equals("")) { fileFilter = new RegexFileFilter(pattern); } IOFileFilter dirFilter = recursive.equals(Boolean.TRUE) ? TrueFileFilter.TRUE : null; // Get directory name. We need to make sure we're not allowing this to fetch other resources String basePath = FilenameUtils.normalize(getPluginDirectory().getAbsolutePath()); String elementFullPath = FilenameUtils.normalize(basePath + File.separator + elementPath); if (!elementFullPath.startsWith(basePath)) { logger.warn("PluginUtils.getPluginResources is trying to access a parent path - denied : " + elementFullPath); return null; } File dir = new File(elementFullPath); if (!dir.exists() || !dir.isDirectory()) { return null; } return FileUtils.listFiles(dir, fileFilter, dirFilter); }