Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ public ParameterValue createValue(StaplerRequest req, JSONObject formData) {
@Override
public ParameterValue getDefaultParameterValue() {
if (StringUtils.isEmpty(this.defaultValue)) {
if ( isInt(this.maxTags) && Integer.parseInt(this.maxTags) == 1 ){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite understanding the use case for this I guess, but:
It seems intuitively wrong to me that we would automatically select something, just because the default value is empty.
That would IMHO violate the principle of the least surprise for the user.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Kutzi,
Yes I know this was a poor solution, but due to my limited knowledge of how to implement an GUI option, I made this way.

I put on Jira (https://issues.jenkins-ci.org/browse/JENKINS-14155), asking for help a while ago on implementing the GUI option.

return new ListSubversionTagsParameterValue(getName(), getTagsDir(), this.getTags().get(0));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if getTags() returns an empty list here (IndexOutOfBoundException)? Can that happen?

}
return null;
}
return new ListSubversionTagsParameterValue(getName(), getTagsDir(), this.defaultValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,40 @@ public void handleDirEntry(SVNDirEntry dirEntry) throws SVNException {
}
});
}


/**
* Make sure we are giving the tag matched when default empty and maxTags is 1.
*/
@Bug(14155)
public void testDefaultFromTags() throws Exception {
Proc p = runSvnServe(getClass().getResource("JENKINS-14155.zip"));
try {
ListSubversionTagsParameterDefinition def = new ListSubversionTagsParameterDefinition("FOO", "svn://localhost/tags/"
, "(.*)" // tagsFilter
, "" // defaultValue => Needs to be empty
, "1" // maxTags => Needs to set to one
, true // reverseByDate, so we will get the most recent item
, false
, null);
List<String> tags = def.getTags();
List<String> expected = Arrays.asList("d");

if (!expected.equals(tags)) {
// retry. Maybe the svnserve just didn't start up correctly, yet
System.out.println("First attempt failed. Retrying.");
Thread.sleep(300L);
tags = def.getTags();
if (!expected.equals(tags)) {
dumpRepositoryContents();

Assert.fail("Expected " + expected + ", but got " + tags);
}
}

} finally {
p.kill();
}

}
}
Binary file not shown.