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)); 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 { if (input != null)
protected void addToStatus(CoreException ex) { IStatus status= ex.getStatus(); String message= ex.getLocalizedMessage(); if (message == null || message.length() < 1) { message= JarPackagerMessages.JarFileExportOperation_coreErrorDuringExport; status= new Status(status.getSeverity(), status.getPlugin(), status.getCode(), message, ex); } fStatus.add(status); }
/** * Log the given CoreException in a manner that will include the stacktrace of * the exception in the log. * @param e the exception */ public static void log(CoreException e) { log(e.getStatus().getSeverity(), e.getMessage(), e); }
public static CoreException wrap(IStatus status) { CoreException e = new CoreException(status); Throwable t = status.getException(); if (t != null) e.initCause(t); return e; }
@Override public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { try { project.build(buildType, monitor); } catch (CoreException e) { e.printStackTrace(); status = e.getStatus(); } return status; } };
/** * @param baseline the baseline that is disposed * @throws CoreException with the baseline disposed information */ protected void baselineDisposed(IApiBaseline baseline) throws CoreException { throw new CoreException(new Status(IStatus.ERROR, ApiPlugin.PLUGIN_ID, ApiPlugin.REPORT_BASELINE_IS_DISPOSED, NLS.bind(Messages.BundleApiComponent_baseline_disposed, baseline.getName()), null)); } }
if (!PREFS_FILE_EXTENSION.equals(path.getFileExtension())) return; String project = path.segment(0); String qualifier = path.removeFileExtension().lastSegment(); Preferences root = Platform.getPreferencesService().getRootNode(); Preferences node = root.node(ProjectScope.SCOPE).node(project).node(qualifier); String message = null; try { message = NLS.bind(Messages.preferences_syncException, node.absolutePath()); if (!(node instanceof ProjectPreferences)) return; preferencesChanged(file.getProject()); } catch (BackingStoreException e) { IStatus status = new Status(IStatus.ERROR, ResourcesPlugin.PI_RESOURCES, IStatus.ERROR, message, e); throw new CoreException(status);
public static IProject createInvisibleProjectIfNotExist(IPath workspaceRoot) throws OperationCanceledException, CoreException { String invisibleProjectName = ProjectUtils.getWorkspaceInvisibleProjectName(workspaceRoot); IProject invisibleProject = ResourcesPlugin.getWorkspace().getRoot().getProject(invisibleProjectName); if (!invisibleProject.exists()) { JavaLanguageServerPlugin.getProjectsManager().createJavaProject(invisibleProject, null, null, "bin", null); // Link the workspace root to the invisible project. IFolder workspaceLinkFolder = invisibleProject.getFolder(ProjectUtils.WORKSPACE_LINK); if (!workspaceLinkFolder.isLinked()) { try { JDTUtils.createFolders(workspaceLinkFolder.getParent(), null); workspaceLinkFolder.createLink(workspaceRoot.toFile().toURI(), IResource.REPLACE, null); } catch (CoreException e) { invisibleProject.delete(true, null); throw new CoreException(new Status(IStatus.ERROR, IConstants.PLUGIN_ID, Messages.format("Failed to create linked resource from ''{0}'' to the invisible project ''{1}''.", new String[] { workspaceRoot.toString(), invisibleProjectName }), e)); } } } return invisibleProject; }
private static void updateContainerClasspath(IJavaProject jproject, IPath containerPath, IClasspathEntry newEntry, String[] changedAttributes, IProgressMonitor monitor) throws CoreException { IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject); if (container == null) { throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IStatus.ERROR, "Container " + containerPath + " cannot be resolved", null)); //$NON-NLS-1$//$NON-NLS-2$ } IClasspathEntry[] entries= container.getClasspathEntries(); IClasspathEntry[] newEntries= new IClasspathEntry[entries.length]; for (int i= 0; i < entries.length; i++) { IClasspathEntry curr= entries[i]; if (curr.getEntryKind() == newEntry.getEntryKind() && curr.getPath().equals(newEntry.getPath())) { newEntries[i]= getUpdatedEntry(curr, newEntry, changedAttributes, jproject); } else { newEntries[i]= curr; } } requestContainerUpdate(jproject, container, newEntries); monitor.worked(1); }
public static File getLocalFile(IPath path) throws CoreException { File localFile = null; IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IResource file = root.findMember(path); if (file != null) { // internal resource URI location; if (file.getType() != IResource.FILE || (location = file.getLocationURI()) == null) { throw new CoreException(new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.bind(Messages.file_notFound, path.toString()), null)); } localFile = Util.toLocalFile(location, null/*no progress availaible*/); if (localFile == null) throw new CoreException(new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.bind(Messages.file_notFound, path.toString()), null)); } else { // external resource -> it is ok to use toFile() localFile= path.toFile(); } return localFile; }
private void validateFeatures() throws CoreException { IPath installPath = PDEPlugin.getWorkspace().getRoot().getLocation(); String lastSegment = installPath.lastSegment(); boolean badStructure = lastSegment == null; if (!badStructure) { IPath featuresPath = installPath.removeLastSegments(1).append("features"); //$NON-NLS-1$ badStructure = !lastSegment.equalsIgnoreCase("plugins") //$NON-NLS-1$ || !featuresPath.toFile().exists(); } if (badStructure) { throw new CoreException(LauncherUtils.createErrorStatus(PDEMessages.WorkbenchLauncherConfigurationDelegate_badFeatureSetup)); } // Ensure important files are present ensureProductFilesExist(getProductPath()); }
public static AngularProject getAngularProject(IProject project) throws CoreException { if (!hasAngularNature(project)) { throw new CoreException(new Status(IStatus.ERROR, AngularCorePlugin.PLUGIN_ID, "The project " + project.getName() + " is not an angular project.")); } IIDETernProject ternProject = TernCorePlugin.getTernProject(project); AngularProject angularProject = ternProject.getData(ANGULAR_PROJECT); if (angularProject == null) { angularProject = new AngularProject(ternProject); } return angularProject; }
/** * Logs a CoreException */ private void log(CoreException e) { //create a new status to wrap the exception if there is no exception in the status IStatus status = e.getStatus(); if (status.getException() == null) status = new Status(IStatus.ERROR, ResourcesPlugin.PI_RESOURCES, IResourceStatus.FAILED_WRITE_METADATA, "Internal error in history store", e); //$NON-NLS-1$ Policy.log(status); }
private IResourceVariant validateRemote(IResource resource, IResourceVariant remote) throws CoreException { boolean containerExpected = resource.getType() != IResource.FILE; if (remote.isContainer() && !containerExpected) { throw new CoreException(new Status(IStatus.ERROR, TeamPlugin.ID, IResourceStatus.RESOURCE_WRONG_TYPE, Messages.SubscriberResourceMappingContext_0 + resource.getFullPath().toString(), null)); } else if (!remote.isContainer() && containerExpected) { throw new CoreException(new Status(IStatus.ERROR, TeamPlugin.ID, IResourceStatus.RESOURCE_WRONG_TYPE, Messages.SubscriberResourceMappingContext_1 + resource.getFullPath().toString(), null)); } return remote; }
private IRuntimeClasspathEntry[] resolveOptional(IRuntimeClasspathEntry entry) throws CoreException { if (isOptional(entry.getClasspathEntry())) { return EMPTY_RESULT; } else { throw new CoreException(new Status(IStatus.ERROR, CorePlugin.PLUGIN_ID, String.format("The project: %s which is referenced by the classpath, does not exist", entry.getPath().lastSegment()))); } }
@Override public String getMemento() throws CoreException { try { URI uri = new URI(SCHEME, fFile.getFullPath().toPortableString(), null); return uri.toString(); } catch (URISyntaxException e) { throw new CoreException(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, Messages.WorkspaceFileTargetHandle_0, e)); } }
@Override public IContentType getContentType() throws CoreException { try { if (isDirty()) { try(Reader reader = new DocumentReader(getDocument())) { IContentDescription desc= Platform.getContentTypeManager().getDescriptionFor(reader, fFile.getName(), NO_PROPERTIES); if (desc != null && desc.getContentType() != null) return desc.getContentType(); } } IContentDescription desc= fFile.getContentDescription(); if (desc != null && desc.getContentType() != null) return desc.getContentType(); return null; } catch (IOException x) { throw new CoreException(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, NLSUtility.format(FileBuffersMessages.FileBuffer_error_queryContentDescription, fFile.getFullPath().toOSString()), x)); } }
protected Collection<IMarker> getRelatedProjectMarkers(IProject project) { if (!project.isAccessible()) { return Collections.emptyList(); } try { return Arrays.asList(project.findMarkers(MARKER_TYPE, true, IResource.DEPTH_ONE)); } catch (CoreException e) { ResourcesPlugin.getPlugin().getLog().log(new Status(IStatus.ERROR, ResourcesPlugin.PI_RESOURCES, e.getMessage(), e)); return Collections.emptyList(); } }
private static void ensureExists(IContainer container, IProgressMonitor monitor) throws CoreException { if (container.exists()) return; if (!(container instanceof IFolder)) throw new CoreException(new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, "not a folder: "+container)); //$NON-NLS-1$ IContainer parent= container.getParent(); if (parent instanceof IFolder) { ensureExists(parent, monitor); } ((IFolder) container).create(false, true, monitor); }