Skip to content

Commit e2fef0e

Browse files
authored
Merge pull request #215 from jglick/SCMSource.id
Predictable `Snippetizer` output for `LibraryStep`
2 parents 947a7bc + 7f7ba37 commit e2fef0e

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@
7979
<scope>import</scope>
8080
<type>pom</type>
8181
</dependency>
82+
<!-- TODO until in BOM -->
83+
<dependency>
84+
<groupId>org.jenkins-ci.plugins</groupId>
85+
<artifactId>structs</artifactId>
86+
<version>362.va_b_695ef4fdf9</version>
87+
</dependency>
8288
</dependencies>
8389
</dependencyManagement>
8490
<dependencies>

src/main/java/org/jenkinsci/plugins/workflow/libs/SCMSourceRetriever.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
import java.io.StringWriter;
4040
import java.util.ArrayList;
4141
import java.util.Collection;
42-
import java.util.HashMap;
42+
import java.util.LinkedHashMap;
4343
import java.util.List;
4444
import java.util.Map;
4545
import jenkins.scm.api.SCMRevision;
@@ -121,13 +121,13 @@ public Collection<SCMSourceDescriptor> getSCMDescriptors() {
121121
return descriptors;
122122
}
123123

124+
// TODO can be deleted after https://github.com/jenkinsci/scm-api-plugin/pull/357
124125
@Override public UninstantiatedDescribable customUninstantiate(UninstantiatedDescribable ud) {
125126
Object scm = ud.getArguments().get("scm");
126-
if (scm instanceof UninstantiatedDescribable) {
127-
UninstantiatedDescribable scmUd = (UninstantiatedDescribable) scm;
128-
Map<String, Object> scmArguments = new HashMap<>(scmUd.getArguments());
127+
if (scm instanceof UninstantiatedDescribable scmUd) {
128+
Map<String, Object> scmArguments = new LinkedHashMap<>(scmUd.getArguments());
129129
scmArguments.remove("id");
130-
Map<String, Object> retrieverArguments = new HashMap<>(ud.getArguments());
130+
Map<String, Object> retrieverArguments = new LinkedHashMap<>(ud.getArguments());
131131
retrieverArguments.put("scm", scmUd.withArguments(scmArguments));
132132
return ud.withArguments(retrieverArguments);
133133
}

src/test/java/org/jenkinsci/plugins/workflow/libs/LibraryStepTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ public class LibraryStepTest {
7878
s.setRetriever(new SCMSourceRetriever(scmSource));
7979
s.setChangelog(true);
8080
r.assertEqualDataBoundBeans(s, stepTester.configRoundTrip(s));
81-
// TODO uninstantiate works but SnippetizerTester.assertRoundTrip fails due to differing SCMSource.id values
82-
assertEquals("library identifier: 'foo@master', retriever: modernSCM(gitSource(traits: [gitBranchDiscovery()], credentialsId: '', remote: 'https://nowhere.net/'))", Snippetizer.object2Groovy(s));
81+
// TODO uninstantiate works but SnippetizerTester.assertRoundTrip fails due to differing SCMSource.id values pending https://github.com/jenkinsci/scm-api-plugin/pull/357
82+
assertEquals("library identifier: 'foo@master', retriever: modernSCM(gitSource(credentialsId: '', remote: 'https://nowhere.net/', traits: [gitBranchDiscovery()]))", Snippetizer.object2Groovy(s));
8383
s.setRetriever(new SCMRetriever(new GitSCM(Collections.singletonList(new UserRemoteConfig("https://nowhere.net/", null, null, null)),
8484
Collections.singletonList(new BranchSpec("${library.foo.version}")),
8585
null, null, Collections.<GitSCMExtension>emptyList())));

0 commit comments

Comments
 (0)