Skip to content

Commit 81c52c4

Browse files
author
Glyn Normington
committed
Add Postgresql JDBC framework
[#52325263]
1 parent 36cf532 commit 81c52c4

8 files changed

Lines changed: 141 additions & 31 deletions

File tree

.idea/codeStyleSettings.xml

Lines changed: 1 addition & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/components.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ frameworks:
3131
- "JavaBuildpack::Framework::SpringInsight"
3232
- "JavaBuildpack::Framework::PlayAutoReconfiguration"
3333
- "JavaBuildpack::Framework::PlayJpaPlugin"
34+
- "JavaBuildpack::Framework::PostgresqlJdbc"
3435
- "JavaBuildpack::Framework::SpringAutoReconfiguration"

config/postgresqljdbc.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Cloud Foundry Java Buildpack
2+
# Copyright (c) 2013 the original author or authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# Configuration for the Postgresql JDBC framework
17+
---
18+
version: 9.3.+
19+
repository_root: "http://download.pivotal.io.s3.amazonaws.com/postgresql-jdbc"

java-buildpack.iml

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<module type="RUBY_MODULE" version="4">
33
<component name="ModuleRunConfigurationManager">
4-
<configuration default="false" name="Without Integration Tests" type="RSpecRunConfigurationType" factoryName="RSpec" singleton="true">
4+
<configuration default="false" name="All Tests" type="RSpecRunConfigurationType" factoryName="RSpec" singleton="true">
55
<predefined_log_file id="RUBY_RSPEC" enabled="true" />
66
<module name="java-buildpack" />
77
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
@@ -26,7 +26,7 @@
2626
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/*_spec.rb" />
2727
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="" />
2828
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="ALL_IN_FOLDER" />
29-
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_ARGS" VALUE="-t ~integration" />
29+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_ARGS" VALUE="" />
3030
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_VERSION" VALUE="" />
3131
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="USE_CUSTOM_SPEC_RUNNER" VALUE="false" />
3232
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="DRB" VALUE="false" />
@@ -38,7 +38,7 @@
3838
<ConfigurationWrapper RunnerId="RubyRunner" />
3939
<method />
4040
</configuration>
41-
<configuration default="false" name="All Tests" type="RSpecRunConfigurationType" factoryName="RSpec" singleton="true">
41+
<configuration default="false" name="Without Integration Tests" type="RSpecRunConfigurationType" factoryName="RSpec" singleton="true">
4242
<predefined_log_file id="RUBY_RSPEC" enabled="true" />
4343
<module name="java-buildpack" />
4444
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
@@ -63,7 +63,7 @@
6363
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/*_spec.rb" />
6464
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="" />
6565
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="ALL_IN_FOLDER" />
66-
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_ARGS" VALUE="" />
66+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_ARGS" VALUE="-t ~integration" />
6767
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_VERSION" VALUE="" />
6868
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="USE_CUSTOM_SPEC_RUNNER" VALUE="false" />
6969
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="DRB" VALUE="false" />
@@ -75,7 +75,7 @@
7575
<ConfigurationWrapper RunnerId="RubyRunner" />
7676
<method />
7777
</configuration>
78-
<configuration default="false" name="maria_db_jdbc_spec" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true">
78+
<configuration default="false" name="compile_spec" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true">
7979
<predefined_log_file id="RUBY_RSPEC" enabled="true" />
8080
<module name="java-buildpack" />
8181
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
@@ -95,7 +95,7 @@
9595
</EXTENSION>
9696
<EXTENSION ID="org.jetbrains.plugins.ruby.motion.run.MotionSimulatorRunExtension" />
9797
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TESTS_FOLDER_PATH" VALUE="" />
98-
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$MODULE_DIR$/spec/java_buildpack/framework/maria_db_jdbc_spec.rb" />
98+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$MODULE_DIR$/spec/bin/compile_spec.rb" />
9999
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_RUNNER_PATH" VALUE="" />
100100
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/*_spec.rb" />
101101
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="" />
@@ -149,7 +149,7 @@
149149
<ConfigurationWrapper RunnerId="RubyRunner" />
150150
<method />
151151
</configuration>
152-
<configuration default="false" name="compile_spec" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true">
152+
<configuration default="false" name="groovy_spec" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true">
153153
<predefined_log_file id="RUBY_RSPEC" enabled="true" />
154154
<module name="java-buildpack" />
155155
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
@@ -169,7 +169,7 @@
169169
</EXTENSION>
170170
<EXTENSION ID="org.jetbrains.plugins.ruby.motion.run.MotionSimulatorRunExtension" />
171171
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TESTS_FOLDER_PATH" VALUE="" />
172-
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$MODULE_DIR$/spec/bin/compile_spec.rb" />
172+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$MODULE_DIR$/spec/java_buildpack/container/groovy_spec.rb" />
173173
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_RUNNER_PATH" VALUE="" />
174174
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/*_spec.rb" />
175175
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="" />
@@ -180,13 +180,11 @@
180180
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="DRB" VALUE="false" />
181181
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ZEUS" VALUE="false" />
182182
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="FULL_BACKTRACE" VALUE="false" />
183-
<RunnerSettings RunnerId="RubyDebugRunner" />
184183
<RunnerSettings RunnerId="RubyRunner" />
185-
<ConfigurationWrapper RunnerId="RubyDebugRunner" />
186184
<ConfigurationWrapper RunnerId="RubyRunner" />
187185
<method />
188186
</configuration>
189-
<configuration default="false" name="groovy_spec" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true">
187+
<configuration default="false" name="spring_boot_cli_spec" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true">
190188
<predefined_log_file id="RUBY_RSPEC" enabled="true" />
191189
<module name="java-buildpack" />
192190
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
@@ -206,7 +204,7 @@
206204
</EXTENSION>
207205
<EXTENSION ID="org.jetbrains.plugins.ruby.motion.run.MotionSimulatorRunExtension" />
208206
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TESTS_FOLDER_PATH" VALUE="" />
209-
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$MODULE_DIR$/spec/java_buildpack/container/groovy_spec.rb" />
207+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$MODULE_DIR$/spec/java_buildpack/container/spring_boot_cli_spec.rb" />
210208
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_RUNNER_PATH" VALUE="" />
211209
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/*_spec.rb" />
212210
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="" />
@@ -221,7 +219,7 @@
221219
<ConfigurationWrapper RunnerId="RubyRunner" />
222220
<method />
223221
</configuration>
224-
<configuration default="false" name="spring_boot_cli_spec" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true">
222+
<configuration default="false" name="Run spec 'postgresql_jdbc_spec': java-buildpack" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true">
225223
<predefined_log_file id="RUBY_RSPEC" enabled="true" />
226224
<module name="java-buildpack" />
227225
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
@@ -232,7 +230,7 @@
232230
<envs>
233231
<env name="JRUBY_OPTS" value="-X+O" />
234232
</envs>
235-
<EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" />
233+
<EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="false" />
236234
<EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
237235
<EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov">
238236
<COVERAGE_PATTERN ENABLED="true">
@@ -241,7 +239,7 @@
241239
</EXTENSION>
242240
<EXTENSION ID="org.jetbrains.plugins.ruby.motion.run.MotionSimulatorRunExtension" />
243241
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TESTS_FOLDER_PATH" VALUE="" />
244-
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$MODULE_DIR$/spec/java_buildpack/container/spring_boot_cli_spec.rb" />
242+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$MODULE_DIR$/spec/java_buildpack/framework/postgresql_jdbc_spec.rb" />
245243
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_RUNNER_PATH" VALUE="" />
246244
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/*_spec.rb" />
247245
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="" />
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Encoding: utf-8
2+
# Cloud Foundry Java Buildpack
3+
# Copyright 2013 the original author or authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
require 'fileutils'
18+
require 'java_buildpack/framework'
19+
require 'java_buildpack/util/service_utils'
20+
require 'java_buildpack/versioned_dependency_component'
21+
22+
module JavaBuildpack::Framework
23+
24+
# Encapsulates the functionality for enabling the Postgres JDBC client.
25+
class PostgresqlJdbc < JavaBuildpack::VersionedDependencyComponent
26+
27+
def initialize(context)
28+
super('Postgresql JDBC', context)
29+
end
30+
31+
def compile
32+
download_jar jar_name
33+
end
34+
35+
def release
36+
end
37+
38+
protected
39+
40+
def supports?
41+
!has_driver? && JavaBuildpack::Util::ServiceUtils.find_service(@vcap_services, SERVICE_NAME)
42+
end
43+
44+
private
45+
46+
SERVICE_NAME = /elephantsql/.freeze
47+
48+
def jar_name
49+
"#{@parsable_component_name}-#{@version}.jar"
50+
end
51+
52+
def has_driver?
53+
!@application.glob('postgresql-*.jar').empty?
54+
end
55+
56+
end
57+
58+
end

spec/fixtures/framework_postgresql_jdbc_with_driver/postgresql-9.3-1100-jdbc41.jar

Whitespace-only changes.

spec/fixtures/stub-postgresql-0.0-0000-jdbc00.jar

Whitespace-only changes.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Encoding: utf-8
2+
# Cloud Foundry Java Buildpack
3+
# Copyright 2013 the original author or authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
require 'spec_helper'
18+
require 'component_helper'
19+
require 'java_buildpack/framework/postgresql_jdbc'
20+
21+
describe JavaBuildpack::Framework::PostgresqlJdbc, service_type: 'elephantsql-n/a' do
22+
include_context 'component_helper'
23+
24+
it 'should detect with elephantsql-n/a service' do
25+
expect(component.detect).to eq("postgresql-jdbc=#{version}")
26+
end
27+
28+
context do
29+
let(:vcap_services) { {} }
30+
31+
it 'should not detect without elephantsql-n/a service' do
32+
expect(component.detect).to be_nil
33+
end
34+
end
35+
36+
it 'should not detect if the application already has a Postgres driver',
37+
app_fixture: 'framework_postgresql_jdbc_with_driver' do
38+
expect(component.detect).not_to be
39+
end
40+
41+
it 'should copy the Postgres driver to the lib directory when needed',
42+
cache_fixture: 'stub-postgresql-0.0-0000-jdbc00.jar' do
43+
44+
component.compile
45+
46+
expect(additional_libs_dir + 'postgresql-jdbc-0.0.0.jar').to exist
47+
end
48+
49+
end

0 commit comments

Comments
 (0)