Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GitWrapper
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Georg Seibt
GitWrapper
Commits
cc894a5f
Commit
cc894a5f
authored
8 years ago
by
Georg Seibt
Browse files
Options
Downloads
Patches
Plain Diff
doc
parent
aaf1d04d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/de/uni_passau/fim/seibt/gitwrapper/process/ProcessExecutor.java
+36
-1
36 additions, 1 deletion
..._passau/fim/seibt/gitwrapper/process/ProcessExecutor.java
with
36 additions
and
1 deletion
src/de/uni_passau/fim/seibt/gitwrapper/process/ProcessExecutor.java
+
36
−
1
View file @
cc894a5f
...
...
@@ -8,18 +8,34 @@ import java.util.logging.Logger;
import
org.apache.commons.io.IOUtils
;
/**
* Contains static methods for executing commands and gathering their output and exit code.
*/
public
class
ProcessExecutor
{
private
static
final
Logger
LOG
=
Logger
.
getLogger
(
ProcessExecutor
.
class
.
getCanonicalName
());
/**
* The result of a
command line
execution.
* The result of a
process
execution.
*/
public
static
class
ExecRes
{
public
int
exitCode
;
public
String
output
;
}
/**
* Executes the given <code>cmd</code> with the supplied <code>parameters</code>.
*
* @param cmd
* the command to execute
* @param workingDir
* the working directory for the execution
* @param redirectError
* whether to merge the standard output and error streams
* @param parameters
* the parameters for the command (may be null or none)
* @return the result of the execution or an empty {@link Optional} if there is an exception executing the command
*/
public
static
Optional
<
ExecRes
>
exec
(
String
cmd
,
File
workingDir
,
boolean
redirectError
,
String
...
parameters
)
{
if
(
parameters
==
null
)
{
...
...
@@ -34,6 +50,18 @@ public class ProcessExecutor {
return
exec
(
workingDir
,
redirectError
,
cmdArray
);
}
/**
* Executes the given <code>command</code>. If <code>command</code> is <code>null</code> no var-args are given
* and empty {@link Optional} will be returned.
*
* @param workingDir
* the working directory for the execution
* @param redirectError
* whether to merge the standard output and error streams
* @param command
* the command to be executed
* @return the result of the execution or an empty {@link Optional} if there is an exception executing the command
*/
public
static
Optional
<
ExecRes
>
exec
(
File
workingDir
,
boolean
redirectError
,
String
...
command
)
{
if
(
command
==
null
)
{
...
...
@@ -49,6 +77,13 @@ public class ProcessExecutor {
return
exec
(
builder
);
}
/**
* Executes the command represented by the given <code>builder</code>.
*
* @param builder
* the {@link ProcessBuilder} to be executed
* @return the result of the execution or an empty {@link Optional} if there is an exception executing the command
*/
public
static
Optional
<
ExecRes
>
exec
(
ProcessBuilder
builder
)
{
String
cmd
=
String
.
join
(
" "
,
builder
.
command
());
LOG
.
fine
(()
->
String
.
format
(
"Executing '%s'."
,
cmd
));
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment