Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 0 additions & 61 deletions .github/workflows/codescene.yml

This file was deleted.

15 changes: 13 additions & 2 deletions build/docker/alpine.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ RUN wget https://services.gradle.org/distributions/gradle-$GRADLE_VERSION-bin.zi
unzip gradle-$GRADLE_VERSION-bin.zip -d $GRADLE_HOME && \
rm gradle-$GRADLE_VERSION-bin.zip

# Add SBT, used for Scala resolution
ENV SBT_VERSION="1.10.11"
ENV SBT_HOME="/usr/lib/sbt"
ENV PATH="$SBT_HOME/bin:$PATH"
RUN wget https://github.com/sbt/sbt/releases/download/v${SBT_VERSION}/sbt-${SBT_VERSION}.tgz && \
mkdir -p $SBT_HOME && \
tar -zxvf sbt-${SBT_VERSION}.tgz -C $SBT_HOME --strip-components=1 && \
rm sbt-${SBT_VERSION}.tgz && \
ln -s $SBT_HOME/bin/sbt /usr/bin/sbt

# g++ needed to compile python packages with C dependencies (numpy, scipy, etc.)
RUN apk --no-cache --update add \
openjdk21-jdk \
Expand All @@ -47,7 +57,8 @@ RUN apk --no-cache --update add \
npm \
yarn \
g++ \
curl
curl \
bash

RUN apk --no-cache --update add dotnet8-sdk go~=1.23 --repository=https://dl-cdn.alpinelinux.org/alpine/v3.20/community

Expand All @@ -68,7 +79,7 @@ RUN apk add --no-cache --virtual build-dependencies curl && \
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer \
&& apk del build-dependencies

RUN php -v && composer --version
RUN php -v && composer --version && sbt --version

CMD [ "debricked", "scan" ]

Expand Down
12 changes: 12 additions & 0 deletions build/docker/debian.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ RUN apt update -y && \
sh -c 'echo "deb https://packages.sury.org/php/ bookworm main" > /etc/apt/sources.list.d/php.list' && \
apt -y clean && rm -rf /var/lib/apt/lists/*

# Add SBT, used for Scala resolution
ENV SBT_VERSION="1.10.11"
ENV SBT_HOME="/usr/lib/sbt"
ENV PATH="$SBT_HOME/bin:$PATH"
RUN curl -fsSLO https://github.com/sbt/sbt/releases/download/v${SBT_VERSION}/sbt-${SBT_VERSION}.tgz && \
mkdir -p $SBT_HOME && \
tar -zxvf sbt-${SBT_VERSION}.tgz -C $SBT_HOME --strip-components=1 && \
rm sbt-${SBT_VERSION}.tgz && \
ln -s $SBT_HOME/bin/sbt /usr/bin/sbt

RUN sbt --version

RUN apt -y update && apt -y install \
php8.3 \
php8.3-curl \
Expand Down
8 changes: 8 additions & 0 deletions internal/file/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,14 @@ func (finder *Finder) GetSupportedFormats() ([]*CompiledFormat, error) {
return nil, err
}

sbtEntry := &Format{
ManifestFileRegex: "^build\\.sbt$",
DocumentationUrl: "https://docs.debricked.com/overview/language-support/scala-sbt",
LockFileRegexes: []string{""},
}

formats = append(formats, sbtEntry)

var compiledDependencyFileFormats []*CompiledFormat
for _, format := range formats {
compiledDependencyFileFormat, err := NewCompiledFormat(format)
Expand Down
10 changes: 9 additions & 1 deletion internal/resolution/pm/maven/testdata/cmd_factory_mock.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package testdata

import "os/exec"
import (
"os/exec"
"runtime"
)

type CmdFactoryMock struct {
Err error
Expand All @@ -12,5 +15,10 @@ func (f CmdFactoryMock) MakeDependencyTreeCmd(_ string) (*exec.Cmd, error) {
if len(f.Arg) == 0 {
f.Arg = `"MakeDependencyTreeCmd"`
}

if runtime.GOOS == "windows" && f.Name == "echo" {
return exec.Command("cmd", "/C", f.Name, f.Arg), nil
}

return exec.Command(f.Name, f.Arg), f.Err
}
2 changes: 2 additions & 0 deletions internal/resolution/pm/pm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/debricked/cli/internal/resolution/pm/npm"
"github.com/debricked/cli/internal/resolution/pm/nuget"
"github.com/debricked/cli/internal/resolution/pm/pip"
"github.com/debricked/cli/internal/resolution/pm/sbt"
"github.com/debricked/cli/internal/resolution/pm/yarn"
)

Expand All @@ -28,5 +29,6 @@ func Pms() []IPm {
bower.NewPm(),
nuget.NewPm(),
composer.NewPm(),
sbt.NewPm(),
}
}
55 changes: 55 additions & 0 deletions internal/resolution/pm/sbt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# SBT (Scala) Resolution Logic

The resolution of SBT (Scala Build Tool) dependencies works as follows:

1. Parse the `build.sbt` file to identify any modules
2. Run `sbt makePom` in the project directory to generate a POM file
3. Find the generated `.pom` file (typically in `target/scala-<version>/<project>-<version>.pom`)
4. Copy/rename the `.pom` file to `pom.xml` in the same directory as `build.sbt`
5. Use the existing Maven resolver to handle the `pom.xml` file

This approach allows SBT projects to leverage the existing Maven resolution logic after the POM file is generated.

## Requirements

1. SBT must be installed and available in the PATH
2. The SBT project must be configured to support the `makePom` command (most SBT projects support this by default)
3. Maven dependencies must be resolvable as described in the Maven resolution documentation

## Private Dependencies

Similar to Maven projects, SBT projects might use dependencies from repositories other than the default ones. The
SBT `makePom` command will include these repository configurations in the generated POM file, and then the Maven
resolution process will handle them as described in the Maven README.

## Troubleshooting

If you encounter issues with SBT resolution:

1. Verify SBT is installed and accessible in the PATH
2. Try running `sbt makePom` manually in your project directory to check if it works
3. Inspect the generated `.pom` file in `target/scala-*/` to ensure it contains the correct dependencies
4. Check if any repository authentication is required for your dependencies

## Error Messages

Common error messages and their meanings:

- `SBT wasn't found`: The SBT executable isn't installed or isn't in the PATH
- `Failed to generate Maven POM file`: There was an error during the POM generation process
- `SBT configuration file not found`: The build.sbt file couldn't be found or accessed
- `Failed to parse SBT build file`: The build.sbt file contains syntax errors
- `We weren't able to retrieve one or more dependencies or plugins`: Network issues prevented dependency resolution

## Example Command

```shell
debricked resolve /path/to/scala/project
```

This will:

1. Find all `build.sbt` files in the specified path
2. Generate a POM file for each one
3. Resolve dependencies using the Maven resolver
4. Create `maven.debricked.lock` files with the dependency information
67 changes: 67 additions & 0 deletions internal/resolution/pm/sbt/build_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package sbt

import (
"os"
"path/filepath"
"regexp"
)

type IBuildService interface {
ParseBuildModules(path string) ([]string, error)
FindPomFile(dir string) (string, error)
RenamePomToXml(pomFile, destDir string) (string, error)
}

type BuildService struct{}

func (b BuildService) ParseBuildModules(path string) ([]string, error) {
content, err := os.ReadFile(path)
if err != nil {
return nil, err
}

moduleRegex := regexp.MustCompile(`project\s*\(\s*"([^"]+)"\s*\)`)
matches := moduleRegex.FindAllStringSubmatch(string(content), -1)

modules := make([]string, 0, len(matches))
for _, match := range matches {
if len(match) > 1 {
modules = append(modules, match[1])
}
}

return modules, nil
}

func (b BuildService) FindPomFile(dir string) (string, error) {
targetDir := filepath.Join(dir, "target")

scalaVersionDirs, err := filepath.Glob(filepath.Join(targetDir, "scala-*"))
if err != nil || len(scalaVersionDirs) == 0 {
return "", err
}

for _, scalaDir := range scalaVersionDirs {
pomFiles, err := filepath.Glob(filepath.Join(scalaDir, "*.pom"))
if err == nil && len(pomFiles) > 0 {
return pomFiles[0], nil
}
}

return "", nil
}

func (b BuildService) RenamePomToXml(pomFile, destDir string) (string, error) {
content, err := os.ReadFile(pomFile)
if err != nil {
return "", err
}

pomXmlPath := filepath.Join(destDir, "pom.xml")
err = os.WriteFile(pomXmlPath, content, 0600)
if err != nil {
return "", err
}

return pomXmlPath, nil
}
Loading
Loading