本文整理匯總了Java中org.eclipse.jgit.api.errors.TransportException類的典型用法代碼示例。如果您正苦於以下問題:Java TransportException類的具體用法?Java TransportException怎麽用?Java TransportException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TransportException類屬於org.eclipse.jgit.api.errors包,在下文中一共展示了TransportException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: fetchExternalIdsBranch
import org.eclipse.jgit.api.errors.TransportException; //導入依賴的package包/類
@Test
public void fetchExternalIdsBranch() throws Exception {
TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers, user);
// refs/meta/external-ids is only visible to users with the 'Access Database' capability
try {
fetch(allUsersRepo, RefNames.REFS_EXTERNAL_IDS);
fail("expected TransportException");
} catch (TransportException e) {
assertThat(e.getMessage())
.isEqualTo(
"Remote does not have " + RefNames.REFS_EXTERNAL_IDS + " available for fetch.");
}
allowGlobalCapabilities(REGISTERED_USERS, GlobalCapability.ACCESS_DATABASE);
// re-clone to get new request context, otherwise the old global capabilities are still cached
// in the IdentifiedUser object
allUsersRepo = cloneProject(allUsers, user);
fetch(allUsersRepo, RefNames.REFS_EXTERNAL_IDS);
}
示例2: execute
import org.eclipse.jgit.api.errors.TransportException; //導入依賴的package包/類
private void execute() throws InvalidRemoteException, TransportException, GitAPIException, IOException {
setProxy();
CloneCommand cmd = Git.cloneRepository()
.setURI(config.getRemoteUrl());
if (config.getLocalPath() != "") {
cmd.setDirectory(new File(config.getLocalPath()));
}
Git git = cmd.call();
// Set proxy setting to repository config.
StoredConfig gitConfig = git.getRepository().getConfig();
gitConfig.setString("remote", "origin", "proxy", config.getProxyAddress());
gitConfig.save();
git.getRepository().close();
}
示例3: should_fail_with_repository_not_found_when_trying_to_clone_non_existing_repo
import org.eclipse.jgit.api.errors.TransportException; //導入依賴的package包/類
@Test
public void should_fail_with_repository_not_found_when_trying_to_clone_non_existing_repo() throws Exception {
// given
gitServer = EmbeddedHttpGitServer.fromBundle("launchpad", "saas-launchpad.bundle")
.usingPort(6432)
.create();
gitServer.start();
expectedException.expect(TransportException.class);
expectedException.expectMessage("Git repository not found");
// when
final GitCloner launchpadCloner = new GitCloner("http://localhost:6432/launchpadeeeee");
final Repository launchpad = launchpadCloner.cloneRepositoryToTempFolder();
// then
// should fail
}
示例4: shouldFailOnException
import org.eclipse.jgit.api.errors.TransportException; //導入依賴的package包/類
@Test
public void shouldFailOnException() throws Exception {
// Given
SyncableRepository pushRepository = config.getPushRepository();
Git git = mock(Git.class);
doNothing().when(git).close();
CloneCommand cloneCommand = mock(CloneCommand.class);
when(cloneCommand.setBare(true)).thenReturn(cloneCommand);
when(cloneCommand.call()).thenThrow(new TransportException("Expected test exception"));
when(pushRepository.clone(any())).thenReturn(cloneCommand);
when(config.configure(cloneCommand)).thenReturn(cloneCommand);
exception.expect(TransportException.class);
exception.expectMessage("Expected test exception");
// When
Status status = uut.call();
// Then
assertThat(status, is(FAILED));
}
示例5: testRemoteRepositoryHasNoCommitst
import org.eclipse.jgit.api.errors.TransportException; //導入依賴的package包/類
@Test(expected = MissingObjectException.class)
public void testRemoteRepositoryHasNoCommitst()
throws URISyntaxException, IOException, InvalidRemoteException, TransportException, GitAPIException, NoRepositorySelected {
gitAccess.setRepository(LOCAL_TEST_REPOSITPRY);
final StoredConfig config = gitAccess.getRepository().getConfig();
RemoteConfig remoteConfig = new RemoteConfig(config, "origin");
URIish uri = new URIish(db2.getDirectory().toURI().toURL());
remoteConfig.addURI(uri);
remoteConfig.update(config);
config.save();
gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
gitAccess.commit("file test added");
// throws missingObjectException
db2.resolve(gitAccess.getLastLocalCommit().getName() + "^{commit}");
}
示例6: testPushOK
import org.eclipse.jgit.api.errors.TransportException; //導入依賴的package包/類
@Test
public void testPushOK()
throws URISyntaxException, IOException, InvalidRemoteException, TransportException, GitAPIException, NoRepositorySelected {
gitAccess.setRepository(LOCAL_TEST_REPOSITPRY);
final StoredConfig config = gitAccess.getRepository().getConfig();
RemoteConfig remoteConfig = new RemoteConfig(config, "origin");
URIish uri = new URIish(db2.getDirectory().toURI().toURL());
remoteConfig.addURI(uri);
remoteConfig.update(config);
config.save();
gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
gitAccess.commit("file test added");
gitAccess.push("", "");
assertEquals(db1.resolve(gitAccess.getLastLocalCommit().getName() + "^{commit}"),
db2.resolve(gitAccess.getLastLocalCommit().getName() + "^{commit}"));
}
示例7: cloneRepo
import org.eclipse.jgit.api.errors.TransportException; //導入依賴的package包/類
public boolean cloneRepo( String directory, String uri ) {
CloneCommand cmd = Git.cloneRepository();
cmd.setDirectory( new File( directory ) );
cmd.setURI( uri );
cmd.setCredentialsProvider( credentialsProvider );
try {
Git git = cmd.call();
git.close();
return true;
} catch ( Exception e ) {
if ( ( e instanceof TransportException )
&& ( ( e.getMessage().contains( "Authentication is required but no CredentialsProvider has been registered" )
|| e.getMessage().contains( "not authorized" ) ) ) ) {
if ( promptUsernamePassword() ) {
return cloneRepo( directory, uri );
}
} else {
showMessageBox( BaseMessages.getString( PKG, "Dialog.Error" ), e.getMessage() );
}
}
return false;
}
示例8: cloneRepository
import org.eclipse.jgit.api.errors.TransportException; //導入依賴的package包/類
private void cloneRepository() throws IOException, InvalidRemoteException, TransportException, GitAPIException {
File localPath = File.createTempFile("TestGitRepository", "");
localPath.delete();
System.out.println("Cloning from " + repository_url + " to " + localPath);
Git result = Git.cloneRepository()
.setURI(repository_url)
.setDirectory(localPath)
.call();
// Note: the call() returns an opened repository already which needs to be closed to avoid file handle leaks!
System.out.println("Having repository: " + result.getRepository().getDirectory());
repositoryPath = result.getRepository().getDirectory().getAbsolutePath();
@SuppressWarnings("deprecation")
Preferences preferences = new InstanceScope().getNode(ModularityCheck.PLUGIN_ID);
preferences.put(REPOSITORY_PATH, repositoryPath);
}
示例9: openRepository
import org.eclipse.jgit.api.errors.TransportException; //導入依賴的package包/類
public void openRepository() throws IOException, GitAPIException,
InvalidRemoteException, TransportException {
// Now open the created repository
FileRepositoryBuilder builder = new FileRepositoryBuilder();
String directory = System.getProperty("user.home") + Properties.SEPARATOR + "TestGit\\";///.git
if(new File(directory).mkdir() || new File(directory).exists()){
directory = directory + "/.git";
repository = builder
.setGitDir(
new File(
directory)).readEnvironment() // scan
// environment
// GIT_*
// variables
.findGitDir() // scan up the file system tree
.build();
}else System.out.println("Error during repository clonage. Permission denied for creating files at user home");
}
示例10: cleanUp
import org.eclipse.jgit.api.errors.TransportException; //導入依賴的package包/類
@After
public void cleanUp() throws Exception {
gApi.accounts().id(admin.getId().toString()).setDiffPreferences(DiffPreferencesInfo.defaults());
TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers);
try {
fetch(allUsersRepo, RefNames.REFS_USERS_DEFAULT + ":defaults");
} catch (TransportException e) {
if (e.getMessage()
.equals(
"Remote does not have " + RefNames.REFS_USERS_DEFAULT + " available for fetch.")) {
return;
}
throw e;
}
allUsersRepo.reset("defaults");
PushOneCommit push =
pushFactory.create(
db,
admin.getIdent(),
allUsersRepo,
"Delete default preferences",
VersionedAccountPreferences.PREFERENCES,
"");
push.rm(RefNames.REFS_USERS_DEFAULT).assertOkStatus();
}
示例11: main
import org.eclipse.jgit.api.errors.TransportException; //導入依賴的package包/類
public static void main(String[] args) throws IOException, InvalidRemoteException, TransportException, GitAPIException {
// prepare a new folder for the cloned repository
File localPath = File.createTempFile("TestGitRepository", "");
localPath.delete();
// then clone
System.out.println("Cloning from " + REMOTE_URL + " to " + localPath);
Git.cloneRepository()
.setURI(REMOTE_URL)
.setDirectory(localPath)
.call();
// now open the created repository
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.setGitDir(localPath)
.readEnvironment() // scan environment GIT_* variables
.findGitDir() // scan up the file system tree
.build();
System.out.println("Having repository: " + repository.getDirectory());
repository.close();
}
示例12: shouldDeleteBaseDirWhenCloneFails
import org.eclipse.jgit.api.errors.TransportException; //導入依賴的package包/類
@Test
public void shouldDeleteBaseDirWhenCloneFails() throws Exception {
Git mockGit = mock(Git.class);
CloneCommand mockCloneCommand = mock(CloneCommand.class);
when(mockCloneCommand.setURI(anyString())).thenReturn(mockCloneCommand);
when(mockCloneCommand.setDirectory(any(File.class))).thenReturn(mockCloneCommand);
when(mockCloneCommand.call()).thenThrow(new TransportException("failed to clone"));
JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment);
envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand));
envRepository.setUri("http://somegitserver/somegitrepo");
envRepository.setBasedir(this.basedir);
try {
envRepository.findOne("bar", "staging", "master");
} catch (Exception ex) {
// expected - ignore
}
assertFalse("baseDir should be deleted when clone fails", this.basedir.listFiles().length>0);
}
示例13: call
import org.eclipse.jgit.api.errors.TransportException; //導入依賴的package包/類
public Git call(final GitOperationsStep gitOperationsStep, Git git,
CredentialsProvider cp, String gitRepoUrl, File gitRepoFolder)
throws InvalidRemoteException, TransportException, GitAPIException {
CloneCommand cc = Git.cloneRepository().setURI(gitRepoUrl)
.setDirectory(gitRepoFolder);
if (!Const.isEmpty(this.branchName)) {
cc = cc.setBranch(gitOperationsStep
.environmentSubstitute(this.branchName));
}
cc.setCloneAllBranches(this.cloneAllBranches).setCloneSubmodules(
this.cloneSubModules);
if (cp != null) {
cc.setCredentialsProvider(cp);
}
return cc.setBare(false).call();
}
示例14: wrapException
import org.eclipse.jgit.api.errors.TransportException; //導入依賴的package包/類
public StoreException.TestUpdateException wrapException(final StoreException.TestUpdateException exception) {
final Throwable cause = exception.getCause();
if (gitUrl.endsWith(".git")) {
if (cause instanceof TransportException) {
if (cause.getMessage().contains("not authorized")) {
return new GitNoAuthorizationException("Please check your user name and password", exception);
} else if (cause.getMessage().contains("git-receive-pack not permitted")) {
return new GitNoDevelperAccessLevelException(
"Check if your access level is developer in [" + gitUrl.substring(0, gitUrl.length() - 4) + "/project_members]",
exception);
}
} else if (cause instanceof IllegalStateException) {
if ("pre-receive hook declined".equals(cause.getMessage())) {
return new GitNoMasterAccessLevelException(
"Check if your access level is master in [" + gitUrl.substring(0, gitUrl.length() - 4) + "/project_members]",
exception);
}
}
}
return exception;
}
示例15: gitAddCommitAndPush
import org.eclipse.jgit.api.errors.TransportException; //導入依賴的package包/類
private static void gitAddCommitAndPush(Git git, String gitUrl, UserDetails userDetails, File basedir, String message, String branch, String origin, Logger logger) throws GitAPIException {
PersonIdent personIdent = userDetails.createPersonIdent();
GitUtils.configureBranch(git, branch, origin, gitUrl);
GitUtils.addDummyFileToEmptyFolders(basedir);
logger.info("About to git commit and push to: " + gitUrl + " and remote name " + origin);
int retryCount = 5;
for (int i = retryCount; i > 0; i--) {
if (i < retryCount) {
try {
Thread.sleep(500);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
try {
GitUtils.doAddCommitAndPushFiles(git, userDetails, personIdent, branch, origin, message, true);
return;
} catch (TransportException e) {
if (i <= 1) {
throw e;
} else {
logger.info("Caught a transport exception: " + e + " so retrying");
}
}
}
}