Search in sources :

Example 11 with UsernamePasswordCredentialsProvider

use of org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider in project spring-cloud-config by spring-cloud.

the class GitCredentialsProviderFactoryTests method testCreateForFileWithUsername.

@Test
public void testCreateForFileWithUsername() {
    CredentialsProvider provider = factory.createFor(FILE_REPO, USER, PASSWORD, null);
    assertNotNull(provider);
    assertTrue(provider instanceof UsernamePasswordCredentialsProvider);
}
Also used : UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) PassphraseCredentialsProvider(org.springframework.cloud.config.server.support.PassphraseCredentialsProvider) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) CredentialsProvider(org.eclipse.jgit.transport.CredentialsProvider) Test(org.junit.Test)

Example 12 with UsernamePasswordCredentialsProvider

use of org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider in project contribution by checkstyle.

the class XdocPublisher method publish.

/**
 * Publish release notes.
 * @throws IOException if problem with access to files appears.
 * @throws GitAPIException for problems with jgit.
 */
public void publish() throws IOException, GitAPIException {
    changeLocalRepoXdoc();
    final FileRepositoryBuilder builder = new FileRepositoryBuilder();
    final File localRepo = new File(localRepoPath);
    final Repository repo = builder.findGitDir(localRepo).readEnvironment().build();
    final Git git = new Git(repo);
    git.add().addFilepattern(PATH_TO_XDOC_IN_REPO).call();
    git.commit().setMessage(String.format(Locale.ENGLISH, COMMIT_MESSAGE_TEMPLATE, releaseNumber)).call();
    if (doPush) {
        final CredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider(authToken, "");
        git.push().setCredentialsProvider(credentialsProvider).call();
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) Git(org.eclipse.jgit.api.Git) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) CredentialsProvider(org.eclipse.jgit.transport.CredentialsProvider) FileRepositoryBuilder(org.eclipse.jgit.storage.file.FileRepositoryBuilder) File(java.io.File)

Example 13 with UsernamePasswordCredentialsProvider

use of org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider in project ArTEMiS by ls1intum.

the class GitService method commitAndPush.

/**
 * Commits with the given message into the repository and pushes it to the remote.
 *
 * @param repo Local Repository Object.
 * @param message Commit Message
 * @throws GitAPIException
 */
public void commitAndPush(Repository repo, String message) throws GitAPIException {
    Git git = new Git(repo);
    git.commit().setMessage(message).setAllowEmpty(true).setCommitter(GIT_NAME, GIT_EMAIL).call();
    git.push().setCredentialsProvider(new UsernamePasswordCredentialsProvider(GIT_USER, GIT_PASSWORD)).call();
    git.close();
}
Also used : UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) Git(org.eclipse.jgit.api.Git)

Example 14 with UsernamePasswordCredentialsProvider

use of org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider in project ArTEMiS by ls1intum.

the class GitService method getOrCheckoutRepository.

/**
 * Get the local repository for a given remote repository URL.
 * If the local repo does not exist yet, it will be checked out.
 *
 * @param repoUrl The remote repository.
 * @return
 * @throws IOException
 * @throws GitAPIException
 */
public Repository getOrCheckoutRepository(URL repoUrl) throws IOException, GitAPIException {
    Path localPath = new java.io.File(REPO_CLONE_PATH + folderNameForRepositoryUrl(repoUrl)).toPath();
    // check if Repository object already created and available in cachedRepositories
    if (cachedRepositories.containsKey(localPath)) {
        return cachedRepositories.get(localPath);
    }
    // Check if the repository is already checked out on the server
    if (!Files.exists(localPath)) {
        // Repository is not yet available on the server
        // We need to check it out from the remote repository
        log.info("Cloning from " + repoUrl + " to " + localPath);
        Git result = Git.cloneRepository().setURI(repoUrl.toString()).setCredentialsProvider(new UsernamePasswordCredentialsProvider(GIT_USER, GIT_PASSWORD)).setDirectory(localPath.toFile()).call();
        result.close();
    } else {
        log.info("Repository at " + localPath + " already exists");
    }
    // Open the repository from the filesystem
    FileRepositoryBuilder builder = new FileRepositoryBuilder();
    builder.setGitDir(new java.io.File(localPath + "/.git")).readEnvironment().findGitDir().setup();
    // Create the JGit repository object
    Repository repository = new Repository(builder);
    repository.setLocalPath(localPath);
    // Cache the JGit repository object for later use
    // Avoids the expensive re-opening of local repositories
    cachedRepositories.put(localPath, repository);
    return repository;
}
Also used : Path(java.nio.file.Path) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) Repository(de.tum.in.www1.artemis.domain.Repository) Git(org.eclipse.jgit.api.Git) FileRepositoryBuilder(org.eclipse.jgit.storage.file.FileRepositoryBuilder) File(de.tum.in.www1.artemis.domain.File)

Example 15 with UsernamePasswordCredentialsProvider

use of org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider in project Android-Password-Store by zeapo.

the class GitOperation method setAuthentication.

/**
 * Sets the authentication using user/pwd scheme
 *
 * @param username the username
 * @param password the password
 * @return the current object
 */
GitOperation setAuthentication(String username, String password) {
    SshSessionFactory.setInstance(new GitConfigSessionFactory());
    this.provider = new UsernamePasswordCredentialsProvider(username, password);
    return this;
}
Also used : UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) GitConfigSessionFactory(com.zeapo.pwdstore.git.config.GitConfigSessionFactory)

Aggregations

UsernamePasswordCredentialsProvider (org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider)76 Git (org.eclipse.jgit.api.Git)47 File (java.io.File)34 CredentialsProvider (org.eclipse.jgit.transport.CredentialsProvider)23 IOException (java.io.IOException)19 Test (org.junit.Test)18 CloneCommand (org.eclipse.jgit.api.CloneCommand)17 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)15 RepositoryModel (com.gitblit.models.RepositoryModel)12 PushResult (org.eclipse.jgit.transport.PushResult)12 RemoteRefUpdate (org.eclipse.jgit.transport.RemoteRefUpdate)9 FileOutputStream (java.io.FileOutputStream)8 PushCommand (org.eclipse.jgit.api.PushCommand)8 RevCommit (org.eclipse.jgit.revwalk.RevCommit)8 BufferedWriter (java.io.BufferedWriter)7 OutputStreamWriter (java.io.OutputStreamWriter)7 Date (java.util.Date)7 Ref (org.eclipse.jgit.lib.Ref)7 Repository (org.eclipse.jgit.lib.Repository)7 URIish (org.eclipse.jgit.transport.URIish)7