Skip to content

Commit 2874ca9

Browse files
author
Glyn Normington
committed
Merge 61282032-class-files-not-groovy to master
[Completes #61282032]
2 parents 96a6cf1 + f85e935 commit 2874ca9

15 files changed

Lines changed: 126 additions & 9 deletions

File tree

.idea/misc.xml

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

.idea/runConfigurations/All_Tests.xml

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

.idea/runConfigurations/Without_Integration_Tests.xml

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

docs/container-groovy.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ The Groovy Container allows a uncompiled (i.e. `*.groovy`) to be run.
77
<li>A <tt>.groovy</tt> file exists which has a <tt>main()</tt> method, or</li>
88
<li>A <tt>.groovy</tt> file exists which is not a POGO (a POGO contains one or more classes), or</li>
99
<li>A <tt>.groovy</tt> file exists which has a shebang (<tt>#!</tt>) declaration</li>
10+
</ul>and<ul>
11+
<li>No <tt>.class</tt> files exist</li>
1012
</ul></td>
1113
</tr>
1214
<tr>

docs/container-spring-boot-cli.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The Spring Boot CLI Container runs one or more Groovy (i.e. `*.groovy`) files us
77
<li>The application has one or more <tt>.groovy</tt> files in the root directory, and</li>
88
<li>All the application's <tt>.groovy</tt> files in the root directory are POGOs (a POGO contains one or more classes), and</li>
99
<li>None of the application's <tt>.groovy</tt> files in the root directory contain a <tt>main</tt> method, and</li>
10+
<li>None of the application's <tt>.groovy</tt> files in the root directory contain a shebang (`#!`) declaration, and</li>
1011
<li>The application does not have a <tt>WEB-INF</tt> subdirectory of its root directory.</li>
1112
</ul></td>
1213
</tr>

java-buildpack.iml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<module type="RUBY_MODULE" version="4">
3-
<component name="NewModuleRootManager" inherit-compiler-output="false">
3+
<component name="NewModuleRootManager">
44
<content url="file://$MODULE_DIR$">
55
<sourceFolder url="file://$MODULE_DIR$/lib/java_buildpack" isTestSource="false" />
66
<sourceFolder url="file://$MODULE_DIR$/bin" isTestSource="false" />

lib/java_buildpack/container/groovy.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# limitations under the License.
1616

1717
require 'java_buildpack/container'
18+
require 'java_buildpack/util/class_file_utils'
1819
require 'java_buildpack/util/format_duration'
1920
require 'java_buildpack/util/groovy_utils'
2021
require 'java_buildpack/versioned_dependency_component'
@@ -50,7 +51,9 @@ def release
5051
protected
5152

5253
def supports?
53-
main_groovy
54+
class_files = JavaBuildpack::Util::ClassFileUtils.class_files(@application)
55+
56+
class_files.empty? && main_groovy
5457
end
5558

5659
private

lib/java_buildpack/container/spring_boot_cli.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def release
5252

5353
def supports?
5454
gf = JavaBuildpack::Util::GroovyUtils.groovy_files(@application)
55-
gf.length > 0 && all_pogo(gf) && no_main_method(gf) && !has_web_inf
55+
gf.length > 0 && all_pogo(gf) && no_main_method(gf) && no_shebang(gf) && !has_web_inf
5656
end
5757

5858
private
@@ -65,6 +65,10 @@ def no_main_method(groovy_files)
6565
none?(groovy_files) { |file| JavaBuildpack::Util::GroovyUtils.main_method? file } # note that this will scan comments
6666
end
6767

68+
def no_shebang(groovy_files)
69+
none?(groovy_files) { |file| JavaBuildpack::Util::GroovyUtils.shebang? file }
70+
end
71+
6872
def has_web_inf
6973
@application.child('WEB-INF').exist?
7074
end
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 'pathname'
18+
require 'java_buildpack/util'
19+
20+
module JavaBuildpack::Util
21+
22+
# Utilities for dealing with .class files
23+
class ClassFileUtils
24+
25+
# Returns all the .class files in the given directory
26+
#
27+
# @param [Application] application the application to search
28+
# @return [Array] a possibly empty list of files
29+
def self.class_files(application)
30+
application.glob(CLASS_FILE_PATTERN).reject { |path| path.directory? }
31+
.map { |path| application.relative_path_to path }.sort
32+
end
33+
34+
private_class_method :new
35+
36+
private
37+
38+
CLASS_FILE_PATTERN = '**/*.class'.freeze
39+
40+
end
41+
42+
end

spec/fixtures/container_groovy_non_pogo_with_class_file/A.class

Whitespace-only changes.

0 commit comments

Comments
 (0)