use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.
the class RuntimeEnvironmentsHelper method containsAllCompatible.
/**
* Compares two provided lists of {@link IN4JSProject}. Assumes both contain instances of type
* {@link ProjectType#RUNTIME_ENVIRONMENT}. Checks if either all elements of latter list are contained in first one,
* or if all elements of latter one are compatible (are in extend chain) of elements of the first one. If this check
* holds returns true, otherwise false (also when either of the lists is empty)
*
* @param runnerEnvironments
* lists which must contain (might be indirectly via extend chain) elements of latter list
* @param requiredEnvironments
* lists that is checked if it is supported by first one
* @return true if all elements of latter list are (directly or indirectly) compatible with elements of the first
* list.
*/
public boolean containsAllCompatible(List<RuntimeEnvironment> runnerEnvironments, List<RuntimeEnvironment> requiredEnvironments) {
if (runnerEnvironments.isEmpty() || requiredEnvironments.isEmpty()) {
LOGGER.debug("cannot compare empty runtime environments lists");
return false;
}
if (runnerEnvironments.containsAll(requiredEnvironments))
return true;
// check compatible / extend feature
boolean result = true;
List<IN4JSProject> allRuntimeEnvironments = from(getAllProjects()).filter(p -> isRuntimeEnvironemnt(p)).toList();
Map<IN4JSProject, List<String>> reExtendedEnvironments = allRuntimeEnvironments.stream().map(re -> getExtendedRuntimeEnvironmentsNames(re, allRuntimeEnvironments)).collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue()));
// if runnerEnvironments (first param) would be single IN4JSProject (instead of collection)
// code below could be simplified
Iterator<RuntimeEnvironment> iterRuntimeEnvironment = runnerEnvironments.iterator();
while (result && iterRuntimeEnvironment.hasNext()) {
RuntimeEnvironment re = iterRuntimeEnvironment.next();
List<IN4JSProject> listExtendedEnvironments = reExtendedEnvironments.keySet().stream().filter(p -> p.getProjectId().equals(re.getProjectId())).collect(Collectors.toList());
if (listExtendedEnvironments.size() != 1) {
LOGGER.debug("Multiple projects with name " + re.getProjectId() + " : " + listExtendedEnvironments.stream().map(p -> p.getProjectId()).reduce(new String(), (String r, String e) -> r += ", " + e));
LOGGER.error("Cannot obtain project for name " + re.getProjectId());
return false;
}
IN4JSProject extendedRuntimeEnvironment = listExtendedEnvironments.get(0);
List<String> listExtendedEnvironemntsNames = reExtendedEnvironments.get(extendedRuntimeEnvironment);
result = result && requiredEnvironments.stream().map(bre -> {
return bre.getProjectId();
}).allMatch(breName -> listExtendedEnvironemntsNames.contains(breName));
}
return result;
}
use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.
the class RuntimeEnvironmentsHelper method recursiveProvidedRuntimeLibrariesCollector.
/**
* Maps passed collection of {@link IN4JSSourceContainerAware} to list of {@link IN4JSProject}, that is instances of
* {@link IN4JSProject} project are returned as they are, while instances of {@link IN4JSArchive} have contained
* project extracted. For each result of that transformation, examines its
* {@link IN4JSProject#getProvidedRuntimeLibraries()} to check if they pass predicate test. Instances that do are
* stored in the passed collection.
*
* Calls itself recursively on each processed element, accumulating results in collection passed along call chains.
*
* @param runtimeLibraries
* list of source containers to analyze (usually of type {@link ProjectType#RUNTIME_LIBRARY})
* @param collection
* where provided runtime libraries are collected
* @param predicate
* to test if provided project is of type {@link ProjectType#RUNTIME_LIBRARY}
*/
private void recursiveProvidedRuntimeLibrariesCollector(com.google.common.collect.ImmutableList<? extends IN4JSSourceContainerAware> runtimeLibraries, Collection<IN4JSProject> collection, Predicate<IN4JSProject> predicate) {
runtimeLibraries.forEach(runtimeLibrary -> {
IN4JSProject project = (extractProject(runtimeLibrary));
if (predicate.test(project))
collection.add(project);
recursiveProvidedRuntimeLibrariesCollector(project.getProvidedRuntimeLibraries(), collection, predicate);
});
}
use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.
the class RuntimeEnvironmentsHelper method getEnvironemntWithAncestorsRecursive.
private void getEnvironemntWithAncestorsRecursive(IN4JSProject project, Set<IN4JSProject> environemtns) {
if (!project.getProjectType().equals(ProjectType.RUNTIME_ENVIRONMENT)) {
return;
}
Optional<IN4JSSourceContainerAware> maybePArent = project.getExtendedRuntimeEnvironment();
if (maybePArent.isPresent()) {
IN4JSProject parent = (IN4JSProject) maybePArent.get();
environemtns.add(parent);
getEnvironemntWithAncestorsRecursive(parent, environemtns);
}
return;
}
use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.
the class RunnerHelper method recursiveExtendedREsCollector.
/**
* Collects transitive collection of project extended RuntimeEnvironemnts
*
* @see RuntimeEnvironmentsHelper#recursiveDependencyCollector
*/
public void recursiveExtendedREsCollector(IN4JSSourceContainerAware sourceContainer, Collection<IN4JSProject> addHere, Iterable<IN4JSProject> projects) {
final IN4JSProject project = extractProject(sourceContainer);
if (project.getProjectType().equals(ProjectType.RUNTIME_ENVIRONMENT)) {
addHere.add(project);
// TODO RLs can extend each other, should we use recursive RL deps collector?
// if RLs extend each other and are provided by REs in hierarchy we will collect them anyway
// if RLs extend each other but are from independent REs, that is and error?
project.getProvidedRuntimeLibraries().forEach(rl -> addHere.add(extractProject(rl)));
Optional<String> ep = project.getExtendedRuntimeEnvironmentId();
Optional<IN4JSProject> extendedRE = Optional.absent();
if (ep.isPresent()) {
extendedRE = findRuntimeEnvironemtnWithName(ep.get(), projects);
}
if (extendedRE.isPresent()) {
IN4JSProject e = extendedRE.get();
recursiveExtendedREsCollector(e, addHere, projects);
}
}
}
use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.
the class N4JSAllContainersState method tryValidateManifest.
private void tryValidateManifest(final IResourceDelta delta) {
final String fullPath = delta.getFullPath().toString();
final URI folderUri = URI.createPlatformResourceURI(fullPath, true);
final IN4JSProject project = core.findProject(folderUri).orNull();
if (null != project && project.exists()) {
final URI manifestLocation = project.getManifestLocation().orNull();
if (null != manifestLocation) {
final IFile manifest = delta.getResource().getProject().getFile(N4MF_MANIFEST);
final ResourceSet resourceSet = core.createResourceSet(Optional.of(project));
final Resource resource = resourceSet.getResource(manifestLocation, true);
final Job job = Job.create("", monitor -> {
validatorExtension.updateValidationMarkers(manifest, resource, ALL, monitor);
return OK_STATUS;
});
job.setPriority(INTERACTIVE);
job.schedule();
}
}
}
Aggregations