/** * After trying to set addRepository with p2.inf for 2 full days, I ended up to set it * programmatically like others also did, found a solution here: <a href= * "http://coopology.com/2012/08/eclipse-rcp-setting-p2-repositories-update-sites-programmatically-for-when-p2-inf-fails/" * >http://coopology.com/2012/08/eclipse-rcp-setting-p2-repositories-update-sites- * programmatically-for-when-p2-inf-fails/</a> * * @param memento * @throws InvocationTargetException */ public static void setUpdateSites(final IMemento memento) { // // Original // // ElementUtils.updateRepositoryUsingElements(ui, DEFAULT_UPDATE_SITES, null); // final MetadataRepositoryElement[] mergedRepos = mergeRepositories(memento); try { updateRepositoryUsingElements(ProvisioningUI.getDefaultUI(), mergedRepos, null); } catch (final Exception e) { // this can occure when running in the IDE StatusUtil.handleStatus(e, 0); } }
@Override public void execute() { CommandProvider provider = (CommandProvider) getProvider(); try { provider.executeCommand(parameterizedCommand); } catch (Exception e) { StatusUtil.handleStatus(e, StatusManager.SHOW | StatusManager.LOG); } return; }
private static ArrayList<MetadataRepositoryElement> getOldRepos(final IMemento memento) { final ArrayList<MetadataRepositoryElement> oldRepos = new ArrayList<MetadataRepositoryElement>(); try { final IMemento xmlRepos = memento.getChild(TAG_REPOSITORIES); for (final IMemento xmlRepo : xmlRepos.getChildren(TAG_REPOSITORY)) { final String uriName = xmlRepo.getString(ATTR_URI); final String nickName = xmlRepo.getString(ATTR_NICK_NAME); final Boolean isEnabled = xmlRepo.getBoolean(ATTR_IS_ENABLED); if (uriName != null && isEnabled != null) { final MetadataRepositoryElement oldRepo = new MetadataRepositoryElement(null, // new URI(uriName), isEnabled); if (nickName != null) { oldRepo.setNickname(nickName); } oldRepos.add(oldRepo); } else { StatusUtil.handleStatus(String.format( "Repository data is invalid - Nickname:%s - URI:%s - Enabled:%s", //$NON-NLS-1$ nickName, uriName, isEnabled), 0); } } } catch (final Exception e) { StatusUtil.handleStatus(e, 0); } return oldRepos; }
/** * Logs the given exception, and opens an error dialog saying that something went wrong. The exception is assumed to * have something to do with the preference store. * @param exception * The exception to be logged; must not be <code>null</code>. */ private final void logPreferenceStoreException(final Throwable exception) { final String message = NewKeysPreferenceMessages.PreferenceStoreError_Message; String exceptionMessage = exception.getMessage(); if (exceptionMessage == null) { exceptionMessage = message; } final IStatus status = new Status(IStatus.ERROR, WorkbenchPlugin.PI_WORKBENCH, 0, exceptionMessage, exception); WorkbenchPlugin.log(message, status); StatusUtil.handleStatus(message, exception, StatusManager.SHOW); }
/** * Save update sites in a memento because when a new app is installed then the configuration is * cleaned up. */ public static void saveState(final IMemento memento) { try { final ProvisioningUI ui = ProvisioningUI.getDefaultUI(); ui.signalRepositoryOperationStart(); final IMetadataRepositoryManager metaManager = ProvUI.getMetadataRepositoryManager(ui.getSession()); try { final int visibilityFlags = ui.getRepositoryTracker().getMetadataRepositoryFlags(); final URI[] currentlyEnabledURIs = metaManager.getKnownRepositories(// IRepositoryManager.REPOSITORIES_ALL); final URI[] currentlyDisabledURIs = metaManager.getKnownRepositories(// IRepositoryManager.REPOSITORIES_DISABLED | visibilityFlags); final IMemento xmlRepositories = memento.createChild(TAG_REPOSITORIES); saveState_URI(currentlyEnabledURIs, metaManager, xmlRepositories, true); saveState_URI(currentlyDisabledURIs, metaManager, xmlRepositories, false); } finally { ui.signalRepositoryOperationComplete(null, true); } } catch (final Exception e) { // this can occure when running in the IDE StatusUtil.handleStatus(e, 0); } }