Class PerforceManager


  • public class PerforceManager
    extends Object
    This class is designed to be the interface between the perforce library and the repository. TODO Please note that there have been some issues with the legacy perforce api so please only use the tek42 api.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static org.apache.commons.lang3.time.FastDateFormat dateFormat  
    • Constructor Summary

      Constructors 
      Constructor Description
      PerforceManager()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      @NotNull CapabilitySet addDefaultPerforceExe​(@NotNull CapabilitySet capabilitySet)
      Extracts the default perforce executable from the system properties and creates a capability
      void clearCache()  
      @NotNull List<Commit> getChangeLogEntries​(@NotNull com.tek42.perforce.Depot perforceDepot, @NotNull List<Integer> changeNumbers)
      Retrieves a list of Bamboo Commit including Commit Files based on list of change numbers
      List<Integer> getChangeNumbersFromRevision​(@NotNull com.tek42.perforce.Depot perforceDepot, String clientViewDepot, int lastRevisionInBamboo, boolean useClientMapping)  
      @NotNull List<Integer> getChangeNumsBetweenRevisions​(@NotNull com.tek42.perforce.Depot perforceDepot, @Nullable String depot, int firstRevision, int secondRevision, boolean useClientMapping)
      Retrieves a list of change log numbers after the first number and up to (and including) the second number for the depot.
      @NotNull String getClientRoot​(com.tek42.perforce.Depot perforceDepot)
      Retrieves the workspace root as defined in the client configuration
      protected String getDepotFromView​(@NotNull com.tek42.perforce.Depot perforceDepot, @Nullable String depotView, boolean useClientMapping)
      Takes in the client view of a depot (right hand side of the view map) and returns the actual depot (left hand side of the view map) If it fails it will return the client view, chances are what you are doing will still work with this.
      Map<String,​String> getDepotViewCache()  
      @Nullable String getFileNameForUrl​(String fileName, String depot, String clientName)  
      @Nullable String getHostFromInfo​(@NotNull com.tek42.perforce.Depot perforceDepot)
      parses output of perforce indo command to extract out the address of the perforce server
      int getLatestChangeNumber​(@NotNull com.tek42.perforce.Depot perforceDepot, @Nullable String depot, int latestRevisionInBamboo, boolean useClientMapping)
      retrieves the latest change list number on the perforce server for comparison to the one stored in Bamboo
      @Nullable String getWorkingDir​(@Nullable String client, @Nullable String clientRoot, @Nullable String depot)
      Extracts the directory from the depot(client view) and source code directory which will contain the build files
      void setupSync​(@NotNull com.tek42.perforce.Depot perforceDepot, @NotNull File sourceDirectory)
      Sets the directory for perforce to check the code out to.
      void syncToHead​(@NotNull com.tek42.perforce.Depot perforceDepot, @NotNull String depot, boolean forceSync)
      Syncs the source code to head
      void syncToRevision​(@NotNull com.tek42.perforce.Depot perforceDepot, @NotNull String depot, int revisionNumber, boolean forceSync)
      Syncs the source code to a specific revision number
      void validateClient​(@NotNull ErrorCollection errorCollection, @NotNull com.tek42.perforce.Depot depot, @NotNull String client)
      Validates the existence of the specified client of the perforce depot.
      void validateConnection​(@NotNull ErrorCollection errorCollection, @NotNull com.tek42.perforce.Depot depot)
      Validates the connection to the perforce depot.
      void validateDepot​(@NotNull ErrorCollection errorCollection, @NotNull com.tek42.perforce.Depot validationDepot, @NotNull String depot)
      Validates that the depot string specified is correct.
      void validateLogin​(@NotNull ErrorCollection errorCollection, @NotNull com.tek42.perforce.Depot depot)
      Validates that the login credential supplied (ie user/password combination) is correct.
    • Field Detail

      • dateFormat

        protected static final org.apache.commons.lang3.time.FastDateFormat dateFormat
    • Constructor Detail

      • PerforceManager

        public PerforceManager()
    • Method Detail

      • syncToRevision

        public void syncToRevision​(@NotNull
                                   @NotNull com.tek42.perforce.Depot perforceDepot,
                                   @NotNull
                                   @NotNull String depot,
                                   int revisionNumber,
                                   boolean forceSync)
                            throws RepositoryException
        Syncs the source code to a specific revision number
        Parameters:
        perforceDepot - containing all connection information except client workspace mapping
        depot - client workspace mapping
        revisionNumber - to sync to
        forceSync - whether or not to force a full clean checkout
        Throws:
        RepositoryException - if perforce failed to sync the workspace
      • syncToHead

        public void syncToHead​(@NotNull
                               @NotNull com.tek42.perforce.Depot perforceDepot,
                               @NotNull
                               @NotNull String depot,
                               boolean forceSync)
                        throws RepositoryException
        Syncs the source code to head
        Parameters:
        perforceDepot - containing all connection information except client workspace mapping
        depot - client workspace mapping
        forceSync - whether or not to force a full clean checkout
        Throws:
        RepositoryException - if perforce failed to sync the workspace
      • setupSync

        public void setupSync​(@NotNull
                              @NotNull com.tek42.perforce.Depot perforceDepot,
                              @NotNull
                              @NotNull File sourceDirectory)
                       throws RepositoryException
        Sets the directory for perforce to check the code out to. To do this it alters the client definition in particular the client root. It also ensures that there are no machine restrictions in place. Please use sparingly
        Parameters:
        perforceDepot - containing connection information
        sourceDirectory - where you want the sync to occur
        Throws:
        RepositoryException - if it fails to connect to the repository
      • getClientRoot

        @NotNull
        public @NotNull String getClientRoot​(com.tek42.perforce.Depot perforceDepot)
                                      throws RepositoryException
        Retrieves the workspace root as defined in the client configuration
        Parameters:
        perforceDepot - the client to extract the workspace root for
        Returns:
        String client root, Null if it couldn't find it.
        Throws:
        RepositoryException - if it fails to connect to the repository
      • getFileNameForUrl

        @Nullable
        public @Nullable String getFileNameForUrl​(String fileName,
                                                  String depot,
                                                  String clientName)
      • getLatestChangeNumber

        public int getLatestChangeNumber​(@NotNull
                                         @NotNull com.tek42.perforce.Depot perforceDepot,
                                         @Nullable
                                         @Nullable String depot,
                                         int latestRevisionInBamboo,
                                         boolean useClientMapping)
                                  throws RepositoryException
        retrieves the latest change list number on the perforce server for comparison to the one stored in Bamboo
        Parameters:
        perforceDepot - containing all connection information except the client workspace mapping
        depot - the client workspace mapping
        latestRevisionInBamboo - the last change list number stored in bamboo
        useClientMapping - will use the client side mapping rather than the depot mapping for this command
        Returns:
        long Number of latest change list from perforce, If it can not find it, the latestRevisionInBamboo is returned
        Throws:
        RepositoryException - if it fails to connect to the repository
      • getChangeNumsBetweenRevisions

        @NotNull
        public @NotNull List<Integer> getChangeNumsBetweenRevisions​(@NotNull
                                                                    @NotNull com.tek42.perforce.Depot perforceDepot,
                                                                    @Nullable
                                                                    @Nullable String depot,
                                                                    int firstRevision,
                                                                    int secondRevision,
                                                                    boolean useClientMapping)
                                                             throws RepositoryException
        Retrieves a list of change log numbers after the first number and up to (and including) the second number for the depot. This can then be used To extract the change logs.
        Parameters:
        perforceDepot - containing all connection information except the client workspace mapping
        depot - the client workspace mapping
        firstRevision - change logs will be found which occur after this number
        secondRevision - change logs will be found up to and including this number
        useClientMapping - will use the client side mapping rather than the depot mapping for this command
        Returns:
        List of change list numbers matching the given criteria.
        Throws:
        RepositoryException - on failure to connect to the repository
      • getChangeNumbersFromRevision

        public List<Integer> getChangeNumbersFromRevision​(@NotNull
                                                          @NotNull com.tek42.perforce.Depot perforceDepot,
                                                          String clientViewDepot,
                                                          int lastRevisionInBamboo,
                                                          boolean useClientMapping)
                                                   throws RepositoryException
        Throws:
        RepositoryException
      • getChangeLogEntries

        @NotNull
        public @NotNull List<Commit> getChangeLogEntries​(@NotNull
                                                         @NotNull com.tek42.perforce.Depot perforceDepot,
                                                         @NotNull
                                                         @NotNull List<Integer> changeNumbers)
                                                  throws RepositoryException
        Retrieves a list of Bamboo Commit including Commit Files based on list of change numbers
        Parameters:
        perforceDepot - containing all connection information
        changeNumbers - to retrieve changeLog entries for
        Returns:
        the list of Commits
        Throws:
        RepositoryException - if it fails to connect to the repository
      • getHostFromInfo

        @Nullable
        public @Nullable String getHostFromInfo​(@NotNull
                                                @NotNull com.tek42.perforce.Depot perforceDepot)
        parses output of perforce indo command to extract out the address of the perforce server
        Parameters:
        perforceDepot - containing connection information
        Returns:
        address of the perforce server
      • validateConnection

        public void validateConnection​(@NotNull
                                       @NotNull ErrorCollection errorCollection,
                                       @NotNull
                                       @NotNull com.tek42.perforce.Depot depot)
        Validates the connection to the perforce depot. Uses the legacy perforce api
        Parameters:
        errorCollection - to add validation errors to
        depot - containing connection info to validate
      • validateLogin

        public void validateLogin​(@NotNull
                                  @NotNull ErrorCollection errorCollection,
                                  @NotNull
                                  @NotNull com.tek42.perforce.Depot depot)
        Validates that the login credential supplied (ie user/password combination) is correct. Uses the legacy perforce api
        Parameters:
        errorCollection - to add validation errors to
        depot - connection information to test
      • validateClient

        public void validateClient​(@NotNull
                                   @NotNull ErrorCollection errorCollection,
                                   @NotNull
                                   @NotNull com.tek42.perforce.Depot depot,
                                   @NotNull
                                   @NotNull String client)
        Validates the existence of the specified client of the perforce depot. Uses the legacy perforce api
        Parameters:
        errorCollection - to add any validation errors to
        depot - connection information to use to validate client.
        client - to check for
      • validateDepot

        public void validateDepot​(@NotNull
                                  @NotNull ErrorCollection errorCollection,
                                  @NotNull
                                  @NotNull com.tek42.perforce.Depot validationDepot,
                                  @NotNull
                                  @NotNull String depot)
        Validates that the depot string specified is correct. This still uses a direct perforce command call.
        Parameters:
        errorCollection - to add any validation errors to
        validationDepot - connection information to use to validate
        depot - client workspace to validate
      • getWorkingDir

        @Nullable
        public @Nullable String getWorkingDir​(@Nullable
                                              @Nullable String client,
                                              @Nullable
                                              @Nullable String clientRoot,
                                              @Nullable
                                              @Nullable String depot)
        Extracts the directory from the depot(client view) and source code directory which will contain the build files
        Parameters:
        client - - name of the client
        clientRoot - - the location the source will be checked out to
        depot - - the depot(client view) as specified by the user
        Returns:
        the working directory for the given client.
      • addDefaultPerforceExe

        @NotNull
        public @NotNull CapabilitySet addDefaultPerforceExe​(@NotNull
                                                            @NotNull CapabilitySet capabilitySet)
        Extracts the default perforce executable from the system properties and creates a capability
        Parameters:
        capabilitySet - to add the capability to
        Returns:
        the supplied capabilitySet with the new capability included if found, else the given capabilitySet
      • getDepotFromView

        protected String getDepotFromView​(@NotNull
                                          @NotNull com.tek42.perforce.Depot perforceDepot,
                                          @Nullable
                                          @Nullable String depotView,
                                          boolean useClientMapping)
        Takes in the client view of a depot (right hand side of the view map) and returns the actual depot (left hand side of the view map) If it fails it will return the client view, chances are what you are doing will still work with this. Perforce views are in the format //myDepot/src... //myClient/view/... with any amount of whitespace around it (also known to get \t on occassion)
        Parameters:
        perforceDepot - containing all connection information except the client mapping
        depotView - - the client mapping you want to match
        Returns:
        returns the actual depot (left hand side of the view map)
      • clearCache

        public void clearCache()