本文整理汇总了Java中org.eclipse.jgit.transport.Transport类的典型用法代码示例。如果您正苦于以下问题:Java Transport类的具体用法?Java Transport怎么用?Java Transport使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Transport类属于org.eclipse.jgit.transport包,在下文中一共展示了Transport类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: openTransport
import org.eclipse.jgit.transport.Transport; //导入依赖的package包/类
protected Transport openTransport (boolean openPush) throws URISyntaxException, NotSupportedException, TransportException {
URIish uri = getUriWithUsername(openPush);
// WA for #200693, jgit fails to initialize ftp protocol
for (TransportProtocol proto : Transport.getTransportProtocols()) {
if (proto.getSchemes().contains("ftp")) { //NOI18N
Transport.unregister(proto);
}
}
try {
Transport transport = Transport.open(getRepository(), uri);
RemoteConfig config = getRemoteConfig();
if (config != null) {
transport.applyConfig(config);
}
if (transport.getTimeout() <= 0) {
transport.setTimeout(45);
}
transport.setCredentialsProvider(getCredentialsProvider());
return transport;
} catch (IllegalArgumentException ex) {
throw new TransportException(ex.getLocalizedMessage(), ex);
}
}
示例2: testDeleteStaleReferencesFails
import org.eclipse.jgit.transport.Transport; //导入依赖的package包/类
public void testDeleteStaleReferencesFails () throws Exception {
setupRemoteSpec("origin", "+refs/heads/*:refs/remotes/origin/*");
GitClient client = getClient(workDir);
Map<String, GitBranch> branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
assertEquals(0, branches.size());
Map<String, GitTransportUpdate> updates = client.fetch("origin", NULL_PROGRESS_MONITOR);
branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
assertEquals(2, branches.size());
new File(workDir, ".git/refs/remotes/origin").mkdirs();
write(new File(workDir, ".git/refs/remotes/origin/HEAD"), "ref: refs/remotes/origin/master");
branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
assertEquals(2, branches.size());
// and now the master is deleted and HEAD points to nowhere :(
Transport transport = Transport.open(repository, "origin");
transport.setRemoveDeletedRefs(true);
transport.fetch(new DelegatingProgressMonitor(NULL_PROGRESS_MONITOR), new RemoteConfig(repository.getConfig(), "origin").getFetchRefSpecs());
branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
assertEquals(1, branches.size());
}
示例3: getTransportConfigCallback
import org.eclipse.jgit.transport.Transport; //导入依赖的package包/类
public static TransportConfigCallback getTransportConfigCallback() {
final SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
@Override
protected void configure(OpenSshConfig.Host host, Session session) {
//session.setPassword(password);
}
};
return new TransportConfigCallback() {
public void configure(Transport transport) {
if (transport instanceof TransportHttp)
return;
SshTransport sshTransport = (SshTransport) transport;
sshTransport.setSshSessionFactory(sshSessionFactory);
}
};
}
示例4: pushVia
import org.eclipse.jgit.transport.Transport; //导入依赖的package包/类
private PushResult pushVia(Transport tn)
throws IOException, NotSupportedException, TransportException, PermissionBackendException {
tn.applyConfig(config);
tn.setCredentialsProvider(credentialsProvider);
List<RemoteRefUpdate> todo = generateUpdates(tn);
if (todo.isEmpty()) {
// If we have no commands selected, we have nothing to do.
// Calling JGit at this point would just redo the work we
// already did, and come up with the same answer. Instead
// send back an empty result.
return new PushResult();
}
repLog.info("Push to " + uri + " references: " + todo);
return tn.push(NullProgressMonitor.INSTANCE, todo);
}
示例5: afterTest
import org.eclipse.jgit.transport.Transport; //导入依赖的package包/类
protected void afterTest() throws Exception {
Transport.unregister(inProcessProtocol);
for (Repository repo : toClose) {
repo.close();
}
db.close();
if (adminSshSession != null) {
adminSshSession.close();
}
if (userSshSession != null) {
userSshSession.close();
}
if (server != commonServer) {
server.close();
server = null;
}
NoteDbMode.resetFromEnv(notesMigration);
}
示例6: getHeadRev
import org.eclipse.jgit.transport.Transport; //导入依赖的package包/类
/** {@inheritDoc} */
public Map<String, ObjectId> getHeadRev(String url) throws GitException, InterruptedException {
Map<String, ObjectId> heads = new HashMap<>();
try (Repository repo = openDummyRepository();
final Transport tn = Transport.open(repo, new URIish(url))) {
tn.setCredentialsProvider(getProvider());
try (FetchConnection c = tn.openFetch()) {
for (final Ref r : c.getRefs()) {
heads.put(r.getName(), r.getPeeledObjectId() != null ? r.getPeeledObjectId() : r.getObjectId());
}
}
} catch (IOException | URISyntaxException e) {
throw new GitException(e);
}
return heads;
}
示例7: listRemoteBranches
import org.eclipse.jgit.transport.Transport; //导入依赖的package包/类
private Set<String> listRemoteBranches(String remote) throws NotSupportedException, TransportException, URISyntaxException {
Set<String> branches = new HashSet<>();
try (final Repository repo = getRepository()) {
StoredConfig config = repo.getConfig();
try (final Transport tn = Transport.open(repo, new URIish(config.getString("remote",remote,"url")))) {
tn.setCredentialsProvider(getProvider());
try (final FetchConnection c = tn.openFetch()) {
for (final Ref r : c.getRefs()) {
if (r.getName().startsWith(R_HEADS))
branches.add("refs/remotes/"+remote+"/"+r.getName().substring(R_HEADS.length()));
}
}
}
}
return branches;
}
示例8: testFileProtocolFails
import org.eclipse.jgit.transport.Transport; //导入依赖的package包/类
public void testFileProtocolFails () throws Exception {
try {
Transport.open(repository, new URIish(workDir.toURI().toURL()));
fail("Workaround not needed, fix ListRemoteBranchesCommand - Transport.open(String) to Transport.open(URL)");
} catch (NotSupportedException ex) {
}
}
示例9: testFtpProtocol
import org.eclipse.jgit.transport.Transport; //导入依赖的package包/类
public void testFtpProtocol () throws Exception {
Transport t = Transport.open(repository, new URIish("ftp://ftphost/abc"));
try {
t.openFetch();
fail("JGit ftp support fixed, fix #200693 workaround");
// ftp support fixed, wa in TransportCommand.openTransport should be removed
} catch (ClassCastException ex) {
// jgit has a bug that prevents from using ftp protocol
}
}
示例10: runImpl
import org.eclipse.jgit.transport.Transport; //导入依赖的package包/类
private void runImpl() throws IOException, PermissionBackendException {
PushResult res;
try (Transport tn = Transport.open(git, uri)) {
res = pushVia(tn);
}
updateStates(res.getRemoteUpdates());
}
示例11: generateUpdates
import org.eclipse.jgit.transport.Transport; //导入依赖的package包/类
private List<RemoteRefUpdate> generateUpdates(Transport tn)
throws IOException, PermissionBackendException {
ProjectState projectState = projectCache.checkedGet(projectName);
if (projectState == null) {
return Collections.emptyList();
}
Map<String, Ref> local = git.getAllRefs();
boolean filter;
try {
permissionBackend.user(userProvider).project(projectName).check(ProjectPermission.READ);
filter = false;
} catch (AuthException e) {
filter = true;
}
if (filter) {
if (!pushAllRefs) {
// If we aren't mirroring, reduce the space we need to filter
// to only the references we will update during this operation.
//
Map<String, Ref> n = new HashMap<>();
for (String src : delta) {
Ref r = local.get(src);
if (r != null) {
n.put(src, r);
}
}
local = n;
}
local = refFilterFactory.create(projectState, git).filter(local, true);
}
return pushAllRefs ? doPushAll(tn, local) : doPushDelta(local);
}
示例12: shouldDoNothingWhenTransportHttpReceived
import org.eclipse.jgit.transport.Transport; //导入依赖的package包/类
@Test
public void shouldDoNothingWhenTransportHttpReceived() throws Exception {
// given
/*
* We need create {@link TransportHttp} mock, but this class has parent
* abstract class {@link Transport}. Class Transport uses fields of children
* classes for static initialization collection {@link Transport#protocols}.
* When we create mock for {@link TransportHttp} - Mockito mocks fields and
* they return null value. For full mock creation TransportHttp Mockito
* launches static block in the parent class {@link Transport}, but static
* block initializes collection with help mocked children fields which
* return null values, so Transport class loses real field value in the
* collection. It creates troubles in other tests when we use real object
* of TransportHttp(collection 'protocols' contains not all values).
* To realize right initialization {@link Transport#protocols} we create
* mock of {@link Transport} and this class initializes collection "protocols"
* with help real children {@link TransportHttp}, which returns real not null
* value. And then we can create mock {@link TransportHttp}.
*/
mock(Transport.class);
TransportHttp transportHttp = mock(TransportHttp.class);
when(sshKeyProvider.getPrivateKey(anyString())).thenReturn(new byte[0]);
doAnswer(
invocation -> {
TransportConfigCallback callback =
(TransportConfigCallback) invocation.getArguments()[0];
callback.configure(transportHttp);
return null;
})
.when(transportCommand)
.setTransportConfigCallback(any());
// when
jGitConnection.executeRemoteCommand("ssh://host.xz/repo.git", transportCommand, null, null);
// then
verifyZeroInteractions(transportHttp);
}
示例13: configureCommand
import org.eclipse.jgit.transport.Transport; //导入依赖的package包/类
/**
* Configures the transport of the command to deal with things like SSH
*/
public static <C extends GitCommand> void configureCommand(TransportCommand<C, ?> command, CredentialsProvider credentialsProvider, final File sshPrivateKey, final File sshPublicKey) {
if (sshPrivateKey != null) {
final CredentialsProvider provider = credentialsProvider;
command.setTransportConfigCallback(new TransportConfigCallback() {
@Override
public void configure(Transport transport) {
if (transport instanceof SshTransport) {
SshTransport sshTransport = (SshTransport) transport;
SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
@Override
protected void configure(OpenSshConfig.Host host, Session session) {
session.setConfig("StrictHostKeyChecking", "no");
UserInfo userInfo = new CredentialsProviderUserInfo(session, provider);
session.setUserInfo(userInfo);
}
@Override
protected JSch createDefaultJSch(FS fs) throws JSchException {
JSch jsch = super.createDefaultJSch(fs);
jsch.removeAllIdentity();
String absolutePath = sshPrivateKey.getAbsolutePath();
if (LOG.isDebugEnabled()) {
LOG.debug("Adding identity privateKey: " + sshPrivateKey + " publicKey: " + sshPublicKey);
}
if (sshPublicKey != null) {
jsch.addIdentity(absolutePath, sshPublicKey.getAbsolutePath(), null);
} else {
jsch.addIdentity(absolutePath);
}
return jsch;
}
};
sshTransport.setSshSessionFactory(sshSessionFactory);
}
}
});
}
}
示例14: configure
import org.eclipse.jgit.transport.Transport; //导入依赖的package包/类
/**
* Configures the transport to work with ssh-agent if an SSH transport is
* being used. {@inheritDoc}
*/
@Override
public void configure(final Transport transport) {
if (transport instanceof SshTransport) {
final SshTransport sshTransport = (SshTransport) transport;
final SshSessionFactory sshSessionFactory = new AgentJschConfigSessionFactory(authenticationInfo);
sshTransport.setSshSessionFactory(sshSessionFactory);
}
}
示例15: configureTransport
import org.eclipse.jgit.transport.Transport; //导入依赖的package包/类
/**
* Configures the Git transport before using it.
*
* @param transport the transport to configure. Must not be {@code null}
* @param repository the repository configuration being used. Must not be {@code null}
*/
private void configureTransport(final Transport transport, final GitRepository repository) {
assert transport != null : "transport must not be null";
assert repository != null : "repository must not be null";
// Configure private key for SSH
if (transport instanceof SshTransport) {
((SshTransport)transport).setSshSessionFactory(getSshSessionFactory(repository));
}
}