Skip to content

Commit 326ade4

Browse files
committed
Empty classpath improvements
Previously, when there were no additional libraries, the classpath would render as '-cp '. This was a problem when that argument was followed by something else. Applications would end up with something like '-cp app.groovy' which was incorrect. This change updates the as_classpath() method to return nil if there is are no additional libraries ensuring that the '-cp' argument is never added to the command.
1 parent 0eeaace commit 326ade4

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/java_buildpack/component/additional_libraries.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def initialize(droplet_root)
4040
def as_classpath
4141
qualified_paths = sort.map { |path| qualify_path path }
4242

43-
"-cp #{qualified_paths.join ':'}"
43+
"-cp #{qualified_paths.join ':'}" unless empty?
4444
end
4545

4646
# Symlink the contents of the collection to a destination directory.

spec/java_buildpack/component/additional_libraries_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@
4444
end
4545
end
4646

47+
it 'should render empty string if classpath is empty' do
48+
additional_libraries.clear
49+
expect(additional_libraries.as_classpath).not_to be
50+
end
51+
4752
it 'should symbolically link additional libraries' do
4853
additional_libraries.link_to app_dir
4954

0 commit comments

Comments
 (0)