Search in sources :

Example 1 with IRunnerDescriptor

use of org.eclipse.n4js.runner.extension.IRunnerDescriptor in project n4js by eclipse.

the class RunnerFrontEnd method createConfiguration.

/**
 * Create a new run configuration from scratch for running the given moduleToRun.
 *
 * @param runnerId
 *            identifier of the runner to use.
 * @param implementationId
 *            implementation ID to use or <code>null</code>. See {@link RunConfiguration#getImplementationId() here}
 *            for details.
 * @param systemLoader
 *            the application specific unique ID of the javascript system loader. For more details about the
 *            available options, check {@link SystemLoaderInfo}. If {@code null}, then the default System.js loader
 *            will be used.
 * @param moduleToRun
 *            the module to execute. When running in Eclipse, this will be a platform resource URI, in the headless
 *            case it will be a file URI.
 * @return the run configuration.
 */
public RunConfiguration createConfiguration(String runnerId, String implementationId, String systemLoader, URI moduleToRun) {
    final IRunnerDescriptor runnerDesc = runnerRegistry.getDescriptor(runnerId);
    final IRunner runner = runnerDesc.getRunner();
    final RunConfiguration config = runner.createConfiguration();
    config.setName(runnerHelper.computeConfigurationName(runnerId, moduleToRun));
    config.setRunnerId(runnerId);
    config.setRuntimeEnvironment(runnerDesc.getEnvironment());
    config.setImplementationId(implementationId);
    config.setUserSelection(moduleToRun);
    if (null != SystemLoaderInfo.fromString(systemLoader)) {
        config.setSystemLoader(systemLoader);
    }
    computeDerivedValues(config);
    return config;
}
Also used : IRunnerDescriptor(org.eclipse.n4js.runner.extension.IRunnerDescriptor)

Example 2 with IRunnerDescriptor

use of org.eclipse.n4js.runner.extension.IRunnerDescriptor in project n4js by eclipse.

the class HeadlessRunner method startRunner.

/**
 * Actually start the requested file with the chosen runner. Workspace from headlesCompiler should be configured
 * before calling this method.
 *
 * @param runner
 *            the runner to be used
 * @param implementationId
 *            to be used for API-IMPL projects
 * @param systemLoader
 *            to be used when loading the modules
 * @param locationToRun
 *            location of the code to be executed
 * @param targetPlatformInstallLocation
 *            location for externally installed node_modules
 * @throws ExitCodeException
 *             in cases of errors
 */
public void startRunner(String runner, String implementationId, String systemLoader, URI locationToRun, File targetPlatformInstallLocation) throws ExitCodeException {
    IRunnerDescriptor runnerDescriptor = checkRunner(runner);
    logger.info("Using runner :" + runnerDescriptor.getId());
    RunConfiguration runConfiguration = null;
    try {
        if (targetPlatformInstallLocation != null) {
            runConfiguration = runnerFrontEnd.createConfiguration(runnerDescriptor.getId(), implementationId, systemLoader, locationToRun, targetPlatformInstallLocation.toPath().resolve("node_modules").toAbsolutePath().toString());
        } else {
            runConfiguration = runnerFrontEnd.createConfiguration(runnerDescriptor.getId(), implementationId, systemLoader, locationToRun);
        }
    } catch (java.lang.IllegalStateException e2) {
        logger.error(Throwables.getStackTraceAsString(e2));
        throw new ExitCodeException(EXITCODE_RUNNER_STOPPED_WITH_ERROR, "Cannot create run configuration.", e2);
    }
    try {
        Process process = runnerFrontEnd.run(runConfiguration);
        int exit = process.waitFor();
        if (exit != 0) {
            throw new ExitCodeException(EXITCODE_RUNNER_STOPPED_WITH_ERROR, "The spawned runner '" + runnerDescriptor.getId() + "' exited with code=" + exit);
        }
    } catch (InterruptedException e1) {
        logger.error(Throwables.getStackTraceAsString(e1));
        throw new ExitCodeException(EXITCODE_RUNNER_STOPPED_WITH_ERROR, "The spawned runner exited by throwing an exception", e1);
    }
}
Also used : RunConfiguration(org.eclipse.n4js.runner.RunConfiguration) IRunnerDescriptor(org.eclipse.n4js.runner.extension.IRunnerDescriptor) ExitCodeException(org.eclipse.n4js.hlc.base.ExitCodeException)

Example 3 with IRunnerDescriptor

use of org.eclipse.n4js.runner.extension.IRunnerDescriptor in project n4js by eclipse.

the class SupportingRunnerPropertyTester method test.

/**
 * Check if given receiver object is supported by given runner. Runner is specified by first arguments in args
 * parameter which is expected to be runner key value.
 *
 * @param receiver
 *            is either {@link FileEditorInput} or {@link IFile} to be check against runner.
 * @param property
 *            used to verify callers are invoking correct tester.
 * @param args
 *            expected to contain {@link String} representing runner key of the runner to test.
 * @param expectedValue
 *            not really used
 */
