@Override public Status validate() { final Value<String> packagePath = context().find(ServiceBuilder.class).getPackagePath(); String packPathVal = packagePath.getContent(); if (packPathVal == null) { return Status.createErrorStatus(Msgs.packagePathNotEmpty); } // Use standard java conventions to validate the package name IStatus javaStatus = JavaConventions.validatePackageName( packPathVal, CompilerOptions.VERSION_1_5, CompilerOptions.VERSION_1_5); if (javaStatus.getSeverity() == IStatus.ERROR) { return Status.createErrorStatus( J2EECommonMessages.ERR_JAVA_PACAKGE_NAME_INVALID + javaStatus.getMessage()); } if (javaStatus.getSeverity() == IStatus.WARNING) { return Status.createWarningStatus( J2EECommonMessages.ERR_JAVA_PACKAGE_NAME_WARNING + javaStatus.getMessage()); } return Status.createOkStatus(); }
/** * Checks if there was an error. * * @param caller The caller or <code>null</code>. * @param status The status. <code>null</code> if status should not be checked. * @param callback The callback to call on cancel or error. * @return <code>false</code> if everything is OK. */ public static final boolean isError(Object caller, IStatus status, ICallback callback) { if (status == null) status = Status.OK_STATUS; if (!status.isOK() && status.getSeverity() != IStatus.CANCEL) { if (status.getSeverity() == IStatus.ERROR) { Throwable e = status.getException(); try { throw e; } catch (Throwable thrown) { e = thrown; } CoreBundleActivator.getTraceHandler() .trace( status.getMessage(), 1, ITraceIds.TRACE_CALLBACKS, status.getSeverity(), caller != null ? caller.getClass() : ProgressHelper.class); status = new Status(IStatus.ERROR, status.getPlugin(), status.getCode(), status.getMessage(), e); } if (callback != null) { if (caller instanceof ICallback) { Callback.copyProperties((ICallback) caller, callback); } callback.done(caller, status); } return true; } return false; }
/* (non-Javadoc) * @see org.eclipse.jdt.internal.ui.text.correction.CUCorrectionProposal#getAdditionalProposalInfo() */ public Object getAdditionalProposalInfo(IProgressMonitor monitor) { StringBuffer result = new StringBuffer(); IStatus status = getFixStatus(); if (status != null && !status.isOK()) { result.append("<b>"); // $NON-NLS-1$ if (status.getSeverity() == IStatus.WARNING) { result.append(CorrectionMessages.FixCorrectionProposal_WarningAdditionalProposalInfo); } else if (status.getSeverity() == IStatus.ERROR) { result.append(CorrectionMessages.FixCorrectionProposal_ErrorAdditionalProposalInfo); } result.append("</b>"); // $NON-NLS-1$ result.append(status.getMessage()); result.append("<br><br>"); // $NON-NLS-1$ } String info = fFix.getAdditionalProposalInfo(); if (info != null) { result.append(info); } else { result.append(super.getAdditionalProposalInfo(monitor)); } return result.toString(); }
/** * Compares two instances of <code>IStatus</code>. The more severe is returned: An error is more * severe than a warning, and a warning is more severe than ok. If the two stati have the same * severity, the second is returned. * * @param s1 first status * @param s2 second status * @return the more severe status */ public static IStatus getMoreSevere(IStatus s1, IStatus s2) { if (s1.getSeverity() > s2.getSeverity()) { return s1; } else { return s2; } }
/** Implements logging of an IStatus object, recursively as needed. */ private static void doLog(IStatus status) { if (status.isOK()) return; Throwable t = status.getException(); if (status.getSeverity() == IStatus.ERROR) { logger.error(status.getMessage(), t); } else if (status.getSeverity() == IStatus.WARNING) { logger.warn(status.getMessage(), t); } else { logger.info(status.getMessage(), t); } int stackCode = t instanceof CoreException ? 1 : 0; // ensure a substatus inside a CoreException is properly logged if (stackCode == 1) { IStatus coreStatus = ((CoreException) t).getStatus(); if (coreStatus != null) { doLog(coreStatus); } } if (status.isMultiStatus()) { IStatus[] children = status.getChildren(); for (int i = 0; i < children.length; i++) { doLog(children[i]); } } }
public void doValidate() { if (!createdFields) { page.setPageComplete(false); return; } List<IStatus> list = new ArrayList<IStatus>(); validate(list); for (IStatus status : list) { if (status.getSeverity() == IStatus.ERROR) { page.setPageComplete(false); page.setErrorMessage(status.getMessage()); return; } } page.setErrorMessage(null); for (IStatus status : list) { if (status.getSeverity() == IStatus.WARNING) { page.setPageComplete(true); page.setMessage(status.getMessage(), IMessageProvider.WARNING); return; } } page.setMessage(null, IMessageProvider.WARNING); page.setPageComplete(true); }
/** * Install selected features in to developer studio. Note: call {@link * #setSelectedFeaturesToInstall(List) setSelectedFeaturesToInstall} first. * * @param monitor */ public void installSelectedFeatures(IProgressMonitor monitor) { SubMonitor progress = SubMonitor.convert(monitor, Messages.UpdateManager_32, 2); URI[] repos = new URI[] {getDevStudioReleaseSite()}; session = new ProvisioningSession(p2Agent); installOperation = new InstallOperation(session, selectedFeatures); installOperation.getProvisioningContext().setArtifactRepositories(repos); installOperation.getProvisioningContext().setMetadataRepositories(repos); IStatus status = installOperation.resolveModal(progress.newChild(1)); if (status.getSeverity() == IStatus.CANCEL || progress.isCanceled()) { throw new OperationCanceledException(); } else if (status.getSeverity() == IStatus.ERROR) { String message = status.getChildren()[0].getMessage(); log.error(Messages.UpdateManager_33 + message); } else { ProvisioningJob provisioningJob = installOperation.getProvisioningJob(progress.newChild(1)); if (provisioningJob != null) { provisioningJob.addJobChangeListener( new JobChangeAdapter() { @Override public void done(IJobChangeEvent arg0) { Display.getDefault() .syncExec( new Runnable() { @Override public void run() { boolean restart = MessageDialog.openQuestion( Display.getDefault().getActiveShell(), Messages.UpdateManager_34, Messages.UpdateManager_35 + Messages.UpdateManager_36); if (restart) { PlatformUI.getWorkbench().restart(); } } }); } }); provisioningJob.schedule(); Display.getDefault() .syncExec( new Runnable() { @Override public void run() { try { PlatformUI.getWorkbench() .getActiveWorkbenchWindow() .getActivePage() .showView(IProgressConstants.PROGRESS_VIEW_ID); } catch (PartInitException e) { log.error(e); } } }); } else { log.error(Messages.UpdateManager_37); } } }
@Override public IStatus execute( final String id, final IConsoleService service, final Map<String, Object> data, final IProgressMonitor monitor) { final IStatus status = ToolCommandHandlerUtil.getCheckedData(data, REPORT_STATUS_DATA_KEY, IStatus.class, false); if (status != null) { final String br = service.getWorkspaceData().getLineSeparator(); final StringBuilder msg = new StringBuilder(br); switch (status.getSeverity()) { case IStatus.ERROR: msg.append("[ERROR] "); break; case IStatus.WARNING: msg.append("[WARNING] "); break; case IStatus.INFO: msg.append("[INFO] "); break; } msg.append(status.getMessage()); msg.append(br); boolean details = (status.getException() != null); final IStatus[] children = status.getChildren(); for (final IStatus subStatus : children) { msg.append(" "); // $NON-NLS-1$ msg.append(subStatus.getMessage()); msg.append(br); details |= (subStatus.getChildren().length > 0 || subStatus.getException() != null); } if (details) { msg.append(" (details available in Eclipse error log)"); msg.append(br); } try { final ToolStreamMonitor infoStream = service.getController().getStreams().getInfoStreamMonitor(); infoStream.append(msg.toString(), service.getController().getCurrentSubmitType(), 0); } catch (final Exception e) { } switch (status.getSeverity()) { case IStatus.ERROR: StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.SHOW); break; case IStatus.WARNING: StatusManager.getManager().handle(status, StatusManager.LOG); break; default: break; } } return Status.OK_STATUS; }
/** * Finds available WSO2 features in current profile and search for updates to them in WSO2 p2 * repository for updates. * * @param monitor * @throws Exception */ public void checkForAvailableUpdates(IProgressMonitor monitor) throws Exception { if (monitor == null) { monitor = new NullProgressMonitor(); } SubMonitor progress = SubMonitor.convert(monitor, Messages.UpdateManager_18, 6); // get all available IUs in update repository IMetadataRepository metadataRepo = metadataRepoManager.loadRepository(getDevStudioUpdateSite(), progress.newChild(1)); IQuery<IInstallableUnit> allIUQuery = QueryUtil.createIUAnyQuery(); IQueryResult<IInstallableUnit> allIUQueryResult = metadataRepo.query(allIUQuery, progress.newChild(1)); // read artifact repository for updates IArtifactRepository artifactRepo = artifactRepoManager.loadRepository(getDevStudioUpdateSite(), progress.newChild(1)); // read meta-data of all available features Map<String, EnhancedFeature> allFeaturesInUpdateRepo = loadWSO2FeaturesInRepo(artifactRepo, allIUQueryResult, progress.newChild(1)); // get all installed wso2 features Collection<IInstallableUnit> installedWSO2Features = getInstalledWSO2Features(progress.newChild(1)); installedWSO2FeaturesMap = new HashMap<String, IInstallableUnit>(); for (IInstallableUnit iInstallableUnit : installedWSO2Features) { installedWSO2FeaturesMap.put(iInstallableUnit.getId(), iInstallableUnit); } if (progress.isCanceled()) { throw new OperationCanceledException(); } URI[] repos = new URI[] {getDevStudioUpdateSite()}; updateOperation = new UpdateOperation(session, installedWSO2Features); updateOperation.getProvisioningContext().setArtifactRepositories(repos); updateOperation.getProvisioningContext().setMetadataRepositories(repos); // resolve update operation IStatus status = updateOperation.resolveModal(progress.newChild(1)); // user cancelled the job while resolving if (status.getSeverity() == IStatus.CANCEL || progress.isCanceled()) { throw new OperationCanceledException(); } // there is nothing to update if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) { featuresWithPossibleUpdates = new HashMap<String, EnhancedFeature>(); log.info(Messages.UpdateManager_19); } else if (status.getSeverity() == IStatus.ERROR) { // resolution errors // something wrong with the updates log.info(Messages.UpdateManager_20); } else { // good to proceed installing updates setPossibleUpdates(updateOperation.getPossibleUpdates(), allFeaturesInUpdateRepo); } }
private static int collectStatus(OutputStream stream, ArrayList<IStatus> list) { IStatus status = getStatus(stream); list.add(status); OutputStream destination = getDestination(stream); if (destination == null || !(destination instanceof IStateful)) return status.getSeverity(); int result = collectStatus(destination, list); // TODO greater than test here is a little brittle but it is very unlikely that we will add // a new status severity. return status.getSeverity() > result ? status.getSeverity() : result; }
/** * Utility method to determine the maximum severity of the list of statuses * * @param cmdType * @return maximum severity value */ public int getMaxSeverity() { if (getStatusList() == null || getStatusList().isEmpty()) return IStatus.OK; int resultSeverity = IStatus.OK; for (IStatus status : getStatusList()) { if (status.getSeverity() > resultSeverity) resultSeverity = status.getSeverity(); } return resultSeverity; }
private void validatePage() { IStatus[] all = standardOptions.validate(); IStatus[] all2 = perModuleOptions.validate(); // show highest status error IStatus highest = null; for (int i = 0; i < all.length; i++) { if (highest == null || all[i].getSeverity() > highest.getSeverity()) highest = all[i]; } for (int i = 0; i < all2.length; i++) { if (highest == null || all2[i].getSeverity() > highest.getSeverity()) highest = all2[i]; } setStatus(highest); }
/** * Finds the most severe status from a array of stati. An error is more severe than a warning, and * a warning is more severe than ok. * * @param status an array of stati * @return the most severe status */ public static IStatus getMostSevere(IStatus[] status) { IStatus max = null; for (int i = 0; i < status.length; i++) { IStatus curr = status[i]; if (curr.matches(IStatus.ERROR)) { return curr; } if (max == null || curr.getSeverity() > max.getSeverity()) { max = curr; } } return max; }
private static int collectErrorStatus(OutputStream stream, ArrayList<IStatus> list) { IStatus status = getStatus(stream); if (!status.isOK()) list.add(status); if (status.matches(IStatus.ERROR)) // Errors past this should be bogus as they rely on output from this step return status.getSeverity(); OutputStream destination = getDestination(stream); if (destination == null || !(destination instanceof IStateful)) return status.getSeverity(); int result = collectErrorStatus(destination, list); // TODO greater than test here is a little brittle but it is very unlikely that we will add // a new status severity. return status.getSeverity() > result ? status.getSeverity() : result; }
private boolean statusContainsError(IStatus validationStatus) { if (validationStatus != null) { if (validationStatus.getChildren().length > 0) { for (IStatus s : validationStatus.getChildren()) { if (s.getSeverity() == IStatus.WARNING || s.getSeverity() == IStatus.ERROR) { return true; } } } else { return validationStatus.getSeverity() == IStatus.WARNING || validationStatus.getSeverity() == IStatus.ERROR; } } return false; }
public Map<String, IStatus> validate(Object value, Object context) { if (!(context instanceof Object[])) { throw new IllegalArgumentException( "Context parameter should be instance of Object[]"); //$NON-NLS-1$ } Object[] contextArray = ((Object[]) context); IProject project = (IProject) contextArray[1]; IJavaProject jProject = JavaCore.create(project); IStatus status = JavaConventions.validateJavaTypeName( value.toString(), getCompilerSourceLevel(jProject), getCompilerComplianceLevel(jProject)); if (((IStatus.ERROR | IStatus.WARNING) & status.getSeverity()) != 0) { return createErrormessage( new Status( IStatus.ERROR, SeamCorePlugin.PLUGIN_ID, SeamCoreMessages.VALIDATOR_FACTORY_LOCAL_INTERFACE_NAME_IS_NOT_VALID + status.getMessage())); } return NO_ERRORS; }
protected IStatus validateServer(IProgressMonitor monitor) { String host = serverWC.getHost(); if (CoreUtil.isNullOrEmpty(host)) { return LiferayServerUI.createErrorStatus(Msgs.specifyHostname); } String username = remoteServerWC.getUsername(); if (CoreUtil.isNullOrEmpty(username)) { return LiferayServerUI.createErrorStatus(Msgs.specifyUsernamePassword); } String port = remoteServerWC.getHTTPPort(); if (CoreUtil.isNullOrEmpty(port)) { return LiferayServerUI.createErrorStatus(Msgs.specifyHTTPPort); } IStatus status = remoteServerWC.validate(monitor); if (status != null && status.getSeverity() == IStatus.ERROR) { fragment.lastServerStatus = new Status( IStatus.WARNING, status.getPlugin(), status.getMessage(), status.getException()); } else { fragment.lastServerStatus = status; } return status; }
// Code copied from PlatformLogWriter.getLog(). Why is logging an IStatus so // hard? FrameworkLogEntry createLogEntry(IStatus status) { Throwable t = status.getException(); ArrayList childlist = new ArrayList(); int stackCode = t instanceof CoreException ? 1 : 0; // ensure a substatus inside a CoreException is properly logged if (stackCode == 1) { IStatus coreStatus = ((CoreException) t).getStatus(); if (coreStatus != null) { childlist.add(createLogEntry(coreStatus)); } } if (status.isMultiStatus()) { IStatus[] children = status.getChildren(); for (int i = 0; i < children.length; i++) { childlist.add(createLogEntry(children[i])); } } FrameworkLogEntry[] children = (FrameworkLogEntry[]) (childlist.size() == 0 ? null : childlist.toArray(new FrameworkLogEntry[childlist.size()])); return new FrameworkLogEntry( status.getPlugin(), status.getSeverity(), status.getCode(), status.getMessage(), stackCode, t, children); }
void doAction() { JobTreeElement[] jobTreeElements = FinishedJobs.getInstance().getKeptElements(); // search from end (youngest) for (int i = jobTreeElements.length - 1; i >= 0; i--) { if (jobTreeElements[i] instanceof JobInfo) { JobInfo ji = (JobInfo) jobTreeElements[i]; Job job = ji.getJob(); if (job != null) { IStatus status = job.getResult(); if (status != null && status.getSeverity() == IStatus.ERROR) { StatusAdapter statusAdapter = StatusAdapterHelper.getInstance().getStatusAdapter(ji); if (statusAdapter == null) statusAdapter = new StatusAdapter(status); StatusManager.getManager().handle(statusAdapter, StatusManager.SHOW); removeTopElement(ji); } execute(ji, job); } } } progressRegion.processDoubleClick(); refresh(); }
private void swallowError(IPath file, Throwable e) throws CoreException { IStatus s; /* * If the thrown CoreException is for a STATUS_PDOM_TOO_LARGE, we don't want to * swallow this one. */ if (e instanceof CoreException) { s = ((CoreException) e).getStatus(); if (s.getCode() == CCorePlugin.STATUS_PDOM_TOO_LARGE) { if (CCorePlugin.PLUGIN_ID.equals(s.getPlugin())) throw (CoreException) e; } // mask errors in order to avoid dialog from platform Throwable exception = s.getException(); if (exception != null) { Throwable masked = getMaskedException(exception); if (masked != exception) { e = masked; exception = null; } } if (exception == null) { s = new Status(s.getSeverity(), s.getPlugin(), s.getCode(), s.getMessage(), e); } } else { e = getMaskedException(e); s = createStatus(getMessage(MessageKind.errorWhileParsing, file), e); } logError(s); if (++fStatistics.fErrorCount > MAX_ERRORS) { throw new CoreException(createStatus(getMessage(MessageKind.tooManyIndexProblems))); } }
/* (non-Javadoc) * @see org.eclipse.core.databinding.validation.IValidator#validate(java.lang.Object) */ @Override public IStatus validate(Object value) { IStatus validate = validator.validate(value); int severity = validate.getSeverity(); if (severity > IStatus.OK) { controlDecoration.show(); if (severity >= IStatus.ERROR) { controlDecoration.setImage(error); } else if (severity == IStatus.WARNING) { controlDecoration.setImage(warn); } else if (severity == IStatus.INFO) { controlDecoration.setImage(info); } if (updateMessage) { controlDecoration.setDescriptionText(validate.getMessage()); } } else { controlDecoration.hide(); } if (onlyChangeDecoration) { return Status.OK_STATUS; } else { return validate; } }
public void helpIsValidJdbcDriver( final JdbcDriver driver, final int expectedCode, final int expectedSeverity) { final IStatus status = mgr.isValid(driver); assertNotNull(status); assertEquals(expectedCode, status.getCode()); assertEquals(expectedSeverity, status.getSeverity()); }
public Map<String, IStatus> validate(Object value, Object context) { if (!(context instanceof Object[])) { throw new IllegalArgumentException( "Context parameter should be instance of Object[]"); //$NON-NLS-1$ } Object[] contextArray = ((Object[]) context); String targetName = contextArray[0].toString(); IProject project = (IProject) contextArray[1]; IJavaProject jProject = JavaCore.create(project); IStatus status = JavaConventions.validateMethodName( value.toString(), getCompilerSourceLevel(jProject), getCompilerComplianceLevel(jProject)); if (status.getSeverity() == IStatus.ERROR) { return createErrormessage( new Status( IStatus.ERROR, SeamCorePlugin.PLUGIN_ID, NLS.bind(SeamCoreMessages.VALIDATOR_FACTORY_NAME_IS_NOT_VALID, targetName))); } return NO_ERRORS; }
public void helpIsValidJdbcSource( final JdbcSource source, final int expectedCode, final int expectedSeverity) { final IStatus status = mgr.isValid(source); assertNotNull(status); assertEquals(expectedCode, status.getCode()); assertEquals(expectedSeverity, status.getSeverity()); }
private IProject createProject(final GridProjectProperties props, final IProgressMonitor monitor) throws CoreException { monitor.subTask(Messages.getString("GridProjectCreationOperation.init_task")); // $NON-NLS-1$ String projectName = props.getProjectName(); IPath projectPath = props.getProjectLocation(); IProject[] referencesProjects = props.getReferencesProjects(); IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject project = workspaceRoot.getProject(projectName); IStatus status = ResourcesPlugin.getWorkspace().validateProjectLocation(project, projectPath); if (status.getSeverity() != IStatus.OK) { throw new CoreException(status); } IProjectDescription desc = project.getWorkspace().newProjectDescription(projectName); desc.setLocation(projectPath); if (referencesProjects != null) { desc.setReferencedProjects(referencesProjects); } project.create(desc, new SubProgressMonitor(monitor, 50)); project.open(new SubProgressMonitor(monitor, 50)); createProjectStructure(project, props); setProjectProperties(project, props); if (monitor.isCanceled()) { throw new OperationCanceledException(); } return project; }
/* * (non-Javadoc) * * @see org.eclipse.papyrus.commands.ICreationCommand#createDiagram(org.eclipse.emf.ecore.resource.Resource, org.eclipse.emf.ecore.EObject, * org.eclipse.emf.ecore.EObject, org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype, java.lang.String) */ @Override public final Diagram createDiagram( ModelSet modelSet, EObject owner, EObject element, ViewPrototype prototype, String name) { ICommand createCmd = getCreateDiagramCommand(modelSet, owner, element, prototype, name); TransactionalEditingDomain dom = modelSet.getTransactionalEditingDomain(); CompositeCommand cmd = new CompositeCommand("Create diagram"); cmd.add(createCmd); cmd.add(new OpenDiagramCommand(dom, createCmd)); try { IStatus status = CheckedOperationHistory.getInstance().execute(cmd, new NullProgressMonitor(), null); if (status.isOK()) { CommandResult result = cmd.getCommandResult(); Object returnValue = result.getReturnValue(); // CompositeCommands should always return a collection if (returnValue instanceof Collection<?>) { for (Object returnElement : (Collection<?>) returnValue) { if (returnElement instanceof Diagram) { return (Diagram) returnElement; } } } } else if (status.getSeverity() != IStatus.CANCEL) { StatusManager.getManager().handle(status, StatusManager.SHOW); } } catch (ExecutionException ex) { Activator.log.error(ex); } return null; }
public void testEditOutputFolder01SetOutputFolderForSourceFolder() throws Exception { fJavaProject = createProject(DEFAULT_OUTPUT_FOLDER_NAME); IPackageFragmentRoot src = JavaProjectHelper.addSourceContainer(fJavaProject, "src"); IPath projectPath = fJavaProject.getProject().getFullPath(); IPath outputPath = projectPath.append("srcbin"); CPJavaProject cpProject = CPJavaProject.createFromExisting(fJavaProject); CPListElement element = cpProject.getCPElement( CPListElement.createFromExisting(src.getRawClasspathEntry(), fJavaProject)); IStatus status = ClasspathModifier.checkSetOutputLocationPrecondition(element, outputPath, false, cpProject); assertTrue(status.getMessage(), status.getSeverity() != IStatus.ERROR); BuildpathDelta delta = ClasspathModifier.setOutputLocation(element, outputPath, false, cpProject); assertDeltaResources(delta, new IPath[] {outputPath}, new IPath[0], new IPath[0], new IPath[0]); assertDeltaDefaultOutputFolder(delta, fJavaProject.getOutputLocation()); assertDeltaAddedEntries(delta, new IPath[0]); assertDeltaRemovedEntries(delta, new IPath[0]); ClasspathModifier.commitClassPath(cpProject, null); IClasspathEntry[] classpathEntries = fJavaProject.getRawClasspath(); assertNumberOfEntries(classpathEntries, 2); IClasspathEntry entry = classpathEntries[1]; assertTrue(src.getRawClasspathEntry() == entry); IPath location = entry.getOutputLocation(); assertTrue( "Output path is " + location + " expected was " + outputPath, outputPath.equals(location)); }
/** * Applies the status to the status line of a dialog page. * * @param page the dialog page * @param status the status to apply */ public static void applyToStatusLine(DialogPage page, IStatus status) { if (status == null) { page.setMessage(null, IMessageProvider.NONE); page.setErrorMessage(null); return; } String message = status.getMessage(); if (message != null && message.length() == 0) { message = null; } switch (status.getSeverity()) { case IStatus.OK: page.setMessage(message, IMessageProvider.NONE); page.setErrorMessage(null); break; case IStatus.WARNING: page.setMessage(message, IMessageProvider.WARNING); page.setErrorMessage(null); break; case IStatus.INFO: page.setMessage(message, IMessageProvider.INFORMATION); page.setErrorMessage(null); break; default: page.setMessage(null); page.setErrorMessage(message); break; } }
// private helper to appendProblems() that can be called recursively private void appendProblemsRecursive(IStatus[] statuses, StringBuffer output) { for (IStatus next : statuses) { if (!next.isOK()) { final String messagePattern; switch (next.getSeverity()) { case IStatus.ERROR: hasProblems = true; hasErrors = true; messagePattern = ValidationUIMessages.Validation_error; break; case IStatus.WARNING: hasProblems = true; messagePattern = ValidationUIMessages.Validation_warn; break; default: messagePattern = ValidationUIMessages.Validation_note; break; } output.append(MessageFormat.format(messagePattern, new Object[] {next.getMessage()})); output.append(PLATFORM_NEWLINE); } if (next.isMultiStatus()) { appendProblemsRecursive(next.getChildren(), output); } } }
public void testAddExternalJarBug132827() throws Exception { fJavaProject = createProject(DEFAULT_OUTPUT_FOLDER_NAME); IPath[] jarPaths = new IPath[] {JavaProjectHelper.MYLIB.makeAbsolute()}; CPJavaProject cpProject = CPJavaProject.createFromExisting(fJavaProject); ClasspathModifier.addExternalJars(jarPaths, cpProject); ClasspathModifier.commitClassPath(cpProject, null); cpProject = CPJavaProject.createFromExisting(fJavaProject); IStatus status = ClasspathModifier.checkAddExternalJarsPrecondition(jarPaths, cpProject); assertTrue(status.getSeverity() == IStatus.INFO); BuildpathDelta delta = ClasspathModifier.addExternalJars(jarPaths, cpProject); assertDeltaResources(delta, new IPath[0], new IPath[0], new IPath[0], new IPath[0]); assertDeltaDefaultOutputFolder(delta, fJavaProject.getOutputLocation()); assertDeltaRemovedEntries(delta, new IPath[0]); assertDeltaAddedEntries(delta, new IPath[0]); ClasspathModifier.commitClassPath(cpProject, null); IClasspathEntry[] classpathEntries = fJavaProject.getRawClasspath(); assertNumberOfEntries(classpathEntries, 2); assertIsOnBuildpath(classpathEntries, JavaProjectHelper.MYLIB.makeAbsolute()); }