hudson.model.Saveable#hudson.scm.SCM源码实例Demo

下面列出了hudson.model.Saveable#hudson.scm.SCM 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: gitea-plugin   文件: GiteaWebhookListener.java
/**
 * {@inheritDoc}
 */
@Override
public void onChange(Saveable o, XmlFile file) {
    if (!(o instanceof Item)) {
        // must be an Item
        return;
    }
    SCMTriggerItem item = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem((Item) o);
    if (item == null) {
        // more specifically must be an SCMTriggerItem
        return;
    }
    SCMTrigger trigger = item.getSCMTrigger();
    if (trigger == null || trigger.isIgnorePostCommitHooks()) {
        // must have the trigger enabled and not opted out of post commit hooks
        return;
    }
    for (SCM scm : item.getSCMs()) {
        if (scm instanceof GitSCM) {
            // we have a winner
            GiteaWebhookListener.register(item, (GitSCM) scm);
        }
    }
}
 
private String getRepositoryName() {
    String repositoryName = null;
    SCM scm = this.project.getScm();
    if (scm instanceof GitSCM) {
        GitSCM git = (GitSCM)scm;
        List<UserRemoteConfig> userRemoteConfigs = git.getUserRemoteConfigs();
        if (!userRemoteConfigs.isEmpty()) {
            String repoUrl = userRemoteConfigs.get(0).getUrl();
            if (repoUrl != null) {
                GitlabRepositoryName gitlabRepositoryName = GitlabRepositoryName.create(repoUrl);
                if (gitlabRepositoryName != null) {
                    repositoryName = gitlabRepositoryName.userName + "/" + gitlabRepositoryName.repositoryName;
                }
            }
        }
    }
    return repositoryName;
}
 
@Override
public SCM newInstance(final StaplerRequest req,
                       final JSONObject formData) throws FormException {
    return new AWSCodePipelineSCM(
            req.getParameter("name"),
            req.getParameter("clearWorkspace") != null,
            req.getParameter("region"),
            req.getParameter("awsAccessKey"),
            req.getParameter("awsSecretKey"),
            req.getParameter("proxyHost"),
            req.getParameter("proxyPort"),
            req.getParameter("category"),
            req.getParameter("provider"),
            req.getParameter("version"),
            new AWSClientFactory());
}
 
/**
 * Construct a SingleTestFlakyStatsWithRevision object with {@link SingleTestFlakyStats} and
 * build information.
 *
 * @param stats Embedded {@link SingleTestFlakyStats} object
 * @param build The {@link hudson.model.Run} object to get SCM information from.
 */
public SingleTestFlakyStatsWithRevision(SingleTestFlakyStats stats, Run build) {
  this.stats = stats;
  revision = Integer.toString(build.getNumber());

  Job job = build.getParent();
  SCMTriggerItem s = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(job);
  if (s != null) {
    ArrayList<SCM> scms = new ArrayList<>(s.getSCMs());
    SCM scm = scms.size() > 0 ? scms.get(0) : null;

    if (scm != null && "hudson.plugins.git.GitSCM".equalsIgnoreCase(scm.getType())) {
      GitSCM gitSCM = (GitSCM) scm;
      BuildData buildData = gitSCM.getBuildData(build);
      if (buildData != null) {
        Revision gitRevision = buildData.getLastBuiltRevision();
        if (gitRevision != null) {
          revision = gitRevision.getSha1String();
        }
      }
    }
  }
}
 
public static Collection<? extends SCMDescriptor<?>> getSupportedSCMs() {
    List<SCMDescriptor<?>> list = new ArrayList<>();
    for (SCMDescriptor<?> scmDescriptor : SCM.all()) {
        // It doesn't really make sense to have the None SCM per the spirit of this plugin.
        if (!scmDescriptor.getDisplayName().equals("None")) {
            list.add(scmDescriptor);
        }
    }
    return list;
}
 
