Java Code Examples for org.eclipse.core.runtime.MultiStatus#merge()
The following examples show how to use
org.eclipse.core.runtime.MultiStatus#merge() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExternalLibraryPreferencePage.java From n4js with Eclipse Public License 1.0 | 6 votes |
@Override public boolean performOk() { final MultiStatus multistatus = statusHelper .createMultiStatus("Status of importing target platform."); try { new ProgressMonitorDialog(getShell()).run(true, false, monitor -> { final IStatus status = store.save(monitor); if (!status.isOK()) { setMessage(status.getMessage(), ERROR); multistatus.merge(status); } else { updateInput(viewer, store.getLocations()); } }); } catch (final InvocationTargetException | InterruptedException exc) { multistatus.merge(statusHelper.createError("Error while building external libraries.", exc)); } if (multistatus.isOK()) return super.performOk(); else return false; }
Example 2
Source File: LibraryManager.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** Deletes all 'node_modules' folders (and their npm projects). Afterwards, the ext. library state is updated. */ public IStatus deleteAllNodeModulesFolders(IProgressMonitor monitor) { MultiStatus multistatus = statusHelper.createMultiStatus("Delete all node_modules folders"); for (SafeURI<?> nodeModulesLoc : extLibPreferenceStore.getNodeModulesLocations()) { // delete whole target platform folder if (nodeModulesLoc.exists()) { nodeModulesLoc.delete((IOException ioe) -> multistatus.merge( statusHelper.createError("Exception during deletion of the npm folder.", ioe))); } if (nodeModulesLoc.exists()) { // should never happen multistatus.merge(statusHelper .createError("Could not verify deletion of " + nodeModulesLoc.getAbsolutePath())); } } // other actions like reinstall depends on this state externalLibraryWorkspace.updateState(); indexSynchronizer.synchronizeNpms(monitor); return multistatus; }
Example 3
Source File: LibraryManager.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** Runs 'npm/yarn install' in a given folder. Afterwards, re-registers all npms. */ public IStatus runNpmYarnInstall(PlatformResourceURI target, IProgressMonitor monitor) { IN4JSProject project = n4jsCore.findProject(target.toURI()).orNull(); File projectFolder = project.getLocation().toJavaIoFile(); boolean usingYarn = npmCli.isYarnUsed(projectFolder); String msg = "Running '" + (usingYarn ? "yarn" : "npm") + " install' on " + project.getProjectName(); MultiStatus status = statusHelper.createMultiStatus(msg); logger.logInfo(msg); IStatus binaryStatus = checkBinary(usingYarn); if (!binaryStatus.isOK()) { status.merge(binaryStatus); return status; } SubMonitor subMonitor = SubMonitor.convert(monitor, 2); SubMonitor subMonitor1 = subMonitor.split(1); subMonitor1.setTaskName("Building installed packages..."); // Calculate the folder in which npm/yarn should be executed, either local project folder // or yarn root folder NodeModulesFolder nmf = nodeModulesDiscoveryHelper.getNodeModulesFolder(projectFolder.toPath()); File nmfFile = nmf.isYarnWorkspace() ? nmf.workspaceNodeModulesFolder : nmf.localNodeModulesFolder; File folderInWhichToExecute = nmfFile.getParentFile(); npmCli.runNpmYarnInstall(folderInWhichToExecute); SubMonitor subMonitor2 = subMonitor.split(1); subMonitor2.setTaskName("Registering packages..."); indexSynchronizer.reindexAllExternalProjects(subMonitor2); return status; }
Example 4
Source File: SVNRepositoryLocation.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
public static SVNRepositoryLocation fromString(String location) throws SVNException { try { return fromString(location, false); } catch (SVNException e) { // Parsing failed. Include a status that // shows the passed location and the proper form MultiStatus error = new MultiStatus(SVNProviderPlugin.ID, SVNStatus.ERROR, Policy.bind("SVNRepositoryLocation.invalidFormat", new Object[] { location }), null); //$NON-NLS-1$ error.merge(new SVNStatus(SVNStatus.ERROR, Policy.bind("SVNRepositoryLocation.locationForm"))); //$NON-NLS-1$ error.merge(e.getStatus()); throw new SVNException(error); } }
Example 5
Source File: SVNAction.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
/** * Return the status to be displayed in an error dialog for the given list * of non-OK status. * * This method can be overridden by subclasses. Returning an OK status will * prevent the error dialog from being shown. */ protected IStatus getStatusToDisplay(IStatus[] problems) { if (problems.length == 1) { return problems[0]; } MultiStatus combinedStatus = new MultiStatus(SVNUIPlugin.ID, 0, getMultiStatusMessage(), null); //$NON-NLS-1$ for (int i = 0; i < problems.length; i++) { combinedStatus.merge(problems[i]); } return combinedStatus; }
Example 6
Source File: CloudToolsEclipseProjectNotifier.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
/** * Perform the upgrade. */ private IStatus upgradeProjects(Collection<IProject> projects, SubMonitor progress) { progress.setWorkRemaining(projects.size()); MultiStatus status = StatusUtil.multi(this, Messages.getString("updating.projects.jobname")); //$NON-NLS-1$ for (IProject project : projects) { progress.subTask(Messages.getString("updating.project", project.getName())); //$NON-NLS-1$ IStatus result = CloudToolsEclipseProjectUpdater.updateProject(project, progress.newChild(1)); status.merge(result); } // rewrite if OK as otherwise Progress View shows the "Updating projects for..." message return StatusUtil.filter(status); }
Example 7
Source File: LibraryManager.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Uninstalls the given npm package in a blocking fashion. * * @param packageURI * the name of the package that has to be uninstalled via package manager. * @param monitor * the monitor for the blocking uninstall process. * @return a status representing the outcome of the uninstall process. */ public IStatus uninstallNPM(FileURI packageURI, IProgressMonitor monitor) { String msg = "Uninstalling NPM: " + packageURI; MultiStatus status = statusHelper.createMultiStatus(msg); logger.logInfo(msg); // trim package name and node_modules segments from packageURI: FileURI containingProjectURI = getParentOfMatchingLocation(packageURI, name -> N4JSGlobals.NODE_MODULES.equals(name)); boolean usingYarn = npmCli.isYarnUsed(containingProjectURI.toJavaIoFile()); IStatus binaryStatus = checkBinary(usingYarn); if (!binaryStatus.isOK()) { status.merge(binaryStatus); return status; } try (Measurement mes = N4JSDataCollectors.dcLibMngr.getMeasurement("uninstallDependenciesInternal");) { N4JSExternalProject externalProject = externalLibraryWorkspace.getProject(packageURI); if (externalProject == null) { return status; } IN4JSProject iProject = externalProject.getIProject(); LibraryChange requestedChange = new LibraryChange(LibraryChangeType.Uninstall, packageURI, iProject.getProjectName(), iProject.getVersion().toString()); Collection<LibraryChange> actualChanges = npmCli.uninstall(monitor, status, requestedChange); try (Measurement m = N4JSDataCollectors.dcIndexSynchronizer.getMeasurement("synchronizeNpms")) { indexSynchronizer.synchronizeNpms(monitor, actualChanges); } return status; } finally { monitor.done(); } }
Example 8
Source File: RunnableInstallDependencies.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** @return status of runnable */ public synchronized IStatus getResultStatus() { if (multistatus == null) return statusHelper.createError(getClass().getName() + " was not called yet!"); MultiStatus result = statusHelper.createMultiStatus("result"); result.merge(multistatus); return result; }
Example 9
Source File: NpmCLI.java From n4js with Eclipse Public License 1.0 | 5 votes |
private Set<LibraryChange> computeActualChanges(Path installPath, Collection<LibraryChange> requestedChanges, MultiStatus mergeStatusHere) { Set<LibraryChange> result = new LinkedHashSet<>(); Path nodeModulesFolder = installPath.resolve(N4JSGlobals.NODE_MODULES); for (LibraryChange reqChg : requestedChanges) { if (reqChg.type == LibraryChangeType.Install) { Path completePath = nodeModulesFolder.resolve(reqChg.name.getRawName()); String actualVersion = getActualVersion(completePath); if (actualVersion.isEmpty()) { // unable to load version from package.json: // -> retry loading from node_modules folder located in yarn workspace root folder NodeModulesFolder nmf = nodeModulesDiscoveryHelper.getNodeModulesFolder(installPath); if (nmf.isYarnWorkspace()) { Path nodeModulesFolderInYarnWorkspaceRoot = nmf.workspaceNodeModulesFolder.toPath(); completePath = nodeModulesFolderInYarnWorkspaceRoot.resolve(reqChg.name.getRawName()); actualVersion = getActualVersion(completePath); } } if (actualVersion.isEmpty()) { String msg = "Error reading package json when " + reqChg.toString(); IStatus packJsonError = statusHelper.createError(msg); mergeStatusHere.merge(packJsonError); } else { FileURI actualLocation = new FileURI(URIUtils.toFileUri(completePath)); LibraryChange actualChange = new LibraryChange(LibraryChangeType.Added, actualLocation, reqChg.name, actualVersion); result.add(actualChange); } } } return result; }
Example 10
Source File: NpmCLI.java From n4js with Eclipse Public License 1.0 | 5 votes |
private Collection<LibraryChange> batchInstallInternal(IProgressMonitor monitor, MultiStatus status, Collection<LibraryChange> requestedChanges, FileURI target) { SubMonitor subMonitor = SubMonitor.convert(monitor, 1); subMonitor.setTaskName("Installing npm packages."); // Convert platform URI to local (e.g. file) URI File installPath = target.toJavaIoFile(); // for installation, we invoke npm only once for all packages final List<Pair<N4JSProjectName, String>> packageNamesAndVersions = Lists.newArrayList(); for (LibraryChange reqChg : requestedChanges) { if (reqChg.type == LibraryChangeType.Install) { packageNamesAndVersions.add(Tuples.pair(reqChg.name, "@" + reqChg.version)); } } IStatus installStatus = install(packageNamesAndVersions, installPath); subMonitor.worked(1); Set<LibraryChange> actualChanges; MultiStatus batchStatus = statusHelper.createMultiStatus("Installing npm packages."); if (installStatus == null || !installStatus.isOK()) { actualChanges = Collections.emptySet(); batchStatus.merge(installStatus); } else { actualChanges = computeActualChanges(installPath.toPath(), requestedChanges, batchStatus); } if (!batchStatus.isOK()) { logger.logInfo("Some packages could not be installed due to errors, see log for details."); status.merge(batchStatus); } return actualChanges; }
Example 11
Source File: ExternalLibraryPreferencePage.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** Actions to be taken if re-registering npms is requested. */ private MultiStatus reregisterNpms(final IProgressMonitor monitor, final MultiStatus multistatus) { try { IStatus status = libManager.registerAllExternalProjects(monitor); multistatus.merge(status); } catch (Exception e) { String msg = "Error when re-registering external libraries."; multistatus.merge(statusHelper.createError(msg, e)); } finally { updateInput(viewer, store.getLocations()); } return multistatus; }
Example 12
Source File: ExternalLibraryPreferencePage.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** Actions to be taken if deleting npms is requested. */ private MultiStatus cleanNpms(final IProgressMonitor monitor, final MultiStatus multistatus) { try { multistatus.merge(externalLibrariesActionsHelper.maintenanceDeleteNpms(monitor)); } catch (Exception e) { String msg = "Error when cleaning external libraries."; multistatus.merge(statusHelper.createError(msg, e)); } finally { updateInput(viewer, store.getLocations()); } return multistatus; }
Example 13
Source File: ExternalLibrariesActionsHelper.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Streamlined process of calculating and installing the dependencies, npm cache cleaning forced by passed flag. * <p> * <b>IMPORTANT:</b> If <code>npmrcLocation</code> is given (and only then), this method will change the default * <code>.npmrc</code> location in the Eclipse preferences and this value will stay in effect after this method * returns. Rationale of original implementor:<br> * <cite>information about {@code .npmrc} is deep in the NodeProcessBuilder and by design it is not exposed. We * could redesign that part and expose it, but it makes sense to assume user selected {@code .npmrc} file while * setting up the workspace should be used for further dependencies setups (e.g. quick-fixes in manifests) in this * workspace hence we save provided {@code .npmrc} file in the preferences.</cite> * * @param npmrcLocation * optional path to an <code>.npmrc</code> file to be used during installation of dependencies. */ public void cleanAndInstallAllDependencies(Optional<Path> npmrcLocation, SubMonitor monitor, MultiStatus multiStatus) { try (Measurement m = N4JSDataCollectors.dcInstallHelper.getMeasurement("Install Missing Dependencies")) { // configure .npmrc if (npmrcLocation.isPresent()) { configureNpmrc(npmrcLocation.get(), multiStatus); } SubMonitor subMonitor = SubMonitor.convert(monitor, 2); // remove npms multiStatus.merge(maintenanceDeleteNpms(subMonitor.split(1))); // install dependencies and force external library workspace reload try (Measurement mm = N4JSDataCollectors.dcInstallMissingDeps .getMeasurement("Install missing dependencies")) { IStatus status = libManager.runNpmYarnInstallOnAllProjects(subMonitor.split(1)); if (!status.isOK()) { multiStatus.merge(status); } } } }
Example 14
Source File: NpmCLI.java From n4js with Eclipse Public License 1.0 | 4 votes |
/** * Installs npm package with given name at the given path. Updates dependencies in the package.json of that * location. If there is no package.json at that location npm errors will be logged to the error log. In that case * npm/yarn usual still installs requested dependency (if possible). * * @param packageNamesAndVersions * to be installed * @param installPath * path where package is supposed to be installed */ private IStatus install(List<Pair<N4JSProjectName, String>> packageNamesAndVersions, File installPath) { List<String> packageNamesAndVersionsMerged = new ArrayList<>(packageNamesAndVersions.size()); for (Pair<N4JSProjectName, String> pair : packageNamesAndVersions) { N4JSProjectName packageName = pair.getFirst(); String packageVersion = pair.getSecond(); // FIXME better error reporting (show all invalid names/versions, not just the first) if (invalidPackageName(packageName)) { return statusHelper.createError("Malformed npm package name: '" + packageName + "'."); } if (invalidPackageVersion(packageVersion)) { return statusHelper.createError("Malformed npm package version: '" + packageVersion + "'."); } String nameAndVersion = packageVersion.isEmpty() ? packageName.getRawName() : packageName.getRawName() + packageVersion; packageNamesAndVersionsMerged.add(nameAndVersion); } IStatus status = executor.execute( () -> commandFactory.createInstallPackageCommand(installPath, packageNamesAndVersionsMerged, true), "Error while installing npm package."); // TODO IDE-3136 / GH-1011 workaround for a problem in node related to URL/GitHub version requirements // In case of a dependency like "JSONSelect@dbo/JSONSelect" (wherein "dbo/JSONSelect" is a GitHub version // requirement), the first installation works fine, but subsequent installations of additional npm packages may // uninstall(!) the earlier package that used a URL/GitHub version requirement. This is supposed to be fixed // in npm version 5.7.1. As a work-around we run a plain "npm install" after every installation of new packages, // which should re-install the package with a URL/GitHub version requirement. boolean isNpmUsed = !isYarnUsed(installPath); if (isNpmUsed) { VersionNumber currNpmVersion = getNpmVersion(); VersionNumber fixedNpmVersion = SemverUtils.createVersionNumber(5, 7, 1); if (currNpmVersion != null && SemverMatcher.compareLoose(currNpmVersion, fixedNpmVersion) < 0) { IStatus workaroundStatus = executor.execute( () -> commandFactory.createInstallPackageCommand(installPath, Collections.emptyList(), false), "Error while running \"npm install\" after installing npm packages."); MultiStatus combinedStatus = statusHelper .createMultiStatus("Installing npm packages with additional \"npm install\" afterwards."); combinedStatus.merge(status); combinedStatus.merge(workaroundStatus); status = combinedStatus; } } return status; }
Example 15
Source File: LibraryManager.java From n4js with Eclipse Public License 1.0 | 4 votes |
/** * NOTE: if the target points to a member project in a yarn workspace, this method will *NOT* switch to the yarn * workspace root folder for executing yarn! Rationale: in case an explicitly mentioned npm package is installed * (e.g. "yarn add lodash") it makes a difference whether that command is being executed in the member project's * root folder or the yarn workspace root folder (i.e. the newly installed npm package will be added to a different * package.json file in each case) and we want to support both cases. */ private IStatus installNPMsInternal(Map<N4JSProjectName, NPMVersionRequirement> versionedNPMs, boolean forceReloadAll, FileURI target, IProgressMonitor monitor) { String msg = getMessage(versionedNPMs); MultiStatus status = statusHelper.createMultiStatus(msg); logger.logInfo(msg); boolean usingYarn = npmCli.isYarnUsed(target); IStatus binaryStatus = checkBinary(usingYarn); if (!binaryStatus.isOK()) { status.merge(binaryStatus); return status; } try (Measurement mes = N4JSDataCollectors.dcLibMngr.getMeasurement("installDependenciesInternal");) { final int steps = forceReloadAll ? 3 : 2; SubMonitor subMonitor = SubMonitor.convert(monitor, steps + 4); Map<N4JSProjectName, NPMVersionRequirement> npmsToInstall = new LinkedHashMap<>(versionedNPMs); SubMonitor subMonitor1 = subMonitor.split(2); subMonitor1.setTaskName("Installing packages... [step 1 of " + steps + "]"); List<LibraryChange> actualChanges = installNPMs(subMonitor1, status, npmsToInstall, target); if (!status.isOK()) { return status; } // if forceReloadAll, unregister all currently-registered projects from // the workspace and remove them from the index if (forceReloadAll) { SubMonitor subMonitor2 = subMonitor.split(1); subMonitor2.setTaskName("Clean all packages... [step 2 of 3]"); externalLibraryWorkspace.deregisterAllProjects(subMonitor2); } try (Measurement m = N4JSDataCollectors.dcIndexSynchronizer.getMeasurement("synchronizeNpms")) { SubMonitor subMonitor3 = subMonitor.split(4); subMonitor3.setTaskName("Building installed packages... [step " + steps + " of " + steps + "]"); indexSynchronizer.synchronizeNpms(subMonitor3, actualChanges); } return status; } finally { monitor.done(); } }
Example 16
Source File: ResourceDropAdapterAssistant.java From translationstudio8 with GNU General Public License v2.0 | 4 votes |
/** * Adds the given status to the list of problems. Discards OK statuses. If * the status is a multi-status, only its children are added. */ private void mergeStatus(MultiStatus status, IStatus toMerge) { if (!toMerge.isOK()) { status.merge(toMerge); } }
Example 17
Source File: ResourceDropAdapterAssistant.java From tmxeditor8 with GNU General Public License v2.0 | 4 votes |
/** * Adds the given status to the list of problems. Discards OK statuses. If * the status is a multi-status, only its children are added. */ private void mergeStatus(MultiStatus status, IStatus toMerge) { if (!toMerge.isOK()) { status.merge(toMerge); } }
Example 18
Source File: PyResourceDropAdapterAssistant.java From Pydev with Eclipse Public License 1.0 | 4 votes |
/** * Adds the given status to the list of problems. Discards OK statuses. If * the status is a multi-status, only its children are added. */ private void mergeStatus(MultiStatus status, IStatus toMerge) { if (!toMerge.isOK()) { status.merge(toMerge); } }
Example 19
Source File: NavigatorResourceDropAssistant.java From gama with GNU General Public License v3.0 | 4 votes |
/** * Adds the given status to the list of problems. Discards OK statuses. If the status is a multi-status, only its * children are added. */ private void mergeStatus(final MultiStatus status, final IStatus toMerge) { if (!toMerge.isOK()) { status.merge(toMerge); } }
Example 20
Source File: LibraryManager.java From n4js with Eclipse Public License 1.0 | 3 votes |
/** * Uninstalls the given npm package in a blocking fashion. Note that this will uninstall *all* npms with the given * name. * * @param npmName * the name of the npm projects that have to be uninstalled via package manager. * @param monitor * the monitor for the blocking uninstall process. * @return a status representing the outcome of the uninstall process. */ public IStatus uninstallNPM(N4JSProjectName npmName, IProgressMonitor monitor) { List<N4JSExternalProject> npmProjects = externalLibraryWorkspace.getProjectsForName(npmName); MultiStatus multiStatus = statusHelper.createMultiStatus("Uninstall all npms with the name: " + npmName); for (N4JSExternalProject npm : npmProjects) { IStatus status = uninstallNPM(npm.getSafeLocation(), monitor); multiStatus.merge(status); } return multiStatus; }