diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index a93ebe3..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,189 +0,0 @@ -# -# Copyright 2023 Adobe. All rights reserved. -# This file is licensed 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 REPRESENTATIONS -# OF ANY KIND, either express or implied. See the License for the specific language -# governing permissions and limitations under the License. -# - -version: 2.1 -orbs: - # Use the circleci android orb version that supports OpenJDK17 required by AGP 8.2+ - android: circleci/android@2.4.0 - codecov: codecov/codecov@4.0.1 - -parameters: - gradle-cache-prefix: - type: string - default: v1 - build-cache-prefix: - type: string - default: v1 - build-path: - type: string - default: "code/media/build" - -# Workflows orchestrate a set of jobs to be run; -workflows: - version: 2 - build-test-deploy: - jobs: - - validate-code - - build-and-unit-test: - requires: - - validate-code - - functional-test: - requires: - - validate-code - - build-test-app: - requires: - - validate-code - filters: - branches: - only: - - main - - staging - -jobs: - validate-code: - executor: - name: android/android-docker - resource-class: medium - tag: 2024.01.1 - - steps: - - checkout - - - android/restore-gradle-cache: - cache-prefix: << pipeline.parameters.gradle-cache-prefix >> - - - android/restore-build-cache: - cache-prefix: << pipeline.parameters.build-cache-prefix >> - - - run: - name: Check Format - command: make checkformat - - - run: - name: Check Style - command: make checkstyle - - - android/save-gradle-cache: - cache-prefix: << pipeline.parameters.gradle-cache-prefix >> - - - android/save-build-cache: - cache-prefix: << pipeline.parameters.build-cache-prefix >> - - - store_artifacts: - path: << pipeline.parameters.build-path >>/reports - - build-and-unit-test: - executor: - name: android/android-docker - resource-class: medium - tag: 2024.01.1 - - steps: - - checkout - - - android/restore-gradle-cache: - cache-prefix: << pipeline.parameters.gradle-cache-prefix >> - - - android/restore-build-cache: - cache-prefix: << pipeline.parameters.build-cache-prefix >> - - - run: - name: Javadoc - command: make javadoc - - - store_artifacts: - path: << pipeline.parameters.build-path >>/docs/javadoc - - - run: - name: Assemble Phone - command: make assemble-phone - - - android/run-tests: - test-command: make unit-test-coverage - - - android/save-gradle-cache: - cache-prefix: << pipeline.parameters.gradle-cache-prefix >> - - - android/save-build-cache: - cache-prefix: << pipeline.parameters.build-cache-prefix >> - - - store_artifacts: - path: << pipeline.parameters.build-path >>/reports/tests - - - store_test_results: - path: << pipeline.parameters.build-path >>/test-results/testPhoneDebugUnitTest - - - codecov/upload: - file: << pipeline.parameters.build-path >>/reports/coverage/test/phone/debug/report.xml - flags: unit-tests - - functional-test: - executor: - name: android/android-machine - resource-class: medium - tag: 2024.01.1 - - steps: - - checkout - - - android/restore-build-cache: - cache-prefix: << pipeline.parameters.build-cache-prefix >> - - - run: - name: List available emulator images - command: sdkmanager --list - - - android/start-emulator-and-run-tests: - # It should match the name seen in the "sdkmanager --list" output - system-image: system-images;android-29;default;x86 - # The command to be run, while waiting for emulator startup - post-emulator-launch-assemble-command: make assemble-phone - # The test command - test-command: make functional-test-coverage - restore-gradle-cache-prefix: << pipeline.parameters.gradle-cache-prefix >> - - - android/save-build-cache: - cache-prefix: << pipeline.parameters.build-cache-prefix >> - - - codecov/upload: - file: << pipeline.parameters.build-path >>/reports/coverage/androidTest/phone/debug/connected/report.xml - flags: functional-tests - - - store_artifacts: - path: << pipeline.parameters.build-path >>/reports/androidTests - - - store_test_results: - path: << pipeline.parameters.build-path >>/outputs/androidTest-results - - build-test-app: - executor: - name: android/android-docker - resource-class: medium - tag: 2024.01.1 - - steps: - - checkout - - - android/restore-gradle-cache: - cache-prefix: << pipeline.parameters.gradle-cache-prefix >> - - - android/restore-build-cache: - cache-prefix: << pipeline.parameters.build-cache-prefix >> - - - run: - name: Assemble App - command: make assemble-app - - - android/save-gradle-cache: - cache-prefix: << pipeline.parameters.gradle-cache-prefix >> - - android/save-build-cache: - cache-prefix: << pipeline.parameters.build-cache-prefix >> diff --git a/.github/release-drafter.yml b/.github/workflows/build-and-test.yml similarity index 55% rename from .github/release-drafter.yml rename to .github/workflows/build-and-test.yml index e053484..f6fb017 100644 --- a/.github/release-drafter.yml +++ b/.github/workflows/build-and-test.yml @@ -1,5 +1,5 @@ # -# Copyright 2024 Adobe. All rights reserved. +# Copyright 2025 Adobe. All rights reserved. # This file is licensed 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 @@ -10,7 +10,20 @@ # governing permissions and limitations under the License. # -template: | - ## What’s Changed +name: Build and Test - $CHANGES \ No newline at end of file +on: + pull_request: + +jobs: + build-and-test: + name: "CI" + uses: adobe/aepsdk-commons/.github/workflows/android-build-and-test.yml@gha-android-3.3.0 + with: + android-api-levels: '[29]' + run-test-unit: true + run-test-functional: true + run-build-app: true + enable-codecov: true + javadoc-build-path: code/media/build/dokka/javadoc + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/maven-release.yml b/.github/workflows/maven-release.yml index 3a95b8f..ca111de 100644 --- a/.github/workflows/maven-release.yml +++ b/.github/workflows/maven-release.yml @@ -11,66 +11,34 @@ # name: Publish Release + on: workflow_dispatch: inputs: tag: - description: 'tag/version' - required: true - - action_tag: - description: 'Create tag? ("no" to skip)' + description: 'The tag (version) to be released (ex: 1.2.3).' + type: string required: true - default: 'yes' -jobs: - publish: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Set up Java - uses: actions/setup-java@v3 - with: - distribution: 'zulu' - java-version: 17 - - name: Cache Gradle packages - uses: actions/cache@v2 - with: - path: ~/.gradle/caches - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} - restore-keys: ${{ runner.os }}-gradle - - - name: Verify version - run: | - set -eo pipefail - echo Release version: ${{ github.event.inputs.tag }} - (./scripts/version.sh -v ${{ github.event.inputs.tag }}) + create-github-release: + description: 'Create GitHub release using tag. If the provided `tag` does not exist, it will be created.' + type: boolean + required: true + default: true - - name: Create GH Release - id: create_release - uses: release-drafter/release-drafter@v5 - if: ${{ github.event.inputs.action_tag == 'yes' }} - with: - name: v${{ github.event.inputs.tag }} - tag: v${{ github.event.inputs.tag }} - version: v${{ github.event.inputs.tag }} - publish: true - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Import GPG key - env: - GPG_SECRET_KEYS: ${{ secrets.GPG_SECRET_KEYS }} - GPG_OWNERTRUST: ${{ secrets.GPG_OWNERTRUST }} - run: | - echo $GPG_SECRET_KEYS | base64 --decode | gpg --import --no-tty --batch --yes - echo $GPG_OWNERTRUST | base64 --decode | gpg --import-ownertrust --no-tty --batch --yes + core-dependency: + description: 'The Core dependency version in gradle.properties to be validated (ex: 1.2.3).' + type: string + required: true - - name: Publish to Maven Central Repository - run: make ci-publish - env: - SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} - SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} - GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} - GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }} +jobs: + publish: + permissions: + contents: write + uses: adobe/aepsdk-commons/.github/workflows/android-maven-release.yml@gha-android-3.3.0 + with: + tag: ${{ github.event.inputs.tag }} + create-github-release: ${{ github.event.inputs.create-github-release == 'true' }} + version-validation-paths: code/gradle.properties, code/media/src/phone/java/com/adobe/marketing/mobile/Media.java + version-validation-dependencies: Core ${{ github.event.inputs.core-dependency }} + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/maven-snapshot.yml b/.github/workflows/maven-snapshot.yml index 1a19c19..c0f398d 100644 --- a/.github/workflows/maven-snapshot.yml +++ b/.github/workflows/maven-snapshot.yml @@ -11,37 +11,13 @@ # name: Publish Snapshot -on: + +on: workflow_dispatch: jobs: publish: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Set up Java - uses: actions/setup-java@v3 - with: - distribution: 'zulu' - java-version: 17 - - name: Cache Gradle packages - uses: actions/cache@v2 - with: - path: ~/.gradle/caches - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} - restore-keys: ${{ runner.os }}-gradle - - name: Import GPG key - env: - GPG_SECRET_KEYS: ${{ secrets.GPG_SECRET_KEYS }} - GPG_OWNERTRUST: ${{ secrets.GPG_OWNERTRUST }} - run: | - echo $GPG_SECRET_KEYS | base64 --decode | gpg --import --no-tty --batch --yes - echo $GPG_OWNERTRUST | base64 --decode | gpg --import-ownertrust --no-tty --batch --yes - - name: Publish to Maven Snapshot Repository - run: make ci-publish-staging - env: - SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} - SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} - GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} - GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }} + permissions: + contents: write + uses: adobe/aepsdk-commons/.github/workflows/android-maven-snapshot.yml@gha-android-3.3.0 + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/update-version.yml b/.github/workflows/update-version.yml index 7bf5ba5..5394f1c 100644 --- a/.github/workflows/update-version.yml +++ b/.github/workflows/update-version.yml @@ -10,35 +10,38 @@ # governing permissions and limitations under the License. # -name: Update Version +name: Update Versions + on: workflow_dispatch: inputs: - version: - description: 'New version to use for the Media extension. Example: 3.0.0' + version: + description: 'New version to use for the extension (ex: 1.2.3).' + type: string + required: true + + branch: + description: 'The target branch where the version update will be applied and the pull request will be merged into.' + type: string required: true core-dependency: - description: '[Optional] Update Core dependency in pom.xml. Example: 3.0.0' + description: | + If a version is provided, update Core dependency in gradle.properties (ex: 1.2.3). + This is a published dependency in the pom.xml file. + type: string required: false + default: '' jobs: - update-version: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Update Versions - run: (./scripts/version.sh -u -v ${{ github.event.inputs.version }} -d "Core ${{ github.event.inputs.core-dependency }}") - - - name: Create Pull Request - uses: peter-evans/create-pull-request@v5 - with: - token: ${{ github.token }} - commit-message: Updating version to ${{ github.event.inputs.version }}. - branch: version-${{ github.event.inputs.version }}-update - delete-branch: true - title: Updating version to ${{ github.event.inputs.version }} - body: Updating version to ${{ github.event.inputs.version }} + update-versions: + permissions: + contents: write + pull-requests: write + uses: adobe/aepsdk-commons/.github/workflows/versions.yml@gha-android-3.3.0 + with: + version: ${{ github.event.inputs.version }} + branch: ${{ github.event.inputs.branch }} + dependencies: Core ${{ github.event.inputs.core-dependency }} + paths: code/gradle.properties, code/media/src/phone/java/com/adobe/marketing/mobile/Media.java + update: true diff --git a/Makefile b/Makefile index b6d839b..d01393a 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,9 @@ checkformat: (./code/gradlew -p code/$(EXTENSION-LIBRARY-FOLDER-NAME) spotlessCheck) (./code/gradlew -p code/$(TEST-APP-FOLDER-NAME) spotlessCheck) +# Used by build and test CI workflow +lint: checkstyle checkformat + format: (./code/gradlew -p code/$(EXTENSION-LIBRARY-FOLDER-NAME) spotlessApply) (./code/gradlew -p code/$(TEST-APP-FOLDER-NAME) spotlessApply) diff --git a/code/gradle.properties b/code/gradle.properties index 6785829..cc35815 100644 --- a/code/gradle.properties +++ b/code/gradle.properties @@ -15,7 +15,7 @@ android.injected.testOnly=false org.gradle.configureondemand=false moduleName=media -moduleVersion=3.1.0 +moduleVersion=3.1.1 mavenCoreVersion=3.0.0 mavenRepoName=AdobeMobileMediaSdk mavenRepoDescription=Android Analytics Extension for Audio and Video. diff --git a/code/media/src/main/java/com/adobe/marketing/mobile/media/internal/MediaDBServiceImpl.java b/code/media/src/main/java/com/adobe/marketing/mobile/media/internal/MediaDBServiceImpl.java index 55e9efe..7820cef 100644 --- a/code/media/src/main/java/com/adobe/marketing/mobile/media/internal/MediaDBServiceImpl.java +++ b/code/media/src/main/java/com/adobe/marketing/mobile/media/internal/MediaDBServiceImpl.java @@ -113,7 +113,7 @@ public List getHits(final String sessionID) { } List dbHits = database.getHits(sessionID); - if (dbHits == null || dbHits.size() == 0) { + if (dbHits == null || dbHits.isEmpty()) { return ret; } diff --git a/code/media/src/main/java/com/adobe/marketing/mobile/media/internal/MediaDatabase.java b/code/media/src/main/java/com/adobe/marketing/mobile/media/internal/MediaDatabase.java index d6ae0a7..93e659b 100644 --- a/code/media/src/main/java/com/adobe/marketing/mobile/media/internal/MediaDatabase.java +++ b/code/media/src/main/java/com/adobe/marketing/mobile/media/internal/MediaDatabase.java @@ -58,26 +58,27 @@ class MediaDatabase { Set getSessionIDs() { Set ret = new HashSet<>(); - SQLiteDatabase database = null; synchronized (dbMutex) { - try { - database = openDatabase(); - Cursor cursor = - database.query( - true, - MEDIA_TABLE_NAME, - new String[] {TB_KEY_SESSION_ID}, - null, - null, - null, - null, - null, - null); - if (cursor.moveToFirst()) { + try (SQLiteDatabase database = openDatabase(); + Cursor cursor = + database.query( + true, + MEDIA_TABLE_NAME, + new String[] {TB_KEY_SESSION_ID}, + null, + null, + null, + null, + null, + null)) { + + if (cursor != null && cursor.moveToFirst()) { + int sessionIdIndex = + cursor.getColumnIndexOrThrow(TB_KEY_SESSION_ID); // Cache column index + do { - ContentValues contentValues = new ContentValues(); - DatabaseUtils.cursorRowToContentValues(cursor, contentValues); - ret.add(contentValues.getAsString(TB_KEY_SESSION_ID)); + String sessionId = cursor.getString(sessionIdIndex); + ret.add(sessionId); } while (cursor.moveToNext()); } } catch (final SQLiteException e) { @@ -87,8 +88,6 @@ Set getSessionIDs() { "Error getting session ids from table (%s). Error: (%s)", MEDIA_TABLE_NAME, e.getLocalizedMessage()); - } finally { - closeDatabase(database); } } @@ -98,19 +97,18 @@ Set getSessionIDs() { List getHits(final String sessionID) { ArrayList ret = new ArrayList<>(); - SQLiteDatabase database = null; synchronized (dbMutex) { - try { - database = openDatabase(); - Cursor cursor = - database.query( - MEDIA_TABLE_NAME, - new String[] {TB_KEY_DATA}, - TB_KEY_SESSION_ID + "= ?", - new String[] {sessionID}, - null, - null, - "id ASC"); + try (SQLiteDatabase database = openDatabase(); + Cursor cursor = + database.query( + MEDIA_TABLE_NAME, + new String[] {TB_KEY_DATA}, + TB_KEY_SESSION_ID + "= ?", + new String[] {sessionID}, + null, + null, + "id ASC")) { + if (cursor.moveToFirst()) { do { ContentValues contentValues = new ContentValues(); @@ -122,11 +120,10 @@ List getHits(final String sessionID) { Log.warning( MediaInternalConstants.EXTENSION_LOG_TAG, LOG_TAG, - "Error getting session ids from table (%s). Error: (%s)", + "Error getting hits for session ID (%s) from table (%s). Error: (%s)", + sessionID, MEDIA_TABLE_NAME, e.getLocalizedMessage()); - } finally { - closeDatabase(database); } } diff --git a/code/media/src/main/java/com/adobe/marketing/mobile/media/internal/MediaOfflineService.java b/code/media/src/main/java/com/adobe/marketing/mobile/media/internal/MediaOfflineService.java index c2dc4d8..061133f 100644 --- a/code/media/src/main/java/com/adobe/marketing/mobile/media/internal/MediaOfflineService.java +++ b/code/media/src/main/java/com/adobe/marketing/mobile/media/internal/MediaOfflineService.java @@ -16,6 +16,7 @@ import com.adobe.marketing.mobile.services.Log; import com.adobe.marketing.mobile.services.NetworkRequest; import com.adobe.marketing.mobile.services.ServiceProvider; +import com.adobe.marketing.mobile.util.StringUtils; import java.util.*; class MediaOfflineService implements MediaHitProcessor { @@ -78,7 +79,7 @@ public void run() { }; flushTimer = new Timer(FLUSH_TIMER); - flushTimer.scheduleAtFixedRate(timerTask, 0, FLUSH_TIMER_INTERVAL_MS); + flushTimer.schedule(timerTask, 0, FLUSH_TIMER_INTERVAL_MS); } catch (Exception e) { Log.error( MediaInternalConstants.EXTENSION_LOG_TAG, @@ -278,7 +279,7 @@ boolean reportCompletedSessions() { url = MediaReportHelper.getTrackingURL(mediaState.getMediaCollectionServer()); body = MediaReportHelper.generateDownloadReport(mediaState, hits); - if (body == null || body.length() == 0) { + if (StringUtils.isNullOrEmpty(body)) { Log.warning( MediaInternalConstants.EXTENSION_LOG_TAG, LOG_TAG, @@ -295,7 +296,7 @@ boolean reportCompletedSessions() { return false; } - if (url == null || url.length() == 0) { + if (StringUtils.isNullOrEmpty(url)) { Log.warning( MediaInternalConstants.EXTENSION_LOG_TAG, LOG_TAG, @@ -321,6 +322,14 @@ boolean reportCompletedSessions() { // assuranceIntegrationId); // } + Log.trace( + MediaInternalConstants.EXTENSION_LOG_TAG, + LOG_TAG, + "reportCompletedSessions - Sending offline media request with url %s and \n" + + " body %s.", + url, + body); + NetworkRequest request = new NetworkRequest( url, diff --git a/code/media/src/main/java/com/adobe/marketing/mobile/media/internal/MediaRealTimeService.java b/code/media/src/main/java/com/adobe/marketing/mobile/media/internal/MediaRealTimeService.java index d01ef96..cff2e89 100644 --- a/code/media/src/main/java/com/adobe/marketing/mobile/media/internal/MediaRealTimeService.java +++ b/code/media/src/main/java/com/adobe/marketing/mobile/media/internal/MediaRealTimeService.java @@ -159,6 +159,17 @@ public void processHit(final String sessionId, final MediaHit hit) { "processHit - Session (%s) Queueing hit %s.", sessionId, hit.getEventType()); + + if (sessionObj == null) { + Log.trace( + MediaInternalConstants.EXTENSION_LOG_TAG, + LOG_TAG, + "processHit - Unable to process session with ID:(%s), session object is" + + " null.", + sessionId); + return; + } + sessionObj.queueHit(hit); } } diff --git a/code/media/src/main/java/com/adobe/marketing/mobile/media/internal/MediaReportHelper.java b/code/media/src/main/java/com/adobe/marketing/mobile/media/internal/MediaReportHelper.java index ca39ba6..06d7895 100644 --- a/code/media/src/main/java/com/adobe/marketing/mobile/media/internal/MediaReportHelper.java +++ b/code/media/src/main/java/com/adobe/marketing/mobile/media/internal/MediaReportHelper.java @@ -16,6 +16,7 @@ import com.adobe.marketing.mobile.services.DeviceInforming; import com.adobe.marketing.mobile.services.Log; import com.adobe.marketing.mobile.util.DataReader; +import com.adobe.marketing.mobile.util.StringUtils; import com.adobe.marketing.mobile.util.URLBuilder; import java.util.HashMap; import java.util.List; @@ -298,34 +299,34 @@ static ReturnTuple hasTrackingParams(final MediaState mediaState) { String mediaCollectionServer = mediaState.getMediaCollectionServer(); - if (mediaCollectionServer == null || mediaCollectionServer.length() == 0) { + if (StringUtils.isNullOrEmpty(mediaCollectionServer)) { return new ReturnTuple( false, MediaInternalConstants.Configuration.MEDIA_COLLECTION_SERVER); } String analyticsServer = mediaState.getAnalyticsTrackingServer(); - if (analyticsServer == null || analyticsServer.length() == 0) { + if (StringUtils.isNullOrEmpty(analyticsServer)) { return new ReturnTuple( false, MediaInternalConstants.Configuration.ANALYTICS_TRACKING_SERVER); } String analyticsRsid = mediaState.getAnalyticsRsid(); - if (analyticsRsid == null || analyticsRsid.length() == 0) { + if (StringUtils.isNullOrEmpty(analyticsRsid)) { return new ReturnTuple(false, MediaInternalConstants.Configuration.ANALYTICS_RSID); } String mcOrgId = mediaState.getMcOrgId(); - if (mcOrgId == null || mcOrgId.length() == 0) { + if (StringUtils.isNullOrEmpty(mcOrgId)) { return new ReturnTuple( false, MediaInternalConstants.Configuration.EXPERIENCE_CLOUD_ORGID); } String mcid = mediaState.getMcid(); - if (mcid == null || mcid.length() == 0) { + if (StringUtils.isNullOrEmpty(mcid)) { return new ReturnTuple(false, MediaInternalConstants.Identity.MARKETING_VISITOR_ID); } diff --git a/code/media/src/phone/java/com/adobe/marketing/mobile/Media.java b/code/media/src/phone/java/com/adobe/marketing/mobile/Media.java index 352a57e..80f9703 100644 --- a/code/media/src/phone/java/com/adobe/marketing/mobile/Media.java +++ b/code/media/src/phone/java/com/adobe/marketing/mobile/Media.java @@ -19,7 +19,7 @@ import org.jetbrains.annotations.Nullable; public class Media { - private static final String EXTENSION_VERSION = "3.1.0"; + private static final String EXTENSION_VERSION = "3.1.1"; private Media() {} diff --git a/scripts/version.sh b/scripts/version.sh deleted file mode 100755 index 09418d0..0000000 --- a/scripts/version.sh +++ /dev/null @@ -1,131 +0,0 @@ -#!/bin/bash - -# Make this script executable from terminal: -# chmod 755 version.sh -set -e # Any subsequent(*) commands which fail will cause the shell script to exit immediately - -ROOT_DIR=$(git rev-parse --show-toplevel) -LINE="================================================================================" -VERSION_REGEX="[0-9]+\.[0-9]+\.[0-9]+" - -GRADLE_PROPERTIES_FILE=$ROOT_DIR"/code/gradle.properties" -CONSTANTS_FILE=$ROOT_DIR"/code/media/src/phone/java/com/adobe/marketing/mobile/Media.java" -# Java files -EXTENSION_VERSION_REGEX="^.*String EXTENSION_VERSION *= *" -# Kotlin files -#EXTENSION_VERSION_REGEX="^ +const val VERSION *= *" - -help() -{ - echo "" - echo "Usage: $0 -v VERSION -d DEPENDENCIES" - echo "" - echo -e " -v\t- Version to update or verify for the extension. \n\t Example: 3.0.2\n" - echo -e " -d\t- Comma seperated dependecies to update along with their version. \n\t Example: "Core 3.1.1, Edge 3.2.1"\n" - echo -e " -u\t- Updates the version. If this flag is absent, the script verifies if the version is correct\n" - exit 1 # Exit script after printing help -} - -sed_platform() { - # Ensure sed works properly in linux and mac-os. - if [[ "$OSTYPE" == "darwin"* ]]; then - sed -i '' "$@" - else - sed -i "$@" - fi -} - -update() { - echo "Changing version to $VERSION" - - # Replace version in Constants file - echo "Changing 'EXTENSION_VERSION' to '$VERSION' in '$CONSTANTS_FILE'" - sed_platform -E "/$EXTENSION_VERSION_REGEX/{s/$VERSION_REGEX/$VERSION/;}" $CONSTANTS_FILE - - # Replace version in gradle.properties - echo "Changing 'moduleVersion' to '$VERSION' in '$GRADLE_PROPERTIES_FILE'" - sed_platform -E "/^moduleVersion/{s/$VERSION_REGEX/$VERSION/;}" $GRADLE_PROPERTIES_FILE - - # Replace dependencies in gradle.properties - if [ "$DEPENDENCIES" != "none" ]; then - IFS="," - dependenciesArray=($(echo "$DEPENDENCIES")) - - IFS=" " - for dependency in "${dependenciesArray[@]}"; do - dependencyArray=(${dependency// / }) - dependencyName=${dependencyArray[0]} - dependencyVersion=${dependencyArray[1]} - - if [ "$dependencyVersion" != "" ]; then - echo "Changing 'maven${dependencyName}Version' to '$dependencyVersion' in '$GRADLE_PROPERTIES_FILE'" - sed_platform -E "/^maven${dependencyName}Version/{s/$VERSION_REGEX/$dependencyVersion/;}" $GRADLE_PROPERTIES_FILE - fi - done - fi -} - -verify() { - echo "Verifing version is $VERSION" - - if ! grep -E "$EXTENSION_VERSION_REGEX\"$VERSION\"" "$CONSTANTS_FILE" >/dev/null; then - echo "'EXTENSION_VERSION' does not match '$VERSION' in '$CONSTANTS_FILE'" - exit 1 - fi - - if ! grep -E "^moduleVersion=.*$VERSION" "$GRADLE_PROPERTIES_FILE" >/dev/null; then - echo "'moduleVersion' does not match '$VERSION' in '$GRADLE_PROPERTIES_FILE'" - exit 1 - fi - - if [ "$DEPENDENCIES" != "none" ]; then - IFS="," - dependenciesArray=($(echo "$DEPENDENCIES")) - - IFS=" " - for dependency in "${dependenciesArray[@]}"; do - dependencyArray=(${dependency// / }) - dependencyName=${dependencyArray[0]} - dependencyVersion=${dependencyArray[1]} - - if [ "$dependencyVersion" != "" ]; then - if ! grep -E "^maven${dependencyName}Version=.*$dependencyVersion" "$GRADLE_PROPERTIES_FILE" >/dev/null; then - echo "maven${dependencyName}Version does not match '$dependencyVersion' in '$GRADLE_PROPERTIES_FILE'" - exit 1 - fi - fi - done - fi - - echo "Success" -} - - -while getopts "v:d:u" opt -do - case "$opt" in - v ) VERSION="$OPTARG" ;; - d ) DEPENDENCIES="$OPTARG" ;; - u ) UPDATE="true" ;; - ? ) help ;; # Print help in case parameter is non-existent - esac -done - -# Print help in case parameters are empty -if [ -z "$VERSION" ] -then - echo "********** USAGE ERROR **********" - echo "Some or all of the parameters are empty. See usage below:"; - help -fi - - - -echo "$LINE" -if [[ ${UPDATE} = "true" ]]; -then - update -else - verify -fi -echo "$LINE" \ No newline at end of file