1 11 package org.eclipse.pde.internal.core; 12 13 import java.io.*; 14 import java.net.*; 15 16 import org.eclipse.core.runtime.*; 17 import org.eclipse.osgi.service.resolver.*; 18 import org.eclipse.pde.core.plugin.*; 19 import org.eclipse.pde.internal.core.plugin.*; 20 21 24 public class TargetPlatformRegistryLoader { 25 26 private static final String KEY_SCANNING_PROBLEMS = 27 "ExternalModelManager.scanningProblems"; private static String getMode(URL[] urls) { 29 String targetMode = "2.1"; for (int i = 0; i < urls.length; i++) { 31 if (urls[i].getFile().indexOf("org.eclipse.osgi") != -1) targetMode = null; 33 } 34 return targetMode; 35 } 36 37 public static void load(URL[] urls, PDEState state, IProgressMonitor monitor) { 38 String targetMode = getMode(urls); 39 state.setTargetMode(targetMode); 40 monitor.beginTask("", urls.length); for (int i = 0; i < urls.length; i++) { 42 state.addBundle(new File(urls[i].getFile())); 43 monitor.worked(1); 44 } 45 } 46 47 public static IPluginModelBase[] loadModels(URL[] urls, boolean resolve, PDEState state, IProgressMonitor monitor) { 48 if (monitor == null) 49 monitor = new NullProgressMonitor(); 50 51 monitor.beginTask(PDECore.getResourceString("TargetPlatformRegistryLoader.parsing"), 10); load(urls, state, new SubProgressMonitor(monitor, 8)); 53 54 state.resolveState(); 55 monitor.worked(1); 56 57 if (resolve) { 58 logResolutionErrors(state.getState()); 59 } 60 61 BundleDescription[] bundleDescriptions = resolve ? state.getState().getResolvedBundles() : state.getState().getBundles(); 62 IPluginModelBase[] models = new IPluginModelBase[bundleDescriptions.length]; 63 for (int i = 0; i < bundleDescriptions.length; i++) { 64 monitor.subTask(bundleDescriptions[i].getSymbolicName()); 65 models[i] = createModelFromDescription(bundleDescriptions[i], state); 66 } 67 monitor.done(); 68 return models; 69 } 70 71 private static void logResolutionErrors(State state) { 72 MultiStatus errors = 73 new MultiStatus( 74 PDECore.getPluginId(), 75 1, 76 PDECore.getResourceString(KEY_SCANNING_PROBLEMS), 77 null); 78 79 StateHelper helper = acquireStateHelper(); 80 BundleDescription[] all = state.getBundles(); 81 for (int i = 0; i < all.length; i++) { 82 if (!all[i].isResolved()) { 83 VersionConstraint[] unsatisfiedConstraints = helper.getUnsatisfiedConstraints(all[i]); 84 if (unsatisfiedConstraints.length == 0) { 85 BundleDescription activeBundle = findActiveBundle(state, all[i].getSymbolicName()); 86 if (activeBundle == null) { 87 String message = PDECore.getFormattedMessage("ECLIPSE_IGNORE", all[i].getLocation()); errors.add(new Status(IStatus.ERROR, all[i].getSymbolicName(), IStatus.WARNING, message, null)); 89 } else { 90 String message = PDECore.getFormattedMessage("ECLIPSE_OTHER_VERSION", new String [] {all[i].getLocation(), activeBundle.getLocation()}); errors.add(new Status(IStatus.INFO, all[i].getSymbolicName(), IStatus.INFO, message, null)); 92 } 93 } else { 94 for (int j = 0; j < unsatisfiedConstraints.length; j++) { 95 String message = getResolutionFailureMessage(unsatisfiedConstraints[j]); 96 errors.add(new Status(IStatus.WARNING, all[i].getSymbolicName(), IStatus.WARNING, message, null)); 97 } 98 } 99 } 100 } 101 if (errors.getChildren().length > 0) 102 PDECore.log(errors); 103 104 } 105 106 private static BundleDescription findActiveBundle(State state, String symbolicName) { 107 BundleDescription[] bundles = state.getBundles(symbolicName); 108 for (int i = 0; i < bundles.length; i++) { 109 if (bundles[i].isResolved()) 110 return bundles[i]; 111 } 112 return null; 113 } 114 115 public static String getResolutionFailureMessage(VersionConstraint unsatisfied) { 116 if (unsatisfied.isResolved()) 117 throw new IllegalArgumentException (); 118 if (unsatisfied instanceof PackageSpecification) 119 return PDECore.getFormattedMessage("ECLIPSE_MISSING_IMPORTED_PACKAGE", toString(unsatisfied)); if (unsatisfied instanceof BundleSpecification) { 121 if (((BundleSpecification) unsatisfied).isOptional()) 122 return PDECore.getFormattedMessage("ECLIPSE_MISSING_OPTIONAL_REQUIRED_BUNDLE", toString(unsatisfied)); return PDECore.getFormattedMessage("ECLIPSE_MISSING_REQUIRED_BUNDLE", toString(unsatisfied)); } 125 return PDECore.getFormattedMessage("ECLIPSE_MISSING_HOST", toString(unsatisfied)); } 127 128 private static String toString(VersionConstraint constraint) { 129 VersionRange versionRange = constraint.getVersionRange(); 130 if (versionRange == null || versionRange.getMinimum() != null) 131 return constraint.getName(); 132 return constraint.getName() + '_' + versionRange; 133 } 134 135 136 public static IPluginModelBase[] loadModels(URL[] urls, boolean resolve, IProgressMonitor monitor) { 137 PDEState state = new PDEState(); 138 return loadModels(urls, resolve, state, monitor); 139 } 140 141 145 private static IPluginModelBase createModelFromDescription(BundleDescription description, PDEState state) { 146 ExternalPluginModelBase model = null; 147 if (description.getHost() == null) 148 model = new ExternalPluginModel(); 149 else 150 model = new ExternalFragmentModel(); 151 model.load(description, state); 152 return model; 153 } 154 155 private static StateHelper acquireStateHelper(){ 156 return PDECore.getDefault().acquirePlatform().getStateHelper(); 157 } 158 159 160 } 161 | Popular Tags |