load("@rules_go//go:def.bzl", "go_library", "go_test")
load("@rules_java//java:defs.bzl", "java_library")
load("@rules_pkg//pkg:mappings.bzl", "pkg_files")

# gazelle:prefix github.com/github/codeql-go/extractor
# gazelle:map_kind go_binary codeql_go_binary //go:rules.bzl

# the immediately following `extractor` target is kept up to date by `bazel run //go:gen`, do not edit directly
go_library(
    name = "extractor",
    srcs = [
        "extractor.go",
        "gomodextractor.go",
        "semaphore.go",
    ],
    importpath = "github.com/github/codeql-go/extractor",
    visibility = ["//visibility:public"],
    deps = [
        "//go/extractor/dbscheme",
        "//go/extractor/diagnostics",
        "//go/extractor/srcarchive",
        "//go/extractor/toolchain",
        "//go/extractor/trap",
        "//go/extractor/util",
        "@org_golang_x_mod//modfile",
        "@org_golang_x_tools//go/packages",
    ],
)

# the other targets are not generated by gazelle

# this is separate from `tokenizer-jar` below because we don't want these compiled class files in the pack
java_library(
    name = "tokenizer-deps",
    srcs = [
        "net/sourceforge/pmd/cpd/AbstractLanguage.java",
        "net/sourceforge/pmd/cpd/SourceCode.java",
        "net/sourceforge/pmd/cpd/TokenEntry.java",
        "net/sourceforge/pmd/cpd/Tokenizer.java",
    ],
)

# we only need these compiled class files in the pack
java_library(
    name = "tokenizer-jar",
    srcs = [
        "net/sourceforge/pmd/cpd/GoLanguage.java",
        "opencsv/CSVParser.java",
        "opencsv/CSVReader.java",
    ],
    deps = [":tokenizer-deps"],
)

pkg_files(
    name = "tokenizer",
    srcs = [":tokenizer-jar"],
    prefix = "tools",
    renames = {
        ":tokenizer-jar": "tokenizer.jar",  # name is `libtokenizer.jar` by default
    },
    visibility = ["//go:__pkg__"],
)

go_test(
    name = "extractor_test",
    srcs = ["extractor_test.go"],
    embed = [":extractor"],
    deps = ["@org_golang_x_tools//go/packages"],
)
