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");
}
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();
}
}
});
}
});
}
}
});
}
}
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");
}
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;
}
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;
}
Aggregations