Build core-junit from external/junit source.

Bug 5826326

Change-Id: I63b409009ab995742a84e8615314e649adb88a3e
diff --git a/Android.mk b/Android.mk
index ef7e3af..4a842dd 100644
--- a/Android.mk
+++ b/Android.mk
@@ -15,10 +15,16 @@
 #
 
 LOCAL_PATH := $(call my-dir)
+
+# include definition of core-junit-files
+include $(LOCAL_PATH)/Common.mk
+
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
+# note: ideally this should be junit-host, but leave as is for now to avoid
+# changing all its dependencies
 LOCAL_MODULE := junit
 
 LOCAL_MODULE_TAGS := optional
@@ -26,3 +32,38 @@
 LOCAL_STATIC_JAVA_LIBRARIES := hamcrest-host
 
 include $(BUILD_HOST_JAVA_LIBRARY)
+
+# ----------------------------------
+# build a core-junit target jar that is built into Android system image
+
+include $(CLEAR_VARS)
+
+# TODO: remove extensions once core-tests is no longer dependent on it
+LOCAL_SRC_FILES := $(call all-java-files-under, src/junit/extensions)
+LOCAL_SRC_FILES += $(core-junit-files)
+
+LOCAL_NO_STANDARD_LIBRARIES := true
+LOCAL_JAVA_LIBRARIES := core
+LOCAL_JAVACFLAGS := $(local_javac_flags)
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE := core-junit
+include $(BUILD_JAVA_LIBRARY)
+
+# ----------------------------------
+# build a core-junit-hostdex jar that contains exactly the same classes
+# as core-junit.
+
+include $(CLEAR_VARS)
+
+# TODO: remove extensions once apache-harmony/luni/ is no longer dependent
+# on it
+LOCAL_SRC_FILES := $(call all-java-files-under, src/junit/extensions)
+LOCAL_SRC_FILES += $(core-junit-files)
+LOCAL_NO_STANDARD_LIBRARIES := true
+LOCAL_JAVA_LIBRARIES := core-hostdex
+LOCAL_JAVACFLAGS := $(local_javac_flags)
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE := core-junit-hostdex
+LOCAL_BUILD_HOST_DEX := true
+include $(BUILD_HOST_JAVA_LIBRARY)
+
diff --git a/Common.mk b/Common.mk
new file mode 100644
index 0000000..2275c9b
--- /dev/null
+++ b/Common.mk
@@ -0,0 +1,31 @@
+# -*- mode: makefile -*-
+# List of junit files include in documentation.
+# Shared with frameworks/base.
+# based off libcore/Docs.mk
+
+
+# List of source to build into the core-junit library
+#
+# The list also includes all junit files in public API.
+#
+core-junit-files := \
+src/junit/framework/Assert.java \
+src/junit/framework/AssertionFailedError.java \
+src/junit/framework/ComparisonCompactor.java \
+src/junit/framework/ComparisonFailure.java \
+src/junit/framework/Protectable.java \
+src/junit/framework/Test.java \
+src/junit/framework/TestCase.java \
+src/junit/framework/TestFailure.java \
+src/junit/framework/TestListener.java \
+src/junit/framework/TestResult.java \
+src/junit/framework/TestSuite.java
+
+# TODO: add define for public API files in android.test.runner
+
+# List of junit javadoc source files for Android public API
+#
+# $(1): directory for search (to support use from frameworks/base)
+define junit_to_document
+ $(core-junit-files)
+endef