blob: dc29b1c3e5d69906d21f187c003dda01ab45d217 [file] [log] [blame]
Colin Crossbe9cdb82019-01-21 21:37:16 -08001// 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
15package java
16
17import (
Colin Crossbe9cdb82019-01-21 21:37:16 -080018 "testing"
19)
20
21func TestNoPlugin(t *testing.T) {
Jaewoong Jungf9a04432019-07-17 11:15:09 -070022 ctx, _ := testJava(t, `
Colin Crossbe9cdb82019-01-21 21:37:16 -080023 java_library {
24 name: "foo",
25 srcs: ["a.java"],
26 }
27 `)
28
29 javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
30 turbine := ctx.ModuleForTests("foo", "android_common").MaybeRule("turbine")
31
32 if turbine.Rule == nil {
33 t.Errorf("expected turbine to be enabled")
34 }
35
36 if javac.Args["processsorpath"] != "" {
37 t.Errorf("want empty processorpath, got %q", javac.Args["processorpath"])
38 }
39
Colin Cross7788c122019-01-23 16:14:02 -080040 if javac.Args["processor"] != "-proc:none" {
41 t.Errorf("want '-proc:none' argument, got %q", javac.Args["processor"])
Colin Crossbe9cdb82019-01-21 21:37:16 -080042 }
43}
44
45func TestPlugin(t *testing.T) {
Jaewoong Jungf9a04432019-07-17 11:15:09 -070046 ctx, _ := testJava(t, `
Colin Crossbe9cdb82019-01-21 21:37:16 -080047 java_library {
48 name: "foo",
49 srcs: ["a.java"],
50 plugins: ["bar"],
51 }
52
53 java_plugin {
54 name: "bar",
55 processor_class: "com.bar",
56 srcs: ["b.java"],
57 }
58 `)
59
Colin Cross0c66bc62021-07-20 09:47:41 -070060 buildOS := ctx.Config().BuildOS.String()
Colin Crossbe9cdb82019-01-21 21:37:16 -080061
62 javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
63 turbine := ctx.ModuleForTests("foo", "android_common").MaybeRule("turbine")
64
65 if turbine.Rule == nil {
66 t.Errorf("expected turbine to be enabled")
67 }
68
69 bar := ctx.ModuleForTests("bar", buildOS+"_common").Rule("javac").Output.String()
70
71 if !inList(bar, javac.Implicits.Strings()) {
72 t.Errorf("foo implicits %v does not contain %q", javac.Implicits.Strings(), bar)
73 }
74
75 if javac.Args["processorpath"] != "-processorpath "+bar {
76 t.Errorf("foo processorpath %q != '-processorpath %s'", javac.Args["processorpath"], bar)
77 }
78
79 if javac.Args["processor"] != "-processor com.bar" {
80 t.Errorf("foo processor %q != '-processor com.bar'", javac.Args["processor"])
81 }
82}
83
84func TestPluginGeneratesApi(t *testing.T) {
Jaewoong Jungf9a04432019-07-17 11:15:09 -070085 ctx, _ := testJava(t, `
Colin Crossbe9cdb82019-01-21 21:37:16 -080086 java_library {
87 name: "foo",
88 srcs: ["a.java"],
89 plugins: ["bar"],
90 }
91
92 java_plugin {
93 name: "bar",
94 processor_class: "com.bar",
95 generates_api: true,
96 srcs: ["b.java"],
97 }
98 `)
99
Colin Cross0c66bc62021-07-20 09:47:41 -0700100 buildOS := ctx.Config().BuildOS.String()
Colin Crossbe9cdb82019-01-21 21:37:16 -0800101
102 javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
103 turbine := ctx.ModuleForTests("foo", "android_common").MaybeRule("turbine")
104
105 if turbine.Rule != nil {
106 t.Errorf("expected turbine to be disabled")
107 }
108
109 bar := ctx.ModuleForTests("bar", buildOS+"_common").Rule("javac").Output.String()
110
111 if !inList(bar, javac.Implicits.Strings()) {
112 t.Errorf("foo implicits %v does not contain %q", javac.Implicits.Strings(), bar)
113 }
114
115 if javac.Args["processorpath"] != "-processorpath "+bar {
116 t.Errorf("foo processorpath %q != '-processorpath %s'", javac.Args["processorpath"], bar)
117 }
118
119 if javac.Args["processor"] != "-processor com.bar" {
120 t.Errorf("foo processor %q != '-processor com.bar'", javac.Args["processor"])
121 }
122}