Skip to content

Commit

Permalink
Merge pull request #587 from travis-ci/gc-add-oraclejdk9
Browse files Browse the repository at this point in the history
Add support for (upcoming) Oracle JDK 9 and refactor similar recipes to reduce duplications
  • Loading branch information
meatballhat committed Nov 23, 2015
2 parents 50db719 + 972bdf6 commit e7525d0
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 160 deletions.
18 changes: 8 additions & 10 deletions cookbooks/.rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2015-10-16 11:18:17 -0400 using RuboCop version 0.34.2.
# on 2015-11-23 11:15:06 -0500 using RuboCop version 0.35.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -25,15 +25,19 @@ Lint/UselessAssignment:
- 'travis_worker/recipes/bluebox.rb'
- 'travis_worker/recipes/ec2-docker.rb'

# Offense count: 257
# Offense count: 1
Metrics/AbcSize:
Max: 36

# Offense count: 241
# Configuration parameters: AllowURI, URISchemes.
Metrics/LineLength:
Max: 317

# Offense count: 1
# Offense count: 3
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 11
Max: 31

# Offense count: 4
# Configuration parameters: Exclude.
Expand All @@ -49,9 +53,3 @@ Style/FileName:
Style/FormatString:
Exclude:
- 'travis_jupiter_brain/recipes/default.rb'

# Offense count: 1
# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
Style/Next:
Exclude:
- 'nodejs/recipes/multi.rb'
21 changes: 10 additions & 11 deletions cookbooks/nodejs/recipes/multi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,16 @@
end

node['nodejs']['default_modules'].each do |mod|
if Gem::Version.new(version) >= Gem::Version.new(mod['required'])
bash "install #{mod[:module]} for node version #{version}" do
code "#{nvm} use #{version}; npm install -g #{mod['module']}"
creates "#{node['travis_build_environment']['home']}/.nvm/#{version}/lib/node_modules/#{mod['module']}"
user node['travis_build_environment']['user']
group node['travis_build_environment']['group']
cwd node['travis_build_environment']['home']
environment(
'HOME' => node['travis_build_environment']['home']
)
end
next unless Gem::Version.new(version) >= Gem::Version.new(mod['required'])
bash "install #{mod[:module]} for node version #{version}" do
code "#{nvm} use #{version}; npm install -g #{mod['module']}"
creates "#{node['travis_build_environment']['home']}/.nvm/#{version}/lib/node_modules/#{mod['module']}"
user node['travis_build_environment']['user']
group node['travis_build_environment']['group']
cwd node['travis_build_environment']['home']
environment(
'HOME' => node['travis_build_environment']['home']
)
end
end
end
Expand Down
3 changes: 3 additions & 0 deletions cookbooks/travis_java/attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@
default['travis_java']['oraclejdk8']['jvm_name'] = 'java-8-oracle'
default['travis_java']['oraclejdk8']['install_jce_unlimited'] = true
default['travis_java']['oraclejdk8']['pinned_release'] = nil
default['travis_java']['oraclejdk9']['jvm_name'] = 'java-9-oracle'
default['travis_java']['oraclejdk9']['install_jce_unlimited'] = true
default['travis_java']['oraclejdk9']['pinned_release'] = nil
47 changes: 47 additions & 0 deletions cookbooks/travis_java/libraries/oraclejdk.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

module TravisJava
module OracleJdk
def install_oraclejdk(version)
attribute_key = "oraclejdk#{version}"
pkg_prefix = "oracle-java#{version}"
pkg_installer = "#{pkg_prefix}-installer"
deb_installer = File.join(Chef::Config[:file_cache_path], "#{pkg_installer}.deb")
installer_cache_path = "/var/cache/oracle-jdk#{version}-installer"
java_home = File.join(node['travis_java']['jvm_base_dir'], node['travis_java'][attribute_key]['jvm_name'])

include_recipe 'travis_java::webupd8'

