1 11 package org.eclipse.pde.internal.core.builders; 12 13 import java.util.Vector ; 14 15 import org.eclipse.osgi.util.NLS; 16 import org.eclipse.pde.core.plugin.IPlugin; 17 import org.eclipse.pde.core.plugin.IPluginImport; 18 import org.eclipse.pde.core.plugin.IPluginModel; 19 import org.eclipse.pde.core.plugin.IPluginModelBase; 20 import org.eclipse.pde.core.plugin.PluginRegistry; 21 import org.eclipse.pde.internal.core.PDECoreMessages; 22 23 public class DependencyLoopFinder { 24 25 public static DependencyLoop [] findLoops(IPlugin root) { 26 return findLoops(root, null); 27 } 28 29 public static DependencyLoop [] findLoops(IPlugin root, IPlugin [] candidates) { 30 return findLoops(root, candidates, false); 31 } 32 33 public static DependencyLoop [] findLoops(IPlugin root, IPlugin [] candidates, boolean onlyCandidates) { 34 Vector loops = new Vector (); 35 36 Vector path = new Vector (); 37 findLoops(loops, path, root, candidates, onlyCandidates, new Vector ()); 38 return (DependencyLoop[])loops.toArray(new DependencyLoop[loops.size()]); 39 } 40 41 private static void findLoops( 42 Vector loops, 43 Vector path, 44 IPlugin subroot, 45 IPlugin[] candidates, 46 boolean onlyCandidates, 47 Vector exploredPlugins) { 48 if (path.size() > 0) { 49 52 IPlugin root = (IPlugin) path.elementAt(0); 53 if (isEquivalent(root, subroot)) { 54 DependencyLoop loop = new DependencyLoop(); 56 loop.setMembers((IPlugin[]) path.toArray(new IPlugin[path.size()])); 57 int no = loops.size() + 1; 58 loop.setName(NLS.bind(PDECoreMessages.Builders_DependencyLoopFinder_loopName, ("" + no))); loops.add(loop); 60 return; 61 } 62 for (int i = 1; i < path.size(); i++) { 65 IPlugin node = (IPlugin) path.elementAt(i); 66 if (isEquivalent(subroot, node)) { 67 return; 69 } 70 } 71 } 72 Vector newPath = path.size() > 0 ? ((Vector ) path.clone()) : path; 73 newPath.add(subroot); 74 75 if (!onlyCandidates) { 76 IPluginImport[] iimports = subroot.getImports(); 77 for (int i = 0; i < iimports.length; i++) { 78 IPluginImport iimport = iimports[i]; 79 String id = iimport.getId(); 80 if (id == null) 82 continue; 83 if (!exploredPlugins.contains(id)) { 84 IPlugin child = findPlugin(id); 91 if (child != null) { 92 int oldLoopSize = loops.size(); 94 95 findLoops(loops, newPath, child, null, false, exploredPlugins); 96 97 int newLoopsSize = loops.size(); 99 100 if (oldLoopSize == newLoopsSize) { exploredPlugins.add(id); 103 } 104 } 105 } 106 107 } 108 109 } 110 if (candidates != null) { 111 for (int i = 0; i < candidates.length; i++) { 112 IPlugin candidate = candidates[i]; 113 114 int oldLoopSize = loops.size(); 116 117 findLoops(loops, newPath, candidate, null, false, exploredPlugins); 118 119 int newLoopsSize = loops.size(); 121 122 if (oldLoopSize == newLoopsSize) { exploredPlugins.add(candidate.getId()); 125 } 126 } 127 } 128 129 } 130 131 private static IPlugin findPlugin(String id) { 132 IPluginModelBase childModel = PluginRegistry.findModel(id); 133 if (childModel == null || !(childModel instanceof IPluginModel)) return null; 134 return (IPlugin)childModel.getPluginBase(); 135 } 136 137 private static boolean isEquivalent(IPlugin left, IPlugin right) { 138 return left.getId().equals(right.getId()); 139 } 140 } 141 | Popular Tags |