hudson.scm.NullSCM Java Examples

The following examples show how to use hudson.scm.NullSCM. 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: ScmInternalSubscriptionIT.java    From aws-codecommit-trigger-plugin with Apache License 2.0 5 votes vote down vote up
@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)
        }
    });
}
 
Example #2
Source File: AbstractFreestyleTestProject.java    From aws-codecommit-trigger-plugin with Apache License 2.0 5 votes vote down vote up
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);
    }
 
Example #3
Source File: TemplateStaplerRequestWrapper.java    From multi-branch-project-plugin with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example #4
Source File: TemplateDrivenMultiBranchProject.java    From multi-branch-project-plugin with MIT License 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #5
Source File: ScmJobEventTriggerMatcher.java    From aws-codecommit-trigger-plugin with Apache License 2.0 4 votes vote down vote up
@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;
}