Java Code Examples for org.eclipse.core.resources.IWorkspaceRoot#findContainersForLocationURI()

The following examples show how to use org.eclipse.core.resources.IWorkspaceRoot#findContainersForLocationURI() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourceUIValidatorExtension.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private void deleteMarkersRecursively(FileURI location) {
	if (location == null) {
		return;
	}

	IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
	IContainer[] containers = root.findContainersForLocationURI(URI.create(location.toString()));
	if (containers == null || containers.length == 0) {
		return;
	}

	try {
		for (IContainer container : containers) {
			if (container.isAccessible()) {
				container.deleteMarkers(null, true, IResource.DEPTH_INFINITE);
			}
		}
	} catch (CoreException e) {
		e.printStackTrace();
	}
}
 
Example 2
Source File: LocationSelector.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the selected workspace container,or <code>null</code>
 */
protected IContainer getContainer() {
    String path = getLocationTxt();
    if (path.length() > 0) {
        IResource res = null;
        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
        if (path.startsWith("${workspace_loc:")) { //$NON-NLS-1$
            try {
                path = VariableUtils.performStringSubstitution(path, false);
                IPath uriPath = new Path(path).makeAbsolute();
                IContainer[] containers = root.findContainersForLocationURI(URIUtil.toURI(uriPath));
                if (containers.length > 0) {
                    res = containers[0];
                }
            } catch (CoreException e) {
            }
        } else {
            res = root.findMember(path);
        }
        if (res instanceof IContainer) {
            return (IContainer) res;
        }
    }
    return (browseProject != null) ? browseProject : ResourcesPlugin.getWorkspace().getRoot();
}
 
Example 3
Source File: ResourceUtils.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
public static String getRelativePath(IProject project, String absolutePath) {
 	if (project == null) {
 		return null;
 	}
     URI uri = new File(absolutePath).toURI();
     IWorkspaceRoot root = getWorkspaceRoot();
     if (root == null) {
         return null;
     }
     IResource[] resources = root.findFilesForLocationURI(uri);
     if (resources.length == 0) {
         resources = root.findContainersForLocationURI(uri);
     }
     if (resources.length == 0) 
         return null;
     
     for (IResource res : resources) {
     	if (res.getProject() == null){ // Workspace root.
     		return null;
     	}
if (res.getProject().getName().equals(project.getName())) return getProjectRelativePath(res);
     }
     
     return null;
 }
 
Example 4
Source File: ResourceUtils.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
/**
   * Searches for existent resource with the given URI from the project
   * @param project
   * @param uri
   * @return Returns first {@link IResource} from the {@link IProject} with the given {@link URI}
   */
  public static IResource getResource(IProject project, URI uri) {
  	IWorkspaceRoot root = getWorkspaceRoot();
      if (root == null) {
          return null;
      }
      IResource[] fileResources = root.findFilesForLocationURI(uri);
      IResource[] folderResources = root.findContainersForLocationURI(uri);
      
      Iterable<IResource> iterable = Stream.concat(Arrays.stream(fileResources), Arrays.stream(folderResources))::iterator;
      for (IResource r : iterable) {
      	if (ObjectUtils.equals(r.getProject(), project) && r.exists() && !isInsideXdsRelativeFolderPathesToSkip(r)) return r;
}
      
      return null;
  }
 
Example 5
Source File: CheckGenModelUtil.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Given a base URI, figure out which {@link IFolder}, if any, it refers to.
 *
 * @param baseURI
 *          to find the folder(s) for; must not be {@code null}
 * @return an array of all folders mapping to that URI, or an empty array if none do.
 */
private static IContainer[] determineContainersToCheck(final URI baseURI) {
  Preconditions.checkNotNull(baseURI);
  IContainer[] result = {};
  if (baseURI.isPlatformResource() || baseURI.isFile()) {
    IWorkspaceRoot workspace = EcorePlugin.getWorkspaceRoot();
    if (workspace != null) {
      if (baseURI.isFile()) {
        result = workspace.findContainersForLocationURI(java.net.URI.create(baseURI.toString()));
      } else {
        // Must be a platform/resource URI
        IPath platformPath = new Path(baseURI.toPlatformString(true));
        IFolder folder = workspace.getFolder(platformPath);
        if (folder != null) {
          result = new IContainer[] {folder};
        }
      }
    }
  }
  return result;
}
 
Example 6
Source File: JavadocOptionsManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private IContainer[] getSourceContainers(Element element) {
	String sourcePaths= element.getAttribute(SOURCEPATH);

	if (sourcePaths.endsWith(File.pathSeparator)) {
		sourcePaths += '.';
	}
	IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();

	ArrayList<IContainer> res= new ArrayList<IContainer>();

	String[] strings= sourcePaths.split(File.pathSeparator);
	for (int i= 0; i < strings.length; i++) {
		IPath path= makeAbsolutePathFromRelative(new Path(strings[i].trim()));
		if (path != null) {
			IContainer[] containers= root.findContainersForLocationURI(URIUtil.toURI(path.makeAbsolute()));
			for (int k= 0; k < containers.length; k++) {
				res.add(containers[k]);
			}
		}

	}
	return res.toArray(new IContainer[res.size()]);
}
 
Example 7
Source File: CompilerWorkingDirectoryBlock.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the selected workspace container,or <code>null</code>
 */
public static IContainer getContainer(String path) {
    if (path.length() > 0) {
        IResource res = null;
        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
        if (path.startsWith("${workspace_loc:")) { //$NON-NLS-1$
            try {
                path = VariableUtils.performStringSubstitution(path, false);
                IPath uriPath = new Path(path).makeAbsolute();
                IContainer[] containers = root.findContainersForLocationURI(URIUtil.toURI(uriPath));
                if (containers.length > 0) {
                    res = containers[0];
                }
            } 
            catch (CoreException e) {
            }
        } 
        else {      
            res = root.findMember(path);
        }
        if (res instanceof IFile) {
            res = ((IFile)res).getParent();
        }
        if (res instanceof IContainer) {
            return (IContainer)res;
        }
    }
    return null;
}