Search in sources :

Example 21 with IN4JSProject

use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.

the class ProjectCompareHelper method getImplementationID.

/**
 * Retrieves the implementation ID for an implementor of some API
 *
 * @param apiImplModule
 *            the implementor
 * @return implementation ID if applicable - unset if the parameter is not implementing an API or is itself from an
 *         API definition.
 */
public Optional<String> getImplementationID(TModule apiImplModule) {
    Optional<? extends IN4JSProject> opt = n4jsCore.findProject(apiImplModule.eResource().getURI());
    IN4JSProject implProject = opt.get();
    return implProject.getImplementationId();
}
Also used : IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject)

Example 22 with IN4JSProject

use of org.eclipse.n4js.projectModel.IN4JSProject 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 23 with IN4JSProject

use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.

the class RunnerFrontEnd method configureRuntimeEnvironment.

/**
 * Configures provided configuration based on the {@link RunConfiguration#getRuntimeEnvironment() runtime
 * environment} value it stores.
 *
 * Recomputes {@link RunConfiguration#getInitModules() init modules} and {@link RunConfiguration#getExecModule()
 * exec module} based on current state of the workspace.
 *
 * @param config
 *            the runtime configuration whose derived values are computed.
 */
public void configureRuntimeEnvironment(RunConfiguration config, Iterable<IN4JSProject> projects) {
    RuntimeEnvironment runtimeEnvironment = config.getRuntimeEnvironment();
    Optional<IN4JSProject> findRuntimeEnvironmentProject = hRuntimeEnvironments.findRuntimeEnvironmentProject(runtimeEnvironment, projects);
    if (findRuntimeEnvironmentProject.isPresent()) {
        IN4JSProject runtimeEnvironmentProject = findRuntimeEnvironmentProject.get();
        // 3) collect custom(!) init modules based on selected runtime environment
        final List<String> initModulePaths = getInitModulesPathsFrom(runtimeEnvironmentProject);
        config.setInitModules(initModulePaths);
        // 4) find compiled .js file to be executed first (the "executionModule" of the runtime environment)
        Optional<String> executionModule = getExecModulePathFrom(runtimeEnvironmentProject);
        if (executionModule.isPresent()) {
            config.setExecModule(executionModule.get());
        }
    }
}
Also used : RuntimeEnvironment(org.eclipse.n4js.runner.extension.RuntimeEnvironment) IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject)

Example 24 with IN4JSProject

use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.

the class RunnerFrontEnd method configureExecutionData.

/**
 * Configures execution data from user selection, init modules, and apiImplProjectMapping
 *
 * this should transform user selection into execution data, but concrete runner/tester may transform this further
 * into its own representation.
 *
 * Testers need to pass test discovery result. Runners need to pass module/class/method selection.
 */
private void configureExecutionData(RunConfiguration config) {
    final URI userSelection = config.getUserSelection();
    if (userSelection != null && (hasValidFileExtension(userSelection.toString()))) {
        final String userSelection_targetFileName = resourceNameComputer.generateFileDescriptor(userSelection, null);
        IN4JSProject project = resolveProject(userSelection);
        String base = AbstractSubGenerator.calculateProjectBasedOutputDirectory(project);
        config.setExecutionData(RunConfiguration.EXEC_DATA_KEY__USER_SELECTION, base + "/" + userSelection_targetFileName);
    } else {
        // this can happen if the RunConfiguration 'config' is actually a TestConfiguration, because then the user
        // selection is allowed to point to a project or folder (and method CompilerUtils#getModuleName() above
        // would throw an exception)
        config.setExecutionData(RunConfiguration.EXEC_DATA_KEY__USER_SELECTION, null);
    }
    config.setExecutionData(RunConfiguration.EXEC_DATA_KEY__INIT_MODULES, config.getInitModules());
    config.setExecutionData(RunConfiguration.EXEC_DATA_KEY__PROJECT_NAME_MAPPING, config.getApiImplProjectMapping());
}
Also used : IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) URI(org.eclipse.emf.common.util.URI)

Example 25 with IN4JSProject

use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.

the class RuntimeEnvironmentsHelper method recursiveCollectRlFromChain.

private void recursiveCollectRlFromChain(IN4JSProject runtimeEnvironment, Collection<IN4JSProject> collection) {
    Optional<String> extended = runtimeEnvironment.getExtendedRuntimeEnvironmentId();
    if (extended.isPresent()) {
        String id = extended.get();
        List<IN4JSProject> extendedRE = from(getAllProjects()).filter(p -> id.equals(p.getProjectId())).toList();
        if (extendedRE.isEmpty()) {
            return;
        }
        if (extendedRE.size() > 1) {
            LOGGER.debug("multiple projects match id " + id);
            LOGGER.error(new RuntimeException("Cannot obtain transitive list of provided libraries"));
            return;
        }
        IN4JSProject extendedRuntimeEnvironemnt = extendedRE.get(0);
        recursiveProvidedRuntimeLibrariesCollector(extendedRuntimeEnvironemnt.getProvidedRuntimeLibraries(), collection, p -> isRuntimeLibrary(p));
        recursiveCollectRlFromChain(extendedRuntimeEnvironemnt, collection);
    }
}
Also used : InsolvableRuntimeEnvironmentException(org.eclipse.n4js.runner.exceptions.InsolvableRuntimeEnvironmentException) Inject(com.google.inject.Inject) IN4JSCore(org.eclipse.n4js.projectModel.IN4JSCore) IN4JSSourceContainerAware(org.eclipse.n4js.projectModel.IN4JSSourceContainerAware) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Logger(org.apache.log4j.Logger) Optional(com.google.common.base.Optional) FluentIterable.from(com.google.common.collect.FluentIterable.from) Map(java.util.Map) RuntimeEnvironment(org.eclipse.n4js.runner.extension.RuntimeEnvironment) SoureContainerAwareDependencyTraverser(org.eclipse.n4js.validation.helper.SoureContainerAwareDependencyTraverser) Iterator(java.util.Iterator) Predicate(java.util.function.Predicate) Collection(java.util.Collection) IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) Set(java.util.Set) Collectors(java.util.stream.Collectors) ProjectType(org.eclipse.n4js.n4mf.ProjectType) DependencyCycleDetectedException(org.eclipse.n4js.runner.exceptions.DependencyCycleDetectedException) AbstractMap(java.util.AbstractMap) List(java.util.List) IN4JSArchive(org.eclipse.n4js.projectModel.IN4JSArchive) Entry(java.util.Map.Entry) Logger.getLogger(org.apache.log4j.Logger.getLogger) IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject)

Aggregations

IN4JSProject (org.eclipse.n4js.projectModel.IN4JSProject)93 URI (org.eclipse.emf.common.util.URI)32 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)13 List (java.util.List)11 Inject (com.google.inject.Inject)9 Map (java.util.Map)9 IProject (org.eclipse.core.resources.IProject)9 IN4JSCore (org.eclipse.n4js.projectModel.IN4JSCore)9 Optional (com.google.common.base.Optional)7 File (java.io.File)7 Collection (java.util.Collection)7 HashSet (java.util.HashSet)7 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)7 Set (java.util.Set)6 Collectors (java.util.stream.Collectors)6 IOException (java.io.IOException)5 IN4JSArchive (org.eclipse.n4js.projectModel.IN4JSArchive)5 IN4JSSourceContainer (org.eclipse.n4js.projectModel.IN4JSSourceContainer)5 FluentIterable.from (com.google.common.collect.FluentIterable.from)4