Skip to content
This repository has been archived by the owner on May 23, 2019. It is now read-only.

Commit

Permalink
Correct #207
Browse files Browse the repository at this point in the history
  • Loading branch information
hdsdi3g committed Nov 13, 2016
1 parent 580954a commit 072f8f0
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 6 deletions.
7 changes: 6 additions & 1 deletion app/hd3gtv/mydmam/web/NodeJSBabel.java
Expand Up @@ -31,6 +31,7 @@
import hd3gtv.mydmam.MyDMAM;
import hd3gtv.tools.CopyMove;
import hd3gtv.tools.ExecBinaryPath;
import hd3gtv.tools.ExecprocessBadExecutionException;
import hd3gtv.tools.ExecprocessGettext;
import hd3gtv.tools.ExecprocessOutputstreamHandler;

Expand Down Expand Up @@ -138,7 +139,11 @@ private void checkNPMVersion() throws IOException {
List<String> params = Arrays.asList("-v");
File npm_executable = ExecBinaryPath.get("npm");
ExecprocessGettext exec = new ExecprocessGettext(npm_executable, params);
exec.start();
try {
exec.start();
} catch (ExecprocessBadExecutionException e) {
throw new IOException("Problem with node exec \"" + exec.getResultstderr().toString() + "\"", e);
}
String npm_version = exec.getResultstdout().toString().trim();

if (MyDMAM.versionCompare(npm_version, MIN_NPM_VERSION) < 0) {
Expand Down
37 changes: 32 additions & 5 deletions app/hd3gtv/tools/ExecBinaryPath.java
Expand Up @@ -19,8 +19,11 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BinaryOperator;

import org.apache.commons.lang.SystemUtils;
import org.apache.log4j.Logger;
Expand All @@ -34,12 +37,30 @@ public class ExecBinaryPath {
private ExecBinaryPath() {
}

public static final String[] PATH;
private static final ArrayList<String> PATHS;
private static final HashMap<String, File> declared_in_configuration;
private final static String[] WINDOWS_EXEC_EXTENTIONS = { "exe", "com", "bat", "cmd" };

static {
PATH = System.getenv("PATH").split(File.pathSeparator);
String[] PATH = System.getenv("PATH").split(File.pathSeparator);
PATHS = new ArrayList<>(Arrays.asList(PATH));

String user_home = System.getProperty("user.home");

ArrayList<String> all_configured_execpath = Configuration.global.getValues("execpath", "sets", null);
if (all_configured_execpath != null) {
all_configured_execpath.forEach(entry -> {
File test = new File(entry);
if (test.exists() == false) {
test = new File(user_home + File.separator + entry);
}

if (test.exists() && test.isDirectory() && test.canRead()) {
PATHS.add(test.getAbsolutePath());
}
});
}

declared_in_configuration = new HashMap<String, File>();

Map<String, String> values = Configuration.global.getValues("executables");
Expand All @@ -57,6 +78,12 @@ private ExecBinaryPath() {
}
}

public static String getFullPath() {
return PATHS.stream().reduce((BinaryOperator<String>) (left, right) -> {
return left + File.pathSeparator + right;
}).get();
}

private static boolean validExec(File exec) {
if (exec.exists() == false) {
return false;
Expand Down Expand Up @@ -93,14 +120,14 @@ public static File get(String name) throws IOException {
return exec;
}

for (int pos_path = 0; pos_path < PATH.length; pos_path++) {
exec = new File(PATH[pos_path] + File.separator + name);
for (int pos_path = 0; pos_path < PATHS.size(); pos_path++) {
exec = new File(PATHS.get(pos_path) + File.separator + name);
if (validExec(exec)) {
return exec;
}
if (SystemUtils.IS_OS_WINDOWS) {
for (int pos_w_exe = 0; pos_w_exe < WINDOWS_EXEC_EXTENTIONS.length; pos_w_exe++) {
exec = new File(PATH[pos_path] + File.separator + name + "." + WINDOWS_EXEC_EXTENTIONS[pos_w_exe]);
exec = new File(PATHS.get(pos_path) + File.separator + name + "." + WINDOWS_EXEC_EXTENTIONS[pos_w_exe]);
if (validExec(exec)) {
return exec;
}
Expand Down
2 changes: 2 additions & 0 deletions app/hd3gtv/tools/Execprocess.java
Expand Up @@ -128,7 +128,9 @@ public void run() {
status = STATE_RUNNIG;

pb = new ProcessBuilder(processinfo);

pb.environment().put("LANG", Locale.getDefault().getLanguage() + "_" + Locale.getDefault().getCountry() + "." + Charset.forName("UTF-8"));
pb.environment().put("PATH", ExecBinaryPath.getFullPath());

if (working_directory != null) {
pb.directory(working_directory);
Expand Down
1 change: 1 addition & 0 deletions app/hd3gtv/tools/ExecprocessBadExecutionException.java
Expand Up @@ -26,6 +26,7 @@ public class ExecprocessBadExecutionException extends IOException {
private int returncode;

ExecprocessBadExecutionException(String processname, String commandline, int returncode) {
super("Exec \"" + commandline + "\" return code " + returncode);
this.commandline = commandline;
this.returncode = returncode;
this.processname = processname;
Expand Down
5 changes: 5 additions & 0 deletions conf/app.d-examples/executables.yml.example
Expand Up @@ -6,3 +6,8 @@ executables:
mxf2raw: /usr/bin/mxf2raw
bmxtranswrap: /usr/bin/bmxtranswrap

# Use exepath for add to current PATH (for Java only) some local or external binary path and avoid to add manually executables.
#execpath:
# sets:
# - App/bin
# - App/macport/bin

0 comments on commit 072f8f0

Please sign in to comment.