From ea89e21fc7b234fed70424550d329bd4b151bb4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ignas=20Mikalaj=C5=ABnas?= Date: Mon, 24 Jul 2023 15:18:19 +0300 Subject: [PATCH] Handle excluded artifacts defined in non-root packages (#190) This handles different sub-packages having different sets of excluded artifacts, also fixes a crash when such a case occurs. --- java/gazelle/configure.go | 1 - java/gazelle/javaconfig/config.go | 5 + java/gazelle/private/maven/resolver.go | 25 +- java/gazelle/private/maven/resolver_test.go | 14 +- java/gazelle/resolve.go | 17 +- java/gazelle/resolve_test.go | 4 +- .../testdata/java_exclude_artifact/BUILD.in | 0 .../testdata/java_exclude_artifact/BUILD.out | 0 .../testdata/java_exclude_artifact/WORKSPACE | 27 ++ .../java_exclude_artifact/maven_install.json | 406 ++++++++++++++++++ .../java/com/example/hamcrest_all/App.java | 19 + .../java/com/example/hamcrest_all/BUILD.in | 1 + .../java/com/example/hamcrest_all/BUILD.out | 20 + .../java/com/example/hamcrest_core/App.java | 19 + .../java/com/example/hamcrest_core/BUILD.in | 1 + .../java/com/example/hamcrest_core/BUILD.out | 20 + 16 files changed, 553 insertions(+), 26 deletions(-) create mode 100644 java/gazelle/testdata/java_exclude_artifact/BUILD.in create mode 100644 java/gazelle/testdata/java_exclude_artifact/BUILD.out create mode 100644 java/gazelle/testdata/java_exclude_artifact/WORKSPACE create mode 100644 java/gazelle/testdata/java_exclude_artifact/maven_install.json create mode 100644 java/gazelle/testdata/java_exclude_artifact/src/java/com/example/hamcrest_all/App.java create mode 100644 java/gazelle/testdata/java_exclude_artifact/src/java/com/example/hamcrest_all/BUILD.in create mode 100644 java/gazelle/testdata/java_exclude_artifact/src/java/com/example/hamcrest_all/BUILD.out create mode 100644 java/gazelle/testdata/java_exclude_artifact/src/java/com/example/hamcrest_core/App.java create mode 100644 java/gazelle/testdata/java_exclude_artifact/src/java/com/example/hamcrest_core/BUILD.in create mode 100644 java/gazelle/testdata/java_exclude_artifact/src/java/com/example/hamcrest_core/BUILD.out diff --git a/java/gazelle/configure.go b/java/gazelle/configure.go index 7e5ddd98..9f60b9fc 100644 --- a/java/gazelle/configure.go +++ b/java/gazelle/configure.go @@ -134,7 +134,6 @@ func (jc *Configurer) Configure(c *config.Config, rel string, f *rule.File) { if jc.lang.mavenResolver == nil { resolver, err := maven.NewResolver( cfg.MavenInstallFile(), - cfg.ExcludedArtifacts(), jc.lang.logger, ) if err != nil { diff --git a/java/gazelle/javaconfig/config.go b/java/gazelle/javaconfig/config.go index da9cf481..4d4e8ad8 100644 --- a/java/gazelle/javaconfig/config.go +++ b/java/gazelle/javaconfig/config.go @@ -51,6 +51,10 @@ type Configs map[string]*Config // NewChild creates a new child Config. It inherits desired values from the // current Config and sets itself as the parent to the child. func (c *Config) NewChild() *Config { + clonedExcludedArtifacts := make(map[string]struct{}) + for key, value := range c.excludedArtifacts { + clonedExcludedArtifacts[key] = value + } return &Config{ parent: c, extensionEnabled: c.extensionEnabled, @@ -62,6 +66,7 @@ func (c *Config) NewChild() *Config { testMode: c.testMode, customTestFileSuffixes: c.customTestFileSuffixes, annotationToAttribute: c.annotationToAttribute, + excludedArtifacts: clonedExcludedArtifacts, } } diff --git a/java/gazelle/private/maven/resolver.go b/java/gazelle/private/maven/resolver.go index 5f978305..a600ea92 100644 --- a/java/gazelle/private/maven/resolver.go +++ b/java/gazelle/private/maven/resolver.go @@ -12,7 +12,7 @@ import ( ) type Resolver interface { - Resolve(pkg types.PackageName) (label.Label, error) + Resolve(pkg types.PackageName, excludedArtifacts map[string]struct{}) (label.Label, error) } // resolver finds Maven provided packages by reading the maven_install.json @@ -22,7 +22,7 @@ type resolver struct { logger zerolog.Logger } -func NewResolver(installFile string, excludedArtifacts map[string]struct{}, logger zerolog.Logger) (Resolver, error) { +func NewResolver(installFile string, logger zerolog.Logger) (Resolver, error) { r := resolver{ data: multiset.NewStringMultiSet(), logger: logger.With().Str("_c", "maven-resolver").Logger(), @@ -43,10 +43,7 @@ func NewResolver(installFile string, excludedArtifacts map[string]struct{}, logg if err != nil { return nil, fmt.Errorf("failed to parse coordinate %v: %w", coords, err) } - l := label.New("maven", "", bazel.CleanupLabel(coords.ArtifactString())) - if _, found := excludedArtifacts[l.String()]; found { - continue - } + l := LabelFromArtifact(coords.ArtifactString()) for _, pkg := range c.ListDependencyPackages(depName) { r.data.Add(pkg, l.String()) } @@ -55,19 +52,27 @@ func NewResolver(installFile string, excludedArtifacts map[string]struct{}, logg return &r, nil } -func (r *resolver) Resolve(pkg types.PackageName) (label.Label, error) { +func (r *resolver) Resolve(pkg types.PackageName, excludedArtifacts map[string]struct{}) (label.Label, error) { v, found := r.data.Get(pkg.Name) if !found { return label.NoLabel, fmt.Errorf("package not found: %s", pkg) } - switch len(v) { + var filtered []string + for k := range v { + if _, excluded := excludedArtifacts[k]; excluded { + continue + } + filtered = append(filtered, k) + } + + switch len(filtered) { case 0: return label.NoLabel, errors.New("no external imports") case 1: var ret string - for r := range v { + for _, r := range filtered { ret = r break } @@ -75,7 +80,7 @@ func (r *resolver) Resolve(pkg types.PackageName) (label.Label, error) { default: r.logger.Error().Msg("Append one of the following to BUILD.bazel:") - for k := range v { + for _, k := range filtered { r.logger.Error().Msgf("# gazelle:resolve java %s %s", pkg, k) } diff --git a/java/gazelle/private/maven/resolver_test.go b/java/gazelle/private/maven/resolver_test.go index 035305be..cd02249d 100644 --- a/java/gazelle/private/maven/resolver_test.go +++ b/java/gazelle/private/maven/resolver_test.go @@ -18,26 +18,26 @@ func TestResolver(t *testing.T) { m := make(map[string]struct{}) m["@maven//:com_google_j2objc_j2objc_annotations"] = struct{}{} - r, err := NewResolver("testdata/guava_maven_install.json", m, logger) + r, err := NewResolver("testdata/guava_maven_install.json", logger) if err != nil { t.Fatal(err) } - assertResolves(t, r, "com.google.common.collect", "@maven//:com_google_guava_guava") - assertResolves(t, r, "javax.annotation", "@maven//:com_google_code_findbugs_jsr305") - got, err := r.Resolve(types.NewPackageName("unknown.package")) + assertResolves(t, r, m, "com.google.common.collect", "@maven//:com_google_guava_guava") + assertResolves(t, r, m, "javax.annotation", "@maven//:com_google_code_findbugs_jsr305") + got, err := r.Resolve(types.NewPackageName("unknown.package"), m) if err == nil { t.Errorf("Want error finding label for unknown.package, got %v", got) } - got, err = r.Resolve(types.NewPackageName("com.google.j2objc.annotations")) + got, err = r.Resolve(types.NewPackageName("com.google.j2objc.annotations"), m) if err == nil { t.Errorf("Want error finding label for excluded artifact, got %v", got) } } -func assertResolves(t *testing.T, r Resolver, pkg, wantLabelStr string) { - got, err := r.Resolve(types.NewPackageName(pkg)) +func assertResolves(t *testing.T, r Resolver, excludePackages map[string]struct{}, pkg, wantLabelStr string) { + got, err := r.Resolve(types.NewPackageName(pkg), excludePackages) if err != nil { t.Errorf("Error finding label for %v: %v", pkg, err) } diff --git a/java/gazelle/resolve.go b/java/gazelle/resolve.go index 05a3780f..4eced15b 100644 --- a/java/gazelle/resolve.go +++ b/java/gazelle/resolve.go @@ -4,6 +4,7 @@ import ( "fmt" "sort" + "github.com/bazel-contrib/rules_jvm/java/gazelle/javaconfig" "github.com/bazel-contrib/rules_jvm/java/gazelle/private/java" "github.com/bazel-contrib/rules_jvm/java/gazelle/private/sorted_set" "github.com/bazel-contrib/rules_jvm/java/gazelle/private/types" @@ -81,13 +82,17 @@ func (Resolver) Embeds(r *rule.Rule, from label.Label) []label.Label { func (jr Resolver) Resolve(c *config.Config, ix *resolve.RuleIndex, rc *repo.RemoteCache, r *rule.Rule, imports interface{}, from label.Label) { resolveInput := imports.(types.ResolveInput) + packageConfig := c.Exts[languageName].(javaconfig.Configs)[from.Pkg] + if packageConfig == nil { + jr.lang.logger.Fatal().Msg("failed retrieving package config") + } isTestRule := isTestRule(r.Kind()) - jr.populateAttr(c, r, "deps", resolveInput.ImportedPackageNames, ix, isTestRule, from, resolveInput.PackageNames) - jr.populateAttr(c, r, "exports", resolveInput.ExportedPackageNames, ix, isTestRule, from, resolveInput.PackageNames) + jr.populateAttr(c, packageConfig, r, "deps", resolveInput.ImportedPackageNames, ix, isTestRule, from, resolveInput.PackageNames) + jr.populateAttr(c, packageConfig, r, "exports", resolveInput.ExportedPackageNames, ix, isTestRule, from, resolveInput.PackageNames) } -func (jr Resolver) populateAttr(c *config.Config, r *rule.Rule, attrName string, requiredPackageNames *sorted_set.SortedSet[types.PackageName], ix *resolve.RuleIndex, isTestRule bool, from label.Label, ownPackageNames *sorted_set.SortedSet[types.PackageName]) { +func (jr Resolver) populateAttr(c *config.Config, pc *javaconfig.Config, r *rule.Rule, attrName string, requiredPackageNames *sorted_set.SortedSet[types.PackageName], ix *resolve.RuleIndex, isTestRule bool, from label.Label, ownPackageNames *sorted_set.SortedSet[types.PackageName]) { labels := sorted_set.NewSortedSetFn[label.Label]([]label.Label{}, labelLess) for _, implicitDep := range r.AttrStrings(attrName) { @@ -99,7 +104,7 @@ func (jr Resolver) populateAttr(c *config.Config, r *rule.Rule, attrName string, } for _, imp := range requiredPackageNames.SortedSlice() { - dep, err := jr.resolveSinglePackage(c, imp, ix, from, isTestRule, ownPackageNames) + dep, err := jr.resolveSinglePackage(c, pc, imp, ix, from, isTestRule, ownPackageNames) if err != nil { jr.lang.logger.Error().Str("import", dep.String()).Err(err).Msg("error converting import") panic(fmt.Sprintf("error converting import: %s", err)) @@ -151,7 +156,7 @@ func simplifyLabel(repoName string, l label.Label, from label.Label) label.Label return l } -func (jr *Resolver) resolveSinglePackage(c *config.Config, imp types.PackageName, ix *resolve.RuleIndex, from label.Label, isTestRule bool, ownPackageNames *sorted_set.SortedSet[types.PackageName]) (out label.Label, err error) { +func (jr *Resolver) resolveSinglePackage(c *config.Config, pc *javaconfig.Config, imp types.PackageName, ix *resolve.RuleIndex, from label.Label, isTestRule bool, ownPackageNames *sorted_set.SortedSet[types.PackageName]) (out label.Label, err error) { cacheKey := types.NewResolvableJavaPackage(imp, false, false) importSpec := resolve.ImportSpec{Lang: languageName, Imp: cacheKey.String()} if ol, found := resolve.FindRuleWithOverride(c, importSpec, languageName); found { @@ -192,7 +197,7 @@ func (jr *Resolver) resolveSinglePackage(c *config.Config, imp types.PackageName return label.NoLabel, nil } - if l, err := jr.lang.mavenResolver.Resolve(imp); err == nil { + if l, err := jr.lang.mavenResolver.Resolve(imp, pc.ExcludedArtifacts()); err == nil { return l, nil } diff --git a/java/gazelle/resolve_test.go b/java/gazelle/resolve_test.go index 295f5238..a6ae218f 100644 --- a/java/gazelle/resolve_test.go +++ b/java/gazelle/resolve_test.go @@ -240,7 +240,7 @@ func testConfig(t *testing.T, args ...string) (*config.Config, []language.Langua type testResolver struct{} -func (*testResolver) Resolve(pkg types.PackageName) (label.Label, error) { +func (*testResolver) Resolve(pkg types.PackageName, excludedArtifacts map[string]struct{}) (label.Label, error) { return label.NoLabel, errors.New("not implemented") } @@ -280,7 +280,7 @@ func NewTestMavenResolver() *TestMavenResolver { } } -func (r *TestMavenResolver) Resolve(pkg types.PackageName) (label.Label, error) { +func (r *TestMavenResolver) Resolve(pkg types.PackageName, excludedArtifacts map[string]struct{}) (label.Label, error) { l, found := r.data[pkg] if !found { return label.NoLabel, fmt.Errorf("unexpected import: %s", pkg) diff --git a/java/gazelle/testdata/java_exclude_artifact/BUILD.in b/java/gazelle/testdata/java_exclude_artifact/BUILD.in new file mode 100644 index 00000000..e69de29b diff --git a/java/gazelle/testdata/java_exclude_artifact/BUILD.out b/java/gazelle/testdata/java_exclude_artifact/BUILD.out new file mode 100644 index 00000000..e69de29b diff --git a/java/gazelle/testdata/java_exclude_artifact/WORKSPACE b/java/gazelle/testdata/java_exclude_artifact/WORKSPACE new file mode 100644 index 00000000..e462198f --- /dev/null +++ b/java/gazelle/testdata/java_exclude_artifact/WORKSPACE @@ -0,0 +1,27 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +http_archive( + name = "rules_jvm_external", + sha256 = "23fe83890a77ac1a3ee143e2306ec12da4a845285b14ea13cb0df1b1e23658fe", + strip_prefix = "rules_jvm_external-4.3", + urls = ["https://github.com/bazelbuild/rules_jvm_external/archive/refs/tags/4.3.tar.gz"], +) + +load("@rules_jvm_external//:defs.bzl", "maven_install") + +maven_install( + artifacts = [ + "com.google.guava:guava:30.0-jre", + "junit:junit:4.13.1", + "org.hamcrest:hamcrest-all:1.3", + ], + fetch_sources = True, + maven_install_json = "//:maven_install.json", + repositories = [ + "https://repo1.maven.org/maven2", + ], +) + +load("@maven//:defs.bzl", "pinned_maven_install") + +pinned_maven_install() diff --git a/java/gazelle/testdata/java_exclude_artifact/maven_install.json b/java/gazelle/testdata/java_exclude_artifact/maven_install.json new file mode 100644 index 00000000..c4d43a92 --- /dev/null +++ b/java/gazelle/testdata/java_exclude_artifact/maven_install.json @@ -0,0 +1,406 @@ +{ + "dependency_tree": { + "__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": "THERE_IS_NO_DATA_ONLY_ZUUL", + "__INPUT_ARTIFACTS_HASH": 233644259, + "__RESOLVED_ARTIFACTS_HASH": 463965812, + "conflict_resolution": {}, + "dependencies": [ + { + "coord": "com.google.code.findbugs:jsr305:3.0.2", + "dependencies": [], + "directDependencies": [], + "file": "v1/https/repo1.maven.org/maven2/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar", + "mirror_urls": [ + "https://repo1.maven.org/maven2/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar" + ], + "packages": [ + "javax.annotation", + "javax.annotation.concurrent", + "javax.annotation.meta" + ], + "sha256": "766ad2a0783f2687962c8ad74ceecc38a28b9f72a2d085ee438b7813e928d0c7", + "url": "https://repo1.maven.org/maven2/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar" + }, + { + "coord": "com.google.code.findbugs:jsr305:jar:sources:3.0.2", + "dependencies": [], + "directDependencies": [], + "file": "v1/https/repo1.maven.org/maven2/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2-sources.jar", + "mirror_urls": [ + "https://repo1.maven.org/maven2/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2-sources.jar" + ], + "packages": [], + "sha256": "1c9e85e272d0708c6a591dc74828c71603053b48cc75ae83cce56912a2aa063b", + "url": "https://repo1.maven.org/maven2/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2-sources.jar" + }, + { + "coord": "com.google.errorprone:error_prone_annotations:2.3.4", + "dependencies": [], + "directDependencies": [], + "file": "v1/https/repo1.maven.org/maven2/com/google/errorprone/error_prone_annotations/2.3.4/error_prone_annotations-2.3.4.jar", + "mirror_urls": [ + "https://repo1.maven.org/maven2/com/google/errorprone/error_prone_annotations/2.3.4/error_prone_annotations-2.3.4.jar" + ], + "packages": [ + "com.google.errorprone.annotations", + "com.google.errorprone.annotations.concurrent" + ], + "sha256": "baf7d6ea97ce606c53e11b6854ba5f2ce7ef5c24dddf0afa18d1260bd25b002c", + "url": "https://repo1.maven.org/maven2/com/google/errorprone/error_prone_annotations/2.3.4/error_prone_annotations-2.3.4.jar" + }, + { + "coord": "com.google.errorprone:error_prone_annotations:jar:sources:2.3.4", + "dependencies": [], + "directDependencies": [], + "file": "v1/https/repo1.maven.org/maven2/com/google/errorprone/error_prone_annotations/2.3.4/error_prone_annotations-2.3.4-sources.jar", + "mirror_urls": [ + "https://repo1.maven.org/maven2/com/google/errorprone/error_prone_annotations/2.3.4/error_prone_annotations-2.3.4-sources.jar" + ], + "packages": [], + "sha256": "0b1011d1e2ea2eab35a545cffd1cff3877f131134c8020885e8eaf60a7d72f91", + "url": "https://repo1.maven.org/maven2/com/google/errorprone/error_prone_annotations/2.3.4/error_prone_annotations-2.3.4-sources.jar" + }, + { + "coord": "com.google.guava:failureaccess:1.0.1", + "dependencies": [], + "directDependencies": [], + "file": "v1/https/repo1.maven.org/maven2/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar", + "mirror_urls": [ + "https://repo1.maven.org/maven2/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar" + ], + "packages": [ + "com.google.common.util.concurrent.internal" + ], + "sha256": "a171ee4c734dd2da837e4b16be9df4661afab72a41adaf31eb84dfdaf936ca26", + "url": "https://repo1.maven.org/maven2/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar" + }, + { + "coord": "com.google.guava:failureaccess:jar:sources:1.0.1", + "dependencies": [], + "directDependencies": [], + "file": "v1/https/repo1.maven.org/maven2/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1-sources.jar", + "mirror_urls": [ + "https://repo1.maven.org/maven2/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1-sources.jar" + ], + "packages": [], + "sha256": "092346eebbb1657b51aa7485a246bf602bb464cc0b0e2e1c7e7201fadce1e98f", + "url": "https://repo1.maven.org/maven2/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1-sources.jar" + }, + { + "coord": "com.google.guava:guava:30.0-jre", + "dependencies": [ + "com.google.code.findbugs:jsr305:3.0.2", + "com.google.errorprone:error_prone_annotations:2.3.4", + "com.google.guava:failureaccess:1.0.1", + "com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava", + "com.google.j2objc:j2objc-annotations:1.3", + "org.checkerframework:checker-qual:3.5.0" + ], + "directDependencies": [ + "com.google.code.findbugs:jsr305:3.0.2", + "com.google.errorprone:error_prone_annotations:2.3.4", + "com.google.guava:failureaccess:1.0.1", + "com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava", + "com.google.j2objc:j2objc-annotations:1.3", + "org.checkerframework:checker-qual:3.5.0" + ], + "file": "v1/https/repo1.maven.org/maven2/com/google/guava/guava/30.0-jre/guava-30.0-jre.jar", + "mirror_urls": [ + "https://repo1.maven.org/maven2/com/google/guava/guava/30.0-jre/guava-30.0-jre.jar" + ], + "packages": [ + "com.google.common.annotations", + "com.google.common.base", + "com.google.common.base.internal", + "com.google.common.cache", + "com.google.common.collect", + "com.google.common.escape", + "com.google.common.eventbus", + "com.google.common.graph", + "com.google.common.hash", + "com.google.common.html", + "com.google.common.io", + "com.google.common.math", + "com.google.common.net", + "com.google.common.primitives", + "com.google.common.reflect", + "com.google.common.util.concurrent", + "com.google.common.xml", + "com.google.thirdparty.publicsuffix" + ], + "sha256": "56b292df9ec29d102820c1fd7dd581cd749d5c416c7b3aeac008dbda3b984cc2", + "url": "https://repo1.maven.org/maven2/com/google/guava/guava/30.0-jre/guava-30.0-jre.jar" + }, + { + "coord": "com.google.guava:guava:jar:sources:30.0-jre", + "dependencies": [ + "com.google.code.findbugs:jsr305:jar:sources:3.0.2", + "com.google.errorprone:error_prone_annotations:jar:sources:2.3.4", + "com.google.guava:failureaccess:jar:sources:1.0.1", + "com.google.guava:listenablefuture:jar:sources:9999.0-empty-to-avoid-conflict-with-guava", + "com.google.j2objc:j2objc-annotations:jar:sources:1.3", + "org.checkerframework:checker-qual:jar:sources:3.5.0" + ], + "directDependencies": [ + "com.google.code.findbugs:jsr305:jar:sources:3.0.2", + "com.google.errorprone:error_prone_annotations:jar:sources:2.3.4", + "com.google.guava:failureaccess:jar:sources:1.0.1", + "com.google.guava:listenablefuture:jar:sources:9999.0-empty-to-avoid-conflict-with-guava", + "com.google.j2objc:j2objc-annotations:jar:sources:1.3", + "org.checkerframework:checker-qual:jar:sources:3.5.0" + ], + "file": "v1/https/repo1.maven.org/maven2/com/google/guava/guava/30.0-jre/guava-30.0-jre-sources.jar", + "mirror_urls": [ + "https://repo1.maven.org/maven2/com/google/guava/guava/30.0-jre/guava-30.0-jre-sources.jar" + ], + "packages": [], + "sha256": "daa8a245663f9027ae4b84239147d3439221839155a4d93cbab280c3e657a73d", + "url": "https://repo1.maven.org/maven2/com/google/guava/guava/30.0-jre/guava-30.0-jre-sources.jar" + }, + { + "coord": "com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava", + "dependencies": [], + "directDependencies": [], + "file": "v1/https/repo1.maven.org/maven2/com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar", + "mirror_urls": [ + "https://repo1.maven.org/maven2/com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar" + ], + "packages": [], + "sha256": "b372a037d4230aa57fbeffdef30fd6123f9c0c2db85d0aced00c91b974f33f99", + "url": "https://repo1.maven.org/maven2/com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar" + }, + { + "coord": "com.google.guava:listenablefuture:jar:sources:9999.0-empty-to-avoid-conflict-with-guava", + "dependencies": [], + "directDependencies": [], + "file": null + }, + { + "coord": "com.google.j2objc:j2objc-annotations:1.3", + "dependencies": [], + "directDependencies": [], + "file": "v1/https/repo1.maven.org/maven2/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3.jar", + "mirror_urls": [ + "https://repo1.maven.org/maven2/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3.jar" + ], + "packages": [ + "com.google.j2objc.annotations" + ], + "sha256": "21af30c92267bd6122c0e0b4d20cccb6641a37eaf956c6540ec471d584e64a7b", + "url": "https://repo1.maven.org/maven2/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3.jar" + }, + { + "coord": "com.google.j2objc:j2objc-annotations:jar:sources:1.3", + "dependencies": [], + "directDependencies": [], + "file": "v1/https/repo1.maven.org/maven2/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3-sources.jar", + "mirror_urls": [ + "https://repo1.maven.org/maven2/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3-sources.jar" + ], + "packages": [], + "sha256": "ba4df669fec153fa4cd0ef8d02c6d3ef0702b7ac4cabe080facf3b6e490bb972", + "url": "https://repo1.maven.org/maven2/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3-sources.jar" + }, + { + "coord": "junit:junit:4.13.1", + "dependencies": [ + "org.hamcrest:hamcrest-core:1.3" + ], + "directDependencies": [ + "org.hamcrest:hamcrest-core:1.3" + ], + "file": "v1/https/repo1.maven.org/maven2/junit/junit/4.13.1/junit-4.13.1.jar", + "mirror_urls": [ + "https://repo1.maven.org/maven2/junit/junit/4.13.1/junit-4.13.1.jar" + ], + "packages": [ + "junit.extensions", + "junit.framework", + "junit.runner", + "junit.textui", + "org.junit", + "org.junit.experimental", + "org.junit.experimental.categories", + "org.junit.experimental.max", + "org.junit.experimental.results", + "org.junit.experimental.runners", + "org.junit.experimental.theories", + "org.junit.experimental.theories.internal", + "org.junit.experimental.theories.suppliers", + "org.junit.function", + "org.junit.internal", + "org.junit.internal.builders", + "org.junit.internal.management", + "org.junit.internal.matchers", + "org.junit.internal.requests", + "org.junit.internal.runners", + "org.junit.internal.runners.model", + "org.junit.internal.runners.rules", + "org.junit.internal.runners.statements", + "org.junit.matchers", + "org.junit.rules", + "org.junit.runner", + "org.junit.runner.manipulation", + "org.junit.runner.notification", + "org.junit.runners", + "org.junit.runners.model", + "org.junit.runners.parameterized", + "org.junit.validator" + ], + "sha256": "c30719db974d6452793fe191b3638a5777005485bae145924044530ffa5f6122", + "url": "https://repo1.maven.org/maven2/junit/junit/4.13.1/junit-4.13.1.jar" + }, + { + "coord": "junit:junit:jar:sources:4.13.1", + "dependencies": [ + "org.hamcrest:hamcrest-core:jar:sources:1.3" + ], + "directDependencies": [ + "org.hamcrest:hamcrest-core:jar:sources:1.3" + ], + "file": "v1/https/repo1.maven.org/maven2/junit/junit/4.13.1/junit-4.13.1-sources.jar", + "mirror_urls": [ + "https://repo1.maven.org/maven2/junit/junit/4.13.1/junit-4.13.1-sources.jar" + ], + "packages": [], + "sha256": "624c08005c95c47287c9d921479cff0b71dd50a101b0810cd5e207242eb8fe0e", + "url": "https://repo1.maven.org/maven2/junit/junit/4.13.1/junit-4.13.1-sources.jar" + }, + { + "coord": "org.checkerframework:checker-qual:3.5.0", + "dependencies": [], + "directDependencies": [], + "file": "v1/https/repo1.maven.org/maven2/org/checkerframework/checker-qual/3.5.0/checker-qual-3.5.0.jar", + "mirror_urls": [ + "https://repo1.maven.org/maven2/org/checkerframework/checker-qual/3.5.0/checker-qual-3.5.0.jar" + ], + "packages": [ + "org.checkerframework.checker.compilermsgs.qual", + "org.checkerframework.checker.fenum.qual", + "org.checkerframework.checker.formatter", + "org.checkerframework.checker.formatter.qual", + "org.checkerframework.checker.guieffect.qual", + "org.checkerframework.checker.i18n.qual", + "org.checkerframework.checker.i18nformatter", + "org.checkerframework.checker.i18nformatter.qual", + "org.checkerframework.checker.index.qual", + "org.checkerframework.checker.initialization.qual", + "org.checkerframework.checker.interning.qual", + "org.checkerframework.checker.lock.qual", + "org.checkerframework.checker.nullness", + "org.checkerframework.checker.nullness.qual", + "org.checkerframework.checker.optional.qual", + "org.checkerframework.checker.propkey.qual", + "org.checkerframework.checker.regex", + "org.checkerframework.checker.regex.qual", + "org.checkerframework.checker.signature.qual", + "org.checkerframework.checker.signedness", + "org.checkerframework.checker.signedness.qual", + "org.checkerframework.checker.tainting.qual", + "org.checkerframework.checker.units", + "org.checkerframework.checker.units.qual", + "org.checkerframework.common.aliasing.qual", + "org.checkerframework.common.reflection.qual", + "org.checkerframework.common.returnsreceiver.qual", + "org.checkerframework.common.subtyping.qual", + "org.checkerframework.common.util.report.qual", + "org.checkerframework.common.value.qual", + "org.checkerframework.dataflow.qual", + "org.checkerframework.framework.qual", + "org.checkerframework.framework.util" + ], + "sha256": "729990b3f18a95606fc2573836b6958bcdb44cb52bfbd1b7aa9c339cff35a5a4", + "url": "https://repo1.maven.org/maven2/org/checkerframework/checker-qual/3.5.0/checker-qual-3.5.0.jar" + }, + { + "coord": "org.checkerframework:checker-qual:jar:sources:3.5.0", + "dependencies": [], + "directDependencies": [], + "file": "v1/https/repo1.maven.org/maven2/org/checkerframework/checker-qual/3.5.0/checker-qual-3.5.0-sources.jar", + "mirror_urls": [ + "https://repo1.maven.org/maven2/org/checkerframework/checker-qual/3.5.0/checker-qual-3.5.0-sources.jar" + ], + "packages": [], + "sha256": "0724b40995c1b05516caa2dd9a3b2f5378f948cf20f3404f4db316af25239368", + "url": "https://repo1.maven.org/maven2/org/checkerframework/checker-qual/3.5.0/checker-qual-3.5.0-sources.jar" + }, + { + "coord": "org.hamcrest:hamcrest-all:1.3", + "dependencies": [], + "directDependencies": [], + "file": "v1/https/repo1.maven.org/maven2/org/hamcrest/hamcrest-all/1.3/hamcrest-all-1.3.jar", + "mirror_urls": [ + "https://repo1.maven.org/maven2/org/hamcrest/hamcrest-all/1.3/hamcrest-all-1.3.jar" + ], + "packages": [ + "org.hamcrest", + "org.hamcrest.beans", + "org.hamcrest.collection", + "org.hamcrest.core", + "org.hamcrest.generator", + "org.hamcrest.generator.config", + "org.hamcrest.generator.qdox", + "org.hamcrest.generator.qdox.ant", + "org.hamcrest.generator.qdox.directorywalker", + "org.hamcrest.generator.qdox.junit", + "org.hamcrest.generator.qdox.model", + "org.hamcrest.generator.qdox.model.annotation", + "org.hamcrest.generator.qdox.model.util", + "org.hamcrest.generator.qdox.parser", + "org.hamcrest.generator.qdox.parser.impl", + "org.hamcrest.generator.qdox.parser.structs", + "org.hamcrest.generator.qdox.tools", + "org.hamcrest.integration", + "org.hamcrest.internal", + "org.hamcrest.number", + "org.hamcrest.object", + "org.hamcrest.text", + "org.hamcrest.xml" + ], + "sha256": "4877670629ab96f34f5f90ab283125fcd9acb7e683e66319a68be6eb2cca60de", + "url": "https://repo1.maven.org/maven2/org/hamcrest/hamcrest-all/1.3/hamcrest-all-1.3.jar" + }, + { + "coord": "org.hamcrest:hamcrest-all:jar:sources:1.3", + "dependencies": [], + "directDependencies": [], + "file": "v1/https/repo1.maven.org/maven2/org/hamcrest/hamcrest-all/1.3/hamcrest-all-1.3-sources.jar", + "mirror_urls": [ + "https://repo1.maven.org/maven2/org/hamcrest/hamcrest-all/1.3/hamcrest-all-1.3-sources.jar" + ], + "packages": [], + "sha256": "c53535c3d25b5bf0b00a324a5583c7dd2fed0fa6d1bbc622e2dec460c24faab3", + "url": "https://repo1.maven.org/maven2/org/hamcrest/hamcrest-all/1.3/hamcrest-all-1.3-sources.jar" + }, + { + "coord": "org.hamcrest:hamcrest-core:1.3", + "dependencies": [], + "directDependencies": [], + "file": "v1/https/repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar", + "mirror_urls": [ + "https://repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar" + ], + "packages": [ + "org.hamcrest", + "org.hamcrest.core", + "org.hamcrest.internal" + ], + "sha256": "66fdef91e9739348df7a096aa384a5685f4e875584cce89386a7a47251c4d8e9", + "url": "https://repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar" + }, + { + "coord": "org.hamcrest:hamcrest-core:jar:sources:1.3", + "dependencies": [], + "directDependencies": [], + "file": "v1/https/repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-sources.jar", + "mirror_urls": [ + "https://repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-sources.jar" + ], + "packages": [], + "sha256": "e223d2d8fbafd66057a8848cc94222d63c3cedd652cc48eddc0ab5c39c0f84df", + "url": "https://repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-sources.jar" + } + ], + "version": "0.1.0" + } +} diff --git a/java/gazelle/testdata/java_exclude_artifact/src/java/com/example/hamcrest_all/App.java b/java/gazelle/testdata/java_exclude_artifact/src/java/com/example/hamcrest_all/App.java new file mode 100644 index 00000000..936e9092 --- /dev/null +++ b/java/gazelle/testdata/java_exclude_artifact/src/java/com/example/hamcrest_all/App.java @@ -0,0 +1,19 @@ +package com.example.hamcrest_all; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; + +import com.google.common.primitives.Ints; + +/** This application compares two numbers, using the Ints.compare method from Guava. */ +public class App { + + public static int compare(int a, int b) { + return Ints.compare(a, b); + } + + public static void main(String... args) throws Exception { + App app = new App(); + System.out.println("Success: " + app.compare(2, 1)); + } +} diff --git a/java/gazelle/testdata/java_exclude_artifact/src/java/com/example/hamcrest_all/BUILD.in b/java/gazelle/testdata/java_exclude_artifact/src/java/com/example/hamcrest_all/BUILD.in new file mode 100644 index 00000000..1d14b70c --- /dev/null +++ b/java/gazelle/testdata/java_exclude_artifact/src/java/com/example/hamcrest_all/BUILD.in @@ -0,0 +1 @@ +# gazelle:java_exclude_artifact @maven//:org_hamcrest_hamcrest_core diff --git a/java/gazelle/testdata/java_exclude_artifact/src/java/com/example/hamcrest_all/BUILD.out b/java/gazelle/testdata/java_exclude_artifact/src/java/com/example/hamcrest_all/BUILD.out new file mode 100644 index 00000000..855ccdef --- /dev/null +++ b/java/gazelle/testdata/java_exclude_artifact/src/java/com/example/hamcrest_all/BUILD.out @@ -0,0 +1,20 @@ +load("@rules_java//java:defs.bzl", "java_binary", "java_library") + +# gazelle:java_exclude_artifact @maven//:org_hamcrest_hamcrest_core + +java_library( + name = "hamcrest_all", + srcs = ["App.java"], + visibility = ["//:__subpackages__"], + deps = [ + "@maven//:com_google_guava_guava", + "@maven//:org_hamcrest_hamcrest_all", + ], +) + +java_binary( + name = "App", + main_class = "com.example.hamcrest_all.App", + visibility = ["//visibility:public"], + runtime_deps = [":hamcrest_all"], +) diff --git a/java/gazelle/testdata/java_exclude_artifact/src/java/com/example/hamcrest_core/App.java b/java/gazelle/testdata/java_exclude_artifact/src/java/com/example/hamcrest_core/App.java new file mode 100644 index 00000000..eca70ac8 --- /dev/null +++ b/java/gazelle/testdata/java_exclude_artifact/src/java/com/example/hamcrest_core/App.java @@ -0,0 +1,19 @@ +package com.example.hamcrest_core; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; + +import com.google.common.primitives.Ints; + +/** This application compares two numbers, using the Ints.compare method from Guava. */ +public class App { + + public static int compare(int a, int b) { + return Ints.compare(a, b); + } + + public static void main(String... args) throws Exception { + App app = new App(); + System.out.println("Success: " + app.compare(2, 1)); + } +} diff --git a/java/gazelle/testdata/java_exclude_artifact/src/java/com/example/hamcrest_core/BUILD.in b/java/gazelle/testdata/java_exclude_artifact/src/java/com/example/hamcrest_core/BUILD.in new file mode 100644 index 00000000..ecff609b --- /dev/null +++ b/java/gazelle/testdata/java_exclude_artifact/src/java/com/example/hamcrest_core/BUILD.in @@ -0,0 +1 @@ +# gazelle:java_exclude_artifact @maven//:org_hamcrest_hamcrest_all diff --git a/java/gazelle/testdata/java_exclude_artifact/src/java/com/example/hamcrest_core/BUILD.out b/java/gazelle/testdata/java_exclude_artifact/src/java/com/example/hamcrest_core/BUILD.out new file mode 100644 index 00000000..2e4d65e6 --- /dev/null +++ b/java/gazelle/testdata/java_exclude_artifact/src/java/com/example/hamcrest_core/BUILD.out @@ -0,0 +1,20 @@ +load("@rules_java//java:defs.bzl", "java_binary", "java_library") + +# gazelle:java_exclude_artifact @maven//:org_hamcrest_hamcrest_all + +java_library( + name = "hamcrest_core", + srcs = ["App.java"], + visibility = ["//:__subpackages__"], + deps = [ + "@maven//:com_google_guava_guava", + "@maven//:org_hamcrest_hamcrest_core", + ], +) + +java_binary( + name = "App", + main_class = "com.example.hamcrest_core.App", + visibility = ["//visibility:public"], + runtime_deps = [":hamcrest_core"], +)