Search in sources :

Example 31 with MultiStatus

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;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) MultiStatus(org.eclipse.core.runtime.MultiStatus) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 32 with MultiStatus

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);
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IOException(java.io.IOException) PackageJson(org.eclipse.n4js.external.libraries.PackageJson) File(java.io.File) IOException(java.io.IOException) LightweightException(org.eclipse.n4js.utils.LightweightException)

Example 33 with MultiStatus

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();
    }
}
Also used : ClosableMeasurement(org.eclipse.n4js.smith.ClosableMeasurement) IStatus(org.eclipse.core.runtime.IStatus) MultiStatus(org.eclipse.core.runtime.MultiStatus) URI(java.net.URI) Collection(java.util.Collection) File(java.io.File)

Example 34 with MultiStatus

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);
}
Also used : Arrays(java.util.Arrays) MultiStatus(org.eclipse.core.runtime.MultiStatus) SortedSet(java.util.SortedSet) Inject(com.google.inject.Inject) ClosableMeasurement(org.eclipse.n4js.smith.ClosableMeasurement) PackageJson(org.eclipse.n4js.external.libraries.PackageJson) Sets.difference(com.google.common.collect.Sets.difference) IStatus(org.eclipse.core.runtime.IStatus) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FluentIterable.from(com.google.common.collect.FluentIterable.from) Map(java.util.Map) BinaryCommandFactory(org.eclipse.n4js.binaries.BinaryCommandFactory) URI(java.net.URI) N4MF_MANIFEST(org.eclipse.n4js.projectModel.IN4JSProject.N4MF_MANIFEST) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) ShippedCodeAccess(org.eclipse.n4js.external.libraries.ShippedCodeAccess) DataCollector(org.eclipse.n4js.smith.DataCollector) DataCollectors(org.eclipse.n4js.smith.DataCollectors) StatusHelper(org.eclipse.n4js.utils.StatusHelper) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) Strings(org.eclipse.xtext.util.Strings) Set(java.util.Set) ExternalProject(org.eclipse.n4js.utils.resources.ExternalProject) Collectors(java.util.stream.Collectors) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IllegalBinaryStateException(org.eclipse.n4js.binaries.IllegalBinaryStateException) Singleton(com.google.inject.Singleton) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) RegisterResult(org.eclipse.n4js.external.ExternalLibraryWorkspace.RegisterResult) ProcessExecutionCommandStatus(org.eclipse.n4js.utils.ProcessExecutionCommandStatus) SubMonitor(org.eclipse.core.runtime.SubMonitor) OK_STATUS(org.eclipse.core.runtime.Status.OK_STATUS) Multimap(com.google.common.collect.Multimap) Supplier(java.util.function.Supplier) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Pair(org.eclipse.xtext.util.Pair) IProject(org.eclipse.core.resources.IProject) GitUtils(org.eclipse.n4js.utils.git.GitUtils) LinkedList(java.util.LinkedList) Tuples(org.eclipse.xtext.util.Tuples) Job(org.eclipse.core.runtime.jobs.Job) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) IOException(java.io.IOException) File(java.io.File) Provider(com.google.inject.Provider) NpmBinary(org.eclipse.n4js.binaries.nodejs.NpmBinary) Platform(org.eclipse.core.runtime.Platform) Collections(java.util.Collections) IStatus(org.eclipse.core.runtime.IStatus)

Example 35 with MultiStatus

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;
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Iterator(java.util.Iterator) MultiStatus(org.eclipse.core.runtime.MultiStatus)

Aggregations

MultiStatus (org.eclipse.core.runtime.MultiStatus)140 IStatus (org.eclipse.core.runtime.IStatus)98 Status (org.eclipse.core.runtime.Status)60 CoreException (org.eclipse.core.runtime.CoreException)41 ArrayList (java.util.ArrayList)29 File (java.io.File)24 SubMonitor (org.eclipse.core.runtime.SubMonitor)24 IOException (java.io.IOException)14 InvocationTargetException (java.lang.reflect.InvocationTargetException)13 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)13 List (java.util.List)11 HashMap (java.util.HashMap)10 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)10 IPath (org.eclipse.core.runtime.IPath)8 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 FileNotFoundException (java.io.FileNotFoundException)7 HashSet (java.util.HashSet)7 IProject (org.eclipse.core.resources.IProject)7 IContainer (org.eclipse.core.resources.IContainer)6 URI (java.net.URI)5