hudson.plugins.collabnet.util
Class CNHudsonUtil

java.lang.Object
  extended by hudson.plugins.collabnet.util.CNHudsonUtil

public class CNHudsonUtil
extends java.lang.Object

Class for methods that are useful across Hudson plugins.


Method Summary
static int compareVersion(int[] version1, int[] version2)
          Compare two equal length version array
static CollabNetApp getCollabNetApp(org.kohsuke.stapler.StaplerRequest request)
          Get a CollabNetApp, given a StaplerRequest with url, username, and password set.
static CollabNetApp getCollabNetApp(java.lang.String url, java.lang.String username, java.lang.String password)
           
static java.lang.String getFileId(CollabNetApp cna, java.lang.String releaseId, java.lang.String file)
          Get the file id.
static java.lang.String getFileId(CollabNetApp cna, java.lang.String project, java.lang.String rpackage, java.lang.String release, java.lang.String file)
          Given project, package, release, and file name, find the fileId for a file in the system, or null if none is found.
static java.lang.String getPackageId(CollabNetApp cna, java.lang.String rpackage, java.lang.String projectId)
          Get the packageId for the package name.
static java.lang.String getProjectId(CollabNetApp cna, java.lang.String project)
          Get the projectId for the project name.
static java.lang.String getProjectReleaseId(CollabNetApp cna, java.lang.String projectId, java.lang.String release)
          Get a releaseId, given a projectId and a release title.
static java.lang.String getReleaseId(CollabNetApp cna, java.lang.String packageId, java.lang.String release)
          Get the release id.
static java.lang.String getRepoId(CollabNetApp cna, java.lang.String projectId, java.lang.String repoName)
           
static java.lang.String getScmViewerUrl(CollabNetApp cna, java.lang.String collabnetUrl, java.lang.String projectName, java.lang.String repoName)
           
static java.lang.String getSystemId(CollabNetApp cna, java.lang.String projectName, java.lang.String repoName)
           
static com.collabnet.ce.soap50.webservices.tracker.ArtifactSoapDO getTrackerArtifact(CollabNetApp cna, java.lang.String project, java.lang.String tracker, java.lang.String issueTitle)
          Given a project and issue title, find the most recent matching issue object, or null if none matches.
static java.lang.String getTrackerId(CollabNetApp cna, java.lang.String projectId, java.lang.String trackerName)
          Given a tracker title and a projectId, find the matching tracker id.
static java.lang.String getUsername(org.kohsuke.stapler.StaplerRequest request)
           
static int[] getVersionArray(java.lang.String apiVersionStr)
          Turn version string into an array, where each version is in its own index/pos.
static boolean isSupportedVersion(int[] startSupportVersion, int[] endSupportVersion, int[] actualVersion)
          Check if the actual version is within the range of the start/end support version
static boolean isUserMember(CollabNetApp cna, java.lang.String username, java.lang.String projectId)
           
static boolean isUserValid(CollabNetApp cna, java.lang.String username)
           
static void logoff(CollabNetApp cna)
          Logs off the CollabNetApp, if possible.
static java.lang.String sanitizeCollabNetUrl(java.lang.String url)
          Sanitizes a CollabNet url and make it appropriate to be used by this plugin.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getCollabNetApp

public static CollabNetApp getCollabNetApp(java.lang.String url,
                                           java.lang.String username,
                                           java.lang.String password)
Parameters:
url -
username -
password -
Returns:
collabnet app, if one can be created; null otherwise.

getCollabNetApp

public static CollabNetApp getCollabNetApp(org.kohsuke.stapler.StaplerRequest request)
Get a CollabNetApp, given a StaplerRequest with url, username, and password set. If login fails, null will be returned.


getUsername

public static java.lang.String getUsername(org.kohsuke.stapler.StaplerRequest request)
Returns:
the username from the stapler request or the global value, if applicable.

logoff

public static void logoff(CollabNetApp cna)
Logs off the CollabNetApp, if possible.

Parameters:
cna - CollabNetApp

getPackageId

public static java.lang.String getPackageId(CollabNetApp cna,
                                            java.lang.String rpackage,
                                            java.lang.String projectId)
Get the packageId for the package name.

Parameters:
cna - the collab net app instance to use
rpackage - name of the package.
projectId - the project id.
Returns:
the package id if found, null otherwise.

getProjectId

public static java.lang.String getProjectId(CollabNetApp cna,
                                            java.lang.String project)
Get the projectId for the project name.

Parameters:
cna - for accessing the webservice methods.
project - name.
Returns:
the id for the project or null, if no such project exist.

