Search in sources :

Example 1 with ApiUsage

use of org.eclipse.n4js.runner.RunnerHelper.ApiUsage in project n4js by eclipse.

the class RunnerFrontEnd method configureDependenciesAndPaths.

/**
 * Configures paths based on project dependencies and API-IMPL relations.
 */
private void configureDependenciesAndPaths(RunConfiguration config) {
    // 1) for all API projects among the direct and indirect dependencies we have to provide a mapping
    // from the projectId of the API project to the projectId of the implementation project to be used
    final ApiUsage apiUsage = runnerHelper.getProjectExtendedDepsAndApiImplMapping(config.getRuntimeEnvironment(), config.getUserSelection(), config.getImplementationId(), true);
    final List<IN4JSProject> deps = apiUsage.projects;
    final Map<IN4JSProject, IN4JSProject> apiImplProjectMapping = apiUsage.concreteApiImplProjectMapping;
    config.setApiImplProjectMappingFromProjects(apiImplProjectMapping);
    // 2) collect paths to all output folders of all N4JS projects (dependencies) with the compiled code
    // (these are the .../es5/ folders)
    final List<IN4JSProject> depsImpl = deps.stream().map(p -> {
        final IN4JSProject p2 = apiImplProjectMapping.get(p);
        final IN4JSProject p3 = p2 != null ? p2 : p;
        return p3;
    }).collect(Collectors.toList());
    final Collection<String> coreProjectPaths = runnerHelper.getCoreProjectPaths(depsImpl);
    config.setCoreProjectPaths(coreProjectPaths);
}
Also used : Arrays(java.util.Arrays) URI(org.eclipse.emf.common.util.URI) ApiUsage(org.eclipse.n4js.runner.RunnerHelper.ApiUsage) Inject(com.google.inject.Inject) FileExtensionsRegistry(org.eclipse.n4js.fileextensions.FileExtensionsRegistry) ResourceNameComputer(org.eclipse.n4js.utils.ResourceNameComputer) IN4JSCore(org.eclipse.n4js.projectModel.IN4JSCore) ArrayList(java.util.ArrayList) RunnerRegistry(org.eclipse.n4js.runner.extension.RunnerRegistry) Lists(com.google.common.collect.Lists) FileExtensionType(org.eclipse.n4js.fileextensions.FileExtensionType) Optional(com.google.common.base.Optional) Map(java.util.Map) IRunnerDescriptor(org.eclipse.n4js.runner.extension.IRunnerDescriptor) RuntimeEnvironment(org.eclipse.n4js.runner.extension.RuntimeEnvironment) Redirect(java.lang.ProcessBuilder.Redirect) Collection(java.util.Collection) IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) AbstractSubGenerator(org.eclipse.n4js.generator.AbstractSubGenerator) Singleton(com.google.inject.Singleton) ApiUsage(org.eclipse.n4js.runner.RunnerHelper.ApiUsage) IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject)

Example 2 with ApiUsage

use of org.eclipse.n4js.runner.RunnerHelper.ApiUsage in project n4js by eclipse.

the class ChooseImplementationHelper method chooseImplementationIfRequired.

/**
 * Choose an implementation if needed
 *
 * @param runnerId
 *            the runner ID, e.g. NODEJS
 * @param moduleToRun
 *            the emf-full URI to the module to run
 * @return the selected implementation Id
 */
public String chooseImplementationIfRequired(String runnerId, URI moduleToRun) {
    // first see if we need to supply an implementationId
    // (we need one if there are API projects among the dependencies of the moduleToRun AND there exist 2 or more
    // implementations for them)
    final ApiUsage apiUsage = runnerHelper.getProjectExtendedDeps(runnerId, moduleToRun);
    final ApiImplMapping apiImplMapping = apiUsage.apiImplMapping;
    final List<String> availableImplIds = apiImplMapping.getAllImplIds();
    if (apiImplMapping.isEmpty())
        // no API projects among the dependencies -> no need to bother the user
        return null;
    if (availableImplIds.isEmpty())
        // no implementations available -> error will be shown somewhere else
        return null;
    if (availableImplIds.size() == 1)
        // exactly 1 implementation -> use that, no need to bother the user
        return availableImplIds.get(0);
    // make user choose:
    // We have to open the dialog on the UI-thread
    // See:
    // http://stackoverflow.com/questions/354796/whats-the-best-way-to-get-a-return-value-out-of-an-asyncexec-in-eclipse
    final AtomicReference<String> result = new AtomicReference<>();
    final ChooseImplementationDialog dlg = new ChooseImplementationDialog(null, apiImplMapping);
    Display.getDefault().syncExec(new Runnable() {

        @Override
        public void run() {
            if (dlg.open() == Window.OK) {
                result.set((String) dlg.getResult()[0]);
            } else {
                result.set(CANCEL);
            }
        }
    });
    return result.get();
}
Also used : ApiUsage(org.eclipse.n4js.runner.RunnerHelper.ApiUsage) ApiImplMapping(org.eclipse.n4js.compare.ApiImplMapping) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Aggregations

ApiUsage (org.eclipse.n4js.runner.RunnerHelper.ApiUsage)2 Optional (com.google.common.base.Optional)1 Lists (com.google.common.collect.Lists)1 Inject (com.google.inject.Inject)1 Singleton (com.google.inject.Singleton)1 File (java.io.File)1 IOException (java.io.IOException)1 Redirect (java.lang.ProcessBuilder.Redirect)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Collectors (java.util.stream.Collectors)1 URI (org.eclipse.emf.common.util.URI)1 ApiImplMapping (org.eclipse.n4js.compare.ApiImplMapping)1 FileExtensionType (org.eclipse.n4js.fileextensions.FileExtensionType)1