Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
Commandline |
|
| 2.2;2.2 |
1 | package org.apache.maven.surefire.booter; |
|
2 | ||
3 | /* |
|
4 | * Copyright 2001-2006 The Apache Software Foundation. |
|
5 | * |
|
6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
7 | * you may not use this file except in compliance with the License. |
|
8 | * You may obtain a copy of the License at |
|
9 | * |
|
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
11 | * |
|
12 | * Unless required by applicable law or agreed to in writing, software |
|
13 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 | * See the License for the specific language governing permissions and |
|
16 | * limitations under the License. |
|
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 | 0 | super(); |
43 | 0 | setDefaultShell(); |
44 | 0 | } |
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 | 0 | String os = System.getProperty( OS_NAME ); |
53 | ||
54 | //If this is windows set the shell to command.com or cmd.exe with correct arguments. |
|
55 | 0 | if ( os.indexOf( WINDOWS ) != -1 ) |
56 | { |
|
57 | 0 | if ( os.indexOf( "95" ) != -1 || os.indexOf( "98" ) != -1 || os.indexOf( "Me" ) != -1 ) |
58 | { |
|
59 | 0 | setShell( new CommandShell() ); |
60 | 0 | } |
61 | else |
|
62 | { |
|
63 | 0 | setShell( new CmdShell() ); |
64 | } |
|
65 | } |
|
66 | 0 | } |
67 | ||
68 | /** |
|
69 | * Returns the shell, executable and all defined arguments. |
|
70 | */ |
|
71 | public String[] getShellCommandline() |
|
72 | { |
|
73 | ||
74 | 0 | if ( getShell() == null ) |
75 | { |
|
76 | 0 | if ( executable != null ) |
77 | { |
|
78 | 0 | List commandLine = new ArrayList(); |
79 | 0 | commandLine.add( executable ); |
80 | 0 | commandLine.addAll( Arrays.asList( getArguments() ) ); |
81 | 0 | return (String[]) commandLine.toArray( new String[0] ); |
82 | } |
|
83 | else |
|
84 | { |
|
85 | 0 | return getArguments(); |
86 | } |
|
87 | ||
88 | } |
|
89 | else |
|
90 | { |
|
91 | 0 | 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 | 0 | this.shell = shell; |
104 | 0 | } |
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 | 0 | return shell; |
114 | } |
|
115 | ||
116 | } |