@Nonnull
@Restricted(NoExternalUse.class)
@SuppressWarnings("unused") // used by index.jelly
public Set<Permission> getAgentPermissions() {
    HashSet<PermissionGroup> groups = new HashSet<>(PermissionGroup.getAll());
    groups.remove(PermissionGroup.get(Run.class));
    groups.remove(PermissionGroup.get(SCM.class));
    groups.remove(PermissionGroup.get(View.class));
    groups.remove(PermissionGroup.get(Item.class));
    groups.remove(PermissionGroup.get(Hudson.class));
    groups.remove(PermissionGroup.get(Permission.class));
    return getSafePermissions(groups);
}
 
@Override
public void onCheckout(Run<?, ?> build, SCM scm, FilePath workspace, TaskListener listener,
    File changelogFile,
    SCMRevisionState pollingBaseline) {
    LOGGER.log(Level.FINE, String.format("SCMListener: Checkout > %s", build.getFullDisplayName()));
    sendNotifications(build, listener);
}
 
源代码8 项目: gitea-plugin   文件: GiteaNotifier.java
@Override
public void onCheckout(Run<?, ?> build, SCM scm, FilePath workspace, TaskListener listener, File changelogFile,
                       SCMRevisionState pollingBaseline) throws Exception {
    try {
        sendNotifications(build, listener);
    } catch (IOException | InterruptedException e) {
        e.printStackTrace(listener.error("Could not send notifications"));
    }
}
 
private boolean matches(final Event event, final SCM scm) {
    if (event == null || scm == null) {
        return false;
    }

    if (this.isGitScmAvailable() && this.matchesGitSCM(event, scm)) {
        return true;
    } else if (this.isMultiScmAvailable() && this.matchesMultiSCM(event, scm)) {
        return true;
    } else {
        return false;
    }
}
 
private boolean matchesGitSCM(final Event event, final SCM scmProvider) {
    if (!(scmProvider instanceof GitSCM)) {
        return false;
    }

    final GitSCM git = (GitSCM) scmProvider;
    final List<RemoteConfig> configs = git.getRepositories();

    boolean matched = this.matchesConfigs(event, configs);
    matched = matched && this.matchBranch(event, git.getBranches());
    return matched;
}
 
private boolean matchesMultiSCM(final Event event, final SCM scmProvider) {
    if (!(scmProvider instanceof org.jenkinsci.plugins.multiplescms.MultiSCM)) {
        return false;
    }

    final MultiSCM multiSCM = (MultiSCM) scmProvider;
    final List<SCM> scms = multiSCM.getConfiguredSCMs();

    for (final SCM scm : scms) {
        if (this.matches(event, scm)) {
            return true;
        }
    }
    return false;
}
 
源代码12 项目: aws-codecommit-trigger-plugin   文件: RepoInfo.java
public static RepoInfo fromSqsJob(SQSJob sqsJob) {
    if (sqsJob == null) {
        return null;
    }

    RepoInfo repoInfo = new RepoInfo();

    List<SCM> scms = sqsJob.getScmList();
    List<String> codeCommitUrls = new ArrayList<>();
    List<String> nonCodeCommitUrls = new ArrayList<>();
    List<String> branches = new ArrayList<>();

    for (SCM scm : scms) {
        if (scm instanceof GitSCM) {//TODO refactor to visitor
            GitSCM git = (GitSCM) scm;
            List<RemoteConfig> repos = git.getRepositories();
            for (RemoteConfig repo : repos) {
                for (URIish urIish : repo.getURIs()) {
                    String url = urIish.toString();
                    if (StringUtils.isCodeCommitRepo(url)) {
                        codeCommitUrls.add(url);
                    }
                    else {
                        nonCodeCommitUrls.add(url);
                    }
                }
            }

            for (BranchSpec branchSpec : git.getBranches()) {
                branches.add(branchSpec.getName());
            }
        }
    }

    repoInfo.nonCodeCommitUrls = nonCodeCommitUrls;
    repoInfo.codeCommitUrls = codeCommitUrls;
    repoInfo.branches = branches;
    return repoInfo;
}
 
