private String getVariableString(IPath path) { String name= path.makeRelative().toString(); IPath entryPath= JavaCore.getClasspathVariable(path.segment(0)); if (entryPath != null) { String appended= entryPath.append(path.removeFirstSegments(1)).toOSString(); return Messages.format(NewWizardMessages.CPListLabelProvider_twopart, new String[] { name, appended }); } else { return name; } }
public static File fromOSGiJarToOSGiInstallArea(String path) { IPath parentFolder = new Path(path).removeLastSegments(1); if ("plugins".equalsIgnoreCase(parentFolder.lastSegment())) //$NON-NLS-1$ return parentFolder.removeLastSegments(1).toFile(); return parentFolder.toFile(); }
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; }
public Properties getProductTranslation() { initValues(); URL transURL = null; if (customizationValue != null) transURL = FileLocator.find(customizationBundle, NL_DIR.append(customizationValue).removeFileExtension().addFileExtension(PROPERTIES_FILE_EXTENSION), null); if (transURL == null && InternalPlatform.DEBUG_PLUGIN_PREFERENCES) InternalPlatform.message("No preference translations found for product/file: " + customizationBundle.getSymbolicName() + '/' + customizationValue); //$NON-NLS-1$ return loadProperties(transURL); }
if (!path.toFile().exists()) { String msg = NLS.bind(PrefsMessages.preferences_fileNotFound, path.toOSString()); throw new CoreException(new Status(IStatus.ERROR, PrefsMessages.OWNER_NAME, 1, msg, null)); InputStream input = null; try { input = new BufferedInputStream(new FileInputStream(path.toFile())); service.importPreferences(input); } catch (FileNotFoundException e) { String msg = NLS.bind(PrefsMessages.preferences_fileNotFound, path.toOSString()); throw new CoreException(new Status(IStatus.ERROR, PrefsMessages.OWNER_NAME, 1, msg, e)); } finally {
/** * Private constructor to enforce singleton usage. */ private PerformanceStatsProcessor() { super("Performance Stats"); //$NON-NLS-1$ setSystem(true); setPriority(DECORATE); BundleContext context = PlatformActivator.getContext(); String filter = '(' + FrameworkLog.SERVICE_PERFORMANCE + '=' + Boolean.TRUE.toString() + ')'; Collection<ServiceReference<FrameworkLog>> references; FrameworkLog perfLog = null; try { references = context.getServiceReferences(FrameworkLog.class, filter); if (references != null && !references.isEmpty()) { //just take the first matching service perfLog = context.getService(references.iterator().next()); //make sure correct location is set IPath logLocation = Platform.getLogFileLocation(); logLocation = logLocation.removeLastSegments(1).append("performance.log"); //$NON-NLS-1$ perfLog.setFile(logLocation.toFile(), false); } } catch (Exception e) { IStatus error = new Status(IStatus.ERROR, Platform.PI_RUNTIME, 1, "Error loading performance log", e); //$NON-NLS-1$ InternalPlatform.getDefault().log(error); } //use the platform log if we couldn't create the performance log if (perfLog == null) perfLog = InternalPlatform.getDefault().getFrameworkLog(); log = perfLog; }
private IFile getFile(IStructuredModel model) { if (model != null) { String location = model.getBaseLocation(); if (location != null) { IPath path = new Path(location); if (!path.toFile().exists() && path.segmentCount() > 1) { return ResourcesPlugin.getWorkspace().getRoot().getFile(path); } } } return null; }
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 IFile getMapSource() { String name = path.lastSegment(); if (name.endsWith(SOURCE_MAP_EXT)) { name = name.substring(0, name.length() - SOURCE_MAP_EXT.length()); IPath newPath = path.removeLastSegments(1).append(name); IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(newPath); if (resource instanceof IFile) { return (IFile) resource; } } return null; }
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; }
/** * Determine if there is a directory with the project name in the workspace path. * * @param projectName the name of the project * @return true if there is a directory with the same name of the imported project */ private boolean isProjectInWorkspacePath(String projectName){ final IWorkspace workspace = ResourcesPlugin.getWorkspace(); IPath wsPath = workspace.getRoot().getLocation(); IPath localProjectPath = wsPath.append(projectName); return localProjectPath.toFile().exists(); }
@Override public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException { IResource resource = getResource(); if (resource == null || !resource.exists()) return RefactoringStatus.createFatalErrorStatus(MessageFormat.format(PDEUIMessages.RenameProjectChange_projectDoesNotExist, fResourcePath.toString())); if (ResourcesPlugin.getWorkspace().getRoot().getProject(fNewName).exists()) return RefactoringStatus.createFatalErrorStatus(MessageFormat.format(PDEUIMessages.RenameProjectChange_destinationExists, fNewName)); return new RefactoringStatus(); }
private IResource getResource() { IResource resource= ResourcesPlugin.getWorkspace().getRoot().findMember(fResourcePath); if (resource == null && fResourcePath.segmentCount() == 1) { resource= ResourcesPlugin.getWorkspace().getRoot().getProject(fResourcePath.segment(0)); } return resource; }
/** * The path is known to match a source/library folder entry. * @param path IPath * @return IPackageFragmentRoot */ public IPackageFragmentRoot getFolderPackageFragmentRoot(IPath path) { if (path.segmentCount() == 1) { // default project root return getPackageFragmentRoot(this.project); } return getPackageFragmentRoot(this.project.getWorkspace().getRoot().getFolder(path)); }
public static boolean isExternalFolderPath(IPath externalPath) { if (externalPath == null) return false; String firstSegment = externalPath.segment(0); if (firstSegment != null && ResourcesPlugin.getWorkspace().getRoot().getProject(firstSegment).exists()) return false; File externalFolder = externalPath.toFile(); if (externalFolder.isFile()) return false; if (externalPath.getFileExtension() != null/*likely a .jar, .zip, .rar or other file*/ && !externalFolder.exists()) return false; return true; }
static public IResource findWorkspaceResource(IPath path) { IWorkspaceRoot ws = ResourcesPlugin.getWorkspace().getRoot(); IPath wsPath = ws.getLocation(); if (wsPath.isPrefixOf(path)) { path = path.removeFirstSegments(wsPath.segmentCount()); path = path.setDevice(null); } return ws.findMember(path); }
private IResource internalGetResource(IPath fullPath, boolean container) { if (container) { if (fullPath.segmentCount() == 1) return ResourcesPlugin.getWorkspace().getRoot().getProject(fullPath.segment(0)); return ResourcesPlugin.getWorkspace().getRoot().getFolder(fullPath); } return ResourcesPlugin.getWorkspace().getRoot().getFile(fullPath); }
/** * @param path full absolute workspace path */ private static boolean isInternalContainerPath(IPath path) { IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); // in case this is full workspace path it should start with project segment int segmentCount = path.segmentCount(); if(segmentCount == 1 && wsRoot.getProject(path.segment(0)).exists()) { return true; } if(segmentCount > 1 && wsRoot.getFolder(path).exists()) { return true; } return false; }
private IResource createSourceResource(IResourceDelta delta) { IPath sourcePath = delta.getMovedFromPath(); IResource resource = delta.getResource(); IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); switch (resource.getType()) { case IResource.PROJECT : return wsRoot.getProject(sourcePath.segment(0)); case IResource.FOLDER : return wsRoot.getFolder(sourcePath); case IResource.FILE : return wsRoot.getFile(sourcePath); } return null; }
/** * Gets the description file (as workspace resource). * * @return a file which points to the description */ public IFile getDescriptionFile() { IPath path= getDescriptionLocation(); if (path.isValidPath(path.toString()) && path.segmentCount() >= 2) return JavaPlugin.getWorkspace().getRoot().getFile(path); else return null; }