Skip to content

Commit

Permalink
Upgraded the SurroundSCM plugin to implement the newer 'Run' based AP…
Browse files Browse the repository at this point in the history
…I vs the previous 'AbstractBuild' based API.

Added code for basic Pipeline support.
Improved parsing of the changelog file.
Added code to set the email on a changelog parsed user, assuming that the email for said user has not already been explicitly set.
  • Loading branch information
pvince committed Nov 10, 2016
1 parent 9c46a59 commit 0d73ca3
Show file tree
Hide file tree
Showing 7 changed files with 663 additions and 265 deletions.
28 changes: 27 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
~ hpi-plugin.version: The HPI Maven Plugin version used by the plugin..
~ stapler-plugin.version: The Stapler Maven plugin version required by the plugin.
-->
<workflow.version>1.14.2</workflow.version>
</properties>

<name>Seapine Surround SCM - Jenkins Plugin</name>
Expand Down Expand Up @@ -60,5 +61,30 @@
<url>http://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>


<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>scm-api</artifactId>
<version>1.3</version>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-scm-step</artifactId>
<version>${workflow.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>mailer</artifactId>
<version>1.16</version>
</dependency>
</dependencies>
</project>
136 changes: 136 additions & 0 deletions src/main/java/hudson/scm/SSCMUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package hudson.scm;

/**
* Class of basic utils for working with 'sscm://' urls.
*/
public class SSCMUtils {
private final static String URI = "sscm://";

/**
* Parses the Surround SCM Server host name from the passed in sscm:// url.
*
* ex. sscm://server:4900//branch//Mainline/Path/To/Repository
*
* @param URL ex. sscm://server:4900//branch//Mainline/Path/To/Repository
* @return Returns server
*/
public static String getServerFromURL(String URL)
{
String result = "";

if(validateSSCMURL(URL))
{
int startOfServer = URI.length();
int endOfServer = URL.indexOf(":", startOfServer);
if(startOfServer > 0 && endOfServer > 0) // Everything should be greater than 0 because 0 = the URI
result = URL.substring(startOfServer, endOfServer);
}

return result;
}

/**
* Parses the Surround SCM Server port from the pased in sscm:// url.
*
* ex. sscm://server:4900//branch//Mainline/Path/To/Repository
*
* @param URL ex. sscm://server:4900//branch//Mainline/Path/To/Repository
* @return returns the port (ex. 4900)
*/
public static String getPortFromURL(String URL)
{
String port = "";
if(validateSSCMURL(URL))
{
int startOfPort = URL.indexOf(":",URI.length()) ; // start search after the URI's ':'
int endOfPort = URL.indexOf("//", startOfPort);
if(startOfPort > 0 && endOfPort > 0) // Everything should be greater than 0 because 0 = the URI
port = URL.substring(startOfPort + 1, endOfPort); // Need to account for the ':'
try {
Integer.parseInt(port);
} catch( NumberFormatException ex)
{
port = "";
}
}
return port;
}

/**
* Parses the Surround SCM Server port from the pased in sscm:// url.
*
* ex. sscm://server:4900//branch//Mainline/Path/To/Repository
*
* @param URL ex. sscm://server:4900//branch//Mainline/Path/To/Repository
* @return returns the port (ex. 4900)
*/
public static String getBranchFromURL(String URL)
{
String branch = "";
if(validateSSCMURL(URL))
{
int startOfBranch = URL.indexOf("//", URI.length()); // start search after the URI's '//'
int endOfBranch = URL.indexOf("//", startOfBranch + 2);
if(startOfBranch > 0 && endOfBranch > 0) { // Everything should be greater than 0 because 0 = the URI
branch = URL.substring(startOfBranch + 2, endOfBranch);
}
}
return branch;
}

/**
* Parses the Surround SCM Server port from the pased in sscm:// url.
*
* ex. sscm://server:4900//branch//Mainline/Path/To/Repository
*
* @param URL ex. sscm://server:4900//branch//Mainline/Path/To/Repository
* @return returns the port (ex. 4900)
*/
public static String getRepositoryFromURL(String URL)
{
String repository = "";
if(validateSSCMURL(URL))
{
int startOfRepository = URL.lastIndexOf("//");
if(startOfRepository > 0) // Everything should be greater than 0 because 0 = the URI
repository = URL.substring(startOfRepository + 2); // Need to account for the fact that start found "//"
}
return repository;
}

@SuppressWarnings("ResultOfMethodCallIgnored")
public static boolean validateSSCMURL(String URL)
{
if(!URL.startsWith(URI))
return false;

String[] splitURL = URL.split("//");

if(splitURL.length != 4)
return false;

// Check section 1
if(!splitURL[0].equals("sscm:"))
return false;

// Check section 2
String[] splitServerPort = splitURL[1].split(":");
if(splitServerPort.length != 2)
return false;

if(splitServerPort[0].isEmpty() || splitServerPort[1].isEmpty())
return false;

try
{
Integer.parseInt(splitServerPort[1]);
} catch (NumberFormatException ex)
{
return false;
}

// Check section 3 & 4
return !(splitURL[2].isEmpty() || splitURL[3].isEmpty());

}
}

0 comments on commit 0d73ca3

Please sign in to comment.