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);
}
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();
}
Aggregations