---
-
  name: "Block to Allow Loading of Variables without running task"
  when: run_tasks
  block:
    -
      name: "Creating Installation Directories"
      ansible.builtin.file:
        mode: "0755"
        path: "{{ item }}"
        state: directory
        owner: "{{ service_user }}"
      with_items:
        - "/vagrant/installers/update-site"
        - "{{ nsfodp_updatesite_path }}"
        - "{{ service_home_dir }}/.m2"
    
    -
      name: "Checking if the updatesite has been installed"
      register: updatesite_deployed
      ansible.builtin.stat:
        path: "{{ completed_dir }}/updatesite_deployed"
        checksum_algorithm: sha256
    
    -
      name: "Cloning updatesite to /vagrant/installers/update-site"
      become: true
      become_user: "{{ service_user }}"
      when: not updatesite_deployed.stat.exists
      ansible.builtin.git: # noqa: latest
        repo: "{{ updatesite_repo }}"
        dest: "/vagrant/installers/update-site/"
        force: false
        update: false
    
    -
      name: "Placing Configuration and scripts"
      when: not updatesite_deployed.stat.exists
      become_user: "{{ service_user }}"
      become: true
      ansible.builtin.template:
        owner: "{{ item.owner }}"
        src: "{{ item.src }}"
        dest: "{{ item.dest }}"
        mode: "a+x"
      loop:
        - { src: 'run_nsfodp.sh.j2', dest: '/opt/nsfodp/run_nsfodp.sh', owner: '{{ service_user }}' }
        - { src: 'maven_settings.xml.j2', dest: '{{ service_home_dir }}/.m2/settings.xml', owner: '{{ service_user }}' }
    
    -
      name: "Installing updatesite over proxy with Maven {{ maven_version }}"
      when: not updatesite_deployed.stat.exists and use_proxy
      ansible.builtin.shell: |
        source {{ service_home_dir }}/.sdkman/bin/sdkman-init.sh && mvn install
        touch {{ completed_dir }}/updatesite_installed
      become: true
      become_user: "{{ service_user }}"
      args:
        executable: "/bin/bash"
        chdir: "/vagrant/installers/update-site/generate-domino-update-site"
        creates: "{{ completed_dir }}/updatesite_installed"
      environment:
        MAVEN_HOME: "{{ service_home_dir }}/.sdkman/candidates/maven/current"
        http_proxy: "http://{{ proxy_server }}:{{ proxy_port }}"
        https_proxy: "http://{{ proxy_server }}:{{ proxy_port }}"
    
    -
      name: "Installing updatesite with Maven {{ maven_version }}"
      when: not updatesite_deployed.stat.exists and not use_proxy
      ansible.builtin.shell: |
        source {{ service_home_dir }}/.sdkman/bin/sdkman-init.sh && mvn install
        touch {{ completed_dir }}/updatesite_installed
      become: true
      become_user: "{{ service_user }}"
      args:
        executable: "/bin/bash"
        chdir: "/vagrant/installers/update-site/generate-domino-update-site"
        creates: "{{ completed_dir }}/updatesite_installed"
      environment:
        MAVEN_HOME: "{{ service_home_dir }}/.sdkman/candidates/maven/current"
    
    -
      name: "Deploying updatesite over proxy with Maven {{ maven_version }}"
      when: not updatesite_deployed.stat.exists and use_proxy
      ansible.builtin.shell: |
        source {{ service_home_dir }}/.sdkman/bin/sdkman-init.sh
        mvn org.openntf.p2:generate-domino-update-site:generateUpdateSite -Ddest={{ nsfodp_updatesite_path }} -Dsrc={{ domino_install_dir }}
        touch {{ completed_dir }}/updatesite_deployed
      become: true
      become_user: "{{ service_user }}"
      args:
        executable: "/bin/bash"
        chdir: "/vagrant/installers/update-site/generate-domino-update-site"
        creates: "{{ completed_dir }}/updatesite_deployed"
      environment:
        MAVEN_HOME: "{{ service_home_dir }}/.sdkman/candidates/maven/current"
        http_proxy: "http://{{ proxy_server }}:{{ proxy_port }}"
        https_proxy: "http://{{ proxy_server }}:{{ proxy_port }}"
    
    -
      name: "Deploying updatesite with Maven {{ maven_version }}"
      when: not updatesite_deployed.stat.exists and not use_proxy
      ansible.builtin.shell: |
        source {{ service_home_dir }}/.sdkman/bin/sdkman-init.sh
        mvn org.openntf.p2:generate-domino-update-site:generateUpdateSite -Ddest={{ nsfodp_updatesite_path }} -Dsrc={{ domino_install_dir }}
        touch {{ completed_dir }}/updatesite_deployed
      become: true
      become_user: "{{ service_user }}"
      args:
        executable: "/bin/bash"
        chdir: "/vagrant/installers/update-site/generate-domino-update-site"
        creates: "{{ completed_dir }}/updatesite_deployed"
      environment:
        MAVEN_HOME: "{{ service_home_dir }}/.sdkman/candidates/maven/current"
    
    -
      name: "Archiving updatesite into a zip for later use: {{ nsfodp_updatesite_path }}"
      when: not updatesite_deployed.stat.exists
      community.general.archive:
        mode: '0644'
        path: "{{ nsfodp_updatesite_path }}"
        dest: "{{ nsfodp_updatesite_path }}.zip"
        format: zip
