@@ -19,7 +19,9 @@ use crate::version_resolver::{
19
19
resolve_version, OpenJdkArtifactRequirementSource , VersionResolveError ,
20
20
} ;
21
21
use buildpacks_jvm_shared:: output;
22
- use buildpacks_jvm_shared:: output:: { BuildpackOutputText , BuildpackOutputTextSection } ;
22
+ use buildpacks_jvm_shared:: output:: {
23
+ track_buildpack_timing, BuildpackOutputText , BuildpackOutputTextSection ,
24
+ } ;
23
25
use buildpacks_jvm_shared:: system_properties:: { read_system_properties, ReadSystemPropertiesError } ;
24
26
#[ cfg( test) ]
25
27
use buildpacks_jvm_shared_test as _;
@@ -92,18 +94,19 @@ impl Buildpack for OpenJdkBuildpack {
92
94
}
93
95
94
96
fn build ( & self , context : BuildContext < Self > ) -> libcnb:: Result < BuildResult , Self :: Error > {
95
- output:: print_buildpack_name ( "Heroku OpenJDK Buildpack" ) ;
96
-
97
- let resolved_version = resolve_version ( & context. app_dir )
98
- . map_err ( OpenJdkBuildpackError :: ResolveVersionError ) ?;
99
-
100
- if matches ! (
101
- resolved_version. source,
102
- OpenJdkArtifactRequirementSource :: DefaultVersionLatestLts
103
- ) {
104
- output:: print_warning (
105
- "No OpenJDK version specified" ,
106
- formatdoc ! { "
97
+ track_buildpack_timing ( || {
98
+ output:: print_buildpack_name ( "Heroku OpenJDK Buildpack" ) ;
99
+
100
+ let resolved_version = resolve_version ( & context. app_dir )
101
+ . map_err ( OpenJdkBuildpackError :: ResolveVersionError ) ?;
102
+
103
+ if matches ! (
104
+ resolved_version. source,
105
+ OpenJdkArtifactRequirementSource :: DefaultVersionLatestLts
106
+ ) {
107
+ output:: print_warning (
108
+ "No OpenJDK version specified" ,
109
+ formatdoc ! { "
107
110
Your application does not explicitly specify an OpenJDK version. The latest
108
111
long-term support (LTS) version will be installed. This currently is OpenJDK {OPENJDK_LATEST_LTS_VERSION}.
109
112
@@ -115,74 +118,79 @@ impl Buildpack for OpenJdkBuildpack {
115
118
directory of your application to contain:
116
119
117
120
java.runtime.version = {OPENJDK_LATEST_LTS_VERSION}" } ,
118
- ) ;
119
- }
120
-
121
- output:: print_section ( "OpenJDK version resolution" ) ;
122
-
123
- match resolved_version. source {
124
- OpenJdkArtifactRequirementSource :: SystemProperties => {
125
- output:: print_subsection ( BuildpackOutputText :: new ( vec ! [
126
- BuildpackOutputTextSection :: regular( "Using version string provided in " ) ,
127
- BuildpackOutputTextSection :: value( "system.properties" ) ,
128
- ] ) ) ;
121
+ ) ;
129
122
}
130
- OpenJdkArtifactRequirementSource :: DefaultVersionLatestLts => {
131
- output:: print_subsection ( "No explicit configuration found, using latest LTS" ) ;
132
- }
133
- OpenJdkArtifactRequirementSource :: DefaultVersionFunctions => {
134
- output:: print_subsection ( BuildpackOutputText :: new ( vec ! [
135
- BuildpackOutputTextSection :: regular( "No explicit configuration found, using " ) ,
136
- BuildpackOutputTextSection :: value( "8" ) ,
137
- ] ) ) ;
138
- }
139
- } ;
140
-
141
- let openjdk_inventory = include_str ! ( "../openjdk_inventory.toml" )
142
- . parse :: < Inventory < OpenJdkVersion , Sha256 , OpenJdkArtifactMetadata > > ( )
143
- . map_err ( OpenJdkBuildpackError :: ParseInventoryError ) ?;
144
-
145
- let openjdk_artifact = openjdk_inventory
146
- . partial_resolve (
147
- context
148
- . target
149
- . os
150
- . parse :: < Os > ( )
151
- . expect ( "OS should be always parseable, buildpack will not run on unsupported operating systems." ) ,
152
- // On platform API <= `0.9` together with lifecycle <= `0.17`, the `CNB_TARGET_ARCH` environment variable will not be set.
153
- // This will be the case for the `salesforce-functions` builder. To ensure this buildpack can run there, we will
154
- // fall back to Rust's architecture constant when the architecture cannot be determined. This workaround can be removed when
155
- // the `salesforce-functions` builder is EOL.
156
- Some ( context. target . arch . as_str ( ) )
157
- . filter ( |value| !value. is_empty ( ) )
158
- . unwrap_or ( consts:: ARCH )
159
- . parse :: < Arch > ( )
160
- . expect ( "arch should be always parseable, buildpack will not run on unsupported architectures." ) ,
161
- & resolved_version. requirement ,
162
- )
163
- . ok_or ( OpenJdkBuildpackError :: UnsupportedOpenJdkVersion (
164
- resolved_version. requirement . clone ( ) ,
165
- ) ) ?;
166
-
167
- output:: print_subsection ( match resolved_version. requirement . version {
168
- HerokuOpenJdkVersionRequirement :: Major ( major_version) => {
169
- BuildpackOutputText :: new ( vec ! [
170
- BuildpackOutputTextSection :: regular( "Selected major version " ) ,
171
- BuildpackOutputTextSection :: value( format!( "{major_version}" ) ) ,
172
- BuildpackOutputTextSection :: regular( " resolves to " ) ,
173
- BuildpackOutputTextSection :: value( format!( "{}" , openjdk_artifact. version) ) ,
174
- ] )
175
- }
176
- HerokuOpenJdkVersionRequirement :: Specific ( version) => BuildpackOutputText :: new ( vec ! [
177
- BuildpackOutputTextSection :: regular( "Selected version " ) ,
178
- BuildpackOutputTextSection :: value( format!( "{version}" ) ) ,
179
- ] ) ,
180
- } ) ;
181
-
182
- handle_openjdk_layer ( & context, openjdk_artifact) ?;
183
- handle_runtime_layer ( & context) ?;
184
123
185
- BuildResultBuilder :: new ( ) . build ( )
124
+ output:: print_section ( "OpenJDK version resolution" ) ;
125
+
126
+ match resolved_version. source {
127
+ OpenJdkArtifactRequirementSource :: SystemProperties => {
128
+ output:: print_subsection ( BuildpackOutputText :: new ( vec ! [
129
+ BuildpackOutputTextSection :: regular( "Using version string provided in " ) ,
130
+ BuildpackOutputTextSection :: value( "system.properties" ) ,
131
+ ] ) ) ;
132
+ }
133
+ OpenJdkArtifactRequirementSource :: DefaultVersionLatestLts => {
134
+ output:: print_subsection ( "No explicit configuration found, using latest LTS" ) ;
135
+ }
136
+ OpenJdkArtifactRequirementSource :: DefaultVersionFunctions => {
137
+ output:: print_subsection ( BuildpackOutputText :: new ( vec ! [
138
+ BuildpackOutputTextSection :: regular(
139
+ "No explicit configuration found, using " ,
140
+ ) ,
141
+ BuildpackOutputTextSection :: value( "8" ) ,
142
+ ] ) ) ;
143
+ }
144
+ } ;
145
+
146
+ let openjdk_inventory = include_str ! ( "../openjdk_inventory.toml" )
147
+ . parse :: < Inventory < OpenJdkVersion , Sha256 , OpenJdkArtifactMetadata > > ( )
148
+ . map_err ( OpenJdkBuildpackError :: ParseInventoryError ) ?;
149
+
150
+ let openjdk_artifact = openjdk_inventory
151
+ . partial_resolve (
152
+ context
153
+ . target
154
+ . os
155
+ . parse :: < Os > ( )
156
+ . expect ( "OS should be always parseable, buildpack will not run on unsupported operating systems." ) ,
157
+ // On platform API <= `0.9` together with lifecycle <= `0.17`, the `CNB_TARGET_ARCH` environment variable will not be set.
158
+ // This will be the case for the `salesforce-functions` builder. To ensure this buildpack can run there, we will
159
+ // fall back to Rust's architecture constant when the architecture cannot be determined. This workaround can be removed when
160
+ // the `salesforce-functions` builder is EOL.
161
+ Some ( context. target . arch . as_str ( ) )
162
+ . filter ( |value| !value. is_empty ( ) )
163
+ . unwrap_or ( consts:: ARCH )
164
+ . parse :: < Arch > ( )
165
+ . expect ( "arch should be always parseable, buildpack will not run on unsupported architectures." ) ,
166
+ & resolved_version. requirement ,
167
+ )
168
+ . ok_or ( OpenJdkBuildpackError :: UnsupportedOpenJdkVersion (
169
+ resolved_version. requirement . clone ( ) ,
170
+ ) ) ?;
171
+
172
+ output:: print_subsection ( match resolved_version. requirement . version {
173
+ HerokuOpenJdkVersionRequirement :: Major ( major_version) => {
174
+ BuildpackOutputText :: new ( vec ! [
175
+ BuildpackOutputTextSection :: regular( "Selected major version " ) ,
176
+ BuildpackOutputTextSection :: value( format!( "{major_version}" ) ) ,
177
+ BuildpackOutputTextSection :: regular( " resolves to " ) ,
178
+ BuildpackOutputTextSection :: value( format!( "{}" , openjdk_artifact. version) ) ,
179
+ ] )
180
+ }
181
+ HerokuOpenJdkVersionRequirement :: Specific ( version) => {
182
+ BuildpackOutputText :: new ( vec ! [
183
+ BuildpackOutputTextSection :: regular( "Selected version " ) ,
184
+ BuildpackOutputTextSection :: value( format!( "{version}" ) ) ,
185
+ ] )
186
+ }
187
+ } ) ;
188
+
189
+ handle_openjdk_layer ( & context, openjdk_artifact) ?;
190
+ handle_runtime_layer ( & context) ?;
191
+
192
+ BuildResultBuilder :: new ( ) . build ( )
193
+ } )
186
194
}
187
195
188
196
fn on_error ( & self , error : libcnb:: Error < Self :: Error > ) {
0 commit comments