hudson.plugins.git.extensions.GitSCMExtension Java Examples

The following examples show how to use hudson.plugins.git.extensions.GitSCMExtension. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GitLabSCMMergeRequestHead.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 6 votes vote down vote up
@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 */"nobody@nowhere");
        git.setCommitter("Jenkins", "nobody@nowhere");
        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
}
 
Example #2
Source File: AbstractGitTestCase.java    From flaky-test-handler-plugin with Apache License 2.0 6 votes vote down vote up
protected FreeStyleProject setupProject(List<BranchSpec> branches, boolean authorOrCommitter,
    String relativeTargetDir, String excludedRegions,
    String excludedUsers, String localBranch, boolean fastRemotePoll,
    String includedRegions, List<SparseCheckoutPath> sparseCheckoutPaths) throws Exception {
  FreeStyleProject project = createFreeStyleProject();
  GitSCM scm = new GitSCM(
      createRemoteRepositories(),
      branches,
      false, Collections.<SubmoduleConfig>emptyList(),
      null, null,
      Collections.<GitSCMExtension>emptyList());
  scm.getExtensions().add(new DisableRemotePoll()); // don't work on a file:// repository
  if (relativeTargetDir!=null)
    scm.getExtensions().add(new RelativeTargetDirectory(relativeTargetDir));
  if (excludedUsers!=null)
    scm.getExtensions().add(new UserExclusion(excludedUsers));
  if (excludedRegions!=null || includedRegions!=null)
    scm.getExtensions().add(new PathRestriction(includedRegions,excludedRegions));

  scm.getExtensions().add(new SparseCheckoutPaths(sparseCheckoutPaths));

  project.setScm(scm);
  project.getBuildersList().add(new CaptureEnvironmentBuilder());
  return project;
}
 
Example #3
Source File: GerritSCMSource.java    From gerrit-code-review-plugin with Apache License 2.0 5 votes vote down vote up
@Restricted(DoNotUse.class)
@DataBoundSetter
public void setExtensions(@CheckForNull List<GitSCMExtension> extensions) {
  List<SCMSourceTrait> traits = new ArrayList<>(this.traits);
  for (Iterator<SCMSourceTrait> iterator = traits.iterator(); iterator.hasNext(); ) {
    if (iterator.next() instanceof GitSCMExtensionTrait) {
      iterator.remove();
    }
  }
  EXTENSIONS:
  for (GitSCMExtension extension : Util.fixNull(extensions)) {
    for (SCMSourceTraitDescriptor d : SCMSourceTrait.all()) {
      if (d instanceof GitSCMExtensionTraitDescriptor) {
        GitSCMExtensionTraitDescriptor descriptor = (GitSCMExtensionTraitDescriptor) d;
        if (descriptor.getExtensionClass().isInstance(extension)) {
          try {
            SCMSourceTrait trait = descriptor.convertToTrait(extension);
            if (trait != null) {
              traits.add(trait);
              continue EXTENSIONS;
            }
          } catch (UnsupportedOperationException e) {
            LOGGER.log(
                Level.WARNING,
                "Could not convert " + extension.getClass().getName() + " to a trait",
                e);
          }
        }
      }
      LOGGER.log(
          Level.FINE,
          "Could not convert {0} to a trait (likely because this option does not "
              + "make sense for a GitSCMSource)",
          extension.getClass().getName());
    }
  }
  setTraits(traits);
}
 
Example #4
Source File: ScmFactoryImpl.java    From aws-codecommit-trigger-plugin with Apache License 2.0 5 votes vote down vote up
public GitSCM createGit(String url, List<BranchSpec> branchSpecs) {
    return new GitSCM(
        GitSCM.createRepoList(url, null),
        branchSpecs,
        false,
        Collections.<SubmoduleConfig>emptyList(),
        null,
        null,
        Collections.<GitSCMExtension>emptyList()
    );
}
 
Example #5
Source File: MockGitSCM.java    From aws-codecommit-trigger-plugin with Apache License 2.0 5 votes vote down vote up
@DataBoundConstructor
public MockGitSCM(
    List<UserRemoteConfig> userRemoteConfigs,
    List<BranchSpec> branches,
    Boolean doGenerateSubmoduleConfigurations,
    Collection<SubmoduleConfig> submoduleCfg,
    GitRepositoryBrowser browser,
    String gitTool,
    List<GitSCMExtension> extensions
) {
    super(userRemoteConfigs, branches, doGenerateSubmoduleConfigurations, submoduleCfg, browser, gitTool, extensions);
    this.url = userRemoteConfigs.get(0).getUrl();
}
 
Example #6
Source File: MockGitSCM.java    From aws-codecommit-trigger-plugin with Apache License 2.0 5 votes vote down vote up
public static MockGitSCM fromUrlAndBranchSpecs(String url, List<BranchSpec> branchSpecs) {
    return new MockGitSCM(
        GitSCM.createRepoList(url, null),
        branchSpecs,
        false,
        Collections.<SubmoduleConfig>emptyList(),
        null,
        null,
        Collections.<GitSCMExtension>emptyList()
    );
}
 
Example #7
Source File: GitLabSCMMergeRequestHead.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example #8
Source File: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 5 votes vote down vote up
private static <T extends GitSCMExtension> T getExtension(GitSCM scm, Class<T> type) {
    for (GitSCMExtension e : scm.getExtensions()) {
        if (type.isInstance(e)) {
            return type.cast(e);
        }
    }
    return null;
}
 
Example #9
Source File: GitLabSCMHeadImpl.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 4 votes vote down vote up
@Nonnull
List<GitSCMExtension> getExtensions(GitLabSCMSource source) {
    return emptyList();
}
 
Example #10
Source File: GitLabSCMMergeRequestHead.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 4 votes vote down vote up
@Nonnull
@Override
List<GitSCMExtension> getExtensions(GitLabSCMSource source) {
    return merge ? Collections.<GitSCMExtension>singletonList(new MergeWith()) : Collections.<GitSCMExtension>emptyList();
}