/** * 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()); }
/* * Run the reconciler to discover changes in the drop-ins folder and update the system state. */ public void reconcile(String message, boolean clean) { List<String> args = new ArrayList<String>(); args.add("-application"); args.add("org.eclipse.equinox.p2.reconciler.application"); if (clean) args.add("-clean"); runEclipse(message, args.toArray(new String[args.size()])); }
public static IFileArtifactRepository getAggregatedBundleRepository( IProvisioningAgent agent, IProfile profile, int repoFilter) { List<IFileArtifactRepository> bundleRepositories = new ArrayList<IFileArtifactRepository>(); // we check for a shared bundle pool first as it should be preferred over the user bundle pool // in a shared install IArtifactRepositoryManager manager = getArtifactRepositoryManager(agent); if ((repoFilter & AGGREGATE_SHARED_CACHE) != 0) { String sharedCache = profile.getProperty(IProfile.PROP_SHARED_CACHE); if (sharedCache != null) { try { URI repoLocation = new File(sharedCache).toURI(); IArtifactRepository repository = manager.loadRepository(repoLocation, null); if (repository != null && repository instanceof IFileArtifactRepository && !bundleRepositories.contains(repository)) bundleRepositories.add((IFileArtifactRepository) repository); } catch (ProvisionException e) { // skip repository if it could not be read } } } if ((repoFilter & AGGREGATE_CACHE) != 0) { IFileArtifactRepository bundlePool = Util.getBundlePoolRepository(agent, profile); if (bundlePool != null) bundleRepositories.add(bundlePool); } if ((repoFilter & AGGREGATE_CACHE_EXTENSIONS) != 0) { List<String> repos = getListProfileProperty(profile, CACHE_EXTENSIONS); for (String repo : repos) { try { URI repoLocation; try { repoLocation = new URI(repo); } catch (URISyntaxException e) { // in 1.0 we wrote unencoded URL strings, so try as an unencoded string repoLocation = URIUtil.fromString(repo); } IArtifactRepository repository = manager.loadRepository(repoLocation, null); if (repository != null && repository instanceof IFileArtifactRepository && !bundleRepositories.contains(repository)) bundleRepositories.add((IFileArtifactRepository) repository); } catch (ProvisionException e) { // skip repositories that could not be read } catch (URISyntaxException e) { // unexpected, URLs should be pre-checked LogHelper.log(new Status(IStatus.ERROR, Activator.ID, e.getMessage(), e)); } } } return new AggregatedBundleRepository(agent, bundleRepositories); }
/** * 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 identification of source bundles in a 3.0.2 install. * * @throws Exception */ public void testClassicSourcePlugins() 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}); definition.resolve(null); TargetBundle[] bundles = definition.getBundles(); List source = new ArrayList(); for (int i = 0; i < bundles.length; i++) { TargetBundle sb = bundles[i]; if (sb.isSourceBundle()) { source.add(sb); } } assertEquals("Wrong number of source bundles", 4, source.size()); Set names = new HashSet(); for (int i = 0; i < source.size(); i++) { names.add(((TargetBundle) source.get(i)).getBundleInfo().getSymbolicName()); } String[] expected = new String[] { "org.eclipse.platform.source", "org.eclipse.jdt.source", "org.eclipse.pde.source", "org.eclipse.platform.source.win32.win32.x86" }; for (int i = 0; i < expected.length; i++) { assertTrue("Missing source for " + expected[i], names.contains(expected[i])); } }
/** * 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()]); }
/** * Returns paths constructed by rewriting pathInfo using rules from the hosted site's mappings. * Paths are ordered from most to least specific match. * * @param site The hosted site. * @param pathInfo Path to be rewritten. * @param queryString * @return The rewritten path. May be either: * <ul> * <li>A path to a file in the Orion workspace, eg. <code>/ProjectA/foo/bar.txt</code> * <li>An absolute URL pointing to another site, eg. <code>http://foo.com/bar.txt</code> * </ul> * * @return The rewritten paths. * @throws URISyntaxException */ private URI[] getMapped(IHostedSite site, IPath pathInfo, String queryString) throws URISyntaxException { final Map<String, List<String>> map = site.getMappings(); final IPath originalPath = pathInfo; IPath path = originalPath.removeTrailingSeparator(); List<URI> uris = new ArrayList<URI>(); String rest = null; final int count = path.segmentCount(); for (int i = 0; i <= count; i++) { List<String> base = map.get(path.toString()); if (base != null) { rest = originalPath.removeFirstSegments(count - i).toString(); for (int j = 0; j < base.size(); j++) { URI uri = rest.equals("") ? new URI(base.get(j)) : URIUtil.append(new URI(base.get(j)), rest); uris.add( new URI( uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), queryString, uri.getFragment())); } } path = path.removeLastSegments(1); } if (uris.size() == 0) // No mapping for / return null; else return uris.toArray(new URI[uris.size()]); }
/** * 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(); } }
@Override protected IStatus performJob() { try { // list all tags File gitDir = GitUtils.getGitDir(path); Repository db = new FileRepository(gitDir); Git git = new Git(db); List<Ref> refs = git.tagList().call(); JSONObject result = new JSONObject(); List<Tag> tags = new ArrayList<Tag>(); for (Ref ref : refs) { Tag tag = new Tag(cloneLocation, db, ref); tags.add(tag); } Collections.sort(tags, Tag.COMPARATOR); JSONArray children = new JSONArray(); int firstTag = pageSize > 0 ? pageSize * (pageNo - 1) : 0; int lastTag = pageSize > 0 ? firstTag + pageSize - 1 : tags.size() - 1; lastTag = lastTag > tags.size() - 1 ? tags.size() - 1 : lastTag; if (pageNo > 1 && baseLocation != null) { String prev = baseLocation + "?page=" + (pageNo - 1) + "&pageSize=" + pageSize; if (commitsSize > 0) { prev += "&" + GitConstants.KEY_TAG_COMMITS + "=" + commitsSize; } result.put(ProtocolConstants.KEY_PREVIOUS_LOCATION, prev); } if (lastTag < tags.size() - 1) { String next = baseLocation + "?page=" + (pageNo + 1) + "&pageSize=" + pageSize; if (commitsSize > 0) { next += "&" + GitConstants.KEY_TAG_COMMITS + "=" + commitsSize; } result.put(ProtocolConstants.KEY_NEXT_LOCATION, next); } for (int i = firstTag; i <= lastTag; i++) { Tag tag = tags.get(i); if (this.commitsSize == 0) { children.put(tag.toJSON()); } else { // add info about commits if requested LogCommand lc = git.log(); String toCommitName = tag.getRevCommitName(); ObjectId toCommitId = db.resolve(toCommitName); Ref toCommitRef = db.getRef(toCommitName); toCommitId = getCommitObjectId(db, toCommitId); lc.add(toCommitId); lc.setMaxCount(this.commitsSize); Iterable<RevCommit> commits = lc.call(); Log log = new Log(cloneLocation, db, commits, null, null, toCommitRef); children.put(tag.toJSON(log.toJSON(1, commitsSize))); } } result.put(ProtocolConstants.KEY_CHILDREN, children); result.put(ProtocolConstants.KEY_TYPE, Tag.TYPE); return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, result); } catch (Exception e) { String msg = NLS.bind("An error occured when listing tags for {0}", path); return new Status(IStatus.ERROR, GitActivator.PI_GIT, msg, e); } }
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); } }
/** * Method getRepositoryRoots. * * @param iCVSRepositoryLocations * @return RepositoryRoot[] */ private RepositoryRoot[] getRepositoryRoots(ICVSRepositoryLocation[] locations) { List roots = new ArrayList(); for (int i = 0; i < locations.length; i++) { ICVSRepositoryLocation location = locations[i]; RepositoryRoot root = getRepositoryRootFor(location); if (root != null) roots.add(root); } return (RepositoryRoot[]) roots.toArray(new RepositoryRoot[roots.size()]); }
private void handleRemoved(IResourceDelta delta) { if ((delta.getFlags() & IResourceDelta.OPEN) != 0) { closedProjects.add(delta.getResource()); } else if ((delta.getFlags() & IResourceDelta.MOVED_TO) != 0) { handleMove(delta); } else { ensureResourceCovered(delta.getResource(), removedRoots); } }
/** * Erstellt einen neuen Evaluierungsjob, fuer die Evaluierung eines Ausdrucks. * * @param connection - Die Verbindung an dem der Job die Evaluierung vornimmt * @param form - Der Ausdrucke der ausgewertet werden soll * @param listener - Der Listener der die Durchfuehrung der Abarbeitung des Jobs ueberwacht. * @throws NullPointerException - wenn connection, form oder listener <code>null</code> */ public EvaluationJob( final IConnection connection, final PackageBoundForm form, final IBackgroundEvaluationListener listener) { super(connection, listener, JOB_NAME); List<PackageBoundForm> forms = new ArrayList<PackageBoundForm>(1); forms.add(form); init(forms); }
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); }
private static List<String> getListProfileProperty(IProfile profile, String key) { List<String> listProperty = new ArrayList<String>(); String dropinRepositories = profile.getProperty(key); if (dropinRepositories != null) { StringTokenizer tokenizer = new StringTokenizer(dropinRepositories, PIPE); while (tokenizer.hasMoreTokens()) { listProperty.add(tokenizer.nextToken()); } } return listProperty; }
private void accumulateStatus(IResource[] resources, List result, String message) { for (int i = 0; i < resources.length; i++) { IResource resource = resources[i]; result.add( new ModelStatus( IStatus.WARNING, "org.eclipse.core.tests.resources", TestModelProvider.ID, getMessageFor(message, resource))); } }
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; }
/** * Parses registry element to extract mode and selection elements that will be used for * verification. */ private void parseClasses(IConfigurationElement config) { // Get enables for. String enablesFor = config.getAttribute(IWorkbenchRegistryConstants.ATT_ENABLES_FOR); if (enablesFor == null) { enablesFor = "*"; // $NON-NLS-1$ } if (enablesFor.equals("*")) { // $NON-NLS-1$ mode = ANY_NUMBER; } else if (enablesFor.equals("?")) { // $NON-NLS-1$ mode = NONE_OR_ONE; } else if (enablesFor.equals("!")) { // $NON-NLS-1$ mode = NONE; } else if (enablesFor.equals("+")) { // $NON-NLS-1$ mode = ONE_OR_MORE; } else if (enablesFor.equals("multiple") // $NON-NLS-1$ || enablesFor.equals("2+")) { // $NON-NLS-1$ mode = MULTIPLE; } else { try { mode = Integer.parseInt(enablesFor); } catch (NumberFormatException e) { mode = UNKNOWN; } } // Get enablement block. IConfigurationElement[] children = config.getChildren(IWorkbenchRegistryConstants.TAG_ENABLEMENT); if (children.length > 0) { enablementExpression = new ActionExpression(children[0]); return; } // Get selection block. children = config.getChildren(IWorkbenchRegistryConstants.TAG_SELECTION); if (children.length > 0) { classes = new ArrayList(); for (int i = 0; i < children.length; i++) { IConfigurationElement sel = children[i]; String cname = sel.getAttribute(IWorkbenchRegistryConstants.ATT_CLASS); String name = sel.getAttribute(IWorkbenchRegistryConstants.ATT_NAME); SelectionClass sclass = new SelectionClass(); sclass.className = cname; sclass.nameFilter = name; classes.add(sclass); } } }
/** * 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 IStatus computeAllRemediations(IProgressMonitor monitor) { SubMonitor sub = SubMonitor.convert(monitor, remedyConfigs.length); sub.setTaskName(Messages.RemediationOperation_ProfileChangeRequestProgress); List<Remedy> tmpRemedies = new ArrayList<Remedy>(remedyConfigs.length); try { for (int i = 0; i < remedyConfigs.length; i++) { sub.subTask((i + 1) + " / " + remedyConfigs.length); // $NON-NLS-1$ if (sub.isCanceled()) return Status.CANCEL_STATUS; Remedy remedy = computeRemedy(remedyConfigs[i], sub.newChild(1, SubMonitor.SUPPRESS_ALL_LABELS)); if (remedy != null) { tmpRemedies.add(remedy); } } } finally { sub.done(); } remedies = tmpRemedies; return getResolutionResult(); }
/** * Creates the text changes for all the affected files. Updates all the include statements in the * current file and all the includes in the "including " files. In case of folders, creates the * changes recursively * * @param pm - progress monitor * @param rootChange - the root change that the new changes are added to * @param sourceResources * @return the root change after the additions * @throws CoreException */ private Change createTextChanges( IProgressMonitor pm, CompositeChange rootChange, Set<IFile> phpFiles, IResource[] sourceResources) throws CoreException { List<ProgramFileChange> changes = new ArrayList<ProgramFileChange>(); try { pm.beginTask(PhpRefactoringCoreMessages.getString("MoveDelegate.1"), 100); // $NON-NLS-1$ // creat text changes: // for each file that will be moved, update its includes // and update all the files that include it, IResource[] uniqueSourceResources = removeDuplicateResources(sourceResources); for (Iterator<IFile> it = phpFiles.iterator(); it.hasNext(); ) { IFile currentMovedResource = it.next(); Map<IFile, Program> participantFiles = collectReferencingFiles(currentMovedResource, pm); for (Entry<IFile, Program> entry : participantFiles.entrySet()) { final IFile file = entry.getKey(); if (phpFiles.contains(file)) { continue; } final Program program = entry.getValue(); final ChangeIncludePath rename = new ChangeIncludePath( currentMovedResource, file, fMainDestinationPath, false, uniqueSourceResources); // aggregate the changes identifiers program.accept(rename); if (pm.isCanceled()) throw new OperationCanceledException(); pm.worked(1); if (rename.hasChanges()) { ProgramFileChange change = new ProgramFileChange(file.getName(), file, program); change.setEdit(new MultiTextEdit()); change.setTextType("php"); // $NON-NLS-1$ changes.add(change); rename.updateChange(change); } } ISourceModule sourceModule = DLTKCore.createSourceModuleFrom(currentMovedResource); if (sourceModule instanceof ISourceModule) { Program program = null; try { program = ASTUtils.createProgramFromSource(sourceModule); } catch (Exception e) { } if (program != null) { final ChangeIncludePath rename = new ChangeIncludePath( currentMovedResource, currentMovedResource, fMainDestinationPath, true, uniqueSourceResources); // aggregate the changes identifiers program.accept(rename); if (pm.isCanceled()) throw new OperationCanceledException(); pm.worked(1); if (rename.hasChanges()) { ProgramFileChange change = new ProgramFileChange( currentMovedResource.getName(), currentMovedResource, program); change.setEdit(new MultiTextEdit()); change.setTextType("php"); // $NON-NLS-1$ changes.add(change); rename.updateChange(change); } } } } pm.worked(70); } finally { pm.done(); } // getChildren() Map<IFile, List<TextEdit>> changeMap = new HashMap<IFile, List<TextEdit>>(); Map<IFile, ProgramFileChange> fileMap = new HashMap<IFile, ProgramFileChange>(); for (ProgramFileChange programFileChange : changes) { List<TextEdit> list = changeMap.get(programFileChange.getFile()); if (list == null) { list = new ArrayList<TextEdit>(); changeMap.put(programFileChange.getFile(), list); fileMap.put(programFileChange.getFile(), programFileChange); } else { } list.addAll(Arrays.asList(programFileChange.getEdit().getChildren())); } for (IFile file : changeMap.keySet()) { ProgramFileChange change = new ProgramFileChange(file.getName(), file, fileMap.get(file).getProgram()); change.setEdit(new MultiTextEdit()); change.setTextType("php"); // $NON-NLS-1$ List<TextEdit> list = changeMap.get(file); Collections.sort( list, new Comparator<TextEdit>() { public int compare(TextEdit o1, TextEdit o2) { return o2.getOffset() - o1.getOffset(); } }); for (TextEdit textEdit : list) { if (textEdit instanceof ReplaceEdit) { ReplaceEdit replaceEdit = (ReplaceEdit) textEdit; change.addEdit( new ReplaceEdit( replaceEdit.getOffset(), replaceEdit.getLength(), replaceEdit.getText())); } } rootChange.add(change); } return rootChange; }
@Override public void addModelChangedListener(IModelChangedListener listener) { fListeners.add(listener); }
public void add(Filter filter) { filters.add(filter); }
public void addRepositoryListener(IRepositoryListener listener) { listeners.add(listener); }
public List getAllElements() { List result = new ArrayList(); result.add(this); return result; }
private void recordStatus(IStatus status) { statuses.add(status); }
public void addError(CoreException e) { errors.add( new Status(IStatus.ERROR, "org.eclipse.core.tests.resources", 0, "An error occurred", e)); }
public void addPage(IWizardPage page) { pages.add(page); page.setWizard(this); }