use of org.eclipse.jdt.internal.core.JarPackageFragmentRoot in project che by eclipse.
the class JavaNavigation method getContent.
public ClassContent getContent(IJavaProject project, int rootId, String path) throws CoreException {
IPackageFragmentRoot root = getPackageFragmentRoot(project, rootId);
if (root == null) {
return null;
}
if (path.startsWith("/")) {
//non java file
if (root instanceof JarPackageFragmentRoot) {
JarPackageFragmentRoot jarPackageFragmentRoot = (JarPackageFragmentRoot) root;
ZipFile jar = null;
try {
jar = jarPackageFragmentRoot.getJar();
ZipEntry entry = jar.getEntry(path.substring(1));
if (entry != null) {
try (InputStream stream = jar.getInputStream(entry)) {
return createContent(IoUtil.readStream(stream), false);
} catch (IOException e) {
LOG.error("Can't read file content: " + entry.getName(), e);
}
}
} 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 readFileContent(file);
}
}
if (resource instanceof JarEntryDirectory) {
JarEntryDirectory directory = (JarEntryDirectory) resource;
JarEntryFile file = findJarFile(directory, path);
if (file != null) {
return readFileContent(file);
}
}
}
} else {
return getContent(project, path);
}
return null;
}
use of org.eclipse.jdt.internal.core.JarPackageFragmentRoot in project che by eclipse.
the class JavaNavigation method getProjectDependecyJars.
public List<Jar> getProjectDependecyJars(IJavaProject project) throws JavaModelException {
List<Jar> jars = new ArrayList<>();
for (IPackageFragmentRoot fragmentRoot : project.getAllPackageFragmentRoots()) {
if (fragmentRoot instanceof JarPackageFragmentRoot) {
Jar jar = DtoFactory.getInstance().createDto(Jar.class);
jar.setId(fragmentRoot.hashCode());
jar.setName(fragmentRoot.getElementName());
jars.add(jar);
}
}
return jars;
}
use of org.eclipse.jdt.internal.core.JarPackageFragmentRoot in project che by eclipse.
the class IndexSelector method canSeeFocus.
private static int canSeeFocus(IJavaElement focus, JavaProject javaProject, char[][][] focusQualifiedNames) {
try {
if (focus == null)
return PROJECT_CAN_NOT_SEE_FOCUS;
if (focus.equals(javaProject))
return PROJECT_CAN_SEE_FOCUS;
if (focus instanceof JarPackageFragmentRoot) {
// focus is part of a jar
IPath focusPath = focus.getPath();
IClasspathEntry[] entries = javaProject.getExpandedClasspath();
for (int i = 0, length = entries.length; i < length; i++) {
IClasspathEntry entry = entries[i];
if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && entry.getPath().equals(focusPath))
return PROJECT_CAN_SEE_FOCUS;
}
return PROJECT_CAN_NOT_SEE_FOCUS;
}
// look for dependent projects
IPath focusPath = ((JavaProject) focus).getProject().getFullPath();
IClasspathEntry[] entries = javaProject.getExpandedClasspath();
for (int i = 0, length = entries.length; i < length; i++) {
IClasspathEntry entry = entries[i];
if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT && entry.getPath().equals(focusPath)) {
if (focusQualifiedNames != null) {
// builder state is usable, hence use it to try to reduce project which can see the focus...
State projectState = (State) JavaModelManager.getJavaModelManager().getLastBuiltState(javaProject.getProject(), null);
if (projectState != null) {
Object[] values = projectState.getReferences().valueTable;
int vLength = values.length;
for (int j = 0; j < vLength; j++) {
if (values[j] == null)
continue;
ReferenceCollection references = (ReferenceCollection) values[j];
if (references.includes(focusQualifiedNames, null, null)) {
return PROJECT_CAN_SEE_FOCUS;
}
}
return PROJECT_SOURCE_CAN_NOT_SEE_FOCUS;
}
}
return PROJECT_CAN_SEE_FOCUS;
}
}
return PROJECT_CAN_NOT_SEE_FOCUS;
} catch (JavaModelException e) {
return PROJECT_CAN_NOT_SEE_FOCUS;
}
}
use of org.eclipse.jdt.internal.core.JarPackageFragmentRoot in project xtext-eclipse by eclipse.
the class JavaClassPathResourceForIEditorInputFactoryTest method testBug463258_03c.
@Test(expected = CoreException.class)
public void testBug463258_03c() throws Throwable {
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);
IPackageFragmentRoot root = new JarPackageFragmentRoot(file, (JavaProject) project) {
};
IPackageFragment foo = root.getPackageFragment("foo");
JarEntryFile fileInJar = new JarEntryFile("bar.testlanguage");
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);
XtextReadonlyEditorInput editorInput = new XtextReadonlyEditorInput(fileInJar);
try {
factory.createResource(editorInput);
} catch (WrappedException e) {
throw e.getCause();
}
}
use of org.eclipse.jdt.internal.core.JarPackageFragmentRoot 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;
}
Aggregations