Example usage for org.eclipse.jdt.internal.core JarEntryFile JarEntryFile

List of usage examples for org.eclipse.jdt.internal.core JarEntryFile JarEntryFile

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core JarEntryFile JarEntryFile.

Prototype

public JarEntryFile(String simpleName) 

Source Link

Usage

From source file:org.eclipse.jdt.internal.core.JarPackageFragment.java

License:Open Source License

/**
 * Compute all the non-java resources according to the given entry names.
 *///from w w w  .  j  ava2s .c o  m
private Object[] computeNonJavaResources(ArrayList entryNames) {
    int length = entryNames.size();
    if (length == 0)
        return JavaElementInfo.NO_NON_JAVA_RESOURCES;
    HashMap jarEntries = new HashMap(); // map from IPath to IJarEntryResource
    HashMap childrenMap = new HashMap(); // map from IPath to ArrayList<IJarEntryResource>

    // GROOVY start
    boolean isInteresting = LanguageSupportFactory.isInterestingProject(this.getJavaProject().getProject());
    // GROOVY end

    ArrayList topJarEntries = new ArrayList();
    for (int i = 0; i < length; i++) {
        String resName = (String) entryNames.get(i);
        // consider that a .java file is not a non-java resource (see bug 12246 Packages view shows .class and .java files when JAR has source)
        // GROOVY start 
        // we want to show uncompiled groovy scripts that are coming in from a jar file
        /* old {
        if (!Util.isJavaLikeFileName(resName)) {
        } new */
        if ((!Util.isJavaLikeFileName(resName)
                || (isInteresting && LanguageSupportFactory.isInterestingSourceFile(resName)))) {
            // GROOVY end
            IPath filePath = new Path(resName);
            IPath childPath = filePath.removeFirstSegments(this.names.length);
            if (jarEntries.containsKey(childPath)) {
                // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=222665
                continue;
            }
            JarEntryFile file = new JarEntryFile(filePath.lastSegment());
            jarEntries.put(childPath, file);
            if (childPath.segmentCount() == 1) {
                file.setParent(this);
                topJarEntries.add(file);
            } else {
                IPath parentPath = childPath.removeLastSegments(1);
                while (parentPath.segmentCount() > 0) {
                    ArrayList parentChildren = (ArrayList) childrenMap.get(parentPath);
                    if (parentChildren == null) {
                        Object dir = new JarEntryDirectory(parentPath.lastSegment());
                        jarEntries.put(parentPath, dir);
                        childrenMap.put(parentPath, parentChildren = new ArrayList());
                        parentChildren.add(childPath);
                        if (parentPath.segmentCount() == 1) {
                            topJarEntries.add(dir);
                            break;
                        }
                        childPath = parentPath;
                        parentPath = childPath.removeLastSegments(1);
                    } else {
                        parentChildren.add(childPath);
                        break; // all parents are already registered
                    }
                }
            }
        }
    }
    Iterator entries = childrenMap.entrySet().iterator();
    while (entries.hasNext()) {
        Map.Entry entry = (Map.Entry) entries.next();
        IPath entryPath = (IPath) entry.getKey();
        ArrayList entryValue = (ArrayList) entry.getValue();
        JarEntryDirectory jarEntryDirectory = (JarEntryDirectory) jarEntries.get(entryPath);
        int size = entryValue.size();
        IJarEntryResource[] children = new IJarEntryResource[size];
        for (int i = 0; i < size; i++) {
            JarEntryResource child = (JarEntryResource) jarEntries.get(entryValue.get(i));
            child.setParent(jarEntryDirectory);
            children[i] = child;
        }
        jarEntryDirectory.setChildren(children);
        if (entryPath.segmentCount() == 1) {
            jarEntryDirectory.setParent(this);
        }
    }
    return topJarEntries.toArray(new Object[topJarEntries.size()]);
}

From source file:org.eclipse.xtext.ui.tests.core.resource.Storage2UriMapperJdtImplTest.java

License:Open Source License

@Flaky
@Test/*from  w  ww  . j a v  a  2 s  .c  o m*/
public void testBug463258_01() throws Exception {
    IJavaProject project = createJavaProject("foo");
    IFile file = project.getProject().getFile("foo.jar");
    file.create(jarInputStream(new TextFile("foo/bar.notindexed", "//empty")), true, monitor());
    addJarToClasspath(project, file);

    Storage2UriMapperJavaImpl impl = getStorage2UriMapper();
    IPackageFragmentRoot root = project.getPackageFragmentRoot(file);
    IPackageFragment foo = root.getPackageFragment("foo");
    JarEntryFile fileInJar = new JarEntryFile("bar.notindexed");
    fileInJar.setParent(foo);

    URI uri = impl.getUri(fileInJar);
    assertEquals("archive:platform:/resource/foo/foo.jar!/foo/bar.notindexed", uri.toString());

    InputStream stream = new ResourceSetImpl().getURIConverter().createInputStream(uri);
    byte[] bytes = ByteStreams.toByteArray(stream);
    assertEquals("//empty", new String(bytes));
}

