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);
}
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();
}
}
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();
}
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;
}
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;
}
Aggregations