import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
return false;
}
- private Collection<IProjectFeatureExtension> sortTopologically(Collection<IProjectFeatureExtension> toSort) {
- ArrayList<IProjectFeatureExtension> sorted = new ArrayList<IProjectFeatureExtension>(toSort);
- Collections.sort(sorted, new Comparator<IProjectFeatureExtension>() {
- Set<IProjectFeatureExtension> visited = new HashSet<IProjectFeatureExtension>();
- @Override
- public int compare(IProjectFeatureExtension e1, IProjectFeatureExtension e2) {
- visited.clear();
- if (deepRequires(visited, e1, e2))
- return 1;
- visited.clear();
- if (deepRequires(visited, e2, e1))
- return -1;
- return 0;
+ private void requiresDFS(IProjectFeatureExtension ext, ArrayList<IProjectFeatureExtension> result, Set<IProjectFeatureExtension> visited) {
+ if(visited.add(ext)) {
+ Set<IProjectFeatureExtension> reqs = required.getValues(ext);
+ if(reqs != null) {
+ for(IProjectFeatureExtension req : reqs) {
+ requiresDFS(req, result, visited);
+ }
}
- });
- return sorted;
+ result.add(ext);
+ }
+ }
+
+ private Collection<IProjectFeatureExtension> sortTopologically(Collection<IProjectFeatureExtension> toSort) {
+ ArrayList<IProjectFeatureExtension> result = new ArrayList<>();
+ Set<IProjectFeatureExtension> visited = new HashSet<>();
+ for(IProjectFeatureExtension ext : toSort) {
+ requiresDFS(ext, result, visited);
+ }
+ return result;
}
private Collection<IProjectFeatureExtension> requiredExtensions(IProjectFeatureExtension[] allExtensions, Collection<IProjectFeatureExtension> includedExtensions) throws ProjectException {
if (injectionTargetExt != null) {
changed = true;
includedProjectFeatureIds.add(ext.getId());
- result.add(ext);
+ if(!result.contains(ext))
+ result.add(ext);
required.add(injectionTargetExt, ext);
}
}
String description = StringUtils.safeString(el.getAttribute("description"));
boolean published = "true".equalsIgnoreCase(el.getAttribute("published"));
Collection<ProjectFeatureReference> requires = readProjectFeatureReferenceCollection(el, "requires");
- Collection<InjectedDependency> injections = readInjectedDependencies(el);
+ Collection<InjectedDependency> injections = readInjectedDependencies(el, id);
Collection<GroupReference> installGroups = readGroupReferenceCollection(el, "installGroup");
ProjectFeatureExtension ext = new ProjectFeatureExtension(el, id, label, description, published, requires, injections, installGroups);
this.extensions = newExtensions.toArray(new IProjectFeatureExtension[newExtensions.size()]);
}
- private Collection<InjectedDependency> readInjectedDependencies(IConfigurationElement element) {
+ private Collection<InjectedDependency> readInjectedDependencies(IConfigurationElement element, String id) {
Collection<InjectedDependency> result = new ArrayList<InjectedDependency>();
for (IConfigurationElement child : element.getChildren(INJECT_DEPENDENCY)) {
- String id = StringUtils.safeString(child.getAttribute("id"));
- if (id.isEmpty())
- // Invalid extension
- return null;
-
String targetId = StringUtils.safeString(child.getAttribute("targetId"));
if (targetId.isEmpty())
// Invalid extension
return null;
+
+ result.add(new InjectedDependency(new ProjectFeatureReference(id, false), new ProjectFeatureReference(targetId, false)));
+
}
return result;