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; }
/** * @param req The request. * @return The query string of the request in its raw (not URI-encoded) form. This is suitable for * passing as the 'query' parameter to one of the multi-argument {@link URI} constructors. */ private static String getQueryString(HttpServletRequest req) throws UnsupportedEncodingException { StringBuilder buf = new StringBuilder(); Map<String, String[]> params = req.getParameterMap(); if (params.size() == 0) return null; for (Entry<String, String[]> entry : params.entrySet()) { String name = entry.getKey(); String[] values = entry.getValue(); if (values.length == 0) { buf.append("&").append(name); } else { for (String value : values) { buf.append("&").append(name).append("=").append(value); } } } return buf.substring(1); }
/** * Returns the existing git repositories for the given file path, following the given traversal * rule. * * @param path expected format /file/{Workspace}/{projectName}[/{path}] * @return a map of all git repositories found, or <code>null</code> if the provided path format * doesn't match the expected format. * @throws CoreException */ public static Map<IPath, File> getGitDirs(IPath path, Traverse traverse) throws CoreException { IPath p = path.removeFirstSegments(1); // remove /file IFileStore fileStore = NewFileServlet.getFileStore(null, p); if (fileStore == null) return null; Map<IPath, File> result = new HashMap<IPath, File>(); File file = fileStore.toLocalFile(EFS.NONE, null); // jgit can only handle a local file if (file == null) return result; switch (traverse) { case CURRENT: if (RepositoryCache.FileKey.isGitRepository(file, FS.DETECTED)) { result.put(new Path(""), file); // $NON-NLS-1$ } else if (RepositoryCache.FileKey.isGitRepository( new File(file, Constants.DOT_GIT), FS.DETECTED)) { result.put(new Path(""), new File(file, Constants.DOT_GIT)); // $NON-NLS-1$ } break; case GO_UP: getGitDirsInParents(file, result); break; case GO_DOWN: getGitDirsInChildren(file, p, result); break; } return result; }
protected void mergeEncodingPreferences(IProject project) { Preferences projectRegularPrefs = null; Preferences projectDerivedPrefs = getPreferences(project, false, true, true); if (projectDerivedPrefs == null) return; try { boolean prefsChanged = false; String[] affectedResources; affectedResources = projectDerivedPrefs.keys(); for (int i = 0; i < affectedResources.length; i++) { String path = affectedResources[i]; String value = projectDerivedPrefs.get(path, null); projectDerivedPrefs.remove(path); // lazy creation of non-derived preferences if (projectRegularPrefs == null) projectRegularPrefs = getPreferences(project, true, false, false); projectRegularPrefs.put(path, value); prefsChanged = true; } if (prefsChanged) { Map<IProject, Boolean> projectsToSave = new HashMap<>(); // this is internal change so do not notify charset delta job projectsToSave.put(project, Boolean.TRUE); job.addChanges(projectsToSave); } } catch (BackingStoreException e) { // problems with the project scope... we will miss the changes (but will log) String message = Messages.resources_readingEncoding; Policy.log( new ResourceStatus( IResourceStatus.FAILED_GETTING_CHARSET, project.getFullPath(), message, e)); } }
private boolean workaroundBug356918( HttpServletRequest request, HttpServletResponse response, Exception e) throws ServletException, JSONException { if (e instanceof CheckoutConflictException) { JSONObject result = new JSONObject(); result.put(GitConstants.KEY_RESULT, MergeStatus.FAILED.name()); Map<String, MergeFailureReason> failingPaths = new HashMap<String, MergeFailureReason>(); String[] files = e.getMessage().split("\n"); // $NON-NLS-1$ for (int i = 1; i < files.length; i++) { // TODO: this is not always true, but it's a temporary workaround failingPaths.put(files[i], MergeFailureReason.DIRTY_WORKTREE); } result.put(GitConstants.KEY_FAILING_PATHS, failingPaths); try { OrionServlet.writeJSONResponse( request, response, result, JsonURIUnqualificationStrategy.ALL_NO_GIT); return true; } catch (IOException e1) { e = e1; } } return statusHandler.handleRequest( request, response, new ServerStatus( IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An error occured when merging.", e.getCause())); }
ISourceContainer[] getSourceContainers(String location, String id) throws CoreException { ISourceContainer[] containers = (ISourceContainer[]) fSourceContainerMap.get(location); if (containers != null) { return containers; } ArrayList result = new ArrayList(); ModelEntry entry = MonitorRegistry.findEntry(id); boolean match = false; IMonitorModelBase[] models = entry.getWorkspaceModels(); for (int i = 0; i < models.length; i++) { if (isPerfectMatch(models[i], new Path(location))) { IResource resource = models[i].getUnderlyingResource(); // if the plug-in matches a workspace model, // add the project and any libraries not coming via a container // to the list of source containers, in that order if (resource != null) { addProjectSourceContainers(resource.getProject(), result); } match = true; break; } } if (!match) { File file = new File(location); if (file.isFile()) { // in case of linked plug-in projects that map to an external JARd plug-in, // use source container that maps to the library in the linked project. ISourceContainer container = getArchiveSourceContainer(location); if (container != null) { containers = new ISourceContainer[] {container}; fSourceContainerMap.put(location, containers); return containers; } } models = entry.getExternalModels(); for (int i = 0; i < models.length; i++) { if (isPerfectMatch(models[i], new Path(location))) { // try all source zips found in the source code locations IClasspathEntry[] entries = MDEClasspathContainer.getExternalEntries(models[i]); for (int j = 0; j < entries.length; j++) { IRuntimeClasspathEntry rte = convertClasspathEntry(entries[j]); if (rte != null) result.add(rte); } break; } } } IRuntimeClasspathEntry[] entries = (IRuntimeClasspathEntry[]) result.toArray(new IRuntimeClasspathEntry[result.size()]); containers = JavaRuntime.getSourceContainers(entries); fSourceContainerMap.put(location, containers); return containers; }
/** * Returns the file representing the Git repository directory for the given file path or any of * its parent in the filesystem. If the file doesn't exits, is not a Git repository or an error * occurred while transforming the given path into a store <code>null</code> is returned. * * @param path expected format /file/{Workspace}/{projectName}[/{path}] * @return the .git folder if found or <code>null</code> the give path cannot be resolved to a * file or it's not under control of a git repository * @throws CoreException */ public static File getGitDir(IPath path) throws CoreException { Map<IPath, File> gitDirs = GitUtils.getGitDirs(path, Traverse.GO_UP); if (gitDirs == null) return null; Collection<File> values = gitDirs.values(); if (values.isEmpty()) return null; return values.toArray(new File[] {})[0]; }
public void addChanges(Map<IProject, Boolean> newChanges) { if (newChanges.isEmpty()) return; synchronized (asyncChanges) { asyncChanges.addAll(newChanges.entrySet()); asyncChanges.notify(); } schedule(CHARSET_UPDATE_DELAY); }
/* (non-Javadoc) * @see org.eclipse.ui.IWorkbenchPart3#setPartProperty(java.lang.String, java.lang.String) */ public void setPartProperty(String key, String value) { String oldValue = (String) partProperties.get(key); if (value == null) { partProperties.remove(key); } else { partProperties.put(key, value); } firePartPropertyChanged(key, oldValue, value); }
public void removeDescriptor(IArtifactKey key, IProgressMonitor monitor) { for (IArtifactDescriptor nextDescriptor : artifactDescriptors) { if (key.equals(nextDescriptor.getArtifactKey())) artifactDescriptors.remove(nextDescriptor); } if (keysToLocations.containsKey(key)) { URI theLocation = keysToLocations.get(key); locationsToContents.remove(theLocation); keysToLocations.remove(key); } }
/* (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(); }
/* * XXX I hope this methos is not needed in this form */ public Map getKnownProjectsAndVersions(ICVSRepositoryLocation location) { Map knownTags = new HashMap(); RepositoryRoot root = getRepositoryRootFor(location); String[] paths = root.getKnownRemotePaths(); for (int i = 0; i < paths.length; i++) { String path = paths[i]; Set result = new HashSet(); result.addAll(Arrays.asList(root.getAllKnownTags(path))); knownTags.put(path, result); } return knownTags; }
public void testGetAction() { final ArrayList actionsList1 = new ArrayList(); InstallableUnitPhase phase1 = new InstallableUnitPhase("test", 1) { protected List<ProvisioningAction> getActions(InstallableUnitOperand operand) { List<ProvisioningAction> actions = getActions(operand.second(), "test1"); actionsList1.addAll(actions); return actions; } }; final ArrayList actionsList2 = new ArrayList(); InstallableUnitPhase phase2 = new InstallableUnitPhase("test", 1) { protected List<ProvisioningAction> getActions(InstallableUnitOperand operand) { List<ProvisioningAction> actions = getActions(operand.second(), "test2"); actionsList2.addAll(actions); return actions; } }; PhaseSet phaseSet = new TestPhaseSet(new Phase[] {phase1, phase2}); IProfile profile = createProfile("PhaseTest"); Map instructions = new HashMap(); instructions.put("test1", MetadataFactory.createTouchpointInstruction("test1.test()", null)); instructions.put("test2", MetadataFactory.createTouchpointInstruction("test2.test()", null)); ITouchpointData touchpointData = MetadataFactory.createTouchpointData(instructions); IInstallableUnit unit = createIU( "test", Version.create("1.0.0"), null, NO_REQUIRES, new IProvidedCapability[0], NO_PROPERTIES, ITouchpointType.NONE, touchpointData, false); IProvisioningPlan plan = engine.createPlan(profile, null); plan.addInstallableUnit(unit); IStatus status = engine.perform(plan, phaseSet, new NullProgressMonitor()); if (!status.isOK()) { fail(status.toString()); } assertEquals( TestAction.class, ((ParameterizedProvisioningAction) actionsList1.get(0)).getAction().getClass()); assertEquals( TestAction.class, ((ParameterizedProvisioningAction) actionsList2.get(0)).getAction().getClass()); }
public static String resolveArtifactParam(Map<String, Object> parameters) throws CoreException { String artifactLocation = (String) parameters.get(EclipseTouchpoint.PARM_ARTIFACT_LOCATION); if (artifactLocation != null) return artifactLocation; IArtifactKey artifactKey = (IArtifactKey) parameters.get(EclipseTouchpoint.PARM_ARTIFACT); if (artifactKey == null) { IInstallableUnit iu = (IInstallableUnit) parameters.get(EclipseTouchpoint.PARM_IU); throw new CoreException(Util.createError(NLS.bind(Messages.iu_contains_no_arifacts, iu))); } throw new CoreException( Util.createError(NLS.bind(Messages.artifact_file_not_found, artifactKey))); }
private String readPatch(ServletInputStream requestStream, String contentType) throws IOException { // fast forward stream past multi-part header int boundaryOff = contentType.indexOf("boundary="); // $NON-NLS-1$ String boundary = contentType.substring( boundaryOff + "boundary=".length(), contentType.length()); // $NON-NLS-1$ Map<String, String> parts = IOUtilities.parseMultiPart(requestStream, boundary); if ("fileRadio".equals(parts.get("radio"))) // $NON-NLS-1$ //$NON-NLS-2$ return parts.get("uploadedfile"); // $NON-NLS-1$ if ("urlRadio".equals(parts.get("radio"))) // $NON-NLS-1$ //$NON-NLS-2$ return fetchPatchContentFromUrl(parts.get("url")); // $NON-NLS-1$ return null; }
/** * 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); } } } }
private void broadcastRepositoryChange(RepositoryRoot root) { if (notificationLevel == 0) { broadcastRepositoriesChanged(new ICVSRepositoryLocation[] {root.getRoot()}); } else { changedRepositories.put(root.getRoot().getLocation(false), root.getRoot()); } }
/* * (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; } }
public RepositoryRoot getRepositoryRootFor(ICVSRepositoryLocation location) { RepositoryRoot root = (RepositoryRoot) repositoryRoots.get(location.getLocation(false)); if (root == null) { root = new RepositoryRoot(location); add(root); } return root; }
/** * Run the given runnable, waiting until the end to perform a refresh * * @param runnable * @param monitor */ public void run(IRunnableWithProgress runnable, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { notificationLevel++; runnable.run(monitor); } finally { notificationLevel = Math.max(0, notificationLevel - 1); if (notificationLevel == 0) { try { Collection roots = changedRepositories.values(); broadcastRepositoriesChanged( (ICVSRepositoryLocation[]) roots.toArray(new ICVSRepositoryLocation[roots.size()])); } finally { changedRepositories.clear(); } } } }
protected IStatus initializeOperand( IProfile profile, InstallableUnitOperand operand, Map parameters, IProgressMonitor monitor) { parameters.put("TestPhase.initializeOperand", "true"); initializeOperand = true; return super.initializeOperand(profile, operand, parameters, monitor); }
public IStatus getArtifact( IArtifactDescriptor descriptor, OutputStream destination, IProgressMonitor monitor) { ProcessingStepHandler handler = new ProcessingStepHandler(); destination = handler.createAndLink( getProvisioningAgent(), descriptor.getProcessingSteps(), null, destination, monitor); testhandler.download(keysToLocations.get(descriptor.getArtifactKey()), destination, monitor); return Status.OK_STATUS; }
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; }
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 static void getGitDirsInParents(File file, Map<IPath, File> gitDirs) { int levelUp = 0; File workspaceRoot = Activator.getDefault().getPlatformLocation().toFile(); while (file != null && !file.getAbsolutePath().equals(workspaceRoot.getAbsolutePath())) { if (file.exists()) { if (RepositoryCache.FileKey.isGitRepository(file, FS.DETECTED)) { gitDirs.put(getPathForLevelUp(levelUp), file); return; } else if (RepositoryCache.FileKey.isGitRepository( new File(file, Constants.DOT_GIT), FS.DETECTED)) { gitDirs.put(getPathForLevelUp(levelUp), new File(file, Constants.DOT_GIT)); return; } } file = file.getParentFile(); levelUp++; } return; }
private void validateIdentifierAttribute(Element element, Attr attr, ISchemaAttribute attInfo) { int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_IDENTIFIER); if (severity != CompilerFlags.IGNORE) { String value = attr.getValue(); String basedOn = attInfo.getBasedOn(); // only validate if we have a valid value and basedOn value if (value != null && basedOn != null && value.length() > 0 && basedOn.length() > 0) { Map attributes = PDESchemaHelper.getValidAttributes(attInfo); if (!attributes.containsKey(value)) { // report error if we are missing something report( NLS.bind( MDECoreMessages.ExtensionsErrorReporter_unknownIdentifier, (new String[] {attr.getValue(), attr.getName()})), getLine(element, attr.getName()), severity, MDEMarkerFactory.CAT_OTHER); } } } }
private static synchronized String getSymbolicName(String path) { if (fCachedLocations == null) fCachedLocations = new HashMap(); File file = new File(path); if (file.exists() && !fCachedLocations.containsKey(path)) { try { Dictionary dictionary = MinimalState.loadManifest(file); String value = (String) dictionary.get(Constants.BUNDLE_SYMBOLICNAME); if (value != null) { ManifestElement[] elements = ManifestElement.parseHeader(Constants.BUNDLE_SYMBOLICNAME, value); String id = elements.length > 0 ? elements[0].getValue() : null; if (id != null) fCachedLocations.put(path, elements[0].getValue()); } } catch (IOException e) { } catch (BundleException e) { } } return (String) fCachedLocations.get(path); }
public static synchronized IFileArtifactRepository getBundlePoolRepository( IProvisioningAgent agent, IProfile profile) { URI location = getBundlePoolLocation(agent, profile); if (location == null) return null; IArtifactRepositoryManager manager = getArtifactRepositoryManager(agent); try { return (IFileArtifactRepository) manager.loadRepository(location, null); } catch (ProvisionException e) { // the repository doesn't exist, so fall through and create a new one } try { String repositoryName = Messages.BundlePool; Map<String, String> properties = new HashMap<String, String>(1); properties.put(IRepository.PROP_SYSTEM, Boolean.TRUE.toString()); return (IFileArtifactRepository) manager.createRepository(location, repositoryName, REPOSITORY_TYPE, properties); } catch (ProvisionException e) { LogHelper.log(e); throw new IllegalArgumentException(NLS.bind(Messages.bundle_pool_not_writeable, location)); } }
private FragmentedWizardPage getFragmentData(WizardFragment fragment) { try { FragmentedWizardPage page = (FragmentedWizardPage) fragmentData.get(fragment); if (page != null) return page; } catch (Exception e) { PHPUiPlugin.log( new Status( IStatus.ERROR, PHPUiPlugin.ID, 0, "Error getting fragment data", e)); // $NON-NLS-1$ } return null; }
/** @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; }