Remove non-idiomatic inheritance
Remove inheritance implemented with the bad "superclass calls subclass through interface" pattern, and replace it with composition. Test: builds Change-Id: If323f89360455b3f98b40777edaaaa265bb3b5fc
This commit is contained in:
20
java/app.go
20
java/app.go
@@ -57,7 +57,7 @@ type androidAppProperties struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AndroidApp struct {
|
type AndroidApp struct {
|
||||||
javaBase
|
Module
|
||||||
|
|
||||||
appProperties androidAppProperties
|
appProperties androidAppProperties
|
||||||
|
|
||||||
@@ -65,9 +65,10 @@ type AndroidApp struct {
|
|||||||
exportPackage android.Path
|
exportPackage android.Path
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AndroidApp) JavaDependencies(ctx AndroidJavaModuleContext) []string {
|
func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) {
|
||||||
deps := a.javaBase.JavaDependencies(ctx)
|
a.Module.deps(ctx)
|
||||||
|
|
||||||
|
var deps []string
|
||||||
if !a.properties.No_standard_libraries {
|
if !a.properties.No_standard_libraries {
|
||||||
switch a.properties.Sdk_version { // TODO: Res_sdk_version?
|
switch a.properties.Sdk_version { // TODO: Res_sdk_version?
|
||||||
case "current", "system_current", "":
|
case "current", "system_current", "":
|
||||||
@@ -77,10 +78,10 @@ func (a *AndroidApp) JavaDependencies(ctx AndroidJavaModuleContext) []string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return deps
|
ctx.AddDependency(ctx.Module(), nil, deps...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AndroidApp) GenerateJavaBuildActions(ctx android.ModuleContext) {
|
func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||||
aaptFlags, aaptDeps, hasResources := a.aaptFlags(ctx)
|
aaptFlags, aaptDeps, hasResources := a.aaptFlags(ctx)
|
||||||
|
|
||||||
if hasResources {
|
if hasResources {
|
||||||
@@ -114,14 +115,14 @@ func (a *AndroidApp) GenerateJavaBuildActions(ctx android.ModuleContext) {
|
|||||||
ctx.CheckbuildFile(aaptJavaFileList)
|
ctx.CheckbuildFile(aaptJavaFileList)
|
||||||
}
|
}
|
||||||
|
|
||||||
// apps manifests are handled by aapt, don't let javaBase see them
|
// apps manifests are handled by aapt, don't let Module see them
|
||||||
a.properties.Manifest = nil
|
a.properties.Manifest = nil
|
||||||
|
|
||||||
//if !ctx.ContainsProperty("proguard.enabled") {
|
//if !ctx.ContainsProperty("proguard.enabled") {
|
||||||
// a.properties.Proguard.Enabled = true
|
// a.properties.Proguard.Enabled = true
|
||||||
//}
|
//}
|
||||||
|
|
||||||
a.javaBase.GenerateJavaBuildActions(ctx)
|
a.Module.compile(ctx)
|
||||||
|
|
||||||
aaptPackageFlags := append([]string(nil), aaptFlags...)
|
aaptPackageFlags := append([]string(nil), aaptFlags...)
|
||||||
var hasProduct bool
|
var hasProduct bool
|
||||||
@@ -238,7 +239,7 @@ func (a *AndroidApp) aaptFlags(ctx android.ModuleContext) ([]string, android.Pat
|
|||||||
depFile = android.OptionalPathForPath(sdkDep.ClasspathFile())
|
depFile = android.OptionalPathForPath(sdkDep.ClasspathFile())
|
||||||
} else if javaDep, ok := module.(JavaDependency); ok {
|
} else if javaDep, ok := module.(JavaDependency); ok {
|
||||||
if ctx.OtherModuleName(module) == "framework-res" {
|
if ctx.OtherModuleName(module) == "framework-res" {
|
||||||
depFile = android.OptionalPathForPath(javaDep.(*javaBase).module.(*AndroidApp).exportPackage)
|
depFile = android.OptionalPathForPath(javaDep.(*AndroidApp).exportPackage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if depFile.Valid() {
|
if depFile.Valid() {
|
||||||
@@ -278,5 +279,6 @@ func AndroidAppFactory() (blueprint.Module, []interface{}) {
|
|||||||
|
|
||||||
module.properties.Dex = true
|
module.properties.Dex = true
|
||||||
|
|
||||||
return NewJavaBase(&module.javaBase, module, android.DeviceSupported, &module.appProperties)
|
return android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon,
|
||||||
|
&module.Module.properties, &module.appProperties)
|
||||||
}
|
}
|
||||||
|
@@ -84,7 +84,7 @@ func genLogtags(ctx android.ModuleContext, logtagsFile android.Path) android.Pat
|
|||||||
return javaFile
|
return javaFile
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *javaBase) genSources(ctx android.ModuleContext, srcFiles android.Paths,
|
func (j *Module) genSources(ctx android.ModuleContext, srcFiles android.Paths,
|
||||||
flags javaBuilderFlags) android.Paths {
|
flags javaBuilderFlags) android.Paths {
|
||||||
|
|
||||||
for i, srcFile := range srcFiles {
|
for i, srcFile := range srcFiles {
|
||||||
|
95
java/java.go
95
java/java.go
@@ -15,7 +15,7 @@
|
|||||||
package java
|
package java
|
||||||
|
|
||||||
// This file contains the module types for compiling Java for Android, and converts the properties
|
// This file contains the module types for compiling Java for Android, and converts the properties
|
||||||
// into the flags and filenames necessary to pass to the compiler. The final creation of the rules
|
// into the flags and filenames necessary to pass to the Module. The final creation of the rules
|
||||||
// is handled in builder.go
|
// is handled in builder.go
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -54,7 +54,7 @@ func init() {
|
|||||||
// DroidDoc
|
// DroidDoc
|
||||||
// Findbugs
|
// Findbugs
|
||||||
|
|
||||||
type javaBaseProperties struct {
|
type compilerProperties struct {
|
||||||
// list of source files used to compile the Java module. May be .java, .logtags, .proto,
|
// list of source files used to compile the Java module. May be .java, .logtags, .proto,
|
||||||
// or .aidl files.
|
// or .aidl files.
|
||||||
Srcs []string `android:"arch_variant"`
|
Srcs []string `android:"arch_variant"`
|
||||||
@@ -106,13 +106,11 @@ type javaBaseProperties struct {
|
|||||||
Export_aidl_include_dirs []string
|
Export_aidl_include_dirs []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// javaBase contains the properties and members used by all java module types, and implements
|
// Module contains the properties and members used by all java module types
|
||||||
// the blueprint.Module interface.
|
type Module struct {
|
||||||
type javaBase struct {
|
|
||||||
android.ModuleBase
|
android.ModuleBase
|
||||||
module JavaModuleType
|
|
||||||
|
|
||||||
properties javaBaseProperties
|
properties compilerProperties
|
||||||
|
|
||||||
// output file suitable for inserting into the classpath of another compile
|
// output file suitable for inserting into the classpath of another compile
|
||||||
classpathFile android.Path
|
classpathFile android.Path
|
||||||
@@ -138,13 +136,6 @@ type javaBase struct {
|
|||||||
installFile android.Path
|
installFile android.Path
|
||||||
}
|
}
|
||||||
|
|
||||||
type AndroidJavaModuleContext android.BaseContext
|
|
||||||
|
|
||||||
type JavaModuleType interface {
|
|
||||||
GenerateJavaBuildActions(ctx android.ModuleContext)
|
|
||||||
JavaDependencies(ctx AndroidJavaModuleContext) []string
|
|
||||||
}
|
|
||||||
|
|
||||||
type JavaDependency interface {
|
type JavaDependency interface {
|
||||||
ClasspathFile() android.Path
|
ClasspathFile() android.Path
|
||||||
ClassJarSpecs() []jarSpec
|
ClassJarSpecs() []jarSpec
|
||||||
@@ -152,17 +143,7 @@ type JavaDependency interface {
|
|||||||
AidlIncludeDirs() android.Paths
|
AidlIncludeDirs() android.Paths
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewJavaBase(base *javaBase, module JavaModuleType, hod android.HostOrDeviceSupported,
|
func (j *Module) BootClasspath(ctx android.BaseContext) string {
|
||||||
props ...interface{}) (blueprint.Module, []interface{}) {
|
|
||||||
|
|
||||||
base.module = module
|
|
||||||
|
|
||||||
props = append(props, &base.properties)
|
|
||||||
|
|
||||||
return android.InitAndroidArchModule(base, hod, android.MultilibCommon, props...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (j *javaBase) BootClasspath(ctx android.BaseContext) string {
|
|
||||||
if ctx.Device() {
|
if ctx.Device() {
|
||||||
if j.properties.Sdk_version == "" {
|
if j.properties.Sdk_version == "" {
|
||||||
return "core-libart"
|
return "core-libart"
|
||||||
@@ -186,13 +167,7 @@ func (j *javaBase) BootClasspath(ctx android.BaseContext) string {
|
|||||||
|
|
||||||
var defaultJavaLibraries = []string{"core-libart", "legacy-test", "ext", "framework"}
|
var defaultJavaLibraries = []string{"core-libart", "legacy-test", "ext", "framework"}
|
||||||
|
|
||||||
func (j *javaBase) DepsMutator(ctx android.BottomUpMutatorContext) {
|
func (j *Module) deps(ctx android.BottomUpMutatorContext) {
|
||||||
if j, ok := ctx.Module().(JavaModuleType); ok {
|
|
||||||
ctx.AddDependency(ctx.Module(), nil, j.JavaDependencies(ctx)...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (j *javaBase) JavaDependencies(ctx AndroidJavaModuleContext) []string {
|
|
||||||
var deps []string
|
var deps []string
|
||||||
|
|
||||||
if !j.properties.No_standard_libraries {
|
if !j.properties.No_standard_libraries {
|
||||||
@@ -207,10 +182,10 @@ func (j *javaBase) JavaDependencies(ctx AndroidJavaModuleContext) []string {
|
|||||||
deps = append(deps, j.properties.Java_libs...)
|
deps = append(deps, j.properties.Java_libs...)
|
||||||
deps = append(deps, j.properties.Java_static_libs...)
|
deps = append(deps, j.properties.Java_static_libs...)
|
||||||
|
|
||||||
return deps
|
ctx.AddDependency(ctx.Module(), nil, deps...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *javaBase) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
|
func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
|
||||||
aidlIncludeDirs android.Paths) []string {
|
aidlIncludeDirs android.Paths) []string {
|
||||||
|
|
||||||
localAidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl_includes)
|
localAidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl_includes)
|
||||||
@@ -230,7 +205,7 @@ func (j *javaBase) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.O
|
|||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *javaBase) collectDeps(ctx android.ModuleContext) (classpath android.Paths,
|
func (j *Module) collectDeps(ctx android.ModuleContext) (classpath android.Paths,
|
||||||
bootClasspath android.OptionalPath, classJarSpecs, resourceJarSpecs []jarSpec, aidlPreprocess android.OptionalPath,
|
bootClasspath android.OptionalPath, classJarSpecs, resourceJarSpecs []jarSpec, aidlPreprocess android.OptionalPath,
|
||||||
aidlIncludeDirs android.Paths, srcFileLists android.Paths) {
|
aidlIncludeDirs android.Paths, srcFileLists android.Paths) {
|
||||||
|
|
||||||
@@ -251,7 +226,7 @@ func (j *javaBase) collectDeps(ctx android.ModuleContext) (classpath android.Pat
|
|||||||
if ctx.ModuleName() == "framework" {
|
if ctx.ModuleName() == "framework" {
|
||||||
// framework.jar has a one-off dependency on the R.java and Manifest.java files
|
// framework.jar has a one-off dependency on the R.java and Manifest.java files
|
||||||
// generated by framework-res.apk
|
// generated by framework-res.apk
|
||||||
srcFileLists = append(srcFileLists, module.(*javaBase).module.(*AndroidApp).aaptJavaFileList)
|
srcFileLists = append(srcFileLists, module.(*AndroidApp).aaptJavaFileList)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
|
panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
|
||||||
@@ -274,11 +249,7 @@ func (j *javaBase) collectDeps(ctx android.ModuleContext) (classpath android.Pat
|
|||||||
aidlIncludeDirs, srcFileLists
|
aidlIncludeDirs, srcFileLists
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *javaBase) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
func (j *Module) compile(ctx android.ModuleContext) {
|
||||||
j.module.GenerateJavaBuildActions(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (j *javaBase) GenerateJavaBuildActions(ctx android.ModuleContext) {
|
|
||||||
|
|
||||||
j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.properties.Export_aidl_include_dirs)
|
j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.properties.Export_aidl_include_dirs)
|
||||||
|
|
||||||
@@ -404,25 +375,25 @@ func (j *javaBase) GenerateJavaBuildActions(ctx android.ModuleContext) {
|
|||||||
|
|
||||||
var _ JavaDependency = (*JavaLibrary)(nil)
|
var _ JavaDependency = (*JavaLibrary)(nil)
|
||||||
|
|
||||||
func (j *javaBase) ClasspathFile() android.Path {
|
func (j *Module) ClasspathFile() android.Path {
|
||||||
return j.classpathFile
|
return j.classpathFile
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *javaBase) ClassJarSpecs() []jarSpec {
|
func (j *Module) ClassJarSpecs() []jarSpec {
|
||||||
return j.classJarSpecs
|
return j.classJarSpecs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *javaBase) ResourceJarSpecs() []jarSpec {
|
func (j *Module) ResourceJarSpecs() []jarSpec {
|
||||||
return j.resourceJarSpecs
|
return j.resourceJarSpecs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *javaBase) AidlIncludeDirs() android.Paths {
|
func (j *Module) AidlIncludeDirs() android.Paths {
|
||||||
return j.exportAidlIncludeDirs
|
return j.exportAidlIncludeDirs
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ logtagsProducer = (*javaBase)(nil)
|
var _ logtagsProducer = (*Module)(nil)
|
||||||
|
|
||||||
func (j *javaBase) logtags() android.Paths {
|
func (j *Module) logtags() android.Paths {
|
||||||
return j.logtagsSrcs
|
return j.logtagsSrcs
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -431,27 +402,33 @@ func (j *javaBase) logtags() android.Paths {
|
|||||||
//
|
//
|
||||||
|
|
||||||
type JavaLibrary struct {
|
type JavaLibrary struct {
|
||||||
javaBase
|
Module
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *JavaLibrary) GenerateJavaBuildActions(ctx android.ModuleContext) {
|
func (j *JavaLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||||
j.javaBase.GenerateJavaBuildActions(ctx)
|
j.compile(ctx)
|
||||||
|
|
||||||
j.installFile = ctx.InstallFileName(android.PathForModuleInstall(ctx, "framework"), ctx.ModuleName()+".jar", j.outputFile)
|
j.installFile = ctx.InstallFileName(android.PathForModuleInstall(ctx, "framework"), ctx.ModuleName()+".jar", j.outputFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (j *JavaLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
|
||||||
|
j.deps(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
func JavaLibraryFactory() (blueprint.Module, []interface{}) {
|
func JavaLibraryFactory() (blueprint.Module, []interface{}) {
|
||||||
module := &JavaLibrary{}
|
module := &JavaLibrary{}
|
||||||
|
|
||||||
module.properties.Dex = true
|
module.properties.Dex = true
|
||||||
|
|
||||||
return NewJavaBase(&module.javaBase, module, android.HostAndDeviceSupported)
|
return android.InitAndroidArchModule(module, android.HostAndDeviceSupported,
|
||||||
|
android.MultilibCommon, &module.Module.properties)
|
||||||
}
|
}
|
||||||
|
|
||||||
func JavaLibraryHostFactory() (blueprint.Module, []interface{}) {
|
func JavaLibraryHostFactory() (blueprint.Module, []interface{}) {
|
||||||
module := &JavaLibrary{}
|
module := &JavaLibrary{}
|
||||||
|
|
||||||
return NewJavaBase(&module.javaBase, module, android.HostSupported)
|
return android.InitAndroidArchModule(module, android.HostSupported,
|
||||||
|
android.MultilibCommon, &module.Module.properties)
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -469,8 +446,8 @@ type JavaBinary struct {
|
|||||||
binaryProperties javaBinaryProperties
|
binaryProperties javaBinaryProperties
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *JavaBinary) GenerateJavaBuildActions(ctx android.ModuleContext) {
|
func (j *JavaBinary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||||
j.JavaLibrary.GenerateJavaBuildActions(ctx)
|
j.JavaLibrary.GenerateAndroidBuildActions(ctx)
|
||||||
|
|
||||||
// Depend on the installed jar (j.installFile) so that the wrapper doesn't get executed by
|
// Depend on the installed jar (j.installFile) so that the wrapper doesn't get executed by
|
||||||
// another build rule before the jar has been installed.
|
// another build rule before the jar has been installed.
|
||||||
@@ -478,18 +455,24 @@ func (j *JavaBinary) GenerateJavaBuildActions(ctx android.ModuleContext) {
|
|||||||
j.installFile)
|
j.installFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (j *JavaBinary) DepsMutator(ctx android.BottomUpMutatorContext) {
|
||||||
|
j.deps(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
func JavaBinaryFactory() (blueprint.Module, []interface{}) {
|
func JavaBinaryFactory() (blueprint.Module, []interface{}) {
|
||||||
module := &JavaBinary{}
|
module := &JavaBinary{}
|
||||||
|
|
||||||
module.properties.Dex = true
|
module.properties.Dex = true
|
||||||
|
|
||||||
return NewJavaBase(&module.javaBase, module, android.HostAndDeviceSupported, &module.binaryProperties)
|
return android.InitAndroidArchModule(module, android.HostAndDeviceSupported,
|
||||||
|
android.MultilibCommon, &module.Module.properties, &module.binaryProperties)
|
||||||
}
|
}
|
||||||
|
|
||||||
func JavaBinaryHostFactory() (blueprint.Module, []interface{}) {
|
func JavaBinaryHostFactory() (blueprint.Module, []interface{}) {
|
||||||
module := &JavaBinary{}
|
module := &JavaBinary{}
|
||||||
|
|
||||||
return NewJavaBase(&module.javaBase, module, android.HostSupported, &module.binaryProperties)
|
return android.InitAndroidArchModule(module, android.HostSupported,
|
||||||
|
android.MultilibCommon, &module.Module.properties, &module.binaryProperties)
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
Reference in New Issue
Block a user