当前位置: 首页>>代码示例>>Java>>正文


Java UsernamePasswordCredentialsProvider类代码示例

本文整理汇总了Java中org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider的典型用法代码示例。如果您正苦于以下问题:Java UsernamePasswordCredentialsProvider类的具体用法?Java UsernamePasswordCredentialsProvider怎么用?Java UsernamePasswordCredentialsProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


UsernamePasswordCredentialsProvider类属于org.eclipse.jgit.transport包,在下文中一共展示了UsernamePasswordCredentialsProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: invoke

import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; //导入依赖的package包/类
@Override
public Boolean invoke(File file, VirtualChannel channel){
    try{
        Git git = Git.cloneRepository()
                .setURI(url)
                .setDirectory(localDir)
                .setTransportConfigCallback(getTransportConfigCallback())
                .setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password))
                .call();

        // Default branch to checkout is master
        if(branch==null || branch.isEmpty()){
            branch = "master";
        } else if (cloneType.equals("branch")){
            branch = "origin" + File.separator + branch;
        }
        git.checkout().setName(branch).call();
        git.close();
        }catch(GitAPIException e){
            status = false;
            e.printStackTrace(listener.getLogger());
        }
    return status;
}
 
开发者ID:warriorframework,项目名称:warrior-jenkins-plugin,代码行数:25,代码来源:WarriorPluginBuilder.java

示例2: load

import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; //导入依赖的package包/类
/**
 * 从指定的git仓库地址(目前仅支持http和https)和文件名获取资源,通过UsernameCredential支持鉴权
 * @return 资源的字符串
 * @throws Exception 资源不存在或网络不通
 */
@Override
public String load() throws Exception {
    //本地临时目录,用户存放clone的代码
    String tempDirPath = localPath + "/iaac.aliyun.tmp_" + new Date().getTime();
    File tempDir = new File(tempDirPath);
    tempDir.mkdirs();
    String result = null;
    try {
        CloneCommand clone = Git.cloneRepository();
        clone.setURI(url);
        clone.setBranch(this.branch);
        clone.setDirectory(tempDir);

        //设置鉴权
        if (this.credential != null) {
            UsernamePasswordCredentialsProvider usernamePasswordCredentialsProvider = new
                    UsernamePasswordCredentialsProvider(this.credential.getUsername(), this.credential.getPassword());
            //git仓库地址
            clone.setCredentialsProvider(usernamePasswordCredentialsProvider);
        }
        //执行clone
        Git git = clone.call();
        //从本地路径中获取指定的文件
        File file = new File(tempDir.getAbsolutePath() + "/" + this.fileName);
        //返回文件的字符串
        result = FileUtils.readFileToString(file, "utf-8");
    } catch (Exception e) {
        throw e;
    } finally {
        //清除本地的git临时目录
        FileUtils.deleteDirectory(tempDir);
    }
    return result;
}
 
开发者ID:peterchen82,项目名称:iaac4j.aliyun,代码行数:40,代码来源:GitLoader.java

示例3: doPull

import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; //导入依赖的package包/类
protected void doPull(Exchange exchange, String operation) throws Exception {
    PullResult result = null;
    try {
        if (ObjectHelper.isEmpty(endpoint.getRemotePath())) {
            throw new IllegalArgumentException("Remote path must be specified to execute " + operation);
        }
        if (ObjectHelper.isNotEmpty(endpoint.getBranchName())) {
            git.checkout().setCreateBranch(false).setName(endpoint.getBranchName()).call();
        }
        if (ObjectHelper.isNotEmpty(endpoint.getUsername()) && ObjectHelper.isNotEmpty(endpoint.getPassword())) {
            UsernamePasswordCredentialsProvider credentials = new UsernamePasswordCredentialsProvider(endpoint.getUsername(), endpoint.getPassword());
            result = git.pull().setCredentialsProvider(credentials).setRemote(endpoint.getRemotePath()).call();
        } else {
            result = git.pull().setRemote(endpoint.getRemotePath()).call();
        }
    } catch (Exception e) {
        LOG.error("There was an error in Git " + operation + " operation");
        throw e;
    }
    exchange.getOut().setBody(result);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:GitProducer.java

示例4: push

import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; //导入依赖的package包/类
/**
 * Push current state to remote repository.
 *
 * @param repositoryName for which repository
 * @param username committer username
 * @param password committer password
 */
public void push(String repositoryName, String username, String password)
{
    RepositoryContext repositoryContext = repositoryByName.get(repositoryName);

    try
    {
        PushCommand pushCommand = repositoryContext.git.push();
        pushCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password));
        pushCommand.call();
    }
    catch (GitAPIException e)
    {
        throw new RuntimeException(e);
    }
}
 
