java-buildpack-utils 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d5a63ec7aa9ecad7568523adc89075349a3b4512
4
+ data.tar.gz: 112cdf27e79dae6a17cda5140d49b38da48e7b8c
5
+ SHA512:
6
+ metadata.gz: 3fb77f8e9818595c4f3542b137b94ada01b3c9dbfca065d25883ee6798bb589a90605ca7518125ff82c869960700e3c27d3a15b9492d76d603f305d8cd79c598
7
+ data.tar.gz: b573305763e73bbad9c6272786bab5bc28bcb357ec5fd4b5f6ff453d7bea4f64180f8152c7f49c470340c11e684abf9bf1b3f64df67d724dcfa0865e84e1beda
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/NOTICE ADDED
@@ -0,0 +1,2 @@
1
+ Cloud Foundry Java Buildpack Utilities
2
+ Copyright 2013 the original author or authors.
@@ -0,0 +1,9 @@
1
+ # Cloud Foundry Java Buildpack Utilities
2
+ [![Build Status](https://travis-ci.org/cloudfoundry/java-buildpack-utils.png?branch=master)](https://travis-ci.org/cloudfoundry/java-buildpack-utils)
3
+ [![Gem Version](https://badge.fury.io/rb/java-buildpack-utils.png)](http://badge.fury.io/rb/java-buildpack-utils)
4
+ [![Dependency Status](https://gemnasium.com/cloudfoundry/java-buildpack-utils.png)](http://gemnasium.com/cloudfoundry/java-buildpack-utils)
5
+ [![Code Climate](https://codeclimate.com/github/cloudfoundry/java-buildpack-utils.png)](https://codeclimate.com/github/cloudfoundry/java-buildpack-utils)
6
+
7
+ `java-buildpack-utils` provides a set of additional utilities for use in [Cloud Foundry][cf] Java buildpacks
8
+
9
+ [cf]: http://www.cloudfoundry.com
@@ -0,0 +1,61 @@
1
+ # Cloud Foundry Java Buildpack Utilities
2
+ # Copyright (c) 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
+ # A mixin that adds the ability to format a +Numeric+ as a user-readable duration
17
+ class Numeric
18
+
19
+ # Formats a number as a user-readable duration
20
+ #
21
+ # @return [String] a user-readable duration. Follows the following algorithm
22
+ # 1. If more than an hour, print hours and minutes
23
+ # 2. If less than an hour and more than a minute, print minutes and seconds
24
+ # 3. If less than a minute and more than a second, print seconds.milliseconds
25
+ # 4. If less than a second, print milliseconds
26
+ def duration
27
+ remainder = self
28
+
29
+ hours = (remainder / HOUR).to_int
30
+ remainder -= HOUR * hours
31
+
32
+ minutes = (remainder / MINUTE).to_int
33
+ remainder -= MINUTE * minutes
34
+
35
+ if hours > 0
36
+ return "#{hours}h #{minutes}m"
37
+ end
38
+
39
+ seconds = (remainder / SECOND).to_int
40
+ remainder -= SECOND * seconds
41
+
42
+ if minutes > 0
43
+ return "#{minutes}m #{seconds}s"
44
+ end
45
+
46
+ tenths = (remainder / TENTH).to_int
47
+ "#{seconds}.#{tenths}s"
48
+ end
49
+
50
+ private
51
+
52
+ MILLISECOND = 0.001
53
+
54
+ TENTH = 100 * MILLISECOND
55
+
56
+ SECOND = 10 * TENTH
57
+
58
+ MINUTE = 60 * SECOND
59
+
60
+ HOUR = 60 * MINUTE
61
+ end
@@ -0,0 +1,44 @@
1
+ # Cloud Foundry Java Buildpack Utilities
2
+ # Copyright (c) 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
+ # A module containing the functionality that allows a user to select which version of the JRE should be used to run
17
+ # their application. The user can set this information by using either a +system.properties+ file in the root of the
18
+ # pushed artifact or using environment variables.
19
+ #
20
+ # The JRE vendor can be specified by setting the +java.runtime.vendor+ property or the +JAVA_RUNTIME_VENDOR+ environment
21
+ # variable. Legal values for these properties are:
22
+ # * +*oracle*+
23
+ # * +openjdk+
24
+ #
25
+ # The JRE version can be specified by setting the +java.runtime.version+ property or the +JAVA_RUNTIME_VERSION+
26
+ # environment variable. Legal values for these properties are:
27
+ # * +6+
28
+ # * +*7*+
29
+ # * +8+
30
+ # * +1.6+
31
+ # * +1.7+
32
+ # * +1.8+
33
+ module JavaBuildpackUtils::Jre
34
+
35
+ # The relative path to Java within an application
36
+ JAVA_HOME = '.java'
37
+
38
+ end
39
+
40
+ require 'java-buildpack-utils/jre/compile'
41
+ require 'java-buildpack-utils/jre/detect'
42
+ require 'java-buildpack-utils/jre/selected_jre'
43
+ require 'java-buildpack-utils/jre/release'
44
+
@@ -0,0 +1,57 @@
1
+ # Cloud Foundry Java Buildpack Utilities
2
+ # Copyright (c) 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
+ require 'buildpack_utils'
17
+ require 'rubygems/package'
18
+ require 'zlib'
19
+
20
+ # A class containing the functionality required to download and unpack a JRE for a user based on input from the user
21
+ class JavaBuildpackUtils::Jre::Compile
22
+
23
+ # Creates a new instance, passing in the application directory and application cache directories used during
24
+ # compilation
25
+ #
26
+ # @param [String] app_dir The application directory used during compilation
27
+ # @param [String] app_cache_dir The application cache directory used during compilation
28
+ def initialize(app_dir, app_cache_dir)
29
+ @app_dir = app_dir
30
+ @global_cache = BuildpackUtils::GlobalCache.new
31
+ @selected_jre = JavaBuildpackUtils::Jre::SelectedJre.new(app_dir)
32
+ end
33
+
34
+ # The execution entry point for compilation. This method is responsible for downloading the correct version of Java
35
+ # and unpacking it to the application's runtime directory.
36
+ #
37
+ # @return [void]
38
+ def run
39
+ uri = @selected_jre.uri
40
+
41
+ download_start_time = Time.now
42
+ print "-----> Downloading #{@selected_jre.vendor} #{@selected_jre.version} JRE from #{uri} "
43
+ @global_cache.get(@selected_jre.id, uri) do |file|
44
+ puts "(#{(Time.now - download_start_time).duration})"
45
+
46
+ expand_start_time = Time.now
47
+ print "-----> Expanding JRE to #{JavaBuildpackUtils::Jre::JAVA_HOME} "
48
+
49
+ absolute_java_home = File.join @app_dir, JavaBuildpackUtils::Jre::JAVA_HOME
50
+ `rm -rf #{absolute_java_home}`
51
+ `mkdir -p #{absolute_java_home}`
52
+ `tar xzvf #{file.path} -C #{absolute_java_home} --strip 1 2>&1`
53
+ puts "(#{(Time.now - expand_start_time).duration})"
54
+ end
55
+ end
56
+
57
+ end
@@ -0,0 +1,35 @@
1
+ # Cloud Foundry Java Buildpack Utilities
2
+ # Copyright (c) 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
+ # A class containing the functionality required to determine if an application is a Java application based on the its
17
+ # explicit JRE configuration
18
+ class JavaBuildpackUtils::Jre::Detect
19
+
20
+ # Creates a new instance, passing in the application directory used during detection
21
+ #
22
+ # @param [String] app_dir The application directory used during detection
23
+ def initialize(app_dir)
24
+ @selected_jre = JavaBuildpackUtils::Jre::SelectedJre.new(app_dir)
25
+ end
26
+
27
+ # The execution entry point for detection. This method is responsible for identifying exactly which version of Java
28
+ # should be used and returning a string that represents it.
29
+ #
30
+ # @return [String] a unique value indicating exactly which version should be used. The value is structured as
31
+ # 'java-<vendor>-<version>'.
32
+ def run
33
+ @selected_jre.id
34
+ end
35
+ end
@@ -0,0 +1,32 @@
1
+ # Cloud Foundry Java Buildpack Utilities
2
+ # Copyright (c) 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
+ # A class containing the functionality required to describe where the JRE to use is located at runtime
17
+ class JavaBuildpackUtils::Jre::Release
18
+
19
+ # Creates a new instance, passing in the application directory used during release
20
+ #
21
+ # @param [String] app_dir The application directory used during release
22
+ def initialize(app_dir)
23
+ end
24
+
25
+ # The execution entry point for release. This method is responsible for describing the +JAVA_HOME+ location for the
26
+ # application.
27
+ #
28
+ # @return [String] the +JAVA_HOME+ location for the release
29
+ def run
30
+ JavaBuildpackUtils::Jre::JAVA_HOME
31
+ end
32
+ end
@@ -0,0 +1,106 @@
1
+ # Cloud Foundry Java Buildpack Utilities
2
+ # Copyright (c) 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
+ # A class containing information about the JRE selected by the user.
17
+ class JavaBuildpackUtils::Jre::SelectedJre
18
+
19
+ # The default JRE vendor
20
+ DEFAULT_VENDOR = 'oracle'
21
+
22
+ # The property key for specifying the vendor
23
+ KEY_VENDOR = 'java.runtime.vendor'
24
+
25
+ # The default JRE version
26
+ DEFAULT_VERSION = '7'
27
+
28
+ # The property key for specifying the version
29
+ KEY_VERSION = 'java.runtime.version'
30
+
31
+ # The collection of legal JREs
32
+ JRES = {
33
+ openjdk: {
34
+ J6: '',
35
+ J7: '',
36
+ J8: 'http://download.java.net/jdk8/archive/b88/binaries/jre-8-ea-bin-b88-linux-x64-02_may_2013.tar.gz'
37
+ },
38
+ oracle: {
39
+ J6: '',
40
+ J7: 'http://javadl.sun.com/webapps/download/AutoDL?BundleId=76853',
41
+ J8: ''
42
+ }
43
+ }
44
+
45
+ # @!attribute [r] id
46
+ # @return [String] a unique value indicating exactly which JRE is being used. The value is structured as
47
+ # 'java-<vendor>-<version>'
48
+ # @!attribute [r] uri
49
+ # @return [String] the download URI for the JRE being used
50
+ # @!attribute [r] vendor
51
+ # @return [String] the vendor for the JRE being used
52
+ # @!attribute [r] version
53
+ # @return [String] the version for the JRE being used
54
+ attr_reader :id, :uri, :vendor, :version
55
+
56
+ # Creates a new instance, passing in the application directory used during release
57
+ #
58
+ # @param [String] app_dir The application to inspect for values specified by the user
59
+ def initialize(app_dir)
60
+ properties = system_properties(app_dir)
61
+
62
+
63
+ @vendor = configured_vendor properties
64
+ @version = configured_version properties
65
+ @id = "java-#{@vendor}-#{@version}"
66
+ @uri = JRES[@vendor.to_sym]["J#{@version}".to_sym]
67
+ end
68
+
69
+ private
70
+
71
+ SYSTEM_PROPERTIES = 'system.properties'
72
+
73
+ def normalize_version(raw_version)
74
+ /(1.)?([\d])/.match(raw_version)[2]
75
+ end
76
+
77
+ def system_properties(app_dir)
78
+ file = File.join(app_dir, SYSTEM_PROPERTIES)
79
+
80
+ if File.exists?(file)
81
+ JavaBuildpackUtils::Properties.new(file)
82
+ else
83
+ nil
84
+ end
85
+ end
86
+
87
+ def configured_vendor(properties)
88
+ vendor = nil
89
+
90
+ unless properties.nil? && File.exists?(file)
91
+ vendor = properties[KEY_VENDOR]
92
+ end
93
+
94
+ vendor
95
+ end
96
+
97
+ def configured_version(properties)
98
+ raw_version = nil
99
+
100
+ unless properties.nil?
101
+ raw_version = properties[KEY_VERSION]
102
+ end
103
+
104
+ normalize_version raw_version
105
+ end
106
+ end
@@ -0,0 +1,42 @@
1
+ # Cloud Foundry Java Buildpack Utilities
2
+ # Copyright (c) 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
+ # A class representing a collection of Java properties
17
+ class JavaBuildpackUtils::Properties < Hash
18
+
19
+ # Create a new instance, populating it with values from a properties file
20
+ #
21
+ # @param [String] file the file to use for initialization
22
+ def initialize(file)
23
+ File.foreach(file) do |line|
24
+ unless blank_line?(line) || comment_line?(line)
25
+ if line =~ /^[\s]*([^:=\s]+)[\s]*[=:]?[\s]*([^:=\s]*)$/
26
+ self[$1] = $2
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def blank_line?(line)
35
+ line =~ /^[\s]*$/
36
+ end
37
+
38
+ def comment_line?(line)
39
+ line =~ /^[\s]*[#!].*$/
40
+ end
41
+
42
+ end
@@ -0,0 +1,22 @@
1
+ # Cloud Foundry Java Buildpack Utilities
2
+ # Copyright (c) 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
+ # A collection of utilities that are useful when implementing Cloud Foundry Java buildpacks.
17
+ module JavaBuildpackUtils
18
+ end
19
+
20
+ require 'java-buildpack-utils/format_duration'
21
+ require 'java-buildpack-utils/jre'
22
+ require 'java-buildpack-utils/properties'
@@ -0,0 +1,59 @@
1
+ # Cloud Foundry Java Buildpack Utilities
2
+ # Copyright (c) 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
+ require 'spec_helper'
17
+
18
+ describe 'format duration' do
19
+
20
+ it 'should display seconds' do
21
+ expect_time_string '0.0s', MILLISECOND
22
+ expect_time_string '0.1s', TENTH
23
+ expect_time_string '1.0s', SECOND
24
+ expect_time_string '1.1s', SECOND + TENTH
25
+ expect_time_string '1.1s', SECOND + TENTH + MILLISECOND
26
+ end
27
+
28
+ it 'should display minutes' do
29
+ expect_time_string '1m 0s', MINUTE
30
+ expect_time_string '1m 1s', MINUTE + SECOND
31
+ expect_time_string '1m 1s', MINUTE + SECOND + TENTH
32
+ expect_time_string '1m 1s', MINUTE + SECOND + TENTH + MILLISECOND
33
+ end
34
+
35
+ it 'should display hours' do
36
+ expect_time_string '1h 0m', HOUR
37
+ expect_time_string '1h 1m', HOUR + MINUTE
38
+ expect_time_string '1h 1m', HOUR + MINUTE + SECOND
39
+ expect_time_string '1h 1m', HOUR + MINUTE + SECOND + TENTH
40
+ expect_time_string '1h 1m', HOUR + MINUTE + SECOND + TENTH + MILLISECOND
41
+ end
42
+
43
+ private
44
+
45
+ MILLISECOND = 0.001
46
+
47
+ TENTH = 100 * MILLISECOND
48
+
49
+ SECOND = 10 * TENTH
50
+
51
+ MINUTE = 60 * SECOND
52
+
53
+ HOUR = 60 * MINUTE
54
+
55
+ def expect_time_string(expected, time)
56
+ expect(time.duration).to eq(expected)
57
+ end
58
+
59
+ end
@@ -0,0 +1,45 @@
1
+ # Cloud Foundry Java Buildpack Utilities
2
+ # Copyright (c) 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
+ require 'spec_helper'
17
+ require 'tmpdir'
18
+
19
+ describe JavaBuildpackUtils::Jre::Compile do
20
+
21
+ before do
22
+ @previous_value = ENV['BUILDPACK_CACHE']
23
+ ENV['BUILDPACK_CACHE'] = Dir.tmpdir
24
+ end
25
+
26
+
27
+ after do
28
+ ENV['BUILDPACK_CACHE'] = @previous_value
29
+ end
30
+
31
+ it 'should download specified JRE' do
32
+ Dir.mktmpdir do |root|
33
+ FileUtils.cp_r "#{FIXTURE}/.", root
34
+ JavaBuildpackUtils::Jre::Compile.new(root, Dir.tmpdir).run
35
+
36
+ absolute_java_home = File.join(root, JavaBuildpackUtils::Jre::JAVA_HOME, 'bin', 'java')
37
+ expect(File.exists?(absolute_java_home)).to be_true
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ FIXTURE = 'spec/fixtures/with_system_properties'
44
+
45
+ end
@@ -0,0 +1,28 @@
1
+ # Cloud Foundry Java Buildpack Utilities
2
+ # Copyright (c) 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
+ require 'spec_helper'
17
+
18
+ describe JavaBuildpackUtils::Jre::Detect do
19
+
20
+ before do
21
+ @detect = JavaBuildpackUtils::Jre::Detect.new('spec/fixtures/with_system_properties')
22
+ end
23
+
24
+ it 'should properly format Java version string' do
25
+ expect(@detect.run).to eq('java-openjdk-8')
26
+ end
27
+
28
+ end
@@ -0,0 +1,28 @@
1
+ # Cloud Foundry Java Buildpack Utilities
2
+ # Copyright (c) 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
+ require 'spec_helper'
17
+
18
+ describe JavaBuildpackUtils::Jre::Release do
19
+
20
+ before do
21
+ @release = JavaBuildpackUtils::Jre::Release.new('spec/fixtures/with_system_properties')
22
+ end
23
+
24
+ it 'should return the proper JAVA_HOME' do
25
+ expect(@release.run).to eq('.java')
26
+ end
27
+
28
+ end
@@ -0,0 +1,32 @@
1
+ # Cloud Foundry Java Buildpack Utilities
2
+ # Copyright (c) 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
+ require 'spec_helper'
17
+
18
+ describe JavaBuildpackUtils::Jre::SelectedJre do
19
+
20
+ before do
21
+ @selected_jre = JavaBuildpackUtils::Jre::SelectedJre.new('spec/fixtures/with_system_properties')
22
+ end
23
+
24
+ it 'should return the id' do
25
+ expect(@selected_jre.id).to eq('java-openjdk-8')
26
+ end
27
+
28
+ it 'should return the uri' do
29
+ expect(@selected_jre.uri).to eq(JavaBuildpackUtils::Jre::SelectedJre::JRES[:openjdk][:J8])
30
+ end
31
+
32
+ end
@@ -0,0 +1,28 @@
1
+ # Cloud Foundry Java Buildpack Utilities
2
+ # Copyright (c) 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
+ require 'spec_helper'
17
+
18
+ describe JavaBuildpackUtils::Properties do
19
+
20
+ it 'should parse properties' do
21
+ properties = JavaBuildpackUtils::Properties.new('spec/fixtures/test.properties')
22
+ expect(properties['alpha']).to eq('bravo')
23
+ expect(properties['charlie']).to eq('delta')
24
+ expect(properties['echo']).to eq('foxtrot')
25
+ expect(properties['golf']).to eq('')
26
+ end
27
+
28
+ end
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: java-buildpack-utils
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ben Hale
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: buildpack-utils
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: redcarpet
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '2.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '2.13'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '2.13'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '0.7'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '0.7'
97
+ - !ruby/object:Gem::Dependency
98
+ name: yard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '0.8'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '0.8'
111
+ description: Provides a set of utilities for use in Cloud Foundry Java buildpacks
112
+ email: bhale@gopivotal.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - LICENSE
118
+ - NOTICE
119
+ - README.md
120
+ - lib/java-buildpack-utils/format_duration.rb
121
+ - lib/java-buildpack-utils/jre/compile.rb
122
+ - lib/java-buildpack-utils/jre/detect.rb
123
+ - lib/java-buildpack-utils/jre/release.rb
124
+ - lib/java-buildpack-utils/jre/selected_jre.rb
125
+ - lib/java-buildpack-utils/jre.rb
126
+ - lib/java-buildpack-utils/properties.rb
127
+ - lib/java_buildpack_utils.rb
128
+ - spec/java-buildpack-utils/format_duration_spec.rb
129
+ - spec/java-buildpack-utils/jre/compile_spec.rb
130
+ - spec/java-buildpack-utils/jre/detect_spec.rb
131
+ - spec/java-buildpack-utils/jre/release_spec.rb
132
+ - spec/java-buildpack-utils/jre/selected_jre_spec.rb
133
+ - spec/java-buildpack-utils/properties_spec.rb
134
+ homepage: https://github.com/cloudfoundry/java-buildpack-utils
135
+ licenses:
136
+ - Apache-2.0
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - '>='
145
+ - !ruby/object:Gem::Version
146
+ version: 1.9.3
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - '>='
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.0.0
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: Utilities for use in Cloud Foundry Java buildpacks
158
+ test_files:
159
+ - spec/java-buildpack-utils/format_duration_spec.rb
160
+ - spec/java-buildpack-utils/jre/compile_spec.rb
161
+ - spec/java-buildpack-utils/jre/detect_spec.rb
162
+ - spec/java-buildpack-utils/jre/release_spec.rb
163
+ - spec/java-buildpack-utils/jre/selected_jre_spec.rb
164
+ - spec/java-buildpack-utils/properties_spec.rb
165
+ has_rdoc: