Search in sources :

Example 96 with IPackageFragmentRoot

use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.

the class JavaNavigation method getEntry.

public JarEntry getEntry(IJavaProject project, int rootId, String path) throws CoreException {
    IPackageFragmentRoot root = getPackageFragmentRoot(project, rootId);
    if (root == null) {
        return null;
    }
    if (path.startsWith("/")) {
        JarPackageFragmentRoot jarPackageFragmentRoot = (JarPackageFragmentRoot) root;
        ZipFile jar = null;
        try {
            jar = jarPackageFragmentRoot.getJar();
            ZipEntry entry = jar.getEntry(path.substring(1));
            if (entry != null) {
                JarEntry result = DtoFactory.getInstance().createDto(JarEntry.class);
                result.setType(JarEntryType.FILE);
                result.setPath(path);
                result.setName(entry.getName().substring(entry.getName().lastIndexOf("/") + 1));
                return result;
            }
        } finally {
            if (jar != null) {
                JavaModelManager.getJavaModelManager().closeZipFile(jar);
            }
        }
        Object[] resources = root.getNonJavaResources();
        for (Object resource : resources) {
            if (resource instanceof JarEntryFile) {
                JarEntryFile file = (JarEntryFile) resource;
                if (file.getFullPath().toOSString().equals(path)) {
                    return getJarEntryResource(file);
                }
            }
            if (resource instanceof JarEntryDirectory) {
                JarEntryDirectory directory = (JarEntryDirectory) resource;
                JarEntryFile file = findJarFile(directory, path);
                if (file != null) {
                    return getJarEntryResource(file);
                }
            }
        }
    } else {
        //java class or file
        IType type = project.findType(path);
        if (type != null && type.isBinary()) {
            IClassFile classFile = type.getClassFile();
            return getJarClass(classFile);
        }
    }
    return null;
}
Also used : JarEntryDirectory(org.eclipse.jdt.internal.core.JarEntryDirectory) IClassFile(org.eclipse.jdt.core.IClassFile) ZipFile(java.util.zip.ZipFile) JarPackageFragmentRoot(org.eclipse.jdt.internal.core.JarPackageFragmentRoot) ZipEntry(java.util.zip.ZipEntry) JarEntry(org.eclipse.che.ide.ext.java.shared.JarEntry) JarEntryFile(org.eclipse.jdt.internal.core.JarEntryFile) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) IType(org.eclipse.jdt.core.IType)

Example 97 with IPackageFragmentRoot

use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.

the class JavaNavigation method getPackageFragmentRoot.

private IPackageFragmentRoot getPackageFragmentRoot(IJavaProject project, int hash) throws JavaModelException {
    IPackageFragmentRoot[] roots = project.getAllPackageFragmentRoots();
    IPackageFragmentRoot packageFragmentRoot = null;
    for (IPackageFragmentRoot root : roots) {
        if (root.hashCode() == hash) {
            packageFragmentRoot = root;
            break;
        }
    }
    return packageFragmentRoot;
}
Also used : IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 98 with IPackageFragmentRoot

use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.

the class JarNavigationTest method testDoNotIncludeDefaultEmptyPackage.

@Test
public void testDoNotIncludeDefaultEmptyPackage() throws Exception {
    String javaHome = System.getProperty("java.home") + "/lib/ext/zipfs.jar";
    IPackageFragmentRoot root = project.getPackageFragmentRoot(new File(javaHome).getPath());
    List<JarEntry> rootContent = navigation.getPackageFragmentRootContent(project, root.hashCode());
    assertThat(rootContent).isNotNull().isNotEmpty().onProperty("name").excludes("(default package)");
    assertThat(rootContent).onProperty("path").contains("/META-INF");
}
Also used : JarEntry(org.eclipse.che.ide.ext.java.shared.JarEntry) File(java.io.File) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test)

Example 99 with IPackageFragmentRoot

use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.

the class JarNavigationTest method testClassFileFQN.

@Test
public void testClassFileFQN() throws Exception {
    String javaHome = System.getProperty("java.home") + "/lib/rt.jar";
    IPackageFragmentRoot root = project.getPackageFragmentRoot(new File(javaHome).getPath());
    List<JarEntry> rootContent = navigation.getChildren(project, root.hashCode(), "java.lang");
    assertThat(rootContent).isNotNull().isNotEmpty().onProperty("path").contains("java.lang.Object", "java.lang.String", "java.lang.Integer");
}
Also used : JarEntry(org.eclipse.che.ide.ext.java.shared.JarEntry) File(java.io.File) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test)

Example 100 with IPackageFragmentRoot

use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.

the class JarNavigationTest method testFileContentInPackage.

@Test
public void testFileContentInPackage() throws Exception {
    String javaHome = getClass().getResource("/temp").getPath() + "/ws/test/gwt-user.jar";
    IPackageFragmentRoot root = project.getPackageFragmentRoot(new File(javaHome).getPath());
    ClassContent content = navigation.getContent(project, root.hashCode(), "/com/google/gwt/user/User.gwt.xml");
    assertThat(content.getContent()).isNotNull().contains("<!-- Combines all user facilities into a single module for convenience.     -->").contains("<!-- Most new code should inherit this module.                              -->").contains("<inherits name=\"com.google.gwt.core.Core\"/>");
}
Also used : ClassContent(org.eclipse.che.ide.ext.java.shared.dto.ClassContent) File(java.io.File) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test)

Aggregations

IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)171 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)94 Test (org.junit.Test)91 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)77 OrganizeImportsOperation (org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation)67 IChooseImportQuery (org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery)67 IJavaProject (org.eclipse.jdt.core.IJavaProject)30 File (java.io.File)26 IJavaElement (org.eclipse.jdt.core.IJavaElement)20 JarEntry (org.eclipse.che.ide.ext.java.shared.JarEntry)16 IResource (org.eclipse.core.resources.IResource)16 IPath (org.eclipse.core.runtime.IPath)13 ArrayList (java.util.ArrayList)12 Path (org.eclipse.core.runtime.Path)11 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)11 CoreException (org.eclipse.core.runtime.CoreException)10 IFile (org.eclipse.core.resources.IFile)8 IType (org.eclipse.jdt.core.IType)8 JavaModelException (org.eclipse.jdt.core.JavaModelException)8 IFolder (org.eclipse.core.resources.IFolder)7