-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
123 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/org/moeaframework/problem/NativeCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.moeaframework.problem; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class NativeCommand { | ||
|
||
private final String executableName; | ||
|
||
private final String[] arguments; | ||
|
||
private final File workingDirectory; | ||
|
||
public NativeCommand(String executableName, String[] arguments, File workingDirectory) { | ||
super(); | ||
this.executableName = executableName; | ||
this.arguments = arguments; | ||
this.workingDirectory = workingDirectory; | ||
} | ||
|
||
public String getExecutableName() { | ||
return executableName; | ||
} | ||
|
||
public String[] getArguments() { | ||
return arguments; | ||
} | ||
|
||
public File getWorkingDirectory() { | ||
return workingDirectory; | ||
} | ||
|
||
public Process exec() throws IOException { | ||
return toProcessBuilder(OsType.getOsType()).start(); | ||
} | ||
|
||
public ProcessBuilder toProcessBuilder(OsType osType) { | ||
List<String> command = new ArrayList<String>(); | ||
|
||
switch (osType) { | ||
case WINDOWS: | ||
command.add(new File(getWorkingDirectory(), getExecutableName() + ".exe").getPath()); | ||
break; | ||
case POSIX: | ||
command.add(new File(".", getExecutableName()).getPath()); | ||
break; | ||
default: | ||
throw new IllegalArgumentException("Unsupported OS " + osType); | ||
} | ||
|
||
command.addAll(List.of(getArguments())); | ||
|
||
return new ProcessBuilder() | ||
.command(command) | ||
.directory(getWorkingDirectory()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.moeaframework.problem; | ||
|
||
import org.apache.commons.lang3.SystemUtils; | ||
|
||
public enum OsType { | ||
|
||
/** | ||
* Windows. | ||
*/ | ||
WINDOWS, | ||
|
||
/** | ||
* POSIX compatible systems, such as Unix, Linux, etc. | ||
*/ | ||
POSIX; | ||
|
||
public static OsType getOsType() { | ||
if (SystemUtils.IS_OS_WINDOWS) { | ||
return WINDOWS; | ||
} else { | ||
return POSIX; | ||
} | ||
} | ||
|
||
} |