@@ -88,6 +88,29 @@ public void testCommandlineWithCommandInConstructor()
88
88
}
89
89
}
90
90
91
+ public void testExecuteBinaryOnPath ()
92
+ {
93
+ try
94
+ {
95
+ // Maven startup script on PATH is required for this test
96
+ Commandline cmd = new Commandline ();
97
+ cmd .setWorkingDirectory ( baseDir );
98
+ cmd .setExecutable ( "mvn" );
99
+ assertEquals ( "mvn" , cmd .getShell ().getOriginalExecutable () );
100
+ cmd .createArg ().setValue ( "-version" );
101
+ Process process = cmd .execute ();
102
+ String out = IOUtil .toString ( process .getInputStream () );
103
+ assertTrue ( out .contains ( "Apache Maven" ) );
104
+ assertTrue ( out .contains ( "Maven home:" ) );
105
+ assertTrue ( out .contains ( "Java version:" ) );
106
+ assertTrue ( out .contains ( "Java home:" ) );
107
+ }
108
+ catch ( Exception e )
109
+ {
110
+ fail ( "Maven startup script seems not on the PATH: " + e .getMessage () );
111
+ }
112
+ }
113
+
91
114
public void testExecute ()
92
115
{
93
116
try
@@ -99,21 +122,8 @@ public void testExecute()
99
122
assertEquals ( "echo" , cmd .getShell ().getOriginalExecutable () );
100
123
cmd .createArgument ().setValue ( "Hello" );
101
124
102
- StringWriter swriter = new StringWriter ();
103
125
Process process = cmd .execute ();
104
-
105
- Reader reader = new InputStreamReader ( process .getInputStream () );
106
-
107
- char [] chars = new char [16 ];
108
- int read = -1 ;
109
- while ( ( read = reader .read ( chars ) ) > -1 )
110
- {
111
- swriter .write ( chars , 0 , read );
112
- }
113
-
114
- String output = swriter .toString ().trim ();
115
-
116
- assertEquals ( "Hello" , output );
126
+ assertEquals ( "Hello" , IOUtil .toString ( process .getInputStream () ).trim () );
117
127
}
118
128
catch ( Exception e )
119
129
{
@@ -248,7 +258,7 @@ public void testGetShellCommandLineBash()
248
258
String expectedShellCmd = "'/bin/echo' 'hello world'" ;
249
259
if ( Os .isFamily ( Os .FAMILY_WINDOWS ) )
250
260
{
251
- expectedShellCmd = "\\ bin\\ echo \' hello world\' " ;
261
+ expectedShellCmd = "' \\ bin\\ echo' \' hello world\' " ;
252
262
}
253
263
assertEquals ( expectedShellCmd , shellCommandline [2 ] );
254
264
}
@@ -307,7 +317,7 @@ public void testGetShellCommandLineBash_WithSingleQuotedArg()
307
317
String expectedShellCmd = "'/bin/echo' ''\" '\" 'hello world'\" '\" ''" ;
308
318
if ( Os .isFamily ( Os .FAMILY_WINDOWS ) )
309
319
{
310
- expectedShellCmd = " \\ bin\\ echo \' hello world \' " ;
320
+ expectedShellCmd = expectedShellCmd . replace ( "/bin/echo" , " \\ bin\\ echo" ) ;
311
321
}
312
322
assertEquals ( expectedShellCmd , shellCommandline [2 ] );
313
323
}
@@ -330,7 +340,7 @@ public void testGetShellCommandLineNonWindows()
330
340
331
341
if ( Os .isFamily ( Os .FAMILY_WINDOWS ) )
332
342
{
333
- assertEquals ( "\\ usr\\ bin a b " , shellCommandline [2 ] );
343
+ assertEquals ( "' \\ usr\\ bin' 'a' 'b' " , shellCommandline [2 ] );
334
344
}
335
345
else
336
346
{
0 commit comments