public Map<String, URIish> getCommitRepoMap() throws Exception {
    HashMap<String, URIish> commitRepoMap = new HashMap<String, URIish>();

    for (SCM scm : multiScm.getConfiguredSCMs()) {
        if (scm instanceof GitSCM) {
            commitRepoMap.putAll(new GitScmAdapter((GitSCM) scm, this.build).getCommitRepoMap());
        } else if (scm instanceof MercurialSCM) {
            commitRepoMap.putAll(new MercurialScmAdapter((MercurialSCM) scm, this.build).getCommitRepoMap());
        }
    }

    return commitRepoMap;
}
 
源代码14 项目: jenkins-plugin   文件: OpenShiftImageStreams.java
@Nonnull
@Override
protected SCM createSCM() {
    com.openshift.jenkins.plugins.pipeline.OpenShiftImageStreams scm = new com.openshift.jenkins.plugins.pipeline.OpenShiftImageStreams(
            name, tag, apiURL, namespace, authToken, verbose);
    scm.setAuth(auth);
    return scm;
}
 
@Test
public void testRoundTripConfiguration() throws Exception {
    final AWSCodePipelineSCM before = awsCodePipelineSCM;
    final Project project = jenkinsRule.createFreeStyleProject();
    project.setScm(before);

    jenkinsRule.configRoundtrip(project);
    final SCM after = project.getScm();

    jenkinsRule.assertEqualDataBoundBeans(before, after);
}
 
源代码16 项目: gitlab-plugin   文件: BuildStatusAction.java
private boolean hasGitSCM(SCMTriggerItem item) {
    if (item != null) {
        for (SCM scm : item.getSCMs()) {
            if (scm instanceof GitSCM) {
                return true;
            }
        }
    }
    return false;
}
 
private GitSCM getGitSCM(SCMTriggerItem item) {
    if (item != null) {
        for (SCM scm : item.getSCMs()) {
            if (scm instanceof GitSCM) {
                return (GitSCM) scm;
            }
        }
    }
    return null;
}
 
源代码18 项目: gitlab-plugin   文件: ProjectLabelsProvider.java
private GitSCM getGitSCM(SCMTriggerItem item) {
    if (item != null) {
        for (SCM scm : item.getSCMs()) {
            if (scm instanceof GitSCM) {
                return (GitSCM) scm;
            }
        }
    }
    return null;
}
 
源代码19 项目: gitlab-plugin   文件: ProjectBranchesProvider.java
private GitSCM getGitSCM(SCMTriggerItem item) {
    if (item != null) {
        for (SCM scm : item.getSCMs()) {
            if (scm instanceof GitSCM) {
                return (GitSCM) scm;
            }
        }
    }
    return null;
}
 
public SCM getJenkinsFileScm() {
    return jenkinsFileScm;
}
 
@DataBoundSetter
public void setJenkinsFileScm(SCM jenkinsFileScm) {
    this.jenkinsFileScm = jenkinsFileScm;
}
 
@DataBoundConstructor public ConfigFileSCMBinder(String scriptPath, SCM jenkinsFileScm) {
    this.scriptPath = scriptPath;
    this.jenkinsFileScm = jenkinsFileScm;
}
 
public SCM getJenkinsFileScm() {
    return jenkinsFileScm;
}
 
@DataBoundSetter
public void setJenkinsFileScm(SCM jenkinsFileScm) {
    this.jenkinsFileScm = jenkinsFileScm;
}
 
@Override
public boolean isMatch(@NonNull SCM scm) {
    return false;
}
 
@Override
public Class<? extends SCM> getScmClass() {
    return GitSCM.class;
}
 
@Override
public boolean supports(SCM source) {
    return false;
}
 
@Override
public SCMFileSystem build(@NonNull Item owner, @NonNull SCM scm,
    @CheckForNull SCMRevision rev) {
    return null;
}
 
@NonNull
@Override
public SCM build(@NonNull SCMHead head, SCMRevision revision) {
    return new GitLabSCMBuilder(this, head, revision).withTraits(traits).build();
}
 
源代码30 项目: gitea-plugin   文件: SSHCheckoutTrait.java
@Override
public Class<? extends SCM> getScmClass() {
    return GitSCM.class;
}