Java Code Examples for org.apache.commons.io.filefilter.DirectoryFileFilter

The following examples show how to use org.apache.commons.io.filefilter.DirectoryFileFilter. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public Set<String> getNamespaces(ResourceType type) {
    Set<String> namespaces = Sets.newHashSet();
    File baseFile = new File(this.base, type.getDirectory());
    File[] files = baseFile.listFiles((FilenameFilter) DirectoryFileFilter.DIRECTORY);
    if (files != null) {
        for (File file : files) {
            String path = relativize(baseFile, file);
            if (path.equals(path.toLowerCase(Locale.ROOT))) {
                namespaces.add(path.substring(0, path.length() - 1));
            } else {
                this.warnNonLowercaseNamespace(path);
            }
        }
    }

    return namespaces;
}
 
Example 2
/**
 * @param args
 */
public static void main(final String[] args) {
	if (args.length != 1) {
		System.err.println("Usage <codeFolder>");
		System.exit(-1);
	}
	final File directory = new File(args[0]);

	final Collection<File> allFiles = FileUtils
			.listFiles(directory, JavaTokenizer.javaCodeFileFilter,
					DirectoryFileFilter.DIRECTORY);

	final JavaTypeHierarchyExtractor jthe = new JavaTypeHierarchyExtractor();
	jthe.addFilesToCorpus(allFiles);

	System.out.println(jthe);
}
 
Example 3
/**
 * Extract the bindings from the input folder to the output file, using the
 * bindingExtractor.
 *
 * @param inputFolder
 * @param outputFile
 * @param bindingExtractor
 * @throws IOException
 * @throws JsonIOException
 */
public static void extractBindings(final File inputFolder,
		final File outputFile,
		final AbstractJavaNameBindingsExtractor bindingExtractor)
		throws IOException, JsonIOException {
	final Collection<File> allFiles = FileUtils
			.listFiles(inputFolder, JavaTokenizer.javaCodeFileFilter,
					DirectoryFileFilter.DIRECTORY);
	final List<SerializableResolvedSourceCode> resolvedCode = allFiles
			.parallelStream()
			.map(f -> getResolvedCode(f, bindingExtractor))
			.filter(r -> r != null)
			.map(r -> SerializableResolvedSourceCode
					.fromResolvedSourceCode(r))
			.filter(s -> !s.boundVariables.isEmpty())
			.collect(Collectors.toList());

	final FileWriter writer = new FileWriter(outputFile);
	try {
		final Gson gson = new Gson();
		gson.toJson(resolvedCode, writer);
	} finally {
		writer.close();
	}
}
 
Example 4
/**
 * @param args
 * @throws ClassNotFoundException
 * @throws IllegalAccessException
 * @throws InstantiationException
 */
public static void main(final String[] args) throws InstantiationException,
		IllegalAccessException, ClassNotFoundException {

	if (args.length != 2) {
		System.err.println("Usage: <directory> <tokenizerClass>");
		return;
	}

	final DistinctTokenCount tokCount = new DistinctTokenCount(args[1]);
	for (final File fi : FileUtils.listFiles(new File(args[0]),
			new RegexFileFilter(".*\\.java$"),
			DirectoryFileFilter.DIRECTORY)) {
		try {
			tokCount.addTokens(fi);
		} catch (final IOException e) {
			LOGGER.warning(ExceptionUtils.getFullStackTrace(e));
		}
	}

	tokCount.printCounts();
}
 
Example 5
private double evaluateNumJunkVars() {
	final Collection<File> allFiles = FileUtils.listFiles(tmpDir,
			tokenizer.getFileFilter(), DirectoryFileFilter.DIRECTORY);

	final ParallelThreadPool ptp = new ParallelThreadPool();
	final JunkPercentage jp = new JunkPercentage();

	for (final File testFile : allFiles) {
		ptp.pushTask(new JunkRenamingRunnable(allFiles, testFile, jp));
	}

	ptp.waitForTermination();
	LOGGER.info("accJunk = " + ((double) jp.nJunkInTotal)
			/ jp.totalVariables);
	return ((double) jp.nJunkInTotal) / jp.totalVariables;
}
 
Example 6
private void doFirstScan(final File repositoryDir, final String sha) {
	for (final File f : FileUtils
			.listFiles(repositoryDir, JavaTokenizer.javaCodeFileFilter,
					DirectoryFileFilter.DIRECTORY)) {
		final String fileInRepo = f.getAbsolutePath().substring(
				(int) (repositoryDir.getAbsolutePath().length() + 1));
		Set<IdentifierInformation> identiferInfos;
		try {
			identiferInfos = infoScanner.scanFile(f, sha);
			identiferInfos
					.forEach(info -> {
						final IdentifierInformationThroughTime iitt = new IdentifierInformationThroughTime();
						iitt.addInformation(info);
						currentStateOfIdentifiers.put(fileInRepo, iitt);
					});
		} catch (final IOException e) {
			LOGGER.severe("Could not find file " + f + "\n"
					+ ExceptionUtils.getFullStackTrace(e));
		}

	}
}
 
Example 7
/**
 * @param args
 */
public static void main(final String[] args) {
	if (args.length != 1) {
		System.err.println("Usage <codeFolder>");
		System.exit(-1);
	}
	final File directory = new File(args[0]);

	final Collection<File> allFiles = FileUtils
			.listFiles(directory, JavaTokenizer.javaCodeFileFilter,
					DirectoryFileFilter.DIRECTORY);

	final JavaTypeHierarchyExtractor jthe = new JavaTypeHierarchyExtractor();
	jthe.addFilesToCorpus(allFiles);

	System.out.println(jthe);
}
 
Example 8
/**
 * Extract the bindings from the input folder to the output file, using the
 * bindingExtractor.
 *
 * @param inputFolder
 * @param outputFile
 * @param bindingExtractor
 * @throws IOException
 * @throws JsonIOException
 */
public static void extractBindings(final File inputFolder,
		final File outputFile,
		final AbstractJavaNameBindingsExtractor bindingExtractor)
		throws IOException, JsonIOException {
	final Collection<File> allFiles = FileUtils
			.listFiles(inputFolder, JavaTokenizer.javaCodeFileFilter,
					DirectoryFileFilter.DIRECTORY);
	final List<SerializableResolvedSourceCode> resolvedCode = allFiles
			.parallelStream()
			.map(f -> getResolvedCode(f, bindingExtractor))
			.filter(r -> r != null)
			.map(r -> SerializableResolvedSourceCode
					.fromResolvedSourceCode(r))
			.filter(s -> !s.boundVariables.isEmpty())
			.collect(Collectors.toList());

	final FileWriter writer = new FileWriter(outputFile);
	try {
		final Gson gson = new Gson();
		gson.toJson(resolvedCode, writer);
	} finally {
		writer.close();
	}
}
 
Example 9
/**
 * @param args
 * @throws ClassNotFoundException
 * @throws IllegalAccessException
 * @throws InstantiationException
 */
public static void main(final String[] args) throws InstantiationException,
		IllegalAccessException, ClassNotFoundException {

	if (args.length != 2) {
		System.err.println("Usage: <directory> <tokenizerClass>");
		return;
	}

	final DistinctTokenCount tokCount = new DistinctTokenCount(args[1]);
	for (final File fi : FileUtils.listFiles(new File(args[0]),
			new RegexFileFilter(".*\\.java$"),
			DirectoryFileFilter.DIRECTORY)) {
		try {
			tokCount.addTokens(fi);
		} catch (final IOException e) {
			LOGGER.warning(ExceptionUtils.getFullStackTrace(e));
		}
	}

	tokCount.printCounts();
}
 
Example 10
public static Collection<File> getLeafDirectories( File repoPath ) 
{
    // Using commons-io, if performance or so is a problem it might be worth looking at the Java 8 streams API
    // e.g. http://blog.jooq.org/2014/01/24/java-8-friday-goodies-the-new-new-io-apis/
    // not yet though..
   Collection<File> subDirectories =
        FileUtils.listFilesAndDirs( repoPath, DirectoryFileFilter.DIRECTORY,
            VisibleDirectoryFileFilter.DIRECTORY );
    Collection<File> leafDirectories = new ArrayList<File>();
    for ( File subDirectory : subDirectories )
    {
        if ( isLeafVersionDirectory( subDirectory ) && subDirectory != repoPath )
        {
            leafDirectories.add( subDirectory );
        }
    }
    return leafDirectories;
}
 
Example 11
/**
 * @param args
 */
public static void main(final String[] args) {
	if (args.length != 1) {
		System.err.println("Usage <codeFolder>");
		System.exit(-1);
	}
	final File directory = new File(args[0]);

	final Collection<File> allFiles = FileUtils
			.listFiles(directory, JavaTokenizer.javaCodeFileFilter,
					DirectoryFileFilter.DIRECTORY);

	final JavaTypeHierarchyExtractor jthe = new JavaTypeHierarchyExtractor();
	jthe.addFilesToCorpus(allFiles);

	System.out.println(jthe);
}
 
Example 12
/**
 * Extract the bindings from the input folder to the output file, using the
 * bindingExtractor.
 *
 * @param inputFolder
 * @param outputFile
 * @param bindingExtractor
 * @throws IOException
 * @throws JsonIOException
 */
public static void extractBindings(final File inputFolder,
		final File outputFile,
		final AbstractJavaNameBindingsExtractor bindingExtractor)
		throws IOException, JsonIOException {
	final Collection<File> allFiles = FileUtils
			.listFiles(inputFolder, JavaTokenizer.javaCodeFileFilter,
					DirectoryFileFilter.DIRECTORY);
	final List<SerializableResolvedSourceCode> resolvedCode = allFiles
			.parallelStream()
			.map(f -> getResolvedCode(f, bindingExtractor))
			.filter(r -> r != null)
			.map(r -> SerializableResolvedSourceCode
					.fromResolvedSourceCode(r))
			.filter(s -> !s.boundVariables.isEmpty())
			.collect(Collectors.toList());

	final FileWriter writer = new FileWriter(outputFile);
	try {
		final Gson gson = new Gson();
		gson.toJson(resolvedCode, writer);
	} finally {
		writer.close();
	}
}
 
Example 13
/**
 * @param args
 * @throws ClassNotFoundException
 * @throws IllegalAccessException
 * @throws InstantiationException
 */
public static void main(final String[] args) throws InstantiationException,
		IllegalAccessException, ClassNotFoundException {

	if (args.length != 2) {
		System.err.println("Usage: <directory> <tokenizerClass>");
		return;
	}

	final DistinctTokenCount tokCount = new DistinctTokenCount(args[1]);
	for (final File fi : FileUtils.listFiles(new File(args[0]),
			new RegexFileFilter(".*\\.java$"),
			DirectoryFileFilter.DIRECTORY)) {
		try {
			tokCount.addTokens(fi);
		} catch (final IOException e) {
			LOGGER.warning(ExceptionUtils.getFullStackTrace(e));
		}
	}

	tokCount.printCounts();
}
 
Example 14
Source Project: camunda-bpm-platform   Source File: TemplateParser.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param sourceDirectory the template directory that stores the models
 * @return a map of model name and file path to it,
 * the map is ordered lexicographically by the model names
 */
protected static Map<String, String> resolveModels(String sourceDirectory) {
  File modelsDir = new File(sourceDirectory + "/models");
  Collection<File> modelFiles = FileUtils.listFiles(
      modelsDir, 
      new RegexFileFilter("^(.*?)"), 
      DirectoryFileFilter.DIRECTORY
      );

  Map<String, String> models = new TreeMap<>();
  for (File file : modelFiles) {
    String modelName = FilenameUtils.removeExtension(file.getName());
    String filePath = file.getAbsolutePath();
    String modelPackage = filePath
        .substring(filePath.lastIndexOf("org"), filePath.lastIndexOf(File.separator));
    
    models.put(modelName, modelPackage);
  }
  
  return models;
}
 
Example 15
Source Project: jkube   Source File: FileUtil.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public static List<File> listFilesAndDirsRecursivelyInDirectory(File directory) {
    return FileUtils.listFilesAndDirs(directory, new RegexFileFilter("^(.*?)"),
        DirectoryFileFilter.DIRECTORY
    )
        .stream()
        .filter(f -> !f.equals(directory))
        .collect(Collectors.toList());
}
 
Example 16
/**
 * Get the domain resource
 *
 * @return a string such as "assets/addonid/textures/texture.png"
 */
public Set<String> getResourceDomains() {
    Set<String> set = Sets.newHashSet();
    File file1 = new File(resourcePackFile, "assets/");

    if (file1.isDirectory()) {
        Arrays.stream(file1.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY)).map(file2 -> getRelativeName(file1, file2)).forEach(s -> {
            if (!s.equals(s.toLowerCase())) logNameNotLowercase(s);
            else set.add(s.substring(0, s.length() - 1));
        });
    }

    return set;
}
 
Example 17
public List<String> getFolders(final ResourceType type,
		final String currentFolder) throws InvalidCurrentFolderException {
	String absolutePath = getRealUserFilesAbsolutePath(RequestCycleHandler
			.getUserFilesAbsolutePath(ThreadLocalData.getRequest()));
	File typeDir = getOrCreateResourceTypeDir(absolutePath, type);
	File currentDir = new File(typeDir, currentFolder);
	if (!currentDir.exists() || !currentDir.isDirectory())
		throw new InvalidCurrentFolderException();

	String[] fileList = currentDir.list(DirectoryFileFilter.DIRECTORY);
	return Arrays.asList(fileList);
}
 
Example 18
Source Project: xds-ide   Source File: ResourceUtils.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/** Driver function for the {@link #listDirectories(File)}
 * @param dir
 * @param dirs
 * @see #listDirectories(File)
 */
private static void listDirectoriesInternal(File dir, Collection<File> dirs) {
	dirs.add(dir);
	String[] subDirNames = dir.list(DirectoryFileFilter.INSTANCE);
	for (String subDirName : subDirNames) {
		File subDir = new File(dir.getAbsolutePath() + IOUtils.DIR_SEPARATOR +  subDirName);
		listDirectoriesInternal(subDir, dirs);
	}
}
 
Example 19
Source Project: confucius-commons   Source File: SimpleFileScannerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testScan() {
    File jarHome = new File(SystemUtils.JAVA_HOME);
    Set<File> directories = simpleFileScanner.scan(jarHome, true, DirectoryFileFilter.INSTANCE);
    Assert.assertFalse(directories.isEmpty());

    directories = simpleFileScanner.scan(jarHome, false, new NameFileFilter("bin"));
    Assert.assertEquals(1, directories.size());
}
 
Example 20
Source Project: multi-module-maven-release-plugin   Source File: MvnRunner.java    License: MIT License 5 votes vote down vote up
public static MvnRunner mvn(String version) {
    System.out.println("Ensuring maven " + version + " is available");
    MvnRunner mvnRunner = new MvnRunner();
    String dirWithMavens = "target/mavens/" + version;
    mvnRunner.runMaven(new File("."), "-Dartifact=org.apache.maven:apache-maven:" + version + ":zip:bin",
        "-DmarkersDirectory=" + dirWithMavens,
        "-DoutputDirectory=" + dirWithMavens,
        "org.apache.maven.plugins:maven-dependency-plugin:2.10:unpack");
    File mvnHome = new File(dirWithMavens).listFiles((FileFilter) DirectoryFileFilter.INSTANCE)[0];
    System.out.println("Maven " + version + " available at " + mvnHome.getAbsolutePath());
    return new MvnRunner(mvnHome);
}
 
Example 21
Source Project: tankbattle   Source File: MapUtils.java    License: MIT License 5 votes vote down vote up
public static List<String> getCustomFileList() {
    Collection<File> listFiles = FileUtils.listFiles(new File(System.getProperty("user.home") + File.separator +
            ".tankBattle" + File.separator + "custom"), FileFilterUtils.suffixFileFilter("xml"), DirectoryFileFilter
            .INSTANCE);
    List<String> list = new ArrayList<>();
    for (File file : listFiles) {
        list.add(file.getName().substring(0, file.getName().lastIndexOf(".")));
        System.out.println(file.getName());
    }
    return list;
}
 
Example 22
/**
 * @param args
 */
public static void main(final String[] args) {
	if (args.length != 2) {
		System.err.println("Usage <fullyQualifiedClass> <directory>");
		System.exit(-1);
	}

	final File directory = new File(args[1]);
	final String qualifiedClass = args[0];

	for (final File fi : FileUtils
			.listFiles(directory, JavaTokenizer.javaCodeFileFilter,
					DirectoryFileFilter.DIRECTORY)) {
		try {
			final List<ASTNode> usages = usagePoints(qualifiedClass, fi);
			if (!usages.isEmpty()) {
				System.out.println(fi.getAbsolutePath());
				for (final ASTNode node : usages) {
					System.out
							.println("----------------------------------------------");
					System.out.println(node);
				}
			}
		} catch (final Exception e) {
			System.err.println("Error processing " + fi.getName());
		}

	}

}
 
Example 23
Source Project: api-mining   Source File: MethodsInClass.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void main(final String[] args) {
	if (args.length != 1) {
		System.err.println("Usage <projectDir>");
		System.exit(-1);
	}

	final MethodsInClass mic = new MethodsInClass();
	mic.scan(FileUtils
			.listFiles(new File(args[0]), JavaTokenizer.javaCodeFileFilter,
					DirectoryFileFilter.DIRECTORY));
	System.out.println(mic);
}
 
Example 24
public void collect() {
	final Collection<File> allFiles = FileUtils
			.listFiles(projectDirectory, JavaTokenizer.javaCodeFileFilter,
					DirectoryFileFilter.DIRECTORY);
	methodInformation.scan(allFiles);
	final JavaTypeHierarchyExtractor hierarchyExtractor = new JavaTypeHierarchyExtractor();
	hierarchyExtractor.addFilesToCorpus(allFiles);
	hierarchy = hierarchyExtractor.getHierarchy();
}
 
Example 25
Source Project: api-mining   Source File: TokenCounter.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param args
 * @throws IOException
 * @throws ClassNotFoundException
 * @throws IllegalAccessException
 * @throws InstantiationException
 */
public static void main(final String[] args) throws IOException,
		InstantiationException, IllegalAccessException,
		ClassNotFoundException {
	if (args.length != 2) {
		System.err.println("Usage <codeDir> <TokenizerClass>");
		return;
	}

	long tokenCount = 0;

	final ITokenizer tokenizer = TokenizerUtils.tokenizerForClass(args[1]);

	for (final File fi : FileUtils.listFiles(new File(args[0]),
			tokenizer.getFileFilter(), DirectoryFileFilter.DIRECTORY)) {
		try {
			final char[] code = FileUtils.readFileToString(fi)
					.toCharArray();
			tokenCount += tokenizer.tokenListFromCode(code).size() - 2; // Remove
																		// sentence
																		// start/end
		} catch (final IOException e) {
			LOGGER.warning(ExceptionUtils.getFullStackTrace(e));
		}
	}

	System.out.println("Tokens: " + tokenCount);
}
 
