weex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ky...@apache.org
Subject [01/14] incubator-weex git commit: * [android] add jacoco 4 gradle config
Date Thu, 07 Sep 2017 08:18:18 GMT
Repository: incubator-weex
Updated Branches:
  refs/heads/0.16-dev ff13f51d5 -> 3f32c552d


* [android] add jacoco 4 gradle config


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/fcc7eec2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/fcc7eec2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/fcc7eec2

Branch: refs/heads/0.16-dev
Commit: fcc7eec2ca8766d53a61f45430d7f0235ac2551c
Parents: 781296f
Author: atomtong <tong_huabing@qq.com>
Authored: Mon Aug 28 16:22:45 2017 +0800
Committer: atomtong <tong_huabing@qq.com>
Committed: Mon Aug 28 16:22:45 2017 +0800

----------------------------------------------------------------------
 android/build.gradle                            |   4 +-
 .../gradle/wrapper/gradle-wrapper.properties    |   2 +-
 android/jacoco.gradle                           |  45 ++++++++
 android/jacoco/android-jacoco-the-missing.jar   | Bin 0 -> 2214869 bytes
 android/jacoco/coverage.ec                      | Bin 0 -> 63 bytes
 android/playground/app/build.gradle             |  11 +-
 .../playground/app/src/main/AndroidManifest.xml |   8 ++
 .../java/com/alibaba/weex/WXPageActivity.java   |   4 +
 .../alibaba/weex/util/CoverageDataDumper.java   |  36 ++++++
 .../alibaba/weex/util/JacocoCodeCoverage.java   | 109 +++++++++++++++++++
 android/sdk/build.gradle                        |  13 ++-
 android/sdk/coverage.ec                         | Bin 0 -> 63 bytes
 android/weex_debug/build.gradle                 |   2 +-
 13 files changed, 226 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/fcc7eec2/android/build.gradle
----------------------------------------------------------------------
diff --git a/android/build.gradle b/android/build.gradle
index 28cf76e..04cbb67 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -5,7 +5,7 @@ buildscript {
         jcenter()
     }
     dependencies {
-        classpath 'com.android.tools.build:gradle:2.1.3'
+        classpath 'com.android.tools.build:gradle:2.3.3'
     }
 }
 
@@ -29,7 +29,7 @@ subprojects {
             jcenter()
         }
         dependencies {
-            classpath 'com.android.tools.build:gradle:2.1.3'
+            classpath 'com.android.tools.build:gradle:2.3.3'
         }
     }
     ext {

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/fcc7eec2/android/gradle/wrapper/gradle-wrapper.properties
----------------------------------------------------------------------
diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties
index d795868..2af1c24 100644
--- a/android/gradle/wrapper/gradle-wrapper.properties
+++ b/android/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
 distributionPath=wrapper/dists
 zipStoreBase=GRADLE_USER_HOME
 zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/fcc7eec2/android/jacoco.gradle
----------------------------------------------------------------------
diff --git a/android/jacoco.gradle b/android/jacoco.gradle
new file mode 100644
index 0000000..e8ea251
--- /dev/null
+++ b/android/jacoco.gradle
@@ -0,0 +1,45 @@
+apply plugin: 'jacoco'
+
+jacoco {
+    toolVersion = "0.7.9+"
+}
+
+//def sdk_path = '../../sdk'
+//println(sdk_path)
+
+def coverageSourceDirs = [
+        '../app/src/main/java',
+        '../../../android/sdk/src/main/java'
+
+]
+
+task jacocoTestReport(type: JacocoReport) {
+    group = "Reporting"
+    description = "Generate Jacoco coverage reports after running tests."
+    reports {
+        xml.enabled = true
+        html.enabled = true
+    }
+    classDirectories = fileTree(//"enter code here"
+            dir: '../../sdk/build/intermediates/classes',
+            excludes: ['**/R*.class',
+                       '**/*$InjectAdapter.class',
+                       '**/*$ModuleAdapter.class',
+                       '**/*$ViewInjector*.class'
+            ])
+    sourceDirectories = files(coverageSourceDirs)
+    File configFile = file('../../../android/sdk/src/main/java')
+    configFile = file(configFile.absolutePath)
+    println configFile.path
+
+
+
+    executionData = files("$buildDir/outputs/code-coverage/connected/coverage.exec")
+    doFirst {
+        new File("$buildDir/intermediates/classes/").eachFileRecurse { file ->
+            if (file.name.contains('$$')) {
+                file.renameTo(file.path.replace('$$', '$'))
+            }
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/fcc7eec2/android/jacoco/android-jacoco-the-missing.jar
----------------------------------------------------------------------
diff --git a/android/jacoco/android-jacoco-the-missing.jar b/android/jacoco/android-jacoco-the-missing.jar
new file mode 100644
index 0000000..59b821c
Binary files /dev/null and b/android/jacoco/android-jacoco-the-missing.jar differ

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/fcc7eec2/android/jacoco/coverage.ec
----------------------------------------------------------------------
diff --git a/android/jacoco/coverage.ec b/android/jacoco/coverage.ec
new file mode 100644
index 0000000..cc4c834
Binary files /dev/null and b/android/jacoco/coverage.ec differ

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/fcc7eec2/android/playground/app/build.gradle
----------------------------------------------------------------------
diff --git a/android/playground/app/build.gradle b/android/playground/app/build.gradle
index bc50f70..073ad4d 100755
--- a/android/playground/app/build.gradle
+++ b/android/playground/app/build.gradle
@@ -1,4 +1,11 @@
 apply plugin: 'com.android.application'
+apply from: '../../jacoco.gradle'
+
+//apply plugin: 'jacoco'
+//
+//jacoco {
+//    toolVersion = "0.7.9+"
+//}
 
 android {
     compileSdkVersion project.compileSdkVersion
@@ -35,7 +42,7 @@ android {
     }
     buildTypes {
         debug {
-            testCoverageEnabled false
+            testCoverageEnabled true
         }
     }
     sourceSets {
@@ -106,4 +113,6 @@ dependencies {
     compile 'com.taobao.android.weex_inspection:urlconnection_interceptor:1.0.0'
     compile 'com.android.support.test.espresso:espresso-idling-resource:2.2.2'
     compile 'com.taobao.android:weex_inspector:0.11.0'
+//    compile group: 'org.jruby', name: 'jruby', version: '1.4.1+'
+    compile 'org.jacoco:org.jacoco.agent:0.7.9'
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/fcc7eec2/android/playground/app/src/main/AndroidManifest.xml
----------------------------------------------------------------------
diff --git a/android/playground/app/src/main/AndroidManifest.xml b/android/playground/app/src/main/AndroidManifest.xml
index dcc0aac..2809e11 100755
--- a/android/playground/app/src/main/AndroidManifest.xml
+++ b/android/playground/app/src/main/AndroidManifest.xml
@@ -47,6 +47,14 @@ under the License.
             tools:overrideLibrary="com.taobao.android.dexposed">
         <uses-library android:name="android.test.runner"/>
 
+        <receiver
+            android:name=".util.CoverageDataDumper"
+            tools:ignore="ExportedReceiver">
+            <intent-filter>
+                <action android:name="com.taobao.weex.DUMP_COVERAGE_DATA"/>
+            </intent-filter>
+        </receiver>
+
         <activity
                 android:name=".SplashActivity"
                 android:configChanges="orientation|keyboardHidden|screenSize"

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/fcc7eec2/android/playground/app/src/main/java/com/alibaba/weex/WXPageActivity.java
----------------------------------------------------------------------
diff --git a/android/playground/app/src/main/java/com/alibaba/weex/WXPageActivity.java b/android/playground/app/src/main/java/com/alibaba/weex/WXPageActivity.java
index fe5994d..dd303b5 100644
--- a/android/playground/app/src/main/java/com/alibaba/weex/WXPageActivity.java
+++ b/android/playground/app/src/main/java/com/alibaba/weex/WXPageActivity.java
@@ -53,6 +53,7 @@ import com.alibaba.weex.https.HotRefreshManager;
 import com.alibaba.weex.https.WXHttpManager;
 import com.alibaba.weex.https.WXHttpTask;
 import com.alibaba.weex.https.WXRequestListener;
+import com.alibaba.weex.util.JacocoCodeCoverage;
 import com.taobao.weex.IWXRenderListener;
 import com.taobao.weex.RenderContainer;
 import com.taobao.weex.WXSDKEngine;
@@ -319,6 +320,9 @@ public class WXPageActivity extends WXBaseActivity implements IWXRenderListener,
   @Override
   protected void onDestroy() {
     super.onDestroy();
+	//jacoco code coverage
+	JacocoCodeCoverage.dumpCodeCoverageByJacoco(getApplicationContext());
+
     if (mInstance != null) {
       mInstance.onActivityDestroy();
     }

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/fcc7eec2/android/playground/app/src/main/java/com/alibaba/weex/util/CoverageDataDumper.java
----------------------------------------------------------------------
diff --git a/android/playground/app/src/main/java/com/alibaba/weex/util/CoverageDataDumper.java
b/android/playground/app/src/main/java/com/alibaba/weex/util/CoverageDataDumper.java
new file mode 100644
index 0000000..adc0476
--- /dev/null
+++ b/android/playground/app/src/main/java/com/alibaba/weex/util/CoverageDataDumper.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+package com.alibaba.weex.util;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+
+import com.taobao.weex.utils.WXLogUtils;
+
+import java.io.File;
+
+public class CoverageDataDumper extends BroadcastReceiver {
+  @Override
+  public void onReceive(Context context, Intent intent) {
+//	JacocoCodeCoverage.dumpCodeCoverage(context);
+	JacocoCodeCoverage.dumpCodeCoverageByJacoco(context);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/fcc7eec2/android/playground/app/src/main/java/com/alibaba/weex/util/JacocoCodeCoverage.java
----------------------------------------------------------------------
diff --git a/android/playground/app/src/main/java/com/alibaba/weex/util/JacocoCodeCoverage.java
b/android/playground/app/src/main/java/com/alibaba/weex/util/JacocoCodeCoverage.java
new file mode 100644
index 0000000..faef7bb
--- /dev/null
+++ b/android/playground/app/src/main/java/com/alibaba/weex/util/JacocoCodeCoverage.java
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+package com.alibaba.weex.util;
+
+import android.content.Context;
+import com.taobao.weex.utils.WXLogUtils;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.reflect.InvocationTargetException;
+
+public class JacocoCodeCoverage {
+  public static final String TAG = "CoverageDataDumper";
+
+  public static void dumpCodeCoverage(Context context){
+
+	WXLogUtils.d( TAG, "CoverageDataDumper BroadcastReceiver " );
+
+	try {
+	  Class
+			  .forName( "com.vladium.emma.rt.RT" )
+			  .getMethod( "dumpCoverageData", File.class, boolean.class, boolean.class )
+			  .invoke( null,
+					  new File(context.getExternalFilesDir( null ) + "/coverage.ec" ),
+					  true, // merge
+					  false // stopDataCollection
+			  );
+	  WXLogUtils.d( TAG, "generateCoverageReport: ok! " +
+			  "file in [Android/data/com.alibaba.weex/files]" );
+	}
+
+	catch ( Exception e ) {
+	  WXLogUtils.e( TAG, e );
+	}
+  }
+
+  public static void dumpCodeCoverageByJacoco(Context context){
+
+	WXLogUtils.d(TAG, "generateCoverageReport()");
+
+	java.io.File coverageFile = new File(context.getExternalFilesDir( null ) + "/coverage.ec");
+	OutputStream out = null;
+	// We may use this if we want to avoid refecltion and we include
+	// emma.jar
+	//RT.dumpCoverageData(coverageFile, false, false);
+	// Use reflection to call emma dump coverage method, to avoid
+	// always statically compiling against emma jar
+	try {
+	  Object agent = Class.forName("org.jacoco.agent.rt.RT")
+			  .getMethod("getAgent")
+			  .invoke(null);
+	  out = new FileOutputStream(coverageFile,false);
+	  out.write((byte[]) agent.getClass().getMethod("getExecutionData", boolean.class)
+			  .invoke(agent, false));
+	  WXLogUtils.d( TAG, "generateCoverageReport: ok! " +
+			  "file in [Android/data/com.alibaba.weex/files]" );
+
+	} catch (ClassNotFoundException e) {
+	  reportJacocoError(e);
+	} catch (SecurityException e) {
+	  reportJacocoError(e);
+	} catch (NoSuchMethodException e) {
+	  reportJacocoError(e);
+	} catch (IllegalArgumentException e) {
+	  reportJacocoError(e);
+	} catch (IllegalAccessException e) {
+	  reportJacocoError(e);
+	} catch (InvocationTargetException e) {
+	  reportJacocoError(e);
+	} catch (FileNotFoundException e){
+	  reportJacocoError(e);
+	} catch (IOException e) {
+	  reportJacocoError(e);
+	} finally {
+	  if (out != null) {
+		try {
+		  out.close();
+		} catch (IOException e) {
+		  reportJacocoError(e);
+		}
+	  }
+	}
+  }
+
+  private static void reportJacocoError(Exception e) {
+	WXLogUtils.e(TAG, e.toString());
+  }
+}
+
+

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/fcc7eec2/android/sdk/build.gradle
----------------------------------------------------------------------
diff --git a/android/sdk/build.gradle b/android/sdk/build.gradle
index 0be69fb..a586241 100755
--- a/android/sdk/build.gradle
+++ b/android/sdk/build.gradle
@@ -4,7 +4,7 @@ buildscript {
     }
 
     dependencies {
-        classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.7.3'
+//        classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.7.3'
         classpath 'com.vanniktech:gradle-android-junit-jacoco-plugin:0.5.0'
     }
 }
@@ -15,9 +15,16 @@ plugins {
 
 apply plugin: 'com.android.library'
 apply plugin: 'checkstyle'
-apply plugin: 'com.getkeepsafe.dexcount'
+apply from: '../jacoco.gradle'
 
-ext.disableCov = project.hasProperty('disableCov') ? project.getProperty('disableCov') :
'false'
+//apply plugin: 'com.getkeepsafe.dexcount'
+//apply plugin: 'jacoco'
+//
+//jacoco {
+//    toolVersion = "0.7.9+"
+//}
+
+ext.disableCov = project.hasProperty('disableCov') ? project.getProperty('disableCov') :
'true'
 if(!disableCov.toBoolean()){
     apply plugin: 'com.vanniktech.android.junit.jacoco'
     junitJacoco {

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/fcc7eec2/android/sdk/coverage.ec
----------------------------------------------------------------------
diff --git a/android/sdk/coverage.ec b/android/sdk/coverage.ec
new file mode 100644
index 0000000..cc4c834
Binary files /dev/null and b/android/sdk/coverage.ec differ

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/fcc7eec2/android/weex_debug/build.gradle
----------------------------------------------------------------------
diff --git a/android/weex_debug/build.gradle b/android/weex_debug/build.gradle
index 32b59ab..2db7371 100644
--- a/android/weex_debug/build.gradle
+++ b/android/weex_debug/build.gradle
@@ -21,7 +21,7 @@ android {
             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
         }
         debug {
-            testCoverageEnabled true
+            testCoverageEnabled false
         }
     }
 }


Mime
View raw message