# accept Oracle License v1.1, otherwise the package won't install
bash "accept oracle license v1.1 for #{attribute_key}" do
code <<-EOBASH.gsub(/^\s+>\s/, '')
> /bin/echo -e #{pkg_installer} shared/accepted-oracle-license-v1-1 select true | \\
> debconf-set-selections
EOBASH
end

if node['travis_java'][attribute_key]['pinned_release']
remote_file deb_installer do
source "http://ppa.launchpad.net/webupd8team/java/ubuntu/pool/main/o/#{pkg_installer}/#{pkg_installer}_#{node['travis_java'][attribute_key]['pinned_release']}.deb"
not_if "test -f #{deb_installer}"
end

dpkg_package deb_installer
else
package pkg_installer
end

package "#{pkg_prefix}-unlimited-jce-policy"

link "#{java_home}/jre/lib/security/cacerts" do
to '/etc/ssl/certs/java/cacerts'
not_if { version > 8 }
# TODO: This "skip condition" must be removed when the Oracle JDK 9 package will provide the 'jre' subdirectory
end

directory installer_cache_path do
action :delete
recursive true
end
end
end
end
2 changes: 1 addition & 1 deletion cookbooks/travis_java/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
maintainer_email '[email protected]'
license 'Apache 2.0'
description 'Installs different Java Development Kits (JDK)'
version '2.1.0'
version '2.2.0'

supports 'ubuntu', '>= 12.04'

Expand Down
66 changes: 2 additions & 64 deletions cookbooks/travis_java/recipes/oraclejdk7.rb
Original file line number Diff line number Diff line change
@@ -1,65 +1,3 @@
#
# Cookbook Name:: travis_java
# Recipe:: oraclejdk7
#
# Copyright 2012-2015, Michael S. Klishin & Travis CI Development Team
#
# 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.
#
Chef::Recipe.send(:include, TravisJava::OracleJdk)

include_recipe 'travis_java::webupd8'

# accept Oracle License v1.1, otherwise the package won't install
bash 'accept oracle license v1.1' do
code <<-EOBASH.gsub(/^\s+>\s/, '')
> /bin/echo -e oracle-java7-installer shared/accepted-oracle-license-v1-1 select true | \\
> debconf-set-selections
EOBASH
end

installer = File.join(Chef::Config[:file_cache_path], 'oracle-java7-installer.deb')

remote_file installer do
source "http://ppa.launchpad.net/webupd8team/java/ubuntu/pool/main/o/oracle-java7-installer/oracle-java7-installer_#{node['travis_java']['oraclejdk7']['pinned_release']}.deb"
not_if "test -f #{installer}"
only_if { node['travis_java']['oraclejdk7']['pinned_release'] }
end

dpkg_package installer do
action :install
only_if { node['travis_java']['oraclejdk7']['pinned_release'] }
end

package 'oracle-java7-installer' do
not_if { node['travis_java']['oraclejdk7']['pinned_release'] }
end

oraclejdk7_home = File.join(
node['travis_java']['jvm_base_dir'],
node['travis_java']['oraclejdk7']['jvm_name']
)

link "#{oraclejdk7_home}/jre/lib/security/cacerts" do
to '/etc/ssl/certs/java/cacerts'
end

bash 'install jce unlimited' do
code <<-EOBASH.gsub(/^\s+>\s/, '')
> curl -L --cookie 'oraclelicense=accept-securebackup-cookie;' \\
> -o /tmp/policy.zip \\
> http://download.oracle.com/otn-pub/java/jce/7/UnlimitedJCEPolicyJDK7.zip && \\
> sudo unzip -j -o /tmp/policy.zip *.jar -d #{oraclejdk7_home}/jre/lib/security && \\
> rm /tmp/policy.zip
EOBASH
only_if { node['travis_java']['oraclejdk7']['install_jce_unlimited'] }
end
install_oraclejdk 7
72 changes: 2 additions & 70 deletions cookbooks/travis_java/recipes/oraclejdk8.rb
Original file line number Diff line number Diff line change
@@ -1,71 +1,3 @@
#
# Cookbook Name:: travis_java
# Recipe:: oraclejdk8
#
# Copyright 2012, Michael S. Klishin & Travis CI Development Team
#
# 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.
#
Chef::Recipe.send(:include, TravisJava::OracleJdk)

