1 package org.apache.maven.surefire.booter;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.util.ArrayList;
20 import java.util.Arrays;
21 import java.util.List;
22
23 import org.apache.maven.surefire.booter.shell.CmdShell;
24 import org.apache.maven.surefire.booter.shell.CommandShell;
25 import org.apache.maven.surefire.booter.shell.Shell;
26
27 /**
28 * Commandline class copied from plexus-utils with fix for PLX-161, as we can not upgrade plexus-utils until it's upgraded in core Maven
29 *
30 * TODO deprecate when plexus-utils 1.2 can be used
31 *
32 * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
33 */
34 public class Commandline
35 extends org.codehaus.plexus.util.cli.Commandline
36 {
37
38 private Shell shell;
39
40 public Commandline()
41 {
42 super();
43 setDefaultShell();
44 }
45
46 /**
47 * <p>Sets the shell or command-line interpretor for the detected operating system,
48 * and the shell arguments.</p>
49 */
50 private void setDefaultShell()
51 {
52 String os = System.getProperty( OS_NAME );
53
54
55 if ( os.indexOf( WINDOWS ) != -1 )
56 {
57 if ( os.indexOf( "95" ) != -1 || os.indexOf( "98" ) != -1 || os.indexOf( "Me" ) != -1 )
58 {
59 setShell( new CommandShell() );
60 }
61 else
62 {
63 setShell( new CmdShell() );
64 }
65 }
66 }
67
68 /**
69 * Returns the shell, executable and all defined arguments.
70 */
71 public String[] getShellCommandline()
72 {
73
74 if ( getShell() == null )
75 {
76 if ( executable != null )
77 {
78 List commandLine = new ArrayList();
79 commandLine.add( executable );
80 commandLine.addAll( Arrays.asList( getArguments() ) );
81 return (String[]) commandLine.toArray( new String[0] );
82 }
83 else
84 {
85 return getArguments();
86 }
87
88 }
89 else
90 {
91 return (String[]) getShell().getShellCommandLine( executable, getArguments() ).toArray( new String[0] );
92 }
93 }
94
95 /**
96 * Allows to set the shell to be used in this command line.
97 *
98 * @param shell
99 * @since 1.2
100 */
101 public void setShell( Shell shell )
102 {
103 this.shell = shell;
104 }
105
106 /**
107 * Get the shell to be used in this command line.
108 *
109 * @since 1.2
110 */
111 public Shell getShell()
112 {
113 return shell;
114 }
115
116 }