Skip to content

Commit ef1bfc8

Browse files
committed
Support Spring Boot beans-style configuration
This change adds support for Spring Boot's beans-style configuration[1]. [1]: https://github.com/spring-projects/spring-boot/tree/master/spring-boot-cli#beans-dsl [#63606834]
1 parent 880c464 commit ef1bfc8

6 files changed

Lines changed: 27 additions & 7 deletions

File tree

java-buildpack.iml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@
270270
<orderEntry type="sourceFolder" forTests="false" />
271271
<orderEntry type="library" scope="PROVIDED" name="addressable (v2.3.5, rbenv: 1.9.3-p484) [gem]" level="application" />
272272
<orderEntry type="library" scope="PROVIDED" name="ast (v1.1.0, rbenv: 1.9.3-p484) [gem]" level="application" />
273-
<orderEntry type="library" scope="PROVIDED" name="bundler (v1.5.1, rbenv: 1.9.3-p484) [gem]" level="application" />
273+
<orderEntry type="library" scope="PROVIDED" name="bundler (v1.5.3, rbenv: 1.9.3-p484) [gem]" level="application" />
274274
<orderEntry type="library" scope="PROVIDED" name="codeclimate-test-reporter (v0.2.0, rbenv: 1.9.3-p484) [gem]" level="application" />
275275
<orderEntry type="library" scope="PROVIDED" name="crack (v0.4.1, rbenv: 1.9.3-p484) [gem]" level="application" />
276276
<orderEntry type="library" scope="PROVIDED" name="debugger-ruby_core_source (v1.2.4, rbenv: 1.9.3-p484) [gem]" level="application" />

lib/java_buildpack/container/spring_boot_cli.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def release
5151
# @macro versioned_dependency_component_supports
5252
def supports?
5353
gf = JavaBuildpack::Util::GroovyUtils.groovy_files(@application)
54-
gf.length > 0 && all_pogo(gf) && no_main_method(gf) && no_shebang(gf) && !has_web_inf
54+
gf.length > 0 && all_pogo_or_configuration(gf) && no_main_method(gf) && no_shebang(gf) && !has_web_inf
5555
end
5656

5757
private
@@ -76,8 +76,10 @@ def has_web_inf
7676
(@application.root + 'WEB-INF').exist?
7777
end
7878

79-
def all_pogo(groovy_files)
80-
all?(groovy_files) { |file| JavaBuildpack::Util::GroovyUtils.pogo? file } # note that this will scan comments
79+
def all_pogo_or_configuration(groovy_files)
80+
all?(groovy_files) do |file|
81+
JavaBuildpack::Util::GroovyUtils.pogo?(file) || JavaBuildpack::Util::GroovyUtils.beans?(file)
82+
end # note that this will scan comments
8183
end
8284

8385
def all?(groovy_files, &block)

lib/java_buildpack/util/groovy_utils.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,36 @@ class GroovyUtils
2626

2727
class << self
2828

29+
# Indicates whether a file is a +beans+style configuration
30+
#
31+
# @param [File] file the file to scan
32+
# @return [Boolean] +true+ if the file is a +beans+style configuration, +false+ otherwise.
33+
def beans?(file)
34+
Pathname.new(file).read =~ /beans[\s]*\{/
35+
end
36+
2937
# Indicates whether a file has a +main()+ method in it
3038
#
3139
# @param [File] file the file to scan
3240
# @return [Boolean] +true+ if the file contains a +main()+ method, +false+ otherwise.
3341
def main_method?(file)
34-
file.read =~ /static void main\(/
42+
Pathname.new(file).read =~ /static void main\(/
3543
end
3644

3745
# Indicates whether a file is a POGO
3846
#
3947
# @param [File] file the file to scan
4048
# @return [Boolean] +true+ if the file is a POGO, +false+ otherwise.
4149
def pogo?(file)
42-
file.read =~ /class [\w]+ [\s\w]*{/
50+
Pathname.new(file).read =~ /class [\w]+ [\s\w]*\{/
4351
end
4452

4553
# Indicates whether a file has a shebang
4654
#
4755
# @param [File] file the file to scan
4856
# @return [Boolean] +true+ if the file has a shebang, +false+ otherwise.
4957
def shebang?(file)
50-
file.read =~ /#!/
58+
Pathname.new(file).read =~ /#!/
5159
end
5260

5361
# Returns all the Ruby files in the given directory
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
beans {
2+
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
class X {

spec/java_buildpack/container/spring_boot_cli_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@
6363
expect(component.detect).to be_nil
6464
end
6565

66+
it 'should detect if there are Groovy files and they are all POGOs plus a beans-style configuration',
67+
app_fixture: 'container_spring_boot_cli_beans_configuration' do
68+
69+
expect(component.detect).to eq("spring-boot-cli=#{version}")
70+
end
71+
6672
it 'should detect if there are Groovy files and they are all POGOs with no main method and there is no WEB-INF directory',
6773
app_fixture: 'container_spring_boot_cli_valid_app' do
6874

0 commit comments

Comments
 (0)