---
  # "Deploy an already converted and compiled the application"

  - name: "Check if the deploy zip file exists."
    stat:
       path: "{{ fwd_install_root }}/{{ fwd_app_deploy_zip }}"
    register: deploy_file
    changed_when: false

  - name: "Check if the deploy jar files already exists."
    find:
       paths: "{{ fwd_install_root }}/{{ fwd_app_name }}/build/lib/"
    register: deploy_jars
    changed_when: false

  - name: "Unzip the deployed zip for the converted FWD application code."
    command: unzip -q "{{ fwd_install_root }}/{{ fwd_app_deploy_zip }}" -d "{{ fwd_install_root }}/{{ fwd_app_name }}/"
    register: deploy_files
    when: deploy_file.stat.exists and deploy_jars.matched|int == 0

  - name: "Do a deploy.prepare if application jar exists."
    command: ant deploy.prepare
    args:
       chdir: "{{ fwd_install_root }}/{{ fwd_app_name }}/"
    when: deploy_files.changed
      
  - name: "Build the embedded app"
    command: ant clean jar
    args:
       chdir: "{{ fwd_install_root }}/{{ fwd_app_name }}/embedded/"

  - name: "Ensure that the ownership and permissions are correct (all contents)." 
    file:
       path: "{{ fwd_install_root }}/{{ fwd_app_name }}/"
       state: directory
       follow: no
       recurse: yes
       owner: "{{ fwd_acct_name }}"
       group: "{{ fwd_acct_name }}"
       mode: 0775
       
  - name: "Ensure that the ownership and permissions for the client directory are correct." 
    file:
       path: "{{ fwd_install_root }}/{{ fwd_app_name }}/deploy/client/"
       state: directory
       owner: "{{ user_acct_name }}"
       group: "{{ user_acct_name }}"
       recurse: yes
       mode: 0775

