Java Code Examples for com.intuit.karate.FileUtils#getBuildDir()

The following examples show how to use com.intuit.karate.FileUtils#getBuildDir() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Main.java    From karate with MIT License 6 votes vote down vote up
public static void main(String[] args) {
    String command;
    if (args.length > 0) {
        command = StringUtils.join(args, ' ');
    } else {
        command = System.getProperty("sun.java.command");
    }
    System.out.println("command: " + command);
    boolean isIntellij = command.contains("org.jetbrains");
    RunnerOptions ro = RunnerOptions.parseCommandLine(command);
    String targetDir = FileUtils.getBuildDir() + File.separator + "surefire-reports";
    int debugPort = ro.getDebugPort();
    if (debugPort != -1) {
        DapServer server = new DapServer(debugPort);
        server.waitSync();
        return;
    }
    CliExecutionHook hook = new CliExecutionHook(true, targetDir, isIntellij);
    Runner.path(ro.getFeatures())
            .tags(ro.getTags()).scenarioName(ro.getName())
            .hook(hook).parallel(ro.getThreads());
}
 
Example 2
Source File: DapServer.java    From karate with MIT License 5 votes vote down vote up
public DapServer(int requestedPort) {
    bossGroup = new NioEventLoopGroup(1);
    workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup)
                .channel(NioServerSocketChannel.class)
                // .handler(new LoggingHandler(getClass().getName(), LogLevel.TRACE))
                .childHandler(new ChannelInitializer() {
                    @Override
                    protected void initChannel(Channel c) {
                        ChannelPipeline p = c.pipeline();
                        p.addLast(new DapDecoder());
                        p.addLast(new DapEncoder());
                        p.addLast(new DapServerHandler(DapServer.this));
                    }
                });
        channel = b.bind(requestedPort).sync().channel();
        InetSocketAddress isa = (InetSocketAddress) channel.localAddress();
        host = "127.0.0.1"; //isa.getHostString();
        port = isa.getPort();
        logger.info("debug server started on port: {}", port);
        String buildDir = FileUtils.getBuildDir();
        FileUtils.writeToFile(new File(buildDir + File.separator + "karate-debug-port.txt"), port + "");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 3
Source File: JobExecutor.java    From karate with MIT License 5 votes vote down vote up
private JobExecutor(String serverUrl) {
    this.serverUrl = serverUrl;
    String targetDir = FileUtils.getBuildDir();
    appender = new FileLogAppender(new File(targetDir + File.separator + "karate-executor.log"));
    logger = new Logger();
    logger.setAppender(appender);
    if (!Command.waitForHttp(serverUrl)) {
        logger.error("unable to connect to server, aborting");
        System.exit(1);
    }
    http = Http.forUrl(appender, serverUrl);
    http.config("lowerCaseResponseHeaders", "true");
    // download ============================================================
    JobMessage download = invokeServer(new JobMessage("download"));
    logger.info("download response: {}", download);
    jobId = download.getJobId();
    executorId = download.getExecutorId();
    workingDir = FileUtils.getBuildDir() + File.separator + jobId + "_" + executorId;
    byte[] bytes = download.getBytes();
    File file = new File(workingDir + ".zip");
    FileUtils.writeToFile(file, bytes);
    JobUtils.unzip(file, new File(workingDir));
    logger.info("download done: {}", workingDir);
    // init ================================================================
    JobMessage init = invokeServer(new JobMessage("init").put("log", appender.collect()));
    logger.info("init response: {}", init);
    uploadDir = workingDir + File.separator + init.get(JobContext.UPLOAD_DIR, String.class);
    List<JobCommand> startupCommands = init.getCommands("startupCommands");
    environment = init.get("environment", Map.class);
    executeCommands(startupCommands, environment);
    shutdownCommands = init.getCommands("shutdownCommands");
    logger.info("init done");        
}
 
Example 4
Source File: ScenarioJobServer.java    From karate with MIT License 5 votes vote down vote up
@Override
public void handleUpload(File upload, String executorId, String chunkId) {
    File jsonFile = getFirstFileWithExtension(upload, "json");
    if (jsonFile == null) {
        return;
    }
    String json = FileUtils.toString(jsonFile);
    File videoFile = getFirstFileWithExtension(upload, "mp4");
    List<Map<String, Object>> list = JsonUtils.toJsonDoc(json).read("$[0].elements");
    synchronized (CHUNK_RESULTS) {
        ChunkResult cr = CHUNK_RESULTS.remove(chunkId);
        LOGGER.info("chunk complete: {}, remaining: {}", chunkId, CHUNK_RESULTS.keySet());
        if (cr == null) {
            LOGGER.error("could not find chunk: {}", chunkId);
            return;
        }
        ScenarioResult sr = new ScenarioResult(cr.scenario, list, true);
        sr.setStartTime(cr.getStartTime());
        sr.setEndTime(System.currentTimeMillis());
        sr.setThreadName(executorId);
        cr.setResult(sr);
        if (videoFile != null) {
            File dest = new File(FileUtils.getBuildDir()
                    + File.separator + "cucumber-html-reports" + File.separator + chunkId + ".mp4");
            FileUtils.copy(videoFile, dest);
            sr.appendEmbed(Embed.forVideoFile(dest.getName()));
        }
        if (cr.parent.isComplete()) {
            LOGGER.info("feature complete, calling onComplete(): {}", cr.parent);
            cr.parent.onComplete();
        }
    }
}
 
