protected int runEclipse(String message, File location, String[] args, File extensions) { File root = new File(Activator.getBundleContext().getProperty("java.home")); root = new File(root, "bin"); File exe = new File(root, "javaw.exe"); if (!exe.exists()) exe = new File(root, "java"); assertTrue("Java executable not found in: " + exe.getAbsolutePath(), exe.exists()); List<String> command = new ArrayList<String>(); Collections.addAll( command, new String[] { (new File(location == null ? output : location, getExeFolder() + "eclipse")) .getAbsolutePath(), "--launcher.suppressErrors", "-nosplash", "-vm", exe.getAbsolutePath() }); Collections.addAll(command, args); Collections.addAll(command, new String[] {"-vmArgs", "-Dosgi.checkConfiguration=true"}); // command-line if you want to run and allow a remote debugger to connect if (debug) Collections.addAll( command, new String[] { "-Xdebug", "-Xnoagent", "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8787" }); int result = run(message, command.toArray(new String[command.size()])); // 13 means that we wrote something out in the log file. // so try and parse it and fail via that message if we can. if (result == 13) parseExitdata(message); return result; }
@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); } }
protected List<ProvisioningAction> getActions(InstallableUnitOperand operand) { IInstallableUnit unit = operand.second(); List<ProvisioningAction> parsedActions = getActions(unit, phaseId); if (parsedActions != null) return parsedActions; ITouchpointType type = unit.getTouchpointType(); if (type == null || type == ITouchpointType.NONE) return null; String actionId = getActionManager().getTouchpointQualifiedActionId(phaseId, type); ProvisioningAction action = getActionManager().getAction(actionId, null); if (action == null) { throw new IllegalArgumentException("action not found: " + phaseId); } return Collections.singletonList(action); }
private boolean handleGetCommitBody( HttpServletRequest request, HttpServletResponse response, Repository db, String ref, String pattern) throws IOException, ServletException, CoreException { ObjectId refId = db.resolve(ref); if (refId == null) { String msg = NLS.bind("Failed to get commit body for ref {0}", ref); return statusHandler.handleRequest( request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, msg, null)); } RevWalk walk = new RevWalk(db); walk.setTreeFilter( AndTreeFilter.create( PathFilterGroup.createFromStrings(Collections.singleton(pattern)), TreeFilter.ANY_DIFF)); RevCommit revCommit = walk.parseCommit(refId); walk.dispose(); Commit commit = new Commit(null /* not needed */, db, revCommit, pattern); ObjectStream stream = commit.toObjectStream(); if (stream == null) { String msg = NLS.bind("Commit body for ref {0} not found", ref); return statusHandler.handleRequest( request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, msg, null)); } IOUtilities.pipe(stream, response.getOutputStream(), true, false); return true; }
public AbstractModel() { fListeners = Collections.synchronizedList(new ArrayList<IModelChangedListener>()); }
public void fill(Menu menu, int index) { final IFileRevision fileRevision = getFileRevision(); if (fileRevision == null) { return; } IEditorDescriptor defaultTextEditor = registry.findEditor("org.eclipse.ui.DefaultTextEditor"); // $NON-NLS-1$ IEditorDescriptor preferredEditor = Utils.getDefaultEditor(fileRevision); Object[] editors = Utils.getEditors(fileRevision); Collections.sort(Arrays.asList(editors), comparer); boolean defaultFound = false; // Check that we don't add it twice. This is possible // if the same editor goes to two mappings. ArrayList alreadyMapped = new ArrayList(); for (int i = 0; i < editors.length; i++) { IEditorDescriptor editor = (IEditorDescriptor) editors[i]; if (!alreadyMapped.contains(editor)) { createMenuItem(menu, editor, preferredEditor); if (defaultTextEditor != null && editor.getId().equals(defaultTextEditor.getId())) { defaultFound = true; } alreadyMapped.add(editor); } } // Only add a separator if there is something to separate if (editors.length > 0) { new MenuItem(menu, SWT.SEPARATOR); } // Add default editor. Check it if it is saved as the preference. if (!defaultFound && defaultTextEditor != null) { createMenuItem(menu, defaultTextEditor, preferredEditor); } // TODO : We might perhaps enable inplace and system external editors menu items /*// Add system editor IEditorDescriptor descriptor = registry .findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID); final MenuItem systemEditorMenuItem = createMenuItem(menu, descriptor, preferredEditor); systemEditorMenuItem.setEnabled(false); // Add system in-place editor descriptor = registry .findEditor(IEditorRegistry.SYSTEM_INPLACE_EDITOR_ID); final MenuItem inPlaceEditorMenuItem = (descriptor != null) ? createMenuItem( menu, descriptor, preferredEditor) : null; if (inPlaceEditorMenuItem != null) inPlaceEditorMenuItem.setEnabled(false); Job job = new Job("updateOpenWithMenu") { //$NON-NLS-1$ protected IStatus run(IProgressMonitor monitor) { try { final boolean isFile = fileRevision.getStorage(monitor) instanceof IFile; Display.getDefault().asyncExec(new Runnable() { public void run() { if (inPlaceEditorMenuItem != null && !inPlaceEditorMenuItem.isDisposed()) inPlaceEditorMenuItem.setEnabled(isFile); if (!systemEditorMenuItem.isDisposed()) systemEditorMenuItem.setEnabled(isFile); } }); return Status.OK_STATUS; } catch (CoreException e) { return new Status(IStatus.WARNING, TeamUIPlugin.ID, null, e); } }; }; job.setSystem(true); job.schedule();*/ createDefaultMenuItem(menu, fileRevision); // add Other... menu item createOtherMenuItem(menu); }
void undo( MultiStatus status, EngineSession session, IProfile profile, Operand operand, ProvisioningAction[] actions, ProvisioningContext context) { if (operandParameters == null) { operandParameters = new HashMap<String, Object>(phaseParameters); operandParameters.put(PARM_OPERAND, operand); mergeStatus( status, initializeOperand(profile, operand, operandParameters, new NullProgressMonitor())); Touchpoint operandTouchpoint = (Touchpoint) operandParameters.get(PARM_TOUCHPOINT); if (operandTouchpoint != null) { mergeStatus( status, initializeTouchpointParameters( profile, operand, operandTouchpoint, new NullProgressMonitor())); if (status.matches(IStatus.ERROR | IStatus.CANCEL)) return; operandParameters = touchpointToTouchpointOperandParameters.get(operandTouchpoint); } operandParameters = Collections.unmodifiableMap(operandParameters); } for (int j = 0; j < actions.length; j++) { ProvisioningAction action = actions[j]; Map<String, Object> parameters = operandParameters; Touchpoint touchpoint = action.getTouchpoint(); if (touchpoint != null) { mergeStatus( status, initializeTouchpointParameters( profile, operand, touchpoint, new NullProgressMonitor())); if (status.matches(IStatus.ERROR)) return; parameters = touchpointToTouchpointOperandParameters.get(touchpoint); } IStatus actionStatus = null; try { session.recordActionUndo(action, parameters); actionStatus = action.undo(parameters); } catch (RuntimeException e) { // "action.undo" calls user code and might throw an unchecked exception // we catch the error here to gather information on where the problem occurred. actionStatus = new Status( IStatus.ERROR, EngineActivator.ID, NLS.bind(Messages.action_undo_error, action.getClass().getName()), e); } catch (LinkageError e) { // Catch linkage errors as these are generally recoverable but let other Errors propagate // (see bug 222001) actionStatus = new Status( IStatus.ERROR, EngineActivator.ID, NLS.bind(Messages.action_undo_error, action.getClass().getName()), e); } if (actionStatus != null && actionStatus.matches(IStatus.ERROR)) { MultiStatus result = new MultiStatus(EngineActivator.ID, IStatus.ERROR, getProblemMessage(), null); result.add( new Status( IStatus.ERROR, EngineActivator.ID, session.getContextString(this, operand, action), null)); result.merge(actionStatus); } } mergeStatus( status, touchpointCompleteOperand(profile, operand, operandParameters, new NullProgressMonitor())); mergeStatus( status, completeOperand(profile, operand, operandParameters, new NullProgressMonitor())); operandParameters = null; }
private void mainPerform( MultiStatus status, EngineSession session, Operand[] operands, SubMonitor subMonitor) { IProfile profile = session.getProfile(); subMonitor.beginTask(null, operands.length); for (int i = 0; i < operands.length; i++) { subMonitor.setWorkRemaining(operands.length - i); if (subMonitor.isCanceled()) throw new OperationCanceledException(); Operand operand = operands[i]; if (!isApplicable(operand)) continue; session.recordOperandStart(operand); List<ProvisioningAction> actions = getActions(operand); operandParameters = new HashMap<String, Object>(phaseParameters); operandParameters.put(PARM_OPERAND, operand); mergeStatus(status, initializeOperand(profile, operand, operandParameters, subMonitor)); if (status.matches(IStatus.ERROR | IStatus.CANCEL)) { operandParameters = null; return; } Touchpoint operandTouchpoint = (Touchpoint) operandParameters.get(PARM_TOUCHPOINT); if (operandTouchpoint != null) { mergeStatus( status, initializeTouchpointParameters(profile, operand, operandTouchpoint, subMonitor)); if (status.matches(IStatus.ERROR | IStatus.CANCEL)) return; operandParameters = touchpointToTouchpointOperandParameters.get(operandTouchpoint); } operandParameters = Collections.unmodifiableMap(operandParameters); if (actions != null) { for (int j = 0; j < actions.size(); j++) { ProvisioningAction action = actions.get(j); Map<String, Object> parameters = operandParameters; Touchpoint touchpoint = action.getTouchpoint(); if (touchpoint != null) { mergeStatus( status, initializeTouchpointParameters(profile, operand, touchpoint, subMonitor)); if (status.matches(IStatus.ERROR | IStatus.CANCEL)) return; parameters = touchpointToTouchpointOperandParameters.get(touchpoint); } IStatus actionStatus = null; try { session.recordActionExecute(action, parameters); actionStatus = action.execute(parameters); } catch (RuntimeException e) { if (!forced) throw e; // "action.execute" calls user code and might throw an unchecked exception // we catch the error here to gather information on where the problem occurred. actionStatus = new Status( IStatus.ERROR, EngineActivator.ID, NLS.bind(Messages.forced_action_execute_error, action.getClass().getName()), e); } catch (LinkageError e) { if (!forced) throw e; // Catch linkage errors as these are generally recoverable but let other Errors // propagate (see bug 222001) actionStatus = new Status( IStatus.ERROR, EngineActivator.ID, NLS.bind(Messages.forced_action_execute_error, action.getClass().getName()), e); } if (forced && actionStatus != null && actionStatus.matches(IStatus.ERROR)) { MultiStatus result = new MultiStatus(EngineActivator.ID, IStatus.ERROR, getProblemMessage(), null); result.add( new Status( IStatus.ERROR, EngineActivator.ID, session.getContextString(this, operand, action), null)); LogHelper.log(result); actionStatus = Status.OK_STATUS; } mergeStatus(status, actionStatus); if (status.matches(IStatus.ERROR | IStatus.CANCEL)) return; } } mergeStatus( status, touchpointCompleteOperand(profile, operand, operandParameters, subMonitor)); mergeStatus(status, completeOperand(profile, operand, operandParameters, subMonitor)); if (status.matches(IStatus.ERROR | IStatus.CANCEL)) return; operandParameters = null; session.recordOperandEnd(operand); subMonitor.worked(1); } }
/* (non-Javadoc) * @see org.eclipse.ui.IWorkbenchPart3#getPartProperties() */ public Map getPartProperties() { return Collections.unmodifiableMap(partProperties); }
/** * 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; }