blob: 007b74a9e76e1743cb8fa00dd08914446c98e42b [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) {
Colin Cross844cb6a2025-01-29 15:53:21 -080022 t.Parallel()
Jaewoong Jungf9a04432019-07-17 11:15:09 -070023 ctx, _ := testJava(t, `
Colin Crossbe9cdb82019-01-21 21:37:16 -080024 java_library {
25 name: "foo",
26 srcs: ["a.java"],
27 }
28 `)
29
Colin Cross90607e92025-02-11 14:58:07 -080030 javac := ctx.ModuleForTests(t, "foo", "android_common").Rule("javac")
31 turbine := ctx.ModuleForTests(t, "foo", "android_common").MaybeRule("turbine")
Colin Crossbe9cdb82019-01-21 21:37:16 -080032
33 if turbine.Rule == nil {
34 t.Errorf("expected turbine to be enabled")
35 }
36
37 if javac.Args["processsorpath"] != "" {
38 t.Errorf("want empty processorpath, got %q", javac.Args["processorpath"])
39 }
40
Colin Cross7788c122019-01-23 16:14:02 -080041 if javac.Args["processor"] != "-proc:none" {
42 t.Errorf("want '-proc:none' argument, got %q", javac.Args["processor"])
Colin Crossbe9cdb82019-01-21 21:37:16 -080043 }
44}
45
46func TestPlugin(t *testing.T) {
Colin Cross844cb6a2025-01-29 15:53:21 -080047 t.Parallel()
Jaewoong Jungf9a04432019-07-17 11:15:09 -070048 ctx, _ := testJava(t, `
Colin Crossbe9cdb82019-01-21 21:37:16 -080049 java_library {
50 name: "foo",
51 srcs: ["a.java"],
52 plugins: ["bar"],
53 }
54
55 java_plugin {
56 name: "bar",
57 processor_class: "com.bar",
58 srcs: ["b.java"],
59 }
60 `)
61
Colin Cross0c66bc62021-07-20 09:47:41 -070062 buildOS := ctx.Config().BuildOS.String()
Colin Crossbe9cdb82019-01-21 21:37:16 -080063
Colin Cross90607e92025-02-11 14:58:07 -080064 javac := ctx.ModuleForTests(t, "foo", "android_common").Rule("javac")
65 turbine := ctx.ModuleForTests(t, "foo", "android_common").MaybeRule("turbine")
Colin Crossbe9cdb82019-01-21 21:37:16 -080066
67 if turbine.Rule == nil {
68 t.Errorf("expected turbine to be enabled")
69 }
70
Colin Cross90607e92025-02-11 14:58:07 -080071 bar := ctx.ModuleForTests(t, "bar", buildOS+"_common").Rule("javac").Output.String()
Colin Crossbe9cdb82019-01-21 21:37:16 -080072
73 if !inList(bar, javac.Implicits.Strings()) {
74 t.Errorf("foo implicits %v does not contain %q", javac.Implicits.Strings(), bar)
75 }
76
77 if javac.Args["processorpath"] != "-processorpath "+bar {
78 t.Errorf("foo processorpath %q != '-processorpath %s'", javac.Args["processorpath"], bar)
79 }
80
81 if javac.Args["processor"] != "-processor com.bar" {
82 t.Errorf("foo processor %q != '-processor com.bar'", javac.Args["processor"])
83 }
84}
85
86func TestPluginGeneratesApi(t *testing.T) {
Colin Cross844cb6a2025-01-29 15:53:21 -080087 t.Parallel()
Jaewoong Jungf9a04432019-07-17 11:15:09 -070088 ctx, _ := testJava(t, `
Colin Crossbe9cdb82019-01-21 21:37:16 -080089 java_library {
90 name: "foo",
91 srcs: ["a.java"],
92 plugins: ["bar"],
93 }
94
95 java_plugin {
96 name: "bar",
97 processor_class: "com.bar",
98 generates_api: true,
99 srcs: ["b.java"],
100 }
101 `)
102
Colin Cross0c66bc62021-07-20 09:47:41 -0700103 buildOS := ctx.Config().BuildOS.String()
Colin Crossbe9cdb82019-01-21 21:37:16 -0800104
Colin Cross90607e92025-02-11 14:58:07 -0800105 javac := ctx.ModuleForTests(t, "foo", "android_common").Rule("javac")
106 turbine := ctx.ModuleForTests(t, "foo", "android_common").MaybeRule("turbine")
Colin Crossbe9cdb82019-01-21 21:37:16 -0800107
108 if turbine.Rule != nil {
109 t.Errorf("expected turbine to be disabled")
110 }
111
Colin Cross90607e92025-02-11 14:58:07 -0800112 bar := ctx.ModuleForTests(t, "bar", buildOS+"_common").Rule("javac").Output.String()
Colin Crossbe9cdb82019-01-21 21:37:16 -0800113
114 if !inList(bar, javac.Implicits.Strings()) {
115 t.Errorf("foo implicits %v does not contain %q", javac.Implicits.Strings(), bar)
116 }
117
118 if javac.Args["processorpath"] != "-processorpath "+bar {
119 t.Errorf("foo processorpath %q != '-processorpath %s'", javac.Args["processorpath"], bar)
120 }
121
122 if javac.Args["processor"] != "-processor com.bar" {
123 t.Errorf("foo processor %q != '-processor com.bar'", javac.Args["processor"])
124 }
125}