Skip to content

Commit

Permalink
[FIXED JENKINS-32768] Round-tripping SingleSCMSource did not work.
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Aug 16, 2016
1 parent ddafb21 commit 6e86e96
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 14 deletions.
25 changes: 15 additions & 10 deletions pom.xml
Expand Up @@ -29,7 +29,8 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>2.3</version>
<version>2.12</version>
<relativePath/>
</parent>

<artifactId>scm-api</artifactId>
Expand All @@ -44,7 +45,7 @@
<licenses>
<license>
<name>The MIT license</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
<url>https://opensource.org/licenses/MIT</url>
<distribution>repo</distribution>
</license>
</licenses>
Expand All @@ -57,29 +58,27 @@
</developers>

<scm>
<connection>scm:git:git://github.com/jenkinsci/scm-api-plugin.git</connection>
<developerConnection>scm:git:git@github.com:jenkinsci/scm-api-plugin.git</developerConnection>
<url>http://github.com/jenkinsci/scm-api-plugin</url>
<connection>scm:git:git://github.com/jenkinsci/${project.artifactId}-plugin.git</connection>
<developerConnection>scm:git:git@github.com:jenkinsci/${project.artifactId}-plugin.git</developerConnection>
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
<tag>HEAD</tag>
</scm>

<properties>
<!-- This should be the highest common parent of the common SCM impls, e.g. Git, SVN, Hg, etc-->
<!-- Under this criteria, using p4-plugin's version. -->
<jenkins.version>1.596.1</jenkins.version>
<jenkins.version>1.609.3</jenkins.version>
<java.level>6</java.level>
</properties>

<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>

Expand All @@ -96,6 +95,12 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>git</artifactId>
<version>2.5.3</version> <!-- 2.4.x does not work since it lacks https://github.com/jenkinsci/git-plugin/pull/402 -->
<scope>test</scope>
</dependency>
</dependencies>

</project>
8 changes: 8 additions & 0 deletions src/main/java/jenkins/scm/impl/SingleSCMSource.java
Expand Up @@ -85,6 +85,14 @@ public SingleSCMSource(String id, String name, SCM scm) {
this.scm = scm;
}

public String getName() {
return name;
}

public SCM getScm() {
return scm;
}

/**
* {@inheritDoc}
*/
Expand Down
Expand Up @@ -29,21 +29,25 @@
<f:entry title="${%Name}" field="name">
<f:textbox/>
</f:entry>
<!-- Known to work from CpsScmFlowDefinition/config.jelly: -->
<f:dropdownDescriptorSelector field="scm" title="${%Source Code Management}"/>
<!-- Presumably cribbed from /lib/hudson/project/config-scm.jelly but does not work for reasons TBD (and radio buttons take too much space anyway):
<j:set var="namePrefix" value="${h.generateId()}"/>
<f:entry title="Source Code Management">
<table width="100%">
<j:set var="scms" value="${descriptor.getSCMDescriptors(sourceOwner)}" />
<j:forEach var="descriptor" items="${scms}" varStatus="loop">
<j:set var="scmd" value="${descriptor}" /><!-- backward compatibility with <1.238 -->
<f:radioBlock name="${namePrefix}.scm" value="${loop.index}" title="${scmd.displayName}" checked="${instance.getSCM().descriptor==scmd}">
<j:set var="scmd" value="${descriptor}" /><!- - backward compatibility with <1.238 - ->
<f:radioBlock name="${namePrefix}.scm" value="${loop.index}" title="${scmd.displayName}" checked="${instance.scm.descriptor == scmd}">
<f:invisibleEntry>
<input type="hidden" name="stapler-class" value="${scmd.clazz.name}"/>
</f:invisibleEntry>
<j:set var="instance" value="${instance.getSCM().descriptor==descriptor ? instance.getSCM() : null}"/>
<j:set var="scm" value="${instance}" /><!-- backward compatibility with <1.238 -->
<j:set var="instance" value="${instance.scm.descriptor == descriptor ? instance.scm : null}"/>
<j:set var="scm" value="${instance}" /><!- - backward compatibility with <1.238 - ->
<st:include from="${scmd}" page="${scmd.configPage}"/>
</f:radioBlock>
</j:forEach>
</table>
</f:entry>
-->
</j:jelly>
77 changes: 77 additions & 0 deletions src/test/java/jenkins/scm/impl/SingleSCMSourceTest.java
@@ -0,0 +1,77 @@
/*
* The MIT License
*
* Copyright 2016 CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package jenkins.scm.impl;

import hudson.model.AbstractProject;
import hudson.plugins.git.GitSCM;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Builder;
import jenkins.scm.api.SCMSource;
import org.junit.Test;
import org.junit.Rule;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.TestExtension;
import org.kohsuke.stapler.DataBoundConstructor;

public class SingleSCMSourceTest {

@Rule
public JenkinsRule r = new JenkinsRule();

@Test
public void configRoundtrip() throws Exception {
SingleSCMSource source = new SingleSCMSource("the-id", "the-name", new GitSCM("https://nowhere.net/something.git"));
SCMSourceBuilder builder = new SCMSourceBuilder(source);
r.assertEqualDataBoundBeans(builder, r.configRoundtrip(builder));
}

public static class SCMSourceBuilder extends Builder {

public final SCMSource scm;

@DataBoundConstructor
public SCMSourceBuilder(SCMSource scm) {
this.scm = scm;
}

@TestExtension("configRoundtrip")
public static class DescriptorImpl extends BuildStepDescriptor<Builder> {

@Override
public String getDisplayName() {
return "SCMSourceBuilder";
}

@SuppressWarnings("rawtypes")
@Override
public boolean isApplicable(Class<? extends AbstractProject> jobType) {
return true;
}

}

}

}
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License
Copyright 2016 CloudBees, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
<f:dropdownDescriptorSelector field="scm" title="${SCM}"/>
</j:jelly>

0 comments on commit 6e86e96

Please sign in to comment.