From: Antti Villberg Date: Mon, 20 Mar 2017 06:48:52 +0000 (+0200) Subject: Project feature dependency injection is broken X-Git-Tag: v1.28.0~48 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=19c8e2d3eba80a750c6fb92de11a209a8132f8c7;p=simantics%2Fplatform.git Project feature dependency injection is broken refs #7027 Change-Id: I97bef3d5be9bf2689de25919d021a3ab005137a4 --- diff --git a/bundles/org.simantics.project/src/org/simantics/project/ProjectFeatures.java b/bundles/org.simantics.project/src/org/simantics/project/ProjectFeatures.java index 7fedc55d1..bb2ba5c2c 100644 --- a/bundles/org.simantics.project/src/org/simantics/project/ProjectFeatures.java +++ b/bundles/org.simantics.project/src/org/simantics/project/ProjectFeatures.java @@ -14,8 +14,6 @@ package org.simantics.project; 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; @@ -188,22 +186,25 @@ public class ProjectFeatures { return false; } - private Collection sortTopologically(Collection toSort) { - ArrayList sorted = new ArrayList(toSort); - Collections.sort(sorted, new Comparator() { - Set visited = new HashSet(); - @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 result, Set visited) { + if(visited.add(ext)) { + Set reqs = required.getValues(ext); + if(reqs != null) { + for(IProjectFeatureExtension req : reqs) { + requiresDFS(req, result, visited); + } } - }); - return sorted; + result.add(ext); + } + } + + private Collection sortTopologically(Collection toSort) { + ArrayList result = new ArrayList<>(); + Set visited = new HashSet<>(); + for(IProjectFeatureExtension ext : toSort) { + requiresDFS(ext, result, visited); + } + return result; } private Collection requiredExtensions(IProjectFeatureExtension[] allExtensions, Collection includedExtensions) throws ProjectException { @@ -234,7 +235,8 @@ public class ProjectFeatures { if (injectionTargetExt != null) { changed = true; includedProjectFeatureIds.add(ext.getId()); - result.add(ext); + if(!result.contains(ext)) + result.add(ext); required.add(injectionTargetExt, ext); } } diff --git a/bundles/org.simantics.project/src/org/simantics/project/internal/ProjectFeatureRegistry.java b/bundles/org.simantics.project/src/org/simantics/project/internal/ProjectFeatureRegistry.java index e861bc09d..b07304ed1 100644 --- a/bundles/org.simantics.project/src/org/simantics/project/internal/ProjectFeatureRegistry.java +++ b/bundles/org.simantics.project/src/org/simantics/project/internal/ProjectFeatureRegistry.java @@ -94,7 +94,7 @@ public class ProjectFeatureRegistry implements IProjectFeatureRegistry, IExtensi String description = StringUtils.safeString(el.getAttribute("description")); boolean published = "true".equalsIgnoreCase(el.getAttribute("published")); Collection requires = readProjectFeatureReferenceCollection(el, "requires"); - Collection injections = readInjectedDependencies(el); + Collection injections = readInjectedDependencies(el, id); Collection installGroups = readGroupReferenceCollection(el, "installGroup"); ProjectFeatureExtension ext = new ProjectFeatureExtension(el, id, label, description, published, requires, injections, installGroups); @@ -111,19 +111,17 @@ public class ProjectFeatureRegistry implements IProjectFeatureRegistry, IExtensi this.extensions = newExtensions.toArray(new IProjectFeatureExtension[newExtensions.size()]); } - private Collection readInjectedDependencies(IConfigurationElement element) { + private Collection readInjectedDependencies(IConfigurationElement element, String id) { Collection result = new ArrayList(); 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;