-
Notifications
You must be signed in to change notification settings - Fork 268
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-14155]Use the lastest changed tag as default #157
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -98,29 +98,31 @@ public class ListSubversionTagsParameterDefinition extends ParameterDefinition { | |
private final boolean reverseByDate; | ||
private final boolean reverseByName; | ||
private final String defaultValue; | ||
private final boolean useLatestTag; | ||
private final String maxTags; | ||
private static final String SVN_BRANCHES = "branches"; | ||
private static final String SVN_TAGS = "tags"; | ||
private static final String SVN_TRUNK = "trunk"; | ||
|
||
@Deprecated | ||
public ListSubversionTagsParameterDefinition(String name, String tagsDir, String tagsFilter, String defaultValue, String maxTags, boolean reverseByDate, boolean reverseByName, String uuid) { | ||
this(name, tagsDir, null, tagsFilter, defaultValue, maxTags, reverseByDate, reverseByName); | ||
public ListSubversionTagsParameterDefinition(String name, String tagsDir, String tagsFilter, String defaultValue, boolean useLatestTag, String maxTags, boolean reverseByDate, boolean reverseByName, String uuid) { | ||
this(name, tagsDir, null, tagsFilter, defaultValue, useLatestTag, maxTags, reverseByDate, reverseByName); | ||
} | ||
|
||
@Deprecated | ||
public ListSubversionTagsParameterDefinition(String name, String tagsDir, String tagsFilter, String defaultValue, String maxTags, boolean reverseByDate, boolean reverseByName, String uuid, String credentialsId) { | ||
this(name, tagsDir, credentialsId, tagsFilter, defaultValue, maxTags, reverseByDate, reverseByName); | ||
public ListSubversionTagsParameterDefinition(String name, String tagsDir, String tagsFilter, String defaultValue, boolean useLatestTag, String maxTags, boolean reverseByDate, boolean reverseByName, String uuid, String credentialsId) { | ||
this(name, tagsDir, credentialsId, tagsFilter, defaultValue, useLatestTag, maxTags, reverseByDate, reverseByName); | ||
} | ||
|
||
@DataBoundConstructor | ||
public ListSubversionTagsParameterDefinition(String name, String tagsDir, String credentialsId, String tagsFilter, String defaultValue, String maxTags, boolean reverseByDate, boolean reverseByName) { | ||
public ListSubversionTagsParameterDefinition(String name, String tagsDir, String credentialsId, String tagsFilter, String defaultValue, boolean useLatestTag, String maxTags, boolean reverseByDate, boolean reverseByName) { | ||
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. I dunno exactly the guideline for this plugin, but from my PoV it's better to use |
||
super(name, ResourceBundleHolder.get(ListSubversionTagsParameterDefinition.class).format("TagDescription")); | ||
this.tagsDir = Util.removeTrailingSlash(tagsDir); | ||
this.tagsFilter = tagsFilter; | ||
this.reverseByDate = reverseByDate; | ||
this.reverseByName = reverseByName; | ||
this.defaultValue = defaultValue; | ||
this.useLatestTag = useLatestTag; | ||
this.maxTags = maxTags; | ||
this.credentialsId = credentialsId; | ||
} | ||
|
@@ -158,7 +160,13 @@ public ParameterValue createValue(CLICommand command, String value) throws IOExc | |
|
||
@Override | ||
public ParameterValue getDefaultParameterValue() { | ||
if (StringUtils.isEmpty(this.defaultValue)) { | ||
if (isUseLatestTag()) { | ||
List<String> tags = getTags(null, "tags", true); | ||
if (tags.size() > 0) { | ||
return new ListSubversionTagsParameterValue(getName(), getTagsDir() + "/tags", tags.get(0)); | ||
} | ||
return null; | ||
} else if (StringUtils.isEmpty(this.defaultValue)) { | ||
List<String> tags = getTags(null); | ||
if (tags.size() > 0) { | ||
return new ListSubversionTagsParameterValue(getName(), getTagsDir(), tags.get(0)); | ||
|
@@ -173,6 +181,10 @@ public DescriptorImpl getDescriptor() { | |
return (DescriptorImpl) super.getDescriptor(); | ||
} | ||
|
||
@Nonnull public List<String> getTags(@Nullable Job context) { | ||
return getTags(context, "", isReverseByDate()); | ||
} | ||
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. 👍 to think about compatibility |
||
|
||
/** | ||
* Returns a list of Subversion dirs to be displayed in | ||
* {@code ListSubversionTagsParameterDefinition/index.jelly}. | ||
|
@@ -183,34 +195,35 @@ public DescriptorImpl getDescriptor() { | |
* <p>This method never returns {@code null}. In case an error happens, the | ||
* returned list contains an error message prefixed by {@code !}.</p> | ||
*/ | ||
@Nonnull public List<String> getTags(@Nullable Job context) { | ||
@Nonnull public List<String> getTags(@Nullable Job context, String subDir, boolean localReverseByDate) { | ||
List<String> dirs = new ArrayList<String>(); | ||
|
||
SVNRepository repo = null; | ||
SVNClientManager clientManager = null; | ||
String tmpTagsDir = StringUtils.isEmpty(subDir) ? getTagsDir() : getTagsDir() + "/" + subDir; | ||
try { | ||
ISVNAuthenticationProvider authProvider = CredentialsSVNAuthenticationProviderImpl.createAuthenticationProvider( | ||
context, getTagsDir(), getCredentialsId(), null, TaskListener.NULL | ||
context, tmpTagsDir, getCredentialsId(), null, TaskListener.NULL | ||
); | ||
ISVNAuthenticationManager authManager = SubversionSCM.createSvnAuthenticationManager(authProvider); | ||
SVNURL repoURL = SVNURL.parseURIDecoded(getTagsDir()); | ||
SVNURL repoURL = SVNURL.parseURIDecoded(tmpTagsDir); | ||
|
||
repo = SVNRepositoryFactory.create(repoURL); | ||
repo.setAuthenticationManager(authManager); | ||
clientManager = SVNClientManager.newInstance(null,authManager); | ||
SVNLogClient logClient = clientManager.getLogClient(); | ||
|
||
if (isSVNRepositoryProjectRoot(repo)) { | ||
dirs = this.getSVNRootRepoDirectories(logClient, repoURL); | ||
dirs = this.getSVNRootRepoDirectories(logClient, repoURL, localReverseByDate); | ||
} else { | ||
SimpleSVNDirEntryHandler dirEntryHandler = new SimpleSVNDirEntryHandler(tagsFilter); | ||
logClient.doList(repoURL, SVNRevision.HEAD, SVNRevision.HEAD, false, SVNDepth.IMMEDIATES, SVNDirEntry.DIRENT_TIME, dirEntryHandler); | ||
dirs = dirEntryHandler.getDirs(isReverseByDate(), isReverseByName()); | ||
dirs = dirEntryHandler.getDirs(localReverseByDate, isReverseByName()); | ||
} | ||
} | ||
catch(SVNException e) { | ||
// logs are not translated (IMO, this is a bad idea to translate logs) | ||
LOGGER.log(Level.SEVERE, "An SVN exception occurred while listing the directory entries at " + getTagsDir(), e); | ||
LOGGER.log(Level.SEVERE, "An SVN exception occurred while listing the directory entries at " + tmpTagsDir, e); | ||
return Collections.singletonList("!" + ResourceBundleHolder.get(ListSubversionTagsParameterDefinition.class).format("SVNException")); | ||
} finally { | ||
if (repo != null) { | ||
|
@@ -261,6 +274,10 @@ public String getMaxTags() { | |
return maxTags; | ||
} | ||
|
||
public boolean isUseLatestTag() { | ||
return useLatestTag; | ||
} | ||
|
||
/** | ||
* Checks to see if given repository contains a trunk, branches, and tags | ||
* directories. | ||
|
@@ -314,20 +331,20 @@ private boolean isInt(String value) { | |
* @return List of directories. | ||
* @throws SVNException | ||
*/ | ||
private List<String> getSVNRootRepoDirectories(SVNLogClient logClient, SVNURL repoURL) throws SVNException { | ||
private List<String> getSVNRootRepoDirectories(SVNLogClient logClient, SVNURL repoURL, boolean localReverseByDate) throws SVNException { | ||
// Get the branches repository contents | ||
SVNURL branchesRepo = repoURL.appendPath(SVN_BRANCHES, true); | ||
SimpleSVNDirEntryHandler branchesEntryHandler = new SimpleSVNDirEntryHandler(null); | ||
logClient.doList(branchesRepo, SVNRevision.HEAD, SVNRevision.HEAD, false, SVNDepth.IMMEDIATES, SVNDirEntry.DIRENT_ALL, branchesEntryHandler); | ||
List<String> branches = branchesEntryHandler.getDirs(isReverseByDate(), isReverseByName()); | ||
List<String> branches = branchesEntryHandler.getDirs(localReverseByDate, isReverseByName()); | ||
branches.remove(""); | ||
appendTargetDir(SVN_BRANCHES, branches); | ||
|
||
// Get the tags repository contents | ||
SVNURL tagsRepo = repoURL.appendPath(SVN_TAGS, true); | ||
SimpleSVNDirEntryHandler tagsEntryHandler = new SimpleSVNDirEntryHandler(null); | ||
logClient.doList(tagsRepo, SVNRevision.HEAD, SVNRevision.HEAD, false, SVNDepth.IMMEDIATES, SVNDirEntry.DIRENT_ALL, tagsEntryHandler); | ||
List<String> tags = tagsEntryHandler.getDirs(isReverseByDate(), isReverseByName()); | ||
List<String> tags = tagsEntryHandler.getDirs(localReverseByDate, isReverseByName()); | ||
tags.remove(""); | ||
appendTargetDir(SVN_TAGS, tags); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<!-- | ||
- The MIT License | ||
- | ||
- Copyright (c) 2011, Manufacture Francaise des Pneumatiques Michelin, Romain Seguy | ||
- | ||
- 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. | ||
--> | ||
|
||
<div> | ||
Check this option so that the latest tag in the tags/ subdirectory is used as default value. | ||
|
||
<p> | ||
If this option is checked, the <b>Default value</b> one won't be taken into | ||
account. | ||
</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.
Those additions will result in breaking the binary compatibility. Is it required to pass by the constructor ? I think a simple use of a setter / putting a default value would be sufficient.