Skip to content

Commit 6097f6a

Browse files
committed
LibraryConfiguration and tests: rename traceBRANCH_NAME to more generic and camel-cased traceDefaultedVersion [JENKINS-69731]
1 parent 6d74aea commit 6097f6a

File tree

5 files changed

+27
-26
lines changed

5 files changed

+27
-26
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,11 @@ public class LibraryConfiguration extends AbstractDescribableImpl<LibraryConfigu
7474
private boolean allowBRANCH_NAME = false;
7575
private boolean allowBRANCH_NAME_PR = false;
7676
// Print defaultedVersion() progress resolving BRANCH_NAME
77-
// to a build console log. This is exposed as UI checkbox
78-
// for deployment troubleshooting, but is primarily intended
79-
// for programmatic consumption e.g. in unit-tests.
80-
private boolean traceBRANCH_NAME = false;
77+
// or env.VARNAME patterns to a build console log. This is
78+
// exposed as UI checkbox for deployment troubleshooting,
79+
// but is primarily intended for programmatic consumption
80+
// e.g. in unit-tests.
81+
private boolean traceDefaultedVersion = false;
8182
private boolean includeInChangesets = true;
8283
private LibraryCachingConfiguration cachingConfiguration = null;
8384

@@ -161,12 +162,12 @@ public boolean isAllowBRANCH_NAME() {
161162
this.allowBRANCH_NAME = allowBRANCH_NAME;
162163
}
163164

