]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Project feature dependency injection is broken 69/369/3
authorAntti Villberg <antti.villberg@semantum.fi>
Mon, 20 Mar 2017 06:48:52 +0000 (08:48 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 20 Mar 2017 07:38:14 +0000 (09:38 +0200)
refs #7027

Change-Id: I97bef3d5be9bf2689de25919d021a3ab005137a4

bundles/org.simantics.project/src/org/simantics/project/ProjectFeatures.java
bundles/org.simantics.project/src/org/simantics/project/internal/ProjectFeatureRegistry.java

index 7fedc55d11ae8a5713f83e6e5315dbc192cb4e7b..bb2ba5c2c411310fb1971e6609dce41fcf2f814d 100644 (file)
@@ -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<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 {
@@ -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);
                             }
                         }
index e861bc09dc47e81f3b1857889c835db091837048..b07304ed1ce3b8d39af3c5c8d06b1dd5cc6ccf3e 100644 (file)
@@ -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<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);
@@ -111,19 +111,17 @@ public class ProjectFeatureRegistry implements IProjectFeatureRegistry, IExtensi
         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;