List of usage examples for org.eclipse.jdt.internal.core JarEntryDirectory JarEntryDirectory
public JarEntryDirectory(String simpleName)
From source file:org.eclipse.jdt.internal.core.JarPackageFragment.java
License:Open Source License
/** * Compute all the non-java resources according to the given entry names. *//*from w w w . j av a 2s .c o m*/ private Object[] computeNonJavaResources(ArrayList entryNames) { int length = entryNames.size(); if (length == 0) return JavaElementInfo.NO_NON_JAVA_RESOURCES; HashMap jarEntries = new HashMap(); // map from IPath to IJarEntryResource HashMap childrenMap = new HashMap(); // map from IPath to ArrayList<IJarEntryResource> // GROOVY start boolean isInteresting = LanguageSupportFactory.isInterestingProject(this.getJavaProject().getProject()); // GROOVY end ArrayList topJarEntries = new ArrayList(); for (int i = 0; i < length; i++) { String resName = (String) entryNames.get(i); // consider that a .java file is not a non-java resource (see bug 12246 Packages view shows .class and .java files when JAR has source) // GROOVY start // we want to show uncompiled groovy scripts that are coming in from a jar file /* old { if (!Util.isJavaLikeFileName(resName)) { } new */ if ((!Util.isJavaLikeFileName(resName) || (isInteresting && LanguageSupportFactory.isInterestingSourceFile(resName)))) { // GROOVY end IPath filePath = new Path(resName); IPath childPath = filePath.removeFirstSegments(this.names.length); if (jarEntries.containsKey(childPath)) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=222665 continue; } JarEntryFile file = new JarEntryFile(filePath.lastSegment()); jarEntries.put(childPath, file); if (childPath.segmentCount() == 1) { file.setParent(this); topJarEntries.add(file); } else { IPath parentPath = childPath.removeLastSegments(1); while (parentPath.segmentCount() > 0) { ArrayList parentChildren = (ArrayList) childrenMap.get(parentPath); if (parentChildren == null) { Object dir = new JarEntryDirectory(parentPath.lastSegment()); jarEntries.put(parentPath, dir); childrenMap.put(parentPath, parentChildren = new ArrayList()); parentChildren.add(childPath); if (parentPath.segmentCount() == 1) { topJarEntries.add(dir); break; } childPath = parentPath; parentPath = childPath.removeLastSegments(1); } else { parentChildren.add(childPath); break; // all parents are already registered } } } } } Iterator entries = childrenMap.entrySet().iterator(); while (entries.hasNext()) { Map.Entry entry = (Map.Entry) entries.next(); IPath entryPath = (IPath) entry.getKey(); ArrayList entryValue = (ArrayList) entry.getValue(); JarEntryDirectory jarEntryDirectory = (JarEntryDirectory) jarEntries.get(entryPath); int size = entryValue.size(); IJarEntryResource[] children = new IJarEntryResource[size]; for (int i = 0; i < size; i++) { JarEntryResource child = (JarEntryResource) jarEntries.get(entryValue.get(i)); child.setParent(jarEntryDirectory); children[i] = child; } jarEntryDirectory.setChildren(children); if (entryPath.segmentCount() == 1) { jarEntryDirectory.setParent(this); } } return topJarEntries.toArray(new Object[topJarEntries.size()]); }
From source file:org.jboss.tools.common.model.ui.editor.ModelObjectStorageEditorInput.java
License:Open Source License
IJarEntryResource findJarEntryFile() {
XModelObject o = object;//from w ww . j a v a 2 s . c om
JarEntryFile f = null;
JarEntryResource current = null;
String packageName = "";
List<String> parts = new ArrayList<String>();
List<XModelObject> os = new ArrayList<XModelObject>();
while (o != null && o.getFileType() != XModelObject.SYSTEM) {
String part = o.getFileType() == XModelObject.FILE ? FileAnyImpl.toFileName(o)
: o.getFileType() == XModelObject.FOLDER ? o.getAttributeValue(XModelObjectConstants.ATTR_NAME)
: null;
if (part != null) {
parts.add(0, part);
os.add(0, o);
if (f == null) {
f = new JarEntryFile(part) {
public InputStream getContents() throws CoreException {
return storage.getContents();
}
};
current = f;
} else {
if (packageName.length() > 0) {
packageName = part + "." + packageName;
} else {
packageName = part;
}
JarEntryDirectory d = new JarEntryDirectory(part);
current.setParent(d);
current = d;
}
}
o = o.getParent();
}
// if(!(o instanceof JarSystemImpl)) return null;
String file = Paths.expand(o.get(XModelObjectConstants.ATTR_NAME_LOCATION), o.getModel().getProperties());
IProject p = EclipseResourceUtil.getProject(o);
IJavaProject jp = EclipseResourceUtil.getJavaProject(p);
if (jp == null)
return null;
IPackageFragmentRoot root = null;
try {
IPackageFragmentRoot[] rs = jp.getAllPackageFragmentRoots();
for (IPackageFragmentRoot r : rs) {
if (r.getResource() != null && r.getResource().exists()
&& r.getResource().getLocation().toString().equals(file)) {
root = r;
} else if (r.getPath() != null && r.getPath().toString().equals(file)) {
root = r;
}
}
} catch (CoreException e) {
ModelUIPlugin.getDefault().logError(e);
}
if (root == null) {
root = jp.getPackageFragmentRoot(file);
}
if (root == null) {
return null;
}
if (current != null && !"META-INF".equalsIgnoreCase(current.getName()) && packageName.length() > 0) {
IPackageFragment pf = root.getPackageFragment(packageName);
f.setParent(pf);
} else {
current.setParent(root);
if (!(o instanceof JarSystemImpl)) {
Object q = root;
NonJavaResource nj = null;
for (int i = 0; i < parts.size(); i++) {
IResource ri = (IResource) os.get(i).getAdapter(IResource.class);
if (ri == null) {
return f;
}
nj = new NonJavaResource(q, ri);
q = nj;
}
if (nj != null) {
return nj;
}
}
}
return f;
}
From source file:org.jboss.tools.common.text.ext.hyperlink.xml.FaceletSourceTagHyperlink.java
License:Open Source License
@Override protected void doHyperlink(IRegion region) { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IEditorPart editorPart = page.getActiveEditor(); // if we open taglib definition in jar file JarEntryFile current = null;/* w w w . j a v a 2 s. co m*/ try { if (editorPart.getEditorInput() instanceof IStorageEditorInput && ((IStorageEditorInput) editorPart.getEditorInput()).getStorage() instanceof JarEntryFile) { current = (JarEntryFile) ((IStorageEditorInput) editorPart.getEditorInput()).getStorage(); } } catch (CoreException e) { ExtensionsPlugin.getDefault().logError(e); } if (current != null) { String fileToOpenName = getFilePath(region); if (fileToOpenName != null) { //remove whitespaces and first '/' fileToOpenName = fileToOpenName.trim(); if (fileToOpenName.indexOf('/') == 0) { fileToOpenName = fileToOpenName.substring(1); } int ii = fileToOpenName.lastIndexOf('/'); String folder = ii < 0 ? "" : fileToOpenName.substring(0, ii); fileToOpenName = fileToOpenName.substring(ii + 1); JarEntryFile fileToOpen = new JarEntryFile(fileToOpenName); if (folder.length() > 0) { if (folder.startsWith("META-INF")) { JarEntryResource r = null; while (folder.length() > 0) { int iii = folder.indexOf('/'); String name = iii < 0 ? folder : folder.substring(0, iii); folder = iii < 0 ? "" : folder.substring(iii + 1); fileToOpenName = fileToOpenName.substring(fileToOpenName.indexOf('/') + 1); JarEntryResource r1 = new JarEntryDirectory(name); r1.setParent(r != null ? r : current.getPackageFragmentRoot()); r = r1; } fileToOpen.setParent(r); } else { IPackageFragment pf = current.getPackageFragmentRoot() .getPackageFragment(folder.replace('/', '.')); fileToOpen.setParent(pf); } } else { fileToOpen.setParent(current.getPackageFragmentRoot()); } JarEntryEditorInput editorInputToOpenEditor = new JarEntryEditorInput(fileToOpen); IEditorPart openedEditor = openFileInEditor(editorInputToOpenEditor, fileToOpen.getName()); if (openedEditor == null) { openFileFailed(); } } return; } else if (editorPart.getEditorInput() instanceof IStorageEditorInput) { IStorageEditorInput modelObjectStorageEditorInput = (IStorageEditorInput) editorPart.getEditorInput(); try { IStorage storage = modelObjectStorageEditorInput.getStorage(); if (storage != null && getFilePath(region) != null) { if (openOnFromModelEditorIntup(storage.getFullPath(), getFilePath(region))) { return; } } } catch (CoreException e) { ExtensionsPlugin.getDefault().logError(e); } } super.doHyperlink(region); }
From source file:org.jboss.tools.jsf.jsf2.util.JSF2ResourceUtil.java
License:Open Source License
private static JarEntryResource searchInClassPath(IProject project, String classPathResource, int jarResourceType) { IJavaProject javaProject = JavaCore.create(project); try {//from w w w . ja va 2s.co m for (IPackageFragmentRoot fragmentRoot : javaProject.getAllPackageFragmentRoots()) { if (fragmentRoot instanceof JarPackageFragmentRoot) { JarPackageFragmentRoot jarPackageFragmentRoot = (JarPackageFragmentRoot) fragmentRoot; ZipEntry zipEntry = jarPackageFragmentRoot.getJar().getEntry(classPathResource); if (zipEntry != null) { if (jarResourceType == JAR_FILE_RESOURCE_TYPE) { JarEntryFile fileInJar = new JarEntryFile(classPathResource); fileInJar.setParent(jarPackageFragmentRoot); return fileInJar; } if (jarResourceType == JAR_DIRECTORY_RESOURCE_TYPE) { JarEntryDirectory directoryInJar = new JarEntryDirectory(classPathResource); directoryInJar.setParent(jarPackageFragmentRoot); return directoryInJar; } } } } } catch (JavaModelException e) { JSFModelPlugin.getPluginLog().logError(e); } catch (CoreException e) { JSFModelPlugin.getPluginLog().logError(e); } return null; }
From source file:org.jboss.tools.jsf.vpe.jsf.test.jbide.OpenOnTLDPackedInJar_JBIDE5693.java
License:Open Source License
public void testOpenOnTLDPackedInJar() throws Throwable { IProject project = ProjectsLoader.getInstance().getProject(JsfAllTests.IMPORT_JSF_20_PROJECT_NAME); IJavaProject javaProject = JavaCore.create(project); IPackageFragmentRoot fragmentRoot = javaProject.getPackageFragmentRoot("" + project.getLocation() + "/" //$NON-NLS-1$ //$NON-NLS-2$ + JAR_LIB_PATH);/*from www . j a va2 s.c o m*/ JarPackageFragmentRoot jarPackageFragmentRoot = (JarPackageFragmentRoot) fragmentRoot; JarEntryDirectory entryDirectory = new JarEntryDirectory(DIR); entryDirectory.setParent(jarPackageFragmentRoot); JarEntryFile fileInJar = new JarEntryFile(TEST_FILE); fileInJar.setParent(entryDirectory); JarEntryEditorInput editorInput = new JarEntryEditorInput(fileInJar); OpenOnUtil.checkOpenOnInEditor(editorInput, getEditorId(fileInJar.getName()), 71, 15, "CoreValidator.class"); //$NON-NLS-1$ }