include_recipe 'travis_java::webupd8'

# accept Oracle License v1.1, otherwise the package won't install
bash 'accept oracle license v1.1' do
code <<-EOBASH.gsub(/^\s+>\s/, '')
> /bin/echo -e oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | \\
> debconf-set-selections
EOBASH
end

installer = File.join(Chef::Config[:file_cache_path], 'oracle-java8-installer.deb')

remote_file installer do
source "http://ppa.launchpad.net/webupd8team/java/ubuntu/pool/main/o/oracle-java8-installer/oracle-java8-installer_#{node['travis_java']['oraclejdk8']['pinned_release']}.deb"
not_if "test -f #{installer}"
only_if { node['travis_java']['oraclejdk8']['pinned_release'] }
end

dpkg_package installer do
action :install
only_if { node['travis_java']['oraclejdk8']['pinned_release'] }
end

package 'oracle-java8-installer' do
not_if { node['travis_java']['oraclejdk8']['pinned_release'] }
end

oraclejdk8_home = File.join(
node['travis_java']['jvm_base_dir'],
node['travis_java']['oraclejdk8']['jvm_name']
)

link "#{oraclejdk8_home}/jre/lib/security/cacerts" do
to '/etc/ssl/certs/java/cacerts'
end

directory '/var/cache/oracle-jdk8-installer' do
action :delete
recursive true
ignore_failure true
end

bash 'install jce unlimited' do
code <<-EOBASH.gsub(/^\s+>\s/, '')
> curl -L --cookie 'oraclelicense=accept-securebackup-cookie;' \\
> -o /tmp/policy.zip \\
> http://download.oracle.com/otn-pub/java/jce/8/jce_policy-8.zip && \\
> sudo unzip -j -o /tmp/policy.zip *.jar -d #{oraclejdk8_home}/jre/lib/security && \\
> rm /tmp/policy.zip
EOBASH
only_if { node['travis_java']['oraclejdk8']['install_jce_unlimited'] }
end
install_oraclejdk 8
3 changes: 3 additions & 0 deletions cookbooks/travis_java/recipes/oraclejdk9.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Chef::Recipe.send(:include, TravisJava::OracleJdk)

install_oraclejdk 9
31 changes: 27 additions & 4 deletions cookbooks/travis_java/templates/ubuntu/jdk_switcher.sh.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,33 @@ else
OPENJDK8_JAVA_HOME="/usr/lib/jvm/java-8-openjdk"
fi

# The java::oraclejdk7 recipe from github.com/travis-ci/travis-cookbooks
# takes care of this alias. We take it for granted here. MK.
if [[ -d "/usr/lib/jvm/java-7-oracle-$ARCH_SUFFIX" ]] ; then
# Currently unused, because the `travis_java` cookbook doesn't create this architecture specific symbolic link
ORACLEJDK7_UJA_ALIAS="java-7-oracle-$ARCH_SUFFIX"
ORACLEJDK7_JAVA_HOME="/usr/lib/jvm/java-7-oracle-$ARCH_SUFFIX"
else
ORACLEJDK7_UJA_ALIAS="java-7-oracle"
ORACLEJDK7_JAVA_HOME="/usr/lib/jvm/java-7-oracle"
fi

