use of org.eclipse.core.runtime.MultiStatus in project n4js by eclipse.
the class ExternalLibraryPreferencePage method performOk.
@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;
}
use of org.eclipse.core.runtime.MultiStatus in project n4js by eclipse.
the class NpmPackageToProjectAdapter method adaptPackages.
/**
* Adapts npm packages in provided folder to the N4JS project structure. Only package folders which match requested
* packages are adapted. It is expected that npm flattens packages structures, therefore it is assumed that other
* folders are dependencies (also transitive) of the requested packages.
*
* Requested npm packages already look like N4JS projects (i.e. have N4MF manifest file), those packages are not
* adapted (proper structure is assumed), but they will be returned in to the caller to allow further processing
* (i.e. passing them to the builder).
*
* Returned set of N4JS project folders will not include those installed by the npm but without matching names in
* provided set of expected packages. Those packages are treated as transitive dependencies and are not return to
* the caller.
*
* @param namesOfPackagesToAdapt
* names of the expected packages
* @return pair of overall adaptation status and folders of successfully adapted npm packages
*/
public Pair<IStatus, Collection<File>> adaptPackages(Iterable<String> namesOfPackagesToAdapt) {
final File nodeModulesFolder = new File(installLocationProvider.getTargetPlatformNodeModulesLocation());
final Collection<String> names = newHashSet(namesOfPackagesToAdapt);
final Collection<File> adaptedProjects = newHashSet();
final File[] packageRoots = nodeModulesFolder.listFiles(packageName -> names.contains(packageName.getName()));
final MultiStatus status = statusHelper.createMultiStatus("Status of adapting npm packages");
final File n4jsdsFolder = getNpmsTypeDefinitionsFolder();
for (File packageRoot : packageRoots) {
try {
PackageJson packageJson = getPackageJson(packageRoot);
final File manifest = new File(packageRoot, N4MF_MANIFEST);
// looks like n4js project skip adaptation
if (manifest.exists() && manifest.isFile()) {
if (!names.remove(packageRoot.getName())) {
throw new IOException("Unexpected error occurred while adapting '" + packageRoot.getName() + "' npm package into N4JS format.");
}
adaptedProjects.add(packageRoot);
} else {
if (manifest.isDirectory()) {
throw new IOException("The manifest location is occupied by the folder '" + manifest + "'.");
}
manifest.createNewFile();
try {
String mainModule = computeMainModule(packageRoot);
generateManifestContent(packageRoot, packageJson, mainModule, manifest);
if (!names.remove(packageRoot.getName())) {
throw new IOException("Unexpected error occurred while adapting '" + packageRoot.getName() + "' npm package into N4JS format.");
}
adaptedProjects.add(packageRoot);
} catch (final Exception e) {
try {
FileDeleter.delete(manifest);
} catch (IOException ioe) {
// Intentionally swallowed to get the original cause.
LOGGER.error("Error while trying to clean up corrupted " + manifest + " file.", e);
}
throw e;
}
}
if (n4jsdsFolder != null && adaptedProjects.contains(packageRoot)) {
addTypeDefinitions(packageRoot, packageJson, manifest, n4jsdsFolder);
}
} catch (final Exception e) {
status.merge(statusHelper.createError("Unexpected error occurred while adapting '" + packageRoot.getName() + "' npm package into N4JS format.", e));
}
}
return pair(status, adaptedProjects);
}
use of org.eclipse.core.runtime.MultiStatus in project n4js by eclipse.
the class NpmManager method installDependenciesInternal.
private IStatus installDependenciesInternal(final Map<String, String> versionedNPMs, final IProgressMonitor monitor, boolean triggerCleanbuild) {
MultiStatus status = statusHelper.createMultiStatus("Status of installing multiple npm dependencies.");
IStatus binaryStatus = checkNPM();
if (!binaryStatus.isOK()) {
status.merge(binaryStatus);
return status;
}
Set<String> requestedNPMs = versionedNPMs.keySet();
try (ClosableMeasurement mes = dcLibMngr.getClosableMeasurement("installDependenciesInternal")) {
Set<String> oldNPMs = getOldNPMs(monitor, requestedNPMs);
installUninstallNPMs(versionedNPMs, monitor, status, requestedNPMs, oldNPMs);
Pair<Collection<String>, Iterable<java.net.URI>> changedDeps = getChangedDependencies(monitor, oldNPMs);
Collection<String> addedDependencies = changedDeps.getFirst();
Iterable<java.net.URI> toBeDeleted = changedDeps.getSecond();
Collection<File> adaptedPackages = adaptNPMPackages(monitor, status, addedDependencies);
cleanBuildDependencies(monitor, status, toBeDeleted, adaptedPackages, triggerCleanbuild);
return status;
} finally {
monitor.done();
}
}
use of org.eclipse.core.runtime.MultiStatus in project n4js by eclipse.
the class NpmManager method installUninstallNPMs.
private void installUninstallNPMs(final Map<String, String> versionedNPMs, final IProgressMonitor monitor, final MultiStatus status, final Set<String> requestedNPMs, final Set<String> oldNPMs) {
monitor.setTaskName("Installing packages... [step 1 of 4]");
// calculate already installed to skip
final Set<String> npmNamesToInstall = difference(requestedNPMs, oldNPMs);
final Set<String> npmsToInstall = versionedNPMs.entrySet().stream().filter(e -> npmNamesToInstall.contains(e.getKey())).map(e -> e.getKey() + Strings.emptyIfNull(e.getValue())).collect(Collectors.toSet());
IStatus installStatus = batchInstallUninstall(monitor, npmsToInstall, true);
// assume that at least some packages were installed correctly and can be adapted
if (!installStatus.isOK()) {
logger.logInfo("Some packages could not be installed due to errors, see log for details.");
status.merge(installStatus);
}
monitor.worked(2);
}
use of org.eclipse.core.runtime.MultiStatus in project egit by eclipse.
the class ExceptionCollector method getStatus.
/**
* Returns a status that represents the exceptions collected. If the
* collector is empty <code>IStatus.OK</code> is returned. Otherwise a
* MultiStatus containing all collected exceptions is returned.
*
* @return a multistatus containing the exceptions collected or IStatus.OK
* if the collector is empty.
*/
public IStatus getStatus() {
if (statuses.isEmpty()) {
return Status.OK_STATUS;
} else {
final MultiStatus multiStatus = new MultiStatus(pluginId, severity, message, null);
final Iterator it = statuses.iterator();
while (it.hasNext()) {
final IStatus status = (IStatus) it.next();
multiStatus.merge(status);
}
return multiStatus;
}
}
Aggregations