org.eclipse.jgit.api.LsRemoteCommand Java Examples

The following examples show how to use org.eclipse.jgit.api.LsRemoteCommand. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LocalGitRepo.java    From multi-module-maven-release-plugin with MIT License 5 votes vote down vote up
@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();
}
 
Example #2
Source File: GitRepositoryHelper.java    From studio with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #3
Source File: GitContentRepository.java    From studio with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #4
Source File: JGitAPIImpl.java    From git-client-plugin with MIT License 5 votes vote down vote up
/** {@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;
}