Class StageClient


  • public class StageClient
    extends Object
    The Stage client acts as the interface to Nexus Pro staging via the Nexus REST APIs. A single StageClient is not thread safe.
    Version:
    0.5
    Author:
    James Nord
    • Constructor Detail

      • StageClient

        public StageClient​(URL nexusURL,
                           String username,
                           String password)
        Create a new StageClient to handle communicating to a Nexus Pro server Staging suite.
        Parameters:
        nexusURL - the base URL for the Nexus server.
        username - user name to use with staging privileges.
        password - password for the user.
    • Method Detail

      • getOpenStageID

        public Stage getOpenStageID​(String group,
                                    String artifact,
                                    String version)
                             throws StageException
        Get the ID for the Staging repository that holds the specified GAV.
        Parameters:
        group - groupID to search for.
        artifact - artifactID to search for.
        version - version of the group/artifact to search for - may be null.
        Returns:
        the stageID or null if no machine stage was found.
        Throws:
        StageException - if any issue occurred whilst locating the open stage.
      • closeStage

        public void closeStage​(Stage stage,
                               String description)
                        throws StageException
        Close the specified stage.
        Parameters:
        stage - the stage to close.
        description - the description to add to the stage..
        Throws:
        StageException - if any issue occurred whilst closing the stage.
      • dropStage

        public void dropStage​(Stage stage)
                       throws StageException
        Drop the stage from Nexus staging.
        Parameters:
        stage - the Stage to drop.
        Throws:
        StageException - if any issue occurred whilst dropping the stage.
      • releaseStage

        public void releaseStage​(Stage stage)
                          throws StageException
        Release the stage from Nexus staging into the default repository for the stage. This does not drop stage repository after a successful release.
        Parameters:
        stage - the Stage to promote.
        Throws:
        StageException - if any issue occurred whilst promoting the stage.
      • promoteStage

        public void promoteStage​(Stage stage)
                          throws StageException
        Promote the stage from Nexus staging into the specified profile.
        Parameters:
        stage - the Stage to promote.
        Throws:
        StageException - if any issue occurred whilst promoting the stage.
      • waitForActionToComplete

        protected void waitForActionToComplete​(Stage stage)
                                        throws StageException
        Completion of the stage action is asynchronous - so poll until the action completed.
        Parameters:
        stage - the stage to wait until the previous action is completed.
        Throws:
        StageException - if any issue occurred whilst closing the stage.
      • checkAuthentication

        public void checkAuthentication()
                                 throws StageException
        Check if we have the required permissions for nexus staging.
        Throws:
        StageException - if an exception occurred whilst checking the authorisation.
      • getServerVersion

        protected String getServerVersion()
                                   throws StageException
        Retrieve the Nexus servers version.
        Returns:
        the String representation of the server version.
        Throws:
        StageException - if we could not obtain the nexus server version.
      • isAsyncClose

        protected boolean isAsyncClose()
                                throws StageException
        Checks if this Nexus server uses asynchronous stage actions.
        Returns:
        true if this server uses asynchronous stage actions (i.e. the server is 2.4 or newer).
        Throws:
        StageException - if we could not retrieve the server version.
      • isAsyncClose

        protected boolean isAsyncClose​(String version)
        Checks if this Nexus server uses asynchronous stage actions.
        Parameters:
        version - the version of this server
        Returns:
        true if this server uses asynchronous stage actions (i.e. the server is 2.4 or newer).
      • getOpenStageIDs

        protected List<Stage> getOpenStageIDs​(Document doc)
                                       throws StageException
        Parses a stagingRepositories element to obtain the list of open stages.
        Parameters:
        doc - the stagingRepositories to parse.
        Returns:
        a List of open stages.
        Throws:
        StageException - if the XPath expression is invalid (which it should never be).
      • getDocument

        protected Document getDocument​(URL url)
                                throws StageException
        Retrieve and parse an XML file from the given URL.
        Parameters:
        url - the URL where the XML document can be obtained.
        Returns:
        the parsed Document.
        Throws:
        StageException - if there was an issue obtaining or parsing the document.
      • createPromoteRequestPayload

        protected String createPromoteRequestPayload​(Stage stage,
                                                     String description,
                                                     Boolean autodrop)
                                              throws StageException
        Construct the XML message for a promoteRequest.
        Parameters:
        stage - The stage to target
        description - the description (used for promote - ignored otherwise)
        autodrop - Boolean.TRUE or Boolean.FALSE sets the autoDropAfterRelease to the appropriate value. null omits the value.
        Returns:
        The XML for the promoteRequest.
        Throws:
        StageException - if we could not determine if this server support async close or not.
      • performStageAction

        protected void performStageAction​(StageAction action,
                                          Stage stage,
                                          String description)
                                   throws StageException
        Perform a staging action.
        Parameters:
        action - the action to perform.
        stage - the stage on which to perform the action.
        description - description to pass to the server for the action (e.g. the description of the stage repo).
        Throws:
        StageException - if an exception occurs whilst performing the action.