use of org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider in project fabric8 by jboss-fuse.
the class FabricPatchServiceImpl method synchronize.
@Override
public String synchronize(final boolean verbose) throws Exception {
final String[] remoteUrl = new String[] { null };
patchManagement.pushPatchInfo(verbose);
GitOperation operation = new GitOperation() {
@Override
public Object call(Git git, GitContext context) throws Exception {
ProfileRegistry registry = fabricService.adapt(ProfileRegistry.class);
Map<String, String> properties = registry.getDataStoreProperties();
String username;
String password;
if (properties != null && properties.containsKey("gitRemoteUser") && properties.containsKey("gitRemotePassword")) {
username = properties.get("gitRemoteUser");
password = properties.get("gitRemotePassword");
} else {
username = ZooKeeperUtils.getContainerLogin(runtimeProperties);
password = ZooKeeperUtils.generateContainerToken(runtimeProperties, curator);
}
remoteUrl[0] = git.getRepository().getConfig().getString("remote", "origin", "url");
Iterable<PushResult> results = git.push().setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password)).setPushTags().setPushAll().call();
logPushResult(results, git.getRepository(), verbose);
return null;
}
};
try {
gitDataStore.gitOperation(new GitContext(), operation, null);
} catch (FabricException e) {
if (e.getCause() != null && e.getCause() instanceof TransportException) {
LOG.warn("Problem when synchronizing patch information: " + e.getCause().getMessage());
} else {
throw e;
}
}
return remoteUrl[0];
}
use of org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider in project Corgi by kevinYin.
the class RepoUtil method getGitAllBranchInfo.
/**
* 获取git 分支的所有信息
*
* @param gitRemoteURL git 地址
* @param userName git账户名
* @param password git 密码
* @return key是分支名,value是 版本号 (前8位)
*/
public static Map<String, String> getGitAllBranchInfo(String gitRemoteURL, String userName, String password) throws GitAPIException {
CredentialsProvider cp = new UsernamePasswordCredentialsProvider(userName, password);
Collection<Ref> refs = Git.lsRemoteRepository().setHeads(true).setCredentialsProvider(cp).setRemote(gitRemoteURL).setTags(true).call();
HashMap<String, String> branch2VersionMap = Maps.newHashMap();
for (Ref ref : refs) {
String versionNo = ref.getObjectId().getName().substring(0, 8);
if (ref.getName().startsWith("refs/heads/master")) {
branch2VersionMap.put("master", versionNo);
continue;
}
if (ref.getName().startsWith("refs/heads/")) {
String branchName = ref.getName().replaceFirst("refs/heads/", "/branches/");
branch2VersionMap.put(branchName, versionNo);
continue;
}
if (ref.getName().startsWith("refs/tags/")) {
String branchName = ref.getName().replaceFirst("refs/tags/", "/tags/");
branch2VersionMap.put(branchName, versionNo);
}
}
return branch2VersionMap;
}
use of org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider in project archi-modelrepository-plugin by archi-contribs.
the class LoadModelFromRepositoryProvider method cloneModel.
private void cloneModel(String url, File cloneFolder, String userName, String password) throws GitAPIException, IOException {
FileUtils.deleteFolder(cloneFolder);
// Make dir
cloneFolder.mkdirs();
CloneCommand cloneCommand = Git.cloneRepository();
cloneCommand.setDirectory(cloneFolder);
cloneCommand.setURI(url);
cloneCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(userName, password));
try (Git git = cloneCommand.call()) {
}
}
use of org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider in project archi-modelrepository-plugin by archi-contribs.
the class ArchiRepository method pullFromRemote.
@Override
public PullResult pullFromRemote(String userName, String userPassword, ProgressMonitor monitor) throws IOException, GitAPIException {
try (Git git = Git.open(getLocalRepositoryFolder())) {
PullCommand pullCommand = git.pull();
pullCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(userName, userPassword));
// Merge, not rebase
pullCommand.setRebase(false);
pullCommand.setProgressMonitor(monitor);
return pullCommand.call();
}
}
use of org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider in project archi-modelrepository-plugin by archi-contribs.
the class ArchiRepository method pushToRemote.
@Override
public Iterable<PushResult> pushToRemote(String userName, String userPassword, ProgressMonitor monitor) throws IOException, GitAPIException {
try (Git git = Git.open(getLocalRepositoryFolder())) {
PushCommand pushCommand = git.push();
pushCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(userName, userPassword));
pushCommand.setProgressMonitor(monitor);
return pushCommand.call();
}
}
Aggregations