Skip to content

Commit e857485

Browse files
committed
Merge 54518072-pogos to master
[Completes #54518072]
2 parents 8527f04 + 5aa4cc4 commit e857485

4 files changed

Lines changed: 58 additions & 5 deletions

File tree

lib/java_buildpack/container/groovy.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
require 'java_buildpack/repository/configured_item'
2020
require 'java_buildpack/util/application_cache'
2121
require 'java_buildpack/util/format_duration'
22+
require 'java_buildpack/util/groovy_utils'
2223
require 'pathname'
2324
require 'set'
2425
require 'tmpdir'
@@ -159,15 +160,15 @@ def other_groovy(app_dir)
159160
end
160161

161162
def self.main_method(app_dir, candidates)
162-
select(app_dir, candidates) { |file| file.read =~ /static void main\(/ }
163+
select(app_dir, candidates) { |file| JavaBuildpack::Util::GroovyUtils.main_method? file }
163164
end
164165

165166
def self.non_pogo(app_dir, candidates)
166-
reject(app_dir, candidates) { |file| file.read =~ /class [\w]+ {/ }
167+
reject(app_dir, candidates) { |file| JavaBuildpack::Util::GroovyUtils.pogo? file }
167168
end
168169

169170
def self.shebang(app_dir, candidates)
170-
select(app_dir, candidates) { |file| file.read =~ /#!/ }
171+
select(app_dir, candidates) { |file| JavaBuildpack::Util::GroovyUtils.shebang? file }
171172
end
172173

173174
def self.reject(app_dir, candidates, &block)

lib/java_buildpack/container/spring_boot_cli.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
require 'java_buildpack/repository/configured_item'
2020
require 'java_buildpack/util/application_cache'
2121
require 'java_buildpack/util/format_duration'
22+
require 'java_buildpack/util/groovy_utils'
2223
require 'fileutils'
2324
require 'pathname'
2425
require 'set'
@@ -151,15 +152,15 @@ def self.spring_boot_cli(app_dir)
151152
end
152153

153154
def self.no_main_method(app_dir, groovy_files)
154-
none?(app_dir, groovy_files) { |file| file.read =~ /static void main\(/ } # note that this will scan comments
155+
none?(app_dir, groovy_files) { |file| JavaBuildpack::Util::GroovyUtils.main_method? file } # note that this will scan comments
155156
end
156157

157158
def self.has_web_inf(app_dir)
158159
File.exist?(File.join(app_dir, 'WEB-INF'))
159160
end
160161

161162
def self.all_pogo(app_dir, groovy_files)
162-
all?(app_dir, groovy_files) { |file| file.read =~ /class [\w]+ {/ } # note that this will scan comments
163+
all?(app_dir, groovy_files) { |file| JavaBuildpack::Util::GroovyUtils.pogo? file } # note that this will scan comments
163164
end
164165

165166
def self.all?(app_dir, groovy_files, &block)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 'java_buildpack/util'
18+
19+
module JavaBuildpack::Util
20+
21+
# Utilities for dealing with Groovy applications
22+
class GroovyUtils
23+
24+
# Indicates whether a file has a +main()+ method in it
25+
#
26+
# @param [File] file the file to scan
27+
# @return [Boolean] +true+ if the file contains a +main()+ method, +false+ otherwise.
28+
def self.main_method?(file)
29+
file.read =~ /static void main\(/
30+
end
31+
32+
# Indicates whether a file is a POGO
33+
#
34+
# @param [File] file the file to scan
35+
# @return [Boolean] +true+ if the file is a POGO, +false+ otherwise.
36+
def self.pogo?(file)
37+
file.read =~ /class [\w]+ [\s\w]*{/
38+
end
39+
40+
# Indicates whether a file has a shebang
41+
#
42+
# @param [File] file the file to scan
43+
# @return [Boolean] +true+ if the file has a shebang, +false+ otherwise.
44+
def self.shebang?(file)
45+
file.read =~ /#!/
46+
end
47+
48+
end
49+
50+
end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
class Runner implements CommandLineRunner {

0 commit comments

Comments
 (0)