#!/bin/bash -ex
#
# Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Distribution License v. 1.0, which is available at
# http://www.eclipse.org/org/documents/edl-v10.php.
#
# SPDX-License-Identifier: BSD-3-Clause
#

# service id: ${serviceId}
# stage: ${stage}
L_STATUS=0

if [ "$failFast" = "true" ] && [ "$G_STATUS" = "1" ]
    then return 1
fi;

if [ "$skipTests" != "true" ]; then

    TOTAL_STEPS=$((TOTAL_STEPS+1))

    export CTX="${serviceId}:${stage}-client(${testName})"

    . shared

    prolog $CTX

    log "Running ${testName}"

    # to be sure the directory is there (used in classpath ...)
    #rm -rf client-classes - wsimport can generate sources
    mkdirp client-classes

    CLIENT_CLASSPATH=${classpath}:$SHARED_LIB

     # compile generated client sources
    mkdirp client-source

    collectSources $SHARED_DIR/src/ client-source
    collectSources ../src/common client-source
    collectSources ../src/client client-source
    collectSources bsh/${clientClass}${stage}.java client-source
    collectSources bsh/Util.java client-source

    # copy resources
    if [ -d ../src/resources ]; then
        r cp -rv ../src/resources/* client-classes | true
    fi

    # compile generated bash.Client#.java
    # bsh/${clientClass}${stage}.java bsh/Util.java
    r javac $TOOL_JAVA_OPTS -XDignore.symbol.file -cp client-source:$SHARED_DIR/lib/* -d client-classes `find client-source -name "*.java"`
    compileModuleInfos client-source client-classes

    runClient $CLIENT_CLASSPATH bsh.${clientClass}${stage}
fi;

