-
Notifications
You must be signed in to change notification settings - Fork 93
Julia Project.toml and Manifest.toml extractors #1422
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
Open
JamesFoxxx
wants to merge
9
commits into
google:main
Choose a base branch
from
JamesFoxxx:julia-pkg-extractor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6bde6f6
julia Project.toml and Manifest.toml extractors
JamesFoxxx d712a44
delte redundant toml fields
JamesFoxxx 81267f3
we assume that the git tree sha1 is always correct
JamesFoxxx ccf5b89
Use the deps version existence at the beginning for efficiency, perfo…
JamesFoxxx 639df72
Merge branch 'google:main' into julia-pkg-extractor
JamesFoxxx 2553041
ignore testdata files for linelint
JamesFoxxx 25700fa
possible fix for golangci-lint error for non-PR file
JamesFoxxx 6779847
autofix linelint errors
JamesFoxxx a950dc9
revert .linelint.yml changes
JamesFoxxx 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 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
131 changes: 131 additions & 0 deletions
131
extractor/filesystem/language/julia/manifesttoml/manifesttoml.go
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,131 @@ | ||
| // Copyright 2025 Google LLC | ||
| // | ||
| // 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 | ||
| // | ||
| // http://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. | ||
|
|
||
| // Copyright 2025 Google LLC | ||
| // | ||
| // 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 | ||
| // | ||
| // http://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 manifesttoml extracts Manifest.toml files for Julia projects | ||
| package manifesttoml | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "path/filepath" | ||
|
|
||
| "github.com/BurntSushi/toml" | ||
|
|
||
| "github.com/google/osv-scalibr/extractor" | ||
| "github.com/google/osv-scalibr/extractor/filesystem" | ||
| "github.com/google/osv-scalibr/inventory" | ||
| "github.com/google/osv-scalibr/plugin" | ||
| "github.com/google/osv-scalibr/purl" | ||
| ) | ||
|
|
||
| const ( | ||
| // Name is the name of the Extractor. | ||
| Name = "julia/manifesttoml" | ||
| ) | ||
|
|
||
| type juliaManifestDependency struct { | ||
| Version string `toml:"version"` | ||
| GitTreeSha1 string `toml:"git-tree-sha1"` | ||
| RepoURL string `toml:"repo-url"` | ||
| Deps []string `toml:"deps"` | ||
| } | ||
|
|
||
| type juliaManifestFile struct { | ||
| ManifestFormat string `toml:"manifest_format"` | ||
| Dependencies map[string][]juliaManifestDependency `toml:"deps"` | ||
| } | ||
|
|
||
| // Extractor extracts Julia packages from Manifest.toml files. | ||
| type Extractor struct{} | ||
|
|
||
| // New returns a new instance of the extractor. | ||
| func New() filesystem.Extractor { return &Extractor{} } | ||
|
|
||
| // Name of the extractor | ||
| func (e Extractor) Name() string { return Name } | ||
|
|
||
| // Version of the extractor | ||
| func (e Extractor) Version() int { return 0 } | ||
|
|
||
| // FileRequired returns true if the specified file matches Julia Manifest.toml file patterns. | ||
| func (e Extractor) FileRequired(api filesystem.FileAPI) bool { | ||
| return filepath.Base(api.Path()) == "Manifest.toml" | ||
| } | ||
|
|
||
| // Requirements of the extractor | ||
| func (e Extractor) Requirements() *plugin.Capabilities { | ||
| return &plugin.Capabilities{} | ||
| } | ||
|
|
||
| // Extract extracts packages from Julia Manifest.toml files passed through the scan input. | ||
| func (e Extractor) Extract(ctx context.Context, input *filesystem.ScanInput) (inventory.Inventory, error) { | ||
| var parsedTomlFile juliaManifestFile | ||
|
|
||
| _, err := toml.NewDecoder(input.Reader).Decode(&parsedTomlFile) | ||
| if err != nil { | ||
| return inventory.Inventory{}, fmt.Errorf("could not extract: %w", err) | ||
| } | ||
|
|
||
| packages := make([]*extractor.Package, 0, len(parsedTomlFile.Dependencies)) | ||
|
|
||
| for name, dependencies := range parsedTomlFile.Dependencies { | ||
| if err := ctx.Err(); err != nil { | ||
| return inventory.Inventory{Packages: packages}, fmt.Errorf("%s halted due to context error: %w", e.Name(), err) | ||
| } | ||
|
|
||
| // Take the first dependency entry (Julia typically has one entry per package name) | ||
| if len(dependencies) == 0 { | ||
| continue | ||
| } | ||
| dependency := dependencies[0] | ||
| // Skip dependencies that have no version | ||
| if dependency.Version == "" { | ||
| continue | ||
| } | ||
|
|
||
| var srcCode *extractor.SourceCodeIdentifier | ||
| if dependency.GitTreeSha1 != "" { | ||
| srcCode = &extractor.SourceCodeIdentifier{ | ||
| Commit: dependency.GitTreeSha1, | ||
| Repo: dependency.RepoURL, // Include repo-url if available | ||
| } | ||
| } | ||
|
|
||
| packages = append(packages, &extractor.Package{ | ||
| Name: name, | ||
| Version: dependency.Version, | ||
| PURLType: purl.TypeJulia, | ||
| Locations: []string{input.Path}, | ||
| SourceCode: srcCode, | ||
| }) | ||
| } | ||
|
|
||
| return inventory.Inventory{Packages: packages}, nil | ||
| } | ||
|
|
||
| var _ filesystem.Extractor = Extractor{} |
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.