Example 5
Source File: JobServer.java    From karate with MIT License 5 votes vote down vote up
public JobServer(JobConfig config, String reportDir) {
    this.config = config;
    this.reportDir = reportDir;
    jobId = System.currentTimeMillis() + "";
    basePath = FileUtils.getBuildDir() + File.separator + jobId;
    ZIP_FILE = new File(basePath + ".zip");
    JobUtils.zip(new File(config.getSourcePath()), ZIP_FILE);
    LOGGER.info("created zip archive: {}", ZIP_FILE);
    bossGroup = new NioEventLoopGroup(1);
    workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup)
                .channel(NioServerSocketChannel.class)
                // .handler(new LoggingHandler(getClass().getName(), LogLevel.TRACE))
                .childHandler(new ChannelInitializer() {
                    @Override
                    protected void initChannel(Channel c) {
                        ChannelPipeline p = c.pipeline();
                        // just to make header size more than the default
                        p.addLast(new HttpServerCodec(4096, 12288, 8192));
                        p.addLast(new HttpObjectAggregator(1048576));
                        p.addLast(new ScenarioJobServerHandler(JobServer.this));
                    }
                });
        channel = b.bind(config.getPort()).sync().channel();
        InetSocketAddress isa = (InetSocketAddress) channel.localAddress();
        port = isa.getPort();
        jobUrl = "http://" + config.getHost() + ":" + port;
        LOGGER.info("job server started - {} - {}", jobUrl, jobId);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 6
Source File: ScriptBridge.java    From karate with MIT License 5 votes vote down vote up
public File write(Object o, String path) {
    ScriptValue sv = new ScriptValue(o);
    path = FileUtils.getBuildDir() + File.separator + path;
    File file = new File(path);
    FileUtils.writeToFile(file, sv.getAsByteArray());
    return file;
}
 
Example 7
Source File: DriverOptions.java    From karate with MIT License 4 votes vote down vote up
public DriverOptions(ScenarioContext context, Map<String, Object> options, LogAppender appender, int defaultPort, String defaultExecutable) {
    this.context = context;
    this.options = options;
    this.appender = appender;
    logger = new Logger(getClass());
    logger.setAppender(appender);
    timeout = get("timeout", DEFAULT_TIMEOUT);
    type = get("type", null);
    start = get("start", true);
    executable = get("executable", defaultExecutable);
    headless = get("headless", false);
    showProcessLog = get("showProcessLog", false);
    addOptions = get("addOptions", null);
    uniqueName = type + "_" + System.currentTimeMillis();
    String packageName = getClass().getPackage().getName();
    processLogger = showProcessLog ? logger : new Logger(packageName + "." + uniqueName);
    showDriverLog = get("showDriverLog", false);
    driverLogger = showDriverLog ? logger : new Logger(packageName + "." + uniqueName);
    if (executable != null) {
        if (executable.startsWith(".")) { // honor path even when we set working dir
            args.add(new File(executable).getAbsolutePath());
        } else {
            args.add(executable);
        }
    }
    workingDir = new File(FileUtils.getBuildDir() + File.separator + uniqueName);
    workingDirPath = workingDir.getAbsolutePath();
    processLogFile = workingDir.getPath() + File.separator + type + ".log";
    maxPayloadSize = get("maxPayloadSize", 4194304);
    target = get("target", null);
    host = get("host", "localhost");
    webDriverUrl = get("webDriverUrl", null);
    webDriverPath = get("webDriverPath", null);
    webDriverSession = get("webDriverSession", null);
    httpConfig = get("httpConfig", null);
    beforeStart = get("beforeStart", null);
    afterStop = get("afterStop", null);
    videoFile = get("videoFile", null);
    pollAttempts = get("pollAttempts", 20);
    pollInterval = get("pollInterval", 250);
    // do this last to ensure things like logger, start-flag, webDriverUrl etc. are set
    port = resolvePort(defaultPort);
}
 
Example 8
Source File: Command.java    From karate with MIT License 4 votes vote down vote up
public static String getBuildDir() {
    return FileUtils.getBuildDir();
}
 
Example 9
Source File: ScenarioExecutionUnit.java    From karate with MIT License 4 votes vote down vote up
@Override
protected LogAppender initialValue() {
    String fileName = FileUtils.getBuildDir() + File.separator + Thread.currentThread().getName() + ".log";
    return new FileLogAppender(new File(fileName));
}