• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
15package java
16
17import (
18	"android/soong/android"
19	"github.com/google/blueprint"
20)
21
22type JavaPluginInfo struct {
23	ProcessorClass *string
24	GeneratesApi   bool
25}
26
27var JavaPluginInfoProvider = blueprint.NewProvider[JavaPluginInfo]()
28
29type KotlinPluginInfo struct {
30}
31
32var KotlinPluginInfoProvider = blueprint.NewProvider[KotlinPluginInfo]()
33
34func init() {
35	registerJavaPluginBuildComponents(android.InitRegistrationContext)
36}
37
38func registerJavaPluginBuildComponents(ctx android.RegistrationContext) {
39	ctx.RegisterModuleType("java_plugin", PluginFactory)
40	ctx.RegisterModuleType("kotlin_plugin", KotlinPluginFactory)
41}
42
43func PluginFactory() android.Module {
44	module := &Plugin{}
45
46	module.addHostProperties()
47	module.AddProperties(&module.pluginProperties)
48
49	InitJavaModule(module, android.HostSupported)
50
51	return module
52}
53
54func KotlinPluginFactory() android.Module {
55	module := &KotlinPlugin{}
56
57	module.addHostProperties()
58
59	InitJavaModule(module, android.HostSupported)
60
61	return module
62}
63
64// Plugin describes a java_plugin module, a host java library that will be used by javac as an annotation processor.
65type Plugin struct {
66	Library
67
68	pluginProperties PluginProperties
69}
70
71type PluginProperties struct {
72	// The optional name of the class that javac will use to run the annotation processor.
73	Processor_class *string
74
75	// If true, assume the annotation processor will generate classes that are referenced from outside the module.
76	// This necessitates disabling the turbine optimization on modules that use this plugin, which will reduce
77	// parallelism and cause more recompilation for modules that depend on modules that use this plugin.
78	Generates_api *bool
79}
80
81func (p *Plugin) GenerateAndroidBuildActions(ctx android.ModuleContext) {
82	p.Library.GenerateAndroidBuildActions(ctx)
83
84	android.SetProvider(ctx, JavaPluginInfoProvider, JavaPluginInfo{
85		ProcessorClass: p.pluginProperties.Processor_class,
86		GeneratesApi:   Bool(p.pluginProperties.Generates_api),
87	})
88}
89
90// Plugin describes a kotlin_plugin module, a host java/kotlin library that will be used by kotlinc as a compiler plugin.
91type KotlinPlugin struct {
92	Library
93}
94
95func (p *KotlinPlugin) GenerateAndroidBuildActions(ctx android.ModuleContext) {
96	p.Library.GenerateAndroidBuildActions(ctx)
97
98	android.SetProvider(ctx, KotlinPluginInfoProvider, KotlinPluginInfo{})
99}
100