---
-
  name: "Checking if java build tools has been deployed"
  register: build_tools_deployed
  ansible.builtin.stat:
    path: "{{ completed_dir }}/javabuildtools"
    get_md5: false

-
  name: "Copying Java helper applications"
  ansible.builtin.copy:
    mode: '0644'
    src: "{{ item }}"
    dest: "{{ service_home_dir }}"
    remote_src: true
    owner: "{{ service_user }}"
  with_items:
    - "{{ installer_dir }}/domino-java-helpers/JavaTest/CreateNamesDatabase.jar"
    - "{{ installer_dir }}/domino-java-helpers/JavaTest/Notes.jar"
    - "{{ installer_dir }}/domino-java-helpers/CreateNamesDatabase.exp"
  when: java_helpers_install and build_utility_jars and not build_tools_deployed.stat.exists

-
  name: "Changing file ownership, group and permissions of Java Build Files"
  when: build_utility_jars and not build_tools_deployed.stat.exists
  ansible.builtin.file:
    path: "/vagrant/installers/domino-java-helpers"
    owner: "{{ service_user }}"
    group: "{{ service_group }}"
    mode: '0777'
    recurse: true

-
  name: "Creating Templated CrossCertify Java file"
  when: build_utility_jars and not build_tools_deployed.stat.exists
  ansible.builtin.template:
    dest: "{{ installer_dir }}/domino-java-helpers/src/main/java/net/prominic/domino/vagrant/CrossCertifyNotesID.java"
    mode: "a+x"
    owner: "{{ service_user }}"
    group: "{{ service_group }}"
    src: "CrossCertifyNotesID.java.j2"

-
  name: "Creating Templated JSON for Names.nsf ACLs"
  when: build_utility_jars and not build_tools_deployed.stat.exists
  ansible.builtin.template:
    dest: "{{ service_home_dir }}/default_cross_certify_acl.json"
    mode: "a+x"
    owner: "{{ service_user }}"
    group: "{{ service_group }}"
    src: "default_cross_certify_acl.json.j2"

-
  name: "Creating Templated Cross Certify Properties file"
  when: build_utility_jars and not build_tools_deployed.stat.exists
  ansible.builtin.template:
    dest: "{{ service_home_dir }}/CrossCertifyNotesID.properties"
    mode: "a+x"
    owner: "{{ service_user }}"
    group: "{{ service_group }}"
    src: "CrossCertifyNotesID.properties.j2"

-
  name: "Building utility jars and deploying"
  ansible.builtin.shell: "{{ item }}"
  become: true
  become_user: "{{ service_user }}"
  when: build_utility_jars and not build_tools_deployed.stat.exists
  args:
    chdir: "/vagrant/installers/domino-java-helpers"
    creates: "{{ completed_dir }}/javabuildtools"
    executable: /bin/bash
  with_items:
    - "source {{ service_home_dir }}/.sdkman/bin/sdkman-init.sh && gradle clean jarIndividual --stacktrace"

-
  name: "Marking jars as installed"
  when: build_utility_jars and not build_tools_deployed.stat.exists
  ansible.builtin.file:
    mode: '0644'
    path: "{{ item }}"
    state: touch
  with_items:
    - "{{ completed_dir }}/javabuildtools"

-
  name: "Finding build Libs in domino-java-helpers/build/libs/"
  when: not build_tools_deployed.stat.exists
  ansible.builtin.find:
    paths: "{{ installer_dir }}/domino-java-helpers/build/libs/"
    file_type: file
    patterns: '*.jar'
  register: build_jar_list

-
  name: "Copying Build Libs for {{ service_user }}"
  when: not build_tools_deployed.stat.exists
  loop: "{{ build_jar_list.files }}"
  ansible.builtin.copy:
    mode: '0755'
    remote_src: true
    owner: "{{ service_user }}"
    src: "{{ item.path }}"
    dest: "{{ service_home_dir }}"
