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


Java GitClient类代码示例

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


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

示例1: doFillCredentialsIdItems

import org.jenkinsci.plugins.gitclient.GitClient; //导入依赖的package包/类
public ListBoxModel doFillCredentialsIdItems(
    @AncestorInPath Item context,
    @QueryParameter String remote,
    @QueryParameter String credentialsId) {
  if (context == null && !Jenkins.getActiveInstance().hasPermission(Jenkins.ADMINISTER)
      || context != null && !context.hasPermission(Item.EXTENDED_READ)) {
    return new StandardListBoxModel().includeCurrentValue(credentialsId);
  }
  return new StandardListBoxModel()
      .includeEmptyValue()
      .includeMatchingAs(
          context instanceof Queue.Task
              ? Tasks.getAuthenticationOf((Queue.Task) context)
              : ACL.SYSTEM,
          context,
          StandardUsernameCredentials.class,
          URIRequirementBuilder.fromUri(remote).build(),
          GitClient.CREDENTIALS_MATCHER)
      .includeCurrentValue(credentialsId);
}
 
开发者ID:GerritForge,项目名称:gerrit-plugin,代码行数:21,代码来源:GerritSCMSource.java

示例2: decorateRevisionToBuild

import org.jenkinsci.plugins.gitclient.GitClient; //导入依赖的package包/类
@Override
public Revision decorateRevisionToBuild(GitSCM scm, Run<?, ?> build, GitClient git, TaskListener listener, Revision marked, Revision rev) throws IOException, InterruptedException, GitException {
    listener.getLogger().println("Merging " + targetBranch.getName() + " commit " + targetBranch.getRevision().getHash() + " into merge-request head commit " + rev.getSha1String());
    checkout(scm, build, git, listener, rev);
    try {
        git.setAuthor("Jenkins", /* could parse out of JenkinsLocationConfiguration.get().getAdminAddress() but seems overkill */"[email protected]");
        git.setCommitter("Jenkins", "[email protected]");
        MergeCommand cmd = git.merge().setRevisionToMerge(ObjectId.fromString(targetBranch.getRevision().getHash()));
        for (GitSCMExtension ext : scm.getExtensions()) {
            // By default we do a regular merge, allowing it to fast-forward.
            ext.decorateMergeCommand(scm, build, git, listener, cmd);
        }
        cmd.execute();
    } catch (GitException e) {
        // Try to revert merge conflict markers.
        checkout(scm, build, git, listener, rev);
        throw e;
    }
    build.addAction(new MergeRecord(targetBranch.getRefSpec().destinationRef(targetBranch.getName()), targetBranch.getRevision().getHash())); // does not seem to be used, but just in case
    ObjectId mergeRev = git.revParse(Constants.HEAD);
    listener.getLogger().println("Merge succeeded, producing " + mergeRev.name());
    return new Revision(mergeRev, rev.getBranches()); // note that this ensures Build.revision != Build.marked
}
 
开发者ID:Argelbargel,项目名称:gitlab-branch-source-plugin,代码行数:24,代码来源:GitLabSCMMergeRequestHead.java

示例3: doFillCheckoutCredentialsIdItems

import org.jenkinsci.plugins.gitclient.GitClient; //导入依赖的package包/类
@Restricted(NoExternalUse.class)
public ListBoxModel doFillCheckoutCredentialsIdItems(@AncestorInPath SCMSourceOwner context, @QueryParameter String connectionName, @QueryParameter String checkoutCredentialsId) {
    if (context == null && !Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER) ||
            context != null && !context.hasPermission(Item.EXTENDED_READ)) {
        return new StandardListBoxModel().includeCurrentValue(checkoutCredentialsId);
    }

    StandardListBoxModel result = new StandardListBoxModel();
    result.add("- anonymous -", CHECKOUT_CREDENTIALS_ANONYMOUS);
    return result.includeMatchingAs(
            context instanceof Queue.Task
                    ? Tasks.getDefaultAuthenticationOf((Queue.Task) context)
                    : ACL.SYSTEM,
            context,
            StandardUsernameCredentials.class,
            SettingsUtils.gitLabConnectionRequirements(connectionName),
            GitClient.CREDENTIALS_MATCHER
    );
}
 
