Merge remote-tracking branch 'aosp/upstream-master' into master

Bug: 36792868
Test: m -j
Change-Id: I93e18d46e04d41256c56d3d7939914e631b29a98
diff --git a/Android.mk b/Android.mk
new file mode 100644
index 0000000..b55fb27
--- /dev/null
+++ b/Android.mk
@@ -0,0 +1,64 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+LOCAL_PATH := $(call my-dir)
+
+# Build jacoco from sources for the platform
+#
+# Note: this is only intended to be used for the platform development. This is *not* intended
+# to be used in the SDK where apps can use the official jacoco release.
+include $(CLEAR_VARS)
+
+jacoco_src_files := $(call all-java-files-under,org.jacoco.core/src)
+jacoco_src_files += $(call all-java-files-under,org.jacoco.agent/src)
+jacoco_src_files += $(call all-java-files-under,org.jacoco.agent.rt/src)
+
+# Some Jacoco source files depend on classes that do not exist in Android. While these classes are
+# not executed at runtime (because we use offline instrumentation), they will cause issues when
+# compiling them with ART during dex pre-opting. Therefore, it would prevent from applying code
+# coverage on classes in the bootclasspath (frameworks, services, ...) or system apps.
+# Note: we still may need to update the source code to cut dependencies in mandatory jacoco classes.
+jacoco_android_exclude_list := \
+  %org.jacoco.core/src/org/jacoco/core/runtime/ModifiedSystemClassRuntime.java \
+  %org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/PreMain.java \
+  %org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/CoverageTransformer.java \
+  %org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/JmxRegistration.java
+
+LOCAL_SRC_FILES := $(filter-out $(jacoco_android_exclude_list),$(jacoco_src_files))
+
+# In order to include Jacoco in core libraries, we cannot depend on anything in the
+# bootclasspath (or we would create dependency cycle). Therefore we compile against
+# the SDK android.jar which gives the same APIs Jacoco depends on.
+LOCAL_SDK_VERSION := 9
+
+LOCAL_MODULE := jacocoagent
+LOCAL_MODULE_TAGS := optional
+LOCAL_STATIC_JAVA_LIBRARIES := jacoco-asm
+include $(BUILD_STATIC_JAVA_LIBRARY)
+
+#
+# Build asm-5.0.1 as a static library.
+#
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := jacoco-asm
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE_CLASS := JAVA_LIBRARIES
+LOCAL_SRC_FILES := asm-debug-all-5.0.1$(COMMON_JAVA_PACKAGE_SUFFIX)
+# Workaround for b/27319022
+LOCAL_JACK_FLAGS := -D jack.import.jar.debug-info=false
+LOCAL_UNINSTALLABLE_MODULE := true
+
+include $(BUILD_PREBUILT)
diff --git a/MODULE_LICENSE_EPL b/MODULE_LICENSE_EPL
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/MODULE_LICENSE_EPL
diff --git a/NOTICE b/NOTICE
new file mode 100644
index 0000000..54fc346
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,14 @@
+License
+=======
+
+Copyright (c) 2009, 2015 Mountainminds GmbH & Co. KG and Contributors
+
+The JaCoCo Java Code Coverage Library and all included documentation is made
+available by Mountainminds GmbH & Co. KG, Munich. Except indicated below, the
+Content is provided to you under the terms and conditions of the Eclipse Public
+License Version 1.0 ("EPL"). A copy of the EPL is available at
+[http://www.eclipse.org/legal/epl-v10.html](http://www.eclipse.org/legal/epl-v10.html).
+
+Please visit
+[http://www.eclemma.org/jacoco/trunk/doc/license.html](http://www.eclemma.org/jacoco/trunk/doc/license.html)
+for the complete license information including third party licenses and trademarks.
diff --git a/PREBUILT b/PREBUILT
new file mode 100644
index 0000000..c8d9fd8
--- /dev/null
+++ b/PREBUILT
@@ -0,0 +1,7 @@
+The ASM jar required by jacoco is updated in the following way:
+
+mvn -f org.jacoco.agent.rt/pom.xml dependency:copy-dependencies
+cp org.jacoco.agent.rt/target/dependency/asm-debug-all-5.0.1.jar ./
+mvn clean
+
+The Android.mk must be updated to reference the right prebuilt.
diff --git a/README.android b/README.android
new file mode 100644
index 0000000..cad30c6
--- /dev/null
+++ b/README.android
@@ -0,0 +1,16 @@
+We build an equivalent of the jacoco-agent.jar which contains classes from org.jacoco.core,
+org.jacoco.agent and org.jacoco.agent.rt packages but also classes from asm 5.0.1.
+
+However, Jacoco depends on classes that do not exist in Android (java.lang.instrument.* or
+javax.management.*) for runtime instrumentation only. The ART compiler would reject those classes
+when they are either in the bootclasspath (core, frameworks, ...) or system apps.
+
+Since we only use offline instrumentation for code coverage (using Jack) and do not execute these
+classes at runtime, we simply not compile them here.
+
+We also need to modify the source code to cut dependencies to the classes that we exclude from the
+compilation. The changes are surrounded by "BEGIN android-change" and "END android-change". Here
+is the list of the changes:
+
+1) Remove the creation of JmxRegistration in org.jacoco.agent.rt.internal.Agent.
+2) Change default OutputMode to none in org.jacoco.core.runtime.AgentOptions
diff --git a/README.version b/README.version
new file mode 100644
index 0000000..0ef82ce
--- /dev/null
+++ b/README.version
@@ -0,0 +1,4 @@
+URL: https://github.com/jacoco/jacoco/tree/v0.7.5
+Version: v0.7.5
+BugComponent: 108682
+Owners: shertz
diff --git a/asm-debug-all-5.0.1.jar b/asm-debug-all-5.0.1.jar
new file mode 100644
index 0000000..76d4b6a
--- /dev/null
+++ b/asm-debug-all-5.0.1.jar
Binary files differ
diff --git a/config.mk b/config.mk
new file mode 100644
index 0000000..d645621
--- /dev/null
+++ b/config.mk
@@ -0,0 +1,16 @@
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+JACOCO_PACKAGE_NAME := org.jacoco.agent.rt.internal
+
diff --git a/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/Agent.java b/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/Agent.java
index dd45e14..e21371b 100644
--- a/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/Agent.java
+++ b/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/Agent.java
@@ -121,7 +121,9 @@
 			output = createAgentOutput();
 			output.startup(options, data);
 			if (options.getJmx()) {
-				jmxRegistration = new JmxRegistration(this);
+// BEGIN android-change
+//				jmxRegistration = new JmxRegistration(this);
+// END android-change
 			}
 		} catch (final Exception e) {
 			logger.logExeption(e);
diff --git a/org.jacoco.core/src/org/jacoco/core/runtime/AgentOptions.java b/org.jacoco.core/src/org/jacoco/core/runtime/AgentOptions.java
index 6422832..cf57512 100644
--- a/org.jacoco.core/src/org/jacoco/core/runtime/AgentOptions.java
+++ b/org.jacoco.core/src/org/jacoco/core/runtime/AgentOptions.java
@@ -494,7 +494,10 @@
 	 */
 	public OutputMode getOutput() {
 		final String value = options.get(OUTPUT);
-		return value == null ? OutputMode.file : OutputMode.valueOf(value);
+// BEGIN android-change
+//		return value == null ? OutputMode.file : OutputMode.valueOf(value);
+		return value == null ? OutputMode.none : OutputMode.valueOf(value);
+// END android-change
 	}
 
 	/**