@Override
public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) {
    if (!PROPERTY_IS_SUPPORTING_RUNNER.equals(property)) {
        LOGGER.debug("invoked wrong property to test : " + property);
        return false;
    }
    // Input is neither a file nor file editor input.
    final Optional<IFile> file = getFileFromInput(receiver);
    if (!file.isPresent()) {
        return false;
    }
    // Cannot locate generated file, what to run?
    if (!generatedFileLocator.tryGetGeneratedSourceForN4jsFile(file.get()).isPresent()) {
        return false;
    }
    final Object arg0 = args[0];
    if (!(arg0 instanceof String)) {
        LOGGER.debug("invalid runner key value, should be String");
        return false;
    }
    final String runnerId = arg0.toString();
    final IRunnerDescriptor runnerDesc;
    try {
        runnerDesc = runnerRegistry.getDescriptor(runnerId);
    } catch (Exception e) {
        LOGGER.debug("invalid runner key value, no runner found for id: " + runnerId);
        return false;
    }
    final List<RuntimeEnvironment> compatibleRuntimeEnvironmets = newArrayList();
    try {
        compatibleRuntimeEnvironmets.addAll(findCompatibleRuntimeEnvironments(file.get()));
    } catch (final DependencyCycleDetectedException | InsolvableRuntimeEnvironmentException e) {
        LOGGER.info(e.getMessage());
        return false;
    }
    // TODO IDE-1351 remove the following hack once the library manager is in place
    if ("org.eclipse.n4js.runner.nodejs.NODEJS".equals(runnerDesc.getId())) {
        // the node-runner supports running without a custom runtime environment in the workspace
        final boolean haveCustomNodeRuntimeEnvironment = hRuntimeEnvironments.findRuntimeEnvironmentProject(RuntimeEnvironment.NODEJS).isPresent();
        if (!haveCustomNodeRuntimeEnvironment)
            return true;
    // otherwise:
    // there is a custom Node.js runtime environment -> continue with the ordinary checks ...
    }
    // TODO IDE-1393 connect testers with extension point
    if (!compatibleRuntimeEnvironmets.isEmpty() && "RE_NodeJS_Mangelhaft".equals(compatibleRuntimeEnvironmets.get(0).getProjectId())) {
        return true;
    }
    final boolean runnerToTestIsCompatible = compatibleRuntimeEnvironmets.contains(runnerDesc.getEnvironment());
    if (!runnerToTestIsCompatible) {
        LOGGER.debug("Runner with id '" + runnerId + "' does not support running selected file.");
        return false;
    }
    return true;
}
Also used : IFile(org.eclipse.core.resources.IFile) RuntimeEnvironment(org.eclipse.n4js.runner.extension.RuntimeEnvironment) IRunnerDescriptor(org.eclipse.n4js.runner.extension.IRunnerDescriptor) InsolvableRuntimeEnvironmentException(org.eclipse.n4js.runner.exceptions.InsolvableRuntimeEnvironmentException) DependencyCycleDetectedException(org.eclipse.n4js.runner.exceptions.DependencyCycleDetectedException) InsolvableRuntimeEnvironmentException(org.eclipse.n4js.runner.exceptions.InsolvableRuntimeEnvironmentException) DependencyCycleDetectedException(org.eclipse.n4js.runner.exceptions.DependencyCycleDetectedException)

Example 4 with IRunnerDescriptor

use of org.eclipse.n4js.runner.extension.IRunnerDescriptor in project n4js by eclipse.

the class RunnerFrontEnd method createXpectOutputTestConfiguration.

/**
 * Create runner-config customized for this Xpect test. cf. org.eclipse.n4js.xpect.XpectN4JSES5TranspilerHelper
 */
public RunConfiguration createXpectOutputTestConfiguration(String runnerId, String userSelectionNodePathResolvableTargetFileName, SystemLoaderInfo systemLoader, String additionalPath) {
    final IRunnerDescriptor runnerDesc = runnerRegistry.getDescriptor(runnerId);
    final IRunner runner = runnerDesc.getRunner();
    final RunConfiguration config = runner.createConfiguration();
    config.setName(runnerId + "__" + userSelectionNodePathResolvableTargetFileName);
    config.setRuntimeEnvironment(runnerDesc.getEnvironment());
    config.setImplementationId(null);
    config.setRunnerId(runnerId);
    config.setSystemLoader(systemLoader.getId());
    config.setUseCustomBootstrap(true);
    config.setCoreProjectPaths(Lists.newArrayList(additionalPath));
    config.setExecutionData(RunConfiguration.EXEC_DATA_KEY__USER_SELECTION, userSelectionNodePathResolvableTargetFileName);
    config.setExecutionData(RunConfiguration.EXEC_DATA_KEY__INIT_MODULES, config.getInitModules());
    IRunner preparedRunner = runnerRegistry.getRunner(config);
    preparedRunner.prepareConfiguration(config);
    return config;
}
Also used : IRunnerDescriptor(org.eclipse.n4js.runner.extension.IRunnerDescriptor)

Aggregations

IRunnerDescriptor (org.eclipse.n4js.runner.extension.IRunnerDescriptor)4 IFile (org.eclipse.core.resources.IFile)1 ExitCodeException (org.eclipse.n4js.hlc.base.ExitCodeException)1 RunConfiguration (org.eclipse.n4js.runner.RunConfiguration)1 DependencyCycleDetectedException (org.eclipse.n4js.runner.exceptions.DependencyCycleDetectedException)1 InsolvableRuntimeEnvironmentException (org.eclipse.n4js.runner.exceptions.InsolvableRuntimeEnvironmentException)1 RuntimeEnvironment (org.eclipse.n4js.runner.extension.RuntimeEnvironment)1