1 11 package org.eclipse.pde.internal.builders; 12 13 17 18 import java.util.*; 19 20 import org.eclipse.osgi.util.NLS; 21 import org.eclipse.pde.core.plugin.*; 22 import org.eclipse.pde.internal.*; 23 import org.eclipse.pde.internal.core.*; 24 25 public class DependencyLoopFinder { 26 27 public static DependencyLoop [] findLoops(IPlugin root) { 28 return findLoops(root, null); 29 } 30 31 public static DependencyLoop [] findLoops(IPlugin root, IPlugin [] candidates) { 32 return findLoops(root, candidates, false); 33 } 34 35 public static DependencyLoop [] findLoops(IPlugin root, IPlugin [] candidates, boolean onlyCandidates) { 36 Vector loops = new Vector(); 37 38 Vector path = new Vector(); 39 findLoops(loops, path, root, candidates, onlyCandidates, new Vector()); 40 return (DependencyLoop[])loops.toArray(new DependencyLoop[loops.size()]); 41 } 42 43 private static void findLoops( 44 Vector loops, 45 Vector path, 46 IPlugin subroot, 47 IPlugin[] candidates, 48 boolean onlyCandidates, 49 Vector exploredPlugins) { 50 if (path.size() > 0) { 51 54 IPlugin root = (IPlugin) path.elementAt(0); 55 if (isEquivalent(root, subroot)) { 56 DependencyLoop loop = new DependencyLoop(); 58 loop.setMembers((IPlugin[]) path.toArray(new IPlugin[path.size()])); 59 int no = loops.size() + 1; 60 loop.setName(NLS.bind(PDEMessages.Builders_DependencyLoopFinder_loopName, ("" + no))); loops.add(loop); 62 return; 63 } 64 for (int i = 1; i < path.size(); i++) { 67 IPlugin node = (IPlugin) path.elementAt(i); 68 if (isEquivalent(subroot, node)) { 69 return; 71 } 72 } 73 } 74 Vector newPath = path.size() > 0 ? ((Vector) path.clone()) : path; 75 newPath.add(subroot); 76 77 if (!onlyCandidates) { 78 IPluginImport[] iimports = subroot.getImports(); 79 for (int i = 0; i < iimports.length; i++) { 80 IPluginImport iimport = iimports[i]; 81 String id = iimport.getId(); 82 if (id == null) 84 continue; 85 if (!exploredPlugins.contains(id)) { 86 IPlugin child = findPlugin(id); 93 if (child != null) { 94 int oldLoopSize = loops.size(); 96 97 findLoops(loops, newPath, child, null, false, exploredPlugins); 98 99 int newLoopsSize = loops.size(); 101 102 if (oldLoopSize == newLoopsSize) { exploredPlugins.add(id); 105 } 106 } 107 } 108 109 } 110 111 } 112 if (candidates != null) { 113 for (int i = 0; i < candidates.length; i++) { 114 IPlugin candidate = candidates[i]; 115 116 int oldLoopSize = loops.size(); 118 119 findLoops(loops, newPath, candidate, null, false, exploredPlugins); 120 121 int newLoopsSize = loops.size(); 123 124 if (oldLoopSize == newLoopsSize) { exploredPlugins.add(candidate.getId()); 127 } 128 } 129 } 130 131 } 132 133 private static IPlugin findPlugin(String id) { 134 IPluginModelBase childModel = PDECore.getDefault().getModelManager().findPlugin(id, null, 0); 135 if (childModel==null || !(childModel instanceof IPluginModel)) return null; 136 return (IPlugin)childModel.getPluginBase(); 137 } 138 139 private static boolean isEquivalent(IPlugin left, IPlugin right) { 140 return left.getId().equals(right.getId()); 141 } 142 } 143 | Popular Tags |