From source file:org.eclipse.xtext.ui.tests.core.resource.Storage2UriMapperJdtImplTest.java

License:Open Source License

@Flaky
@Test/*  w w w  .  ja  va2  s  .c o  m*/
public void testBug463258_02() throws Exception {
    IJavaProject project = createJavaProject("foo");
    IFile file = project.getProject().getFile("foo.jar");
    file.create(jarInputStream(new TextFile("do/not", "care")), true, monitor());
    addJarToClasspath(project, file);

    Storage2UriMapperJavaImpl impl = getStorage2UriMapper();
    IPackageFragmentRoot root = project.getPackageFragmentRoot(file);
    IPackageFragment foo = root.getPackageFragment("unknown");
    JarEntryFile fileInJar = new JarEntryFile("doesNotExist.notindexed");
    fileInJar.setParent(foo);

    URI uri = impl.getUri(fileInJar);
    assertEquals("archive:platform:/resource/foo/foo.jar!/unknown/doesNotExist.notindexed", uri.toString());
}

From source file:org.eclipse.xtext.ui.tests.core.resource.Storage2UriMapperJdtImplTest.java

License:Open Source License

@Flaky
@Test/*from  w  w  w. j a va 2 s  .  co  m*/
public void testBug463258_03a() throws Exception {
    IJavaProject project = createJavaProject("foo");
    IFile file = project.getProject().getFile("foo.jar");
    file.create(jarInputStream(new TextFile("foo/bar.notindexed", "//empty")), true, monitor());
    addJarToClasspath(project, file);

    Storage2UriMapperJavaImpl impl = getStorage2UriMapper();
    IPackageFragmentRoot root = project.getPackageFragmentRoot(file);
    IPackageFragment foo = root.getPackageFragment("foo");
    JarEntryFile fileInJar = new JarEntryFile("bar.notindexed");
    fileInJar.setParent(foo);

    File jarFile = file.getRawLocation().toFile();
    assertTrue("exists", jarFile.exists());
    assertTrue("delete", jarFile.delete());

    URI uri = impl.getUri(fileInJar);
    assertEquals("archive:platform:/resource/foo/foo.jar!/foo/bar.notindexed", uri.toString());
}

From source file:org.eclipse.xtext.ui.tests.core.resource.Storage2UriMapperJdtImplTest.java

License:Open Source License

@Test
public void testBug463258_03b() throws Exception {
    IJavaProject project = createJavaProject("foo");
    IFile file = project.getProject().getFile("foo.jar");
    file.create(jarInputStream(new TextFile("foo/bar.notindexed", "//empty")), true, monitor());

    Storage2UriMapperJavaImpl impl = getStorage2UriMapper();

    IPackageFragmentRoot root = new JarPackageFragmentRoot(file, (JavaProject) project) {
    };//w  ww .j  a v a2  s .c o m
    IPackageFragment foo = root.getPackageFragment("foo");
    JarEntryFile fileInJar = new JarEntryFile("bar.notindexed");
    fileInJar.setParent(foo);

    File jarFile = file.getLocation().toFile();
    assertTrue("exists", jarFile.exists());
    assertTrue("delete", jarFile.delete());

    URI uri = impl.getUri(fileInJar);
    assertNull(uri);
}

From source file:org.eclipse.xtext.ui.tests.core.resource.Storage2UriMapperJdtImplTest.java

License:Open Source License

@Test
public void testBug463258_03c() throws Exception {
    IJavaProject project = createJavaProject("foo");
    IFile file = project.getProject().getFile("foo.jar");
    file.create(jarInputStream(new TextFile("foo/bar.notindexed", "//empty")), true, monitor());
    addJarToClasspath(project, file);/*from  ww  w . java  2 s  . c om*/

    Storage2UriMapperJavaImpl impl = getStorage2UriMapper();

    IPackageFragmentRoot root = new JarPackageFragmentRoot(file, (JavaProject) project) {
    };
    IPackageFragment foo = root.getPackageFragment("foo");
    JarEntryFile fileInJar = new JarEntryFile("bar.notindexed");
    fileInJar.setParent(foo);

    File jarFile = file.getLocation().toFile();
    assertTrue("exists", jarFile.exists());
    assertTrue("delete", jarFile.delete());
    // simulate an automated refresh
    file.refreshLocal(IResource.DEPTH_ONE, null);
    URI uri = impl.getUri(fileInJar);
    assertNull(uri);
}

From source file:org.eclipse.xtext.ui.tests.core.resource.Storage2UriMapperJdtImplTest.java

License:Open Source License

@Test
public void testBug463258_05() throws Exception {
    IJavaProject project = createJavaProject("foo");
    final Storage2UriMapperJavaImpl impl = getStorage2UriMapper();
    IPackageFragmentRoot root = project.getPackageFragmentRoot("does/not/exist.jar");
    IPackageFragment foo = root.getPackageFragment("foo");
    final JarEntryFile fileInJar = new JarEntryFile("bar.notindexed");
    fileInJar.setParent(foo);//from w ww .j av a 2  s. c o  m
    LoggingTester.captureLogging(Level.ERROR, Storage2UriMapperJavaImpl.class, new Runnable() {
        @Override
        public void run() {
            URI uri = impl.getUri(fileInJar);
            assertNull(uri);
        }
    }).assertNoLogEntries();
}

From source file:org.eclipse.xtext.ui.tests.editor.model.JavaClassPathResourceForIEditorInputFactoryTest.java

License:Open Source License

@Test
public void testBug463258_01() throws Exception {
    IJavaProject project = createJavaProject("foo");
    IFile file = project.getProject().getFile("foo.jar");
    file.create(jarInputStream(new TextFile("foo/A.testlanguage", "//empty")), true, monitor());
    addJarToClasspath(project, file);/*  w w  w.  ja  v  a2 s. c  om*/

    IPackageFragmentRoot root = project.getPackageFragmentRoot(file);
    IPackageFragment foo = root.getPackageFragment("foo");
    JarEntryFile fileInJar = new JarEntryFile("A.testlanguage");
    fileInJar.setParent(foo);

    XtextReadonlyEditorInput editorInput = new XtextReadonlyEditorInput(fileInJar);
    Resource resource = factory.createResource(editorInput);
    assertNotNull(resource);
    resource.load(null);
}

From source file:org.eclipse.xtext.ui.tests.editor.model.JavaClassPathResourceForIEditorInputFactoryTest.java

License:Open Source License

@Test
public void testBug463258_02() throws Exception {
    IJavaProject project = createJavaProject("foo");
    IFile file = project.getProject().getFile("foo.jar");
    file.create(jarInputStream(new TextFile("do/not", "care")), true, monitor());
    addJarToClasspath(project, file);//from w  w w.j  a  v a2s .c  o  m

    IPackageFragmentRoot root = project.getPackageFragmentRoot(file);
    IPackageFragment foo = root.getPackageFragment("unknown");
    JarEntryFile fileInJar = new JarEntryFile("doesNotExist.testlanguage");
    fileInJar.setParent(foo);

    XtextReadonlyEditorInput editorInput = new XtextReadonlyEditorInput(fileInJar);
    Resource resource = factory.createResource(editorInput);
    assertNotNull(resource);
    try {
        resource.load(null);
    } catch (IOException e) {
        // expected
    }
}

From source file:org.eclipse.xtext.ui.tests.editor.model.JavaClassPathResourceForIEditorInputFactoryTest.java

License:Open Source License

@Test
public void testBug463258_03a() throws Exception {
    IJavaProject project = createJavaProject("foo");
    IFile file = project.getProject().getFile("foo.jar");
    file.create(jarInputStream(new TextFile("foo/bar.testlanguage", "//empty")), true, monitor());
    addJarToClasspath(project, file);//from  www .  ja v a 2s .  c  om

    IPackageFragmentRoot root = project.getPackageFragmentRoot(file);
    IPackageFragment foo = root.getPackageFragment("foo");
    JarEntryFile fileInJar = new JarEntryFile("bar.testlanguage");
    fileInJar.setParent(foo);

    File jarFile = file.getRawLocation().toFile();
    assertTrue("exists", jarFile.exists());
    assertTrue("delete", jarFile.delete());

    XtextReadonlyEditorInput editorInput = new XtextReadonlyEditorInput(fileInJar);
    Resource resource = factory.createResource(editorInput);
    assertNotNull(resource);
    try {
        resource.load(null);
    } catch (IOException e) {
        // expected
    }
}