List of usage examples for org.eclipse.jgit.api.errors CanceledException CanceledException
public CanceledException(String message)
Constructor for CanceledException.
From source file:ch.sourcepond.maven.release.scm.git.GitProposedTagTest.java
License:Apache License
@Test public void saveAtHEADFailed() throws Exception { prepareTagAndPush();// w w w . j a v a2 s . c o m final GitAPIException expected = new CanceledException(ANY_MESSAGE); doThrow(expected).when(tagCommand).call(); try { tag.tagAndPush(); fail("Exception expected"); } catch (final SCMException e) { assertEquals("Ref 'anyName' could be saved at HEAD!", e.getMessage()); assertSame(expected, e.getCause()); } }
From source file:ch.sourcepond.maven.release.scm.git.GitProposedTagTest.java
License:Apache License
@Test public void tagAndPushFailed() throws Exception { prepareTagAndPush();/* w ww . j a va 2 s .c o m*/ final GitAPIException expected = new CanceledException(ANY_MESSAGE); doThrow(expected).when(pushCommand).call(); try { tag.tagAndPush(); fail("Exception expected"); } catch (final SCMException e) { assertEquals("Tag 'anyName' could not be pushed!", e.getMessage()); assertSame(expected, e.getCause()); } }
From source file:ch.sourcepond.maven.release.scm.git.GitProposedTagTest.java
License:Apache License
@Test public void deleteFailed() throws Exception { when(deleteTagCommand.setTags(ANY_NAME)).thenReturn(deleteTagCommand); when(git.tagDelete()).thenReturn(deleteTagCommand); final GitAPIException expected = new CanceledException(ANY_MESSAGE); doThrow(expected).when(deleteTagCommand).call(); try {// w w w .j av a 2 s.c o m tag.delete(); fail("Exception expected!"); } catch (final SCMException e) { assertEquals("Remote tag 'anyName' could not be deleted!", e.getMessage()); assertSame(expected, e.getCause()); } }
From source file:org.eclipse.thym.core.plugin.CordovaPluginManager.java
License:Open Source License
/** * Installs a Cordova plug-in from a git repository. * This method delegates to {@link #doInstallPlugin(File)} after cloning the * repository to a temporary location to complete the installation of the * plug-in. /* w ww . j av a 2s .c om*/ * <br/> * If commit is not null the cloned repository will be checked out to * commit. * <br/> * If subdir is not null it is assumed that the subdir path exists and installation * will be done from that location. * * @param uri * @param overwrite * @param isDependency * @param monitor * @param commit * @param subdir * @throws CoreException */ public void installPlugin(URI uri, FileOverwriteCallback overwrite, boolean isDependency, IProgressMonitor monitor) throws CoreException { File tempRepoDirectory = new File(FileUtils.getTempDirectory(), "cordova_plugin_tmp_" + Long.toString(System.currentTimeMillis())); tempRepoDirectory.deleteOnExit(); try { if (monitor.isCanceled()) return; monitor.subTask("Clone plugin repository"); String gitUrl = uri.getScheme() + ":" + uri.getSchemeSpecificPart(); Git git = Git.cloneRepository().setDirectory(tempRepoDirectory).setURI(gitUrl).call(); File pluginDirectory = tempRepoDirectory; String fragment = uri.getFragment(); String commit = null; String subdir = null; if (fragment != null) { int idx = fragment.indexOf(':'); if (idx < 0) { idx = fragment.length(); } commit = fragment.substring(0, idx); subdir = fragment.substring(Math.min(idx + 1, fragment.length())); if (monitor.isCanceled()) { throw new CanceledException("Plug-in installation cancelled"); } if (commit != null && !commit.isEmpty()) { git.checkout().setName(commit).call(); } monitor.worked(1); if (subdir != null && !subdir.isEmpty()) { pluginDirectory = new File(tempRepoDirectory, subdir); if (!pluginDirectory.isDirectory()) { throw new CoreException(new Status(IStatus.ERROR, HybridCore.PLUGIN_ID, NLS.bind("{0} directory does not exist in this git repository", subdir))); } } } SubProgressMonitor sm = new SubProgressMonitor(monitor, 1); Document doc = readPluginXML(pluginDirectory); this.doInstallPlugin(pluginDirectory, doc, overwrite, sm); String id = CordovaPluginXMLHelper.getAttributeValue(doc.getDocumentElement(), "id"); JsonObject source = new JsonObject(); source.addProperty("type", "git"); source.addProperty("url", gitUrl); if (subdir != null && !subdir.isEmpty()) { source.addProperty("subdir", subdir); } if (commit != null && !commit.isEmpty()) { source.addProperty("ref", commit); } this.saveFetchMetadata(source, id, monitor); if (!isDependency) {//update config.xml List<IPluginInstallationAction> actions = new ArrayList<IPluginInstallationAction>(1); Map<String, String> params = new HashMap<String, String>(); params.put("url", uri.toString()); actions.add(getPluginInstallRecordAction(doc, params)); runActions(actions, false, overwrite, monitor); } } catch (GitAPIException e) { throw new CoreException( new Status(IStatus.ERROR, HybridCore.PLUGIN_ID, "Error cloning the plugin repository", e)); } finally { monitor.done(); } }
From source file:org.flowerplatform.web.git.operation.internal.PullCommand.java
License:Open Source License
/** * Executes the {@code Pull} command with all the options and parameters * collected by the setter methods (e.g. * {@link #setProgressMonitor(ProgressMonitor)}) of this class. Each * instance of this class should only be used for one invocation of the * command. Don't call this method twice on an instance. * * @return the result of the pull/*from w w w . j a v a 2s . c om*/ * @throws WrongRepositoryStateException * @throws InvalidConfigurationException * @throws DetachedHeadException * @throws InvalidRemoteException * @throws CanceledException * @throws RefNotFoundException * @throws NoHeadException * @throws org.eclipse.jgit.api.errors.TransportException * @throws GitAPIException */ @SuppressWarnings("restriction") public PullResult call() throws GitAPIException, WrongRepositoryStateException, InvalidConfigurationException, DetachedHeadException, InvalidRemoteException, CanceledException, RefNotFoundException, NoHeadException, org.eclipse.jgit.api.errors.TransportException { checkCallable(); monitor.beginTask(JGitText.get().pullTaskName, 2); Object[] data = GitPlugin.getInstance().getUtils().getFetchPushUpstreamDataRefSpecAndRemote(repo); String fullBranch = (String) data[0]; String branchName = fullBranch.substring(Constants.R_HEADS.length()); if (!repo.getRepositoryState().equals(RepositoryState.SAFE)) throw new WrongRepositoryStateException(MessageFormat.format(JGitText.get().cannotPullOnARepoWithState, repo.getRepositoryState().name())); // get the configured remote for the currently checked out branch // stored in configuration key branch.<branch name>.remote Config repoConfig = repo.getConfig(); String remote = repoConfig.getString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REMOTE); if (remote == null) // fall back to default remote remote = Constants.DEFAULT_REMOTE_NAME; // get the name of the branch in the remote repository // stored in configuration key branch.<branch name>.merge String remoteBranchName = (String) data[1]; // determines whether rebase should be used after fetching boolean doRebase = (boolean) data[3]; final boolean isRemote = !remote.equals("."); //$NON-NLS-1$ String remoteUri; FetchResult fetchRes; if (isRemote) { remoteUri = (String) data[2]; if (monitor.isCancelled()) throw new CanceledException( MessageFormat.format(JGitText.get().operationCanceled, JGitText.get().pullTaskName)); RefSpec refSpec = new RefSpec(); refSpec = refSpec.setForceUpdate(true); refSpec = refSpec.setSourceDestination(remoteBranchName, fullBranch); FetchCommand fetch = new Git(repo).fetch().setRemote(remote).setRefSpecs(refSpec); fetch.setProgressMonitor(monitor); configure(fetch); fetchRes = fetch.call(); } else { // we can skip the fetch altogether remoteUri = "local repository"; fetchRes = null; } monitor.update(1); if (monitor.isCancelled()) throw new CanceledException( MessageFormat.format(JGitText.get().operationCanceled, JGitText.get().pullTaskName)); // we check the updates to see which of the updated branches // corresponds // to the remote branch name AnyObjectId commitToMerge; if (isRemote) { Ref r = null; if (fetchRes != null) { r = fetchRes.getAdvertisedRef(remoteBranchName); if (r == null) r = fetchRes.getAdvertisedRef(Constants.R_HEADS + remoteBranchName); } if (r == null) throw new JGitInternalException( MessageFormat.format(JGitText.get().couldNotGetAdvertisedRef, remoteBranchName)); else commitToMerge = r.getObjectId(); } else { try { commitToMerge = repo.resolve(remoteBranchName); if (commitToMerge == null) throw new RefNotFoundException( MessageFormat.format(JGitText.get().refNotResolved, remoteBranchName)); } catch (IOException e) { throw new JGitInternalException(JGitText.get().exceptionCaughtDuringExecutionOfPullCommand, e); } } String upstreamName = "branch \'" + Repository.shortenRefName(remoteBranchName) + "\' of " + remoteUri; PullResult result; if (doRebase) { RebaseCommand rebase = new Git(repo).rebase(); RebaseResult rebaseRes = rebase.setUpstream(commitToMerge).setUpstreamName(upstreamName) .setProgressMonitor(monitor).setOperation(Operation.BEGIN).call(); result = new PullResult(fetchRes, remote, rebaseRes); } else { MergeCommand merge = new Git(repo).merge(); merge.include(upstreamName, commitToMerge); MergeResult mergeRes = merge.call(); monitor.update(1); result = new PullResult(fetchRes, remote, mergeRes); } monitor.endTask(); return result; }