-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[JENKINS-69135] Add a "Versions to include" field to the Global Library Cache feature #16
Changes from 9 commits
f2ae5b7
f29d6cd
433d676
006be8f
e2f1c6d
a0d1dfe
e5374aa
e0a2432
b1b6712
884f777
4d79950
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,16 +29,19 @@ public final class LibraryCachingConfiguration extends AbstractDescribableImpl<L | |
|
||
private int refreshTimeMinutes; | ||
private String excludedVersionsStr; | ||
private String includedVersionsStr; | ||
|
||
private static final String VERSIONS_SEPARATOR = " "; | ||
public static final String GLOBAL_LIBRARIES_DIR = "global-libraries-cache"; | ||
public static final String LAST_READ_FILE = "last_read"; | ||
|
||
@DataBoundConstructor public LibraryCachingConfiguration(int refreshTimeMinutes, String excludedVersionsStr) { | ||
@DataBoundConstructor public LibraryCachingConfiguration(int refreshTimeMinutes, String excludedVersionsStr, String includedVersionsStr) { | ||
this.refreshTimeMinutes = refreshTimeMinutes; | ||
this.excludedVersionsStr = excludedVersionsStr; | ||
this.includedVersionsStr = includedVersionsStr; | ||
} | ||
|
||
|
||
public int getRefreshTimeMinutes() { | ||
return refreshTimeMinutes; | ||
} | ||
|
@@ -54,6 +57,13 @@ public Boolean isRefreshEnabled() { | |
public String getExcludedVersionsStr() { | ||
return excludedVersionsStr; | ||
} | ||
public String getIncludedVersionsStr() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we want a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There isn't any such annotations on the other one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair point, you can disregard my comment :) |
||
if(StringUtils.isBlank(includedVersionsStr)){ | ||
return null; | ||
} | ||
return includedVersionsStr; | ||
} | ||
|
||
|
||
private List<String> getExcludedVersions() { | ||
if (excludedVersionsStr == null) { | ||
|
@@ -62,6 +72,13 @@ private List<String> getExcludedVersions() { | |
return Arrays.asList(excludedVersionsStr.split(VERSIONS_SEPARATOR)); | ||
} | ||
|
||
private List<String> getIncludedVersions() { | ||
if (includedVersionsStr == null) { | ||
return Collections.emptyList(); | ||
} | ||
return Arrays.asList(includedVersionsStr.split(VERSIONS_SEPARATOR)); | ||
} | ||
|
||
public Boolean isExcluded(String version) { | ||
// exit early if the version passed in is null or empty | ||
if (StringUtils.isBlank(version)) { | ||
|
@@ -78,6 +95,22 @@ public Boolean isExcluded(String version) { | |
return false; | ||
} | ||
|
||
public Boolean isIncluded(String version) { | ||
// exit early if the version passed in is null or empty | ||
if (StringUtils.isBlank(version)) { | ||
return false; | ||
} | ||
for (String it : getIncludedVersions()) { | ||
// works on empty or null included versions | ||
// and if the version contains the inclusion thus it can be | ||
// anywhere in the string. | ||
if (StringUtils.isNotBlank(it) && version.contains(it)){ | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
@Override public String toString() { | ||
return "LibraryCachingConfiguration{refreshTimeMinutes=" + refreshTimeMinutes + ", excludedVersions=" | ||
+ excludedVersionsStr + '}'; | ||
|
@@ -129,6 +162,5 @@ public FormValidation doClearCache(@QueryParameter String name, @QueryParameter | |
} | ||
return FormValidation.ok("The cache dir was deleted successfully."); | ||
} | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<div> | ||
Space separated list of versions to include to allow caching via substring search using .contains() method. Ex: "release/ master". | ||
</div> | ||
<div> | ||
Note: Excluded versions will always take precedence over included versions | ||
</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To keep backwards binary compatibility the old constructor signature should be kept and
@Deprecated
and call the new constructor with default values.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe even a better approach would be to instead just add a
@DataboundSetter
for the new field, so that it signals that it is optional and doesn't need to be provided unless needed.