private void loadState() { IPath pluginStateLocation = CVSUIPlugin.getPlugin().getStateLocation().append(REPOSITORIES_VIEW_FILE); File file = pluginStateLocation.toFile(); if (file.exists()) { try { BufferedInputStream is = new BufferedInputStream(new FileInputStream(file)); try { readState(is); } finally { is.close(); } } catch (IOException e) { CVSUIPlugin.log(IStatus.ERROR, CVSUIMessages.RepositoryManager_ioException, e); } catch (TeamException e) { CVSUIPlugin.log(e); } } else { IPath oldPluginStateLocation = CVSUIPlugin.getPlugin().getStateLocation().append(STATE_FILE); file = oldPluginStateLocation.toFile(); if (file.exists()) { try { DataInputStream dis = new DataInputStream(new FileInputStream(file)); try { readOldState(dis); } finally { dis.close(); } saveState(); file.delete(); } catch (IOException e) { CVSUIPlugin.log(IStatus.ERROR, CVSUIMessages.RepositoryManager_ioException, e); } catch (TeamException e) { CVSUIPlugin.log(e); } } } }
/** * Returns the location of the JDT feature in the running host as a path in the local file system. * * @return path to JDT feature */ protected IPath getJdtFeatureLocation() { IPath path = new Path(TargetPlatform.getDefaultLocation()); path = path.append("features"); File dir = path.toFile(); assertTrue("Missing features directory", dir.exists() && !dir.isFile()); String[] files = dir.list(); String location = null; for (int i = 0; i < files.length; i++) { if (files[i].startsWith("org.eclipse.jdt_")) { location = path.append(files[i]).toOSString(); break; } } assertNotNull("Missing JDT feature", location); return new Path(location); }
private void loadCommentTemplates() { IPath pluginStateLocation = CVSUIPlugin.getPlugin().getStateLocation().append(COMMENT_TEMPLATES_FILE); File file = pluginStateLocation.toFile(); if (!file.exists()) return; try { BufferedInputStream is = new BufferedInputStream(new FileInputStream(file)); try { readCommentTemplates(is); } finally { is.close(); } } catch (IOException e) { CVSUIPlugin.log(IStatus.ERROR, CVSUIMessages.RepositoryManager_ioException, e); } catch (TeamException e) { CVSUIPlugin.log(e); } }
private ISourceContainer getArchiveSourceContainer(String location) throws JavaModelException { IWorkspaceRoot root = PDELaunchingPlugin.getWorkspace().getRoot(); IFile[] containers = root.findFilesForLocationURI(URIUtil.toURI(location)); for (int i = 0; i < containers.length; i++) { IJavaElement element = JavaCore.create(containers[i]); if (element instanceof IPackageFragmentRoot) { IPackageFragmentRoot archive = (IPackageFragmentRoot) element; IPath path = archive.getSourceAttachmentPath(); if (path == null || path.segmentCount() == 0) continue; IPath rootPath = archive.getSourceAttachmentRootPath(); boolean detectRootPath = rootPath != null && rootPath.segmentCount() > 0; IFile archiveFile = root.getFile(path); if (archiveFile.exists()) return new ArchiveSourceContainer(archiveFile, detectRootPath); File file = path.toFile(); if (file.exists()) return new ExternalArchiveSourceContainer(file.getAbsolutePath(), detectRootPath); } } return null; }
private boolean resourceExists(String location) { String bundleJar = null; IPath path = new Path(location); if ("platform:".equals(path.getDevice()) && path.segmentCount() > 2) { // $NON-NLS-1$ if ("plugin".equals(path.segment(0))) { // $NON-NLS-1$ String id = path.segment(1); IMonitorModelBase model = MonitorRegistry.findModel(id); if (model != null && model.isEnabled()) { path = path.setDevice(null).removeFirstSegments(2); String bundleLocation = model.getInstallLocation(); if (bundleLocation.endsWith(".jar")) { // $NON-NLS-1$ bundleJar = bundleLocation; } else { path = new Path(model.getInstallLocation()).append(path); } location = path.toString(); } } } else if (path.getDevice() == null && path.segmentCount() > 3 && "platform:".equals(path.segment(0))) { // $NON-NLS-1$ if ("plugin".equals(path.segment(1))) { // $NON-NLS-1$ String id = path.segment(2); IMonitorModelBase model = MonitorRegistry.findModel(id); if (model != null && model.isEnabled()) { path = path.removeFirstSegments(3); String bundleLocation = model.getInstallLocation(); if (bundleLocation.endsWith(".jar")) { // $NON-NLS-1$ bundleJar = bundleLocation; } else { path = new Path(model.getInstallLocation()).append(path); } location = path.toString(); } } } ArrayList paths = new ArrayList(); if (location.indexOf("$nl$") != -1) { // $NON-NLS-1$ StringTokenizer tokenizer = new StringTokenizer(TargetPlatform.getNL(), "_"); // $NON-NLS-1$ String language = tokenizer.hasMoreTokens() ? tokenizer.nextToken() : null; String country = tokenizer.hasMoreTokens() ? tokenizer.nextToken() : null; if (language != null && country != null) paths.add( location.replaceAll( "\\$nl\\$", "nl" + IPath.SEPARATOR + language + IPath.SEPARATOR + country)); //$NON-NLS-1$ //$NON-NLS-2$ if (language != null) paths.add( location.replaceAll( "\\$nl\\$", "nl" + IPath.SEPARATOR + language)); // $NON-NLS-1$ //$NON-NLS-2$ paths.add(location.replaceAll("\\$nl\\$", "")); // $NON-NLS-1$ //$NON-NLS-2$ } else { paths.add(location); } for (int i = 0; i < paths.size(); i++) { if (bundleJar == null) { IPath currPath = new Path(paths.get(i).toString()); if (currPath.isAbsolute() && currPath.toFile().exists()) return true; if (PDEProject.getBundleRoot(fFile.getProject()).findMember(currPath) != null) return true; if (fBuildModel != null && fBuildModel.getEntry("source." + paths.get(i)) != null) // $NON-NLS-1$ return true; } else { if (CoreUtility.jarContainsResource(new File(bundleJar), paths.get(i).toString(), false)) return true; } } return false; }