Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include code format tools #37

Merged
merged 13 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,32 @@ workflows:
version: 2
build-test-deploy:
jobs:
- build-and-unit-test
- functional-test
- validate-code
- build-and-unit-test:
requires:
- validate-code
- functional-test:
requires:
- validate-code

jobs:
validate-code:
working_directory: ~/code
docker:
- image: circleci/android:api-29-node
environment:
JVM_OPTS: -Xmx3200m
steps:
- checkout

- run:
name: Check Code Format
command: make format-check

build-and-unit-test:
working_directory: ~/code
docker:
- image: circleci/android:api-29
- image: circleci/android:api-29-node
environment:
JVM_OPTS: -Xmx3200m
steps:
Expand Down
5 changes: 5 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

make format
git diff --cached --name-only --diff-filter=d | while read filename; do git add "$filename"; done

14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
EXTENSION-LIBRARY-FOLDER-NAME = edgeconsent
TEST-APP-FOLDER-NAME = app

BUILD-ASSEMBLE-LOCATION = ./ci/assemble
ROOT_DIR=$(shell git rev-parse --show-toplevel)
Expand All @@ -10,6 +11,17 @@ LIB_VERSION = $(shell cat $(ROOT_DIR)/code/gradle.properties | grep "moduleVersi
SOURCE_FILE_DIR = $(ROOT_DIR)/code/$(PROJECT_NAME)
AAR_FILE_DIR = $(ROOT_DIR)/code/$(PROJECT_NAME)/build/outputs/aar

init:
git config core.hooksPath .githooks

format:
(./code/gradlew -p code/$(EXTENSION-LIBRARY-FOLDER-NAME) spotlessApply)
(./code/gradlew -p code/$(TEST-APP-FOLDER-NAME) spotlessApply)

format-check:
(./code/gradlew -p code/$(EXTENSION-LIBRARY-FOLDER-NAME) spotlessCheck)
(./code/gradlew -p code/$(TEST-APP-FOLDER-NAME) spotlessCheck)

create-ci: clean
(mkdir -p ci)

Expand All @@ -27,7 +39,7 @@ ci-build: create-ci
(cp -r ./code/$(EXTENSION-LIBRARY-FOLDER-NAME)/build $(BUILD-ASSEMBLE-LOCATION))

ci-build-app:
(./code/gradlew -p code/app assemble)
(./code/gradlew -p code/$(TEST-APP-FOLDER-NAME) assemble)

ci-unit-test: create-ci
(mkdir -p ci/unit-test)
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,16 @@ Note: replace ADD_YOUR_SESSION_ID_HERE with your Assurance session identifier.

Once the connection is established and the events list starts getting populated, you can filter the Edge Consent extension events by typing `Consent` in the `Search Events` search box.

### Code Format

This project uses the code formatting tools [Spotless](https://github.com/diffplug/spotless/tree/main/plugin-gradle) with [Prettier](https://prettier.io/). Formatting is applied when the project is built from Gradle and is checked when changes are submitted to the CI build system.

Prettier requires [Node version](https://nodejs.org/en/download/releases/) 10+

To enable the Git pre-commit hook to apply code formatting on each commit, run the following to update the project's git config `core.hooksPath`:
```
make init
```

## Related Projects

Expand Down
13 changes: 13 additions & 0 deletions code/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
apply plugin: 'com.android.application'
apply plugin: "com.diffplug.spotless"

spotless {
java {
toggleOffOn("format:off", "format:on")
target "src/*/java/**/*.java"
removeUnusedImports()
prettier(['prettier': rootProject.ext.prettierVersion, 'prettier-plugin-java': rootProject.ext.prettierPluginJavaVersion])
.config(['parser': 'java', 'tabWidth': 4, 'useTabs': true, 'printWidth': 120])
endWithNewline()
licenseHeaderFile "../../config/formatter/adobe.header.txt"
}
}

android {
compileSdkVersion 30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@

import android.app.Application;
import android.util.Log;

import com.adobe.marketing.mobile.edge.consent.Consent;
import com.adobe.marketing.mobile.AdobeCallback;
import com.adobe.marketing.mobile.Assurance;
import com.adobe.marketing.mobile.Edge;
import com.adobe.marketing.mobile.LoggingMode;
import com.adobe.marketing.mobile.MobileCore;
import com.adobe.marketing.mobile.edge.consent.Consent;

public class ConsentTestApplication extends Application {

private static final String LOG_TAG = "ConsentTestApplication";

// TODO: fill in your Launch environment ID here
Expand All @@ -41,18 +41,19 @@ public void onCreate() {
*/
MobileCore.configureWithAppID(LAUNCH_ENVIRONMENT_ID);

// register AEP Mobile extensions
Consent.registerExtension();
Edge.registerExtension();
Assurance.registerExtension();
// register AEP Mobile extensions
Consent.registerExtension();
Edge.registerExtension();
Assurance.registerExtension();

// once all the extensions are registered, call MobileCore.start(...) to start processing the events
MobileCore.start(new AdobeCallback() {
@Override
public void call(final Object o) {
Log.d(LOG_TAG, "Mobile SDK was initialized");
MobileCore.start(
new AdobeCallback() {
@Override
public void call(final Object o) {
Log.d(LOG_TAG, "Mobile SDK was initialized");
}
}
});
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@
*/

package com.adobe.marketing.mobile.consentTestApp;
import android.util.Log;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import com.adobe.marketing.mobile.AdobeCallbackWithError;
import com.adobe.marketing.mobile.AdobeError;
import com.adobe.marketing.mobile.edge.consent.Consent;

import java.util.HashMap;
import java.util.Map;

Expand All @@ -30,58 +28,70 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

}

// Implement the OnClickListener callback
public void btnCollectNoClicked(View v) {
Map<String, Object> consents = new HashMap<String, Object>() {
final Map<String, String> collectValue = new HashMap<String, String>() {
{
put("val", "n");
}
};

final Map<String, Object> consentCollect = new HashMap<String, Object>() {
{
put("collect", collectValue);
}
};

final Map<String, Object> consents = new HashMap<String, Object>() {
{
put("consents", new HashMap<String, Object>() {
{
put("collect", new HashMap<String, String>() {
{
put("val", "n");
}
});
}
});
put("consents", consentCollect);
}
};

Consent.update(consents);
}

public void btnCollectYESClicked(View v) {
Map<String, Object> consents = new HashMap<String, Object>() {
final Map<String, String> collectValue = new HashMap<String, String>() {
{
put("val", "y");
}
};

final Map<String, Object> consentCollect = new HashMap<String, Object>() {
{
put("consents", new HashMap<String, Object>() {
{
put("collect", new HashMap<String, String>() {
{
put("val", "y");
}
});
}
});
put("collect", collectValue);
}
};

final Map<String, Object> consents = new HashMap<String, Object>() {
{
put("consents", consentCollect);
}
};

Consent.update(consents);
}

public void btnGetConsentsClicked(View v) {
final TextView txtViewConsents = (TextView) findViewById(R.id.txtViewConsents);
Consent.getConsents(new AdobeCallbackWithError<Map<String, Object>>() {
@Override
public void call(Map<String, Object> consents) {
txtViewConsents.setText(consents.toString());
}
Consent.getConsents(
new AdobeCallbackWithError<Map<String, Object>>() {
@Override
public void call(Map<String, Object> consents) {
txtViewConsents.setText(consents.toString());
}

@Override
public void fail(AdobeError adobeError) {
Log.d(this.getClass().getName(), String.format("GetConsents failed with error - %s", adobeError.getErrorName()));
@Override
public void fail(AdobeError adobeError) {
Log.d(
this.getClass().getName(),
String.format("GetConsents failed with error - %s", adobeError.getErrorName())
);
}
}
});
);
}


}
5 changes: 5 additions & 0 deletions code/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ buildscript {
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.1"
classpath "com.diffplug.spotless:spotless-plugin-gradle:5.12.5"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down Expand Up @@ -45,4 +46,8 @@ ext {
buildToolsVersion = "29.0.3"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
jacocoVersion = "0.8.5"

// spotless config
prettierVersion = "2.3.0"
prettierPluginJavaVersion = "1.1.0"
}
15 changes: 15 additions & 0 deletions code/edgeconsent/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,26 @@ apply plugin: 'com.android.library'
apply plugin: 'jacoco'
apply plugin: 'maven-publish'
apply plugin: 'signing'
apply plugin: "com.diffplug.spotless"

jacoco {
toolVersion = rootProject.ext.jacocoVersion
}

preBuild.dependsOn spotlessApply

spotless {
java {
toggleOffOn("format:off", "format:on")
target "src/*/java/**/*.java"
removeUnusedImports()
prettier(['prettier': rootProject.ext.prettierVersion, 'prettier-plugin-java': rootProject.ext.prettierPluginJavaVersion])
.config(['parser': 'java', 'tabWidth': 4, 'useTabs': true, 'printWidth': 120])
endWithNewline()
licenseHeaderFile "../../config/formatter/adobe.header.txt"
}
}

android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.concurrent.atomic.AtomicInteger;

public class ADBCountDownLatch {

private final CountDownLatch latch;
private final int initialCount;
private final AtomicInteger currentCount;
Expand Down Expand Up @@ -55,5 +56,4 @@ public int getCurrentCount() {
public String toString() {
return String.format("%s, initial: %d, current: %d", latch.toString(), initialCount, currentCount.get());
}

}
Loading