public static IPath getResourceLocation(IResource resource) { if (resource == null) { return null; } IPath location = resource.getLocation(); if (location == null) { return resource.getRawLocation(); } return location; }
boolean isAbsolute(IResource res) { IPath path = res.getRawLocation(); return path != null && path.isAbsolute(); }
private static File getRawLocationFile(IPath simplePath) { IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(simplePath); File file = null; if (resource != null) { file = ResourcesPlugin.getWorkspace().getRoot().findMember( simplePath).getRawLocation().toFile(); } else { file = simplePath.toFile(); } return file; }
@Override public boolean select(Viewer viewer, Object parentElement, Object element) { if (element instanceof IResource) { final IResource resource = (IResource) element; if (resource.isHidden() || resource.isDerived() || resource.isPhantom()) { return false; } final IPath path2 = resource.getRawLocation(); if (path2 != null) { final File rawFile = path2.toFile(); return rawFile != null && !rawFile.isHidden(); } } return true; }
/** * @see org.eclipse.core.resources.IPathVariableChangeListener#pathVariableChanged(org.eclipse.core.resources.IPathVariableChangeEvent) */ @Override public void pathVariableChanged(IPathVariableChangeEvent event) { if (registeredMonitors.isEmpty()) return; String variableName = event.getVariableName(); Set<IResource> invalidResources = new HashSet<>(); for (Iterator<List<IResource>> i = registeredMonitors.values().iterator(); i.hasNext();) { for (Iterator<IResource> j = i.next().iterator(); j.hasNext();) { IResource resource = j.next(); IPath rawLocation = resource.getRawLocation(); if (rawLocation != null) { if (rawLocation.segmentCount() > 0 && variableName.equals(rawLocation.segment(0)) && !invalidResources.contains(resource)) { invalidResources.add(resource); } } } } if (!invalidResources.isEmpty()) { for (Iterator<IResource> i = invalidResources.iterator(); i.hasNext();) { IResource resource = i.next(); unmonitor(resource); monitor(resource); } } }
/** * @see org.eclipse.core.resources.IPathVariableChangeListener#pathVariableChanged(org.eclipse.core.resources.IPathVariableChangeEvent) */ @Override public void pathVariableChanged(IPathVariableChangeEvent event) { if (registeredMonitors.isEmpty()) return; String variableName = event.getVariableName(); Set<IResource> invalidResources = new HashSet<>(); for (Iterator<List<IResource>> i = registeredMonitors.values().iterator(); i.hasNext();) { for (Iterator<IResource> j = i.next().iterator(); j.hasNext();) { IResource resource = j.next(); IPath rawLocation = resource.getRawLocation(); if (rawLocation != null) { if (rawLocation.segmentCount() > 0 && variableName.equals(rawLocation.segment(0)) && !invalidResources.contains(resource)) { invalidResources.add(resource); } } } } if (!invalidResources.isEmpty()) { for (Iterator<IResource> i = invalidResources.iterator(); i.hasNext();) { IResource resource = i.next(); unmonitor(resource); monitor(resource); } } }
res.getProjectRelativePath() .toPortableString(), res.getRawLocation() .toOSString(), location.toOSString() }));
/** * Returns whether the given resource is a linked resource bound * to a path variable. * * @param resource resource to test * @return boolean <code>true</code> the given resource is a linked * resource bound to a path variable. <code>false</code> the given * resource is either not a linked resource or it is not using a * path variable. */ private boolean isPathVariable(IResource resource) { if (!resource.isLinked()) { return false; } IPath resolvedLocation = resource.getLocation(); if (resolvedLocation == null) { // missing path variable return true; } IPath rawLocation = resource.getRawLocation(); if (resolvedLocation.equals(rawLocation)) { return false; } return true; }
for (List<IResource> resources : registeredMonitors.values()) { for (IResource resource : resources) { IPath rawLocation = resource.getRawLocation(); if (rawLocation != null) { if (rawLocation.segmentCount() > 0 && variableName.equals(rawLocation.segment(0)) && !invalidResources.contains(resource)) {
IResource patchFile= resources[0]; if (patchFile != null && patchFile.getType() == IResource.FILE) { File actualFile= patchFile.getRawLocation().toFile(); gotPatch= actualFile.exists()&&actualFile.isFile()&&actualFile.length() > 0; if (!gotPatch)
IResource res = JARfiles[i]; if (res.getFileExtension().equals("jar")){ jarsCP = jarsCP + ";\""+ res.getRawLocation().toOSString()+"\"";
protected void openFile(Combo combo) { CategoryResourceListSelectionDialog dialog = new CategoryResourceListSelectionDialog(fPage.getShell(), false, PDEPlugin.getWorkspace().getRoot(), IResource.FILE); dialog.setInitialPattern("**"); //$NON-NLS-1$ dialog.create(); String path = combo.getText(); if (path.trim().length() == 0) path = PDEPlugin.getWorkspace().getRoot().getLocation().toString(); if (dialog.open() == Window.OK) { Object[] objects = dialog.getResult(); if (objects.length == 1) { String result = ((IResource) objects[0]).getRawLocation().toOSString(); if (result != null) { if (combo.indexOf(result) == -1) combo.add(result, 0); combo.setText(result); } } } } }
if (root.getResource() != null) jarPath = root.getResource().getRawLocation().toString();
return tu.getResource().getRawLocation().toOSString(); } else { String root = ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString();
@Override public String getColumnText(Object obj, int index) { if (obj instanceof IResource) { IResource resource = (IResource) obj; if (index == NAME_COLUMN) return resource.getName(); else if (index == PATH_COLUMN) return resource.getParent() .getProjectRelativePath().toPortableString(); else { IPath rawLocation = resource.getRawLocation(); if (rawLocation != null) return resource.getPathVariableManager().convertToUserEditableFormat(rawLocation.toOSString(), true); } } else if ((obj instanceof String) && index == 0) return (String) obj; return null; }
try { try { reader= new FileReader(patchTarget.getRawLocation().toFile()); if (isPatchFile(reader)) {
void editLocation() { IResource resource = getSelectedResource()[0]; IPath location = resource.getRawLocation(); PathVariableDialog dialog = new PathVariableDialog( fConvertAbsoluteButton.getShell(), PathVariableDialog.EDIT_LINK_LOCATION, resource.getType(), resource.getPathVariableManager(), null); if (location != null) dialog.setLinkLocation(location); dialog.setResource(resource); if (dialog.open() == Window.CANCEL) { return; } location = Path.fromOSString(dialog.getVariableValue()); try { setLinkLocation(resource, location); } catch (Exception e) { e.printStackTrace(); } reparent(new IResource[] { resource }); }
public URI transferVariableDefinition(IResource source, IResource dest, URI sourceURI) throws CoreException { IPath srcLoc = source.getLocation(); IPath srcRawLoc = source.getRawLocation(); if ((srcLoc != null) && (srcRawLoc != null) && !srcLoc.equals(srcRawLoc)) { // the location is variable relative if (!source.getProject().equals(dest.getProject())) { String variable = srcRawLoc.segment(0); variable = copyVariable(source, dest, variable); IPath newLocation = Path.fromPortableString(variable).append(srcRawLoc.removeFirstSegments(1)); sourceURI = toURI(newLocation); } else { sourceURI = toURI(srcRawLoc); } } return sourceURI; }
public URI transferVariableDefinition(IResource source, IResource dest, URI sourceURI) throws CoreException { IPath srcLoc = source.getLocation(); IPath srcRawLoc = source.getRawLocation(); if ((srcLoc != null) && (srcRawLoc != null) && !srcLoc.equals(srcRawLoc)) { // the location is variable relative if (!source.getProject().equals(dest.getProject())) { String variable = srcRawLoc.segment(0); variable = copyVariable(source, dest, variable); IPath newLocation = Path.fromPortableString(variable).append(srcRawLoc.removeFirstSegments(1)); sourceURI = toURI(newLocation); } else { sourceURI = toURI(srcRawLoc); } } return sourceURI; }
public URI transferVariableDefinition(IResource source, IResource dest, URI sourceURI) throws CoreException { IPath srcLoc = source.getLocation(); IPath srcRawLoc = source.getRawLocation(); if ((srcLoc != null) && (srcRawLoc != null) && !srcLoc.equals(srcRawLoc)) { // the location is variable relative if (!source.getProject().equals(dest.getProject())) { String variable = srcRawLoc.segment(0); variable = copyVariable(source, dest, variable); IPath newLocation = Path.fromPortableString(variable).append(srcRawLoc.removeFirstSegments(1)); sourceURI = toURI(newLocation); } else { sourceURI = toURI(srcRawLoc); } } return sourceURI; }