/** * Tests a JDT source feature bundle container contains the appropriate bundles * * @throws Exception */ public void testSourceFeatureBundleContainer() throws Exception { // extract the feature IPath location = extractModifiedFeatures(); ITargetDefinition definition = getNewTarget(); ITargetLocation container = getTargetService() .newFeatureLocation(location.toOSString(), "org.eclipse.jdt.source", null); container.resolve(definition, null); TargetBundle[] bundles = container.getBundles(); List expected = new ArrayList(); expected.add("org.eclipse.jdt.source"); expected.add("org.eclipse.jdt.launching.source"); // There are two versions of junit available, each with source expected.add("org.junit.source"); expected.add("org.junit.source"); if (Platform.getOS().equals(Platform.OS_MACOSX)) { expected.add("org.eclipse.jdt.launching.macosx.source"); } assertEquals("Wrong number of bundles", expected.size(), bundles.length); for (int i = 0; i < bundles.length; i++) { if (bundles[i].getBundleInfo().getSymbolicName().equals("org.eclipse.jdt.doc.isv")) { assertFalse("Should not be a source bundle", bundles[i].isSourceBundle()); } else { assertTrue(expected.remove(bundles[i].getBundleInfo().getSymbolicName())); assertTrue("Should be a source bundle", bundles[i].isSourceBundle()); } } assertTrue("Wrong bundles in JDT feature", expected.isEmpty()); }
/** Loads combo choices fromt he platform and from PDE core preferences */ private void initializeChoices() { IEclipsePreferences node = new InstanceScope().getNode(PDECore.PLUGIN_ID); fOSChoices = new TreeSet<String>(); String[] os = Platform.knownOSValues(); for (int i = 0; i < os.length; i++) { fOSChoices.add(os[i]); } String pref = node.get(ICoreConstants.OS_EXTRA, EMPTY_STRING); if (!EMPTY_STRING.equals(pref)) { addExtraChoices(fOSChoices, pref); } fWSChoices = new TreeSet<String>(); String[] ws = Platform.knownWSValues(); for (int i = 0; i < ws.length; i++) { fWSChoices.add(ws[i]); } pref = node.get(ICoreConstants.WS_EXTRA, EMPTY_STRING); if (!EMPTY_STRING.equals(pref)) { addExtraChoices(fWSChoices, pref); } fArchChoices = new TreeSet<String>(); String[] arch = Platform.knownOSArchValues(); for (int i = 0; i < arch.length; i++) { fArchChoices.add(arch[i]); } pref = node.get(ICoreConstants.ARCH_EXTRA, EMPTY_STRING); if (!EMPTY_STRING.equals(pref)) { addExtraChoices(fArchChoices, pref); } fNLChoices = new TreeSet<String>(); String[] nl = LocaleUtil.getLocales(); for (int i = 0; i < nl.length; i++) { fNLChoices.add(nl[i]); } pref = node.get(ICoreConstants.NL_EXTRA, EMPTY_STRING); if (!EMPTY_STRING.equals(pref)) { addExtraChoices(fNLChoices, pref); } }
/** * Tests a JDT feature bundle container contains the appropriate bundles for a specific OS. * * @throws Exception */ public void testMacOSFeatureBundleContainer() throws Exception { // extract the feature IPath location = extractModifiedFeatures(); ITargetDefinition definition = getNewTarget(); definition.setOS(Platform.OS_MACOSX); ITargetLocation container = getTargetService().newFeatureLocation(location.toOSString(), "org.eclipse.jdt", null); container.resolve(definition, null); TargetBundle[] bundles = container.getBundles(); 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"); expected.add("org.eclipse.jdt.launching.macosx"); assertEquals("Wrong number of bundles in JDT feature", expected.size(), bundles.length); for (int i = 0; i < bundles.length; i++) { String symbolicName = bundles[i].getBundleInfo().getSymbolicName(); expected.remove(symbolicName); if (symbolicName.equals("org.eclipse.jdt.launching.macosx")) { // the bundle should be missing unless on Mac IStatus status = bundles[i].getStatus(); if (Platform.getOS().equals(Platform.OS_MACOSX)) { assertTrue("Mac bundle should be present", status.isOK()); } else { assertFalse("Mac bundle should be missing", status.isOK()); assertEquals( "Mac bundle should be mssing", TargetBundle.STATUS_PLUGIN_DOES_NOT_EXIST, status.getCode()); } } } Iterator iterator = expected.iterator(); while (iterator.hasNext()) { String name = (String) iterator.next(); System.err.println("Missing: " + name); } assertTrue("Wrong bundles in JDT feature", expected.isEmpty()); // should be no source bundles for (int i = 0; i < bundles.length; i++) { TargetBundle bundle = bundles[i]; assertFalse("Should be no source bundles", bundle.isSourceBundle()); } }
/** * 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(); } }
/** * Tests that a target definition equivalent to the default target platform contains the same * bundles as the default target platform using the platform's configuration location (which will * do target weaving). This is really only tested when run as a JUnit plug-in test suite from * within Eclipse. * * @throws Exception */ public void testWovenTargetPlatform() throws Exception { // the new way ITargetDefinition definition = getNewTarget(); ITargetLocation container = getTargetService() .newProfileLocation( TargetPlatform.getDefaultLocation(), new File(Platform.getConfigurationLocation().getURL().getFile()).getAbsolutePath()); definition.setTargetLocations(new ITargetLocation[] {container}); Set urls = getAllBundleURLs(definition); // the old way URL[] pluginPaths = PluginPathFinder.getPluginPaths(TargetPlatform.getDefaultLocation()); assertEquals("Should have same number of bundles", pluginPaths.length, urls.size()); for (int i = 0; i < pluginPaths.length; i++) { URL url = pluginPaths[i]; assertTrue("Missing plug-in " + url.toString(), urls.contains(url)); } }