Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for SBT #314

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Add support for SBT #314

wants to merge 1 commit into from

Conversation

johnewart
Copy link
Contributor

Also support .tgz and .tbz2 files in decompression bits

@johnewart johnewart requested a review from zombiezen June 1, 2021 16:01
if got := versionOutput.String(); !strings.Contains(got, version) {
t.Errorf("sbt --version output does not include %q", version)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to have some unit tests for the sbtDownloadURL function, like for the Java buildpack (but doesn't need to be nearly as extensive):

func TestJavaDownloadURL(t *testing.T) {
tests := []struct {
version string
want string
}{
{
version: "9+181",
want: "https://github.com/AdoptOpenJDK/openjdk9-binaries/releases/download/jdk-9%2B181/OpenJDK9U-jdk_x64_linux_hotspot_9_181.tar.gz",
},
{
version: "8.252+09",
want: "https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u252-b09/OpenJDK8U-jdk_x64_linux_hotspot_8u252b09.tar.gz",
},
{
version: "8.252.9",
want: "https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u252-b09/OpenJDK8U-jdk_x64_linux_hotspot_8u252b09.tar.gz",
},
{
version: "8.252.09",
want: "https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u252-b09/OpenJDK8U-jdk_x64_linux_hotspot_8u252b09.tar.gz",
},
{
version: "8.242+08",
want: "https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u242-b08/OpenJDK8U-jdk_x64_linux_hotspot_8u242b08.tar.gz",
},
{
version: "8.242.8",
want: "https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u242-b08/OpenJDK8U-jdk_x64_linux_hotspot_8u242b08.tar.gz",
},
{
version: "8.242.08",
want: "https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u242-b08/OpenJDK8U-jdk_x64_linux_hotspot_8u242b08.tar.gz",
},
{
version: "8.232+09",
want: "https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u232-b09/OpenJDK8U-jdk_x64_linux_hotspot_8u232b09.tar.gz",
},
{
version: "8.232.09",
want: "https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u232-b09/OpenJDK8U-jdk_x64_linux_hotspot_8u232b09.tar.gz",
},
{
version: "8.232.9",
want: "https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u232-b09/OpenJDK8U-jdk_x64_linux_hotspot_8u232b09.tar.gz",
},
{
version: "11.0.6",
want: "https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.6%2B10/OpenJDK11U-jdk_x64_linux_hotspot_11.0.6_10.tar.gz",
},
{
version: "11.0.6+10",
want: "https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.6%2B10/OpenJDK11U-jdk_x64_linux_hotspot_11.0.6_10.tar.gz",
},
{
version: "12.0.2+10",
want: "https://github.com/AdoptOpenJDK/openjdk12-binaries/releases/download/jdk-12.0.2%2B10/OpenJDK12U-jdk_x64_linux_hotspot_12.0.2_10.tar.gz",
},
{
version: "13.0.2+8",
want: "https://github.com/AdoptOpenJDK/openjdk13-binaries/releases/download/jdk-13.0.2%2B8/OpenJDK13U-jdk_x64_linux_hotspot_13.0.2_8.tar.gz",
},
{
version: "13.0.1+9",
want: "https://github.com/AdoptOpenJDK/openjdk13-binaries/releases/download/jdk-13.0.1%2B9/OpenJDK13U-jdk_x64_linux_hotspot_13.0.1_9.tar.gz",
},
{
version: "14",
want: "https://github.com/AdoptOpenJDK/openjdk14-binaries/releases/download/jdk-14%2B36/OpenJDK14U-jdk_x64_linux_hotspot_14_36.tar.gz",
},
{
version: "14+36",
want: "https://github.com/AdoptOpenJDK/openjdk14-binaries/releases/download/jdk-14%2B36/OpenJDK14U-jdk_x64_linux_hotspot_14_36.tar.gz",
},
}
for _, test := range tests {
desc := &biome.Descriptor{
OS: biome.Linux,
Arch: biome.Intel64,
}
got, err := javaDownloadURL(test.version, desc)
if got != test.want || err != nil {
t.Errorf("javaDownloadURL(%q, %+v) =\n%q, %v; want\n%q, <nil>", test.version, desc, got, err, test.want)
}
}
t.Run("Existence", func(t *testing.T) {
if testing.Short() {
t.Skip("Skipping due to -short")
}
for _, test := range tests {
verifyURLExists(t, http.MethodGet, test.want)
}
})
}

func TestSBT(t *testing.T) {
const version = "1.5.2"
ctx := testlog.WithTB(context.Background(), t)
// TODO(johnewart): SBT depends on Java -- see Ross's comment in sbt tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// TODO(johnewart): SBT depends on Java -- see Ross's comment in sbt tests
// TODO(johnewart): SBT depends on Java -- see Ross's comment in Ant tests

Comment on lines +66 to +111
func sbtDownloadURL(version string, desc *biome.Descriptor) (string, error) {
vparts := strings.SplitN(version, "+", 2)
subVersion := ""
if len(vparts) > 1 {
subVersion = vparts[1]
version = vparts[0]
}

parts := strings.Split(version, ".")

majorVersion, err := convertVersionPiece(parts, 0)
if err != nil {
return "", fmt.Errorf("parse jdk version %q: major: %w", version, err)
}
minorVersion, err := convertVersionPiece(parts, 1)
if err != nil {
return "", fmt.Errorf("parse jdk version %q: minor: %w", version, err)
}
patchVersion, err := convertVersionPiece(parts, 2)
if err != nil {
return "", fmt.Errorf("parse jdk version %q: patch: %w", version, err)
}

urlPattern := "https://github.com/sbt/sbt/releases/download/v{{ .MajorVersion }}.{{ .MinorVersion }}.{{ .PatchVersion }}/sbt-{{ .MajorVersion }}.{{ .MinorVersion }}.{{ .PatchVersion }}.tgz"

var data struct {
OS string
Arch string
MajorVersion int64
MinorVersion int64
PatchVersion int64
SubVersion string // not always an int, sometimes a float
}
data.OS = map[string]string{
biome.Linux: "linux",
biome.MacOS: "mac",
}[desc.OS]
if data.OS == "" {
return "", fmt.Errorf("unsupported os %s", desc.OS)
}
data.MajorVersion = majorVersion
data.MinorVersion = minorVersion
data.PatchVersion = patchVersion
data.SubVersion = subVersion
return templateToString(urlPattern, data)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, the URL is only dependent on version, right? I think this function can be simplified to pass the version string through verbatim.

Suggested change
func sbtDownloadURL(version string, desc *biome.Descriptor) (string, error) {
vparts := strings.SplitN(version, "+", 2)
subVersion := ""
if len(vparts) > 1 {
subVersion = vparts[1]
version = vparts[0]
}
parts := strings.Split(version, ".")
majorVersion, err := convertVersionPiece(parts, 0)
if err != nil {
return "", fmt.Errorf("parse jdk version %q: major: %w", version, err)
}
minorVersion, err := convertVersionPiece(parts, 1)
if err != nil {
return "", fmt.Errorf("parse jdk version %q: minor: %w", version, err)
}
patchVersion, err := convertVersionPiece(parts, 2)
if err != nil {
return "", fmt.Errorf("parse jdk version %q: patch: %w", version, err)
}
urlPattern := "https://github.com/sbt/sbt/releases/download/v{{ .MajorVersion }}.{{ .MinorVersion }}.{{ .PatchVersion }}/sbt-{{ .MajorVersion }}.{{ .MinorVersion }}.{{ .PatchVersion }}.tgz"
var data struct {
OS string
Arch string
MajorVersion int64
MinorVersion int64
PatchVersion int64
SubVersion string // not always an int, sometimes a float
}
data.OS = map[string]string{
biome.Linux: "linux",
biome.MacOS: "mac",
}[desc.OS]
if data.OS == "" {
return "", fmt.Errorf("unsupported os %s", desc.OS)
}
data.MajorVersion = majorVersion
data.MinorVersion = minorVersion
data.PatchVersion = patchVersion
data.SubVersion = subVersion
return templateToString(urlPattern, data)
}
func sbtDownloadURL(version string) (string, error) {
const urlPattern = "https://github.com/sbt/sbt/releases/download/v{{ .Version }}/sbt-{{ .Version }}.tgz"
var data struct {
Version string
}
data.Version = url.PathEscape(version)
return templateToString(urlPattern, data)
}

Comment on lines +34 to +35
parentDir := os.TempDir()
socketDir, err := ioutil.TempDir(parentDir, "*-ybsbt")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unfortunately won't work on Docker-based builds, since it creates the directory on the host instead of inside the biome.

Would it be appropriate to use a directory inside the biome home? Perhaps sys.Biome.JoinPath(sys.Biome.Dirs().Tools, "sbt-server")?

if err != nil {
log.Errorf(ctx, "Error creating directory for SBT sockets: %v", err)
}
log.Infof(ctx, "SBT will use %s as the socket directory", socketDir)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the average user needs to know this information unless something went wrong, so I suggest debug-level log.

Suggested change
log.Infof(ctx, "SBT will use %s as the socket directory", socketDir)
log.Debugf(ctx, "SBT will use %s as the socket directory", socketDir)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants