Search in sources :

Example 1 with Platform

use of org.eclipse.core.runtime.Platform in project n4js by eclipse.

the class ExternalLibrariesActivator method getExternalLibraries.

private static BiMap<URI, String> getExternalLibraries() {
    final Bundle bundle = context.getBundle();
    checkNotNull(bundle, "Bundle was null. Does the platform running?");
    final Iterable<Pair<URI, String>> uriNamePairs = from(EXTERNAL_LIBRARY_FOLDER_NAMES).transform(name -> bundle.getResource(name)).filter(notNull()).transform(URL_TO_FILE_URL_FUNC).transform(URL_TO_URI_FUNC).filter(notNull()).transform(uri -> new File(uri)).transform(FILE_TO_CANONICAL_FILE).transform(file -> file.toURI()).transform(uri -> pair(uri, new File(uri).getName()));
    final Map<URI, String> uriMappings = newLinkedHashMap();
    // npm packages first to be able to shadow runtime libraries and Mangelhaft from npm packages.
    final File targetPlatformInstallLocation = N4_NPM_FOLDER_SUPPLIER.get();
    final File nodeModulesFolder = new File(targetPlatformInstallLocation, NPM_CATEGORY);
    uriMappings.put(nodeModulesFolder.toURI(), NPM_CATEGORY);
    for (final Pair<URI, String> pair : uriNamePairs) {
        uriMappings.put(pair.getFirst(), pair.getSecond());
    }
    return ImmutableBiMap.copyOf(uriMappings);
}
Also used : BundleActivator(org.osgi.framework.BundleActivator) URL(java.net.URL) UtilN4(org.eclipse.n4js.utils.UtilN4) Supplier(com.google.common.base.Supplier) Platform.inDebugMode(org.eclipse.core.runtime.Platform.inDebugMode) Predicates.notNull(com.google.common.base.Predicates.notNull) ImmutableBiMap(com.google.common.collect.ImmutableBiMap) Logger(org.apache.log4j.Logger) Pair(org.eclipse.xtext.util.Pair) IStatus(org.eclipse.core.runtime.IStatus) ImmutableList(com.google.common.collect.ImmutableList) FluentIterable.from(com.google.common.collect.FluentIterable.from) Platform.inDevelopmentMode(org.eclipse.core.runtime.Platform.inDevelopmentMode) Map(java.util.Map) URI(java.net.URI) Bundle(org.osgi.framework.Bundle) Suppliers.memoize(com.google.common.base.Suppliers.memoize) Path(java.nio.file.Path) BiMap(com.google.common.collect.BiMap) Tuples.pair(org.eclipse.xtext.util.Tuples.pair) Function(com.google.common.base.Function) ImmutableMap(com.google.common.collect.ImmutableMap) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) FileWriter(java.io.FileWriter) InternalPlatform(org.eclipse.core.internal.runtime.InternalPlatform) IOException(java.io.IOException) File(java.io.File) BundleContext(org.osgi.framework.BundleContext) Preconditions.checkState(com.google.common.base.Preconditions.checkState) FileLocator(org.eclipse.core.runtime.FileLocator) Boolean.parseBoolean(java.lang.Boolean.parseBoolean) IProduct(org.eclipse.core.runtime.IProduct) Platform(org.eclipse.core.runtime.Platform) Maps.newLinkedHashMap(com.google.common.collect.Maps.newLinkedHashMap) Bundle(org.osgi.framework.Bundle) File(java.io.File) URI(java.net.URI) Pair(org.eclipse.xtext.util.Pair)

Example 2 with Platform

use of org.eclipse.core.runtime.Platform in project n4js by eclipse.

the class RebuildWorkspaceProjectsScheduler method scheduleBuildIfNecessary.

/**
 * Schedules a build with the given projects. Does nothing if the {@link Platform platform} is not running, or the
 * iterable of projects is empty.
 *
 * @param toUpdate
 *            an iterable of projects to build.
 */
public void scheduleBuildIfNecessary(final Iterable<IProject> toUpdate) {
    if (Platform.isRunning() && !Iterables.isEmpty(toUpdate)) {
        final Workspace workspace = (Workspace) ResourcesPlugin.getWorkspace();
        final IBuildConfiguration[] projectsToReBuild = from(asList(workspace.getBuildOrder())).filter(config -> Iterables.contains(toUpdate, config.getProject())).toArray(IBuildConfiguration.class);
        if (!Arrays2.isEmpty(projectsToReBuild)) {
            new RebuildWorkspaceProjectsJob(projectsToReBuild).schedule();
        }
    }
}
Also used : Workspace(org.eclipse.core.internal.resources.Workspace) Iterables(com.google.common.collect.Iterables) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) IProject(org.eclipse.core.resources.IProject) Arrays.asList(java.util.Arrays.asList) FluentIterable.from(com.google.common.collect.FluentIterable.from) IBuildConfiguration(org.eclipse.core.resources.IBuildConfiguration) Platform(org.eclipse.core.runtime.Platform) Arrays2(org.eclipse.n4js.utils.collections.Arrays2) Workspace(org.eclipse.core.internal.resources.Workspace) IBuildConfiguration(org.eclipse.core.resources.IBuildConfiguration)

Aggregations

FluentIterable.from (com.google.common.collect.FluentIterable.from)2 Platform (org.eclipse.core.runtime.Platform)2 Function (com.google.common.base.Function)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Predicates.notNull (com.google.common.base.Predicates.notNull)1 Supplier (com.google.common.base.Supplier)1 Suppliers.memoize (com.google.common.base.Suppliers.memoize)1 BiMap (com.google.common.collect.BiMap)1 ImmutableBiMap (com.google.common.collect.ImmutableBiMap)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Iterables (com.google.common.collect.Iterables)1 Maps.newLinkedHashMap (com.google.common.collect.Maps.newLinkedHashMap)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 Boolean.parseBoolean (java.lang.Boolean.parseBoolean)1 URI (java.net.URI)1 URL (java.net.URL)1