开发者ID:edgehosting,项目名称:jira-dvcs-connector,代码行数:23,代码来源:GitTestSupport.java

示例5: doClone

import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; //导入依赖的package包/类
protected void doClone(Exchange exchange, String operation) throws Exception {
    Git result = null;
    if (ObjectHelper.isEmpty(endpoint.getLocalPath())) {
        throw new IllegalArgumentException("Local path must specified to execute " + operation);
    }
    try {
        File localRepo = new File(endpoint.getLocalPath(), "");
        if (!localRepo.exists()) {
            if (ObjectHelper.isNotEmpty(endpoint.getUsername()) && ObjectHelper.isNotEmpty(endpoint.getPassword())) {
                UsernamePasswordCredentialsProvider credentials = new UsernamePasswordCredentialsProvider(endpoint.getUsername(), endpoint.getPassword());
                result = Git.cloneRepository().setCredentialsProvider(credentials).setURI(endpoint.getRemotePath()).setDirectory(new File(endpoint.getLocalPath(), "")).call();
            } else {
                result = Git.cloneRepository().setURI(endpoint.getRemotePath()).setDirectory(new File(endpoint.getLocalPath(), "")).call();
            }
        } else {
            throw new IllegalArgumentException("The local repository directory already exists");
        }
    } catch (Exception e) {
        LOG.error("There was an error in Git " + operation + " operation");
        throw e;
    } finally {
        result.close();
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:GitProducer.java

示例6: doPush

import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; //导入依赖的package包/类
protected void doPush(Exchange exchange, String operation) throws Exception {
    Iterable<PushResult> result = null;
    try {
        if (ObjectHelper.isEmpty(endpoint.getRemotePath())) {
            throw new IllegalArgumentException("Remote path must be specified to execute " + operation);
        }
        if (ObjectHelper.isNotEmpty(endpoint.getBranchName())) {
            git.checkout().setCreateBranch(false).setName(endpoint.getBranchName()).call();
        }
        if (ObjectHelper.isNotEmpty(endpoint.getUsername()) && ObjectHelper.isNotEmpty(endpoint.getPassword())) {
            UsernamePasswordCredentialsProvider credentials = new UsernamePasswordCredentialsProvider(endpoint.getUsername(), endpoint.getPassword());
            result = git.push().setCredentialsProvider(credentials).setRemote(endpoint.getRemotePath()).call();
        } else {
            result = git.push().setRemote(endpoint.getRemotePath()).call();
        }
    } catch (Exception e) {
        LOG.error("There was an error in Git " + operation + " operation");
        throw e;
    }
    exchange.getOut().setBody(result);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:GitProducer.java

示例7: createBranch

import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; //导入依赖的package包/类
/**
 * Create a new branch in the local git repository
 * (git checkout -b branchname) and finally pushes new branch on the remote repository (git push)
 *
 * @param directory the directory in which the local git repository is located
 * @param username  the username to be used while pushing
 * @param password  the password matching with the provided username to be used
 *                  for authentication
 * @param message   the commit message to be used	 
 */
public static void createBranch(@NonNull File directory, String branchName, String username,
								String password, String message) throws GitAPIException {

	try {
		final Git git = Git.open(directory);

		final UsernamePasswordCredentialsProvider userCredential = new UsernamePasswordCredentialsProvider(
				username, password);

		CreateBranchCommand branchCommand = git.branchCreate();
		branchCommand.setName(branchName);
		branchCommand.call();
		
		// and then commit
		final PersonIdent author = new PersonIdent(username, "");
		git.commit().setCommitter(author).setMessage(message)
				.setAuthor(author).call();
		log.info(message);

		git.push().setCredentialsProvider(userCredential).call();
		log.info("Pushed the changes in remote Git repository...");
	} catch (final GitAPIException | IOException e) {
		log.error(e.getMessage(), e);
	}
}
 
开发者ID:awltech,项目名称:easycukes,代码行数:36,代码来源:GitHelper.java

示例8: simple_checkout_with_no_branch

import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; //导入依赖的package包/类
@Test
public void simple_checkout_with_no_branch() throws Exception {

	File outputFolder = new File( baseLocation + "testGitNoBranch" );

	FileUtils.deleteDirectory( outputFolder );

	String message = "Perform git checkout of " + inputUrl + " to destination: "
			+ outputFolder.getAbsolutePath();
	logger.info(Boot_Container_Test.TC_HEAD + message );

	//
	Git r = Git
			.cloneRepository()
			.setURI( inputUrl )
			.setDirectory( outputFolder )
			.setCredentialsProvider(
					new UsernamePasswordCredentialsProvider( "dummy", "dummy" ) )
			.call();

	File buildPom = new File( outputFolder + "/pom.xml" );
	assertThat( buildPom )
			.as( "Pom file found" )
			.exists().isFile();
}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:26,代码来源:Simple_GIT_API.java

示例9: cloneRepo

import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; //导入依赖的package包/类
@Override
public void cloneRepo(File repoDir) throws SysException {

    try {

        CloneCommand command = Git.cloneRepository();
        command.setURI(config.getRepo("host"));
        command.setDirectory(repoDir);

        String user = config.getRepo("username");
        String passwd = config.getRepo("password");

        if (StringUtils.isNotBlank(user) && StringUtils.isNotBlank(passwd)) {
            UsernamePasswordCredentialsProvider upcp = new UsernamePasswordCredentialsProvider(user, passwd);
            command.setCredentialsProvider(upcp);
        }

        command.call();

    } catch (Exception e) {
        throw new SysException(e);
    }
}
 
开发者ID:speedyproject,项目名称:dcmp,代码行数:24,代码来源:RepertoryServiceImpl.java

示例10: pullRepo

import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; //导入依赖的package包/类
@Override
public PullResult pullRepo(File repoDir) throws SysException {
    try {
        Repository repository = new FileRepository(repoDir.getAbsolutePath() + "/.git");
        Git git = new Git(repository);

        PullCommand pull = git.pull();

        String user = config.getRepo("username");
        String passwd = config.getRepo("password");

        if (StringUtils.isNotBlank(user) && StringUtils.isNotBlank(passwd)) {
            UsernamePasswordCredentialsProvider upcp = new UsernamePasswordCredentialsProvider(user, passwd);
            pull.setCredentialsProvider(upcp);
        }

        PullResult result = pull.call();

        return result;
    } catch (Exception e) {
        throw new SysException(e);
    }
}
 
开发者ID:speedyproject,项目名称:dcmp,代码行数:24,代码来源:RepertoryServiceImpl.java

示例11: fetchMaterial

import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; //导入依赖的package包/类
@Override
public String fetchMaterial(FetchMaterialTask task) {
    String errorMessage = null;
    String materialPath = Paths.get(AgentConfiguration.getInstallInfo().getAgentPipelinesDir(), task.getPipelineName(), task.getDestination()).toString();
    GitMaterial definition = (GitMaterial) task.getMaterialDefinition();
    CloneCommand clone = Git.cloneRepository();
    clone.setURI(definition.getRepositoryUrl());
    clone.setBranch(definition.getBranch());
    clone.setDirectory(new File(materialPath));
    clone.setCloneSubmodules(true);
    UsernamePasswordCredentialsProvider credentials = this.handleCredentials(definition);
    clone.setCredentialsProvider(credentials);
    try {
        Git git = clone.call();
        git.close();
    } catch (GitAPIException e) {
        errorMessage = e.getMessage();
    }

    return errorMessage;
}
 
开发者ID:rndsolutions,项目名称:hawkcd,代码行数:22,代码来源:GitMaterialService.java

示例12: clone

import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; //导入依赖的package包/类
/**
 * Clones repository, which is defined by provided repository URI.
 *
 * @param repositoryName into which repository
 * @param cloneUrl url of cloned repository
 * @param username for get access to clone
 * @param password for get access to clone
 */
public void clone(String repositoryName, String cloneUrl, String username, String password)
{
    RepositoryContext repositoryContext = repositoryByName.get(repositoryName);

    try
    {
        CloneCommand cloneCommand = Git.cloneRepository();
        cloneCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password));
        cloneCommand.setURI(cloneUrl);
        cloneCommand.setDirectory(repositoryContext.repository.getDirectory().getParentFile());
        cloneCommand.call();

    }
    catch (GitAPIException e)
    {
        throw new RuntimeException(e);
    }
}
 
开发者ID:edgehosting,项目名称:jira-dvcs-connector,代码行数:27,代码来源:GitTestSupport.java

示例13: getCredentialsProvider

import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; //导入依赖的package包/类
private static CredentialsProvider getCredentialsProvider() {
    final String token = System.getenv("vma.github.token");
    final String name = System.getenv("vma.github.username");
    if ((name == null || name.isEmpty()) && (token == null || token.isEmpty())) {
        throw new IllegalArgumentException("Необходимо задать логин к репозиторию (vma.github.username) или токен (vma.github.token)");
    }
    final String password = System.getenv("vma.github.password");
    if (name != null && !name.isEmpty() && (password == null || password.isEmpty())) {
        throw new IllegalArgumentException("Не задан пароль к репозиторию (vma.github.password)");
    }
    if (token != null && !token.isEmpty()) {
        logger.info("auth by token");
        return new UsernamePasswordCredentialsProvider(token, "");
    } else {
        logger.info("auth by username and password");
        return new UsernamePasswordCredentialsProvider(name, password);
    }
}
 
开发者ID:cobr123,项目名称:VirtaMarketAnalyzer,代码行数:19,代码来源:GitHubPublisher.java

示例14: shouldExecuteRemoteCommandByHttpOrHttpsUrlWithCredentials

import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; //导入依赖的package包/类
@Test(dataProvider = "gitUrlsWithCredentials")
public void shouldExecuteRemoteCommandByHttpOrHttpsUrlWithCredentials(String url)
    throws Exception {
  // given
  ArgumentCaptor<UsernamePasswordCredentialsProvider> captor =
      ArgumentCaptor.forClass(UsernamePasswordCredentialsProvider.class);
  Field usernameField = UsernamePasswordCredentialsProvider.class.getDeclaredField("username");
  Field passwordField = UsernamePasswordCredentialsProvider.class.getDeclaredField("password");
  usernameField.setAccessible(true);
  passwordField.setAccessible(true);

  // when
  jGitConnection.executeRemoteCommand(url, transportCommand, null, null);

  // then
  verify(transportCommand).setCredentialsProvider(captor.capture());
  UsernamePasswordCredentialsProvider credentialsProvider = captor.getValue();
  String username = (String) usernameField.get(credentialsProvider);
  char[] password = (char[]) passwordField.get(credentialsProvider);
  assertEquals(username, "username");
  assertEquals(String.valueOf(password), "password");
}
 
开发者ID:eclipse,项目名称:che,代码行数:23,代码来源:JGitConnectionTest.java

示例15: commitPush

import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; //导入依赖的package包/类
/**
 * Synchronizes your updates on your local repository with github.
 *
 * @param owner
 * @param repoName
 * @throws KaramelException
 */
public synchronized static void commitPush(String owner, String repoName)
    throws KaramelException {
  if (email == null || user == null) {
    throw new KaramelException("You forgot to call registerCredentials. You must call this method first.");
  }
  File repoDir = getRepoDirectory(repoName);
  Git git = null;
  try {
    git = Git.open(repoDir);

    git.commit().setAuthor(user, email).setMessage("Code generated by Karamel.")
        .setAll(true).call();
    git.push().setCredentialsProvider(new UsernamePasswordCredentialsProvider(user, password)).call();
  } catch (IOException | GitAPIException ex) {
    logger.error("error during github push", ex);
    throw new KaramelException(ex.getMessage());
  } finally {
    if (git != null) {
      git.close();
    }

  }
}
 
开发者ID:karamelchef,项目名称:karamel,代码行数:31,代码来源:GithubApi.java


注:本文中的org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。