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