private Map promptForOverwrite(List plugins, List locales) { Map overwrites = new HashMap(); if (overwriteWithoutAsking) return overwrites; for (Iterator iter = plugins.iterator(); iter.hasNext(); ) { IPluginModelBase plugin = (IPluginModelBase) iter.next(); for (Iterator it = locales.iterator(); it.hasNext(); ) { Locale locale = (Locale) it.next(); IProject project = getNLProject(plugin, locale); if (project.exists() && !overwrites.containsKey(project.getName())) { boolean overwrite = MessageDialog.openConfirm( PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.InternationalizeWizard_NLSFragmentGenerator_overwriteTitle, NLS.bind( PDEUIMessages.InternationalizeWizard_NLSFragmentGenerator_overwriteMessage, pluginName(plugin, locale))); overwrites.put(project.getName(), overwrite ? OVERWRITE : null); } } } return overwrites; }
/* * (non-Javadoc) * * @see org.eclipse.jface.wizard.IWizard#addPages() */ public void addPages() { if (addingPages) return; try { addingPages = true; pages = new ArrayList<IWizardPage>(); Iterator<WizardFragment> iterator = getAllWizardFragments().iterator(); while (iterator.hasNext()) { WizardFragment fragment = (WizardFragment) iterator.next(); FragmentedWizardPage page = getFragmentData(fragment); if (fragment.hasComposite()) { if (page != null) { addPage(page); } else { page = new FragmentedWizardPage(fragment); fragmentData.put(fragment, page); addPage(page); } } } } catch (Exception e) { PHPUiPlugin.log( new Status( IStatus.ERROR, PHPUiPlugin.ID, 0, "Error adding fragments to wizard", e)); //$NON-NLS-1$ } finally { addingPages = false; } }
/** * Returns true if given structured selection matches the conditions specified in the registry for * this action. */ private boolean isEnabledFor(IStructuredSelection ssel) { int count = ssel.size(); if (verifySelectionCount(count) == false) { return false; } // Compare selection to enablement expression. if (enablementExpression != null) { return enablementExpression.isEnabledFor(ssel); } // Compare selection to class requirements. if (classes.isEmpty()) { return true; } for (Iterator elements = ssel.iterator(); elements.hasNext(); ) { Object obj = elements.next(); if (obj instanceof IAdaptable) { IAdaptable element = (IAdaptable) obj; if (verifyElement(element) == false) { return false; } } else { return false; } } return true; }
/** * Method filterResources filters the given resources using the given working set. * * @param current * @param resources * @return ICVSRemoteResource[] */ public ICVSRemoteResource[] filterResources( IWorkingSet workingSet, ICVSRemoteResource[] resources) { if (workingSet == null) return resources; // get the projects associated with the working set IAdaptable[] adaptables = workingSet.getElements(); Set projects = new HashSet(); for (int i = 0; i < adaptables.length; i++) { IAdaptable adaptable = adaptables[i]; Object adapted = adaptable.getAdapter(IResource.class); if (adapted != null) { // Can this code be generalized? IProject project = ((IResource) adapted).getProject(); projects.add(project); } } List result = new ArrayList(); for (int i = 0; i < resources.length; i++) { ICVSRemoteResource resource = resources[i]; for (Iterator iter = projects.iterator(); iter.hasNext(); ) { IProject project = (IProject) iter.next(); if (project.getName().equals(resource.getName())) { result.add(resource); break; } } } return (ICVSRemoteResource[]) result.toArray(new ICVSRemoteResource[result.size()]); }
public static IMarker[] getProblemsFor(IResource resource) { try { if (resource != null && resource.exists()) { IMarker[] markers = resource.findMarkers( IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE); Set markerTypes = JavaModelManager.getJavaModelManager().compilationParticipants.managedMarkerTypes(); if (markerTypes.isEmpty()) return markers; ArrayList markerList = new ArrayList(5); for (int i = 0, length = markers.length; i < length; i++) { markerList.add(markers[i]); } Iterator iterator = markerTypes.iterator(); while (iterator.hasNext()) { markers = resource.findMarkers((String) iterator.next(), false, IResource.DEPTH_INFINITE); for (int i = 0, length = markers.length; i < length; i++) { markerList.add(markers[i]); } } IMarker[] result; markerList.toArray(result = new IMarker[markerList.size()]); return result; } } catch (CoreException e) { // assume there are no problems } return new IMarker[0]; }
/** A repository root has been added. Notify any listeners. */ public void rootAdded(ICVSRepositoryLocation root) { Iterator it = listeners.iterator(); while (it.hasNext()) { IRepositoryListener listener = (IRepositoryListener) it.next(); listener.repositoryAdded(root); } }
private void addSubWizardFragments(WizardFragment fragment, List<WizardFragment> list) { Iterator<?> iterator = fragment.getChildFragments().iterator(); while (iterator.hasNext()) { WizardFragment child = (WizardFragment) iterator.next(); list.add(child); addSubWizardFragments(child, list); } }
private void broadcastRepositoriesChanged(ICVSRepositoryLocation[] roots) { if (roots.length == 0) return; Iterator it = listeners.iterator(); while (it.hasNext()) { IRepositoryListener listener = (IRepositoryListener) it.next(); listener.repositoriesChanged(roots); } }
private void ensureResourceCovered(IResource resource, List list) { IPath path = resource.getFullPath(); for (Iterator iter = list.iterator(); iter.hasNext(); ) { IResource root = (IResource) iter.next(); if (root.getFullPath().isPrefixOf(path)) { return; } } list.add(resource); }
/* (non-Javadoc) * @see org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector#dispose() */ public synchronized void dispose() { Iterator iterator = fSourceContainerMap.values().iterator(); while (iterator.hasNext()) { ISourceContainer[] containers = (ISourceContainer[]) iterator.next(); for (int i = 0; i < containers.length; i++) { containers[i].dispose(); } } fSourceContainerMap.clear(); super.dispose(); }
private void writeState(XMLWriter writer) { writer.startTag(RepositoriesViewContentHandler.REPOSITORIES_VIEW_TAG, null, true); // Write the repositories Collection repos = Arrays.asList(getKnownRepositoryLocations()); Iterator it = repos.iterator(); while (it.hasNext()) { CVSRepositoryLocation location = (CVSRepositoryLocation) it.next(); RepositoryRoot root = getRepositoryRootFor(location); root.writeState(writer); } writer.endTag(RepositoriesViewContentHandler.REPOSITORIES_VIEW_TAG); }
/** * @param element * @param schemaElement */ private void validateMaxElementMult(Element element, ISchemaElement schemaElement) { // Validate max element occurence violations int maxSeverity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ELEMENT); if (maxSeverity != CompilerFlags.IGNORE) { HashSet maxElementSet = ElementOccurenceChecker.findMaxOccurenceViolations(schemaElement, element); Iterator maxIterator = maxElementSet.iterator(); while (maxIterator.hasNext()) { reportMaxOccurenceViolation((ElementOccurrenceResult) maxIterator.next(), maxSeverity); } } }
/* * Clean up the temporary data used to run the tests. * This method is not intended to be called by clients, it will be called * automatically when the clients use a ReconcilerTestSuite. */ public void cleanup() throws Exception { // rm -rf eclipse sub-dir boolean leaveDirty = Boolean.parseBoolean(TestActivator.getContext().getProperty("p2.tests.doNotClean")); if (leaveDirty) return; for (Iterator iter = toRemove.iterator(); iter.hasNext(); ) { File next = (File) iter.next(); delete(next); } output = null; toRemove.clear(); }
public static void checkPluginPropertiesConsistency(Map map, File configDir) { File runtimeDir = new File(configDir, IPDEBuildConstants.BUNDLE_CORE_RUNTIME); if (runtimeDir.exists() && runtimeDir.isDirectory()) { long timestamp = runtimeDir.lastModified(); Iterator iter = map.values().iterator(); while (iter.hasNext()) { if (hasChanged((IMonitorModelBase) iter.next(), timestamp)) { CoreUtility.deleteContent(runtimeDir); break; } } } }
/** * Returns a status that represents the exceptions collected. If the collector is empty <code> * IStatus.OK</code> is returned. Otherwise a MultiStatus containing all collected exceptions is * returned. * * @return a multistatus containing the exceptions collected or IStatus.OK if the collector is * empty. */ public IStatus getStatus() { if (statuses.isEmpty()) { return Status.OK_STATUS; } else { MultiStatus multiStatus = new MultiStatus(pluginId, severity, message, null); Iterator it = statuses.iterator(); while (it.hasNext()) { IStatus status = (IStatus) it.next(); multiStatus.merge(status); } return multiStatus; } }
/** * 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()); } }
/* * Iterate over the sites in the given configuration and remove the one which * has a url matching the given location. */ public boolean removeSite(Configuration configuration, String location) throws IOException, URISyntaxException { File left = new File(new URI(location)).getCanonicalFile(); List sites = configuration.getSites(); for (Iterator iter = sites.iterator(); iter.hasNext(); ) { Site tempSite = (Site) iter.next(); String siteURL = tempSite.getUrl(); File right = new File(new URI(siteURL)).getCanonicalFile(); if (left.equals(right)) { return configuration.removeSite(tempSite); } } return false; }
private List<WizardFragment> getAllWizardFragments() { List<WizardFragment> list = new ArrayList<WizardFragment>(); list.add(rootFragment); addSubWizardFragments(rootFragment, list); Iterator<WizardFragment> iterator = list.iterator(); while (iterator.hasNext()) { WizardFragment fragment = (WizardFragment) iterator.next(); if (!wizardModel.equals(fragment.getWizardModel())) { fragment.setWizardModel(wizardModel); } } return list; }
/** * 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(); } }
/* * Assert that a feature with the given id exists in the configuration. If * a version is specified then match the version, otherwise any version will * do. */ public void assertFeatureExists( String message, Configuration configuration, String id, String version) { List sites = configuration.getSites(); assertNotNull(message, sites); boolean found = false; for (Iterator iter = sites.iterator(); iter.hasNext(); ) { Site site = (Site) iter.next(); Feature[] features = site.getFeatures(); for (int i = 0; features != null && i < features.length; i++) { if (id.equals(features[i].getId())) { if (version == null) found = true; else if (version.equals(features[i].getVersion())) found = true; } } } assertTrue(message, found); }
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 } }
public boolean include(Object object) { if (object instanceof IResource) { IResource resource = (IResource) object; IPath path = IResource.FILE == resource.getType() ? resource.getFullPath() : resource.getFullPath().addTrailingSeparator(); object = path.toPortableString(); } for (Iterator iter = filters.iterator(); iter.hasNext(); ) { Filter filter = (Filter) iter.next(); if (filter.matches(object)) { return filter.inclusive(); } } return default_; }
/** * Return a list of nature ids based on the natures that have been configured for this project. * * @return list of configured nature ids. * @param project */ public static List getRegisteredRuntimeIDs(IProject project) { List result = null; String natureID = null; if (project != null && project.isAccessible()) { Iterator it = EMFNatureRegistry.singleton().REGISTERED_NATURE_IDS.iterator(); while (it.hasNext()) { natureID = (String) it.next(); try { if (project.hasNature(natureID)) { if (result == null) result = new ArrayList(2); result.add(natureID); } } catch (CoreException e) { } } } return result == null ? Collections.EMPTY_LIST : result; }
private String getBundles(boolean defaultAuto) { StringBuffer buffer = new StringBuffer(); Iterator iter = fModels.keySet().iterator(); while (iter.hasNext()) { IMonitorModelBase model = (IMonitorModelBase) iter.next(); String id = model.getMonitorBase().getId(); if (!IPDEBuildConstants.BUNDLE_OSGI.equals(id)) { if (buffer.length() > 0) buffer.append(","); // $NON-NLS-1$ buffer.append(LaunchConfigurationHelper.getBundleURL(model, true)); // fragments must not be started or have a start level if (model instanceof IFragmentModel) continue; String data = fModels.get(model).toString(); appendStartData(buffer, data, defaultAuto); } } return buffer.toString(); }
private Map<IFile, Program> collectReferencingFiles(IFile sourceFile, IProgressMonitor pm) { ISourceModule sourceModule = DLTKCore.createSourceModuleFrom(sourceFile); Map<IFile, Program> participantFiles = new HashMap<IFile, Program>(); Collection<Node> references = MoveUtils.getReferencingFiles(sourceModule); if (references != null) { for (Iterator<Node> it = references.iterator(); it.hasNext(); ) { Node node = it.next(); IFile file = (IFile) node.getFile().getResource(); try { participantFiles.put(file, RefactoringUtility.getProgramForFile(file)); } catch (Exception e) { } } } return participantFiles; }
/** * Tests that a target definition based on the default target platform restricted to a subset of * bundle versions contains the right set. * * @throws Exception */ public void testVersionRestrictedDefaultTargetPlatform() throws Exception { ITargetDefinition definition = getNewTarget(); ITargetLocation container = getTargetService().newProfileLocation(TargetPlatform.getDefaultLocation(), null); definition.setTargetLocations(new ITargetLocation[] {container}); List infos = getAllBundleInfos(definition); // find right versions String v1 = null; String v2 = null; Iterator iterator = infos.iterator(); while (iterator.hasNext() && (v2 == null || v1 == null)) { BundleInfo info = (BundleInfo) iterator.next(); if (info.getSymbolicName().equals("org.eclipse.jdt.launching")) { v1 = info.getVersion(); } else if (info.getSymbolicName().equals("org.eclipse.jdt.debug")) { v2 = info.getVersion(); } } assertNotNull(v1); assertFalse(v1.equals(BundleInfo.EMPTY_VERSION)); assertNotNull(v2); assertFalse(v2.equals(BundleInfo.EMPTY_VERSION)); NameVersionDescriptor[] restrictions = new NameVersionDescriptor[] { new NameVersionDescriptor("org.eclipse.jdt.launching", v1), new NameVersionDescriptor("org.eclipse.jdt.debug", v2) }; definition.setIncluded(restrictions); infos = getAllBundleInfos(definition); assertEquals("Wrong number of bundles", 2, infos.size()); iterator = infos.iterator(); while (iterator.hasNext()) { BundleInfo info = (BundleInfo) iterator.next(); if (info.getSymbolicName().equals("org.eclipse.jdt.launching")) { assertEquals(v1, info.getVersion()); } else if (info.getSymbolicName().equals("org.eclipse.jdt.debug")) { assertEquals(v2, info.getVersion()); } } }
private void determineBestSolutions() { int beingInstalledWeight = 0; int installationWeight = 0; for (Iterator<Remedy> iterator = remedies.iterator(); iterator.hasNext(); ) { Remedy remedy = iterator.next(); if (remedy.getRequest() != null) { if (remedy.getBeingInstalledRelaxedWeight() > beingInstalledWeight && remedy.getInstallationRelaxedWeight() == 0) { bestSolutionChangingTheRequest = remedy; beingInstalledWeight = remedy.getBeingInstalledRelaxedWeight(); continue; } if (remedy.getInstallationRelaxedWeight() > installationWeight && remedy.getBeingInstalledRelaxedWeight() == 0) { bestSolutionChangingWhatIsInstalled = remedy; installationWeight = remedy.getInstallationRelaxedWeight(); continue; } } } }
/** @return a map connecting IPath to the resolved bundles in that path */ private Map getFileBundleMapping() { if (fFileBundleMapping != null) { return fFileBundleMapping; } // Map the bundles into their file locations fFileBundleMapping = new HashMap(); for (Iterator iterator = fAllBundles.iterator(); iterator.hasNext(); ) { IResolvedBundle currentBundle = (IResolvedBundle) iterator.next(); IPath parentPath = getParentPath(currentBundle); List bundles = (List) fFileBundleMapping.get(parentPath); if (bundles == null) { bundles = new ArrayList(); bundles.add(currentBundle); fFileBundleMapping.put(parentPath, bundles); } else { bundles.add(currentBundle); } } return fFileBundleMapping; }
/** * Creates an NL fragment project along with the locale specific properties files. * * @throws CoreException * @throws IOException * @throws InvocationTargetException * @throws InterruptedException */ private void internationalizePlugins(List plugins, List locales, Map overwrites) throws CoreException, IOException, InvocationTargetException, InterruptedException { Set created = new HashSet(); for (Iterator it = plugins.iterator(); it.hasNext(); ) { IPluginModelBase plugin = (IPluginModelBase) it.next(); for (Iterator iter = locales.iterator(); iter.hasNext(); ) { Locale locale = (Locale) iter.next(); IProject project = getNLProject(plugin, locale); if (created.contains(project) || overwriteWithoutAsking || !project.exists() || OVERWRITE == overwrites.get(project.getName())) { if (!created.contains(project) && project.exists()) { project.delete(true, getProgressMonitor()); } if (!created.contains(project)) { createNLFragment(plugin, project, locale); created.add(project); project.getFolder(RESOURCE_FOLDER_PARENT).create(false, true, getProgressMonitor()); } project .getFolder(RESOURCE_FOLDER_PARENT) .getFolder(locale.toString()) .create(true, true, getProgressMonitor()); createLocaleSpecificPropertiesFile(project, plugin, locale); } } } }
/* * Instruct the build manager that this project is involved in a cycle and * needs to propagate structural changes to the other projects in the cycle. */ void mustPropagateStructuralChanges() { LinkedHashSet cycleParticipants = new LinkedHashSet(3); this.javaProject.updateCycleParticipants( new ArrayList(), cycleParticipants, this.workspaceRoot, new HashSet(3), null); IPath currentPath = this.javaProject.getPath(); Iterator i = cycleParticipants.iterator(); while (i.hasNext()) { IPath participantPath = (IPath) i.next(); if (participantPath != currentPath) { IProject project = this.workspaceRoot.getProject(participantPath.segment(0)); if (hasBeenBuilt(project)) { if (DEBUG) System.out.println( "JavaBuilder: Requesting another build iteration since cycle participant " + project.getName() // $NON-NLS-1$ + " has not yet seen some structural changes"); //$NON-NLS-1$ needRebuild(); return; } } } }