-
Notifications
You must be signed in to change notification settings - Fork 12
Simple workaround for scanning scala projects #301
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
47b0320
Scala project support added
biswajit-patra-dev af27b62
Add sbt support for docker images
biswajit-patra-dev b90c182
Add resolver logic to generate pom.xml file
biswajit-patra-dev 6fdeb83
Add review changes and resolve to use maven after creating pom.xml file
biswajit-patra-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,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 | ||
sweoggy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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 | ||
This file contains hidden or 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,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 | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.