From 0f37af0c155b2f934e463da9c47af2afe5ee6cef Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Wed, 27 Sep 2017 17:42:05 -0700 Subject: Add java file resources and flag to include sources Add a properties to allow including files as resources, including support for filegroups. Also add a flag that causes module sources to be included in the final jar. Test: java_test.go TestResources Change-Id: Ida8ee59b28df9fe66952170f46470d3a09fd5d65 --- java/java.go | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index 06ba44db8..dbb755b9f 100644 --- a/java/java.go +++ b/java/java.go @@ -75,6 +75,12 @@ type CompilerProperties struct { // list of directories that should be excluded from java_resource_dirs Exclude_java_resource_dirs []string `android:"arch_variant"` + // list of files to use as Java resources + Java_resources []string `android:"arch_variant"` + + // list of files that should be excluded from java_resources + Exclude_java_resources []string `android:"arch_variant"` + // don't build against the default libraries (legacy-test, core-junit, // ext, and framework for device targets) No_standard_libs *bool @@ -100,6 +106,9 @@ type CompilerProperties struct { // If set to false, don't allow this module to be installed. Defaults to true. Installable *bool + // If set to true, include sources used to compile the module in to the final jar + Include_srcs *bool + // List of modules to use as annotation processors Annotation_processors []string @@ -275,6 +284,7 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) { ctx.AddDependency(ctx.Module(), libTag, j.properties.Annotation_processors...) android.ExtractSourcesDeps(ctx, j.properties.Srcs) + android.ExtractSourcesDeps(ctx, j.properties.Java_resources) } func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath, @@ -426,7 +436,23 @@ func (j *Module) compile(ctx android.ModuleContext) { jars = append(jars, classes) } - resArgs, resDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs, j.properties.Exclude_java_resource_dirs) + dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs, j.properties.Exclude_java_resource_dirs) + fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources) + + var resArgs []string + var resDeps android.Paths + + resArgs = append(resArgs, dirArgs...) + resDeps = append(resDeps, dirDeps...) + + resArgs = append(resArgs, fileArgs...) + resDeps = append(resDeps, fileDeps...) + + if proptools.Bool(j.properties.Include_srcs) { + srcArgs, srcDeps := ResourceFilesToJarArgs(ctx, j.properties.Srcs, j.properties.Exclude_srcs) + resArgs = append(resArgs, srcArgs...) + resDeps = append(resDeps, srcDeps...) + } if len(resArgs) > 0 { // Combine classes + resources into classes-full-debug.jar -- cgit v1.2.3-59-g8ed1b