public static boolean isOptionEnabled(String option) { String enabled = Platform.getDebugOption(option); if (enabled == null) { return false; } return Boolean.parseBoolean(enabled); }
private boolean handlePost(HttpServletRequest request, HttpServletResponse response, String path) throws IOException, JSONException, ServletException, URISyntaxException, CoreException { Path p = new Path(path); if (p.segment(0).equals("file")) { // $NON-NLS-1$ // handle adding new remote // expected path: /git/remote/file/{path} return addRemote(request, response, path); } else { JSONObject requestObject = OrionServlet.readJSONRequest(request); boolean fetch = Boolean.parseBoolean(requestObject.optString(GitConstants.KEY_FETCH, null)); String srcRef = requestObject.optString(GitConstants.KEY_PUSH_SRC_REF, null); boolean tags = requestObject.optBoolean(GitConstants.KEY_PUSH_TAGS, false); boolean force = requestObject.optBoolean(GitConstants.KEY_FORCE, false); // prepare creds GitCredentialsProvider cp = GitUtils.createGitCredentialsProvider(requestObject); // if all went well, continue with fetch or push if (fetch) { return fetch(request, response, cp, path, force); } else if (srcRef != null) { return push(request, response, path, cp, srcRef, tags, force); } else { return statusHandler.handleRequest( request, response, new ServerStatus( IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Only Fetch:true is currently supported.", null)); } } }
private void initialize(final IRefreshSubscriberListener listener) { final GotoActionWrapper actionWrapper = new GotoActionWrapper(); IProgressMonitor group = Job.getJobManager().createProgressGroup(); group.beginTask(taskName, 100); setProgressGroup(group, 80); handleProgressGroupSet(group, 20); setProperty(IProgressConstants.ICON_PROPERTY, participant.getImageDescriptor()); setProperty(IProgressConstants.ACTION_PROPERTY, actionWrapper); setProperty(IProgressConstants.KEEPONE_PROPERTY, Boolean.valueOf(!isJobModal())); // Listener delegate IRefreshSubscriberListener autoListener = new IRefreshSubscriberListener() { @Override public void refreshStarted(IRefreshEvent event) { if (listener != null) { listener.refreshStarted(event); } } @Override public ActionFactory.IWorkbenchAction refreshDone(IRefreshEvent event) { if (listener != null) { boolean isModal = isJobModal(); event.setIsLink(!isModal); final ActionFactory.IWorkbenchAction runnable = listener.refreshDone(event); if (runnable != null) { // If the job is being run modally then simply prompt the user immediately if (isModal) { if (runnable != null) { Job update = new UIJob("") { // $NON-NLS-1$ @Override public IStatus runInUIThread(IProgressMonitor monitor) { runnable.run(); return Status.OK_STATUS; } }; update.setSystem(true); update.schedule(); } } else { // If the job is being run in the background, don't interrupt the user and simply // update the goto action // to perform the results. actionWrapper.setGotoAction(runnable); } } RefreshParticipantJob.removeRefreshListener(this); } return null; } }; if (listener != null) { RefreshParticipantJob.addRefreshListener(autoListener); } }
void prePerform(MultiStatus status, EngineSession session, IProgressMonitor monitor) { IProfile profile = session.getProfile(); phaseParameters.put(PARM_PROFILE, profile); phaseParameters.put(PARM_PROFILE_DATA_DIRECTORY, session.getProfileDataDirectory()); phaseParameters.put(PARM_CONTEXT, session.getProvisioningContext()); phaseParameters.put(PARM_PHASE_ID, phaseId); phaseParameters.put(PARM_FORCED, Boolean.toString(forced)); phaseParameters.put(PARM_AGENT, session.getAgent()); mergeStatus(status, initializePhase(monitor, profile, phaseParameters)); }
/* * 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 Set getApplicationNameSet() { TreeSet result = new TreeSet(); IExtension[] extensions = MDECore.getDefault() .getExtensionsRegistry() .findExtensions("org.eclipse.core.runtime.applications", true); // $NON-NLS-1$ for (int i = 0; i < extensions.length; i++) { String id = extensions[i].getUniqueIdentifier(); IConfigurationElement[] elements = extensions[i].getConfigurationElements(); if (elements.length != 1) continue; String visiblity = elements[0].getAttribute("visible"); // $NON-NLS-1$ boolean visible = visiblity == null ? true : Boolean.valueOf(visiblity).booleanValue(); if (id != null && visible) { result.add(id); } } result.add("org.eclipse.ui.ide.workbench"); // $NON-NLS-1$ return result; }
/** * Convenience method to parses the startData ("startLevel:autoStart"), convert it to the format * expected by the OSGi bundles property, and append to a StringBuffer. * * @param buffer buffer to append the data to * @param startData data to parse ("startLevel:autoStart") * @param defaultAuto default auto start setting */ private void appendStartData(StringBuffer buffer, String startData, boolean defaultAuto) { int index = startData.indexOf(':'); String level = index > 0 ? startData.substring(0, index) : "default"; // $NON-NLS-1$ String auto = index > 0 && index < startData.length() - 1 ? startData.substring(index + 1) : "default"; //$NON-NLS-1$ if ("default".equals(auto)) // $NON-NLS-1$ auto = Boolean.toString(defaultAuto); if (!level.equals("default") || "true".equals(auto)) // $NON-NLS-1$ //$NON-NLS-2$ buffer.append("@"); // $NON-NLS-1$ if (!level.equals("default")) { // $NON-NLS-1$ buffer.append(level); if ("true".equals(auto)) // $NON-NLS-1$ buffer.append(":"); // $NON-NLS-1$ } if ("true".equals(auto)) { // $NON-NLS-1$ buffer.append("start"); // $NON-NLS-1$ } }
private boolean isJobModal() { Boolean isModal = (Boolean) getProperty(IProgressConstants.PROPERTY_IN_DIALOG); if (isModal == null) return false; return isModal.booleanValue(); }
/** * This is run by the job scheduler. A list of subscribers will be refreshed, errors will not stop * the job and it will continue to refresh the other subscribers. */ @Override public IStatus run(IProgressMonitor monitor) { // Perform a pre-check for auto-build or manual build jobs // when auto-refreshing if (shouldReschedule() && (isJobInFamilyRunning(ResourcesPlugin.FAMILY_AUTO_BUILD) || isJobInFamilyRunning(ResourcesPlugin.FAMILY_MANUAL_BUILD))) { return POSTPONED; } // Only allow one refresh job at a time // NOTE: It would be cleaner if this was done by a scheduling // rule but at the time of writing, it is not possible due to // the scheduling rule containment rules. // Acquiring lock to ensure only one refresh job is running at a particular time boolean acquired = false; try { while (!acquired) { try { acquired = lock.acquire(1000); } catch (InterruptedException e1) { acquired = false; } Policy.checkCanceled(monitor); } IChangeDescription changeDescription = createChangeDescription(); RefreshEvent event = new RefreshEvent( reschedule ? IRefreshEvent.SCHEDULED_REFRESH : IRefreshEvent.USER_REFRESH, participant, changeDescription); IStatus status = null; NonblockingProgressMonitor wrappedMonitor = null; try { event.setStartTime(System.currentTimeMillis()); if (monitor.isCanceled()) { return Status.CANCEL_STATUS; } // Pre-Notify notifyListeners(STARTED, event); // Perform the refresh monitor.setTaskName(getName()); wrappedMonitor = new NonblockingProgressMonitor(monitor, this); doRefresh(changeDescription, wrappedMonitor); // Prepare the results setProperty(IProgressConstants.KEEPONE_PROPERTY, Boolean.valueOf(!isJobModal())); } catch (OperationCanceledException e2) { if (monitor.isCanceled()) { // The refresh was canceled by the user status = Status.CANCEL_STATUS; } else { // The refresh was canceled due to a blockage or a canceled authentication if (wrappedMonitor != null && wrappedMonitor.wasBlocking()) { status = POSTPONED; } else { status = Status.CANCEL_STATUS; } } } catch (CoreException e) { // Determine the status to be returned and the GOTO action status = e.getStatus(); if (!isUser()) { // Use the GOTO action to show the error and return OK Object prop = getProperty(IProgressConstants.ACTION_PROPERTY); if (prop instanceof GotoActionWrapper) { GotoActionWrapper wrapper = (GotoActionWrapper) prop; wrapper.setStatus(e.getStatus()); status = new Status(IStatus.OK, TeamUIPlugin.ID, IStatus.OK, e.getStatus().getMessage(), e); } } if (!isUser() && status.getSeverity() == IStatus.ERROR) { // Never prompt for errors on non-user jobs setProperty(IProgressConstants.NO_IMMEDIATE_ERROR_PROMPT_PROPERTY, Boolean.TRUE); } } finally { event.setStopTime(System.currentTimeMillis()); } // Post-Notify if (status == null) { status = calculateStatus(event); } event.setStatus(status); notifyListeners(DONE, event); if (event.getChangeDescription().getChangeCount() > 0) { if (participant instanceof AbstractSynchronizeParticipant) { AbstractSynchronizeParticipant asp = (AbstractSynchronizeParticipant) participant; asp.firePropertyChange( participant, ISynchronizeParticipant.P_CONTENT, null, event.getChangeDescription()); } } return event.getStatus(); } finally { if (acquired) lock.release(); monitor.done(); } }
@Override protected boolean handlePost(RequestInfo requestInfo) throws ServletException { String gitSegment = requestInfo.gitSegment; HttpServletRequest request = requestInfo.request; HttpServletResponse response = requestInfo.response; Repository db = requestInfo.db; String pattern = requestInfo.relativePath; JSONObject requestObject = requestInfo.getJSONRequest(); try { String commitToMerge = requestObject.optString(GitConstants.KEY_MERGE, null); if (commitToMerge != null) { boolean squash = requestObject.optBoolean(GitConstants.KEY_SQUASH, false); return merge(request, response, db, commitToMerge, squash); } String commitToRebase = requestObject.optString(GitConstants.KEY_REBASE, null); String rebaseOperation = requestObject.optString(GitConstants.KEY_OPERATION, null); if (commitToRebase != null) { return rebase(request, response, db, commitToRebase, rebaseOperation); } String commitToCherryPick = requestObject.optString(GitConstants.KEY_CHERRY_PICK, null); if (commitToCherryPick != null) { return cherryPick(request, response, db, commitToCherryPick); } String commitToRevert = requestObject.optString(GitConstants.KEY_REVERT, null); if (commitToRevert != null) { return revert(request, response, db, commitToRevert); } String newCommit = requestObject.optString(GitConstants.KEY_COMMIT_NEW, null); if (newCommit != null) return identifyNewCommitResource(request, response, db, newCommit); String reviewReqLogin = requestObject.optString(GitConstants.KEY_REVIEW_REQ_NOTIFY_LOGIN); if (reviewReqLogin != null && reviewReqLogin.length() != 0) { String reviewReqUrl = requestObject.optString(GitConstants.KEY_REVIEW_REQ_URL); String ReviewReqCommit = requestObject.optString(GitConstants.KEY_REVIEW_REQ_COMMIT); String ReviewReqAuthorName = requestObject.optString(GitConstants.KEY_REVIEW_REQ_AUTHOR_NAME); String ReviewMessage = requestObject.optString(GitConstants.KEY_REVIEW_REQ_MESSAGE); return sendNotification( request, response, db, reviewReqLogin, ReviewReqCommit, reviewReqUrl, ReviewReqAuthorName, ReviewMessage); } ObjectId refId = db.resolve(gitSegment); if (refId == null || !Constants.HEAD.equals(gitSegment)) { String msg = NLS.bind("Commit failed. Ref must be HEAD and is {0}", gitSegment); return statusHandler.handleRequest( request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, msg, null)); } String message = requestObject.optString(GitConstants.KEY_COMMIT_MESSAGE, null); if (message == null || message.isEmpty()) { return statusHandler.handleRequest( request, response, new ServerStatus( IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Missing commit message.", null)); } Git git = new Git(db); CommitCommand cc = git.commit(); Config config = git.getRepository().getConfig(); boolean amend = Boolean.parseBoolean(requestObject.optString(GitConstants.KEY_COMMIT_AMEND, null)); boolean insertChangeId = GitUtils.isGerrit(config) || Boolean.parseBoolean(requestObject.optString(GitConstants.KEY_CHANGE_ID, null)); String committerName = requestObject.optString(GitConstants.KEY_COMMITTER_NAME, null); String committerEmail = requestObject.optString(GitConstants.KEY_COMMITTER_EMAIL, null); String authorName = requestObject.optString(GitConstants.KEY_AUTHOR_NAME, null); String authorEmail = requestObject.optString(GitConstants.KEY_AUTHOR_EMAIL, null); // workaround of a bug in JGit which causes invalid // support of null values of author/committer name/email, see bug 352984 PersonIdent defPersonIdent = new PersonIdent(db); if (committerName == null) committerName = defPersonIdent.getName(); if (committerEmail == null) committerEmail = defPersonIdent.getEmailAddress(); if (authorName == null) authorName = committerName; if (authorEmail == null) authorEmail = committerEmail; cc.setCommitter(committerName, committerEmail); cc.setAuthor(authorName, authorEmail); if (insertChangeId) cc.setInsertChangeId(true); // support for committing by path: "git commit -o path" if (!pattern.isEmpty()) { cc.setOnly(pattern); } try { // "git commit [--amend] -m '{message}' [-a|{path}]" RevCommit lastCommit = cc.setAmend(amend).setMessage(message).call(); URI cloneLocation = BaseToCloneConverter.getCloneLocation( getURI(request), BaseToCloneConverter.COMMIT_REFRANGE); Commit commit = new Commit(cloneLocation, db, lastCommit, pattern); JSONObject result = commit.toJSON(); OrionServlet.writeJSONResponse( request, response, result, JsonURIUnqualificationStrategy.ALL_NO_GIT); return true; } catch (GitAPIException e) { return statusHandler.handleRequest( request, response, new ServerStatus( IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "An error occured when commiting.", e)); } catch (UnmergedPathException e) { return statusHandler.handleRequest( request, response, new ServerStatus( IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An internal error occured when commiting.", e)); } } catch (Exception e) { return statusHandler.handleRequest( request, response, new ServerStatus( IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An error occured when requesting a commit info.", e)); } }
public ProfileChangeRequest generateProfileChangeRequest( IProfile profile, MultiStatus status, IProgressMonitor monitor) { ProfileChangeRequest request = new ProfileChangeRequest(profile); String carbonHome = System.getProperty("carbon.home"); String cacheLocation = carbonHome + File.separator + "repository" + File.separator + "components"; request.setProfileProperty(IProfile.PROP_CACHE, cacheLocation); request.setProfileProperty( SimpleConfiguratorConstants.PROP_KEY_USE_REFERENCE, Boolean.TRUE.toString()); for (IInstallableUnit iu : iusToInstall) { // If the user is installing a patch, we mark it optional. This allows // the patched IU to be updated later by removing the patch. if (Boolean.toString(true) .equals(iu.getProperty(MetadataFactory.InstallableUnitDescription.PROP_TYPE_PATCH))) { request.setInstallableUnitInclusionRules( iu, ProfileInclusionRules.createOptionalInclusionRule(iu)); } // Check to see if it is already installed. This may alter the request. Collection alreadyInstalled = profile .query(QueryUtil.createIUQuery(iu.getId()), new NullProgressMonitor()) .toUnmodifiableSet(); if (alreadyInstalled.size() > 0) { IInstallableUnit installedIU = (IInstallableUnit) alreadyInstalled.iterator().next(); int compareTo = iu.getVersion().compareTo(installedIU.getVersion()); // If the iu is a newer version of something already installed, consider this an // update request if (compareTo > 0) { boolean lockedForUpdate = false; String value = profile.getInstallableUnitProperty(installedIU, IProfile.PROP_PROFILE_LOCKED_IU); if (value != null) { lockedForUpdate = (Integer.parseInt(value) & IProfile.LOCK_UPDATE) == IProfile.LOCK_UPDATE; } if (lockedForUpdate) { // Add a status telling the user that this implies an update, but the // iu should not be updated status.merge( new Status( IStatus.WARNING, "temp", 10013, installedIU.getId() + "-" + installedIU.getVersion() + " will be ignored because it is already installed, " + "and updates are not permitted.", null)); } else { request.addInstallableUnits(new IInstallableUnit[] {iu}); request.removeInstallableUnits(new IInstallableUnit[] {installedIU}); // Add a status informing the user that the update has been inferred status.merge( new Status( IStatus.WARNING, "temp", 10013, installedIU.getId() + "-" + installedIU.getVersion() + " is already installed, so an update will be performed instead.", null)); // Mark it as a root if it hasn't been already if (!Boolean.toString(true) .equals( profile.getInstallableUnitProperty( installedIU, IProfile.PROP_PROFILE_ROOT_IU))) { request.setInstallableUnitProfileProperty( iu, IProfile.PROP_PROFILE_ROOT_IU, Boolean.toString(true)); } } } else if (compareTo < 0) { // An implied downgrade. We will not put this in the plan, add a status informing the // user status.merge( new Status( IStatus.WARNING, "temp", 10004, installedIU.getId() + "-" + installedIU.getVersion() + " will be ignored because a newer version is already installed.", null)); } else { if (Boolean.toString(true) .equals( profile.getInstallableUnitProperty(installedIU, IProfile.PROP_PROFILE_ROOT_IU))) // It is already a root, nothing to do. We tell the user it was already installed { status.merge( new Status( IStatus.WARNING, "temp", 10005, installedIU.getId() + "-" + installedIU.getVersion() + " will be ignored because it is already installed.", null)); } else { // It was already installed but not as a root. // Tell the user that parts of it are already installed and mark it as a root. status.merge( new Status( IStatus.WARNING, "temp", 10006, installedIU.getId() + "-" + installedIU.getVersion() + " is already present because other installed software requires it. " + "It will be added to the installed software list.", null)); request.setInstallableUnitProfileProperty( iu, "org.eclipse.equinox.p2.type.root", Boolean.toString(true)); } } } else { // install this if only this is not category type if (!Boolean.toString(true) .equals( iu.getProperty(MetadataFactory.InstallableUnitDescription.PROP_TYPE_CATEGORY))) { // Install it and mark as a root request.addInstallableUnits(new IInstallableUnit[] {iu}); request.setInstallableUnitProfileProperty( iu, "org.eclipse.equinox.p2.type.root", Boolean.toString(true)); } } } return request; }
private void processEntryChanges( IResourceDelta projectDelta, Map<IProject, Boolean> projectsToSave) { // check each resource with user-set encoding to see if it has // been moved/deleted or if derived state has been changed IProject currentProject = (IProject) projectDelta.getResource(); Preferences projectRegularPrefs = getPreferences(currentProject, false, false, true); Preferences projectDerivedPrefs = getPreferences(currentProject, false, true, true); Map<Boolean, String[]> affectedResourcesMap = new HashMap<>(); try { // no regular preferences for this project if (projectRegularPrefs == null) affectedResourcesMap.put(Boolean.FALSE, new String[0]); else affectedResourcesMap.put(Boolean.FALSE, projectRegularPrefs.keys()); // no derived preferences for this project if (projectDerivedPrefs == null) affectedResourcesMap.put(Boolean.TRUE, new String[0]); else affectedResourcesMap.put(Boolean.TRUE, projectDerivedPrefs.keys()); } 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, currentProject.getFullPath(), message, e)); return; } for (Iterator<Boolean> it = affectedResourcesMap.keySet().iterator(); it.hasNext(); ) { Boolean isDerived = it.next(); String[] affectedResources = affectedResourcesMap.get(isDerived); Preferences projectPrefs = isDerived.booleanValue() ? projectDerivedPrefs : projectRegularPrefs; for (int i = 0; i < affectedResources.length; i++) { IResourceDelta memberDelta = projectDelta.findMember(new Path(affectedResources[i])); // no changes for the given resource if (memberDelta == null) continue; if (memberDelta.getKind() == IResourceDelta.REMOVED) { boolean shouldDisableCharsetDeltaJobForCurrentProject = false; // remove the setting for the original location - save its value though String currentValue = projectPrefs.get(affectedResources[i], null); projectPrefs.remove(affectedResources[i]); if ((memberDelta.getFlags() & IResourceDelta.MOVED_TO) != 0) { IPath movedToPath = memberDelta.getMovedToPath(); IResource resource = workspace.getRoot().findMember(movedToPath); if (resource != null) { Preferences encodingSettings = getPreferences( resource.getProject(), true, resource.isDerived(IResource.CHECK_ANCESTORS)); if (currentValue == null || currentValue.trim().length() == 0) encodingSettings.remove(getKeyFor(movedToPath)); else encodingSettings.put(getKeyFor(movedToPath), currentValue); IProject targetProject = workspace.getRoot().getProject(movedToPath.segment(0)); if (targetProject.equals(currentProject)) // if the file was moved inside the same project disable charset listener shouldDisableCharsetDeltaJobForCurrentProject = true; else projectsToSave.put(targetProject, Boolean.FALSE); } } projectsToSave.put( currentProject, Boolean.valueOf(shouldDisableCharsetDeltaJobForCurrentProject)); } } if (moveSettingsIfDerivedChanged( projectDelta, currentProject, projectPrefs, affectedResources)) { // if settings were moved between preferences files disable charset listener so we don't // react to changes made by ourselves projectsToSave.put(currentProject, Boolean.TRUE); } } }
public boolean isModal() { Boolean m = (Boolean) getProperty(IProgressConstants.PROPERTY_IN_DIALOG); if (m == null) return false; return m.booleanValue(); }