use of org.eclipse.core.resources.IResourceVisitor in project xtext-xtend by eclipse.
the class WorkspaceScenariosTest method testJarWithoutJava.
@Test
public void testJarWithoutJava() {
try {
final Function1<String, Boolean> _function = (String it) -> {
return Boolean.valueOf((it.endsWith("java") || it.endsWith("class")));
};
final IProject project = this.createProjectWithJarDependency(_function);
try {
final ArrayList<IMarker> allXtendMarkers = CollectionLiterals.<IMarker>newArrayList();
final IResourceVisitor _function_1 = (IResource it) -> {
if ((it instanceof IFile)) {
boolean _endsWith = ((IFile) it).getFullPath().lastSegment().endsWith(".xtend");
if (_endsWith) {
final IMarker[] markers = ((IFile) it).findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
for (final IMarker m : markers) {
allXtendMarkers.add(m);
}
}
}
return true;
};
project.accept(_function_1);
Assert.assertEquals(2, allXtendMarkers.size());
Assert.assertEquals(1, ((Object[]) Conversions.unwrapArray(this.persistedResourceDescriptions.get().getAllResourceDescriptions(), Object.class)).length);
} finally {
project.delete(true, true, null);
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.core.resources.IResourceVisitor in project xtext-xtend by eclipse.
the class WorkspaceScenariosTest method createJar.
public byte[] createJar(final Iterable<? extends Pair<? extends String, ? extends String>> sourceFiles, final Function1<? super String, ? extends Boolean> filter) {
try {
final IProject project = WorkbenchTestHelper.createPluginProject("my.temporary.data.project", "org.eclipse.xtext.xbase.lib", "org.eclipse.xtend.lib");
final HashMap<String, InputStream> listOfContents = CollectionLiterals.<String, InputStream>newHashMap();
try {
JavaProjectSetupUtil.addSourceFolder(JavaCore.create(project), "src");
JavaProjectSetupUtil.addSourceFolder(JavaCore.create(project), "xtend-gen");
for (final Pair<? extends String, ? extends String> sourceFile : sourceFiles) {
String _key = sourceFile.getKey();
IResourcesSetupUtil.createFile(("my.temporary.data.project/src/" + _key), sourceFile.getValue());
}
IResourcesSetupUtil.waitForBuild();
final IResourceVisitor _function = (IResource it) -> {
if ((it instanceof IFile)) {
final String path = ((IFile) it).getProjectRelativePath().removeFirstSegments(1).toString();
Boolean _apply = filter.apply(path);
boolean _not = (!(_apply).booleanValue());
if (_not) {
listOfContents.put(path, ((IFile) it).getContents());
}
}
return true;
};
final IResourceVisitor visitor = _function;
project.getFolder("src").accept(visitor);
project.getFolder("xtend-gen").accept(visitor);
project.getFolder("bin").accept(visitor);
final Function1<Map.Entry<String, InputStream>, Pair<String, InputStream>> _function_1 = (Map.Entry<String, InputStream> it) -> {
String _key_1 = it.getKey();
InputStream _value = it.getValue();
return Pair.<String, InputStream>of(_key_1, _value);
};
final InputStream jarin = JavaProjectSetupUtil.jarInputStream(((Pair<String, InputStream>[]) Conversions.unwrapArray(IterableExtensions.<Pair<String, InputStream>>toList(IterableExtensions.<Map.Entry<String, InputStream>, Pair<String, InputStream>>map(listOfContents.entrySet(), _function_1)), Pair.class)));
return ByteStreams.toByteArray(jarin);
} finally {
final Consumer<InputStream> _function_2 = (InputStream it) -> {
try {
it.close();
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
};
listOfContents.values().forEach(_function_2);
project.delete(true, true, null);
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.core.resources.IResourceVisitor in project xtext-xtend by eclipse.
the class XbaseEditorOpenClassFileTest method createJar.
public byte[] createJar(final Pair<? extends String, ? extends String>... sourceFiles) {
try {
final IProject project = WorkbenchTestHelper.createPluginProject("my.temporary.data.project", "org.eclipse.xtext.xbase.lib", "org.eclipse.xtend.lib");
final HashMap<String, InputStream> listOfContents = CollectionLiterals.<String, InputStream>newHashMap();
try {
final IFolder folder = JavaProjectSetupUtil.addSourceFolder(JavaCore.create(project), "src");
JavaProjectSetupUtil.addSourceFolder(JavaCore.create(project), "xtend-gen");
for (final Pair<? extends String, ? extends String> sourceFile : sourceFiles) {
IResourcesSetupUtil.createFile(folder.getFullPath().append(sourceFile.getKey()), sourceFile.getValue());
}
IResourcesSetupUtil.waitForBuild();
final IResourceVisitor _function = (IResource it) -> {
if ((it instanceof IFile)) {
final String path = ((IFile) it).getProjectRelativePath().removeFirstSegments(1).toString();
listOfContents.put(path, ((IFile) it).getContents());
}
return true;
};
final IResourceVisitor visitor = _function;
project.getFolder("src").accept(visitor);
project.getFolder("xtend-gen").accept(visitor);
project.getFolder("bin").accept(visitor);
final Function1<Map.Entry<String, InputStream>, Pair<String, InputStream>> _function_1 = (Map.Entry<String, InputStream> it) -> {
String _key = it.getKey();
InputStream _value = it.getValue();
return Pair.<String, InputStream>of(_key, _value);
};
final InputStream jarin = JavaProjectSetupUtil.jarInputStream(((Pair<String, InputStream>[]) Conversions.unwrapArray(IterableExtensions.<Pair<String, InputStream>>toList(IterableExtensions.<Map.Entry<String, InputStream>, Pair<String, InputStream>>map(listOfContents.entrySet(), _function_1)), Pair.class)));
return ByteStreams.toByteArray(jarin);
} finally {
final Consumer<InputStream> _function_2 = (InputStream it) -> {
try {
it.close();
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
};
listOfContents.values().forEach(_function_2);
project.delete(true, true, null);
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations