---
-
  name: "Managing progress for {{ ansible_role_name }}"
  when: count_progress | default(false)
  run_once: true
  block:
    -
      name: "Incrementing global progress step counter for {{ ansible_role_name }}"
      ansible.builtin.set_fact:
        global_current_progress_step: "{{ global_current_progress_step | default(0) | int + 1 }}"

    -
      name: "Including progress reporting task for {{ ansible_role_name }}"
      ansible.builtin.include_role:
        name: startcloud.startcloud_roles.progress
      vars:
        _progress_role_is_setup_run: false
        current_progress_step: "{{ global_current_progress_step | default(0) }}"
        progress_description: "{{ progress_role_description | default('Processing ' + ansible_role_name) }}"
-
  name: "Block to Allow Loading of Variables without running task"
  when: run_tasks
  block:
    -
      name: "Installing gradle {{ gradle_version }}"
      ansible.builtin.shell: "{{ item }}"
      become: true
      become_user: "{{ service_user }}"
      args:
        executable: "/bin/bash"
        creates: "{{ service_home_dir }}/.sdkman/candidates/gradle/current/bin/gradle"
      with_items:
        - "source {{ service_home_dir }}/.sdkman/bin/sdkman-init.sh && sdk install gradle {{ gradle_version }} && sdk default gradle {{ gradle_version }}"
    
    -
      name: "Adding Gradle to /etc/profile.d/gradle.sh for {{ service_user }}"
      ansible.builtin.lineinfile:
        mode: '0755'
        path: "{{ item.dir }}"
        regexp: "^PATH=\"$PATH:{{ service_home_dir }}/.sdkman/candidates/gradle/current/bin\""
        insertbefore: EOF
        create: true
        line: 'PATH=$PATH:{{ service_home_dir }}/.sdkman/candidates/gradle/current/bin'
      with_items:
        - { user: "{{ service_user }}", dir: "/etc/profile.d/gradle.sh" }
    
    -
      name: "Updating alternatives for Gradle"
      community.general.alternatives:
        name: "{{ item.name }}"
        path: "{{ sdkman_dir }}/candidates/{{ item.candidate }}/current/bin/{{ item.name }}"
        link: "{{ item.link }}"
      loop: "{{ sdkman_update_alternatives }}"
      become: true
      when: ansible_os_family != 'Darwin'
      tags:
        - sdkman_privilege