开发者ID:Argelbargel,项目名称:gitlab-branch-source-plugin,代码行数:20,代码来源:GitLabSCMSourceSettings.java

示例4: getCandidateRevisions

import org.jenkinsci.plugins.gitclient.GitClient; //导入依赖的package包/类
/**
 * Get failing build revision if this is a deflake build, otherwise use the default build chooser
 */
@Override
public Collection<Revision> getCandidateRevisions(boolean isPollCall, String singleBranch,
    GitClient git,
    TaskListener listener, BuildData buildData,
    BuildChooserContext context)
    throws GitException, IOException, InterruptedException {

  AbstractBuild build = context.actOnBuild(new GetBuild());
  // Not sure why it cannot be inferred and we have to put cast here
  DeflakeCause cause = (DeflakeCause) build.getCause(DeflakeCause.class);

  if (cause != null) {
    BuildData gitBuildData = gitSCM.getBuildData(cause.getUpstreamRun(), true);
    Revision revision = gitBuildData.getLastBuiltRevision();
    if (revision != null) {
      return Collections.singletonList(revision);
    }
  }

  // If it is not a deflake run, then use the default git checkout strategy
  defaultBuildChooser.gitSCM = this.gitSCM;
  return defaultBuildChooser
      .getCandidateRevisions(isPollCall, singleBranch, git, listener, buildData, context);
}
 
开发者ID:jenkinsci,项目名称:flaky-test-handler-plugin,代码行数:28,代码来源:DeflakeGitBuildChooser.java

示例5: touchAndCommit

import org.jenkinsci.plugins.gitclient.GitClient; //导入依赖的package包/类
public void touchAndCommit(File repo, String... names) throws Exception {
    GitClient client = gitClient(repo);
    for (String name : names) {
        FilePath toTouch = new FilePath(repo).child(name);
        if (!toTouch.exists()) {
            toTouch.getParent().mkdirs();
            toTouch.touch(0);
            client.add(name);
        } else {
            toTouch.write(toTouch.readToString() + "extra line\n", "UTF-8");
        }
    }
    client.setAuthor("dummy", "[email protected]");
    client.setCommitter("dummy", "[email protected]");
    client.commit("added " + Arrays.toString(names));
}
 
开发者ID:jenkinsci,项目名称:gatekeeper-plugin,代码行数:17,代码来源:GitRule.java

示例6: integrateAsGitPluginExt

import org.jenkinsci.plugins.gitclient.GitClient; //导入依赖的package包/类
@Override
public void integrateAsGitPluginExt(GitSCM scm, Run<?, ?> build, GitClient git, TaskListener listener, Revision marked, Revision rev, GitBridge gitbridge) throws NothingToDoException, IntegrationFailedException, IOException, InterruptedException {


    String expandedRepoName;
    try {
        expandedRepoName = gitbridge.getExpandedRepository(build.getEnvironment(listener));
    } catch (IOException | InterruptedException ex) {
        expandedRepoName = gitbridge.getRepoName();
    }

    if (!PretestedIntegrationGitUtils.isRelevant(rev, expandedRepoName)) {
        throw new NothingToDoException("No revision matches configuration in 'Integration repository'");
    }

    Branch triggerBranch = rev.getBranches().iterator().next();
    String expandedIntegrationBranch = gitbridge.getExpandedIntegrationBranch(build.getEnvironment(listener));
    doTheIntegration((Run) build, listener, gitbridge, triggerBranch.getSHA1(), git, expandedIntegrationBranch, triggerBranch);
}
 
开发者ID:Praqma,项目名称:pretested-integration-plugin,代码行数:20,代码来源:AccumulatedCommitStrategy.java

示例7: tryFastForward

import org.jenkinsci.plugins.gitclient.GitClient; //导入依赖的package包/类
/**
 * Attempts to fast-forward merge the integration integrationBranch to the ready integrationBranch.
 * Only when the ready integrationBranch consists of a single commit.
 *
 * @param commitId The commit
 * @param commitCount The amount of commits
 * @param logger The logger for console logging
 * @param client The GitClient
 * @return true if the FF merge was a success, false if the integrationBranch isn't
 * suitable for a FF merge.
 * @throws IntegrationFailedException When commit counting fails
 * @throws NothingToDoException In case there is no commit to integrate/FF
 */
protected boolean tryFastForward(ObjectId commitId, PrintStream logger, GitClient client, int commitCount ) throws IntegrationFailedException, NothingToDoException {
    LOGGER.log(Level.INFO, GitMessages.LOG_PREFIX+ "Entering tryFastForward");

    if ( commitCount == 1) {
        logger.println(GitMessages.LOG_PREFIX+ "Try FF as there is only one commit");
    } else {
        logger.println(GitMessages.LOG_PREFIX+ "Skip FF as there are several commits");
        return false;
    }

    //FF merge the commit
    try {
        LOGGER.log(Level.INFO, GitMessages.LOG_PREFIX+ "Attempting merge with FF.");
        client.merge().setGitPluginFastForwardMode(MergeCommand.GitPluginFastForwardMode.FF_ONLY).setRevisionToMerge(commitId).execute();
        logger.println(GitMessages.LOG_PREFIX+ "FF merge successful.");
        LOGGER.log(Level.INFO, GitMessages.LOG_PREFIX+ " Exiting tryFastForward.");
        return true;
    } catch (GitException | InterruptedException ex) {
        logger.println(GitMessages.LOG_PREFIX+ "FF merge failed.");
        LOGGER.log(Level.INFO, GitMessages.LOG_PREFIX+ " Exiting tryFastForward.");
        return false;
    }
}
 
开发者ID:Praqma,项目名称:pretested-integration-plugin,代码行数:37,代码来源:GitIntegrationStrategy.java

示例8: containsRemoteBranch

import org.jenkinsci.plugins.gitclient.GitClient; //导入依赖的package包/类
/**
 * Checks whether or not we can find the given remote integrationBranch.
 * @param client the Git Client
 * @param branch the integrationBranch to look for
 * @return True if the integrationBranch was found, otherwise False.
 * @throws IntegrationFailedException when the Git call failed unexpectedly
 */
protected boolean containsRemoteBranch(GitClient client, Branch branch) throws IntegrationFailedException {
    try {
        LOGGER.fine("Resolving and getting Git client from workspace:");
        LOGGER.fine("Remote branches:");
        for (Branch remoteBranch : client.getRemoteBranches()) {
            LOGGER.fine(String.format("Found remote branch %s", remoteBranch.getName()));
            if (remoteBranch.getName().equals(branch.getName())) {
                return true;
            }
        }
    } catch (GitException | InterruptedException ex) {
        LOGGER.log(Level.SEVERE, "GitClient error", ex);
        throw new IntegrationFailedException("GitClient error, unspecified", ex);
    }
    return false;
}
 
开发者ID:Praqma,项目名称:pretested-integration-plugin,代码行数:24,代码来源:GitIntegrationStrategy.java

示例9: pushToIntegrationBranch

import org.jenkinsci.plugins.gitclient.GitClient; //导入依赖的package包/类
/**
 * {@inheritDoc }
 */
@Override
public void pushToIntegrationBranch(AbstractBuild<?, ?> build, BuildListener listener) throws PushFailedException {
    try {
        EnvVars environment = build.getEnvironment(listener);
        String expandedRepo = getExpandedRepository(environment);
        String expandedBranch = getExpandedIntegrationBranch(environment);

        GitSCM gitSCM = findScm(build, listener);
        GitClient client = gitSCM.createClient(listener, build.getEnvironment(listener), build, build.getWorkspace());
        pushToBranch(listener, client, expandedBranch, expandedRepo);
    } catch (IOException | InterruptedException ex) {
        LOGGER.log(Level.SEVERE, "Failed to push changes to integration branch. Exception:", ex);
        listener.getLogger().println(GitMessages.LOG_PREFIX+ String.format("Failed to push changes to integration branch. Exception %s", ex));
        throw new PushFailedException(String.format("Failed to push changes to integration branch, message was:%n%s", ex));
    }
}
 
