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
9fd3e8df
Commit
9fd3e8df
authored
8 years ago
by
Georg Seibt
Browse files
Options
Downloads
Patches
Plain Diff
concatenation method for array+varargs
parent
b1d70360
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
+33
-7
33 additions, 7 deletions
..._passau/fim/seibt/gitwrapper/process/ProcessExecutor.java
with
33 additions
and
7 deletions
src/de/uni_passau/fim/seibt/gitwrapper/process/ProcessExecutor.java
+
33
−
7
View file @
9fd3e8df
...
...
@@ -2,9 +2,11 @@ package de.uni_passau.fim.seibt.gitwrapper.process;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.Arrays
;
import
java.util.Optional
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
java.util.stream.Stream
;
import
org.apache.commons.io.IOUtils
;
...
...
@@ -42,12 +44,7 @@ public class ProcessExecutor {
return
exec
(
workingDir
,
redirectError
,
cmd
);
}
String
[]
cmdArray
=
new
String
[
parameters
.
length
+
1
];
cmdArray
[
0
]
=
cmd
;
System
.
arraycopy
(
parameters
,
0
,
cmdArray
,
1
,
parameters
.
length
);
return
exec
(
workingDir
,
redirectError
,
cmdArray
);
return
exec
(
workingDir
,
redirectError
,
merge
(
false
,
parameters
,
cmd
));
}
/**
...
...
@@ -92,8 +89,8 @@ public class ProcessExecutor {
ExecRes
res
=
new
ExecRes
();
Process
p
=
builder
.
start
();
res
.
output
=
IOUtils
.
toString
(
p
.
getInputStream
());
res
.
exitCode
=
p
.
waitFor
();
res
.
output
=
IOUtils
.
toString
(
p
.
getInputStream
());
LOG
.
fine
(()
->
String
.
format
(
"Execution of '%s' returned exit code %d."
,
cmd
,
res
.
exitCode
));
LOG
.
finest
(()
->
String
.
format
(
"Execution of '%s' output:%n%s"
,
cmd
,
res
.
output
.
trim
()));
...
...
@@ -104,4 +101,33 @@ public class ProcessExecutor {
return
Optional
.
empty
();
}
}
/**
* Returns an array representing the concatenation of <code>arr</code> and <code>varArgs</code> in the order defined
* by <code>av</code>. If one of <code>arr</code> and <code>varArgs</code> is null, the other one is returned.
*
* @param av
* if true returns [arr] + [varArgs] otherwise returns [varArgs] + [arr]
* @param arr
* the array
* @param varArgs
* the variable number of arguments
* @return the concatenation
*/
public
static
String
[]
merge
(
boolean
av
,
String
[]
arr
,
String
...
varArgs
)
{
if
(
arr
!=
null
&&
varArgs
==
null
)
{
return
arr
;
}
else
if
(
arr
==
null
&&
varArgs
!=
null
)
{
return
varArgs
;
}
else
if
(
arr
==
null
&&
varArgs
==
null
){
throw
new
IllegalArgumentException
(
"Both arr and varArgs are null!"
);
}
if
(
av
)
{
return
Stream
.
concat
(
Arrays
.
stream
(
arr
),
Arrays
.
stream
(
varArgs
)).
toArray
(
String
[]::
new
);
}
else
{
return
Stream
.
concat
(
Arrays
.
stream
(
varArgs
),
Arrays
.
stream
(
arr
)).
toArray
(
String
[]::
new
);
}
}
}
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