Example 26
Source Project: api-mining   Source File: FilesetSplit.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 
 * @param fromDirectory
 * @param toDirectory
 * @param isIncluded
 * @param segments
 *            the partition percentages to be used in the split, along with
 *            the name of the folders to be created.
 * @param weightingFunction
 *            the function that returns the weight of each file in the split
 */
public static void splitFiles(final File fromDirectory,
		final File toDirectory, final Map<String, Double> segments,
		final IOFileFilter isIncluded,
		final Function<File, Double> weightingFunction) {
	final Collection<File> fromFiles = FileUtils.listFiles(fromDirectory,
			isIncluded, DirectoryFileFilter.DIRECTORY);

	final Map<File, Double> fileWeights = Maps.newHashMap();
	for (final File f : fromFiles) {
		fileWeights.put(f, weightingFunction.apply(f));
	}

	final Multimap<String, File> fileSplit = SampleUtils.randomPartition(
			fileWeights, segments);
	// Start copying
	final String pathSeparator = System.getProperty("file.separator");
	for (final Entry<String, File> file : fileSplit.entries()) {
		final File targetFilename = new File(toDirectory.getAbsolutePath()
				+ pathSeparator + file.getKey() + pathSeparator
				+ file.getValue().getName());
		try {
			FileUtils.copyFile(file.getValue(), targetFilename);
		} catch (final IOException e) {
			LOGGER.severe("Failed to copy " + file.getValue() + " to "
					+ targetFilename);
		}
	}

}
 
Example 27
Source Project: product-iots   Source File: CarbonServerManagerExtension.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * To check jacoco file sizes and wait for them to get created..
 *
 * @param filePath File Path of the jacoco data files.
 */
private void checkJacocoDataFileSizes(String filePath) {
    Collection<File> fileSetsCollection = FileUtils
            .listFiles(new File(filePath), new RegexFileFilter("[^s]+(." + "(?i)(exec))$"),
                    DirectoryFileFilter.DIRECTORY);

    for (File inputFile : fileSetsCollection) {
        if (inputFile.isDirectory()) {
            continue;
        }
        //retry to check whether exec data file is non empty.
        waitForCoverageDumpFileCreation(inputFile);
    }
}
 
Example 28
public static void main(final String args[]) throws SerializationException {
	if (args.length != 2) {
		System.err.println("Usage <folderWithTypes> <SerialzedTypePrior>");
		return;
	}

	final Collection<File> trainingFiles = FileUtils.listFiles(new File(
			args[0]), new RegexFileFilter(".*\\.java$"),
			DirectoryFileFilter.DIRECTORY);

	final JavaVariableNameTypeDistribution tp = JavaVariableNameTypeDistribution
			.buildFromFiles(trainingFiles);
	Serializer.getSerializer().serialize(tp, args[1]);
}
 
Example 29
/**
 * 
 */
public UnkRenamingsEval(final File directory,
		final IScopeExtractor extractor) {
	allFiles = FileUtils.listFiles(directory,
			(new JavaTokenizer()).getFileFilter(),
			DirectoryFileFilter.DIRECTORY);
	scopeExtractor = extractor;
}
 
Example 30
/**
 * 
 */
public HumanEvaluationOutput(final File directory,
		final IScopeExtractor extractor, final String renamerClass,
		final String renamerConstructorParam, final ITokenizer tokenizer,
		final long nExamples) {
	allFiles = Lists.newArrayList(FileUtils.listFiles(directory,
			tokenizer.getFileFilter(), DirectoryFileFilter.DIRECTORY));
	Collections.shuffle(allFiles);
	this.tokenizer = tokenizer;
	this.nExamples = nExamples;
	this.renamerClass = renamerClass;
	this.renamerConstructorParam = renamerConstructorParam;
	scopeExtractor = extractor;
}