org.eclipse.xtext.mwe.PathTraverser Java Examples

The following examples show how to use org.eclipse.xtext.mwe.PathTraverser. 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: StandaloneBuilder.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected List<URI> collectResources(Iterable<String> roots, ResourceSet resourceSet) {
	String extensions = Joiner.on("|").join(languages.keySet());
	NameBasedFilter nameBasedFilter = new NameBasedFilter();
	// TODO test with whitespaced file extensions
	nameBasedFilter.setRegularExpression(".*\\.(?:(" + extensions + "))$");
	List<URI> resources = new ArrayList<>();
	Multimap<String, URI> modelsFound = new PathTraverser().resolvePathes(IterableExtensions.toList(roots),
			(URI input) -> {
				boolean matches = nameBasedFilter.matches(input);
				if (matches) {
					forceDebugLog("Adding file \'" + input + "\'");
					resources.add(input);
				}
				return matches;
			});
	modelsFound.asMap().forEach((String uri, Collection<URI> resource) -> {
		File file = new File(uri);
		if (resource != null && !file.isDirectory() && file.getName().endsWith(".jar")) {
			registerBundle(file);
		}
	});
	return resources;
}
 
Example #2
Source File: ResourceURICollector.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected Set<URI> collectResources(Iterable<URI> roots, Set<String> fileExtensions) {
	Set<String> extensions = new HashSet<>(fileExtensions);
	extensions.add("java");

	List<String> paths = stream(roots.spliterator(), false).map(URI::toFileString).collect(toList());
	Multimap<String, URI> modelsFound = new PathTraverser().resolvePathes(paths, uri -> extensions.contains(uri.fileExtension()));
	
	modelsFound.asMap().forEach( (path, resource) -> {
		File file = new File(path);
		if (resource != null && !file.isDirectory() && file.getName().endsWith(".jar")) {
			registerBundle(file);
		}
	});

	return IterableExtensions.toSet(modelsFound.values());
}
 
Example #3
Source File: XtendBatchCompiler.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected ResourceSet loadXtendFiles(final ResourceSet resourceSet) {
	encodingProvider.setDefaultEncoding(getFileEncoding());
	final NameBasedFilter nameBasedFilter = new NameBasedFilter();
	nameBasedFilter.setExtension(fileExtensionProvider.getPrimaryFileExtension());
	PathTraverser pathTraverser = new PathTraverser();
	List<String> sourcePathDirectories = getSourcePathDirectories();
	Multimap<String, URI> pathes = pathTraverser.resolvePathes(sourcePathDirectories, new Predicate<URI>() {
		@Override
		public boolean apply(URI input) {
			boolean matches = nameBasedFilter.matches(input);
			return matches;
		}
	});
	for (String src : pathes.keySet()) {
		for (URI uri : pathes.get(src)) {
			if (log.isDebugEnabled()) {
				log.debug("load xtend file '" + uri + "'");
			}
			resourceSet.getResource(uri, true);
		}
	}
	return resourceSet;
}
 
Example #4
Source File: AbstractSarldocCommand.java    From sarl with Apache License 2.0 6 votes vote down vote up
private static Collection<String> getSourceFiles(SystemPath sourcePaths, SarldocConfig config) {
	final Set<String> allFiles = new TreeSet<>();
	final PathTraverser pathTraverser = new PathTraverser();
	final Multimap<String, org.eclipse.emf.common.util.URI> pathes = pathTraverser.resolvePathes(
		sourcePaths.toFilenameList(),
		input -> Objects.equals(JAVA_FILE_EXTENSION, input.fileExtension()));
	for (final Entry<String, org.eclipse.emf.common.util.URI> entry : pathes.entries()) {
		final String filename = entry.getValue().toFileString();
		final File file = FileSystem.convertStringToFile(filename);
		final File root = FileSystem.convertStringToFile(entry.getKey());
		try {
			if (!isExcludedPackage(FileSystem.makeRelative(file, root), config)) {
				allFiles.add(filename);
			}
		} catch (Throwable exception) {
			// Silent exception
		}
	}
	return allFiles;
}
 
Example #5
Source File: EclipseJavaCompiler.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
private boolean containsJavaFiles(Iterable<String> roots) {
	final String javaExt = "java";
	Multimap<String, URI> uris = new PathTraverser().resolvePathes(Lists.newArrayList(roots), new Predicate<URI>() {
		@Override
		public boolean apply(URI input) {
			return javaExt.equals(input.fileExtension());
		}
	});
	return uris.values().size() > 0;
}
 
Example #6
Source File: XcoreReader.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
private PathTraverser getPathTraverser() {
	return new PathTraverser();
}
 
Example #7
Source File: TestEclipseCompiler.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
private Collection<URI> collectOutputFiles() {
	return new PathTraverser().resolvePathes(Lists.newArrayList(outputClassDirectory.getAbsolutePath()),
			new ClassFileFilter()).values();
}
 
Example #8
Source File: TestEclipseCompiler.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
private Collection<URI> collectOutputFiles() {
	return new PathTraverser().resolvePathes(Lists.newArrayList(outputClassDirectory.getAbsolutePath()),
			new ClassFileFilter()).values();
}