List of usage examples for org.eclipse.jdt.core IJarEntryResource getFullPath
@Override IPath getFullPath();
From source file:com.codenvy.ide.ext.java.server.JavaNavigation.java
License:Open Source License
private Object[] findJarDirectoryChildren(JarEntryDirectory directory, String path) { String directoryPath = directory.getFullPath().toOSString(); if (directoryPath.equals(path)) { return directory.getChildren(); }/*from w w w . j a v a 2s . c o m*/ if (path.startsWith(directoryPath)) { for (IJarEntryResource resource : directory.getChildren()) { String childrenPath = resource.getFullPath().toOSString(); if (childrenPath.equals(path)) { return resource.getChildren(); } if (path.startsWith(childrenPath) && resource instanceof JarEntryDirectory) { findJarDirectoryChildren((JarEntryDirectory) resource, path); } } } return null; }
From source file:com.codenvy.ide.ext.java.server.JavaNavigation.java
License:Open Source License
private JarEntryFile findJarFile(JarEntryDirectory directory, String path) { for (IJarEntryResource children : directory.getChildren()) { if (children.isFile() && children.getFullPath().toOSString().equals(path)) { return (JarEntryFile) children; }/*from w w w . jav a2s. com*/ if (!children.isFile()) { JarEntryFile file = findJarFile((JarEntryDirectory) children, path); if (file != null) { return file; } } } return null; }
From source file:com.iw.plugins.spindle.ui.util.Revealer.java
License:Mozilla Public License
/** * @param useSelection/*from w w w.j a v a 2 s . c o m*/ * @return */ private static ISelection checkSelectionForJarEntryFile(ISelection useSelection, IJavaProject jproject) { if (useSelection.isEmpty() || !(useSelection instanceof IStructuredSelection)) return useSelection; IStructuredSelection structured = (IStructuredSelection) useSelection; Object first = structured.getFirstElement(); if (structured.size() > 1 || !(first instanceof IJarEntryResource)) return useSelection; IJarEntryResource jarResource = (IJarEntryResource) first; IPath path = jarResource.getFullPath().removeFileExtension(); String name = path.lastSegment(); IPackageFragment[] fragments = null; try { if (jproject != null) { IPackageFragment frag = (IPackageFragment) jarResource.getParent(); if (frag != null) fragments = new IPackageFragment[] { frag }; } else { fragments = JarEntryFileUtil.getPackageFragments(ResourcesPlugin.getWorkspace().getRoot(), jarResource); } if (fragments.length != 1) return useSelection; // check to see if there is an IClassFile in the package IJavaElement[] children = fragments[0].getChildren(); if (children.length > 0) { IClassFile revealInstead = null; for (int i = 0; i < children.length; i++) { if (children[i].getElementType() != IJavaElement.CLASS_FILE) continue; revealInstead = (IClassFile) children[i]; String temp = revealInstead.getElementName(); temp = temp.substring(0, temp.length() - 6); if (temp.equals(name)) return new StructuredSelection(revealInstead); } if (revealInstead != null) return new StructuredSelection(revealInstead); } return new StructuredSelection(fragments[0]); } catch (CoreException e) { UIPlugin.log(e); } return useSelection; }
From source file:it.unibz.instasearch.indexing.WorkspaceIndexerJDT.java
License:Open Source License
/** * @param jarRes//from w w w . j a v a 2 s .co m * @return */ private boolean isIndexable(IJarEntryResource jarRes) { String ext = jarRes.getFullPath().getFileExtension(); return isIndexableExtension(ext); }
From source file:org.dev.toos.constcode.model.ConstModel.java
License:Apache License
/**Jar*/ private void iterateIJarEntryResource(IJarEntryResource atElement, final String resourceName, Map<String, Object> findRes) throws CoreException { if (atElement.getFullPath().toString().endsWith(resourceName) == true) { //System.out.println(atElement.getFullPath().toString()); JarPackageFragmentRoot root = (JarPackageFragmentRoot) atElement.getPackageFragmentRoot(); String name = root.getJar().getName(); findRes.put(name, atElement);//from w w w. ja v a2 s .c o m } IJarEntryResource[] resourcesItem = atElement.getChildren(); if (resourcesItem != null) for (IJarEntryResource element : resourcesItem) iterateItem(element, resourceName, findRes); }
From source file:org.dev.toos.constcode.model.ConstModel.java
License:Apache License
/**?jar */ private void loadConst4Jar(String name, IJarEntryResource atElement) { //1./*from w ww .j a va 2s . c o m*/ ConstGroup groupModel = this.constGroupMap.get(name); if (groupModel == null) { InputStream inStream = null; String resourceName = atElement.getName(); try { // if (atElement.) JarPackageFragmentRoot root = (JarPackageFragmentRoot) atElement.getPackageFragmentRoot(); ZipFile jar = root.getJar(); ZipEntry zipEntry = jar.getEntry(atElement.getFullPath().toString().substring(1)); if (zipEntry == null) return; inStream = jar.getInputStream(zipEntry); if (inStream == null) return; } catch (Exception e) { Message.errorInfo("load IJarEntryResource " + resourceName + "?", e); return; } // groupModel = new JARSourceConstCodeGroup(name, inStream); groupModel.initGroup(); this.constGroupMap.put(name, groupModel); this.constGroupList.add(groupModel); groupModel.loadData(); } else groupModel.reloadData(); }
From source file:org.eclipse.xtext.ui.resource.JarEntryLocator.java
License:Open Source License
/** * @return a URI for the given jarEntry, can be <code>null</code>. *//*w w w . j av a 2 s .co m*/ public URI getURI(IPackageFragmentRoot root, IJarEntryResource jarEntry, TraversalState state) { if (root.isArchive()) { URI jarURI = JarEntryURIHelper.getUriForPackageFragmentRoot(root); URI storageURI = URI.createURI(jarEntry.getFullPath().toString()); return createJarURI(root.isArchive(), jarURI, storageURI); } else if (root instanceof ExternalPackageFragmentRoot) { IResource resource = ((ExternalPackageFragmentRoot) root).resource(); IPath result = resource.getFullPath(); for (int i = 1; i < state.getParents().size(); i++) { Object obj = state.getParents().get(i); if (obj instanceof IPackageFragment) { result = result.append(new Path(((IPackageFragment) obj).getElementName().replace('.', '/'))); } else if (obj instanceof IJarEntryResource) { result = result.append(((IJarEntryResource) obj).getName()); } } result = result.append(jarEntry.getName()); return URI.createPlatformResourceURI(result.toString(), true); } else { throw new IllegalStateException("Unexpeced root type: " + root.getClass().getName()); } }
From source file:org.eclipse.xtext.ui.tests.core.builder.impl.PackageFragmentRootWalkerTest.java
License:Open Source License
@Test public void testTraversePackageFragmentRoot() throws Exception { IJavaProject project = createJavaProject("foo"); String jarName = "JarWalkerTest.jar"; IFile file = project.getProject().getFile(jarName); file.create(getClass().getResourceAsStream(jarName), true, new NullProgressMonitor()); addJarToClasspath(project, file);//from w ww. j a va 2s. c o m final Set<IPath> pathes = new HashSet<IPath>(); PackageFragmentRootWalker<Void> walker = new PackageFragmentRootWalker<Void>() { @Override protected Void handle(IJarEntryResource jarEntry, TraversalState state) { pathes.add(jarEntry.getFullPath()); return null; } }; for (IPackageFragmentRoot root : project.getPackageFragmentRoots()) { if (root.getElementName().equals(jarName)) walker.traverse(root, false); } assertEquals(3, pathes.size()); }
From source file:org.eclipse.xtext.ui.util.JdtClasspathUriResolver.java
License:Open Source License
protected URI findResourceInWorkspace(IJavaProject javaProject, URI classpathUri) throws CoreException { if (javaProject.exists()) { String packagePath = classpathUri.trimSegments(1).path(); String fullPath = classpathUri.path(); String fileName = classpathUri.lastSegment(); IPath filePath = new Path(fileName); String packageName = isEmpty(packagePath) ? "" : packagePath.substring(1).replace('/', '.'); for (IPackageFragmentRoot packageFragmentRoot : javaProject.getAllPackageFragmentRoots()) { IPackageFragment packageFragment = packageFragmentRoot.getPackageFragment(packageName); if (packageFragment.exists()) { IResource packageFragmentResource = packageFragment.getResource(); if (packageFragmentResource instanceof IContainer) { IFile file = ((IContainer) packageFragmentResource).getFile(filePath); if (file.exists()) return createPlatformResourceURI(file); } else { // jar file or external class folder if (packageFragmentRoot.isArchive()) { // jar file Object[] nonJavaResources = getNonJavaResources(packageFragmentRoot, packageFragment); for (Object nonJavaResource : nonJavaResources) { IJarEntryResource jarEntryResource = (IJarEntryResource) nonJavaResource; if (fullPath.equals(jarEntryResource.getFullPath().toString())) { IResource packageFragmentRootResource = packageFragmentRoot.getResource(); if (packageFragmentRootResource != null) { // we have a resource - use nested platform/resource URI packageFragmentRootURI = createPlatformResourceURI( packageFragmentRootResource); URI result = createArchiveURI(packageFragmentRootURI, fullPath); return result; } else { // no resource - use file uri IPath packageFragmentRootPath = packageFragmentRoot.getPath(); URI packageFragmentRootURI = URI .createFileURI(packageFragmentRootPath.toString()); URI result = createArchiveURI(packageFragmentRootURI, fullPath); return result; }// w w w.j ava 2s .com } } } else if (packageFragmentRoot.isExternal()) { // external class folder Object[] nonJavaResources = getNonJavaResources(packageFragmentRoot, packageFragment); for (Object nonJavaResource : nonJavaResources) { IJarEntryResource jarEntryResource = (IJarEntryResource) nonJavaResource; if (fileName.equals(jarEntryResource.getName())) { IResource packageFragmentRootResource = ((ExternalPackageFragmentRoot) packageFragmentRoot) .resource(); IPath absolutePath = packageFragmentRootResource.getFullPath(); absolutePath = absolutePath.append(fullPath); return createPlatformResourceURI(absolutePath); } } } } } } // not found in a source folder - look for a resource relative to project root // of this project or one of its dependencies URI result = findResourceInProjectRoot(javaProject, classpathUri.path(), Sets.<String>newHashSet()); if (result != null) { return result; } } return classpathUri; }
From source file:org.jboss.ide.eclipse.freemarker.configuration.ConfigurationManager.java
License:Open Source License
public void associateMappingLibraries(List<?> libraries, Shell shell) { for (Iterator<?> i = libraries.iterator(); i.hasNext();) { Object obj = i.next();/*ww w. ja va 2s.c om*/ if (obj instanceof IFile) { IFile file = (IFile) obj; String namespace = file.getName(); int index = namespace.indexOf("."); //$NON-NLS-1$ if (index >= 0) namespace = namespace.substring(0, index); InputDialog inputDialog = new InputDialog(shell, Messages.ConfigurationManager_TITLE_CHOOSE_NAMESPACE, MessageFormat.format(Messages.ConfigurationManager_CHOOSE_NAMESPACE_FOR, file.getName()), namespace, null); int rtn = inputDialog.open(); if (rtn == IDialogConstants.OK_ID) { namespace = inputDialog.getValue(); try { this.macroLibrary.put(namespace, new MacroLibrary(namespace, file)); } catch (CoreException e) { Plugin.error(e); } catch (IOException e) { Plugin.error(e); } } } else if (obj instanceof IJarEntryResource && ((IJarEntryResource) obj).isFile()) { IJarEntryResource jef = (IJarEntryResource) obj; String namespace = jef.getName(); int index = namespace.indexOf("."); //$NON-NLS-1$ if (index >= 0) namespace = namespace.substring(0, index); InputDialog inputDialog = new InputDialog(shell, Messages.ConfigurationManager_TITLE_CHOOSE_NAMESPACE, MessageFormat.format(Messages.ConfigurationManager_CHOOSE_NAMESPACE_FOR, jef.getName()), namespace, null); int rtn = inputDialog.open(); if (rtn == IDialogConstants.OK_ID) { namespace = inputDialog.getValue(); try { InputStream is = null; try { is = getProjectClassLoader().getResourceAsStream(jef.getFullPath().toString()); if (null != is) { this.macroLibrary.put(namespace, new MacroLibrary(namespace, is, jef.getFullPath().toString(), MacroLibrary.TYPE_JAR_ENTRY)); } else { // FIXME: add error dialog here } } finally { if (is != null) { is.close(); } } } catch (CoreException e) { Plugin.error(e); } catch (IOException e) { Plugin.error(e); } } } } save(); }