plugin_test.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // Copyright 2019 Google Inc. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package java
  15. import (
  16. "testing"
  17. )
  18. func TestNoPlugin(t *testing.T) {
  19. ctx, _ := testJava(t, `
  20. java_library {
  21. name: "foo",
  22. srcs: ["a.java"],
  23. }
  24. `)
  25. javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
  26. turbine := ctx.ModuleForTests("foo", "android_common").MaybeRule("turbine")
  27. if turbine.Rule == nil {
  28. t.Errorf("expected turbine to be enabled")
  29. }
  30. if javac.Args["processsorpath"] != "" {
  31. t.Errorf("want empty processorpath, got %q", javac.Args["processorpath"])
  32. }
  33. if javac.Args["processor"] != "-proc:none" {
  34. t.Errorf("want '-proc:none' argument, got %q", javac.Args["processor"])
  35. }
  36. }
  37. func TestPlugin(t *testing.T) {
  38. ctx, _ := testJava(t, `
  39. java_library {
  40. name: "foo",
  41. srcs: ["a.java"],
  42. plugins: ["bar"],
  43. }
  44. java_plugin {
  45. name: "bar",
  46. processor_class: "com.bar",
  47. srcs: ["b.java"],
  48. }
  49. `)
  50. buildOS := ctx.Config().BuildOS.String()
  51. javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
  52. turbine := ctx.ModuleForTests("foo", "android_common").MaybeRule("turbine")
  53. if turbine.Rule == nil {
  54. t.Errorf("expected turbine to be enabled")
  55. }
  56. bar := ctx.ModuleForTests("bar", buildOS+"_common").Rule("javac").Output.String()
  57. if !inList(bar, javac.Implicits.Strings()) {
  58. t.Errorf("foo implicits %v does not contain %q", javac.Implicits.Strings(), bar)
  59. }
  60. if javac.Args["processorpath"] != "-processorpath "+bar {
  61. t.Errorf("foo processorpath %q != '-processorpath %s'", javac.Args["processorpath"], bar)
  62. }
  63. if javac.Args["processor"] != "-processor com.bar" {
  64. t.Errorf("foo processor %q != '-processor com.bar'", javac.Args["processor"])
  65. }
  66. }
  67. func TestPluginGeneratesApi(t *testing.T) {
  68. ctx, _ := testJava(t, `
  69. java_library {
  70. name: "foo",
  71. srcs: ["a.java"],
  72. plugins: ["bar"],
  73. }
  74. java_plugin {
  75. name: "bar",
  76. processor_class: "com.bar",
  77. generates_api: true,
  78. srcs: ["b.java"],
  79. }
  80. `)
  81. buildOS := ctx.Config().BuildOS.String()
  82. javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
  83. turbine := ctx.ModuleForTests("foo", "android_common").MaybeRule("turbine")
  84. if turbine.Rule != nil {
  85. t.Errorf("expected turbine to be disabled")
  86. }
  87. bar := ctx.ModuleForTests("bar", buildOS+"_common").Rule("javac").Output.String()
  88. if !inList(bar, javac.Implicits.Strings()) {
  89. t.Errorf("foo implicits %v does not contain %q", javac.Implicits.Strings(), bar)
  90. }
  91. if javac.Args["processorpath"] != "-processorpath "+bar {
  92. t.Errorf("foo processorpath %q != '-processorpath %s'", javac.Args["processorpath"], bar)
  93. }
  94. if javac.Args["processor"] != "-processor com.bar" {
  95. t.Errorf("foo processor %q != '-processor com.bar'", javac.Args["processor"])
  96. }
  97. }