Java源码示例:org.eclipse.jgit.api.LsRemoteCommand
示例1
@Override
public Collection<Ref> getTags() throws GitAPIException {
LsRemoteCommand lsRemoteCommand = git.lsRemote()
.setTags(true).setHeads(false)
.setCredentialsProvider(credentialsProvider);
if (remoteUrl != null) {
lsRemoteCommand.setRemote(remoteUrl);
}
return lsRemoteCommand.call();
}
示例2
public boolean isRemoteValid(Git git, String remote, String authenticationType,
String remoteUsername, String remotePassword, String remoteToken,
String remotePrivateKey)
throws CryptoException, IOException, ServiceLayerException, GitAPIException {
LsRemoteCommand lsRemoteCommand = git.lsRemote();
lsRemoteCommand.setRemote(remote);
final Path tempKey = Files.createTempFile(UUID.randomUUID().toString(), ".tmp");
lsRemoteCommand = setAuthenticationForCommand(lsRemoteCommand, authenticationType, remoteUsername,
remotePassword, remoteToken, remotePrivateKey, tempKey, false);
lsRemoteCommand.call();
Files.deleteIfExists(tempKey);
return true;
}
示例3
private boolean isRemoteValid(Git git, String remote, String authenticationType,
String remoteUsername, String remotePassword, String remoteToken,
String remotePrivateKey)
throws CryptoException, IOException, ServiceLayerException, GitAPIException {
LsRemoteCommand lsRemoteCommand = git.lsRemote();
lsRemoteCommand.setRemote(remote);
switch (authenticationType) {
case NONE:
logger.debug("No authentication");
break;
case BASIC:
logger.debug("Basic authentication");
lsRemoteCommand.setCredentialsProvider(
new UsernamePasswordCredentialsProvider(remoteUsername, remotePassword));
break;
case TOKEN:
logger.debug("Token based authentication");
lsRemoteCommand.setCredentialsProvider(
new UsernamePasswordCredentialsProvider(remoteToken, EMPTY));
break;
case PRIVATE_KEY:
logger.debug("Private key authentication");
final Path tempKey = Files.createTempFile(UUID.randomUUID().toString(), ".tmp");
tempKey.toFile().deleteOnExit();
lsRemoteCommand.setTransportConfigCallback(
new TransportConfigCallback() {
@Override
public void configure(Transport transport) {
SshTransport sshTransport = (SshTransport) transport;
sshTransport.setSshSessionFactory(getSshSessionFactory(remotePrivateKey, tempKey));
}
});
Files.delete(tempKey);
break;
default:
throw new ServiceLayerException("Unsupported authentication type " + authenticationType);
}
lsRemoteCommand.call();
return true;
}
示例4
/** {@inheritDoc} */
@Override
public Map<String, ObjectId> getRemoteReferences(String url, String pattern, boolean headsOnly, boolean tagsOnly)
throws GitException, InterruptedException {
Map<String, ObjectId> references = new HashMap<>();
String regexPattern = null;
if (pattern != null) {
regexPattern = createRefRegexFromGlob(pattern);
}
try (Repository repo = openDummyRepository()) {
LsRemoteCommand lsRemote = new LsRemoteCommand(repo);
if (headsOnly) {
lsRemote.setHeads(headsOnly);
}
if (tagsOnly) {
lsRemote.setTags(tagsOnly);
}
lsRemote.setRemote(url);
lsRemote.setCredentialsProvider(getProvider());
Collection<Ref> refs = lsRemote.call();
for (final Ref r : refs) {
final String refName = r.getName();
final ObjectId refObjectId =
r.getPeeledObjectId() != null ? r.getPeeledObjectId() : r.getObjectId();
if (regexPattern != null) {
if (refName.matches(regexPattern)) {
references.put(refName, refObjectId);
}
} else {
references.put(refName, refObjectId);
}
}
} catch (JGitInternalException | GitAPIException | IOException e) {
throw new GitException(e);
}
return references;
}