protected IFile getProductFile(String path) { if (path == null || path.length() == 0) return null; IPath thePath = new Path(path); return thePath.segmentCount() < 2 ? null : PDEPlugin.getWorkspace().getRoot().getFile(new Path(path)); }
private IPath getProjectPath() { String projName = (String)getProperty(FACET_PROJECT_NAME); IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projName); if (project.exists()){ return project.getLocation(); } IDataModel projModel = (IDataModel)getProperty(MASTER_PROJECT_DM); if (projModel.getBooleanProperty(IProjectCreationPropertiesNew.USE_DEFAULT_LOCATION)){ return new Path(projModel.getStringProperty(IProjectCreationPropertiesNew.PROJECT_LOCATION)).append(projName); } return new Path(projModel.getStringProperty(IProjectCreationPropertiesNew.USER_DEFINED_LOCATION)).append(projName); }
private boolean isDirectChildOfWorkspaceRootFolder(File location) { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IPath rootLocationPath = workspace.getRoot().getLocation(); IPath locationPath = Path.fromOSString(location.getPath()); return rootLocationPath.equals(locationPath) || rootLocationPath.equals(locationPath.removeLastSegments(1)); }
/** * Returns the last segment of the given URI. For a hierarchical URL this returns * the last segment of the path. For opaque URIs this treats the scheme-specific * part as a path and returns the last segment. Returns <code>null</code> for * a hierarchical URI with an empty path, and for opaque URIs whose scheme-specific * part cannot be interpreted as a path. */ public static String lastSegment(URI location) { String path = location.getPath(); if (path == null) return new Path(location.getSchemeSpecificPart()).lastSegment(); return new Path(path).lastSegment(); }
static IFile getFile(IProject project, String qualifier) { return project.getFile(new Path(DEFAULT_PREFERENCES_DIRNAME).append(qualifier).addFileExtension(PREFS_FILE_EXTENSION)); }
public static IResource findResource(String file) { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IPath path = new Path(file); path.makeRelative(); while (path.segmentCount() > 1) { IResource resource = root.findMember(path); if (resource != null) { return resource; } path = path.removeFirstSegments(1); } return null; }
private static URI getRealLocation(String projectName, URI location) { if (location == null) { // inside workspace try { URI rootLocation= ResourcesPlugin.getWorkspace().getRoot().getLocationURI(); location= new URI(rootLocation.getScheme(), null, Path.fromPortableString(rootLocation.getPath()).append(projectName).toString(), null); } catch (URISyntaxException e) { Assert.isTrue(false, "Can't happen"); //$NON-NLS-1$ } } return location; }
/** * Returns if the specified location is an imported binary project. * <p> * We accept projects that are plug-ins even if not API enabled (i.e. with * API nature), as we still need them to make a complete API baseline * without resolution errors. * </p> * * @param location * @return true if the location is an imported binary project, false * otherwise * @throws CoreException */ private static boolean isBinaryProject(String location) throws CoreException { IPath path = new Path(location); IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(path.lastSegment()); return project != null && (!project.exists() || Util.isBinaryProject(project)); }
public String getLocalFile() { String file = reader.getFile(fileid); if (file.startsWith("file:/")) { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IFile iFile = workspaceRoot.getFileForLocation(new Path(file.substring(6))); file = iFile.getFullPath().toString(); } return file; }
private String getFullyQualifiedURL(String location) { if (location == null || location.trim().length() == 0) return null; IPath path = new Path(location); if (!path.isAbsolute()) return location; String projectName = path.segment(0); IProject project = PDEPlugin.getWorkspace().getRoot().getProject(projectName); if (project.exists()) { IPluginModelBase model = PluginRegistry.findModel(project); if (model != null) { String id = model.getPluginBase().getId(); return "platform:/plugin/" + id + "/" + path.removeFirstSegments(1); //$NON-NLS-1$ //$NON-NLS-2$ } } return location; }
/** * Returns the name of a {@link IProject} with a location that includes * targetDirectory. Returns null if there is no such {@link IProject}. * * @param targetDirectory * the path of the directory to check. * @return the overlapping project name or <code>null</code> */ private String getOverlappingProjectName(String targetDirectory){ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IPath testPath = new Path(targetDirectory); IContainer[] containers = root.findContainersForLocation(testPath); if(containers.length > 0){ return containers[0].getProject().getName(); } return null; }
private List<IProject> findProjectsToDelete(final List<RepositoryNode> selectedNodes) { final List<IProject> projectsToDelete = new ArrayList<IProject>(); for (RepositoryNode node : selectedNodes) { if (node.getRepository().isBare()) continue; File workDir = node.getRepository().getWorkTree(); final IPath wdPath = new Path(workDir.getAbsolutePath()); for (IProject prj : ResourcesPlugin.getWorkspace() .getRoot().getProjects()) { IPath location = prj.getLocation(); if (location != null && wdPath.isPrefixOf(location)) { projectsToDelete.add(prj); } } } return projectsToDelete; }
private String getExpandedPath(String path) { if (path == null || path.length() == 0) return null; IResource resource = PDECore.getWorkspace().getRoot().findMember(new Path(path)); if (resource != null) { IPath fullPath = resource.getLocation(); return fullPath == null ? null : fullPath.toOSString(); } return null; }
public IPath getAnyOpenWorkspaceLocation(IWorkspaceRoot root) { int numMappings = WORKSPACE_MAPPINGS.size(getNd(), this.address); for (int mapping = 0; mapping < numMappings; mapping++) { NdWorkspaceLocation nextMapping = WORKSPACE_MAPPINGS.get(getNd(), this.address, mapping); IPath nextPath = new Path(nextMapping.getPath().getString()); if (nextPath.isEmpty()) { continue; } IProject project = root.getProject(nextPath.segment(0)); if (project.isOpen()) { return nextPath; } } return Path.EMPTY; }
private static IResource getImageResource(String value, String definingPluginId) { if (value == null) return null; IPath path = new Path(value); if (path.isEmpty()) return null; if (!path.isAbsolute()) { path = getRootPath(path, definingPluginId); } IWorkspaceRoot root = PDEPlugin.getWorkspace().getRoot(); return root.findMember(path); }
private CMDocument buildCMDocumentFromDirectory(File file) { IFile[] foundFilesForLocation = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(new Path(file.getPath())); for (int i = 0; i < foundFilesForLocation.length; i++) { if (foundFilesForLocation[i].isAccessible() && foundFilesForLocation[i].getType() == IResource.FOLDER) { return buildCMDocumentFromFolder(foundFilesForLocation[i].getFullPath()); } } return null; }
protected static IPath createPath(IProject p, String defaultSourceName) { IPath path = new Path(p.getName()); path = path.append(defaultSourceName); path = path.makeAbsolute(); return path; }
private void setDefaultValues(File dir, String buildFilename) { try { IContainer container = PDEPlugin.getWorkspace().getRoot().getContainerForLocation(new Path(dir.toString())); if (container != null && container.exists()) { IProject project = container.getProject(); if (project != null) { project.refreshLocal(IResource.DEPTH_INFINITE, null); IFile file = container.getFile(new Path(buildFilename)); if (file.exists()) BaseBuildAction.setDefaultValues(file); } } } catch (CoreException e) { } }
private static IProject getProject(IFeatureModel featureModel) { final java.nio.file.Path file = featureModel.getSourceFile(); final IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IPath location = Path.fromOSString(file.toAbsolutePath().toString()); final IFile iFile = workspace.getRoot().getFileForLocation(location); try { return iFile.getProject(); } catch (final NullPointerException e) { Logger.logWarning(location.toOSString()); throw e; } }