diff --git a/README.md b/README.md index 5c779fe..a520978 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ func main() { | cargo | Cargo.toml | Cargo.lock | | carthage | Cartfile, Cartfile.private | Cartfile.resolved | | chef | metadata.rb, metadata.json, Berksfile | | -| clojars | project.clj | | +| clojars | project.clj, deps.edn, bb.edn | | | cocoapods | Podfile, *.podspec | Podfile.lock | | composer | composer.json | composer.lock | | conan | conanfile.txt, conanfile.py | conan.lock | @@ -142,6 +142,28 @@ and `source` constraints carry no version and are skipped. Entries inside `if`, `elif` and `else` blocks keep the condition in `Marker`, for example `!(os(windows)) && impl(ghc >= 9.6)`, without evaluating it. +### Clojure deps.edn output + +`deps.edn` and babashka's `bb.edn` are read as EDN, so comments, commas, +`#_` discards, tagged literals and metadata are handled. Values nested more +than 100 levels deep are a parse error. Top-level `:deps` are runtime +dependencies under a `deps/` location. In `:aliases`, the `:extra-deps`, +`:replace-deps` and `:deps` of each alias are reported under +`aliases///`. An alias whose name contains `test` gives test +scope, `build` gives build scope and any other alias gives development scope. +`:override-deps` and `:default-deps` only adjust versions, so they are not +reported. + +A `:mvn/version` coordinate keeps its version. A `$classifier` suffix on the +lib is dropped from `Name`, while the location keeps it. Git coordinates use +the `git` source kind with `:git/sha` (or the older `:sha`) in `Ref`, +`:git/tag` in `Tag` and `:deps/root` in `Rel`. When `:git/url` is absent, the +URL is inferred from an `io.github`, `io.gitlab` or `io.bitbucket` lib (and +their `com.` and `org.` forms) as tools.deps does. `:local/root` uses the +`path` source kind. A coordinate with none of these keys is skipped. In +`bb.edn`, `:pods` are babashka pods rather than libraries, so they are not +reported. + ### Erlang output `rebar.config` and `*.app.src` are read as Erlang terms, the way diff --git a/clojure_deps_test.go b/clojure_deps_test.go new file mode 100644 index 0000000..1f95e85 --- /dev/null +++ b/clojure_deps_test.go @@ -0,0 +1,43 @@ +package manifests + +import ( + "os" + "testing" +) + +func TestClojureDepsEDNParse(t *testing.T) { + content, err := os.ReadFile("testdata/clojure/deps.edn") + if err != nil { + t.Fatal(err) + } + got, err := Parse("deps.edn", content) + if err != nil { + t.Fatal(err) + } + if got.Ecosystem != "clojars" || got.Kind != Manifest || len(got.Dependencies) != 13 { + t.Fatalf("got %s %s with %d dependencies", got.Ecosystem, got.Kind, len(got.Dependencies)) + } + if dep := got.Dependencies[0]; dep.Name != "org.clojure/clojure" || dep.PURL != "pkg:clojars/org.clojure%2Fclojure" { + t.Errorf("first dependency = %+v", dep) + } + if dep := got.Dependencies[4]; dep.Source.Kind != SourceGit || dep.Source.Value != "https://github.com/clojure/tools.build.git" { + t.Errorf("git dependency = %+v", dep) + } + if declaration := got.Declarations[8]; declaration.Scope != Test || declaration.PURL != "pkg:clojars/lambdaisland%2Fkaocha" { + t.Errorf("alias declaration = %+v", declaration) + } +} + +func TestClojureBBEDNParse(t *testing.T) { + content, err := os.ReadFile("testdata/clojure/bb.edn") + if err != nil { + t.Fatal(err) + } + got, err := Parse("bb.edn", content) + if err != nil { + t.Fatal(err) + } + if got.Ecosystem != "clojars" || got.Kind != Manifest || len(got.Dependencies) != 2 { + t.Fatalf("got %s %s with %d dependencies", got.Ecosystem, got.Kind, len(got.Dependencies)) + } +} diff --git a/internal/clojure/deps.go b/internal/clojure/deps.go new file mode 100644 index 0000000..bad166c --- /dev/null +++ b/internal/clojure/deps.go @@ -0,0 +1,155 @@ +package clojure + +import ( + "errors" + "strings" + + "github.com/git-pkgs/manifests/internal/core" +) + +func init() { + core.Register("clojars", core.Manifest, &depsEDNParser{}, core.ExactMatch("deps.edn", "bb.edn")) +} + +// depsEDNParser parses the deps and alias deps of deps.edn and bb.edn files. +type depsEDNParser struct{} + +// aliasDepKeys are the alias keys that add or replace dependencies. +var aliasDepKeys = []string{"extra-deps", "replace-deps", "deps"} + +// gitHosts infers a repository URL from a lib such as io.github.user/repo. +var gitHosts = map[string]string{ + "io.github": "https://github.com/", + "com.github": "https://github.com/", + "io.gitlab": "https://gitlab.com/", + "com.gitlab": "https://gitlab.com/", + "io.bitbucket": "https://bitbucket.org/", + "org.bitbucket": "https://bitbucket.org/", +} + +type depsWalker struct { + result *core.Result + locations map[string]int +} + +func (p *depsEDNParser) Parse(filename string, content []byte) (*core.Result, error) { + root, err := parseEDN(string(content)) + if err != nil { + return nil, &core.ParseError{Filename: filename, Err: err} + } + if root.kind != ednMap { + return nil, &core.ParseError{Filename: filename, Err: errors.New("top-level value is not a map")} + } + + walker := &depsWalker{result: &core.Result{}, locations: make(map[string]int)} + if deps, ok := root.get("deps"); ok { + walker.deps(deps, "deps", core.Runtime) + } + if aliases, ok := root.get("aliases"); ok && aliases.kind == ednMap { + for index := 0; index+1 < len(aliases.items); index += 2 { + name, alias := aliases.items[index], aliases.items[index+1] + if name.kind != ednKeyword { + continue + } + for _, key := range aliasDepKeys { + if deps, ok := alias.get(key); ok { + walker.deps(deps, "aliases/"+name.text+"/"+key, aliasScope(name.text)) + } + } + } + } + return walker.result, nil +} + +// aliasScope maps an alias name such as test or build to a scope. +func aliasScope(alias string) core.Scope { + name := strings.ToLower(alias) + switch { + case strings.Contains(name, "test"): + return core.Test + case name == "build" || strings.HasPrefix(name, "build/"): + return core.Build + } + return core.Development +} + +func (w *depsWalker) deps(deps ednValue, prefix string, scope core.Scope) { + if deps.kind != ednMap { + return + } + for index := 0; index+1 < len(deps.items); index += 2 { + lib, coord := deps.items[index], deps.items[index+1] + if lib.kind != ednSymbol { + continue + } + dep, ok := depsCoordinate(lib.text, coord) + if !ok { + continue + } + dep.Scope = scope + dep.Direct = true + w.result.Dependencies = append(w.result.Dependencies, dep) + w.result.Declarations = append(w.result.Declarations, core.Declaration{ + Name: dep.Name, + Version: dep.Version, + Scope: scope, + Direct: true, + Location: core.NextLocation(w.locations, prefix+"/"+lib.text), + Source: dep.Source, + }) + } +} + +// depsCoordinate reads a Maven, git or local coordinate for lib. +func depsCoordinate(lib string, coord ednValue) (core.Dependency, bool) { + if coord.kind != ednMap { + return core.Dependency{}, false + } + // A $classifier suffix selects an artifact of the same library. + name, _, _ := strings.Cut(lib, "$") + dep := core.Dependency{Name: name} + + if version := coord.str("mvn/version"); version != "" { + dep.Version = version + return dep, true + } + if root := coord.str("local/root"); root != "" { + dep.Source = core.Source{Kind: core.SourcePath, Value: root} + return dep, true + } + + url := coord.str("git/url") + sha := firstNonEmpty(coord.str("git/sha"), coord.str("sha")) + tag := firstNonEmpty(coord.str("git/tag"), coord.str("tag")) + if url == "" && sha == "" && tag == "" { + return core.Dependency{}, false + } + if url == "" { + url = inferGitURL(name) + } + dep.Source = core.Source{Kind: core.SourceGit, Value: url, Tag: tag, Ref: sha, Rel: coord.str("deps/root")} + return dep, true +} + +// inferGitURL builds the repository URL tools.deps infers for a lib. +func inferGitURL(lib string) string { + group, repo, ok := strings.Cut(lib, "/") + if !ok { + return "" + } + for prefix, host := range gitHosts { + if user, ok := strings.CutPrefix(group, prefix+"."); ok && user != "" { + return host + user + "/" + repo + ".git" + } + } + return "" +} + +func firstNonEmpty(values ...string) string { + for _, value := range values { + if value != "" { + return value + } + } + return "" +} diff --git a/internal/clojure/deps_test.go b/internal/clojure/deps_test.go new file mode 100644 index 0000000..fe91c10 --- /dev/null +++ b/internal/clojure/deps_test.go @@ -0,0 +1,143 @@ +package clojure + +import ( + "os" + "reflect" + "testing" + + "github.com/git-pkgs/manifests/internal/core" +) + +func parseDepsFixture(t *testing.T, name string) *core.Result { + t.Helper() + content, err := os.ReadFile("../../testdata/clojure/" + name) + if err != nil { + t.Fatalf("failed to read fixture: %v", err) + } + res, err := (&depsEDNParser{}).Parse(name, content) + if err != nil { + t.Fatalf("Parse failed: %v", err) + } + return res +} + +func TestDepsEDN(t *testing.T) { + res := parseDepsFixture(t, "deps.edn") + + dep := func(name, version string, scope core.Scope, source core.Source) core.Dependency { + return core.Dependency{Name: name, Version: version, Scope: scope, Direct: true, Source: source} + } + git := func(url, tag, sha, root string) core.Source { + return core.Source{Kind: core.SourceGit, Value: url, Tag: tag, Ref: sha, Rel: root} + } + want := []core.Dependency{ + dep("org.clojure/clojure", "1.11.1", core.Runtime, core.Source{}), + dep("ring/ring-core", "1.10.0", core.Runtime, core.Source{}), + dep("cheshire", "5.12.0", core.Runtime, core.Source{}), + dep("org.lwjgl/lwjgl", "3.3.3", core.Runtime, core.Source{}), + dep("io.github.clojure/tools.build", "", core.Runtime, git("https://github.com/clojure/tools.build.git", "v0.9.6", "8e78bcc", "")), + dep("com.example/forked", "", core.Runtime, git("https://git.example.com/forked.git", "", "0123456789abcdef0123456789abcdef01234567", "lib")), + dep("legacy/gitdep", "", core.Runtime, git("https://github.com/legacy/gitdep.git", "", "abc123", "")), + dep("my/local-lib", "", core.Runtime, core.Source{Kind: core.SourcePath, Value: "../local-lib"}), + dep("lambdaisland/kaocha", "1.87.1366", core.Test, core.Source{}), + dep("io.github.cognitect-labs/test-runner", "", core.Test, git("https://github.com/cognitect-labs/test-runner.git", "v0.5.1", "dfb30dd", "")), + dep("nrepl/nrepl", "1.1.0", core.Development, core.Source{}), + dep("io.github.clojure/tools.build", "0.9.6", core.Build, core.Source{}), + dep("com.github.liquidz/antq", "2.8.1185", core.Development, core.Source{}), + } + if !reflect.DeepEqual(res.Dependencies, want) { + t.Errorf("dependencies = %+v", res.Dependencies) + } + + if len(res.Declarations) != len(want) { + t.Fatalf("declarations = %+v", res.Declarations) + } + wantLocations := map[int]string{ + 0: "deps/org.clojure/clojure", + 3: "deps/org.lwjgl/lwjgl$natives-linux", + 8: "aliases/test/extra-deps/lambdaisland/kaocha", + 11: "aliases/build/deps/io.github.clojure/tools.build", + 12: "aliases/outdated/replace-deps/com.github.liquidz/antq", + } + for index, location := range wantLocations { + if got := res.Declarations[index].Location; got != location { + t.Errorf("declaration %d location = %q, want %q", index, got, location) + } + } +} + +func TestBBEDN(t *testing.T) { + res := parseDepsFixture(t, "bb.edn") + want := []core.Dependency{ + {Name: "medley/medley", Version: "1.4.0", Scope: core.Runtime, Direct: true}, + { + Name: "io.github.babashka/fs", Scope: core.Runtime, Direct: true, + Source: core.Source{Kind: core.SourceGit, Value: "https://github.com/babashka/fs.git", Ref: "a8d22b3"}, + }, + } + if !reflect.DeepEqual(res.Dependencies, want) { + t.Errorf("dependencies = %+v", res.Dependencies) + } +} + +func TestDepsEDNEdgeCases(t *testing.T) { + content := `{:deps {"string/lib" {:mvn/version "1"} + not-a-map "1.0" + unknown.host/repo {:git/sha "abc"} + ok/lib {:mvn/version "2.0"}} + :aliases {"string-alias" {:extra-deps {skipped/lib {:mvn/version "1"}}} + :empty {} + :test/unit {:extra-deps {unit/lib {:mvn/version "3"}}}}}` + res, err := (&depsEDNParser{}).Parse("deps.edn", []byte(content)) + if err != nil { + t.Fatal(err) + } + want := []core.Dependency{ + {Name: "unknown.host/repo", Scope: core.Runtime, Direct: true, Source: core.Source{Kind: core.SourceGit, Ref: "abc"}}, + {Name: "ok/lib", Version: "2.0", Scope: core.Runtime, Direct: true}, + {Name: "unit/lib", Version: "3", Scope: core.Test, Direct: true}, + } + if !reflect.DeepEqual(res.Dependencies, want) { + t.Errorf("dependencies = %+v", res.Dependencies) + } +} + +func TestDepsEDNInvalid(t *testing.T) { + for _, content := range []string{"[:not :a :map]", "{:deps {a/b", ""} { + if _, err := (&depsEDNParser{}).Parse("deps.edn", []byte(content)); err == nil { + t.Errorf("expected a parse error for %q", content) + } + } +} + +func TestAliasScope(t *testing.T) { + for alias, want := range map[string]core.Scope{ + "test": core.Test, + "test/unit": core.Test, + "kaocha-test": core.Test, + "build": core.Build, + "build/jar": core.Build, + "dev": core.Development, + "rebuild": core.Development, + } { + if got := aliasScope(alias); got != want { + t.Errorf("aliasScope(%q) = %q, want %q", alias, got, want) + } + } +} + +func TestInferGitURL(t *testing.T) { + for lib, want := range map[string]string{ + "io.github.user/repo": "https://github.com/user/repo.git", + "com.github.user/repo": "https://github.com/user/repo.git", + "io.gitlab.group/proj": "https://gitlab.com/group/proj.git", + "org.bitbucket.team/x": "https://bitbucket.org/team/x.git", + "io.github/repo": "", + "unqualified": "", + "org.example.user/repo": "", + } { + if got := inferGitURL(lib); got != want { + t.Errorf("inferGitURL(%q) = %q, want %q", lib, got, want) + } + } +} diff --git a/internal/clojure/edn.go b/internal/clojure/edn.go new file mode 100644 index 0000000..10c355f --- /dev/null +++ b/internal/clojure/edn.go @@ -0,0 +1,239 @@ +package clojure + +import ( + "fmt" + "strings" +) + +type ednKind int + +const ( + ednKeyword ednKind = iota + ednSymbol + ednString + ednScalar + ednMap + ednVector + ednList + ednSet +) + +// ednValue is an EDN value; a map holds alternating keys and values. +type ednValue struct { + kind ednKind + text string + items []ednValue +} + +// get returns the value of the keyword key, written without its colon. +func (v ednValue) get(key string) (ednValue, bool) { + if v.kind != ednMap { + return ednValue{}, false + } + for index := 0; index+1 < len(v.items); index += 2 { + if k := v.items[index]; k.kind == ednKeyword && k.text == key { + return v.items[index+1], true + } + } + return ednValue{}, false +} + +// str returns the text of a string value. +func (v ednValue) str(key string) string { + if value, ok := v.get(key); ok && value.kind == ednString { + return value.text + } + return "" +} + +// maxEDNDepth bounds nesting so hostile input cannot exhaust the stack. +const maxEDNDepth = 100 + +// parseEDN reads the single top-level value of an EDN file. +func parseEDN(src string) (ednValue, error) { + reader := &ednReader{src: src} + value, err := reader.value() + if err != nil { + return ednValue{}, err + } + reader.skipSpace() + if reader.err != nil { + return ednValue{}, reader.err + } + if !reader.eof() { + return ednValue{}, reader.errorf("unexpected content after the top-level value") + } + return value, nil +} + +type ednReader struct { + src string + pos int + depth int + err error +} + +func (r *ednReader) eof() bool { return r.pos >= len(r.src) } + +func (r *ednReader) errorf(format string, args ...any) error { + line := strings.Count(r.src[:min(r.pos, len(r.src))], "\n") + 1 + return fmt.Errorf("line %d: %s", line, fmt.Sprintf(format, args...)) +} + +// skipSpace skips white space, commas, ; comments and #_ discarded forms. +func (r *ednReader) skipSpace() { + for !r.eof() { + switch c := r.src[r.pos]; { + case c == ';': + for !r.eof() && r.src[r.pos] != '\n' { + r.pos++ + } + case c == ',' || c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f': + r.pos++ + case strings.HasPrefix(r.src[r.pos:], "#_"): + r.pos += 2 + if _, err := r.value(); err != nil { + r.err = err + return + } + default: + return + } + } +} + +func (r *ednReader) value() (ednValue, error) { + r.depth++ + defer func() { r.depth-- }() + if r.depth > maxEDNDepth { + return ednValue{}, r.errorf("values nested deeper than %d", maxEDNDepth) + } + r.skipSpace() + if r.err != nil { + return ednValue{}, r.err + } + if r.eof() { + return ednValue{}, r.errorf("unexpected end of input") + } + switch c := r.src[r.pos]; { + case c == '{': + r.pos++ + return r.collection(ednMap, '}') + case c == '[': + r.pos++ + return r.collection(ednVector, ']') + case c == '(': + r.pos++ + return r.collection(ednList, ')') + case strings.HasPrefix(r.src[r.pos:], "#{"): + r.pos += 2 + return r.collection(ednSet, '}') + case c == '#': + // A tagged literal such as #inst "..." reads as the value it tags. + r.pos++ + r.token() + return r.value() + case c == '^': + // Metadata attaches to the next value and is dropped. + r.pos++ + if _, err := r.value(); err != nil { + return ednValue{}, err + } + return r.value() + case c == '"': + return r.stringValue() + case c == '\\': + r.pos++ + start := r.pos + if !r.eof() { + r.pos++ + } + for !r.eof() && isEDNTokenChar(r.src[r.pos]) { + r.pos++ + } + return ednValue{kind: ednScalar, text: r.src[start:r.pos]}, nil + case c == ':': + r.pos++ + return ednValue{kind: ednKeyword, text: r.token()}, nil + case c == ')' || c == ']' || c == '}': + return ednValue{}, r.errorf("unexpected %q", c) + } + token := r.token() + if token == "" { + return ednValue{}, r.errorf("unexpected character %q", r.src[r.pos]) + } + if c := token[0]; c >= '0' && c <= '9' || (len(token) > 1 && (c == '-' || c == '+') && token[1] >= '0' && token[1] <= '9') { + return ednValue{kind: ednScalar, text: token}, nil + } + return ednValue{kind: ednSymbol, text: token}, nil +} + +func (r *ednReader) collection(kind ednKind, closing byte) (ednValue, error) { + collection := ednValue{kind: kind} + for { + r.skipSpace() + if r.err != nil { + return ednValue{}, r.err + } + if r.eof() { + return ednValue{}, r.errorf("expected %q", closing) + } + if r.src[r.pos] == closing { + r.pos++ + if kind == ednMap && len(collection.items)%2 != 0 { + return ednValue{}, r.errorf("map has a key without a value") + } + return collection, nil + } + item, err := r.value() + if err != nil { + return ednValue{}, err + } + collection.items = append(collection.items, item) + } +} + +func (r *ednReader) stringValue() (ednValue, error) { + r.pos++ + var value strings.Builder + for !r.eof() { + c := r.src[r.pos] + r.pos++ + switch { + case c == '"': + return ednValue{kind: ednString, text: value.String()}, nil + case c == '\\' && !r.eof(): + escaped := r.src[r.pos] + r.pos++ + switch escaped { + case 'n': + value.WriteByte('\n') + case 't': + value.WriteByte('\t') + case 'r': + value.WriteByte('\r') + default: + value.WriteByte(escaped) + } + default: + value.WriteByte(c) + } + } + return ednValue{}, r.errorf("unterminated string") +} + +func (r *ednReader) token() string { + start := r.pos + for !r.eof() && isEDNTokenChar(r.src[r.pos]) { + r.pos++ + } + return r.src[start:r.pos] +} + +func isEDNTokenChar(c byte) bool { + switch c { + case ' ', '\t', '\n', '\r', '\f', ',', '"', ';', '(', ')', '[', ']', '{', '}', '\\', '^': + return false + } + return true +} diff --git a/internal/clojure/edn_test.go b/internal/clojure/edn_test.go new file mode 100644 index 0000000..06570a5 --- /dev/null +++ b/internal/clojure/edn_test.go @@ -0,0 +1,80 @@ +package clojure + +import ( + "reflect" + "strings" + "testing" +) + +func TestParseEDN(t *testing.T) { + src := `; comment +{:kw/name "str\"ing\n", sym [1 -2.5 +3 \a \newline nil true] + :list (a b) :set #{x} #_ :discarded #_ #_ a b + :tagged #inst "2024-01-01" :meta ^:private value + "key" {}}` + value, err := parseEDN(src) + if err != nil { + t.Fatal(err) + } + keyword := func(v string) ednValue { return ednValue{kind: ednKeyword, text: v} } + symbol := func(v string) ednValue { return ednValue{kind: ednSymbol, text: v} } + scalar := func(v string) ednValue { return ednValue{kind: ednScalar, text: v} } + str := func(v string) ednValue { return ednValue{kind: ednString, text: v} } + want := ednValue{kind: ednMap, items: []ednValue{ + keyword("kw/name"), str("str\"ing\n"), + symbol("sym"), {kind: ednVector, items: []ednValue{ + scalar("1"), scalar("-2.5"), scalar("+3"), scalar("a"), scalar("newline"), symbol("nil"), symbol("true"), + }}, + keyword("list"), {kind: ednList, items: []ednValue{symbol("a"), symbol("b")}}, + keyword("set"), {kind: ednSet, items: []ednValue{symbol("x")}}, + keyword("tagged"), str("2024-01-01"), + keyword("meta"), symbol("value"), + str("key"), {kind: ednMap}, + }} + if !reflect.DeepEqual(value, want) { + t.Errorf("value = %+v", value) + } + if got := value.str("kw/name"); got != "str\"ing\n" { + t.Errorf("str = %q", got) + } + if _, ok := value.get("missing"); ok { + t.Error("missing key found") + } +} + +func TestParseEDNErrors(t *testing.T) { + for _, src := range []string{ + "", + "{:a 1", + "{:a}", + "[1 2)", + `"unterminated`, + "{} {}", + "#_", + ")", + } { + if _, err := parseEDN(src); err == nil { + t.Errorf("parseEDN(%q) succeeded", src) + } + } +} + +func TestParseEDNDepthLimit(t *testing.T) { + nested := func(depth int) string { + return strings.Repeat("[", depth) + strings.Repeat("]", depth) + } + if _, err := parseEDN(nested(maxEDNDepth)); err != nil { + t.Errorf("depth %d: %v", maxEDNDepth, err) + } + for _, src := range []string{ + nested(maxEDNDepth + 1), + strings.Repeat("{", 1_000_000), + strings.Repeat("#_", 1_000_000) + "a", + strings.Repeat("^", 1_000_000) + "a", + strings.Repeat("#tag ", 1_000) + "a", + } { + if _, err := parseEDN(src); err == nil || !strings.Contains(err.Error(), "nested deeper") { + t.Errorf("parseEDN(%.20q...) error = %v", src, err) + } + } +} diff --git a/manifests_test.go b/manifests_test.go index 1e9328a..88f5ab7 100644 --- a/manifests_test.go +++ b/manifests_test.go @@ -44,6 +44,8 @@ func TestParseAllEcosystems(t *testing.T) { {"vagrant Vagrantfile", "testdata/vagrant/Vagrantfile", "vagrant", Manifest}, {"hackage stack.yaml", "testdata/hackage/stack.yaml", "hackage", Manifest}, {"hex rebar.config", "testdata/rebar/rebar.config", "hex", Manifest}, + {"clojars deps.edn", "testdata/clojure/deps.edn", "clojars", Manifest}, + {"clojars bb.edn", "testdata/clojure/bb.edn", "clojars", Manifest}, {"hex myapp.app.src", "testdata/rebar/myapp.app.src", "hex", Manifest}, {"hackage cabal.project", "testdata/hackage/cabal.project", "hackage", Manifest}, } @@ -720,6 +722,13 @@ func TestIdentifyFiles(t *testing.T) { {"pyproject.toml", "pypi", Manifest, true}, {"poetry.lock", "pypi", Lockfile, true}, + // clojars + {"project.clj", "clojars", Manifest, true}, + {"deps.edn", "clojars", Manifest, true}, + {"bb.edn", "clojars", Manifest, true}, + {"nested/deps.edn", "clojars", Manifest, true}, + {"config.edn", "", "", false}, + // hex {"mix.exs", "hex", Manifest, true}, {"mix.lock", "hex", Lockfile, true}, diff --git a/testdata/clojure/bb.edn b/testdata/clojure/bb.edn new file mode 100644 index 0000000..70799ca --- /dev/null +++ b/testdata/clojure/bb.edn @@ -0,0 +1,8 @@ +{:min-bb-version "1.3.0" + :paths ["bb"] + :deps {medley/medley {:mvn/version "1.4.0"} + io.github.babashka/fs {:git/sha "a8d22b3"}} + :pods {org.babashka/go-sqlite3 {:version "0.1.0"}} + :tasks {:requires ([babashka.fs :as fs]) + test {:doc "Run tests" + :task (shell "clojure -M:test")}}} diff --git a/testdata/clojure/deps.edn b/testdata/clojure/deps.edn new file mode 100644 index 0000000..c021ce1 --- /dev/null +++ b/testdata/clojure/deps.edn @@ -0,0 +1,28 @@ +;; Example tools.deps project +{:paths ["src" "resources"] + + :deps {org.clojure/clojure {:mvn/version "1.11.1"} + ring/ring-core {:mvn/version "1.10.0" :exclusions [commons-io/commons-io]} + cheshire {:mvn/version "5.12.0"} + org.lwjgl/lwjgl$natives-linux {:mvn/version "3.3.3"} + io.github.clojure/tools.build {:git/tag "v0.9.6" :git/sha "8e78bcc"} + com.example/forked {:git/url "https://git.example.com/forked.git" + :git/sha "0123456789abcdef0123456789abcdef01234567" + :deps/root "lib"} + legacy/gitdep {:git/url "https://github.com/legacy/gitdep.git" :sha "abc123"} + my/local-lib {:local/root "../local-lib"} + #_#_ignored/lib {:mvn/version "0.0.1"} + no/coordinate {:exclusions [foo/bar]}} + + :mvn/repos {"internal" {:url "https://repo.example.com/maven"}} + + :aliases + {:test {:extra-paths ["test"] + :extra-deps {lambdaisland/kaocha {:mvn/version "1.87.1366"} + io.github.cognitect-labs/test-runner {:git/tag "v0.5.1" :git/sha "dfb30dd"}}} + :dev {:extra-deps {nrepl/nrepl {:mvn/version "1.1.0"}}} + :build {:deps {io.github.clojure/tools.build {:mvn/version "0.9.6"}} + :ns-default build} + :outdated {:replace-deps {com.github.liquidz/antq {:mvn/version "2.8.1185"}} + :main-opts ["-m" "antq.core"]} + :override {:override-deps {org.clojure/clojure {:mvn/version "1.12.0"}}}}}