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

The following examples show how to use org.apache.commons.io.filefilter.DirectoryFileFilter. 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
Source File: TemplateParser.java    From camunda-bpm-platform with 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 #2
Source File: AddonFolderResourcePack.java    From Sandbox with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #3
Source File: JavaTypeHierarchyExtractor.java    From api-mining with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @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 #4
Source File: JavaBindingsToJson.java    From api-mining with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 #5
Source File: DistinctTokenCount.java    From api-mining with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @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 #6
Source File: JunkIssueEvaluator.java    From naturalize with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 #7
Source File: ChangingIdentifiersRepositoryWalker.java    From naturalize with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 #8
Source File: JavaTypeHierarchyExtractor.java    From tassal with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @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 #9
Source File: JavaBindingsToJson.java    From tassal with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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 #10
Source File: DistinctTokenCount.java    From tassal with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @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 #11
Source File: MavenRepositoryDeployer.java    From maven-repository-tools with Eclipse Public License 1.0 6 votes vote down vote up
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 #12
Source File: JavaTypeHierarchyExtractor.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @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 #13
Source File: JavaBindingsToJson.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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 #14
Source File: DistinctTokenCount.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @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 #15
Source File: ProjectTypeInformation.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 #16
Source File: MethodsInClass.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 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 #17
Source File: CbJinjaTester.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private Collection<File> collectAllSlsFiles(String salt) throws IOException {
    File file = new ClassPathResource(salt).getFile();
    return FileUtils.listFiles(
            file,
            new RegexFileFilter("^(.*.sls)"),
            DirectoryFileFilter.DIRECTORY
    );
}
 
Example #18
Source File: FilesetSplit.java    From tassal with BSD 3-Clause "New" or "Revised" License 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 #19
Source File: TokenCounter.java    From tassal with BSD 3-Clause "New" or "Revised" License 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 #20
Source File: ProjectTypeInformation.java    From tassal with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 #21
Source File: MethodsInClass.java    From tassal with BSD 3-Clause "New" or "Revised" License 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 #22
Source File: UsagePointExtractor.java    From tassal with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @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 File: FormattingEvaluation.java    From naturalize with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void main(final String[] args) {
	if (args.length < 1) {
		System.err.println("Usage <folderToEvaluate>");
		return;
	}

	final JavaWhitespaceTokenizer tokenizer = new JavaWhitespaceTokenizer();

	final Collection<File> allFiles = FileUtils.listFiles(
			new File(args[0]), tokenizer.getFileFilter(),
			DirectoryFileFilter.DIRECTORY);

	final FormattingEvaluation fe = new FormattingEvaluation(allFiles);
	fe.performEvaluation();
}
 
Example #24
Source File: SimpleFileScannerTest.java    From confucius-commons with 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 #25
Source File: FormattingReviewAssistant.java    From naturalize with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @param args
 * @throws IOException
 */
public static void main(final String[] args) throws IOException {
	if (args.length < 3) {
		System.err.println("Usage <trainDirectory> <suggestFile> cpp|java");
		System.exit(-1);
	}

	final File trainDir = new File(args[0]);
	final File testFile = new File(args[1]);
	final String language = args[2];
	final FormattingTokenizer tokenizer;
	if (language.equals("cpp")) {
		tokenizer = new FormattingTokenizer(new CASTAnnotatedTokenizer(
				new CppWhitespaceTokenizer()));
	} else if (language.equals("java")) {
		tokenizer = new FormattingTokenizer(new JavaWhitespaceTokenizer());
	} else {
		throw new IllegalArgumentException("Unrecognized option "
				+ language);
	}

	final Collection<File> trainFiles = FileUtils.listFiles(trainDir,
			tokenizer.getFileFilter(), DirectoryFileFilter.DIRECTORY);
	trainFiles.remove(testFile);
	final FormattingReviewAssistant reviewer = new FormattingReviewAssistant(
			tokenizer, trainFiles);

	reviewer.evaluateFile(testFile);
}
 
Example #26
Source File: SegmentRenamingSuggestion.java    From naturalize with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void main(final String[] args)
		throws IllegalArgumentException, SecurityException,
		InstantiationException, IllegalAccessException,
		InvocationTargetException, NoSuchMethodException,
		ClassNotFoundException, IOException {
	if (args.length < 4) {
		System.err
				.println("Usage <TestFile> <TrainDirectory> <renamerClass> variable|method");
		return;
	}

	final ITokenizer tokenizer = new JavaTokenizer();

	final AbstractIdentifierRenamings renamer = (AbstractIdentifierRenamings) Class
			.forName(args[2]).getDeclaredConstructor(ITokenizer.class)
			.newInstance(tokenizer);

	renamer.buildRenamingModel(FileUtils.listFiles(new File(args[1]),
			tokenizer.getFileFilter(), DirectoryFileFilter.DIRECTORY));

	final IScopeExtractor scopeExtractor = ScopesTUI
			.getScopeExtractorByName(args[3]);
	final SegmentRenamingSuggestion suggestion = new SegmentRenamingSuggestion(
			renamer, scopeExtractor, true);

	System.out.println(suggestion.rankSuggestions(new File(args[0])));

}
 
Example #27
Source File: TemplateParser.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param sourceDirectory the template directory that stores the endpoints
 * @return a map of endpoint path and HTTP methods pairs,
 * the map is ordered lexicographically by the endpoint paths
 * the list of methods is ordered as well
 */
protected static Map<String, List<String>> resolvePaths(String sourceDirectory) {
  File endpointsDir = new File(sourceDirectory + "/paths");
  int endpointStartAt = endpointsDir.getAbsolutePath().length();
  Collection<File> endpointsFiles = FileUtils.listFiles(
      endpointsDir, 
      new RegexFileFilter("^(.*?)"), 
      DirectoryFileFilter.DIRECTORY
      );

  Map<String, List<String>> endpoints = new TreeMap<>();
  for (File file : endpointsFiles) {
    String endpointMethod = FilenameUtils.removeExtension(file.getName());
    String filePath = file.getAbsolutePath();
    String endpointPath = filePath
        .substring(endpointStartAt, filePath.lastIndexOf(File.separator))
        .replace(File.separator, "/");

    List<String> operations;
    if (endpoints.containsKey(endpointPath)) {
      operations = endpoints.get(endpointPath);
      operations.add(endpointMethod);
    } else {
      operations = new ArrayList<>();
      operations.add(endpointMethod);
      endpoints.put(endpointPath, operations);
    }

    if(operations.size() > 1) {
      Collections.sort(operations);
    }
  }

  return endpoints;
}
 
Example #28
Source File: PerturbationEvaluator.java    From naturalize with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public PerturbationEvaluator(final File directory,
		final ITokenizer tokenizer, final IScopeExtractor scopeExtractor,
		final String renamerClass) {
	allFiles = FileUtils.listFiles(directory, tokenizer.getFileFilter(),
			DirectoryFileFilter.DIRECTORY);
	this.tokenizer = tokenizer;
	this.scopeExtractor = scopeExtractor;
	this.renamerClass = renamerClass;
	varRenamer = new ScopedIdentifierRenaming(scopeExtractor,
			ParseType.COMPILATION_UNIT);
}
 
Example #29
Source File: DynamicRangeEval.java    From naturalize with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 
 */
public DynamicRangeEval(final File directory, final ITokenizer tokenizer,
		final IScopeExtractor ex) {
	allFiles = FileUtils.listFiles(directory, tokenizer.getFileFilter(),
			DirectoryFileFilter.DIRECTORY);
	scopeExtractor = ex;
}
 
Example #30
Source File: Files.java    From chipster with MIT License 5 votes vote down vote up
/**
 * Walks the baseDir recursively and deletes files that match filter. When traversing directories, does not follow symbolic links.
 * 
 * @param baseDir
 * @param filter
 * @throws IOException 
 */
public static void walkAndDelete(File baseDir, IOFileFilter filter) throws IOException {
	File[] files = baseDir.listFiles((FileFilter)new OrFileFilter(DirectoryFileFilter.INSTANCE, filter));
	
	if (files == null) {
		return;
	}
	
	for (File f : files) {
		
		// Just try to delete it first
		// Will work for normal files, empty dirs and links (dir or file)
		// Avoid need for dealing with links later on
		if (f.delete()) {
			continue;
		} else if (f.isDirectory()) {
			
			// check the filter for directory before walking it as walking might affect the filter
			// conditions such as directory modified time
			boolean toBeDeleted = false;
			if (filter.accept(f)) {
				toBeDeleted = true;
			}

			// walk into dir
			walkAndDelete(f, filter);
			
			// possibly delete dir 
			if (toBeDeleted) {
				f.delete();
			}
		}
	}
}