@@ -1747,6 +1747,8 @@ private String getConcurrentClientName(FilePath workspace, String p4Client) {
17471747
17481748 @ Extension
17491749 public static final class PerforceSCMDescriptor extends SCMDescriptor <PerforceSCM > {
1750+ private String p4ClientPattern ;
1751+
17501752 public PerforceSCMDescriptor () {
17511753 super (PerforceSCM .class , PerforceRepositoryBrowser .class );
17521754 load ();
@@ -1807,6 +1809,34 @@ public List<PerforceToolInstallation> getP4Tools() {
18071809 PerforceToolInstallation [] p4ToolInstallations = Hudson .getInstance ().getDescriptorByType (PerforceToolInstallation .DescriptorImpl .class ).getInstallations ();
18081810 return Arrays .asList (p4ToolInstallations );
18091811 }
1812+
1813+ public String getP4ClientPattern () {
1814+ if (p4ClientPattern == null ) {
1815+ return ".*" ;
1816+ } else {
1817+ return p4ClientPattern ;
1818+ }
1819+ }
1820+
1821+
1822+ @ Override
1823+ public boolean configure (StaplerRequest req , JSONObject json ) throws FormException {
1824+ p4ClientPattern = Util .fixEmpty (req .getParameter ("p4.clientPattern" ).trim ());
1825+ save ();
1826+ return true ;
1827+ }
1828+
1829+ public FormValidation doValidateNamePattern (StaplerRequest req ) {
1830+ String namePattern = Util .fixEmptyAndTrim (req .getParameter ("value" ));
1831+ if (namePattern != null ) {
1832+ try {
1833+ Pattern .compile (namePattern );
1834+ } catch (PatternSyntaxException exception ) {
1835+ return FormValidation .error ("Pattern format error: " +exception .getMessage ());
1836+ }
1837+ }
1838+ return FormValidation .ok ();
1839+ }
18101840
18111841 public String isValidProjectPath (String path ) {
18121842 if (!path .startsWith ("//" )) {
@@ -1878,19 +1908,26 @@ public FormValidation doValidatePerforceLogin(StaplerRequest req) {
18781908 * Checks to see if the specified workspace is valid.
18791909 */
18801910 public FormValidation doValidateP4Client (StaplerRequest req ) {
1881- Depot depot = getDepotFromRequest (req );
1882- if (depot == null ) {
1883- return FormValidation .error (
1884- "Unable to check workspace against depot" );
1885- }
1886- String workspace = Util .fixEmptyAndTrim (req .getParameter ("client" ));
1911+ String workspace = Util .fixEmptyAndTrim (req .getParameter ("client" ));
18871912 if (workspace == null ) {
18881913 return FormValidation .error ("You must enter a workspaces name" );
18891914 }
18901915 try {
1916+ // Check P4 client pattern first, because workspace check fails on valid client names with variables
1917+ if (!workspace .matches (getP4ClientPattern ())) {
1918+ return FormValidation .error ("Client name doesn't meet global pattern: " +getP4ClientPattern ());
1919+ }
1920+
1921+ // Then, check depot
1922+ Depot depot = getDepotFromRequest (req );
1923+ if (depot == null ) {
1924+ return FormValidation .error (
1925+ "Unable to check workspace against depot" );
1926+ }
1927+
1928+ // Then, check workspace
18911929 Workspace p4Workspace =
18921930 depot .getWorkspaces ().getWorkspace (workspace , "" );
1893-
18941931 if (p4Workspace .getAccess () == null ||
18951932 p4Workspace .getAccess ().equals ("" ))
18961933 return FormValidation .warning ("Workspace does not exist. " +
0 commit comments