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
diff --git a/java/java.go b/java/java.go
index 06ba44d..dbb755b 100644
--- a/java/java.go
+++ b/java/java.go
@@ -75,6 +75,12 @@
 	// 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 @@
 	// 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 @@
 	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 @@
 		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