Search in sources :

Example 11 with IResourceVisitor

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);
    }
}
Also used : IResourceVisitor(org.eclipse.core.resources.IResourceVisitor) IFile(org.eclipse.core.resources.IFile) IMarker(org.eclipse.core.resources.IMarker) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource) Test(org.junit.Test)

Example 12 with IResourceVisitor

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);
    }
}
Also used : IResourceVisitor(org.eclipse.core.resources.IResourceVisitor) IFile(org.eclipse.core.resources.IFile) StringInputStream(org.eclipse.xtext.util.StringInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IProject(org.eclipse.core.resources.IProject) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) HashMap(java.util.HashMap) Map(java.util.Map) IResource(org.eclipse.core.resources.IResource) Pair(org.eclipse.xtext.xbase.lib.Pair)

Example 13 with IResourceVisitor

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);
    }
}
Also used : IResourceVisitor(org.eclipse.core.resources.IResourceVisitor) IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IProject(org.eclipse.core.resources.IProject) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) HashMap(java.util.HashMap) Map(java.util.Map) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder) Pair(org.eclipse.xtext.xbase.lib.Pair)

Aggregations

IResource (org.eclipse.core.resources.IResource)13 IResourceVisitor (org.eclipse.core.resources.IResourceVisitor)13 IFile (org.eclipse.core.resources.IFile)9 CoreException (org.eclipse.core.runtime.CoreException)9 IProject (org.eclipse.core.resources.IProject)8 HashMap (java.util.HashMap)3 IFolder (org.eclipse.core.resources.IFolder)3 Status (org.eclipse.core.runtime.Status)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 ResourceChangeCommandFactory (org.apache.sling.ide.eclipse.core.internal.ResourceChangeCommandFactory)2 IPath (org.eclipse.core.runtime.IPath)2 IStatus (org.eclipse.core.runtime.IStatus)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)2 Pair (org.eclipse.xtext.xbase.lib.Pair)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1