Skip to content

Commit 9fe6690

Browse files
author
Glyn Normington
committed
Avoid Groovy container detecting when there are .class files
Rather than code exceptions for specific files, such as logback.groovy, ensure the Groovy container does not detect when there are one or more .class files present. [#61282032]
1 parent 96a6cf1 commit 9fe6690

10 files changed

Lines changed: 77 additions & 7 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>

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
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.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright 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+
17+
import static ch.qos.logback.classic.Level.INFO
18+
19+
root(INFO)

spec/java_buildpack/container/groovy_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@
4545
expect(component.detect).to eq("groovy=#{version}")
4646
end
4747

48+
it 'should not detect a Groovy file with non-POGO and at least one .class file',
49+
app_fixture: 'container_groovy_non_pogo_with_class_file' do
50+
51+
expect(component.detect).to be_nil
52+
end
53+
4854
it 'should detect a Groovy file with #!',
4955
app_fixture: 'container_groovy_shebang' do
5056

0 commit comments

Comments
 (0)