List of usage examples for org.apache.commons.io FileUtils listFiles
public static Collection listFiles(File directory, String[] extensions, boolean recursive)
From source file:com.btoddb.fastpersitentqueue.InMemorySegmentMgr.java
private void loadPagedSegments() throws IOException { // read files and sort by their UUID name so they are in proper chronological order Collection<File> files = FileUtils.listFiles(pagingDirectory, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);//from w w w. j ava2 s. c o m TreeSet<File> sortedFiles = new TreeSet<File>(new Comparator<File>() { @Override public int compare(File o1, File o2) { return new UUID(o1.getName()).compareTo(new UUID(o2.getName())); } }); sortedFiles.addAll(files); // cleanup memory files.clear(); assert 0 == numberOfActiveSegments.get(); assert segments.isEmpty(); segments.clear(); for (File f : sortedFiles) { MemorySegment segment; // only load the segment's data if room in memory, otherwise just load its header if (numberOfActiveSegments.get() < maxNumberOfActiveSegments - 1) { segment = segmentSerializer.loadFromDisk(f.getName()); segment.setStatus(MemorySegment.Status.READY); segment.setPushingFinished(true); assert segment.getNumberOfOnlineEntries() > 0; assert !segment.getQueue().isEmpty(); numberOfActiveSegments.incrementAndGet(); } else { segment = segmentSerializer.loadHeaderOnly(f.getName()); segment.setStatus(MemorySegment.Status.OFFLINE); segment.setPushingFinished(true); } assert segment.isPushingFinished(); assert segment.getNumberOfEntries() > 0; assert segment.getEntryListOffsetOnDisk() > 0; segments.add(segment); numberOfEntries.addAndGet(segment.getNumberOfEntries()); } // for (MemorySegment seg : segments) { // if (seg.getStatus() == MemorySegment.Status.READY) { // segmentSerializer.removePagingFile(seg); // } // } }
From source file:com.data2semantics.yasgui.server.db.ConnectionFactory.java
private static void applyDeltas(Connection connect, File configDir) throws UnsupportedEncodingException, IOException, SQLException { @SuppressWarnings("unchecked") ArrayList<File> listFiles = new ArrayList<File>( FileUtils.listFiles(new File(configDir.getAbsolutePath() + "/config"), FileFilterUtils.prefixFileFilter("delta_"), null)); TreeMap<Integer, File> files = new TreeMap<Integer, File>(); for (File file : listFiles) { String basename = file.getName(); basename = basename.substring("delta_".length()); basename = basename.substring(0, basename.length() - ".sql".length()); int index = Integer.parseInt(basename); files.put(index, file);//from w w w.ja v a 2s .co m } ArrayList<Integer> currentDeltas = getDeltas(connect); //treemap is naturally sorted, so just iterate through them for (Entry<Integer, File> entry : files.entrySet()) { if (!currentDeltas.contains(entry.getKey())) { ScriptRunner runner = new ScriptRunner(connect, false, true); FileInputStream fileStream = new FileInputStream(entry.getValue()); runner.runScript(new BufferedReader(new InputStreamReader(fileStream, "UTF-8"))); fileStream.close(); setDeltaApplied(connect, entry.getKey()); } } }
From source file:ar.com.fluxit.jqa.JQAMavenPlugin.java
private void doExecute(File buildDirectory, File outputDirectory, File testOutputDirectory, MavenProject project, File sourceDir, String sourceJavaVersion) throws IntrospectionException, TypeFormatException, FileNotFoundException, IOException, RulesContextFactoryException, ExporterException { // Add project dependencies to classpath getLog().debug("Adding project dependencies to classpath"); final Collection<File> classPath = new ArrayList<File>(); @SuppressWarnings("unchecked") final Set<Artifact> artifacts = project.getArtifacts(); for (final Artifact artifact : artifacts) { classPath.add(artifact.getFile()); }/*from w w w . j av a 2 s. c o m*/ // Add project classes to classpath if (outputDirectory != null) { classPath.add(outputDirectory); } if (testOutputDirectory != null) { classPath.add(testOutputDirectory); } getLog().debug("Adding project classes to classpath"); final Collection<File> classFiles = FileUtils.listFiles(buildDirectory, new SuffixFileFilter(RulesContextChecker.CLASS_SUFFIX), TrueFileFilter.INSTANCE); // Reads the config file getLog().debug("Reading rules context"); final RulesContext rulesContext = RulesContextFactoryLocator.getRulesContextFactory() .getRulesContext(getRulesContextFile().getPath()); getLog().debug("Checking rules for " + classFiles.size() + " files"); final CheckingResult checkingResult = RulesContextChecker.INSTANCE.check(project.getArtifactId(), classFiles, classPath, rulesContext, new File[] { sourceDir }, sourceJavaVersion, getLogger()); CheckingResultExporter.INSTANCE.export(checkingResult, project.getArtifactId(), getResultsDirectory(), this.xslt, getLogger()); }
From source file:com.norconex.commons.lang.ClassFinder.java
private static List<String> findSubTypesFromDirectory(File dir, Class<?> superClass) { List<String> classes = new ArrayList<String>(); String dirPath = dir.getAbsolutePath(); Collection<File> classFiles = FileUtils.listFiles(dir, new String[] { "class" }, true); ClassLoader loader = getClassLoader(dir); if (loader == null) { return classes; }/*w w w.j ava2s . c o m*/ for (File classFile : classFiles) { String filePath = classFile.getAbsolutePath(); String className = StringUtils.removeStart(filePath, dirPath); className = resolveName(loader, className, superClass); if (className != null) { classes.add(className); } } return classes; }
From source file:maltcms.ui.nb.pipelineRunner.actions.RunMaltcmsPipelinesAction.java
private Action[] buildActions(Lookup lookup) { final IChromAUIProject project = LookupUtils.ensureSingle(lookup, IChromAUIProject.class); Collection<Action> topLevelActions = new ArrayList<>(); File projectPipelinesPath = new File(FileUtil.toFile(project.getLocation()), "pipelines"); File[] maltcmsVersions = projectPipelinesPath.listFiles(new FileFilter() { @Override//www . jav a 2 s.co m public boolean accept(File f) { return f.isDirectory(); } }); if (maltcmsVersions == null) { return new Action[0]; } Logger.getLogger(RunMaltcmsPipelinesAction.class.getName()).log(Level.FINE, "Found maltcms versions: {0}", Arrays.deepToString(maltcmsVersions)); for (File maltcmsVersion : maltcmsVersions) { Logger.getLogger(RunMaltcmsPipelinesAction.class.getName()).log(Level.FINE, "Checking pipelines below {0}", maltcmsVersion); List<File> c = new ArrayList<>(FileUtils.listFiles(maltcmsVersion, new String[] { "mpl" }, true)); Collections.sort(c, new Comparator<File>() { @Override public int compare(File o1, File o2) { return o1.getName().compareTo(o2.getName()); } }); Logger.getLogger(RunMaltcmsPipelinesAction.class.getName()).log(Level.FINE, "Found {0} pipeline definitions!", c.size()); Collection<Action> actions = new ArrayList<>(); for (File pipelineFile : c) { FileObject fo = FileUtil.toFileObject(pipelineFile); Logger.getLogger(RunMaltcmsPipelinesAction.class.getName()).log(Level.FINE, "Adding pipeline {0}", pipelineFile.getName()); DataObject dobj; try { dobj = DataObject.find(fo); if (dobj instanceof MaltcmsPipelineFormatDataObject) { final MaltcmsPipelineFormatDataObject mpfdo = (MaltcmsPipelineFormatDataObject) dobj; AbstractAction pipelineRunAction = new AbstractAction(fo.getName()) { @Override public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { Logger.getLogger(RunMaltcmsPipelinesAction.class.getName()).log(Level.FINE, "Creating PipelineRunOpenSupport"); PipelineRunOpenSupport pos = new PipelineRunOpenSupport( mpfdo.getPrimaryEntry()); Logger.getLogger(RunMaltcmsPipelinesAction.class.getName()).log(Level.FINE, "Calling pos.open()!"); pos.open(); Logger.getLogger(RunMaltcmsPipelinesAction.class.getName()).log(Level.FINE, "Done!"); } }); } }; Logger.getLogger(RunMaltcmsPipelinesAction.class.getName()).log(Level.FINE, "Adding dataobject action"); actions.add(pipelineRunAction); // subMenu.add(new JMenuItem(pipelineRunAction)); } } catch (DataObjectNotFoundException ex) { Exceptions.printStackTrace(ex); } } Logger.getLogger(RunMaltcmsPipelinesAction.class.getName()).log(Level.FINE, "Adding {0} Pipeline specific actions!", actions.size()); topLevelActions.add(Lookup.getDefault().lookup(INodeFactory.class) .createMenuItem(maltcmsVersion.getName(), actions.toArray(new Action[actions.size()]))); } return topLevelActions.toArray(new Action[topLevelActions.size()]); }
From source file:com.googlecode.dex2jar.test.TestUtils.java
public static Collection<File> listTestDexFiles(boolean withOdex) { File file = new File("target/test-classes/dexes"); List<File> list = new ArrayList<File>(); if (file.exists()) { list.addAll(FileUtils.listFiles(file, new String[] { "dex", "zip", "apk", "odex" }, false)); }// w ww . j av a 2 s .c om if (withOdex) { list = new ArrayList<File>(); file = new File("target/test-classes/odexes"); if (file.exists()) { list.addAll(FileUtils.listFiles(file, new String[] { "odex" }, true)); } } return list; }
From source file:de.teamgrit.grit.checking.compile.JavaCompileChecker.java
/** * Invokes the compiler on a given file and reports the output. * * @param pathToSourceFolder/*from www . j a v a 2 s .co m*/ * Specifies the folder where source files are located. * @param outputFolder * Directory where the resulting binaries are placed * @param compilerName * The compiler to be used (usually javac). * @param compilerFlags * Additional flags to be passed to the compiler. * @throws FileNotFoundException * Is thrown when the file in pathToProgramFile cannot be * opened * @throws BadCompilerSpecifiedException * Is thrown when the given compiler cannot be called * @return A {@link CompilerOutput} that contains all compiler messages and * flags on how the compile run went. * @throws BadFlagException * When javac doesn't recognize a flag, this exception is * thrown. * @throws CompilerOutputFolderExistsException * The output folder may not exist. This is thrown when it does * exist. */ @Override public CompilerOutput checkProgram(Path pathToSourceFolder, Path outputFolder, String compilerName, List<String> compilerFlags) throws FileNotFoundException, BadCompilerSpecifiedException, BadFlagException, CompilerOutputFolderExistsException { // First we build the command to invoke the compiler. This consists of // the compiler executable, the path of the // file to compile and compiler flags. List<String> compilerInvocation = createCompilerInvocation(pathToSourceFolder, outputFolder, compilerName, compilerFlags); // Now we build a launchable process from the given parameters and set // the working directory. CompilerOutput result = runJavacProcess(compilerInvocation, pathToSourceFolder, false); compilerInvocation.clear(); compilerInvocation.add("javac"); compilerInvocation.add("-cp"); // Add testDependencies to classpath String cp = ".:" + m_junitLocation + ":" + outputFolder.toAbsolutePath(); // Add all additional .jar files contained in javalib directory to the classpath if (!m_libLocation.toFile().exists()) { m_libLocation.toFile().mkdir(); } else { for (File f : FileUtils.listFiles(m_libLocation.toFile(), new String[] { "jar" }, false)) { cp = cp + ":" + f.getAbsolutePath(); } } compilerInvocation.add(cp); //make sure java uses utf8 for encoding compilerInvocation.add("-encoding"); compilerInvocation.add("UTF-8"); compilerInvocation.add("-d"); compilerInvocation.add(m_junitTestFilesLocation.toAbsolutePath().toString()); List<Path> foundUnitTests = exploreDirectory(m_junitTestFilesLocation); for (Path path : foundUnitTests) { compilerInvocation.add(path.toAbsolutePath().toString()); } runJavacProcess(compilerInvocation, m_junitTestFilesLocation, true); return result; }
From source file:com.btoddb.fastpersitentqueue.InMemorySegmentMgrTest.java
@Test public void testPop() throws Exception { mgr.init();//w ww. j a v a 2s . co m for (int i = 0; i < numEntries; i++) { mgr.push(new FpqEntry(idGen.incrementAndGet(), String.format( "%02d-3456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", i).getBytes())); } long end = System.currentTimeMillis() + 1000; while (System.currentTimeMillis() < end && mgr.getNumberOfActiveSegments() > 4) { Thread.sleep(100); } for (int i = 0; i < numEntries; i++) { FpqEntry entry; while (null == (entry = mgr.pop())) { Thread.sleep(100); } System.out.println(new String(entry.getData())); } // this triggers the last segment to be removed and gives it a chance to happen mgr.pop(1); Thread.sleep(500); assertThat(mgr.getNumberOfEntries(), is(0L)); assertThat(mgr.getSegments(), hasSize(1)); MemorySegment seg = mgr.getSegments().iterator().next(); assertThat(seg.getStatus(), is(MemorySegment.Status.READY)); assertThat(seg.getNumberOfOnlineEntries(), is(0L)); assertThat(seg.getNumberOfEntries(), is(0L)); assertThat(seg.getQueue().keySet(), is(empty())); assertThat(FileUtils.listFiles(theDir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE), is(empty())); }
From source file:com.ppedregal.typescript.maven.TscMojo.java
private void doCompileFiles(boolean checkTimestamp) throws MojoExecutionException { Collection<File> files = FileUtils.listFiles(sourceDirectory, new String[] { "ts" }, true); doCompileFiles(checkTimestamp, files); }