import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
/**
* Applet providing a set of buttons. Each button is defined by three parameters:<BR>
*/
private static final long serialVersionUID = 3243053622061086715L;
+ /**
+ * The name of the script to run Salome.
+ */
+ private static final String RUN_SALOME_SCRIPT = "run_salome_siman";
+ /**
+ * Possible script extensions.
+ */
+ private static final String[] SCRIPT_EXT = { "", ".sh", ".bat", ".cmd" };
/**
* The response key string: '<i>"canCheckout"</i> :'.
*/
}
}
} catch (Exception error) {
- error.printStackTrace(); // RKV: NOPMD: TODO: try to use logger
+ error.printStackTrace(); // RKV: NOPMD: Applet output
}
}
} else if (!SALOME_HOME.endsWith(File.separator)) {
SALOME_HOME += File.separator;
}
- String pathToScript = SALOME_HOME + "runSalome";
-
- // Look for the launching script in the file system
+ String pathToScript = SALOME_HOME + File.separator + RUN_SALOME_SCRIPT;
File script = new File(pathToScript);
- if (!script.exists()) {
- script = new File(pathToScript + ".bat");
- if (!script.exists()) {
- script = new File(pathToScript + ".cmd");
+ String extensions = "";
+ // Look for the launching script in the file system
+ for (String ext : SCRIPT_EXT) {
+ script = new File(pathToScript + ext); // RKV: NOPMD: There are not so much extensions
+ if (script.exists()) {
+ break;
}
+ extensions += "|" + ext;
}
if (script.exists()) {
// Call to the Siman server to checkout the scenario
URL checkoutUrl = new URL(getCodeBase().toString()
+ "checkout.action?"
- + params.replaceAll("siman-", "").replaceAll("--", "-")
- .replaceAll("-", "&").replaceAll("\\s", ""));
+ + params.replaceAll("--siman-", "&").replaceAll("\\s", ""));
BufferedReader buffer = new BufferedReader(new InputStreamReader(
checkoutUrl.openStream()));
if (isOk) {
// Execute the runSalome script.
// filename here indeed a string containing parameters for runSalome.
- Runtime.getRuntime().exec(
- new String[] { script.getAbsolutePath(), params });
+ List<String> cmd = new ArrayList<String>(Arrays.asList(params
+ .split("\\s")));
+ cmd.add(0, script.getAbsolutePath());
+ Process proc = Runtime.getRuntime().exec(
+ cmd.toArray(new String[] {}), null,
+ new File(SALOME_HOME));
// Refresh the current scenario view
- getAppletContext().showDocument(new URL(this.getParameter("refresh")));
+ getAppletContext().showDocument(
+ new URL(this.getParameter("refresh")));
+ BufferedReader bri = new BufferedReader(new InputStreamReader(
+ proc.getInputStream()));
+ BufferedReader bre = new BufferedReader(new InputStreamReader(
+ proc.getErrorStream()));
+ String line = bri.readLine();
+ while (line != null) {
+ System.out.println(line); // RKV: NOPMD: Applet output
+ line = bri.readLine();
+ }
+ bri.close();
+ line = bre.readLine();
+ while (line != null) {
+ System.out.println(line); // RKV: NOPMD: Applet output
+ line = bre.readLine();
+ }
+ bre.close();
} else {
// Checkout of the scenario is failed at the beginning.
if (response != null) {
showError(response);
}
} else {
- showError("SALOME module is not found: " + script.getAbsolutePath());
+ extensions = "[" + extensions.replaceAll("\\|\\|", "") + "]";
+ showError("SALOME module is not found: " + pathToScript
+ + extensions);
throw new ConfigurationException("SALOME module is not found: "
- + script.getAbsolutePath());
+ + pathToScript + extensions);
}
}