@Test public void testGetCommandTokens() throws Exception { String cmd = "\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\" --incognito " + "--user-data-dir=\"C:/Program Files/sakuli/sahi/userdata/browser/chrome/profiles/sahi0\" " + "--no-default-browser-check --no-first-run --disable-infobars --proxy-server=localhost:9999"; String[] parsed = Utils.getCommandTokens(cmd); assertLastLine(logFile, "MODIFIED SAHI", LogLevel.INFO, "MODIFIED SAHI COMMAND TOKENS: " + "[C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe, --incognito, " + "C:/Program Files/sakuli/sahi/userdata/browser/chrome/profiles/sahi0, --no-default-browser-check, " + "--no-first-run, --disable-infobars, --proxy-server=localhost:9999]" + " => " + "[C:" + File.separator + "Program Files (x86)" + File.separator + "Google" + File.separator + "Chrome" + File.separator + "Application" + File.separator + "chrome.exe, --incognito, " + "\"--user-data-dir=C:/Program Files/sakuli/sahi/userdata/browser/chrome/profiles/sahi0\", " + "--no-default-browser-check, --no-first-run, --disable-infobars, --proxy-server=localhost:9999]"); Iterator<String> it = Arrays.asList(parsed).iterator(); Assert.assertEquals(it.next(), "C:" + File.separator + "Program Files (x86)" + File.separator + "Google" + File.separator + "Chrome" + File.separator + "Application" + File.separator + "chrome.exe"); Assert.assertEquals(it.next(), "--incognito"); Assert.assertEquals(it.next(), "\"--user-data-dir=C:/Program Files/sakuli/sahi/userdata/browser/chrome/profiles/sahi0\""); Assert.assertEquals(it.next(), "--no-default-browser-check"); Assert.assertEquals(it.next(), "--no-first-run"); Assert.assertEquals(it.next(), "--disable-infobars"); Assert.assertEquals(it.next(), "--proxy-server=localhost:9999"); }
@Around("execution(* net.sf.sahi.util.Utils.getCommandTokens(..)) && args(commandString)") public String[] getCommandTokens(ProceedingJoinPoint joinPoint, String commandString) { Logger LOGGER = getLogger(joinPoint); CommandLine parsed = CommandLine.parse(commandString); String[] tokens = new String[]{parsed.getExecutable()}; tokens = ArrayUtils.addAll(tokens, parsed.getArguments()); try { Object result = joinPoint.proceed(); if (result instanceof String[] && !Arrays.equals(tokens, (String[]) result)) { if (commandString.startsWith("sh -c \'")) { return (String[]) result; } LOGGER.info("MODIFIED SAHI COMMAND TOKENS: {} => {}", printArray((String[]) result), printArray(tokens)); } } catch (Throwable e) { LOGGER.error("Exception during execution of JoinPoint net.sf.sahi.util.Utils.getCommandTokens", e); } return tokens; }
SahiCommandExecutionAspect extends BaseSakuliAspect { @Around("execution(* net.sf.sahi.util.Utils.getCommandTokens(..)) && args(commandString)") public String[] getCommandTokens(ProceedingJoinPoint joinPoint, String commandString) { Logger LOGGER = getLogger(joinPoint); CommandLine parsed = CommandLine.parse(commandString); String[] tokens = new String[]{parsed.getExecutable()}; tokens = ArrayUtils.addAll(tokens, parsed.getArguments()); try { Object result = joinPoint.proceed(); if (result instanceof String[] && !Arrays.equals(tokens, (String[]) result)) { if (commandString.startsWith("sh -c \'")) { return (String[]) result; } LOGGER.info("MODIFIED SAHI COMMAND TOKENS: {} => {}", printArray((String[]) result), printArray(tokens)); } } catch (Throwable e) { LOGGER.error("Exception during execution of JoinPoint net.sf.sahi.util.Utils.getCommandTokens", e); } return tokens; } }
SahiCommandExecutionAspect extends BaseSakuliAspect { @Around("execution(* net.sf.sahi.util.Utils.getCommandTokens(..)) && args(commandString)") public String[] getCommandTokens(ProceedingJoinPoint joinPoint, String commandString) { Logger LOGGER = getLogger(joinPoint); CommandLine parsed = CommandLine.parse(commandString); String[] tokens = new String[]{parsed.getExecutable()}; tokens = ArrayUtils.addAll(tokens, parsed.getArguments()); try { Object result = joinPoint.proceed(); if (result instanceof String[] && !Arrays.equals(tokens, (String[]) result)) { if (commandString.startsWith("sh -c \'")) { return (String[]) result; } LOGGER.info("MODIFIED SAHI COMMAND TOKENS: {} => {}", printArray((String[]) result), printArray(tokens)); } } catch (Throwable e) { LOGGER.error("Exception during execution of JoinPoint net.sf.sahi.util.Utils.getCommandTokens", e); } return tokens; }  }
SahiCommandExecutionAspect extends BaseSakuliAspect { @Around("execution(* net.sf.sahi.util.Utils.getCommandTokens(..)) && args(commandString)") public String[] getCommandTokens(ProceedingJoinPoint joinPoint, String commandString) { Logger LOGGER = getLogger(joinPoint); CommandLine parsed = CommandLine.parse(commandString); String[] tokens = new String[]{parsed.getExecutable()}; tokens = ArrayUtils.addAll(tokens, parsed.getArguments()); try { Object result = joinPoint.proceed(); if (result instanceof String[] && !Arrays.equals(tokens, (String[]) result)) { if (commandString.startsWith("sh -c \'")) { return (String[]) result; } LOGGER.info("MODIFIED SAHI COMMAND TOKENS: {} => {}", printArray((String[]) result), printArray(tokens)); } } catch (Throwable e) { LOGGER.error("Exception during execution of JoinPoint net.sf.sahi.util.Utils.getCommandTokens", e); } return tokens; }  @Around("execution(* net.sf.sahi.util.Utils.getCommandTokens(..)) && args(commandString)") String[] getCommandTokens(ProceedingJoinPoint joinPoint, String commandString); @AfterThrowing(pointcut = "execution(* net.sf.sahi.util.Utils.execute*(..))", throwing = "error") void catchSahiCommandExcecutionErrors(JoinPoint joinPoint, Exception error); @Before("execution(* net.sf.sahi.util.Utils.execute*(..))") void logSahiCommandExection(JoinPoint joinPoint); }
SahiCommandExecutionAspect extends BaseSakuliAspect { @Around("execution(* net.sf.sahi.util.Utils.getCommandTokens(..)) && args(commandString)") public String[] getCommandTokens(ProceedingJoinPoint joinPoint, String commandString) { Logger LOGGER = getLogger(joinPoint); CommandLine parsed = CommandLine.parse(commandString); String[] tokens = new String[]{parsed.getExecutable()}; tokens = ArrayUtils.addAll(tokens, parsed.getArguments()); try { Object result = joinPoint.proceed(); if (result instanceof String[] && !Arrays.equals(tokens, (String[]) result)) { if (commandString.startsWith("sh -c \'")) { return (String[]) result; } LOGGER.info("MODIFIED SAHI COMMAND TOKENS: {} => {}", printArray((String[]) result), printArray(tokens)); } } catch (Throwable e) { LOGGER.error("Exception during execution of JoinPoint net.sf.sahi.util.Utils.getCommandTokens", e); } return tokens; }  @Around("execution(* net.sf.sahi.util.Utils.getCommandTokens(..)) && args(commandString)") String[] getCommandTokens(ProceedingJoinPoint joinPoint, String commandString); @AfterThrowing(pointcut = "execution(* net.sf.sahi.util.Utils.execute*(..))", throwing = "error") void catchSahiCommandExcecutionErrors(JoinPoint joinPoint, Exception error); @Before("execution(* net.sf.sahi.util.Utils.execute*(..))") void logSahiCommandExection(JoinPoint joinPoint);  }