Skip to content

Commit

Permalink
Refactoring to resolve warnings, add comments, and clarify code.
Browse files Browse the repository at this point in the history
Modified SurroundStep to assist the Snippet Generator in creating a properly formatted Pipeline command.
Renamed the SurroundStep's "sscm_url" parameter to simply "url"
Changed the Help text to match what I put in the design document.
  • Loading branch information
pvince committed Nov 23, 2016
1 parent 5026866 commit 2e6b1a5
Show file tree
Hide file tree
Showing 10 changed files with 429 additions and 331 deletions.
665 changes: 371 additions & 294 deletions src/main/java/hudson/scm/SurroundSCM.java

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions src/main/java/hudson/scm/SurroundSCMRevisionState.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package hudson.scm;

import hudson.scm.SCMRevisionState;


import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public final class SurroundSCMRevisionState extends SCMRevisionState {

Expand Down
60 changes: 46 additions & 14 deletions src/main/java/hudson/scm/SurroundStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,68 +16,99 @@
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.export.Exported;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* Runs Surround SCM using {@link SurroundSCM}
*/
public class SurroundStep extends SCMStep {
private final String sscm_url;
private final String url;
private final String credentialsId;
private RSAKey rsaKey;

@DataBoundConstructor
public SurroundStep(String sscm_url, String credentialsId)
public SurroundStep(String url, String credentialsId)
{
this.sscm_url = Util.fixEmptyAndTrim(sscm_url);
url = Util.fixEmptyAndTrim(url);
try {
url = URLDecoder.decode(url, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
this.url = url;
this.credentialsId = Util.fixEmptyAndTrim(credentialsId);

}

@DataBoundSetter
public void setRsaKeyFileId(String rsaKeyFileId) {
this.rsaKey = new RSAKey(RSAKey.Type.ID, rsaKeyFileId);
}

@DataBoundSetter
public void setRsaKeyFilePath(String rsaKeyFilePath) {
this.rsaKey = new RSAKey(RSAKey.Type.Path, rsaKeyFilePath);
}

@DataBoundSetter
public void setRsaKey(RSAKey rsaKey) { this.rsaKey = rsaKey; }

@Nonnull
@Override
protected SCM createSCM() {
String server = SSCMUtils.getServerFromURL(sscm_url);
String port = SSCMUtils.getPortFromURL(sscm_url);
String branch = SSCMUtils.getBranchFromURL(sscm_url);
String repository = SSCMUtils.getRepositoryFromURL(sscm_url);
String server = SSCMUtils.getServerFromURL(url);
String port = SSCMUtils.getPortFromURL(url);
String branch = SSCMUtils.getBranchFromURL(url);
String repository = SSCMUtils.getRepositoryFromURL(url);

SurroundSCM sscm = new SurroundSCM(server, port, branch, repository, credentialsId);
sscm.setRsaKey(rsaKey);
return sscm;
}

@Exported
public boolean hasRsaKeyConfigured() {
return rsaKey == null || rsaKey.getRsaKeyType() != RSAKey.Type.NoKey;
}

@Exported
public boolean isUsingRsaKeyPath() {
return rsaKey != null && rsaKey.getRsaKeyType() == RSAKey.Type.Path;
}

@Exported
public boolean isUsingRsaKeyFileId() {
return rsaKey != null && rsaKey.getRsaKeyType() == RSAKey.Type.ID;
}

public String getSscm_url() {
return sscm_url;
@Exported
public String getUrl() {
return url;
}

@Exported
public String getCredentialsId() {
return credentialsId;
}

/**
* So... the RSA key combobox requires we use an RSAKey object, however forcing users to define an RSA key object
* for pipelines is annoying as hell.
* @return Always returns null to prevent this from showing up in the Snippet Generator
*/
@Exported
public RSAKey getRsaKey() {
return rsaKey;
return null;
}

@Exported
public String getRsaKeyFilePath()
{
String result = null;
Expand All @@ -88,6 +119,7 @@ public String getRsaKeyFilePath()
return result;
}

@Exported
public String getRsaKeyFileId() {
String result = null;
if(rsaKey != null && rsaKey.getRsaKeyType() == RSAKey.Type.ID) {
Expand All @@ -100,8 +132,8 @@ public String getRsaKeyFileId() {
// TODO: Somehow make this a shared function between SurroundSCM and SurroundStep
@CheckForNull
public StandardUsernameCredentials getCredentials(Job<?,?> owner, EnvVars env) {
String server = SSCMUtils.getServerFromURL(sscm_url);
String port = SSCMUtils.getPortFromURL(sscm_url);
String server = SSCMUtils.getServerFromURL(url);
String port = SSCMUtils.getPortFromURL(url);

if(credentialsId != null) {
for (StandardUsernameCredentials c : SurroundSCM.availableCredentials(owner, env.expand("sscm://" + server + ":" + port))) { // TODO: This seems like a royal hack.
Expand All @@ -116,8 +148,8 @@ public StandardUsernameCredentials getCredentials(Job<?,?> owner, EnvVars env) {
// TODO: Somehow make this a shared function between SurroundSCM and SurroundStep
@CheckForNull
public FileCredentials getFileCredentials(Job<?,?> owner, EnvVars env) {
String server = SSCMUtils.getServerFromURL(sscm_url);
String port = SSCMUtils.getPortFromURL(sscm_url);
String server = SSCMUtils.getServerFromURL(url);
String port = SSCMUtils.getPortFromURL(url);

if(rsaKey != null && rsaKey.getRsaKeyType() == RSAKey.Type.ID) {
for(FileCredentials fc : SurroundSCM.availableFileCredentials(owner, env.expand(String.format("sscm://%s:%s", server, port)))) { // TODO: This seems like a royal hack
Expand Down
12 changes: 3 additions & 9 deletions src/main/java/hudson/scm/config/RSAKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ public void setRsaKeyFileId(String rsaKeyFileId) {
* This solely exists to fix the stupid Snippet Generator from crashing when asking about this function.
*/
@Exported
public String getRsaKeyFileId() {
return null;
}
public String getRsaKeyFileId() { return null; }

@DataBoundSetter
public void setRsaKeyFilePath(String rsaKeyFilePath) {
Expand All @@ -64,9 +62,7 @@ public void setRsaKeyFilePath(String rsaKeyFilePath) {
* This solely exists to fix the stupid Snippet Generator from crashing when asking about this function.
*/
@Exported
public String getRsaKeyFilePath() {
return null;
}
public String getRsaKeyFilePath() { return null; }

@DataBoundSetter
public void setRsaKeyValue(String rsaKeyValue) { this.rsaKeyValue = rsaKeyValue; }
Expand All @@ -80,8 +76,6 @@ public String getRsaKeyFilePath() {
@Extension
public static class DescriptorImpl extends Descriptor<RSAKey> {
@Override
public String getDisplayName() {
return "RSA Key";
}
public String getDisplayName() { return "RSA Key"; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
Enter the full path the Surround SCM connection RSA key file. Ex: C:\SurroundRSAKeyFile.xml
</div>

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/resources/hudson/scm/SurroundStep/config.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:f="/lib/form" xmlns:c="/lib/credentials">
<f:entry field="sscm_url" title="Repository URL">
<f:entry field="url" title="Repository URL">
<f:textbox/>
</f:entry>
<f:entry title="${%Credentials}" field="credentialsId">
<c:select />
</f:entry>

<f:dropdownList name="rsaKey" title="${%Use RSA key file}">
<f:dropdownListBlock title="${%- None -}" value="0" selected="${!instance.hasRsaKeyConfigured()}" />
<f:dropdownListBlock title="${%- none -}" value="0" selected="${!instance.hasRsaKeyConfigured()}" />
<f:dropdownListBlock title="${%Path to RSA key file}" value="2" selected="${instance.isUsingRsaKeyPath()}">
<f:entry field="rsaKeyFilePath">
<f:textbox />
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
Enter the full path the Surround SCM connection RSA key file. Ex: C:\SurroundRSAKeyFile.xml
</div>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div>
Surround SCM sscm:// URL to the repository you want to retrieve. <br />
Enter the Surround SCM sscm:// URL to the repository you want to retrieve. <br />
Ex: sscm://ServerAddress:4900//BranchName//Mainline/Path/To/Repository
</div>

0 comments on commit 2e6b1a5

Please sign in to comment.