diff options
author | Colin Cross <ccross@android.com> | 2017-06-22 16:51:17 -0700 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2017-06-23 10:57:36 -0700 |
commit | 46c9b8bfd56bf23a54f8e482e282cf84bb407a6f (patch) | |
tree | 42a0e86256e537a1e4edf0bbb1f6d7cb379594de /java/java.go | |
parent | ba211130bdd20082fd6d86a6c6d529acb5abcf88 (diff) |
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
Diffstat (limited to 'java/java.go')
-rw-r--r-- | java/java.go | 95 |
1 files changed, 39 insertions, 56 deletions
diff --git a/java/java.go b/java/java.go index 6dc955db0..8efff6eac 100644 --- a/java/java.go +++ b/java/java.go @@ -15,7 +15,7 @@ package java // 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 import ( @@ -54,7 +54,7 @@ func init() { // DroidDoc // Findbugs -type javaBaseProperties struct { +type compilerProperties struct { // list of source files used to compile the Java module. May be .java, .logtags, .proto, // or .aidl files. Srcs []string `android:"arch_variant"` @@ -106,13 +106,11 @@ type javaBaseProperties struct { Export_aidl_include_dirs []string } -// javaBase contains the properties and members used by all java module types, and implements -// the blueprint.Module interface. -type javaBase struct { +// Module contains the properties and members used by all java module types +type Module struct { android.ModuleBase - module JavaModuleType - properties javaBaseProperties + properties compilerProperties // output file suitable for inserting into the classpath of another compile classpathFile android.Path @@ -138,13 +136,6 @@ type javaBase struct { installFile android.Path } -type AndroidJavaModuleContext android.BaseContext - -type JavaModuleType interface { - GenerateJavaBuildActions(ctx android.ModuleContext) - JavaDependencies(ctx AndroidJavaModuleContext) []string -} - type JavaDependency interface { ClasspathFile() android.Path ClassJarSpecs() []jarSpec @@ -152,17 +143,7 @@ type JavaDependency interface { AidlIncludeDirs() android.Paths } -func NewJavaBase(base *javaBase, module JavaModuleType, hod android.HostOrDeviceSupported, - 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 { +func (j *Module) BootClasspath(ctx android.BaseContext) string { if ctx.Device() { if j.properties.Sdk_version == "" { return "core-libart" @@ -186,13 +167,7 @@ func (j *javaBase) BootClasspath(ctx android.BaseContext) string { var defaultJavaLibraries = []string{"core-libart", "legacy-test", "ext", "framework"} -func (j *javaBase) DepsMutator(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 { +func (j *Module) deps(ctx android.BottomUpMutatorContext) { var deps []string 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_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 { localAidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl_includes) @@ -230,7 +205,7 @@ func (j *javaBase) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.O 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, aidlIncludeDirs android.Paths, srcFileLists android.Paths) { @@ -251,7 +226,7 @@ func (j *javaBase) collectDeps(ctx android.ModuleContext) (classpath android.Pat if ctx.ModuleName() == "framework" { // framework.jar has a one-off dependency on the R.java and Manifest.java files // generated by framework-res.apk - srcFileLists = append(srcFileLists, module.(*javaBase).module.(*AndroidApp).aaptJavaFileList) + srcFileLists = append(srcFileLists, module.(*AndroidApp).aaptJavaFileList) } } else { 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 } -func (j *javaBase) GenerateAndroidBuildActions(ctx android.ModuleContext) { - j.module.GenerateJavaBuildActions(ctx) -} - -func (j *javaBase) GenerateJavaBuildActions(ctx android.ModuleContext) { +func (j *Module) compile(ctx android.ModuleContext) { 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) -func (j *javaBase) ClasspathFile() android.Path { +func (j *Module) ClasspathFile() android.Path { return j.classpathFile } -func (j *javaBase) ClassJarSpecs() []jarSpec { +func (j *Module) ClassJarSpecs() []jarSpec { return j.classJarSpecs } -func (j *javaBase) ResourceJarSpecs() []jarSpec { +func (j *Module) ResourceJarSpecs() []jarSpec { return j.resourceJarSpecs } -func (j *javaBase) AidlIncludeDirs() android.Paths { +func (j *Module) AidlIncludeDirs() android.Paths { 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 } @@ -431,27 +402,33 @@ func (j *javaBase) logtags() android.Paths { // type JavaLibrary struct { - javaBase + Module } -func (j *JavaLibrary) GenerateJavaBuildActions(ctx android.ModuleContext) { - j.javaBase.GenerateJavaBuildActions(ctx) +func (j *JavaLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { + j.compile(ctx) 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{}) { module := &JavaLibrary{} 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{}) { 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 } -func (j *JavaBinary) GenerateJavaBuildActions(ctx android.ModuleContext) { - j.JavaLibrary.GenerateJavaBuildActions(ctx) +func (j *JavaBinary) GenerateAndroidBuildActions(ctx android.ModuleContext) { + j.JavaLibrary.GenerateAndroidBuildActions(ctx) // 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. @@ -478,18 +455,24 @@ func (j *JavaBinary) GenerateJavaBuildActions(ctx android.ModuleContext) { j.installFile) } +func (j *JavaBinary) DepsMutator(ctx android.BottomUpMutatorContext) { + j.deps(ctx) +} + func JavaBinaryFactory() (blueprint.Module, []interface{}) { module := &JavaBinary{} 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{}) { module := &JavaBinary{} - return NewJavaBase(&module.javaBase, module, android.HostSupported, &module.binaryProperties) + return android.InitAndroidArchModule(module, android.HostSupported, + android.MultilibCommon, &module.Module.properties, &module.binaryProperties) } // |