2626
2727import  static  org .csanchez .jenkins .plugins .kubernetes .ContainerTemplate .DEFAULT_WORKING_DIR ;
2828import  static  org .csanchez .jenkins .plugins .kubernetes .KubernetesCloud .JNLP_NAME ;
29- import  static  org .csanchez .jenkins .plugins .kubernetes .PodTemplateUtils .combine ;
30- import  static  org .csanchez .jenkins .plugins .kubernetes .PodTemplateUtils .isNullOrEmpty ;
31- import  static  org .csanchez .jenkins .plugins .kubernetes .PodTemplateUtils .sanitizeLabel ;
32- import  static  org .csanchez .jenkins .plugins .kubernetes .PodTemplateUtils .substituteEnv ;
29+ import  static  org .csanchez .jenkins .plugins .kubernetes .PodTemplateUtils .*;
3330
3431import  edu .umd .cs .findbugs .annotations .CheckForNull ;
3532import  edu .umd .cs .findbugs .annotations .NonNull ;
@@ -95,8 +92,6 @@ public class PodTemplateBuilder {
9592
9693    private  static  final  Logger  LOGGER  = Logger .getLogger (PodTemplateBuilder .class .getName ());
9794
98-     private  static  final  Pattern  SPLIT_IN_SPACES  = Pattern .compile ("([^\" ]\\ S*|\" .+?\" )\\ s*" );
99- 
10095    private  static  final  String  WORKSPACE_VOLUME_NAME  = "workspace-volume" ;
10196    public  static  final  Pattern  FROM_DIRECTIVE  = Pattern .compile ("^FROM (.*)$" );
10297
@@ -537,7 +532,7 @@ private Container createContainer(
537532            }
538533        }
539534        List <String > arguments  =
540-                 isNullOrEmpty (containerTemplate .getArgs ()) ? Collections .emptyList () : parseDockerCommand (cmd );
535+                 isNullOrEmpty (containerTemplate .getArgs ()) ? Collections .emptyList () : splitCommandLine (cmd );
541536
542537        ContainerPort [] ports  = containerTemplate .getPorts ().stream ()
543538                .map (entry  -> entry .toPort ())
@@ -547,9 +542,9 @@ private Container createContainer(
547542
548543        ContainerLivenessProbe  clp  = containerTemplate .getLivenessProbe ();
549544        Probe  livenessProbe  = null ;
550-         if  (clp  != null  && parseLivenessProbe (clp .getExecArgs ()) != null ) {
545+         if  (clp  != null  && splitCommandLine (clp .getExecArgs ()) != null ) {
551546            livenessProbe  = new  ProbeBuilder ()
552-                     .withExec (new  ExecAction (parseLivenessProbe (clp .getExecArgs ())))
547+                     .withExec (new  ExecAction (splitCommandLine (clp .getExecArgs ())))
553548                    .withInitialDelaySeconds (clp .getInitialDelaySeconds ())
554549                    .withTimeoutSeconds (clp .getTimeoutSeconds ())
555550                    .withFailureThreshold (clp .getFailureThreshold ())
@@ -577,7 +572,7 @@ private Container createContainer(
577572                .withVolumeMounts (containerMounts .toArray (new  VolumeMount [containerMounts .size ()]))
578573                .addToEnv (envVars )
579574                .addToPorts (ports )
580-                 .withCommand (parseDockerCommand (containerTemplate .getCommand ()))
575+                 .withCommand (splitCommandLine (containerTemplate .getCommand ()))
581576                .withArgs (arguments )
582577                .withLivenessProbe (livenessProbe )
583578                .withTty (containerTemplate .isTtyEnabled ())
@@ -615,46 +610,6 @@ private List<VolumeMount> getContainerVolumeMounts(Collection<VolumeMount> volum
615610        return  containerMounts ;
616611    }
617612
618-     /** 
619-      * Split a command in the parts that Docker need 
620-      * 
621-      * @param dockerCommand 
622-      * @return 
623-      */ 
624-     @ Restricted (NoExternalUse .class )
625-     static  List <String > parseDockerCommand (String  dockerCommand ) {
626-         if  (dockerCommand  == null  || dockerCommand .isEmpty ()) {
627-             return  null ;
628-         }
629-         // handle quoted arguments 
630-         Matcher  m  = SPLIT_IN_SPACES .matcher (dockerCommand );
631-         List <String > commands  = new  ArrayList <String >();
632-         while  (m .find ()) {
633-             commands .add (substituteEnv (m .group (1 ).replace ("\" " , "" )));
634-         }
635-         return  commands ;
636-     }
637- 
638-     /** 
639-      * Split a command in the parts that LivenessProbe need 
640-      * 
641-      * @param livenessProbeExec 
642-      * @return 
643-      */ 
644-     @ Restricted (NoExternalUse .class )
645-     static  List <String > parseLivenessProbe (String  livenessProbeExec ) {
646-         if  (StringUtils .isBlank (livenessProbeExec )) {
647-             return  null ;
648-         }
649-         // handle quoted arguments 
650-         Matcher  m  = SPLIT_IN_SPACES .matcher (livenessProbeExec );
651-         List <String > commands  = new  ArrayList <String >();
652-         while  (m .find ()) {
653-             commands .add (substituteEnv (m .group (1 ).replace ("\" " , "" ).replace ("?:\\ \" " , "" )));
654-         }
655-         return  commands ;
656-     }
657- 
658613    private  Map <String , Quantity > getResourcesMap (String  memory , String  cpu , String  ephemeralStorage ) {
659614        Map <String , Quantity > builder  = new  HashMap <>();
660615        String  actualMemory  = substituteEnv (memory );
0 commit comments