Java源码示例:hudson.scm.NullSCM

示例1
@Parameterized.Parameters(name = "{0}")
public static List<Object[]> fixtures() {
    return Arrays.asList(new Object[][]{
        {
            "branch matched",
            new ProjectFixture()
                .setSendBranches("refs/heads/foo")
                .setScm(MockGitSCM.fromUrlAndBranchSpecs(defaultSCMUrl, Collections.singletonList(new BranchSpec("refs/heads/foo"))))
                .setShouldStarted(true)
        },
        {
            "no branch not match",
            new ProjectFixture()
                .setSendBranches("refs/heads/bar")
                .setScm(MockGitSCM.fromUrlAndBranchSpecs(defaultSCMUrl, Collections.singletonList(new BranchSpec("refs/heads/foo"))))
                .setShouldStarted(false)
        },
        {
            "scm is undefined",
            new ProjectFixture()
                .setSendBranches("refs/heads/bar")
                .setScm(new NullSCM())
                .setShouldStarted(false)
        },
        {
            "branch is undefined",
            new ProjectFixture()
                .setSendBranches("refs/heads/bar")
                .setScm(MockGitSCM.fromUrlAndBranchSpecs(defaultSCMUrl, Collections.<BranchSpec>emptyList()))
                .setShouldStarted(false)
        }
    });
}
 
示例2
protected void subscribeProject(final ProjectFixture fixture) throws Exception {
        String name = UUID.randomUUID().toString();

        final FreeStyleProject job = jenkinsRule.getInstance().createProject(FreeStyleProject.class, name);
        job.setScm(new NullSCM());
        if (fixture.getScm() != null) {
            job.setScm(fixture.getScm());
        }

        final String uuid = this.sqsQueue.getUuid();

        SQSTrigger trigger = null;

        if (fixture.isHasTrigger()) {
            trigger = new SQSTrigger(uuid, fixture.isSubscribeInternalScm(), fixture.getScmConfigs());
        }

//        final OneShotEvent event = new OneShotEvent();
        fixture.setEvent(new OneShotEvent());
        job.getBuildersList().add(new TestBuilder() {

            @Override
            public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
                fixture.setLastBuild(job.getLastBuild());
                fixture.getEvent().signal();
                return true;
            }
        });
        job.setQuietPeriod(0);

        if (trigger != null) {
            trigger.start(job, false);
            job.addTrigger(trigger);
        }

//        fixture.setEvent(event);
    }
 
示例3
/**
 * Overrides the form with a sanitized version.
 * <br>
 * {@inheritDoc}
 */
@Override
public JSONObject getSubmittedForm() throws ServletException {
    JSONObject json = super.getSubmittedForm().getJSONObject("projectFactory");

    // JENKINS-36043: Provide dummy SCM since the form elements were removed from the config page
    // {"scm": {"value": "0", "stapler-class": "hudson.scm.NullSCM", "$class": "hudson.scm.NullSCM"}}
    JSONObject scm = new JSONObject();
    scm.put("value", "0");
    scm.put("stapler-class", NullSCM.class.getName());
    scm.put("$class", NullSCM.class.getName());

    json.put("scm", scm);
    return json;
}
 
示例4
/**
 * Common initialization that is invoked when either a new project is created with the constructor
 * {@link TemplateDrivenMultiBranchProject#TemplateDrivenMultiBranchProject(ItemGroup, String)} or when a project
 * is loaded from disk with {@link #onLoad(ItemGroup, String)}.
 */
protected void init3() {
    if (disabledSubProjects == null) {
        disabledSubProjects = new PersistedList<>(this);
    }

    // Owner doesn't seem to be set when loading from XML
    disabledSubProjects.setOwner(this);

    try {
        XmlFile templateXmlFile = Items.getConfigFile(getTemplateDir());
        if (templateXmlFile.getFile().isFile()) {
            /*
             * Do not use Items.load here, since it uses getRootDirFor(i) during onLoad,
             * which returns the wrong location since template would still be unset.
             * Instead, read the XML directly into template and then invoke onLoad.
             */
            //noinspection unchecked
            template = (P) templateXmlFile.read();
            template.onLoad(this, TEMPLATE);
        } else {
            /*
             * Don't use the factory here because newInstance calls setBranch, attempting
             * to save the project before template is set.  That would invoke
             * getRootDirFor(i) and get the wrong directory to save into.
             */
            template = newTemplate();
        }

        // Prevent tampering
        if (!(template.getScm() instanceof NullSCM)) {
            template.setScm(new NullSCM());
        }
        template.disable();
    } catch (IOException e) {
        LOGGER.log(Level.WARNING, "Failed to load template project " + getTemplateDir(), e);
    }
}
 
示例5
@Override
public boolean matches(List<Event> events, SQSJob job) {//TODO load scm list
    SQSTrigger trigger = job.getTrigger();
    List<SQSScmConfig> scmConfigs = new ArrayList<>();

    List<SQSScmConfig> triggerScms = trigger.getSqsScmConfigs();
    if (CollectionUtils.isNotEmpty(triggerScms)) {
        scmConfigs.addAll(triggerScms);
    }
    if (trigger.isSubscribeInternalScm()) {
        scmConfigs.add(new SQSScmConfig(SQSScmConfig.Type.AutoSubscription.name(), null, null));
    }

    List<SCM> scms = new ArrayList<>();
    for (SQSScmConfig scmConfig : scmConfigs) {
        switch (scmConfig.getType()) {
            case AutoSubscription:
                scms.addAll(job.getScmList());
                break;

            case ManualSubscription:
                scms.add(scmConfig.toGitSCM());
                break;
        }
    }

    log.debug("Events size: %d, SCMs size: %d", job, events.size(), scms.size());

    for (SCM scm : scms) {
        if (scm.getClass().isAssignableFrom(NullSCM.class)) {
            log.debug("NullSCM detected, continue match next SCM", job);
            continue;
        }

        for (Event event : events) {
            log.debug("Matching event %s with SCM %s", event, scm.getKey());
            if (this.matches(event, scm)) {
                log.debug("Hurray! Event %s matched SCM %s", job, event.getArn(), scm.getKey());
                return true;
            }
        }
    }

    log.debug("No event matched", job);
    return false;
}