@@ -55,8 +55,8 @@ public void testCommandlineWithoutCommandInConstructor()
55
55
{
56
56
Commandline cmd = new Commandline ( new Shell () );
57
57
cmd .setWorkingDirectory ( baseDir );
58
- cmd .createArgument ().setValue ( "cd" );
59
- cmd .createArgument ().setValue ( "." );
58
+ cmd .createArg ().setValue ( "cd" );
59
+ cmd .createArg ().setValue ( "." );
60
60
61
61
// NOTE: cmd.toString() uses CommandLineUtils.toString( String[] ), which *quotes* the result.
62
62
assertEquals ( "cd ." , cmd .toString () );
@@ -78,6 +78,29 @@ public void testExecuteBinaryOnPath()
78
78
{
79
79
// Maven startup script on PATH is required for this test
80
80
Commandline cmd = new Commandline ();
81
+ String executable = "mvn" ;
82
+ if ( Os .isFamily ( Os .FAMILY_WINDOWS ) )
83
+ {
84
+ executable += ".cmd" ;
85
+ }
86
+ cmd .setWorkingDirectory ( baseDir );
87
+ cmd .setExecutable ( executable );
88
+ assertEquals ( executable , cmd .getShell ().getOriginalExecutable () );
89
+ cmd .createArg ().setValue ( "-version" );
90
+ Process process = cmd .execute ();
91
+ String out = IOUtil .toString ( process .getInputStream () );
92
+ assertTrue ( out .contains ( "Apache Maven" ) );
93
+ assertTrue ( out .contains ( "Maven home:" ) );
94
+ assertTrue ( out .contains ( "Java version:" ) );
95
+ }
96
+
97
+ @ Test
98
+ public void testExecuteBinaryOnPathWithOsShell ()
99
+ throws Exception
100
+ {
101
+ // Maven startup script on PATH is required for this test
102
+ Commandline cmd = new Commandline ();
103
+ cmd .setForceShellOsSpecific ( true );
81
104
cmd .setWorkingDirectory ( baseDir );
82
105
cmd .setExecutable ( "mvn" );
83
106
assertEquals ( "mvn" , cmd .getShell ().getOriginalExecutable () );
@@ -92,13 +115,36 @@ public void testExecuteBinaryOnPath()
92
115
@ Test
93
116
public void testExecute ()
94
117
throws Exception
118
+ {
119
+ String executable = "echo" ;
120
+ Commandline cmd = new Commandline ();
121
+ cmd .setWorkingDirectory ( baseDir );
122
+ if ( Os .isFamily ( Os .FAMILY_WINDOWS ) )
123
+ {
124
+ executable = "cmd" ;
125
+ cmd .createArg ().setValue ( "/X" );
126
+ cmd .createArg ().setValue ( "/C" );
127
+ cmd .createArg ().setValue ( "echo" );
128
+ }
129
+ cmd .setExecutable ( executable );
130
+ assertEquals ( executable , cmd .getShell ().getOriginalExecutable () );
131
+ cmd .createArg ().setValue ( "Hello" );
132
+
133
+ Process process = cmd .execute ();
134
+ assertEquals ( "Hello" , IOUtil .toString ( process .getInputStream () ).trim () );
135
+ }
136
+
137
+ @ Test
138
+ public void testExecuteWithOsShell ()
139
+ throws Exception
95
140
{
96
141
// allow it to detect the proper shell here.
97
142
Commandline cmd = new Commandline ();
143
+ cmd .setForceShellOsSpecific ( true );
98
144
cmd .setWorkingDirectory ( baseDir );
99
145
cmd .setExecutable ( "echo" );
100
146
assertEquals ( "echo" , cmd .getShell ().getOriginalExecutable () );
101
- cmd .createArgument ().setValue ( "Hello" );
147
+ cmd .createArg ().setValue ( "Hello" );
102
148
103
149
Process process = cmd .execute ();
104
150
assertEquals ( "Hello" , IOUtil .toString ( process .getInputStream () ).trim () );
@@ -110,8 +156,8 @@ public void testSetLine()
110
156
Commandline cmd = new Commandline ( new Shell () );
111
157
cmd .setWorkingDirectory ( baseDir );
112
158
cmd .setExecutable ( "echo" );
113
- cmd .createArgument ().setLine ( null );
114
- cmd .createArgument ().setLine ( "Hello" );
159
+ cmd .createArg ().setValue ( null );
160
+ cmd .createArg ().setLine ( "Hello" );
115
161
116
162
// NOTE: cmd.toString() uses CommandLineUtils.toString( String[] ), which *quotes* the result.
117
163
assertEquals ( "echo Hello" , cmd .toString () );
@@ -122,8 +168,8 @@ public void testCreateCommandInReverseOrder()
122
168
{
123
169
Commandline cmd = new Commandline ( new Shell () );
124
170
cmd .setWorkingDirectory ( baseDir );
125
- cmd .createArgument ().setValue ( "." );
126
- cmd .createArgument ( true ).setValue ( "cd" );
171
+ cmd .createArg ().setValue ( "." );
172
+ cmd .createArg ( true ).setValue ( "cd" );
127
173
128
174
// NOTE: cmd.toString() uses CommandLineUtils.toString( String[] ), which *quotes* the result.
129
175
assertEquals ( "cd ." , cmd .toString () );
@@ -134,9 +180,9 @@ public void testSetFile()
134
180
{
135
181
Commandline cmd = new Commandline ( new Shell () );
136
182
cmd .setWorkingDirectory ( baseDir );
137
- cmd .createArgument ().setValue ( "more" );
183
+ cmd .createArg ().setValue ( "more" );
138
184
File f = new File ( "test.txt" );
139
- cmd .createArgument ().setFile ( f );
185
+ cmd .createArg ().setFile ( f );
140
186
String fileName = f .getAbsolutePath ();
141
187
if ( fileName .contains ( " " ) )
142
188
{
@@ -455,7 +501,7 @@ public void testDollarSignInArgumentPath()
455
501
}
456
502
457
503
Commandline cmd = new Commandline ();
458
- // cmd.getShell().setShellCommand( "/bin/sh" );
504
+ cmd .setForceShellOsSpecific ( true );
459
505
cmd .getShell ().setQuotedArgumentsEnabled ( true );
460
506
cmd .setExecutable ( "cat" );
461
507
if ( Os .isFamily ( Os .FAMILY_WINDOWS ) )
0 commit comments