开发者ID:Praqma,项目名称:pretested-integration-plugin,代码行数:20,代码来源:GitBridge.java

示例10: retrieveActions

import org.jenkinsci.plugins.gitclient.GitClient; //导入依赖的package包/类
/** {@inheritDoc} */
@NonNull
@Override
protected List<Action> retrieveActions(
    @CheckForNull SCMSourceEvent event, @NonNull TaskListener listener)
    throws IOException, InterruptedException {
  return doRetrieve(
      new Retriever<List<Action>>() {
        @Override
        public List<Action> run(
            GitClient client, String remoteName, Changes.QueryRequest queryRequest)
            throws IOException, InterruptedException {
          Map<String, String> symrefs = client.getRemoteSymbolicReferences(getRemote(), null);
          if (symrefs.containsKey(Constants.HEAD)) {
            // Hurrah! The Server is Git 1.8.5 or newer and our client has symref reporting
            String target = symrefs.get(Constants.HEAD);
            if (target.startsWith(Constants.R_HEADS)) {
              // shorten standard names
              target = target.substring(Constants.R_HEADS.length());
            }
            List<Action> result = new ArrayList<>();
            if (StringUtils.isNotBlank(target)) {
              result.add(new GitRemoteHeadRefAction(getRemote(), target));
            }
            result.add(new GerritLogo());
            return result;
          }

          // Give up, there's no way to get the primary branch
          return new ArrayList<>();
        }
      },
      new GitSCMSourceContext<>(null, SCMHeadObserver.none()).withTraits(getTraits()),
      listener,
      false);
}
 
开发者ID:GerritForge,项目名称:gerrit-plugin,代码行数:37,代码来源:AbstractGerritSCMSource.java

示例11: doCheckCredentialsId

import org.jenkinsci.plugins.gitclient.GitClient; //导入依赖的package包/类
public FormValidation doCheckCredentialsId(
    @AncestorInPath Item context, @QueryParameter String remote, @QueryParameter String value) {
  if (context == null && !Jenkins.getActiveInstance().hasPermission(Jenkins.ADMINISTER)
      || context != null && !context.hasPermission(Item.EXTENDED_READ)) {
    return FormValidation.ok();
  }

  value = Util.fixEmptyAndTrim(value);
  if (value == null) {
    return FormValidation.ok();
  }

  remote = Util.fixEmptyAndTrim(remote);
  if (remote == null)
  // not set, can't check
  {
    return FormValidation.ok();
  }

  for (ListBoxModel.Option o :
      CredentialsProvider.listCredentials(
          StandardUsernameCredentials.class,
          context,
          context instanceof Queue.Task
              ? Tasks.getAuthenticationOf((Queue.Task) context)
              : ACL.SYSTEM,
          URIRequirementBuilder.fromUri(remote).build(),
          GitClient.CREDENTIALS_MATCHER)) {
    if (StringUtils.equals(value, o.value)) {
      // TODO check if this type of credential is acceptable to the Git client or does it merit warning
      // NOTE: we would need to actually lookup the credential to do the check, which may require
      // fetching the actual credential instance from a remote credentials store. Perhaps this is
      // not required
      return FormValidation.ok();
    }
  }
  // no credentials available, can't check
  return FormValidation.warning("Cannot find any credentials with id " + value);
}
 
开发者ID:GerritForge,项目名称:gerrit-plugin,代码行数:40,代码来源:GerritSCMSource.java

示例12: checkout

import org.jenkinsci.plugins.gitclient.GitClient; //导入依赖的package包/类
private void checkout(GitSCM scm, Run<?, ?> build, GitClient git, TaskListener listener, Revision rev) throws InterruptedException, IOException, GitException {
    CheckoutCommand checkoutCommand = git.checkout().ref(rev.getSha1String());
    for (GitSCMExtension ext : scm.getExtensions()) {
        ext.decorateCheckoutCommand(scm, build, git, listener, checkoutCommand);
    }
    checkoutCommand.execute();
}
 
