use of org.eclipse.jdt.internal.core.JarEntryFile in project che by eclipse.
the class JavaNavigation method getJarEntryResource.
private JarEntry getJarEntryResource(JarEntryResource resource) {
JarEntry entry = DtoFactory.getInstance().createDto(JarEntry.class);
if (resource instanceof JarEntryDirectory) {
entry.setType(JarEntryType.FOLDER);
}
if (resource instanceof JarEntryFile) {
entry.setType(JarEntryType.FILE);
}
entry.setName(resource.getName());
entry.setPath(resource.getFullPath().toOSString());
return entry;
}
use of org.eclipse.jdt.internal.core.JarEntryFile 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.JarEntryFile 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