Search in sources :

Example 1 with DependencyCycleDetectedException

use of org.eclipse.n4js.runner.exceptions.DependencyCycleDetectedException 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)

Aggregations

IFile (org.eclipse.core.resources.IFile)1 DependencyCycleDetectedException (org.eclipse.n4js.runner.exceptions.DependencyCycleDetectedException)1 InsolvableRuntimeEnvironmentException (org.eclipse.n4js.runner.exceptions.InsolvableRuntimeEnvironmentException)1 IRunnerDescriptor (org.eclipse.n4js.runner.extension.IRunnerDescriptor)1 RuntimeEnvironment (org.eclipse.n4js.runner.extension.RuntimeEnvironment)1