Skip to content
This repository was archived by the owner on Dec 19, 2024. It is now read-only.

Commit f8964ff

Browse files
committed
system-wide java environment variables
(#5)
1 parent a3799aa commit f8964ff

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ Enable checksum validation on downloaded archives. Boolean value. Defaults to `t
127127

128128
Add Oracle Java to the system alternatives on compatible platforms (Debian/RHEL/SuSE families). Boolean value. Defaults to `false`
129129

130+
#####`add_system_env`
131+
132+
Add `JAVA_HOME` environment variable to the `/etc/environment` file. Boolean value. Defaults to `false`
133+
130134
####Define: `oracle_java::installation`
131135

132136
Installs an extra version of Oracle Java in `/usr/java`

manifests/env.pp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# == Class: oracle_java::env
2+
#
3+
# This class adds Java environment variables to the /etc/environment file
4+
#
5+
class oracle_java::env {
6+
# The base class must be included first
7+
if !defined(Class['oracle_java']) {
8+
fail('You must include the oracle_java base class before using any oracle_java sub class')
9+
}
10+
11+
augeas { 'environment':
12+
context => '/files/etc/environment',
13+
changes => [ "set JAVA_HOME /usr/java/${oracle_java::longversion}" ]
14+
}
15+
}

manifests/init.pp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# enable checksum validation on downloaded archives (boolean)
1515
# [*add_alternative*]
1616
# add java alternative (boolean)
17+
# [*add_system_env*]
18+
# add system-wide java environment variables (boolean)
1719
#
1820
# === Actions:
1921
#
@@ -33,7 +35,14 @@
3335
# add_alternative => true
3436
# }
3537
#
36-
class oracle_java ($version = '8', $type = 'jre', $format = undef, $check_checksum = true, $add_alternative = false) {
38+
class oracle_java (
39+
$version = '8',
40+
$type = 'jre',
41+
$format = undef,
42+
$check_checksum = true,
43+
$add_alternative = false,
44+
$add_system_env = false
45+
) {
3746
if !$format {
3847
if $::osfamily =~ /RedHat|Suse/ or $::operatingsystem == 'Mageia' {
3948
$format_real = 'rpm'
@@ -102,4 +111,8 @@
102111
include oracle_java::alternative
103112
Class['oracle_java::install'] -> Class['oracle_java::alternative']
104113
}
114+
115+
if $add_system_env {
116+
include oracle_java::env
117+
}
105118
}

0 commit comments

Comments
 (0)