/** * Tests reading a 3.0.2 install with a mix of classic and OSGi plug-ins. * * @throws Exception */ public void testClassicPlugins() throws Exception { // extract the 3.0.2 skeleton IPath location = extractClassicPlugins(); // the new way ITargetDefinition definition = getNewTarget(); ITargetLocation container = getTargetService().newDirectoryLocation(location.toOSString()); definition.setTargetLocations(new ITargetLocation[] {container}); Set urls = getAllBundleURLs(definition); assertTrue("Must be bundles", urls.size() > 0); Preferences store = PDECore.getDefault().getPluginPreferences(); boolean restore = store.getBoolean(ICoreConstants.TARGET_PLATFORM_REALIZATION); try { store.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, false); // the old way URL[] pluginPaths = PluginPathFinder.getPluginPaths(location.toOSString()); for (int i = 0; i < pluginPaths.length; i++) { URL url = pluginPaths[i]; if (!urls.contains(url)) { System.err.println(url.toString()); } } assertEquals("Wrong number of bundles", pluginPaths.length, urls.size()); } finally { store.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, restore); } }
private void readOldState(DataInputStream dis) throws IOException, TeamException { int repoSize = dis.readInt(); boolean version1 = false; if (repoSize == STATE_FILE_VERSION_1) { version1 = true; repoSize = dis.readInt(); } for (int i = 0; i < repoSize; i++) { ICVSRepositoryLocation root = KnownRepositories.getInstance().getRepository(dis.readUTF()); RepositoryRoot repoRoot = getRepositoryRootFor(root); // read branch tags associated with this root int tagsSize = dis.readInt(); CVSTag[] branchTags = new CVSTag[tagsSize]; for (int j = 0; j < tagsSize; j++) { String tagName = dis.readUTF(); int tagType = dis.readInt(); branchTags[j] = new CVSTag(tagName, tagType); } // Ignore the branch tags since they are handled differently now // addBranchTags(root, branchTags); // read the number of projects for this root that have version tags int projSize = dis.readInt(); if (projSize > 0) { for (int j = 0; j < projSize; j++) { String name = dis.readUTF(); Set tagSet = new HashSet(); int numTags = dis.readInt(); for (int k = 0; k < numTags; k++) { tagSet.add(new CVSTag(dis.readUTF(), CVSTag.VERSION)); } CVSTag[] tags = (CVSTag[]) tagSet.toArray(new CVSTag[tagSet.size()]); repoRoot.addTags(name, tags); } } // read the auto refresh filenames for this project if (version1) { try { projSize = dis.readInt(); if (projSize > 0) { for (int j = 0; j < projSize; j++) { String name = dis.readUTF(); Set filenames = new HashSet(); int numFilenames = dis.readInt(); for (int k = 0; k < numFilenames; k++) { filenames.add(name + "/" + dis.readUTF()); // $NON-NLS-1$ } repoRoot.setAutoRefreshFiles( name, (String[]) filenames.toArray(new String[filenames.size()])); } } } catch (EOFException e) { // auto refresh files are not persisted, continue and save them next time. } } broadcastRepositoryChange(repoRoot); } }
/** * 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()); }
protected void handleAdd() { ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), new StyledBundleLabelProvider(false, false)); try { dialog.setElements(getValidBundles()); } catch (CoreException e) { dialog.setMessage(e.getMessage()); } dialog.setTitle(PDEUIMessages.PluginSelectionDialog_title); dialog.setMessage(PDEUIMessages.PluginSelectionDialog_message); dialog.setMultipleSelection(true); if (dialog.open() == Window.OK) { Object[] models = dialog.getResult(); ArrayList<NameVersionDescriptor> pluginsToAdd = new ArrayList<NameVersionDescriptor>(); for (int i = 0; i < models.length; i++) { BundleInfo desc = ((BundleInfo) models[i]); pluginsToAdd.add(new NameVersionDescriptor(desc.getSymbolicName(), null)); } Set<NameVersionDescriptor> allDependencies = new HashSet<NameVersionDescriptor>(); allDependencies.addAll(pluginsToAdd); NameVersionDescriptor[] currentBundles = getTargetDefinition().getImplicitDependencies(); if (currentBundles != null) { allDependencies.addAll(Arrays.asList(currentBundles)); } getTargetDefinition() .setImplicitDependencies( allDependencies.toArray(new NameVersionDescriptor[allDependencies.size()])); fElementViewer.refresh(); updateImpButtons(); } }
/** * Method getKnownTags. * * @param repository * @param set * @param i * @param monitor * @return CVSTag[] */ public CVSTag[] getKnownTags( ICVSRepositoryLocation repository, IWorkingSet set, int tagType, IProgressMonitor monitor) throws CVSException { if (set == null) { return getKnownTags(repository, tagType); } ICVSRemoteResource[] folders = getFoldersForTag(repository, CVSTag.DEFAULT, monitor); folders = filterResources(set, folders); Set tags = new HashSet(); for (int i = 0; i < folders.length; i++) { ICVSRemoteFolder folder = (ICVSRemoteFolder) folders[i]; tags.addAll(Arrays.asList(getKnownTags(folder, tagType))); } return (CVSTag[]) tags.toArray(new CVSTag[tags.size()]); }
/** Get the list of known branch tags for a given remote root. */ public CVSTag[] getKnownTags(ICVSFolder project, int tagType) { try { CVSTag[] tags = getKnownTags(project); Set result = new HashSet(); for (int i = 0; i < tags.length; i++) { CVSTag tag = tags[i]; if (tag.getType() == tagType) result.add(tag); } return (CVSTag[]) result.toArray(new CVSTag[result.size()]); } catch (CVSException e) { CVSUIPlugin.log(e); return new CVSTag[0]; } }
public ICVSRemoteResource[] getFoldersForTag( ICVSRepositoryLocation location, CVSTag tag, IProgressMonitor monitor) throws CVSException { monitor = Policy.monitorFor(monitor); try { monitor.beginTask( NLS.bind( CVSUIMessages.RepositoryManager_fetchingRemoteFolders, new String[] {tag.getName()}), 100); if (tag.getType() == CVSTag.HEAD) { ICVSRemoteResource[] resources = location.members(tag, false, Policy.subMonitorFor(monitor, 60)); RepositoryRoot root = getRepositoryRootFor(location); ICVSRemoteResource[] modules = root.getDefinedModules(tag, Policy.subMonitorFor(monitor, 40)); ICVSRemoteResource[] result = new ICVSRemoteResource[resources.length + modules.length]; System.arraycopy(resources, 0, result, 0, resources.length); System.arraycopy(modules, 0, result, resources.length, modules.length); return result; } if (tag.getType() == CVSTag.DATE) { ICVSRemoteResource[] resources = location.members(tag, false, Policy.subMonitorFor(monitor, 60)); RepositoryRoot root = getRepositoryRootFor(location); ICVSRemoteResource[] modules = root.getDefinedModules(tag, Policy.subMonitorFor(monitor, 40)); ICVSRemoteResource[] result = new ICVSRemoteResource[resources.length + modules.length]; System.arraycopy(resources, 0, result, 0, resources.length); System.arraycopy(modules, 0, result, resources.length, modules.length); return result; } Set result = new HashSet(); // Get the tags for the location RepositoryRoot root = getRepositoryRootFor(location); String[] paths = root.getKnownRemotePaths(); for (int i = 0; i < paths.length; i++) { String path = paths[i]; List tags = Arrays.asList(root.getAllKnownTags(path)); if (tags.contains(tag)) { ICVSRemoteFolder remote = root.getRemoteFolder(path, tag, Policy.subMonitorFor(monitor, 100)); result.add(remote); } } return (ICVSRemoteResource[]) result.toArray(new ICVSRemoteResource[result.size()]); } finally { monitor.done(); } }
public static void removeProblemsFor(IResource resource) { try { if (resource != null && resource.exists()) { resource.deleteMarkers( IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE); // delete managed markers Set markerTypes = JavaModelManager.getJavaModelManager().compilationParticipants.managedMarkerTypes(); if (markerTypes.size() == 0) return; Iterator iterator = markerTypes.iterator(); while (iterator.hasNext()) resource.deleteMarkers((String) iterator.next(), false, IResource.DEPTH_INFINITE); } } catch (CoreException e) { // assume there were no problems } }
/** * 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)); } }
/** * Tests that a target definition equivalent to the default target platform contains the same * bundles as the default target platform (this is an explicit location with no target weaving), * when created with a variable referencing ${eclipse_home} * * @throws Exception */ public void testEclipseHomeTargetPlatform() throws Exception { // the new way ITargetDefinition definition = getNewTarget(); ITargetLocation container = getTargetService().newProfileLocation("${eclipse_home}", null); definition.setTargetLocations(new ITargetLocation[] {container}); Set urls = getAllBundleURLs(definition); // the old way IPath location = new Path(TargetPlatform.getDefaultLocation()); URL[] pluginPaths = P2Utils.readBundlesTxt( location.toOSString(), location.append("configuration").toFile().toURL()); // pluginPaths will be null (and NPE) when self-hosting and the target platform is not a real // installation 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)); } }
/** * Tests that a target definition based on the default target platform restricted to a subset of * bundles contains the right set. * * @throws Exception */ public void testRestrictedDefaultTargetPlatform() throws Exception { ITargetDefinition definition = getNewTarget(); ITargetLocation container = getTargetService().newProfileLocation(TargetPlatform.getDefaultLocation(), null); NameVersionDescriptor[] restrictions = new NameVersionDescriptor[] { new NameVersionDescriptor("org.eclipse.jdt.launching", null), new NameVersionDescriptor("org.eclipse.jdt.debug", null) }; definition.setTargetLocations(new ITargetLocation[] {container}); definition.setIncluded(restrictions); List infos = getAllBundleInfos(definition); assertEquals("Wrong number of bundles", 2, infos.size()); Set set = collectAllSymbolicNames(infos); for (int i = 0; i < restrictions.length; i++) { NameVersionDescriptor info = restrictions[i]; set.remove(info.getId()); } assertEquals("Wrong bundles", 0, set.size()); }
/** * Tests that a bundle directory container is equivalent to scanning locations when it uses a * variable to specify its location. * * @throws Exception */ public void testVariableDirectoryBundleContainer() throws Exception { // the new way ITargetDefinition definition = getNewTarget(); ITargetLocation container = getTargetService().newDirectoryLocation("${eclipse_home}/plugins"); definition.setTargetLocations(new ITargetLocation[] {container}); Set urls = getAllBundleURLs(definition); Preferences store = PDECore.getDefault().getPluginPreferences(); boolean restore = store.getBoolean(ICoreConstants.TARGET_PLATFORM_REALIZATION); try { store.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, false); // 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)); } } finally { store.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, restore); } }
protected void doIncludeVersions(NameVersionDescriptor[] descriptions) throws Exception { String bsn = MULTI_VERSION_LOW_DESCRIPTION.getId(); IPath extras = extractMultiVersionPlugins(); ITargetDefinition target = getNewTarget(); ITargetLocation container = getTargetService().newDirectoryLocation(extras.toOSString()); target.setTargetLocations(new ITargetLocation[] {container}); target.setIncluded(descriptions); try { getTargetService().saveTargetDefinition(target); setTargetPlatform(target); IPluginModelBase[] models = PluginRegistry.getExternalModels(); Set enabled = new HashSet(); for (int i = 0; i < models.length; i++) { IPluginModelBase pm = models[i]; if (pm.getBundleDescription().getSymbolicName().equals(bsn)) { NameVersionDescriptor desc = new NameVersionDescriptor( pm.getPluginBase().getId(), pm.getPluginBase().getVersion()); if (pm.isEnabled()) { enabled.add(desc); } } } if (descriptions == null) { } else { assertEquals("Wrong number of enabled bundles", descriptions.length, enabled.size()); for (int i = 0; i < descriptions.length; i++) { assertTrue("Missing bundle", enabled.contains(descriptions[i])); } } } finally { getTargetService().deleteTarget(target.getHandle()); resetTargetPlatform(); } }
/** * Tests that a target definition based on the JDT feature restricted to a subset of bundles * contains the right set. * * @throws Exception */ public void testRestrictedFeatureBundleContainer() throws Exception { // extract the feature IPath location = extractModifiedFeatures(); ITargetDefinition definition = getNewTarget(); ITargetLocation container = getTargetService().newFeatureLocation(location.toOSString(), "org.eclipse.jdt", null); NameVersionDescriptor[] restrictions = new NameVersionDescriptor[] { new NameVersionDescriptor("org.eclipse.jdt", null), new NameVersionDescriptor("org.junit", "3.8.2.v20090203-1005") }; definition.setTargetLocations(new ITargetLocation[] {container}); definition.setIncluded(restrictions); List infos = getAllBundleInfos(definition); assertEquals("Wrong number of bundles", 2, infos.size()); Set set = collectAllSymbolicNames(infos); for (int i = 0; i < restrictions.length; i++) { NameVersionDescriptor info = restrictions[i]; set.remove(info.getId()); } assertEquals("Wrong bundles", 0, set.size()); }
public static String[] getApplicationNames() { Set result = getApplicationNameSet(); return (String[]) result.toArray(new String[result.size()]); }