private static void addProject(Collection<IProject> projects, String location) { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); for(IContainer container : root.findContainersForLocationURI(new File(location).toURI())) { if(container instanceof IProject) { projects.add((IProject) container); break; } } }
public static IContainer getWorkspaceContainer(File file) { IWorkspaceRoot root = CoreUtil.getWorkspaceRoot(); IPath path = new Path(file.getAbsolutePath()); File f = path.toFile(); IContainer[] containers = root.findContainersForLocationURI(f.toURI()); if (containers.length == 0) { return null; } return containers[0]; }
protected IContainer getWorkspaceContainer() { IContainer[] containers = ResourcesPlugin.getWorkspace().getRoot().findContainersForLocationURI(getBuild().getWorkingDirectory().toURI()); if (containers.length < 1) { return null; } return containers[0]; }
private void refresh(IPath path) { IContainer[] containers= fRoot.findContainersForLocationURI(path.toFile().toURI()); try { for (int i= 0; i < containers.length; i++) { containers[i].refreshLocal(IResource.DEPTH_INFINITE, null); } } catch (CoreException e) { JavaPlugin.log(e); } }
private void refresh(IPath path) { IContainer[] containers= fRoot.findContainersForLocationURI(path.toFile().toURI()); try { for (int i= 0; i < containers.length; i++) { containers[i].refreshLocal(IResource.DEPTH_INFINITE, null); } } catch (CoreException e) { JavaPlugin.log(e); } }
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<>(); 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()]); }
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<>(); 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()]); }
protected IResource getResource(IPath path) { if (path != null) { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); // look for files or folders with the given path IFile[] files = root.findFilesForLocationURI(path.toFile().toURI()); if (files.length > 0) { return files[0]; } IContainer[] containers = root.findContainersForLocationURI(path.toFile().toURI()); if (containers.length > 0) { return containers[0]; } if (path.getDevice() == null) { // search relative to the workspace if no device present return root.findMember(path); } } return null; } public String getSourceAttachmentLocation() {
/** * Returns the selected workspace container,or <code>null</code> */ protected IContainer getContainer() { String path = getLocation(); if (path.length() > 0) { IResource res = null; IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); if (path.startsWith("${workspace_loc:")) { //$NON-NLS-1$ IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager(); try { path = manager.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 ResourcesPlugin.getWorkspace().getRoot(); }
private void updateWorkingSet(List<MavenProjectInfo> projects) { MavenProjectInfo rootProject = null; if(projects != null && projects.size() == 1) { rootProject = projects.get(0); } // check if working set name was preselected if(preselectedWorkingSetName != null) { updateWorkingSet(preselectedWorkingSetName, true); return; } // check if imported project(s) are nested inside existing workspace project String rootDirectory = rootDirectoryCombo != null ? rootDirectoryCombo.getText().trim() : null; if(rootDirectory != null && rootDirectory.length() > 0) { Set<IWorkingSet> workingSets = new HashSet<IWorkingSet>(); for(IContainer container : workspaceRoot.findContainersForLocationURI(new File(rootDirectory).toURI())) { workingSets.addAll(WorkingSets.getAssignedWorkingSets(container.getProject())); } if(workingSets.size() == 1) { updateWorkingSet(workingSets.iterator().next().getName(), true); return; } } // derive working set name from project name if(rootProject != null) { updateWorkingSet(getImportConfiguration().getProjectName(rootProject.getModel()), // !rootProject.getProjects().isEmpty()); } else { updateWorkingSet(null, false); } }
/** * Open an appropriate destination browser so that the user can specify a source * to import from */ protected void handleDestinationBrowseButtonPressed() { FileDialog dialog= new FileDialog(getContainer().getShell(), SWT.SAVE | SWT.SHEET); dialog.setFilterExtensions(ArchiveFileFilter.JAR_ZIP_FILTER_EXTENSIONS); String currentSourceString= getDestinationValue(); int lastSeparatorIndex= currentSourceString.lastIndexOf(File.separator); if (lastSeparatorIndex != -1) { dialog.setFilterPath(currentSourceString.substring(0, lastSeparatorIndex)); dialog.setFileName(currentSourceString.substring(lastSeparatorIndex + 1, currentSourceString.length())); } String selectedFileName= dialog.open(); if (selectedFileName != null) { IContainer[] findContainersForLocation= ResourcesPlugin.getWorkspace().getRoot().findContainersForLocationURI(URIUtil.toURI(new Path(selectedFileName).makeAbsolute())); if (findContainersForLocation.length > 0) { selectedFileName= findContainersForLocation[0].getFullPath().makeRelative().toString(); } fDestinationNamesCombo.setText(selectedFileName); } }
/** * Open an appropriate destination browser so that the user can specify a source * to import from */ protected void handleDestinationBrowseButtonPressed() { FileDialog dialog= new FileDialog(getContainer().getShell(), SWT.SAVE); dialog.setFilterExtensions(ArchiveFileFilter.JAR_ZIP_FILTER_EXTENSIONS); String currentSourceString= getDestinationValue(); int lastSeparatorIndex= currentSourceString.lastIndexOf(File.separator); if (lastSeparatorIndex != -1) { dialog.setFilterPath(currentSourceString.substring(0, lastSeparatorIndex)); dialog.setFileName(currentSourceString.substring(lastSeparatorIndex + 1, currentSourceString.length())); } String selectedFileName= dialog.open(); if (selectedFileName != null) { IContainer[] findContainersForLocation= ResourcesPlugin.getWorkspace().getRoot().findContainersForLocationURI(URIUtil.toURI(new Path(selectedFileName).makeAbsolute())); if (findContainersForLocation.length > 0) { selectedFileName= findContainersForLocation[0].getFullPath().makeRelative().toString(); } fDestinationNamesCombo.setText(selectedFileName); } }
path = manager.performStringSubstitution(path, false); IPath uriPath = new Path(path).makeAbsolute(); IContainer[] containers = root.findContainersForLocationURI(URIUtil.toURI(uriPath)); if (containers.length > 0) { res = containers[0];
/** * try to get leaf child project that contains this file, cause a file also be * contained in the parent project */ public static IProject getProject(File file) { IWorkspaceRoot ws = getWorkspaceRoot(); IResource[] containers = ws.findContainersForLocationURI(file.toURI()); IResource resource = null; for (IResource container : containers) { if (resource == null) { resource = container; } else { IPath containerPath = container.getProjectRelativePath(); IPath resourcePath = resource.getProjectRelativePath(); if (containerPath.segmentCount() < resourcePath.segmentCount()) { resource = container; } } } if (resource == null) { return null; } return resource.getProject(); }