Skip to content
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

Handle java_library being remapped with map_kind #199

Merged
merged 2 commits into from
Aug 31, 2023
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
14 changes: 10 additions & 4 deletions java/gazelle/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,13 @@ func (l javaLang) GenerateRules(args language.GenerateArgs) language.GenerateRes
return true
})

javaLibraryKind := "java_library"
if kindMap, ok := args.Config.KindMap["java_library"]; ok {
javaLibraryKind = kindMap.KindName
}

if productionJavaFiles.Len() > 0 {
l.generateJavaLibrary(args.File, args.Rel, filepath.Base(args.Rel), productionJavaFiles.SortedSlice(), allPackageNames, nonLocalProductionJavaImports, nonLocalJavaExports, false, &res)
l.generateJavaLibrary(args.File, args.Rel, filepath.Base(args.Rel), productionJavaFiles.SortedSlice(), allPackageNames, nonLocalProductionJavaImports, nonLocalJavaExports, false, javaLibraryKind, &res)
}

for _, m := range allMains.SortedSlice() {
Expand All @@ -204,7 +209,7 @@ func (l javaLang) GenerateRules(args language.GenerateArgs) language.GenerateRes
testJavaImportsWithHelpers.Add(tf.pkg)
srcs = append(srcs, tf.pathRelativeToBazelWorkspaceRoot)
}
l.generateJavaLibrary(args.File, args.Rel, filepath.Base(args.Rel), srcs, packages, testJavaImports, nonLocalJavaExports, true, &res)
l.generateJavaLibrary(args.File, args.Rel, filepath.Base(args.Rel), srcs, packages, testJavaImports, nonLocalJavaExports, true, javaLibraryKind, &res)
}
}

Expand Down Expand Up @@ -406,7 +411,7 @@ func accumulateJavaFile(cfg *javaconfig.Config, testJavaFiles, testHelperJavaFil
}
}

func (l javaLang) generateJavaLibrary(file *rule.File, pathToPackageRelativeToBazelWorkspace string, name string, srcsRelativeToBazelWorkspace []string, packages, imports *sorted_set.SortedSet[types.PackageName], exports *sorted_set.SortedSet[types.PackageName], testonly bool, res *language.GenerateResult) {
func (l javaLang) generateJavaLibrary(file *rule.File, pathToPackageRelativeToBazelWorkspace string, name string, srcsRelativeToBazelWorkspace []string, packages, imports *sorted_set.SortedSet[types.PackageName], exports *sorted_set.SortedSet[types.PackageName], testonly bool, javaLibraryRuleKind string, res *language.GenerateResult) {
const ruleKind = "java_library"
r := rule.NewRule(ruleKind, name)

Expand All @@ -416,7 +421,8 @@ func (l javaLang) generateJavaLibrary(file *rule.File, pathToPackageRelativeToBa
}
sort.Strings(srcs)

runtimeDeps := l.collectRuntimeDeps(ruleKind, name, file)
// This is so we would default ALL runtime_deps to "keep" mode
runtimeDeps := l.collectRuntimeDeps(javaLibraryRuleKind, name, file)
if runtimeDeps.Len() > 0 {
r.SetAttr("runtime_deps", labelsToStrings(runtimeDeps.SortedSlice()))
}
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12:00AM WRN java/gazelle/private/maven/resolver.go:XXX > not loading maven dependencies error="open %WORKSPACEPATH%/maven_install.json: no such file or directory" _c=maven-resolver
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
load("//libs/bazel/java:rules_java.bzl", "generic_java_library")

# gazelle:map_kind java_library generic_java_library //libs/bazel/java:rules_java.bzl

generic_java_library(
name = "hello",
srcs = ["Hello.java"],
visibility = ["//:__subpackages__"],
runtime_deps = ["//foo/bar"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
load("//libs/bazel/java:rules_java.bzl", "generic_java_library")

# gazelle:map_kind java_library generic_java_library //libs/bazel/java:rules_java.bzl

generic_java_library(
name = "hello",
srcs = ["Hello.java"],
visibility = ["//:__subpackages__"],
runtime_deps = ["//foo/bar"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.hello;

public class Hello {
public static void sayHi() {
System.out.println("Hi!");
}
}
Loading