164-
public boolean isTraceBRANCH_NAME() {
165-
return traceBRANCH_NAME;
165+
public boolean isTraceDefaultedVersion() {
166+
return traceDefaultedVersion;
166167
}
167168

168-
@DataBoundSetter public void setTraceBRANCH_NAME(boolean traceBRANCH_NAME) {
169-
this.traceBRANCH_NAME = traceBRANCH_NAME;
169+
@DataBoundSetter public void setTraceDefaultedVersion(boolean traceDefaultedVersion) {
170+
this.traceDefaultedVersion = traceDefaultedVersion;
170171
}
171172

172173
public boolean isAllowBRANCH_NAME_PR() {
@@ -468,7 +469,7 @@ private String defaultedVersionSCM(@NonNull Run<?, ?> run, @NonNull TaskListener
468469

469470
@NonNull String defaultedVersion(@CheckForNull String version, Run<?, ?> run, TaskListener listener) throws AbortException {
470471
PrintStream logger = null;
471-
if (traceBRANCH_NAME && listener != null) {
472+
if (traceDefaultedVersion && listener != null) {
472473
logger = listener.getLogger();
473474
}
474475
if (logger != null) {

src/main/resources/org/jenkinsci/plugins/workflow/libs/LibraryConfiguration/config.jelly

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ THE SOFTWARE.
4646
<f:entry field="allowBRANCH_NAME_PR" title="${%If you allow literal use of @Library 'libname@${BRANCH_NAME}' above, you can also allow fallback to CHANGE_BRANCH and/or CHANGE_TARGET for pull request builds}">
4747
<f:checkbox default="false"/>
4848
</f:entry>
49-
<f:entry field="traceBRANCH_NAME" title="${%Request tracing of 'libname@${BRANCH_NAME}' resolution into build log}">
49+
<f:entry field="traceDefaultedVersion" title="${%Request tracing of 'libname@${BRANCH_NAME}' resolution into build log}">
5050
<f:checkbox default="false"/>
5151
</f:entry>
5252
<f:entry field="includeInChangesets" title="${%Include @Library changes in job recent changes}">

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ public class LibraryConfigurationTest {
153153
LibraryConfiguration cfg = new LibraryConfiguration(libraryName, new SCMRetriever(new GitSCM("https://phony.jenkins.io/bar.git")));
154154
cfg.setAllowVersionOverride(true);
155155
cfg.setAllowBRANCH_NAME(false);
156-
cfg.setTraceBRANCH_NAME(true);
156+
cfg.setTraceDefaultedVersion(true);
157157

158158
assertEquals(true, cfg.isAllowVersionOverride());
159159
assertEquals(false, cfg.isAllowBRANCH_NAME());
160-
assertEquals(true, cfg.isTraceBRANCH_NAME());
160+
assertEquals(true, cfg.isTraceDefaultedVersion());
161161
assertThrows(AbortException.class, () -> cfg.defaultedVersion("${BRANCH_NAME}"));
162162
/* This SHOULD NOT return a version string that literally remains '${BRANCH_NAME}'! */
163163
}
@@ -170,7 +170,7 @@ public class LibraryConfigurationTest {
170170
LibraryConfiguration cfg = new LibraryConfiguration(libraryName, new SCMRetriever(new GitSCM("https://phony.jenkins.io/bar.git")));
171171
cfg.setDefaultVersion(defaultVersion);
172172
cfg.setAllowBRANCH_NAME(true);
173-
cfg.setTraceBRANCH_NAME(true);
173+
cfg.setTraceDefaultedVersion(true);
174174

175175
assertEquals(true, cfg.isAllowBRANCH_NAME());
176176
try {
@@ -186,7 +186,7 @@ public class LibraryConfigurationTest {
186186

187187
LibraryConfiguration cfg = new LibraryConfiguration(libraryName, new SCMRetriever(new GitSCM("https://phony.jenkins.io/bar.git")));
188188
cfg.setAllowBRANCH_NAME(true);
189-
cfg.setTraceBRANCH_NAME(true);
189+
cfg.setTraceDefaultedVersion(true);
190190

191191
assertEquals(true, cfg.isAllowBRANCH_NAME());
192192
assertThrows(AbortException.class, () -> cfg.defaultedVersion("${BRANCH_NAME}", null, null));

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ public class SCMSourceRetrieverTest {
250250
lc.setDefaultVersion("master");
251251
lc.setIncludeInChangesets(false);
252252
lc.setAllowBRANCH_NAME(true);
253-
lc.setTraceBRANCH_NAME(true);
253+
lc.setTraceDefaultedVersion(true);
254254
GlobalLibraries.get().setLibraries(Collections.singletonList(lc));
255255

256256
// Basename "libname" notation => use specified default branch
@@ -308,7 +308,7 @@ public class SCMSourceRetrieverTest {
308308
lc.setIncludeInChangesets(false);
309309
lc.setAllowVersionOverride(true);
310310
lc.setAllowBRANCH_NAME(true);
311-
lc.setTraceBRANCH_NAME(true);
311+
lc.setTraceDefaultedVersion(true);
312312

313313
sampleRepo2.init();
314314
sampleRepo2.write("vars/myecho2.groovy", "def call() {echo 'something weird'}");
@@ -324,7 +324,7 @@ public class SCMSourceRetrieverTest {
324324
lc2.setIncludeInChangesets(false);
325325
lc2.setAllowVersionOverride(true);
326326
lc2.setAllowBRANCH_NAME(true);
327-
lc2.setTraceBRANCH_NAME(true);
327+
lc2.setTraceDefaultedVersion(true);
328328

329329
// Configure two libs to make a mess :)
330330
GlobalLibraries.get().setLibraries(Arrays.asList(lc, lc2));
@@ -374,7 +374,7 @@ public class SCMSourceRetrieverTest {
374374
lc.setDefaultVersion("master");
375375
lc.setIncludeInChangesets(false);
376376
lc.setAllowBRANCH_NAME(true);
377-
lc.setTraceBRANCH_NAME(true);
377+
lc.setTraceDefaultedVersion(true);
378378
GlobalLibraries.get().setLibraries(Collections.singletonList(lc));
379379

380380
// Inspired in part by tests like
@@ -445,7 +445,7 @@ public class SCMSourceRetrieverTest {
445445
lc.setIncludeInChangesets(false);
446446
lc.setAllowVersionOverride(true);
447447
lc.setAllowBRANCH_NAME(false);
448-
lc.setTraceBRANCH_NAME(true);
448+
lc.setTraceDefaultedVersion(true);
449449
GlobalLibraries.get().setLibraries(Collections.singletonList(lc));
450450

451451
// Inspired in part by tests like
@@ -522,7 +522,7 @@ public class SCMSourceRetrieverTest {
522522
lc.setIncludeInChangesets(false);
523523
lc.setAllowVersionOverride(true);
524524
lc.setAllowBRANCH_NAME(false);
525-
lc.setTraceBRANCH_NAME(true);
525+
lc.setTraceDefaultedVersion(true);
526526
GlobalLibraries.get().setLibraries(Collections.singletonList(lc));
527527

528528
// Inspired in part by tests like
@@ -596,7 +596,7 @@ public class SCMSourceRetrieverTest {
596596
lc.setIncludeInChangesets(false);
597597
lc.setAllowVersionOverride(true);
598598
lc.setAllowBRANCH_NAME(false);
599-
lc.setTraceBRANCH_NAME(true);
599+
lc.setTraceDefaultedVersion(true);
600600
GlobalLibraries.get().setLibraries(Collections.singletonList(lc));
601601

602602
// Inspired in part by tests like
@@ -685,7 +685,7 @@ public class SCMSourceRetrieverTest {
685685
lc.setIncludeInChangesets(false);
686686
lc.setAllowVersionOverride(true);
687687
lc.setAllowBRANCH_NAME(false);
688-
lc.setTraceBRANCH_NAME(true);
688+
lc.setTraceDefaultedVersion(true);
689689
GlobalLibraries.get().setLibraries(Collections.singletonList(lc));
690690

691691
// Inspired in part by tests like
@@ -765,7 +765,7 @@ public class SCMSourceRetrieverTest {
765765
lc.setIncludeInChangesets(false);
766766
lc.setAllowVersionOverride(true);
767767
lc.setAllowBRANCH_NAME(false);
768-
lc.setTraceBRANCH_NAME(true);
768+
lc.setTraceDefaultedVersion(true);
769769
GlobalLibraries.get().setLibraries(Collections.singletonList(lc));
770770

771771
// Inspired in part by tests like
@@ -823,7 +823,7 @@ public class SCMSourceRetrieverTest {
823823
lc.setIncludeInChangesets(false);
824824
lc.setAllowVersionOverride(false);
825825
lc.setAllowBRANCH_NAME(true);
826-
lc.setTraceBRANCH_NAME(true);
826+
lc.setTraceDefaultedVersion(true);
827827
GlobalLibraries.get().setLibraries(Collections.singletonList(lc));
828828

829829
// Inspired in part by tests like
@@ -882,7 +882,7 @@ public class SCMSourceRetrieverTest {
882882
lc.setIncludeInChangesets(false);
883883
lc.setAllowVersionOverride(false);
884884
lc.setAllowBRANCH_NAME(true);
885-
lc.setTraceBRANCH_NAME(true);
885+
lc.setTraceDefaultedVersion(true);
886886
GlobalLibraries.get().setLibraries(Collections.singletonList(lc));
887887

888888
// Inspired in part by tests like
@@ -955,7 +955,7 @@ public class SCMSourceRetrieverTest {
955955
lc.setIncludeInChangesets(false);
956956
lc.setAllowVersionOverride(true);
957957
lc.setAllowVersionEnvvar(true);
958-
lc.setTraceBRANCH_NAME(true);
958+
lc.setTraceDefaultedVersion(true);
959959
GlobalLibraries.get().setLibraries(Collections.singletonList(lc));
960960

961961
// TEST_VAR_NAME for job not set - fall back to default

0 commit comments

Comments
 (0)