Skip to content

Commit

Permalink
Upgrade jackson 2.17.0 (#84)
Browse files Browse the repository at this point in the history
* Upgrade jackson to 2.17.0. Update CustomizedJSON code

* Upgrade to gradle 8.6, AGP to 8.4

* Update circle ci android orb and image

* Update sourceCompatibility to 1.8

* Use cimg/android for local test

* Fix store test result script

* Update mockito-android to 5.12.0
  • Loading branch information
tung-vu-td authored May 16, 2024
1 parent 19caec6 commit 6377dd2
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 78 deletions.
35 changes: 22 additions & 13 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
version: 2.1

orbs:
android: circleci/android@2.1.2
android: circleci/android@2.5.0

_defaults:
- &restore_gradle_cache
Expand Down Expand Up @@ -44,17 +44,26 @@ commands:
store_instrument_results:
description: "Store instrument test results"
steps:
- run:
name: Save test results
command: |
mkdir -p ~/test-results/junit/
find . -type f -regex ".*/build/outputs/androidTest-results/.*xml" -exec cp {} ~/test-results/junit/ \;
when: always
- store_test_results:
path: test-host/build/reports/androidTests/connected
path: ~/test-results
- run:
name: Compress Report
name: Compress Instrument Test Report
command: tar -cvf instrument-report.tar -C ./test-host/build/reports/androidTests/connected .
- store_artifacts:
path: instrument-report.tar
destination: instrument-report.tar
- run:
name: Compress test-result.pb
command: tar -cvf pb-report.tar -C test-host/build/outputs/androidTest-results/connected .
- store_artifacts:
path: test-host/build/outputs/androidTest-results/connected/test-result.pb
destination: test-result.pb
path: pb-report.tar
destination: pb-report.tar

run_instrument_tests:
description: "Run instrument tests"
Expand Down Expand Up @@ -83,15 +92,15 @@ commands:
jobs:
local_tests:
docker:
- image: circleci/android:api-30
- image: cimg/android:2024.04.1
steps:
- run_local_tests

instrument_tests_level_34:
executor:
name: android/android-machine
resource-class: large
tag: "2023.09.1"
tag: "2024.04.1"
steps:
- run_instrument_tests:
api_level: '34'
Expand All @@ -100,7 +109,7 @@ jobs:
executor:
name: android/android-machine
resource-class: large
tag: "2022.07.1"
tag: "2024.04.1"
steps:
- run_instrument_tests:
api_level: '33'
Expand All @@ -109,7 +118,7 @@ jobs:
executor:
name: android/android-machine
resource-class: large
tag: "2022.07.1"
tag: "2024.04.1"
steps:
- run_instrument_tests:
api_level: '32'
Expand All @@ -118,7 +127,7 @@ jobs:
executor:
name: android/android-machine
resource-class: large
tag: "2022.07.1"
tag: "2024.04.1"
steps:
- run_instrument_tests:
api_level: '31'
Expand All @@ -127,7 +136,7 @@ jobs:
executor:
name: android/android-machine
resource-class: large
tag: "2022.07.1"
tag: "2024.04.1"
steps:
- run_instrument_tests:
api_level: '30'
Expand All @@ -136,7 +145,7 @@ jobs:
executor:
name: android/android-machine
resource-class: large
tag: "2022.07.1"
tag: "2024.04.1"
steps:
- run_instrument_tests:
api_level: '29'
Expand All @@ -145,7 +154,7 @@ jobs:
executor:
name: android/android-machine
resource-class: large
tag: "2022.07.1"
tag: "2024.04.1"
steps:
- checkout
- android/start-emulator-and-run-tests:
Expand Down
23 changes: 17 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
buildscript {
repositories {
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.4.0'
}
}

plugins {
id 'java'
// id 'maven'
id 'maven-publish'
id 'signing'
}

group = 'com.treasuredata'
version = '1.0.0'
description = 'Android SDK for Treasure Data Cloud'
sourceCompatibility = '1.7'

java.sourceCompatibility = JavaVersion.VERSION_1_8
java.targetCompatibility = JavaVersion.VERSION_1_8

repositories {
mavenCentral()
Expand All @@ -18,14 +29,14 @@ repositories {

dependencies {
implementation 'org.komamitsu:android-logger-bridge:0.0.2'
implementation 'com.fasterxml.jackson.jr:jackson-jr-objects:2.6.3'
implementation 'com.fasterxml.jackson.jr:jackson-jr-objects:2.17.0'
implementation 'com.treasuredata:keen-client-java-core:3.0.0'

compileOnly 'com.google.android:android:4.1.1.4'

testImplementation 'com.google.android.gms:play-services-ads:17.1.1'
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:1.8.5'
// testImplementation 'com.google.android.gms:play-services-ads:23.0.0'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-core:5.3.1'
testImplementation 'com.squareup.okhttp3:mockwebserver:3.6.0'
testImplementation 'com.google.android:android:4.1.1.4'
}
Expand Down
18 changes: 9 additions & 9 deletions example/build.gradle
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
buildscript {
repositories {
jcenter()
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.2'
classpath 'com.android.tools.build:gradle:8.4.0'
}
}

apply plugin: 'com.android.application'

android {
compileSdkVersion 30

defaultConfig {
applicationId "com.treasuredata.android.demo"
minSdkVersion 14
targetSdkVersion 30
compileSdk 34
minSdkVersion 21
targetSdkVersion 34
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -28,6 +27,7 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
namespace 'com.treasuredata.android.demo'
}

repositories {
Expand All @@ -39,10 +39,10 @@ repositories {

dependencies {
implementation rootProject
implementation 'com.google.android.gms:play-services-ads:17.1.1'
implementation 'com.android.installreferrer:installreferrer:1.1'
implementation 'com.google.android.gms:play-services-ads:23.0.0'
implementation 'com.android.installreferrer:installreferrer:2.2'

testImplementation 'junit:junit:4.12'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'

}
7 changes: 5 additions & 2 deletions example/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.treasuredata.android.demo">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET"/>

Expand All @@ -20,6 +19,7 @@
android:banner="@drawable/banner">
<activity
android:name="com.treasuredata.android.demo.MainActivity"
android:exported="true"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -32,6 +32,9 @@
<meta-data
android:name="com.google.android.gms.ads.AD_MANAGER_APP"
android:value="true" />
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public class MainActivity extends Activity {
private static final String TAG = MainActivity.class.getSimpleName();
private String eventTable = "event_table";
private String eventDatabase = "event_db";
private String serverSideUploadTimestampColumn;
private String recordUUIDColumn;
private String aaidColumn;

Expand Down
4 changes: 4 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@
#Wed Feb 15 01:31:42 ICT 2023
android.useAndroidX=true
android.enableJetifier=true
#android.disableAutomaticComponentCreation=true
android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
android.useAndroidX=true
android.enableJetifier=true
56 changes: 20 additions & 36 deletions src/main/java/com/treasuredata/android/CustomizedJSON.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.fasterxml.jackson.core.TreeCodec;
import com.fasterxml.jackson.jr.ob.JSON;
import com.fasterxml.jackson.jr.ob.impl.JSONWriter;
import com.fasterxml.jackson.jr.ob.impl.TypeDetector;
import com.fasterxml.jackson.jr.ob.impl.ValueWriterLocator;

import java.io.IOException;
import java.text.SimpleDateFormat;
Expand All @@ -14,65 +14,49 @@ public class CustomizedJSON extends JSON {
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");

private static class CustomizedJSONWriter extends JSONWriter {
public CustomizedJSONWriter(int features, TypeDetector td, TreeCodec tc) {
super(features, td, tc);
public CustomizedJSONWriter()
{
super();
}

public CustomizedJSONWriter(CustomizedJSONWriter customizedJSONWriter, JsonGenerator jg)
protected CustomizedJSONWriter(CustomizedJSONWriter base, int features,
ValueWriterLocator loc, TreeCodec tc,
JsonGenerator g)
{
super(customizedJSONWriter, jg);
super(base, features, loc, tc, g);
}

private String getFormatedDate(Date date) {
private String getFormattedDate(Date date) {
String dateStr;
synchronized (SimpleDateFormat.class) {
dateStr = DATE_FORMAT.format(date);
}
return dateStr;
}

// Workaround of https://github.com/FasterXML/jackson-jr/pull/31
// Let's remove this override after it's merged.
@Override
public void writeField(String fieldName, Object value) throws IOException {
if (value == null) {
super.writeField(fieldName, null);
return;
}

int type = _typeDetector.findFullType(value.getClass());
switch (type) {
case TypeDetector.SER_UUID:
case TypeDetector.SER_URL:
case TypeDetector.SER_URI:
writeStringLikeField(fieldName, value.toString(), type);
return;
public JSONWriter perOperationInstance(int features,
ValueWriterLocator loc, TreeCodec tc,
JsonGenerator g)
{
if (getClass() != CustomizedJSONWriter.class) { // sanity check
throw new IllegalStateException("Sub-classes MUST override perOperationInstance(...)");
}
super.writeField(fieldName, value);
return new CustomizedJSONWriter(this, features, loc, tc, g);
}

@Override
protected void writeDateValue(Date v) throws IOException {
writeStringValue(getFormatedDate(v));
writeStringValue(getFormattedDate(v));
}

@Override
protected void writeDateField(String fieldName, Date v) throws IOException {
writeStringField(fieldName, getFormatedDate(v));
}

@Override
public JSONWriter perOperationInstance(JsonGenerator jg)
{
if (getClass() != CustomizedJSONWriter.class) { // sanity check
throw new IllegalStateException("Sub-classes MUST override perOperationInstance(...)");
}
return new CustomizedJSONWriter(this, jg);
writeStringField(fieldName, getFormattedDate(v));
}
}

@Override
protected JSONWriter _defaultWriter(int features, TreeCodec tc) {
return new CustomizedJSONWriter(features, TypeDetector.forWriter(features), tc);
protected JSONWriter _defaultWriter() {
return new CustomizedJSONWriter();
}
}
Loading

0 comments on commit 6377dd2

Please sign in to comment.