org.sitoolkit.wt.gui.domain.test.SitWtRuntimeUtils Maven / Gradle / Ivy
package org.sitoolkit.wt.gui.domain.test;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.sitoolkit.wt.gui.infra.UnInitializedException;
import org.sitoolkit.wt.util.infra.util.StrUtils;
public class SitWtRuntimeUtils {
private static final Logger LOG = Logger.getLogger(SitWtRuntimeUtils.class.getName());
private static String sitwtClasspath;
private static String javaHome;
private static final Pattern SCRIPT_FILE_PATTERN = Pattern
.compile(".*\\.xlsx$|.*\\.xls$|.*\\.csv$|.*\\.html$");
public static String buildScriptStr(List selectedFiles) {
return StrUtils.join(filterTestScripts(selectedFiles));
}
public static String buildScriptStr(File testScript, List caseNos) {
StringBuilder sb = new StringBuilder();
String testScriptPath = testScript.getAbsolutePath();
for (String caseNo : caseNos) {
if (sb.length() != 0)
sb.append(",");
sb.append(testScriptPath);
sb.append("#");
sb.append(caseNo);
}
return sb.toString();
}
public static List filterTestScripts(List selectedFiles) {
return selectedFiles.stream()
.filter(file -> SCRIPT_FILE_PATTERN.matcher(file.getName()).matches())
.collect(Collectors.toList());
}
public static void putJavaHome(Map map) {
if (javaHome == null) {
javaHome = System.getProperty("java.home");
LOG.log(Level.INFO, "set JAVA_HOME to {0}", new Object[] { javaHome });
}
map.put("JAVA_HOME", javaHome);
}
public static List buildPage2ScriptCommand(String browser, String baseUrl) {
List command = buildJavaCommand();
addVmArgs(command, browser, baseUrl);
command.add("org.sitoolkit.wt.app.page2script.Page2Script");
return command;
}
public static List buildOpe2ScriptCommand(String url) {
List command = buildJavaCommand();
if (StrUtils.isNotEmpty(url)) {
command.add("-Durl=" + url);
}
command.add("org.sitoolkit.wt.app.ope2script.FirefoxOpener");
return command;
}
public static List buildJavaCommand() {
List command = new ArrayList<>();
command.add("java");
command.add("-cp");
command.add(getSitWtClasspath());
return command;
}
public static void addVmArgs(List command, String browser, String baseUrl) {
command.add("-Ddriver.type=" + browser);
command.add("-Dsitwt.cli=false");
if (StrUtils.isNotEmpty(baseUrl)) {
command.add("-DbaseUrl=" + baseUrl);
}
}
static String getSitWtClasspath() {
if (sitwtClasspath == null) {
throw new UnInitializedException();
}
return sitwtClasspath;
}
public static void setSitWtClasspath(String sitwtClasspath) {
SitWtRuntimeUtils.sitwtClasspath = sitwtClasspath;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy