Search in sources :

Example 11 with JarEntry

use of org.eclipse.che.ide.ext.java.shared.JarEntry in project che by eclipse.

the class JarNavigationTest method testNonJavaFolder.

@Test
public void testNonJavaFolder() throws Exception {
    String javaHome = System.getProperty("java.home") + "/lib/ext/zipfs.jar";
    IPackageFragmentRoot root = project.getPackageFragmentRoot(new File(javaHome).getPath());
    List<JarEntry> rootContent = navigation.getChildren(project, root.hashCode(), "/META-INF");
    assertThat(rootContent).isNotNull().isNotEmpty().onProperty("name").contains("services", "MANIFEST.MF");
}
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 12 with JarEntry

use of org.eclipse.che.ide.ext.java.shared.JarEntry in project che by eclipse.

the class OpenDeclarationFinder method handleDescriptor.

private void handleDescriptor(final Path projectPath, final OpenDeclarationDescriptor descriptor) {
    final EditorPartPresenter openedEditor = editorAgent.getOpenedEditor(Path.valueOf(descriptor.getPath()));
    if (openedEditor != null) {
        editorAgent.openEditor(openedEditor.getEditorInput().getFile(), new OpenEditorCallbackImpl() {

            @Override
            public void onEditorOpened(EditorPartPresenter editor) {
                setCursorAndActivateEditor(editor, descriptor.getOffset());
            }

            @Override
            public void onEditorActivated(EditorPartPresenter editor) {
                setCursorAndActivateEditor(editor, descriptor.getOffset());
            }
        });
        return;
    }
    if (descriptor.isBinary()) {
        navigationService.getEntry(projectPath, descriptor.getLibId(), descriptor.getPath()).then(new Operation<JarEntry>() {

            @Override
            public void apply(final JarEntry entry) throws OperationException {
                navigationService.getContent(projectPath, descriptor.getLibId(), Path.valueOf(entry.getPath())).then(new Operation<ClassContent>() {

                    @Override
                    public void apply(ClassContent content) throws OperationException {
                        final VirtualFile file = javaNodeFactory.newJarFileNode(entry, descriptor.getLibId(), projectPath, null);
                        editorAgent.openEditor(file, new OpenEditorCallbackImpl() {

                            @Override
                            public void onEditorOpened(final EditorPartPresenter editor) {
                                Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {

                                    @Override
                                    public void execute() {
                                        if (editor instanceof TextEditor) {
                                            ((TextEditor) editor).getDocument().setSelectedRange(LinearRange.createWithStart(descriptor.getOffset()).andLength(0), true);
                                            editor.activate();
                                        }
                                    }
                                });
                            }
                        });
                    }
                });
            }
        });
    } else {
        appContext.getWorkspaceRoot().getFile(descriptor.getPath()).then(new Operation<Optional<File>>() {

            @Override
            public void apply(Optional<File> file) throws OperationException {
                if (file.isPresent()) {
                    editorAgent.openEditor(file.get(), new OpenEditorCallbackImpl() {

                        @Override
                        public void onEditorOpened(final EditorPartPresenter editor) {
                            Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {

                                @Override
                                public void execute() {
                                    if (editor instanceof TextEditor) {
                                        ((TextEditor) editor).getDocument().setSelectedRange(LinearRange.createWithStart(descriptor.getOffset()).andLength(0), true);
                                        editor.activate();
                                    }
                                }
                            });
                        }
                    });
                }
            }
        });
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) ClassContent(org.eclipse.che.ide.ext.java.shared.dto.ClassContent) Optional(com.google.common.base.Optional) Scheduler(com.google.gwt.core.client.Scheduler) OpenEditorCallbackImpl(org.eclipse.che.ide.api.editor.OpenEditorCallbackImpl) Operation(org.eclipse.che.api.promises.client.Operation) JarEntry(org.eclipse.che.ide.ext.java.shared.JarEntry) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) File(org.eclipse.che.ide.api.resources.File) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 13 with JarEntry

use of org.eclipse.che.ide.ext.java.shared.JarEntry in project che by eclipse.

the class JarNavigationTest method testPackageFragmentContent.

@Test
public void testPackageFragmentContent() throws Exception {
    String javaHome = System.getProperty("java.home") + "/lib/rt.jar";
    IPackageFragmentRoot root = project.getPackageFragmentRoot(new File(javaHome).getPath());
    List<JarEntry> rootContent = navigation.getPackageFragmentRootContent(project, root.hashCode());
    assertThat(rootContent).isNotNull().isNotEmpty().onProperty("name").contains("META-INF", "java", "javax");
    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 14 with JarEntry

use of org.eclipse.che.ide.ext.java.shared.JarEntry 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 15 with JarEntry

use of org.eclipse.che.ide.ext.java.shared.JarEntry in project che by eclipse.

the class JavaNavigation method getJarClass.

private JarEntry getJarClass(IClassFile classFile) {
    JarEntry entry = DtoFactory.getInstance().createDto(JarEntry.class);
    entry.setType(JarEntryType.CLASS_FILE);
    entry.setName(classFile.getElementName());
    entry.setPath(classFile.getType().getFullyQualifiedName());
    return entry;
}
Also used : JarEntry(org.eclipse.che.ide.ext.java.shared.JarEntry)

Aggregations

JarEntry (org.eclipse.che.ide.ext.java.shared.JarEntry)23 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)16 File (java.io.File)15 Test (org.junit.Test)15 Operation (org.eclipse.che.api.promises.client.Operation)4 OperationException (org.eclipse.che.api.promises.client.OperationException)4 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)4 Optional (com.google.common.base.Optional)3 Scheduler (com.google.gwt.core.client.Scheduler)3 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)3 OpenEditorCallbackImpl (org.eclipse.che.ide.api.editor.OpenEditorCallbackImpl)3 File (org.eclipse.che.ide.api.resources.File)3 ClassContent (org.eclipse.che.ide.ext.java.shared.dto.ClassContent)3 Project (org.eclipse.che.ide.api.resources.Project)2 Resource (org.eclipse.che.ide.api.resources.Resource)2 SyntheticFile (org.eclipse.che.ide.api.resources.SyntheticFile)2 IClassFile (org.eclipse.jdt.core.IClassFile)2 JarEntryDirectory (org.eclipse.jdt.internal.core.JarEntryDirectory)2 JarEntryFile (org.eclipse.jdt.internal.core.JarEntryFile)2 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1