Merge "Add makefile targets for ojluni jaif-annotated source files."
diff --git a/Docs.mk b/Docs.mk
index bf0d3da..f81a336 100644
--- a/Docs.mk
+++ b/Docs.mk
@@ -18,6 +18,15 @@
    )
 _icu_files := $(addprefix external/icu/, $(_icu_files))
 
+
+# Get list of targets annotated with annotations from jaif file
+# Remove un-annotated original source file and replace them with annotated targets
+#
+_ojluni_annotate_src := $(shell libcore/annotations/classes_from_jaif.py libcore/annotations/ojluni.jaif)
+_ojluni_annotate_output := $(patsubst %,$(call intermediates-dir-for,JAVA_LIBRARIES,core-oj)/annotated/%, $(_ojluni_annotate_src))
+_libcore_files := $(filter-out $(patsubst %, libcore/ojluni/src/main/java/%, $(_ojluni_annotate_src)), $(_libcore_files))
+_libcore_files += $(_ojluni_annotate_output)
+
 # List of libcore-related javadoc source files
 #
 # NOTE: Because libcore-related source spans modules (not just libcore!), files names here are
diff --git a/JavaLibrary.mk b/JavaLibrary.mk
index 4ebf2d8..b623916 100644
--- a/JavaLibrary.mk
+++ b/JavaLibrary.mk
@@ -88,9 +88,24 @@
 android_icu4j_resource_dirs := $(android_icu4j_root)/resources
 
 #
+# Build jaif-annotated source files for ojluni target .
+#
+_insert-annotations-to-source := external/annotation-tools/annotation-file-utilities/scripts/insert-annotations-to-source
+_annotations_classes_from_jaif := $(LOCAL_PATH)/annotations/classes_from_jaif.py
+_ojluni_annotate_target := $(intermediates)/annotated
+_ojluni_annotate_jaif := $(LOCAL_PATH)/annotations/ojluni.jaif
+_ojluni_annotate_input := $(patsubst %,$(LOCAL_PATH)/ojluni/src/main/java/%,$(shell $(_annotations_classes_from_jaif) $(_ojluni_annotate_jaif)))
+_ojluni_annotate_output := $(patsubst $(LOCAL_PATH)/ojluni/src/main/java/%, $(_ojluni_annotate_target)/%, $(_ojluni_annotate_input))
+
+$(_ojluni_annotate_target): $(LOCAL_BUILT_MODULE) $(_ojluni_annotate_input) $(_ojluni_annotate_jaif)
+	rm -rf $(_ojluni_annotate_target)
+	mkdir -p $(_ojluni_annotate_target)
+	$(_insert-annotations-to-source) -d $(_ojluni_annotate_target) $(_ojluni_annotate_jaif) $(_ojluni_annotate_input)
+$(_ojluni_annotate_output): $(_ojluni_annotate_target)
+
+#
 # Build for the target (device).
 #
-
 ifeq ($(LIBCORE_SKIP_TESTS),)
 # A guaranteed unstripped version of core-oj and core-libart.
 # The build system may or may not strip the core-oj and core-libart jars,
diff --git a/annotations/classes_from_jaif.py b/annotations/classes_from_jaif.py
new file mode 100755
index 0000000..579bf0c
--- /dev/null
+++ b/annotations/classes_from_jaif.py
@@ -0,0 +1,19 @@
+#!/usr/bin/env python
+
+"""Print out list of java classes targeted by a jaif file."""
+
+import os
+
+PACKAGE_STRING = 'package '
+CLASS_STRING = 'class '
+
+current_package = None
+with open(os.sys.argv[1], 'r') as jaif_file:
+  for line in jaif_file:
+    if line.startswith(PACKAGE_STRING):
+      current_package = line[len(PACKAGE_STRING): line.find(':')]
+    if line.startswith(CLASS_STRING) && current_package is not None:
+      current_class = line[len(CLASS_STRING): line.find(':')]
+      print current_package.replace('.', '/') + '/' + current_class + '.java'
+
+os.sys.exit(0)