Initial commit
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
new file mode 100644
index 0000000..fae7b32
--- /dev/null
+++ b/CHANGELOG.rst
@@ -0,0 +1,6 @@
+java
+====
+
+0.1 (2015-07-30)
+
+- initial release
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..0c7e4d8
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,13 @@
+ Copyright (c) 2014-2015 tcp cloud a. s.
+
+ Licensed 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.
\ No newline at end of file
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..50e2f51
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,40 @@
+====
+Java
+====
+
+Programming language environment.
+
+Sample pillars
+==============
+
+OpenJDK environment with development libs
+
+.. code-block:: yaml
+
+ java:
+ environment:
+ enabled: true
+ version: '7'
+ platform: openjdk
+ development: true
+
+Oracle JAVA JDK
+
+.. code-block:: yaml
+
+ java:
+ environment:
+ enabled: true
+ version: '7'
+ platform: oracle-java
+ development: true
+
+Read more
+=========
+
+* http://openjdk.java.net/install/
+* http://www.wikihow.com/Install-Oracle-Java-on-Ubuntu-Linux
+* https://github.com/saltstack-formulas/sun-java-formula
+* https://www.digitalocean.com/community/articles/how-to-install-java-on-ubuntu-with-apt-get
+* https://github.com/saltstack-formulas/sun-java-formula
+* https://github.com/saltstack-formulas/java-formula
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..3b04cfb
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+0.2
diff --git a/debian/changelog b/debian/changelog
new file mode 100644
index 0000000..4fe052b
--- /dev/null
+++ b/debian/changelog
@@ -0,0 +1,11 @@
+salt-formula-java (0.2) trusty; urgency=medium
+
+ * First public release
+
+ -- Filip Pytloun <filip.pytloun@tcpcloud.eu> Tue, 06 Oct 2015 16:38:43 +0200
+
+salt-formula-java (0.1) trusty; urgency=medium
+
+ * Initial release
+
+ -- Filip Pytloun <filip.pytloun@tcpcloud.eu> Thu, 13 Aug 2015 23:23:41 +0200
diff --git a/debian/compat b/debian/compat
new file mode 100644
index 0000000..ec63514
--- /dev/null
+++ b/debian/compat
@@ -0,0 +1 @@
+9
diff --git a/debian/control b/debian/control
new file mode 100644
index 0000000..a3f0644
--- /dev/null
+++ b/debian/control
@@ -0,0 +1,15 @@
+Source: salt-formula-java
+Maintainer: Filip Pytloun <filip.pytloun@tcpcloud.eu>
+Section: admin
+Priority: optional
+Build-Depends: debhelper (>= 9)
+Standards-Version: 3.9.6
+Homepage: http://www.tcpcloud.eu
+Vcs-Browser: https://github.com/tcpcloud/salt-formula-java
+Vcs-Git: https://github.com/tcpcloud/salt-formula-java.git
+
+Package: salt-formula-java
+Architecture: all
+Depends: ${misc:Depends}, salt-master, reclass
+Description: Java Salt formula
+ Install and configure Java environment.
diff --git a/debian/copyright b/debian/copyright
new file mode 100644
index 0000000..4027f14
--- /dev/null
+++ b/debian/copyright
@@ -0,0 +1,15 @@
+Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
+Upstream-Name: salt-formula-java
+Upstream-Contact: Filip Pytloun <filip.pytloun@tcpcloud.eu>
+Source: https://github.com/tcpcloud/salt-formula-java
+
+Files: *
+Copyright: 2014-2015 tcp cloud
+License: Apache-2.0
+ Copyright (C) 2014-2015 tcp cloud
+ .
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ .
+ On a Debian system you can find a copy of this license in
+ /usr/share/common-licenses/Apache-2.0.
diff --git a/debian/docs b/debian/docs
new file mode 100644
index 0000000..d585829
--- /dev/null
+++ b/debian/docs
@@ -0,0 +1,3 @@
+README.rst
+CHANGELOG.rst
+VERSION
diff --git a/debian/install b/debian/install
new file mode 100644
index 0000000..8ae8b96
--- /dev/null
+++ b/debian/install
@@ -0,0 +1,2 @@
+java/* /usr/share/salt-formulas/env/java/
+metadata/service/* /usr/share/salt-formulas/reclass/service/java/
diff --git a/debian/rules b/debian/rules
new file mode 100755
index 0000000..abde6ef
--- /dev/null
+++ b/debian/rules
@@ -0,0 +1,5 @@
+#!/usr/bin/make -f
+
+%:
+ dh $@
+
diff --git a/debian/source/format b/debian/source/format
new file mode 100644
index 0000000..89ae9db
--- /dev/null
+++ b/debian/source/format
@@ -0,0 +1 @@
+3.0 (native)
diff --git a/java/environment/init.sls b/java/environment/init.sls
new file mode 100644
index 0000000..972700a
--- /dev/null
+++ b/java/environment/init.sls
@@ -0,0 +1,11 @@
+{%- from "java/map.jinja" import environment with context %}
+{%- if environment.enabled %}
+
+include:
+{%- if environment.platform == 'openjdk' %}
+- java.environment.openjdk
+{%- elif environment.platform == 'oracle-java' %}
+- java.environment.oracle
+{%- endif %}
+
+{%- endif %}
diff --git a/java/environment/openjdk.sls b/java/environment/openjdk.sls
new file mode 100644
index 0000000..f9b1784
--- /dev/null
+++ b/java/environment/openjdk.sls
@@ -0,0 +1,18 @@
+{%- from "java/map.jinja" import environment with context %}
+
+java_packages:
+ pkg.installed:
+ - names: {{ environment.pkgs }}
+
+{%- if environment.get('development', False) %}
+
+java_dev_packages:
+ pkg.installed:
+ - names: {{ environment.dev_pkgs }}
+
+{%- endif %}
+
+java_home_symlink:
+ file.symlink:
+ - name: {{ environment.home_dir }}
+ - target: /usr/lib/jvm/java-{{ environment.version }}-openjdk-amd64
diff --git a/java/environment/oracle.yml b/java/environment/oracle.yml
new file mode 100644
index 0000000..43b079a
--- /dev/null
+++ b/java/environment/oracle.yml
@@ -0,0 +1,41 @@
+{%- from "java/map.jinja" import environment with context %}
+
+{{ environment.prefix }}:
+ file.directory:
+ - user: root
+ - group: root
+ - mode: 755
+ - makedirs: True
+
+unpack_java_source:
+ cmd.run:
+ - name: curl {{ environment.dl_opts }} '{{ environment.source_url }}' | tar xz --no-same-owner
+ - cwd: {{ environment.prefix }}
+ - unless: test -d {{ environment.java_real_home }}
+ - require:
+ - file: {{ environment.prefix }}
+
+java_install:
+ alternatives.install:
+ - name: java-home-link
+ - link: {{ environment.java_home }}
+ - path: {{ environment.java_real_home }}
+ - priority: 30
+
+java_profile_file:
+ file.managed:
+ - name: /etc/profile.d/java.sh
+ - source: salt://java/files/java.sh
+ - user: root
+ - group: root
+ - mode: 644
+ - template: jinja
+ - require:
+ - alternatives: java_install
+
+setup_java_paths:
+ cmd.run:
+ - name: . /etc/profile
+ - cwd: /root
+ - require:
+ - file: java_profile_file
diff --git a/java/files/java.sh b/java/files/java.sh
new file mode 100644
index 0000000..d25a388
--- /dev/null
+++ b/java/files/java.sh
@@ -0,0 +1,11 @@
+{%- from "java/map.jinja" import environment with context %}
+
+JAVA_HOME={{ environment.java_home }}
+PATH=$HOME/bin:$JAVA_HOME/bin:$PATH
+
+#JRE_HOME={{ environment.java_home }}
+#PATH=$PATH:$HOME/bin:$JRE_HOME/bin
+
+export JAVA_HOME
+#export JRE_HOME
+export PATH
diff --git a/java/init.sls b/java/init.sls
new file mode 100644
index 0000000..d4a574e
--- /dev/null
+++ b/java/init.sls
@@ -0,0 +1,7 @@
+
+{%- if pillar.java is defined %}
+include:
+{%- if pillar.java.environment is defined %}
+- java.environment
+{%- endif %}
+{%- endif %}
diff --git a/java/map.jinja b/java/map.jinja
new file mode 100644
index 0000000..7eaed35
--- /dev/null
+++ b/java/map.jinja
@@ -0,0 +1,44 @@
+{% set java_version = pillar.java.environment.get('version', '7') %}
+
+{% if java_version == '7' %}
+{% set java_release = '76' %}
+{% set java_build = '13' %}
+{% elif java_version == '8' %}
+{% set java_release = '60' %}
+{% set java_build = '27' %}
+{% endif %}
+
+{% set environment = salt['grains.filter_by']({
+ 'Debian': {
+ 'version': java_version,
+ 'release': java_release,
+ 'home_dir': '/usr/lib/java',
+ 'build': java_build,
+ 'pkgs': ['openjdk-' + java_version + '-jre'],
+ 'dev_pkgs': ['openjdk-' + java_version + '-jdk'],
+ },
+ 'RedHat': {
+ 'version': java_version,
+ 'release': java_release,
+ 'home_dir': '/usr/lib/java',
+ 'build': java_build,
+ 'pkgs': ['java-1.' + java_version + '.0-openjdk'],
+ 'dev_pkgs': ['java-1.' + java_version + '.0-openjdk'],
+ },
+}, merge=salt['pillar.get']('java:environment')) %}
+
+{%- set java_home = environment.home_dir %}
+{%- set version_name = 'jdk1.'+environment.version+'.0_'+environment.release %}
+{%- set file_name = 'jdk-'+environment.version+'u'+environment.release %}
+{%- set prefix = '/usr/share/java' %}
+{%- set source_url = 'http://download.oracle.com/otn-pub/java/jdk/'+environment.version+'u'+environment.release+'-b'+environment.build+'/'+file_name+'-linux-x64.tar.gz' %}
+{%- set dl_opts = '-b oraclelicense=accept-securebackup-cookie -L' %}
+{%- set java_real_home = prefix + '/' + version_name %}
+
+{%- do environment.update( { 'version_name' : version_name,
+ 'source_url' : source_url,
+ 'dl_opts' : dl_opts,
+ 'java_home' : java_home,
+ 'prefix' : prefix,
+ 'java_real_home' : java_real_home
+}) %}
diff --git a/metadata/service/environment/init.yml b/metadata/service/environment/init.yml
new file mode 120000
index 0000000..d961cfa
--- /dev/null
+++ b/metadata/service/environment/init.yml
@@ -0,0 +1 @@
+openjdk7.yml
\ No newline at end of file
diff --git a/metadata/service/environment/openjdk7.yml b/metadata/service/environment/openjdk7.yml
new file mode 100644
index 0000000..e97c196
--- /dev/null
+++ b/metadata/service/environment/openjdk7.yml
@@ -0,0 +1,9 @@
+applications:
+- java
+parameters:
+ java:
+ environment:
+ enabled: true
+ version: '7'
+ platform: openjdk
+ development: true
\ No newline at end of file
diff --git a/metadata/service/environment/openjdk8.yml b/metadata/service/environment/openjdk8.yml
new file mode 100644
index 0000000..e637d03
--- /dev/null
+++ b/metadata/service/environment/openjdk8.yml
@@ -0,0 +1,9 @@
+applications:
+- java
+parameters:
+ java:
+ environment:
+ enabled: true
+ version: '8'
+ platform: openjdk
+ development: true
\ No newline at end of file
diff --git a/metadata/service/environment/oracle7.yml b/metadata/service/environment/oracle7.yml
new file mode 100644
index 0000000..fb74bd7
--- /dev/null
+++ b/metadata/service/environment/oracle7.yml
@@ -0,0 +1,9 @@
+applications:
+- java
+parameters:
+ java:
+ environment:
+ enabled: true
+ version: '7'
+ platform: oracle-java
+ development: true
\ No newline at end of file
diff --git a/metadata/service/environment/oracle8.yml b/metadata/service/environment/oracle8.yml
new file mode 100644
index 0000000..8b21216
--- /dev/null
+++ b/metadata/service/environment/oracle8.yml
@@ -0,0 +1,9 @@
+applications:
+- java
+parameters:
+ java:
+ environment:
+ enabled: true
+ version: '8'
+ platform: oracle-java
+ development: true
\ No newline at end of file