-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR includes support to read a '.sdkmanrc' file if it's present at the root of the application. The version order is (from lowest to highest priority): Java buildpack default (11), Maven MANIFEST.MF properties, SDKMAN RC file, and BP_JVM_VERSION. Higher priority locations override lower priority locations. Note that Maven MANIFEST.MF entries only apply to pre-compiled assets (as MANIFEST.MF won't exist in a source build) and SDKMAN RC only applies when building from source (as it won't likely exist in a pre-compiled asset). The buildpack will read the '.sdkmanrc' file, look for the 'java' component (if multiple, it picks the first one), and takes the major Java version indicated in the entry. It ignore minor/patch versions, it also ignores the vendor (the vendor is set based on the buildpack you use). The buildpack ignores other components. Signed-off-by: Daniel Mikusa <dmikusa@vmware.com>
- Loading branch information
Daniel Mikusa
committed
May 16, 2022
1 parent
743dda2
commit cc0a400
Showing
6 changed files
with
349 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright 2018-2022 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package libjvm | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"strings" | ||
) | ||
|
||
// SDKInfo represents the information from each line in the `.sdkmanrc` file | ||
type SDKInfo struct { | ||
Type string | ||
Version string | ||
Vendor string | ||
} | ||
|
||
// ReadSDKMANRC reads the `.sdkmanrc` format file from path and retuns the list of SDKS in it | ||
func ReadSDKMANRC(path string) ([]SDKInfo, error) { | ||
sdkmanrcContents, err := ioutil.ReadFile(path) | ||
if err != nil { | ||
return []SDKInfo{}, fmt.Errorf("unable to read SDKMANRC file at %s\n%w", path, err) | ||
} | ||
|
||
sdks := []SDKInfo{} | ||
for _, line := range strings.Split(string(sdkmanrcContents), "\n") { | ||
if strings.TrimSpace(line) == "" { | ||
continue | ||
} | ||
|
||
parts := strings.SplitN(line, "#", 2) // strip comments | ||
if len(parts) != 1 && len(parts) != 2 { | ||
return []SDKInfo{}, fmt.Errorf("unable to strip comments from %q resulted in %q", line, parts) | ||
} | ||
|
||
if strings.TrimSpace(parts[0]) != "" { | ||
kv := strings.SplitN(parts[0], "=", 2) // split key=value | ||
if len(kv) != 2 { | ||
return []SDKInfo{}, fmt.Errorf("unable to split key/value from %q resulted in %q", parts[0], kv) | ||
} | ||
|
||
versionAndVendor := []string{"", ""} | ||
if strings.TrimSpace(kv[1]) != "" { | ||
versionAndVendor = strings.SplitN(kv[1], "-", 2) // split optional vendor name | ||
if len(versionAndVendor) == 1 { | ||
versionAndVendor = append(versionAndVendor, "") | ||
} | ||
if len(versionAndVendor) != 2 { | ||
return []SDKInfo{}, fmt.Errorf("unable to split vendor from %q resulted in %q", kv[1], versionAndVendor) | ||
} | ||
} | ||
|
||
sdks = append(sdks, SDKInfo{ | ||
Type: kv[0], | ||
Version: strings.TrimSpace(versionAndVendor[0]), | ||
Vendor: strings.TrimSpace(versionAndVendor[1]), | ||
}) | ||
} | ||
} | ||
|
||
return sdks, nil | ||
} |
Oops, something went wrong.