/** * Tests that resetting the target platform should work OK (i.e. is equivalent to the models in * the default target platform). * * @throws CoreException */ public void testResetTargetPlatform() throws Exception { ITargetDefinition definition = getDefaultTargetPlatorm(); Set urls = getAllBundleURLs(definition); Set fragments = new HashSet(); TargetBundle[] bundles = definition.getBundles(); for (int i = 0; i < bundles.length; i++) { if (bundles[i].isFragment()) { fragments.add(new File(bundles[i].getBundleInfo().getLocation()).toURL()); } } // current platform IPluginModelBase[] models = TargetPlatformHelper.getPDEState().getTargetModels(); // should be equivalent assertEquals("Should have same number of bundles", urls.size(), models.length); for (int i = 0; i < models.length; i++) { String location = models[i].getInstallLocation(); URL url = new File(location).toURL(); assertTrue("Missing plug-in " + location, urls.contains(url)); if (models[i].isFragmentModel()) { assertTrue("Missing fragmnet", fragments.remove(url)); } } assertTrue("Different number of fragments", fragments.isEmpty()); }
/** * Tests setting the target platform to empty. * * @throws CoreException */ public void testSetEmptyTargetPlatform() throws CoreException { try { setTargetPlatform(null); // current platform IPluginModelBase[] models = TargetPlatformHelper.getPDEState().getTargetModels(); assertEquals("Wrong number of bundles in empty target", 0, models.length); } finally { resetTargetPlatform(); } }
/** * Tests setting the target platform to the stored JDT feature test data * * @throws Exception */ public void testSetTargetPlatformToJdtFeature() throws Exception { try { // extract the feature IPath location = extractModifiedFeatures(); // org.eclipse.jdt_3.6.0.v20100105-0800-7z8VFR9FMTb52_pOyKHhoek1 ITargetDefinition target = getNewTarget(); ITargetLocation container = getTargetService() .newFeatureLocation( location.toOSString(), "org.eclipse.jdt", "3.6.0.v20100105-0800-7z8VFR9FMTb52_pOyKHhoek1"); target.setTargetLocations(new ITargetLocation[] {container}); setTargetPlatform(target); List expected = new ArrayList(); expected.add("org.eclipse.jdt"); expected.add("org.eclipse.jdt.launching"); // 2 versions of JUnit expected.add("org.junit"); expected.add("org.junit"); expected.add("org.junit4"); if (Platform.getOS().equals(Platform.OS_MACOSX)) { expected.add("org.eclipse.jdt.launching.macosx"); } // current platform IPluginModelBase[] models = TargetPlatformHelper.getPDEState().getTargetModels(); assertEquals("Wrong number of bundles in JDT feature", expected.size(), models.length); for (int i = 0; i < models.length; i++) { expected.remove(models[i].getPluginBase().getId()); assertTrue(models[i].isEnabled()); } Iterator iterator = expected.iterator(); while (iterator.hasNext()) { String name = (String) iterator.next(); System.err.println("Missing: " + name); } assertTrue("Wrong bundles in target platform", expected.isEmpty()); } finally { resetTargetPlatform(); } }