# The java::oraclejdk8 recipe from github.com/travis-ci/travis-cookbooks
# takes care of this alias. We take it for granted here. MK.
if [[ -d "/usr/lib/jvm/java-8-oracle-$ARCH_SUFFIX" ]] ; then
# Currently unused, because the `travis_java` cookbook doesn't create this architecture specific symbolic link
ORACLEJDK8_UJA_ALIAS="java-8-oracle-$ARCH_SUFFIX"
ORACLEJDK8_JAVA_HOME="/usr/lib/jvm/java-8-oracle-$ARCH_SUFFIX"
else
ORACLEJDK8_UJA_ALIAS="java-8-oracle"
ORACLEJDK8_JAVA_HOME="/usr/lib/jvm/java-8-oracle"
fi

if [[ -d "/usr/lib/jvm/java-9-oracle-$ARCH_SUFFIX" ]] ; then
# Currently unused, because the `travis_java` cookbook doesn't create this architecture specific symbolic link
ORACLEJDK9_UJA_ALIAS="java-9-oracle-$ARCH_SUFFIX"
ORACLEJDK9_JAVA_HOME="/usr/lib/jvm/java-8-oracle-$ARCH_SUFFIX"
else
ORACLEJDK9_UJA_ALIAS="java-9-oracle"
ORACLEJDK9_JAVA_HOME="/usr/lib/jvm/java-9-oracle"
fi

UJA="update-java-alternatives"

switch_to_openjdk6 () {
Expand Down Expand Up @@ -88,6 +95,12 @@ switch_to_oraclejdk8 () {
export JAVA_HOME="$ORACLEJDK8_JAVA_HOME"
}

switch_to_oraclejdk9 () {
echo "Switching to Oracle JDK9 ($ORACLEJDK9_UJA_ALIAS), JAVA_HOME will be set to $ORACLEJDK9_JAVA_HOME"
sudo $UJA --set "$ORACLEJDK9_UJA_ALIAS"
export JAVA_HOME="$ORACLEJDK9_JAVA_HOME"
}

print_home_of_openjdk6 () {
echo "$OPENJDK6_JAVA_HOME"
}
Expand All @@ -108,6 +121,10 @@ print_home_of_oraclejdk8 () {
echo "$ORACLEJDK8_JAVA_HOME"
}

print_home_of_oraclejdk9 () {
echo "$ORACLEJDK9_JAVA_HOME"
}

warn_sunjdk6_eol () {
echo "Sun/Oracle JDK 6 is EOL since November 2012, and is no longer supported. Please consider upgrading..." >&2
}
Expand Down Expand Up @@ -146,6 +163,9 @@ switch_jdk()
oraclejdk8|oraclejdk1.8|oraclejdk1.8.0|oracle8|oracle1.8.0|oracle8.0)
switch_to_oraclejdk8
;;
oraclejdk9|oraclejdk1.9|oraclejdk1.9.0|oracle9|oracle1.9.0|oracle9.0)
switch_to_oraclejdk9
;;
default)
<% unless node['travis_java']['default_version'].empty? %>
switch_to_<%= node['travis_java']['default_version'] %>
Expand Down Expand Up @@ -188,6 +208,9 @@ print_java_home()
oraclejdk8|oraclejdk1.8|oraclejdk1.8.0|oracle8|oracle1.8.0|oracle8.0)
print_home_of_oraclejdk8
;;
oraclejdk9|oraclejdk1.9|oraclejdk1.9.0|oracle9|oracle1.9.0|oracle9.0)
print_home_of_oraclejdk9
;;
default)
<% unless node['travis_java']['default_version'].empty? %>
print_home_of_<%= node['travis_java']['default_version'] %>
Expand Down
2 changes: 2 additions & 0 deletions runtests
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ unset GEM_PATH
cd "$(dirname ${BASH_SOURCE[0]})"

if [[ -f $COOKBOOK_PATH/.rubocop.yml ]] ; then
echo "Testing with RuboCop $(rubocop --verbose-version)"
(cd $COOKBOOK_PATH && rubocop)
fi

echo "Testing with $(foodcritic --version)"
./run-foodcritic $COOKBOOK_PATH

0 comments on commit e7525d0

Please sign in to comment.