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/resources.go b/java/resources.go
index 4969d48..9f5e5e0 100644
--- a/java/resources.go
+++ b/java/resources.go
@@ -15,7 +15,9 @@
 package java
 
 import (
+	"fmt"
 	"path/filepath"
+	"strings"
 
 	"github.com/google/blueprint/bootstrap"
 
@@ -71,3 +73,20 @@
 
 	return args, deps
 }
+
+func ResourceFilesToJarArgs(ctx android.ModuleContext,
+	res, exclude []string) (args []string, deps android.Paths) {
+	files := ctx.ExpandSources(res, exclude)
+
+	for _, f := range files {
+		rel := f.Rel()
+		path := f.String()
+		if !strings.HasSuffix(path, rel) {
+			panic(fmt.Errorf("path %q does not end with %q", path, rel))
+		}
+		path = filepath.Clean(strings.TrimSuffix(path, rel))
+		args = append(args, "-C", filepath.Clean(path), "-f", f.String())
+	}
+
+	return args, files
+}