From 64ac489eaae93b887dfe39570c8d60b5c872b6ac Mon Sep 17 00:00:00 2001 From: jyuhengwei <70684719+jyuhengwei@users.noreply.github.com> Date: Wed, 2 Sep 2020 23:36:11 -0700 Subject: [PATCH 1/3] Add 0 to allowed package name characters (#1) For some unknown reason, `0` is the only alphanumeric character that wasn't recognized as in a package name. This led to odd scenarios that when you tried to compile code that had a `0` in the package name, the kotlin builder would package the code as the string before the `0` which led to some problems in auto-generated code. --- .../io/bazel/kotlin/builder/utils/jars/SourceJarCreator.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/io/bazel/kotlin/builder/utils/jars/SourceJarCreator.kt b/src/main/kotlin/io/bazel/kotlin/builder/utils/jars/SourceJarCreator.kt index 9419a79be..7ac7e5692 100644 --- a/src/main/kotlin/io/bazel/kotlin/builder/utils/jars/SourceJarCreator.kt +++ b/src/main/kotlin/io/bazel/kotlin/builder/utils/jars/SourceJarCreator.kt @@ -35,7 +35,7 @@ class SourceJarCreator( private const val BL = """\p{Blank}*""" private const val COM_BL = """$BL(?:/\*[^\n]*\*/$BL)*""" private val PKG_PATTERN: Pattern = - Pattern.compile("""^${COM_BL}package$COM_BL([a-zA-Z1-9._]+)$COM_BL(?:;?.*)$""") + Pattern.compile("""^${COM_BL}package$COM_BL([a-zA-Z0-9._]+)$COM_BL(?:;?.*)$""") @JvmStatic fun extractPackage(line: String): String? = From 9804a36767cf68321483fc668d624fceacc00b3c Mon Sep 17 00:00:00 2001 From: justhecuke Date: Thu, 3 Sep 2020 12:06:25 -0700 Subject: [PATCH 2/3] Add Test --- .../builder/utils/jars/SourceJarCreatorTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/kotlin/io/bazel/kotlin/builder/utils/jars/SourceJarCreatorTest.java b/src/test/kotlin/io/bazel/kotlin/builder/utils/jars/SourceJarCreatorTest.java index 8e5b39191..2cd7d1cf5 100644 --- a/src/test/kotlin/io/bazel/kotlin/builder/utils/jars/SourceJarCreatorTest.java +++ b/src/test/kotlin/io/bazel/kotlin/builder/utils/jars/SourceJarCreatorTest.java @@ -49,4 +49,16 @@ public void testPackageNameRegex() { subj.that(pkg).isEqualTo(expectedPackage); }); } + + @Test + public void testPackageNameRegexWithZero() { + cases.forEach( + (testCase) -> { + testCase = testCase.replace("some1", "some0") + String pkg = SourceJarCreator.Companion.extractPackage(testCase); + StandardSubjectBuilder subj = assertWithMessage("positive test case: " + testCase); + subj.that(pkg).isNotNull(); + subj.that(pkg).isEqualTo("iO.some0.package"); + }); + } } From 49537c95157c84cf78f7bc5c72ff0a8dbb410813 Mon Sep 17 00:00:00 2001 From: justhecuke Date: Thu, 3 Sep 2020 12:27:32 -0700 Subject: [PATCH 3/3] Fix missing colon --- .../bazel/kotlin/builder/utils/jars/SourceJarCreatorTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/kotlin/io/bazel/kotlin/builder/utils/jars/SourceJarCreatorTest.java b/src/test/kotlin/io/bazel/kotlin/builder/utils/jars/SourceJarCreatorTest.java index 2cd7d1cf5..fbaa6c5f7 100644 --- a/src/test/kotlin/io/bazel/kotlin/builder/utils/jars/SourceJarCreatorTest.java +++ b/src/test/kotlin/io/bazel/kotlin/builder/utils/jars/SourceJarCreatorTest.java @@ -54,7 +54,7 @@ public void testPackageNameRegex() { public void testPackageNameRegexWithZero() { cases.forEach( (testCase) -> { - testCase = testCase.replace("some1", "some0") + testCase = testCase.replace("some1", "some0"); String pkg = SourceJarCreator.Companion.extractPackage(testCase); StandardSubjectBuilder subj = assertWithMessage("positive test case: " + testCase); subj.that(pkg).isNotNull();