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

Commit ae945ed

Browse files
committed
ready to publish v2.0
1 parent 0944cc5 commit ae945ed

File tree

8 files changed

+178
-156
lines changed

8 files changed

+178
-156
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
###2.0.0
22

3+
* Support tar.gz format
4+
* now multiplatform!
5+
* Dropped support for Java 6
6+
* it relied on dirty hacks to work properly, and that's not the direction I want this module to take
7+
* nobody uses JSE6 anymore ... right?
38
* Major refactoring
9+
* splitted the old bulky init class
410
* Use nanliu/archive for download and extraction
5-
* Minor fixes
11+
* reliable module, multiplatform, well supported
612

713
###1.1.5
814

README.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,21 @@
1212

1313
##Overview
1414

15-
The oracle_java module allows you to install the Oracle JRE or JDK of your choice from the official RPM archives provided by Oracle.
15+
The oracle_java module allows you to install the Oracle JRE or JDK of your choice from the official archives provided by Oracle.
1616

1717
##Module description
1818

19-
Oracle provides a RPM version of both its JRE and JDK for every Java release. These packages are available from the Oracle [Java SE Downloads](http://www.oracle.com/technetwork/java/javase/downloads/index.html) and Oracle [Java Archive](http://www.oracle.com/technetwork/java/archive-139210.html) pages.
19+
This module downloads the desired Java version from Oracle's website and installs it on the target system. On [RPM-based distributions](http://en.wikipedia.org/wiki/List_of_Linux_distributions#RPM-based) the RPM version will be used by default. On all other platforms a tar.gz archive will be retrieved and extracted.
2020

21-
This module simply downloads the desired Java version and installs it on the target system. It is intended for systems which do not need to have several Java versions installed in parallel and for users looking for an easy way to update their Java environment.
21+
Java SE archives are available from the Oracle [Java SE Downloads](http://www.oracle.com/technetwork/java/javase/downloads/index.html) and Oracle [Java Archive](http://www.oracle.com/technetwork/java/archive-139210.html) pages.
2222

23-
It currently supports all released versions from Java SE 6 on.
23+
This module is suitable for pretty much any Linux system. It currently supports all released versions from Java SE 7 on.
2424

2525
##Setup
2626

2727
oracle_java will affect the following parts of your system:
2828

2929
* jre/jdk package
30-
* 'java' alternative
3130

3231
Including the main class is enough to install the latest version of the Oracle JRE.
3332

@@ -62,6 +61,14 @@ class { '::oracle_java':
6261
}
6362
```
6463

64+
Force installation from standard tar.gz archive
65+
66+
```puppet
67+
class { '::oracle_java':
68+
69+
format => 'tar.gz'
70+
}
71+
6572
##Usage
6673
6774
####Class: `oracle_java`
@@ -80,19 +87,21 @@ Note: a minor version of '0' (for example '8u0') matches the initial release of
8087
8188
What envionment type to install. Valid values are 'jre' and 'jdk'. Defaults to 'jre'
8289
90+
#####`format`
91+
92+
What format of installation archive to retrieve. Valid values are 'rpm' and 'tar.gz'. Default depends on the platform
93+
8394
##Limitations
8495
85-
* Prior to Java 8u20, two different releases of the same Java series could not cohabit on the same system when installed from RPM. Each new version overrides the previous one.
86-
* Works only on [RPM-based distributions](http://en.wikipedia.org/wiki/List_of_Linux_distributions#RPM-based)
96+
* Prior to Java 8u20, two different releases of the same Java series could not cohabit on the same system when installed from RPM. Each new version would override the previous one. This does not happen with tar.gz archives.
8797
8898
##Credits
8999
90-
The method used by this module to retrieve its installation packages relies on the useful information found on [Ivan Dyedov's Blog](https://ivan-site.com/2012/05/download-oracle-java-jre-jdk-using-a-script/)
100+
The cookie manipulation used by this module to download its installation packages directly from Oracle's page was found on [Ivan Dyedov's Blog](https://ivan-site.com/2012/05/download-oracle-java-jre-jdk-using-a-script/)
91101
92102
##To Do
93103
94104
* Add Oracle Java as a 'java' alternative (waiting for an official release of [this module](https://github.com/adrienthebo/puppet-alternatives))
95105
* Allow the manipulation of Java related environment variables
96-
* Propose an alternative based on tar.gz archives, also available from Oracle's archives
97106
98107
Features request and contributions are always welcome!

manifests/download.pp

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,6 @@
55
fail('You must include the oracle_java base class before using any oracle_java sub class')
66
}
77

8-
if !defined(Class['archive']) {
9-
include archive
10-
}
11-
12-
$require_extraction = $oracle_java::format ? {
13-
'tar.gz' => true,
14-
default => false
15-
}
16-
178
# make sure install/download directory exists
189
file { '/usr/java':
1910
ensure => directory,
@@ -22,14 +13,8 @@
2213
group => 'root'
2314
} ->
2415
# download archive
25-
archive { 'java archive':
26-
ensure => present,
27-
path => '/usr/java',
28-
cookie => "oraclelicense=accept-securebackup-cookie",
29-
source => $oracle_java::downloadurl,
30-
extract => $require_extraction,
31-
extract_path => '/usr/java',
32-
creates => "/usr/java/${oracle_java::longversion}",
33-
cleanup => true
16+
archive { "/usr/java/${oracle_java::filename}":
17+
cookie => "oraclelicense=accept-securebackup-cookie",
18+
source => $oracle_java::downloadurl
3419
}
3520
}

manifests/init.pp

Lines changed: 25 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,26 @@
2929
# format => 'rpm'
3030
# }
3131
#
32-
class oracle_java ($version = '8', $type = 'jre', $format = 'rpm') {
32+
class oracle_java ($version = '8', $type = 'jre', $format = undef) {
33+
if !$format {
34+
case $::osfamily {
35+
/RedHat|Suse/ : { $format_real = 'rpm' }
36+
default : { $format_real = 'tar.gz' }
37+
}
38+
} else {
39+
$format_real = $format
40+
}
41+
3342
# parameters validation
3443
validate_re($version, '^([0-9]|[0-9]u[0-9]{1,2})$', '$version must be formated as \'major\'u\'minor\' or just \'major\'')
3544
validate_re($type, '^(jre|jdk)$', '$type must be either \'jre\' or \'jdk\'')
36-
validate_re($format, '^(rpm|tar.gz)$', '$format must be either \'rpm\' or \'tar.gz\'')
45+
validate_re($format_real, '^(rpm|tar\.gz)$', '$format must be either \'rpm\' or \'tar.gz\'')
3746

3847
# set to latest release if no minor version was provided
3948
if $version == '8' {
4049
$version_real = '8u25'
4150
} elsif $version == '7' {
4251
$version_real = '7u72'
43-
} elsif $version == '6' {
44-
$version_real = '6u45'
4552
} else {
4653
$version_real = $version
4754
}
@@ -60,7 +67,7 @@
6067
'11' : { $build = '-b12' }
6168
'5' : { $build = '-b13' }
6269
'0' : { $build = '-b132' }
63-
default : { fail("Unexisting Java SE ${maj_version} update number ${min_version}") }
70+
default : { fail("Unreleased Java SE version ${version_real}") }
6471
}
6572
}
6673
7 : {
@@ -90,51 +97,7 @@
9097
'2' : { $build = '-b13' }
9198
'1' : { $build = '-b08' }
9299
'0' : { $build = '' }
93-
default : { fail("Unexisting Java SE ${maj_version} update number ${min_version}") }
94-
}
95-
}
96-
6 : {
97-
case $min_version {
98-
'45' : { $build = '-b06' }
99-
'43' : { $build = '-b01' }
100-
'41' : { $build = '-b02' }
101-
'39' : { $build = '-b04' }
102-
'38' : { $build = '-b05' }
103-
'37' : { $build = '-b06' }
104-
'35' : { $build = '-b10' }
105-
'34' : { $build = '-b04' }
106-
'33' : { $build = '-b04' }
107-
'32' : { $build = '-b05' }
108-
'31' : { $build = '-b04' }
109-
'30' : { $build = '-b12' }
110-
'29' : { $build = '-b11' }
111-
'27' : { $build = '-b07' }
112-
'26' : { $build = '-b03' }
113-
'25' : { $build = '-b06' }
114-
'24' : { $build = '-b07' }
115-
'23' : { $build = '-b05' }
116-
'22' : { $build = '-b04' }
117-
'21' : { $build = '-b07' }
118-
'20' : { $build = '-b02' }
119-
'19' : { $build = '-b04' }
120-
'18' : { $build = '-b07' }
121-
'17' : { $build = '-b04' }
122-
'16' : { $build = '-b01' }
123-
'15' : { $build = '-b03' }
124-
'14' : { $build = '-b08' }
125-
'13' : { $build = '-b03' }
126-
'12' : { $build = '-b04' }
127-
'11' : { $build = '-b03' }
128-
'10' : { $build = '' }
129-
'7' : { $build = '' }
130-
'6' : { $build = '' }
131-
'5' : { $build = 'b' }
132-
'4' : { $build = '-b12' }
133-
'3' : { $build = '' }
134-
'2' : { $build = '' }
135-
'1' : { $build = '' }
136-
'0' : { $build = '' }
137-
default : { fail("Unexisting Java SE ${maj_version} update number ${min_version}") }
100+
default : { fail("Unreleased Java SE version ${version_real}") }
138101
}
139102
}
140103
default : {
@@ -145,49 +108,34 @@
145108
# remove extra particle if minor version is 0
146109
$version_final = delete($version_real, 'u0')
147110
$longversion = $min_version ? {
148-
'0' => "${type}1.${maj_version}.0",
149-
default => "${type}1.${maj_version}.0_${min_version}"
111+
'0' => "${type}1.${maj_version}.0",
112+
/^[0-9]$/ => "${type}1.${maj_version}.0_0${min_version}",
113+
default => "${type}1.${maj_version}.0_${min_version}"
150114
}
151115

152116
# translate system architecture to expected value
153117
case $::architecture {
154-
'x86_64' : {
155-
if $maj_version == '6' and $min_version < '4' {
156-
$arch = 'amd64'
157-
} else {
158-
$arch = 'x64'
159-
}
160-
}
161-
'x86' : {
162-
$arch = 'i586'
163-
}
164-
default : {
165-
fail("oracle_java does not support architecture ${arch} (yet)")
166-
}
118+
/x86_64|amd64/ : { $arch = 'x64' }
119+
'x86' : { $arch = 'i586' }
120+
default : { fail("oracle_java does not support architecture ${::architecture} (yet)") }
167121
}
168122

169123
# define installer filename and download URL
170-
$filename = $maj_version ? {
171-
'6' => "${type}-${version_final}-linux-${arch}-rpm.bin",
172-
default => "${type}-${version_final}-linux-${arch}.rpm"
173-
}
124+
$filename = "${type}-${version_final}-linux-${arch}.${format_real}"
174125
$downloadurl = "http://download.oracle.com/otn-pub/java/jdk/${version_final}${build}/${filename}"
175126

176-
# used for installing Java 6
177-
# translate system architecture one more time
178-
$arch_extracted = $::architecture ? {
179-
'x86_64' => 'amd64',
180-
default => $arch
181-
}
182-
$filename_extracted = "${type}-${version_final}-linux-${arch_extracted}.rpm"
183-
184127
# define package name
185128
if $maj_version == '8' and $min_version >= '20' {
186129
$packagename = $longversion
187130
} else {
188131
$packagename = $type
189132
}
190133

134+
# include classes as required
135+
if !defined(Class['archive']) {
136+
include archive
137+
}
138+
191139
include oracle_java::download
192140
include oracle_java::install
193141
Class['oracle_java::download'] -> Class['oracle_java::install']

manifests/install.pp

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,8 @@
55
fail('You must include the oracle_java base class before using any oracle_java sub class')
66
}
77

8-
# define packages required by the exec resources
9-
if $oracle_java::maj_version < 7 {
10-
if !defined(Package['sed']) {
11-
package { 'sed': ensure => present }
12-
}
13-
}
14-
15-
# install package
16-
if $oracle_java::maj_version >= 7 {
17-
package { $oracle_java::packagename:
18-
ensure => latest,
19-
source => "/usr/java/${oracle_java::filename}",
20-
provider => rpm
21-
}
22-
}
23-
# the procedure is a bit more complicated for Java 6...
24-
# RPM files are packaged into a BIN archive which needs to be extracted
25-
else {
26-
exec { 'unpack java RPM':
27-
path => '/bin',
28-
cwd => '/usr/java',
29-
creates => "/usr/java/${oracle_java::filename_extracted}",
30-
command => "sed -ni '/exit 0/,\${//!p}' ${oracle_java::filename}; chmod +x ${oracle_java::filename}; ./${oracle_java::filename}",
31-
require => Package['sed']
32-
} ~>
33-
# remove undesired extra RPMs
34-
exec { 'cleanup java RPM':
35-
path => '/bin',
36-
cwd => '/usr/java',
37-
refreshonly => true,
38-
command => 'rm -f sun-javadb-*.rpm'
39-
} ->
40-
package { $oracle_java::packagename:
41-
ensure => latest,
42-
source => "/usr/java/${oracle_java::filename_extracted}",
43-
provider => rpm
44-
}
8+
case $oracle_java::format_real {
9+
'rpm' : { contain oracle_java::install::rpm }
10+
'tar.gz' : { contain oracle_java::install::targz }
4511
}
4612
}

manifests/install/rpm.pp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# == Class: oracle_java::install::rpm
2+
class oracle_java::install::rpm {
3+
# The base class must be included first
4+
if !defined(Class['oracle_java']) {
5+
fail('You must include the oracle_java base class before using any oracle_java sub class')
6+
}
7+
8+
# install package
9+
package { $oracle_java::packagename:
10+
ensure => latest,
11+
source => "/usr/java/${oracle_java::filename}",
12+
provider => rpm
13+
}
14+
}

manifests/install/targz.pp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# == Class: oracle_java::install::targz
2+
class oracle_java::install::targz {
3+
# The base class must be included first
4+
if !defined(Class['oracle_java']) {
5+
fail('You must include the oracle_java base class before using any oracle_java sub class')
6+
}
7+
8+
# extract archive
9+
archive { 'extract java archive':
10+
path => "/usr/java/${oracle_java::filename}",
11+
extract => true,
12+
extract_path => '/usr/java',
13+
creates => "/usr/java/${oracle_java::longversion}"
14+
} ->
15+
# fix permissions
16+
file { "/usr/java/${oracle_java::longversion}":
17+
recurse => true,
18+
owner => 'root',
19+
group => 'root',
20+
loglevel => debug
21+
}
22+
23+
# mimic RPM behaviour
24+
file { '/usr/java/default':
25+
ensure => link,
26+
target => "/usr/java/${oracle_java::longversion}"
27+
}
28+
}

0 commit comments

Comments
 (0)