本文整理汇总了Java中org.eclipse.jgit.api.TransportConfigCallback类的典型用法代码示例。如果您正苦于以下问题:Java TransportConfigCallback类的具体用法?Java TransportConfigCallback怎么用?Java TransportConfigCallback使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TransportConfigCallback类属于org.eclipse.jgit.api包,在下文中一共展示了TransportConfigCallback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTransportConfigCallback
import org.eclipse.jgit.api.TransportConfigCallback; //导入依赖的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);
}
};
}
示例2: shouldSetSshSessionFactoryWhenSshTransportReceived
import org.eclipse.jgit.api.TransportConfigCallback; //导入依赖的package包/类
@Test
public void shouldSetSshSessionFactoryWhenSshTransportReceived() throws Exception {
// given
SshTransport sshTransport = mock(SshTransport.class);
when(sshKeyProvider.getPrivateKey(anyString())).thenReturn(new byte[0]);
doAnswer(
invocation -> {
TransportConfigCallback callback =
(TransportConfigCallback) invocation.getArguments()[0];
callback.configure(sshTransport);
return null;
})
.when(transportCommand)
.setTransportConfigCallback(any());
// when
jGitConnection.executeRemoteCommand("ssh://host.xz/repo.git", transportCommand, null, null);
// then
verify(sshTransport).setSshSessionFactory(any());
}
示例3: shouldSetTransportConfigCallbackOnCloneAndFetch
import org.eclipse.jgit.api.TransportConfigCallback; //导入依赖的package包/类
@Test
public void shouldSetTransportConfigCallbackOnCloneAndFetch() throws Exception {
Git mockGit = mock(Git.class);
FetchCommand fetchCommand = mock(FetchCommand.class);
when(mockGit.fetch()).thenReturn(fetchCommand);
when(fetchCommand.call()).thenReturn(mock(FetchResult.class));
CloneCommand mockCloneCommand = mock(CloneCommand.class);
when(mockCloneCommand.setURI(anyString())).thenReturn(mockCloneCommand);
when(mockCloneCommand.setDirectory(any(File.class))).thenReturn(mockCloneCommand);
TransportConfigCallback configCallback = mock(TransportConfigCallback.class);
JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment);
envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand));
envRepository.setUri("http://somegitserver/somegitrepo");
envRepository.setTransportConfigCallback(configCallback);
envRepository.setCloneOnStart(true);
envRepository.afterPropertiesSet();
verify(mockCloneCommand, times(1)).setTransportConfigCallback(configCallback);
envRepository.fetch(mockGit, "master");
verify(fetchCommand, times(1)).setTransportConfigCallback(configCallback);
}
示例4: shouldSetTransportConfigCallback
import org.eclipse.jgit.api.TransportConfigCallback; //导入依赖的package包/类
@Test
public void shouldSetTransportConfigCallback() throws Exception {
TransportConfigCallback mockCallback1 = mock(TransportConfigCallback.class);
TransportConfigCallback mockCallback2 = mock(TransportConfigCallback.class);
PatternMatchingJGitEnvironmentRepository repo1 = createRepository("test1", "*test1*", "test1Uri");
PatternMatchingJGitEnvironmentRepository repo2 = createRepository("test2", "*test2*", "test2Uri");
repo2.setTransportConfigCallback(mockCallback2);
Map<String, PatternMatchingJGitEnvironmentRepository> repos = new HashMap<>();
repos.put("test1", repo1);
repos.put("test2", repo2);
this.repository.setRepos(repos);
this.repository.setTransportConfigCallback(mockCallback1);
this.repository.afterPropertiesSet();
assertEquals(repo1.getTransportConfigCallback(), mockCallback1);
assertEquals(repo2.getTransportConfigCallback(), mockCallback2);
}
开发者ID:spring-cloud,项目名称:spring-cloud-config,代码行数:22,代码来源:MultipleJGitEnvironmentRepositoryTests.java
示例5: shouldDoNothingWhenTransportHttpReceived
import org.eclipse.jgit.api.TransportConfigCallback; //导入依赖的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);
}
示例6: configureCommand
import org.eclipse.jgit.api.TransportConfigCallback; //导入依赖的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);
}
}
});
}
}
示例7: configure
import org.eclipse.jgit.api.TransportConfigCallback; //导入依赖的package包/类
@Override
protected void configure() {
install(RepositoryScope.module());
install(OperationScope.module());
bind(UserInfo.class).to(GUIUserInfo.class);
bind(ImageSession.class).toProvider(ImageSessionProvider.class).in(ContextSingleton.class);
bind(Repository.class).toProvider(RepositoryProvider.class);
bind(Ref.class).annotatedWith(named("branch")).toProvider(BranchRefProvider.class);
bind(AndroidAuthAgent.class).toProvider(AndroidAuthAgentProvider.class);
bind(GitAsyncTaskFactory.class).toProvider(newFactory(GitAsyncTaskFactory.class, GitAsyncTask.class));
bind(ContextScopedViewInflatorFactory.class).toProvider(newFactory(ContextScopedViewInflatorFactory.class,
ContextScopedViewInflator.class));
bind(SyncCampaignFactory.class).toProvider(newFactory(SyncCampaignFactory.class, SyncCampaign.class));
bind(TransportConfigCallback.class).to(AgitTransportConfig.class);
bind(CredentialsProvider.class).to(GUICredentialsProvider.class);
bind(SshSessionFactory.class).to(AndroidSshSessionFactory.class);
bind(PromptUIRegistry.class);
bind(HostKeyRepository.class).to(CuriousHostKeyRepository.class);
bind(PromptUI.class).annotatedWith(named("status-bar")).to(StatusBarPromptUI.class);
bind(RepoDomainType.class).annotatedWith(named("branch")).to(RDTBranch.class);
bind(RepoDomainType.class).annotatedWith(named("remote")).to(RDTRemote.class);
bind(RepoDomainType.class).annotatedWith(named("tag")).to(RDTTag.class);
bind(CommitViewHolderFactory.class).toProvider(newFactory(CommitViewHolderFactory.class,
CommitViewHolder.class));
bind(BranchViewHolderFactory.class).toProvider(newFactory(BranchViewHolderFactory.class,
BranchViewHolder.class));
}
示例8: propertiesBasedSshTransportCallback
import org.eclipse.jgit.api.TransportConfigCallback; //导入依赖的package包/类
@ConditionalOnMissingBean(TransportConfigCallback.class)
@Bean
public TransportConfigCallback propertiesBasedSshTransportCallback(final SshUriProperties sshUriProperties) {
if(sshUriProperties.isIgnoreLocalSshSettings()) {
return new PropertiesBasedSshTransportConfigCallback(sshUriProperties);
}
else return new FileBasedSshTransportConfigCallback(sshUriProperties);
}
示例9: privateKeyPropertyWithLineBreaks
import org.eclipse.jgit.api.TransportConfigCallback; //导入依赖的package包/类
@Test
public void privateKeyPropertyWithLineBreaks() throws Exception {
TransportConfigCallback transportConfigCallback = jGitEnvironmentRepository.getTransportConfigCallback();
assertThat(transportConfigCallback, is(instanceOf(TransportConfiguration.PropertiesBasedSshTransportConfigCallback.class)));
TransportConfiguration.PropertiesBasedSshTransportConfigCallback configCallback =
(TransportConfiguration.PropertiesBasedSshTransportConfigCallback) transportConfigCallback;
assertThat(configCallback.getSshUriProperties().getPrivateKey(), is(equalTo(TestProperties.TEST_PRIVATE_KEY_1)));
}
开发者ID:spring-cloud,项目名称:spring-cloud-config,代码行数:10,代码来源:TransportConfigurationIntegrationTests.java
示例10: sshPropertiesWithinNestedRepo
import org.eclipse.jgit.api.TransportConfigCallback; //导入依赖的package包/类
@Test
public void sshPropertiesWithinNestedRepo() throws Exception {
TransportConfigCallback transportConfigCallback = jGitEnvironmentRepository.getTransportConfigCallback();
assertThat(transportConfigCallback, is(instanceOf(TransportConfiguration.PropertiesBasedSshTransportConfigCallback.class)));
TransportConfiguration.PropertiesBasedSshTransportConfigCallback configCallback =
(TransportConfiguration.PropertiesBasedSshTransportConfigCallback) transportConfigCallback;
SshUriProperties sshUriProperties = configCallback.getSshUriProperties();
assertThat(sshUriProperties.getPrivateKey(), is(equalTo(TestProperties.TEST_PRIVATE_KEY_1)));
assertThat(sshUriProperties.getRepos().get("repo1"), is(notNullValue()));
assertThat(sshUriProperties.getRepos().get("repo1").getPrivateKey(), is(equalTo(TestProperties.TEST_PRIVATE_KEY_2)));
}
开发者ID:spring-cloud,项目名称:spring-cloud-config,代码行数:14,代码来源:TransportConfigurationIntegrationTests.java
示例11: propertiesBasedSshTransportCallbackCreated
import org.eclipse.jgit.api.TransportConfigCallback; //导入依赖的package包/类
@Test
public void propertiesBasedSshTransportCallbackCreated() throws Exception {
SshUriProperties ignoreLocalSettings = SshUri.builder()
.uri("[email protected]:proj/repo")
.ignoreLocalSshSettings(true)
.build();
TransportConfiguration transportConfiguration = new TransportConfiguration();
TransportConfigCallback transportConfigCallback = transportConfiguration.propertiesBasedSshTransportCallback(ignoreLocalSettings);
assertThat(transportConfigCallback, is(instanceOf(TransportConfiguration.PropertiesBasedSshTransportConfigCallback.class)));
}
示例12: fileBasedSshTransportCallbackCreated
import org.eclipse.jgit.api.TransportConfigCallback; //导入依赖的package包/类
@Test
public void fileBasedSshTransportCallbackCreated() throws Exception {
SshUriProperties dontIgnoreLocalSettings = SshUri.builder()
.uri("[email protected]:proj/repo")
.ignoreLocalSshSettings(false)
.build();
TransportConfiguration transportConfiguration = new TransportConfiguration();
TransportConfigCallback transportConfigCallback = transportConfiguration.propertiesBasedSshTransportCallback(dontIgnoreLocalSettings);
assertThat(transportConfigCallback, is(instanceOf(TransportConfiguration.FileBasedSshTransportConfigCallback.class)));
}
示例13: cloneRepository
import org.eclipse.jgit.api.TransportConfigCallback; //导入依赖的package包/类
public static File cloneRepository(String cloneUrl, String repoPw) throws GitAPIException, JSONException, IOException {
config = ConfigParser.getConfig();
File tmpDir = new File("temp_repo");
String key = null;
String keyPassPhrase = null;
if (config.has("privateKey")) {
key = config.getString("privateKey");
keyPassPhrase = config.getString("privateKeyPassPhrase");
}
// git clone will fail if the directory already exists, even if empty
if (tmpDir.exists()) {
FileUtils.deleteDirectory(tmpDir);
}
String pw = null;
if (repoPw != null) {
pw = repoPw;
}
else if (config.has("gitClonePassword")) {
pw = config.getString("gitClonePassword");
}
final String finalKeyPassPhrase = keyPassPhrase;
final String finalKey = key;
SshSessionFactory sessionFactory = new CustomJschConfigSessionFactory();
// use a private key if provided
if (finalKey != null) {
SshSessionFactory.setInstance(sessionFactory);
}
// use a password if provided
if (pw != null) {
final String finalPw = pw;
SshSessionFactory.setInstance(new JschConfigSessionFactory() {
@Override
protected void configure(OpenSshConfig.Host host, Session session) {
session.setPassword(finalPw);
}
});
}
SshSessionFactory.setInstance(sessionFactory);
Git.cloneRepository()
.setURI(cloneUrl)
.setDirectory(tmpDir)
.setTransportConfigCallback(new TransportConfigCallback() {
@Override
public void configure(Transport transport) {
SshTransport sshTransport = (SshTransport) transport;
sshTransport.setSshSessionFactory(sessionFactory);
}
})
.call();
return tmpDir;
}
示例14: getTransportConfigCallback
import org.eclipse.jgit.api.TransportConfigCallback; //导入依赖的package包/类
public TransportConfigCallback getTransportConfigCallback() {
return transportConfigCallback;
}
示例15: setTransportConfigCallback
import org.eclipse.jgit.api.TransportConfigCallback; //导入依赖的package包/类
public void setTransportConfigCallback(
TransportConfigCallback transportConfigCallback) {
this.transportConfigCallback = transportConfigCallback;
}