# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# setup maven
# Assumes Ubuntu Server 14.04 LTS
# Assumes Java 7+ jdk installed
---

- name: Install pythons httplib2 library so that ansible uri module works
  apt: pkg=python-httplib2 state=present


- name: Call apache web service to find preferred maven download mirror
  uri: url=http://www.apache.org/dyn/closer.cgi?path=maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz&asjson=1 return_content=yes
  register: webResponse

#- debug: var=webResponse

- name: download maven
  get_url: url="{{webResponse.json.preferred}}{{webResponse.json.path_info}}"
           dest=/tmp/apache-maven-3.3.9-bin.tar.gz
           mode=0440
           validate_certs=False

- name: extract maven tgz
  unarchive: src=/tmp/apache-maven-3.3.9-bin.tar.gz
             dest=/usr/local/
             copy=no
             creates=/usr/local/apache-maven-3.3.9

- name: create symlink to this maven version
  file: src=/usr/local/apache-maven-3.3.9/bin/mvn
        path=/usr/bin/mvn
        state=link