getReleaseId

public static java.lang.String getReleaseId(CollabNetApp cna,
                                            java.lang.String packageId,
                                            java.lang.String release)
Get the release id.

Parameters:
cna - for accessing the webservice methods.
packageId - the id of the package which contains this release.
release - the name of the release
Returns:
the release id, or null if none is found.

getFileId

public static java.lang.String getFileId(CollabNetApp cna,
                                         java.lang.String releaseId,
                                         java.lang.String file)
Get the file id.

Parameters:
cna - for accessing the webservice methods.
releaseId - the id of the release.
file - name
Returns:
the file id, or null if none is found.

getProjectReleaseId

public static java.lang.String getProjectReleaseId(CollabNetApp cna,
                                                   java.lang.String projectId,
                                                   java.lang.String release)
Get a releaseId, given a projectId and a release title.

Parameters:
cna - for accessing the webservice methods.
projectId -
release -
Returns:
the releaseId in this project which matches the release name or null if none is found.

getTrackerId

public static java.lang.String getTrackerId(CollabNetApp cna,
                                            java.lang.String projectId,
                                            java.lang.String trackerName)
Given a tracker title and a projectId, find the matching tracker id.

Parameters:
cna - for accessing the webservice methods.
projectId -
trackerName -
Returns:
the tracker id for the tracker that matches this name, or null if no matching tracker is found.

getTrackerArtifact

public static com.collabnet.ce.soap50.webservices.tracker.ArtifactSoapDO getTrackerArtifact(CollabNetApp cna,
                                                                                            java.lang.String project,
                                                                                            java.lang.String tracker,
                                                                                            java.lang.String issueTitle)
Given a project and issue title, find the most recent matching issue object, or null if none matches.


getFileId

public static java.lang.String getFileId(CollabNetApp cna,
                                         java.lang.String project,
                                         java.lang.String rpackage,
                                         java.lang.String release,
                                         java.lang.String file)
Given project, package, release, and file name, find the fileId for a file in the system, or null if none is found.

Parameters:
cna - for accessing webservice methods
project - name
rpackage - name
release - name
file - name

isUserValid

public static boolean isUserValid(CollabNetApp cna,
                                  java.lang.String username)
Parameters:
cna - for accessing the webservice methods.
username -
Returns:
true if the user can be found.

isUserMember

public static boolean isUserMember(CollabNetApp cna,
                                   java.lang.String username,
                                   java.lang.String projectId)
Parameters:
cna - for accessing the webservice methods.
username -
projectId -
Returns:
true if the user is a member of the project.

getScmViewerUrl

public static java.lang.String getScmViewerUrl(CollabNetApp cna,
                                               java.lang.String collabnetUrl,
                                               java.lang.String projectName,
                                               java.lang.String repoName)
Parameters:
cna - for accessing the webservice methods.
collabnetUrl - the collabnet url
projectName - name of the project
repoName - name of the repository
Returns:
the scm viewer url

getVersionArray

public static int[] getVersionArray(java.lang.String apiVersionStr)
Turn version string into an array, where each version is in its own index/pos.

Parameters:
apiVersionStr -
Returns:

isSupportedVersion

public static boolean isSupportedVersion(int[] startSupportVersion,
                                         int[] endSupportVersion,
                                         int[] actualVersion)
Check if the actual version is within the range of the start/end support version

Parameters:
startSupportVersion - the start version, inclusive. null to ignore check.
endSupportVersion - the ending version, not inclusive. null to ignore check.
actualVersion - the actual version
Returns:
true if actual version is between start version (inclusive) and end version (non inclusive)

compareVersion

public static int compareVersion(int[] version1,
                                 int[] version2)
Compare two equal length version array

Parameters:
version1 - first version
version2 - second version
Returns:
-1 if version1 is less than version2, 0 if they are the same, and 1 if version1 is greater than version2

getSystemId

public static java.lang.String getSystemId(CollabNetApp cna,
                                           java.lang.String projectName,
                                           java.lang.String repoName)
Parameters:
cna - for accessing the webservice methods.
projectName -
repoName -

getRepoId

public static java.lang.String getRepoId(CollabNetApp cna,
                                         java.lang.String projectId,
                                         java.lang.String repoName)
Parameters:
cna - for accessing the webservice methods.
projectId -
repoName -

sanitizeCollabNetUrl

public static java.lang.String sanitizeCollabNetUrl(java.lang.String url)
Sanitizes a CollabNet url and make it appropriate to be used by this plugin.

Parameters:
url - original url
Returns:
sanitized collabnet url


Copyright © 2010. All Rights Reserved.