---
apiVersion: 1.0.0
metadata:
  generateName: java-eap-maven-
projects:
  -
    name: kitchensink-example
    source:
      location: 'https://github.com/jboss-developer/jboss-eap-quickstarts.git'
      type: git
      tag: EAP_7.3.0.GA
      sparseCheckoutDir: kitchensink-jsp
components:
  -
    type: chePlugin
    id: redhat/java8/latest
  -
    # NOTE: instead of the old stack-analysis script, should be able to use the latest dependency-analysis plugin instead
    type: chePlugin
    id: redhat/dependency-analytics/latest
  -
    type: dockerimage
    alias: maven
    image: registry.redhat.io/jboss-eap-7/eap73-openjdk8-openshift-rhel7:7.3.6
    env:
      - name: MAVEN_OPTS
        value: "-Xmx200m -XX:+UseParallelGC -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xms20m -Djava.security.egd=file:/dev/./urandom -Duser.home=/home/jboss"
      - name: JAVA_OPTS_APPEND
        value: "-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n -Dsun.util.logging.disableCallerCheck=true"
      - name: MVN_ARGS_APPEND
        value: '-Dmaven.repo.local=/home/jboss/.m2/repository -Dcom.redhat.xpaas.repo.jbossorg'        
    memoryLimit: 1024Mi
    endpoints:
      - name: 'eap'
        port: 8080
        attributes:
          path: /index.jsp
      - name: 'jgroups'
        port: 7600
        attributes:
          public: 'false'
    mountSources: true
    volumes:
      - name: m2
        containerPath: /home/jboss/.m2/repository
commands:
  -
    name: 1. Build
    actions:
      - workdir: '${CHE_PROJECTS_ROOT}/kitchensink-example/kitchensink-jsp'
        type: exec
        command: scl enable rh-maven35 'mvn ${MVN_ARGS_APPEND} clean install'
        component: maven
  - name: 2. Configure web server
    actions:
      - workdir: /opt/eap/bin
        type: exec
        command: >-
          ./jboss-cli.sh --connect --command="data-source add --name=ExampleDS
          --jndi-name=java:jboss/datasources/ExampleDS --driver-name=h2
          --connection-url=jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
          --user-name=sa --password=sa" && echo 'Server was configured'
        component: maven
  -
    name: 3. Copy war
    actions:
      -
        type: exec
        component: maven
        command: cp target/*.war /opt/eap/standalone/deployments/ROOT.war && 
          echo 'Archive was deployed, click on eap endpoint from Workspace view to open the application'
        workdir: ${CHE_PROJECTS_ROOT}/kitchensink-example/kitchensink-jsp
  -
    name: 4. Hot update
    actions:
      -
        type: exec
        component: maven
        command: "scl enable rh-maven35 'mvn ${MVN_ARGS_APPEND} clean install' && sleep 2 && cp target/*.war /opt/eap/standalone/deployments/ROOT.war"
        workdir: ${CHE_PROJECTS_ROOT}/kitchensink-example/kitchensink-jsp
  -
    name: Debug (Attach)
    actions:
    - type: vscode-launch
      referenceContent: |
        {
        "version": "0.2.0",
        "configurations": [
        {
            "type": "java",
            "request": "attach",
            "name": "Debug (Attach)",
            "hostName": "localhost",
            "port": 8000
        }
        ]
        }