开发者ID:Argelbargel,项目名称:gitlab-branch-source-plugin,代码行数:8,代码来源:GitLabSCMMergeRequestHead.java

示例13: getSSHCredentials

import org.jenkinsci.plugins.gitclient.GitClient; //导入依赖的package包/类
public static SSHUserPrivateKey getSSHCredentials(BuildContext context, EnvVars envVars) {
    SCM scm = context.build.getProject().getScm();
    if (!(scm instanceof GitSCM)) {
        context.listener.getLogger().println("Error: SCM is not a GitSCM: " + scm.getType());
        return null;
    }

    GitSCM git = (GitSCM) scm;

    SSHUserPrivateKey theCreds = null;
    for (UserRemoteConfig uc : git.getUserRemoteConfigs()) {
        if (uc.getCredentialsId() != null) {
            String url = uc.getUrl();
            url = GitSCM.getParameterString(url, envVars);
            theCreds = CredentialsMatchers
                    .firstOrNull(
                            CredentialsProvider.lookupCredentials(SSHUserPrivateKey.class, context.build.getProject(),
                                    ACL.SYSTEM, URIRequirementBuilder.fromUri(url).build()),
                            CredentialsMatchers.allOf(CredentialsMatchers.withId(uc.getCredentialsId()),
                                    GitClient.CREDENTIALS_MATCHER));
            // just choose the first one. there should only be one...
            if (theCreds != null) {
                break;

            }
        }
    }

    return theCreds;
}
 
开发者ID:tanium,项目名称:pyjenkins,代码行数:31,代码来源:GitSSHKeyHelper.java

示例14: getCredentials

import org.jenkinsci.plugins.gitclient.GitClient; //导入依赖的package包/类
private StandardUsernameCredentials getCredentials(String credentialsID) {
	GitSCMSource source = new GitSCMSource("id", this.remote, credentialsID, "*", "", false);

	return CredentialsMatchers.firstOrNull(
			CredentialsProvider.lookupCredentials(StandardUsernameCredentials.class, source.getOwner(), ACL.SYSTEM,
					URIRequirementBuilder.fromUri(source.getRemoteName()).build()),
			CredentialsMatchers.allOf(CredentialsMatchers.withId(credentialsID), GitClient.CREDENTIALS_MATCHER));
}
 
开发者ID:EvoSuite,项目名称:evosuite,代码行数:9,代码来源:Git.java

示例15: testBasicMerge

import org.jenkinsci.plugins.gitclient.GitClient; //导入依赖的package包/类
@Test
public void testBasicMerge() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject();
    List<UserRemoteConfig> remotes = new ArrayList<UserRemoteConfig>();
    remotes.add(new UserRemoteConfig(repo.getPath(), "origin", "master", null));
    List<BranchSpec> branches = new ArrayList<BranchSpec>();
    branches.add(new BranchSpec("master"));
    p.setScm(new GitSCM(remotes, branches, false, null, null, null, null));

    // Init repo with release and feature branch.
    GitClient client = g.gitClient(repo);
    client.init();
    g.touchAndCommit(repo, "init");
    client.checkout("HEAD", "r1336");
    g.touchAndCommit(repo, "r1336");
    client.checkout("HEAD", "c3");
    g.touchAndCommit(repo, "c3");

    // Custom builder that merges feature branch with release branch using AdvancedSCMManager.
    p.getBuildersList().add(new TestBuilder() {
        @Override
        public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
            try {
                AdvancedSCMManager amm = SCMManagerFactory.getManager(build, launcher, listener);
                amm.update("r1336");
                amm.mergeWorkspaceWith("c3", null);
                amm.commit("merge c3", "test <[email protected]>");
                return true;
            } catch (Exception e) {
                e.printStackTrace(listener.getLogger());
                return false;
            }
        }
    });

    // Assert file is here (should be after successful merge)
    g.buildAndCheck(p, "c3");
}
 
开发者ID:jenkinsci,项目名称:gatekeeper-plugin,代码行数:39,代码来源:BasicGitTest.java


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