Skip to content

Commit

Permalink
Merge pull request #81 from daniel-beck/JENKINS-22859
Browse files Browse the repository at this point in the history
[JENKINS-22859] Don't fail revprop validation as easily
  • Loading branch information
stephenc committed May 7, 2014
2 parents 5a2683e + 6eb865f commit 29d25bd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
48 changes: 35 additions & 13 deletions src/main/java/hudson/scm/SubversionSCM.java
Expand Up @@ -170,16 +170,7 @@
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
import org.tmatesoft.svn.core.ISVNLogEntryHandler;
import org.tmatesoft.svn.core.SVNAuthenticationException;
import org.tmatesoft.svn.core.SVNDepth;
import org.tmatesoft.svn.core.SVNDirEntry;
import org.tmatesoft.svn.core.SVNErrorCode;
import org.tmatesoft.svn.core.SVNErrorMessage;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNLogEntry;
import org.tmatesoft.svn.core.SVNNodeKind;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.*;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationProvider;
import org.tmatesoft.svn.core.auth.SVNAuthentication;
Expand Down Expand Up @@ -2428,19 +2419,34 @@ public FormValidation doCheckExcludedCommitMessages(@QueryParameter String value
*/
public FormValidation doCheckRevisionPropertiesSupported(@AncestorInPath AbstractProject context,
@QueryParameter String value,
@QueryParameter String credentialsId) throws IOException, ServletException {
String v = Util.fixNull(value).trim();
@QueryParameter String credentialsId,
@QueryParameter String excludedRevprop) throws IOException, ServletException {
String v = Util.fixNull(value).trim();
if (v.length() == 0)
return FormValidation.ok();

String revprop = Util.fixNull(excludedRevprop).trim();
if (revprop.length() == 0)
return FormValidation.ok();

// Test the connection only if we have admin permission
if (!Hudson.getInstance().hasPermission(Hudson.ADMINISTER))
return FormValidation.ok();

try {
SVNURL repoURL = SVNURL.parseURIDecoded(new EnvVars(EnvVars.masterEnvVars).expand(v));
StandardCredentials credentials = lookupCredentials(context, credentialsId, repoURL);
if (checkRepositoryPath(context,repoURL, credentials)!=SVNNodeKind.NONE)
SVNNodeKind node = null;
try {
node = checkRepositoryPath(context,repoURL, credentials);
} catch (SVNCancelException ce) {
if (isAuthenticationFailedError(ce)) {
// don't care about this here, another field's validation will show this
return FormValidation.ok();
}
throw ce;
}
if (node!=SVNNodeKind.NONE)
// something exists
return FormValidation.ok();

Expand Down Expand Up @@ -2469,6 +2475,22 @@ public FormValidation doCheckRevisionPropertiesSupported(@AncestorInPath Abstrac

}

// copied from WorkspaceUpdater:
private static boolean isAuthenticationFailedError(SVNCancelException e) {
// this is very ugly. SVNKit (1.7.4 at least) reports missing authentication data as a cancel exception
// "No credential to try. Authentication failed"
// See DefaultSVNAuthenticationManager#getFirstAuthentication
if (String.valueOf(e.getMessage()).contains("No credential to try")) {
return true;
}
Throwable cause = e.getCause();
if (cause instanceof SVNCancelException) {
return isAuthenticationFailedError((SVNCancelException) cause);
} else {
return false;
}
}

private static DescriptorImpl descriptor() {
return Jenkins.getInstance() == null ? null : Jenkins.getInstance().getDescriptorByType(DescriptorImpl.class);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/hudson/scm/SubversionSCM/config.jelly
Expand Up @@ -51,7 +51,7 @@ THE SOFTWARE.
<f:textarea />
</f:entry>
<f:entry title="${%Exclusion revprop name}" field="excludedRevprop">
<f:textbox checkUrl="'descriptorByName/hudson.scm.SubversionSCM/checkRevisionPropertiesSupported?value='+toValue(document.getElementById('svn.remote.loc'))+'&amp;credentialsId='+toValue(document.getElementById('svn.remote.cred'))"/>
<f:textbox checkUrl="'descriptorByName/hudson.scm.SubversionSCM/checkRevisionPropertiesSupported?value='+toValue(document.getElementById('svn.remote.loc'))+'&amp;credentialsId='+toValue(document.getElementById('svn.remote.cred'))+'&amp;excludedRevprop='+toValue(this)"/>
</f:entry>
<f:entry title="${%Filter changelog}" field="filterChangelog">
<f:checkbox />
Expand Down

0 comments on commit 29d25bd

Please sign in to comment.