@Override protected URI internalGetUri(IStorage storage) { if (!uriValidator.isPossiblyManaged(storage)) return null; URI uri = super.internalGetUri(storage); if (uri != null) return uri; if (storage instanceof IJarEntryResource) { final IJarEntryResource storage2 = (IJarEntryResource) storage; Map<URI, IStorage> data = getAllEntries(storage2.getPackageFragmentRoot()); for (Map.Entry<URI, IStorage> entry : data.entrySet()) { if (entry.getValue().equals(storage2)) return entry.getKey(); } } return null; }
/** * @return a URI for the given jarEntry, can be <code>null</code>. */ 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()); } }
/** * Converts the physical URI to a logic URI based on the bundle symbolic name. */ protected URI getLogicalURI(URI uri, IStorage storage, TraversalState state) { if (bundleSymbolicName != null) { URI logicalURI = URI.createPlatformResourceURI(bundleSymbolicName, false); List<?> parents = state.getParents(); for (int i = 1; i < parents.size(); i++) { Object obj = parents.get(i); if (obj instanceof IPackageFragment) { logicalURI = logicalURI.appendSegments(((IPackageFragment) obj).getElementName().split("\\.")); } else if (obj instanceof IJarEntryResource) { logicalURI = logicalURI.appendSegment(((IJarEntryResource) obj).getName()); } else if (obj instanceof IFolder) { logicalURI = logicalURI.appendSegment(((IFolder) obj).getName()); } } return logicalURI.appendSegment(uri.lastSegment()); } return uri; }
public T traverse(IPackageFragmentRoot root, boolean stopOnFirstResult) throws JavaModelException { T result = null; if (root.exists()) { Object[] resources = root.getNonJavaResources(); TraversalState state = new TraversalState(root); for (Object object : resources) { if (object instanceof IJarEntryResource) { result = traverse((IJarEntryResource) object, stopOnFirstResult, state); if (stopOnFirstResult && result != null) return result; } } IJavaElement[] children = root.getChildren(); for (IJavaElement javaElement : children) { if (javaElement instanceof IPackageFragment) { result = traverse((IPackageFragment) javaElement, stopOnFirstResult, state); if (stopOnFirstResult && result != null) return result; } } } return result; }
protected T traverse(IPackageFragment pack, boolean stopOnFirstResult, TraversalState state) throws JavaModelException { T result = null; state.push(pack); IJavaElement[] children = pack.getChildren(); for (IJavaElement iJavaElement : children) { if (iJavaElement instanceof IPackageFragment) { result = traverse((IPackageFragment) iJavaElement, stopOnFirstResult, state); if (stopOnFirstResult && result!=null) return result; } } Object[] resources = pack.getNonJavaResources(); for (Object object : resources) { if (object instanceof IJarEntryResource) { result = traverse((IJarEntryResource) object, stopOnFirstResult, state); if (stopOnFirstResult && result!=null) return result; } } state.pop(); return result; }
protected T traverse(IJarEntryResource jarEntry, boolean stopOnFirstResult, TraversalState state) { T result = null; if (jarEntry.isFile()) { result = handle(jarEntry, state); } else { state.push(jarEntry); IJarEntryResource[] children = jarEntry.getChildren(); for (IJarEntryResource child : children) { result = traverse(child, stopOnFirstResult, state); if (stopOnFirstResult && result!=null) return result; } state.pop(); } return result; }
protected IPackageFragmentRoot getJarWithEntry(URI uri) { Iterable<Pair<IStorage, IProject>> storages = getStorages(uri); IPackageFragmentRoot result = null; for (Pair<IStorage, IProject> storage2Project : storages) { IStorage storage = storage2Project.getFirst(); if (storage instanceof IJarEntryResource) { IPackageFragmentRoot fragmentRoot = ((IJarEntryResource) storage).getPackageFragmentRoot(); if (fragmentRoot != null) { IJavaProject javaProject = fragmentRoot.getJavaProject(); if (isAccessibleXtextProject(javaProject.getProject())) return fragmentRoot; if (result != null) result = fragmentRoot; } } } return result; }
private Object[] findJarDirectoryChildren(JarEntryDirectory directory, String path) { String directoryPath = directory.getFullPath().toOSString(); if (directoryPath.equals(path)) { return directory.getChildren(); } 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; }
@Override public String getText(Object element) { if (!(element instanceof IModule)) { return super.getText(element); } String text = null; IModule module = (IModule) element; String packageName = module.getPackageName(); if (!module.isBinary()) { ModuleFile moduleFile = (ModuleFile) module; IFile file = moduleFile.getFile(); String modulePath = file.getFullPath().makeRelative().toString(); text = packageName + " - " + modulePath; } else { ModuleJarResource moduleJarResource = (ModuleJarResource) module; IJarEntryResource jarEntryResource = moduleJarResource.getJarEntryResource(); String jarPath = jarEntryResource.getPackageFragmentRoot().getPath().makeRelative().toString(); text = packageName + " - " + jarPath; } return text; }
/** * Helper method to return the absolute workspace path of a GWT Module. * * If the module file is located in a JAR, then the absolute path of the JAR * on the file system is returned. */ private static IPath getPathForModule(IModule module) { if (module == null) { return null; } if (!module.isBinary()) { ModuleFile moduleFile = (ModuleFile) module; IFile file = moduleFile.getFile(); return file.getFullPath(); } ModuleJarResource moduleJarResource = (ModuleJarResource) module; IJarEntryResource jarEntryResource = moduleJarResource.getJarEntryResource(); return jarEntryResource.getPackageFragmentRoot().getPath(); }
/** * @param packageFragmentRoot * @throws JavaModelException * @throws CoreException */ @SuppressWarnings("restriction") private static Manifest extractManifest(IPackageFragmentRoot packageFragmentRoot) throws JavaModelException { Manifest result = null; final Object[] nonJavaResources = packageFragmentRoot.getNonJavaResources(); for (Object obj : nonJavaResources) { if (obj instanceof JarEntryDirectory) { final JarEntryDirectory jarEntryDirectory = (JarEntryDirectory) obj; final IJarEntryResource[] jarEntryResources = jarEntryDirectory.getChildren(); for (IJarEntryResource jarEntryResource : jarEntryResources) { if ("MANIFEST.MF".equals(jarEntryResource.getName())) { try { final InputStream stream = jarEntryResource.getContents(); result = new Manifest(stream); } catch (Exception e) { // no manifest as result } } } } } return result; }
private static void collectNonJavaResources(Object[] nonJavaResources, IPath rootPath, List<JarEntryStorage> list, JarEntryPredicate jarEntryPredicate) { for (Object nonJavaRes : nonJavaResources) { if (nonJavaRes instanceof IJarEntryResource) { IJarEntryResource jarEntry = (IJarEntryResource) nonJavaRes; boolean addToList = jarEntryPredicate == null ? true : jarEntryPredicate.test(jarEntry); if (addToList) { list.add(new JarEntryStorage(rootPath.append(jarEntry .getFullPath()), jarEntry)); } } } }
private static boolean isEclipseNLSAvailable(IStorageEditorInput editorInput) { IStorage storage; try { storage= editorInput.getStorage(); } catch (CoreException ex) { return false; } if (!(storage instanceof IJarEntryResource)) return false; IJavaProject javaProject= ((IJarEntryResource) storage).getPackageFragmentRoot().getJavaProject(); if (javaProject == null || !javaProject.exists()) return false; try { return javaProject.findType("org.eclipse.osgi.util.NLS") != null; //$NON-NLS-1$ } catch (JavaModelException e) { return false; } }
private String getQualifiedName(Object element) throws JavaModelException { if (element instanceof IResource) return ((IResource)element).getFullPath().toString(); if (element instanceof IJarEntryResource) return ((IJarEntryResource)element).getFullPath().toString(); if (element instanceof LogicalPackage) return ((LogicalPackage)element).getElementName(); if (element instanceof IJavaProject || element instanceof IPackageFragmentRoot || element instanceof ITypeRoot) { IResource resource= ((IJavaElement)element).getCorrespondingResource(); if (resource != null) return getQualifiedName(resource); } if (element instanceof IBinding) return BindingLabelProvider.getBindingLabel((IBinding)element, LABEL_FLAGS); return TextProcessor.deprocess(JavaElementLabels.getTextLabel(element, LABEL_FLAGS)); }
public IJarEntryResource[] getChildren() { if (this.resource instanceof IContainer) { IResource[] members; try { members = ((IContainer) this.resource).members(); } catch (CoreException e) { Util.log(e, "Could not retrieve children of " + this.resource.getFullPath()); //$NON-NLS-1$ return NO_CHILDREN; } int length = members.length; if (length == 0) return NO_CHILDREN; IJarEntryResource[] children = new IJarEntryResource[length]; for (int i = 0; i < length; i++) { children[i] = new NonJavaResource(this, members[i]); } return children; } return NO_CHILDREN; }
private TapestryFile searchNonJavaResources(IParent root, String path) throws JavaModelException { String[] segments = path.split("/"); if (root instanceof IPackageFragmentRoot) { for (Object nonJava : ((IPackageFragmentRoot) root).getNonJavaResources()) { if (nonJava instanceof IJarEntryResource) { IJarEntryResource resource = (IJarEntryResource) nonJava; if (StringUtils.equals(segments[0], resource.getName())) { return searchRecursively(resource, path, segments, 1); } } } } return null; }
/** * Initialize the processor cache from JAR resources. * * @param jarEntryResources A list of JAR entries describing the dialects and their * processors to store. * @throws CoreException * @throws XMLException */ public static void initializeFromResources(List<IJarEntryResource> jarEntryResources) throws XMLException, CoreException { XMLReader<Dialect> xmlreader = new XMLReader<Dialect>(Dialect.class); for (IJarEntryResource jarEntry: jarEntryResources) { // Get default file as stream Dialect dialect = xmlreader.readXMLData(jarEntry.getContents()); // Link the processor with it's dialect for (Processor processor: dialect.getProcessors()) { processor.setDialect(dialect); processors.add(processor); } // Ensure processors are in alphabetical order Collections.sort(processors, new Comparator<Processor>() { @Override public int compare(Processor p1, Processor p2) { return p1.getName().compareTo(p2.getName()); } }); } }
/** * Delegate to * {@link #handle(URI, IStorage, org.eclipse.xtext.ui.resource.PackageFragmentRootWalker.TraversalState)}. */ @Override protected T handle(IJarEntryResource jarEntry, TraversalState state) { URI uri = getURI(jarEntry, state); if (isValid(uri, jarEntry)) { return handle(getLogicalURI(uri, jarEntry, state), jarEntry, state); } return null; }
@Override protected Resource createResource(IStorage storage) throws CoreException { if (storage instanceof IJarEntryResource) { return createResourceFor((IJarEntryResource) storage); } return super.createResource(storage); }
protected Resource createResourceFor(IJarEntryResource storage) { ResourceSet resourceSet = getResourceSet(storage); URI uri = storageToUriMapper.getUri(storage); configureResourceSet(resourceSet, uri); XtextResource resource = createResource(resourceSet, uri); resource.setValidationDisabled(isValidationDisabled(storage)); return resource; }
/** * @since 2.4 */ @Override protected boolean isValidationDisabled(IStorage storage) { if (storage instanceof IJarEntryResource) { return true; } return super.isValidationDisabled(storage); }
@Override protected ResourceSet getResourceSet(IStorage storage) { if (storage instanceof IJarEntryResource) { IPackageFragmentRoot root = ((IJarEntryResource) storage).getPackageFragmentRoot(); if (root != null) { IJavaProject project = root.getJavaProject(); if (project != null) return getResourceSetProvider().get(project.getProject()); } } return super.getResourceSet(storage); }
private JarEntryFile findJarFile(JarEntryDirectory directory, String path) { for (IJarEntryResource children : directory.getChildren()) { if (children.isFile() && children.getFullPath().toOSString().equals(path)) { return (JarEntryFile) children; } if (!children.isFile()) { JarEntryFile file = findJarFile((JarEntryDirectory) children, path); if (file != null) { return file; } } } return null; }
public Object[] getChildren(Object element) { if (!exists(element)) return NO_CHILDREN; try { if (element instanceof IJavaModel) return getJavaProjects((IJavaModel) element); if (element instanceof IJavaProject) return getPackageFragmentRoots((IJavaProject) element); if (element instanceof IPackageFragmentRoot) return getPackageFragmentRootContent((IPackageFragmentRoot) element); if (element instanceof IPackageFragment) return getPackageContent((IPackageFragment) element); if (element instanceof IFolder) return getFolderContent((IFolder) element); if (element instanceof IJarEntryResource) { return ((IJarEntryResource) element).getChildren(); } if (getProvideMembers() && element instanceof ISourceReference && element instanceof IParent) { return ((IParent) element).getChildren(); } } catch (CoreException e) { return NO_CHILDREN; } return NO_CHILDREN; }
/** * Returns the jar entry resources from the list of elements. * * @param elements the list of elements * @return the array of jar entry resources * @since 3.6 */ public static IJarEntryResource[] getJarEntryResources(List<?> elements) { List<IJarEntryResource> resources = new ArrayList<IJarEntryResource>(elements.size()); for (Iterator<?> iter = elements.iterator(); iter.hasNext(); ) { Object element = iter.next(); if (element instanceof IJarEntryResource) resources.add((IJarEntryResource) element); } return resources.toArray(new IJarEntryResource[resources.size()]); }
public ParentChecker( IResource[] resources, IJavaElement[] javaElements, IJarEntryResource[] jarResources) { Assert.isNotNull(resources); Assert.isNotNull(javaElements); Assert.isNotNull(jarResources); fResources = resources; fJavaElements = javaElements; fJarResources = jarResources; }
private static String getHTMLContent(IJarEntryResource jarEntryResource, String encoding) throws CoreException { InputStream in = jarEntryResource.getContents(); try { return getContentsFromInputStream(in, encoding); } finally { if (in != null) { try { in.close(); } catch (IOException e) { // ignore } } } }
/** * Returns the module corresponding to the given JAR resource. * * @param jarResource the module JAR resource * @return the module, or <code>null</code> if unable to associate the given JAR resource with a * module */ public static ModuleJarResource create(IJarEntryResource jarResource) { if (!isModuleXml(jarResource)) { return null; } return new ModuleJarResource(jarResource); }
private static IModule create(Object resource, boolean allowModulesInJars) { IFile file = AdapterUtilities.getAdapter(resource, IFile.class); if (file != null) { return create(file); } else { IJarEntryResource jarEntryRes = AdapterUtilities.getAdapter(resource, IJarEntryResource.class); if (jarEntryRes != null && allowModulesInJars) { return create(jarEntryRes); } } return null; }
public boolean isReadOnly() { if (resource instanceof IJarEntryResource) return true; if (resource instanceof IFile) { IFile file = (IFile) resource; return file.isReadOnly() || file.isLinked(); } return false; }
private static JarEntryStorage findJarEntry(final IDocument document, final String packageName, final String name) { IJavaProject javaProject = getCurrentJavaProject(document); if (javaProject != null && javaProject.exists()) { try { IPackageFragmentRoot[] roots = javaProject .getPackageFragmentRoots(); for (IPackageFragmentRoot root : roots) { if (root.isArchive()) { IPackageFragment p = root .getPackageFragment(packageName); if (p != null && p.exists()) { Object[] o = p.getNonJavaResources(); for (Object nonJavaRes : o) { if (nonJavaRes instanceof IJarEntryResource) { IJarEntryResource jarEntry = (IJarEntryResource) nonJavaRes; if (jarEntry.getName() != null && jarEntry.getName().equals(name)) { return new JarEntryStorage( root.getPath().append( jarEntry.getFullPath()), jarEntry); } } } } } } } catch (JavaModelException e) { e.printStackTrace(); } } return null; }
@Override public boolean test(IJarEntryResource jarEntryResource) { return jarEntryResource.isFile() && (StrutsXmlConstants.STRUTS_DEFAULT_FILE_NAME .equals(jarEntryResource.getName()) || StrutsXmlConstants.STRUTS_PLUGIN_FILE_NAME .equals(jarEntryResource.getName())); }
@Override public boolean test(IJarEntryResource jarEntryResource) { return jarEntryResource.isFile() && jarEntryResource.getName() != null && jarEntryResource.getName().endsWith( PROPERTIES_FILE_EXTENSION) && compare(bundleNames, jarEntryResource.getName()); }
/** * Returns the jar entry resources from the list of elements. * * @param elements the list of elements * @return the array of jar entry resources * @since 3.6 */ public static IJarEntryResource[] getJarEntryResources(List<?> elements) { List<IJarEntryResource> resources= new ArrayList<IJarEntryResource>(elements.size()); for (Iterator<?> iter= elements.iterator(); iter.hasNext();) { Object element= iter.next(); if (element instanceof IJarEntryResource) resources.add((IJarEntryResource) element); } return resources.toArray(new IJarEntryResource[resources.size()]); }
public ParentChecker(IResource[] resources, IJavaElement[] javaElements, IJarEntryResource[] jarResources) { Assert.isNotNull(resources); Assert.isNotNull(javaElements); Assert.isNotNull(jarResources); fResources= resources; fJavaElements= javaElements; fJarResources= jarResources; }