diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 71cc5b37..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,104 +0,0 @@ -# -# Copyright 2024 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@3.2.4 - -jobs: - build-and-unit-test: - executor: - name: android/android-docker - resource-class: large - tag: 2024.01.1 - - steps: - - checkout - - - run: - name: Check format - command: make checkformat - - - run: - name: Check style - command: make checkstyle - - - run: - name: Javadoc - command: make javadoc - - - store_artifacts: - path: code/notificationbuilder/build/docs/javadoc - - - run: - name: Assemble phone - command: make assemble-phone - - - run: - name: Build Jitpack Library - command: make notificationbuilder-publish-maven-local-jitpack - - - run: - name: Build Test app - command: make assemble-app - - - run: - name: Run Unit tests - command: make unit-test-coverage - - - store_test_results: - path: code/notificationbuilder/build/test-results/testPhoneDebugUnitTest - - - codecov/upload: - file: code/notificationbuilder/build/reports/coverage/test/phone/debug/report.xml - flags: unit-tests - - - functional-test: - executor: - name: android/android-machine - resource-class: large - tag: 2024.01.1 - - steps: - - checkout - - - android/create-avd: - avd-name: myavd - install: true - system-image: system-images;android-29;default;x86 - - - android/start-emulator: - avd-name: myavd - no-window: true - post-emulator-launch-assemble-command: "" - restore-gradle-cache-prefix: v1a - - - run: - name: Run Functional tests - command: | - make functional-test-coverage - - - codecov/upload: - file: code/core/build/reports/coverage/androidTest/phone/connected/debug/report.xml - flags: functional-tests - - - android/save-gradle-cache: - cache-prefix: v1a - -workflows: - build: - jobs: - - build-and-unit-test - # - functional-test diff --git a/.github/release-drafter.yml b/.github/workflows/build-and-test.yml similarity index 54% rename from .github/release-drafter.yml rename to .github/workflows/build-and-test.yml index e053484e..879cb38b 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/notificationbuilder/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 23978656..a6a3a2e0 100644 --- a/.github/workflows/maven-release.yml +++ b/.github/workflows/maven-release.yml @@ -11,72 +11,41 @@ # name: Publish Release + on: workflow_dispatch: inputs: + tag: + description: 'The tag (version) to be released (ex: 1.2.3).' + type: string + required: true + + 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 + component: type: choice - description: UI Component to release + description: UI component which will be released. options: - notificationbuilder - - tag: - description: 'tag/version' - required: true - action_tag: - description: 'Create tag? ("no" to skip)' + core-dependency: + description: 'The Core dependency version in gradle.properties to be validated (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 -n ${{ github.event.inputs.component }} -v ${{ github.event.inputs.tag }}) - - - 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 }}-${{ github.event.inputs.component }} - tag: v${{ github.event.inputs.tag }}-${{ github.event.inputs.component }} - version: v${{ github.event.inputs.tag }}-${{ github.event.inputs.component }} - 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 - - - name: Publish to Maven Central Repository - run: make ${{ github.event.inputs.component }}-publish - 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-release.yml@gha-android-3.3.0 + with: + tag: ${{ github.event.inputs.tag }} + create-github-release: ${{ github.event.inputs.create-github-release == 'true' }} + release-variant: ${{ github.event.inputs.component }} + version-validation-paths: code/gradle.properties, code/notificationbuilder/src/main/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilder.kt + 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 85b45f0b..345d5c30 100644 --- a/.github/workflows/maven-snapshot.yml +++ b/.github/workflows/maven-snapshot.yml @@ -11,47 +11,21 @@ # name: Publish Snapshot -on: + +on: workflow_dispatch: inputs: - release_notificationbuilder: - required: false - type: boolean - default: false - description: Release Notification Builder + component: + type: choice + description: UI component for which a snapshot will be released. + options: + - notificationbuilder 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 NotificationBuilder to Maven Snapshot Repository - if: ${{ inputs.release_notificationbuilder }} - run: make notificationbuilder-publish-snapshot - 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 + with: + release-variant: ${{ github.event.inputs.component }} + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/update-version.yml b/.github/workflows/update-version.yml index 999a7547..b77f0d78 100644 --- a/.github/workflows/update-version.yml +++ b/.github/workflows/update-version.yml @@ -11,43 +11,37 @@ # name: Update Versions + on: workflow_dispatch: inputs: - notificationbuilder-version: - description: 'New version to use for the NotificationBuilder. Example: 3.0.0' - required: false + 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 - - - if: ${{ github.event.inputs.notificationbuilder-version != '' }} - name: Update NotificationBuilder version - run: (sh ./scripts/version.sh -u -n NotificationBuilder -v ${{ github.event.inputs.notificationbuilder-version }} -d "Core ${{ github.event.inputs.core-dependency }}") - - - name: Generate Commit Message - shell: bash - run: | - COMMIT_MSG="" - if [ "${{ github.event.inputs.notificationbuilder-version }}" ]; then - COMMIT_MSG="[NotificationBuilder-${{ github.event.inputs.notificationbuilder-version }}]" - fi - echo $COMMIT_MSG - echo COMMIT_MSG=$COMMIT_MSG >> $GITHUB_ENV - - - name: Create Pull Request - uses: peter-evans/create-pull-request@v5 - with: - delete-branch: true - commit-message: Update versions ${{ env.COMMIT_MSG }} - title: Update versions ${{ env.COMMIT_MSG }} - body: Update versions ${{ env.COMMIT_MSG }} \ No newline at end of file + 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/notificationbuilder/src/main/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilder.kt + update: true \ No newline at end of file diff --git a/Makefile b/Makefile index e82a5b52..4034da8a 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,9 @@ checkstyle: checkformat: (./code/gradlew -p code/notificationbuilder spotlessCheck) +# Used by build and test CI workflow +lint: checkformat checkstyle + format: (./code/gradlew -p code/notificationbuilder spotlessApply) @@ -41,5 +44,5 @@ notificationbuilder-publish-maven-local-jitpack: assemble-phone-release notificationbuilder-publish-snapshot: assemble-phone-release (./code/gradlew -p code/notificationbuilder publishReleasePublicationToSonatypeRepository) -notificationbuilder-publish: assemble-phone-release +notificationbuilder-publish-main: assemble-phone-release (./code/gradlew -p code/notificationbuilder publishReleasePublicationToSonatypeRepository -Prelease) diff --git a/code/gradle.properties b/code/gradle.properties index 08233f40..ec31ce4a 100644 --- a/code/gradle.properties +++ b/code/gradle.properties @@ -18,7 +18,7 @@ android.useAndroidX=true #Maven artifacts #Notification Builder Module notificationbuilderModuleName=notificationbuilder -notificationbuilderVersion=3.0.2 +notificationbuilderVersion=3.0.3 notificationbuilderMavenRepoName=AdobeMobileNotificationBuilderSdk notificationbuilderMavenRepoDescription=Android Notification Builder library for Adobe Mobile Marketing diff --git a/code/notificationbuilder/src/main/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilder.kt b/code/notificationbuilder/src/main/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilder.kt index a4959aa0..339b65a8 100644 --- a/code/notificationbuilder/src/main/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilder.kt +++ b/code/notificationbuilder/src/main/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilder.kt @@ -53,7 +53,7 @@ import com.adobe.marketing.mobile.services.ServiceProvider */ object NotificationBuilder { private const val SELF_TAG = "NotificationBuilder" - private const val VERSION = "3.0.2" + private const val VERSION = "3.0.3" @JvmStatic fun version(): String { diff --git a/code/notificationbuilder/src/main/java/com/adobe/marketing/mobile/notificationbuilder/internal/builders/InputBoxNotificationBuilder.kt b/code/notificationbuilder/src/main/java/com/adobe/marketing/mobile/notificationbuilder/internal/builders/InputBoxNotificationBuilder.kt index 02f2fa96..13486505 100644 --- a/code/notificationbuilder/src/main/java/com/adobe/marketing/mobile/notificationbuilder/internal/builders/InputBoxNotificationBuilder.kt +++ b/code/notificationbuilder/src/main/java/com/adobe/marketing/mobile/notificationbuilder/internal/builders/InputBoxNotificationBuilder.kt @@ -27,7 +27,7 @@ import com.adobe.marketing.mobile.notificationbuilder.PushTemplateConstants.LOG_ import com.adobe.marketing.mobile.notificationbuilder.PushTemplateConstants.PushPayloadKeys import com.adobe.marketing.mobile.notificationbuilder.R import com.adobe.marketing.mobile.notificationbuilder.internal.extensions.createNotificationChannelIfRequired -import com.adobe.marketing.mobile.notificationbuilder.internal.extensions.setRemoteImage +import com.adobe.marketing.mobile.notificationbuilder.internal.extensions.setRemoteViewImage import com.adobe.marketing.mobile.notificationbuilder.internal.templates.InputBoxPushTemplate import com.adobe.marketing.mobile.services.Log import java.util.Random @@ -74,7 +74,12 @@ internal object InputBoxNotificationBuilder { // get push payload data. if we are handling an intent then we know that we should be building a feedback received notification. val imageUri = if (pushTemplate.isFromIntent) pushTemplate.feedbackImage else pushTemplate.imageUrl - expandedLayout.setRemoteImage(imageUri, R.id.expanded_template_image) + + // set the image on the notification + expandedLayout.setRemoteViewImage( + imageUri, + R.id.expanded_template_image, + ) val expandedBodyText = if (pushTemplate.isFromIntent) pushTemplate.feedbackText else pushTemplate.expandedBodyText diff --git a/code/notificationbuilder/src/test/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilderTests.kt b/code/notificationbuilder/src/test/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilderTests.kt index 6007d30f..2ddafbf6 100644 --- a/code/notificationbuilder/src/test/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilderTests.kt +++ b/code/notificationbuilder/src/test/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilderTests.kt @@ -118,7 +118,7 @@ class NotificationBuilderTests { fun `NotificationBuilder version values matches the expected version`() { val version = NotificationBuilder.version() - assertEquals("3.0.2", version) + assertEquals("3.0.3", version) } @Test diff --git a/code/notificationbuilder/src/test/java/com/adobe/marketing/mobile/notificationbuilder/internal/builders/BasicNotificationBuilderTest.kt b/code/notificationbuilder/src/test/java/com/adobe/marketing/mobile/notificationbuilder/internal/builders/BasicNotificationBuilderTest.kt index e2a3414a..4789a5d9 100644 --- a/code/notificationbuilder/src/test/java/com/adobe/marketing/mobile/notificationbuilder/internal/builders/BasicNotificationBuilderTest.kt +++ b/code/notificationbuilder/src/test/java/com/adobe/marketing/mobile/notificationbuilder/internal/builders/BasicNotificationBuilderTest.kt @@ -101,6 +101,20 @@ class BasicNotificationBuilderTest { verify(exactly = 1) { any().setRemoteViewImage(MOCKED_IMAGE_URI, R.id.expanded_template_image) } } + @Test + fun `construct should return a NotificationCompat Builder when push template has required data only`() { + val pushTemplate = provideMockedBasicPushTemplateWithRequiredData() + val notificationBuilder = BasicNotificationBuilder.construct( + context, + pushTemplate, + trackerActivityClass, + broadcastReceiverClass + ) + + assertEquals(NotificationCompat.Builder::class.java, notificationBuilder.javaClass) + verify(exactly = 0) { any().setRemoteViewImage(MOCKED_IMAGE_URI, R.id.expanded_template_image) } + } + @Config(sdk = [23]) @Test fun `construct should use the api23 expanded layout for API level below 24`() { diff --git a/code/notificationbuilder/src/test/java/com/adobe/marketing/mobile/notificationbuilder/internal/builders/InputBoxNotificationBuilderTest.kt b/code/notificationbuilder/src/test/java/com/adobe/marketing/mobile/notificationbuilder/internal/builders/InputBoxNotificationBuilderTest.kt index 5839a983..6e988838 100644 --- a/code/notificationbuilder/src/test/java/com/adobe/marketing/mobile/notificationbuilder/internal/builders/InputBoxNotificationBuilderTest.kt +++ b/code/notificationbuilder/src/test/java/com/adobe/marketing/mobile/notificationbuilder/internal/builders/InputBoxNotificationBuilderTest.kt @@ -20,7 +20,7 @@ import androidx.core.app.NotificationCompat import com.adobe.marketing.mobile.notificationbuilder.NotificationConstructionFailedException import com.adobe.marketing.mobile.notificationbuilder.PushTemplateConstants import com.adobe.marketing.mobile.notificationbuilder.R -import com.adobe.marketing.mobile.notificationbuilder.internal.extensions.setRemoteImage +import com.adobe.marketing.mobile.notificationbuilder.internal.extensions.setRemoteViewImage import com.adobe.marketing.mobile.notificationbuilder.internal.templates.InputBoxPushTemplate import com.adobe.marketing.mobile.notificationbuilder.internal.templates.MOCKED_BASIC_TEMPLATE_BODY import com.adobe.marketing.mobile.notificationbuilder.internal.templates.MOCKED_BASIC_TEMPLATE_BODY_EXPANDED @@ -41,6 +41,7 @@ import io.mockk.Runs import io.mockk.every import io.mockk.just import io.mockk.mockkConstructor +import io.mockk.mockkStatic import io.mockk.unmockkAll import io.mockk.verify import org.junit.After @@ -74,6 +75,7 @@ class InputBoxNotificationBuilderTest { trackerActivityClass = DummyActivity::class.java broadcastReceiverClass = DummyBroadcastReceiver::class.java mockkConstructor(RemoteViews::class) + mockkStatic(RemoteViews::setRemoteViewImage) } @After @@ -93,6 +95,7 @@ class InputBoxNotificationBuilderTest { assertNotNull(notificationBuilder) assertEquals(NotificationCompat.Builder::class.java, notificationBuilder.javaClass) + verify(exactly = 0) { any().setRemoteViewImage(MOCKED_IMAGE_URI, R.id.expanded_template_image) } } @Test(expected = NotificationConstructionFailedException::class) @@ -265,7 +268,7 @@ class InputBoxNotificationBuilderTest { broadcastReceiverClass ) - verify { anyConstructed().setRemoteImage(MOCKED_FEEDBACK_IMAGE, R.id.expanded_template_image) } + verify(exactly = 1) { any().setRemoteViewImage(MOCKED_FEEDBACK_IMAGE, R.id.expanded_template_image) } verify { anyConstructed().setTextViewText(R.id.notification_body, MOCKED_FEEDBACK_TEXT) } verify { anyConstructed().setTextViewText(R.id.notification_body_expanded, MOCKED_FEEDBACK_TEXT) } } @@ -282,7 +285,7 @@ class InputBoxNotificationBuilderTest { broadcastReceiverClass ) - verify { anyConstructed().setRemoteImage(MOCKED_IMAGE_URI, R.id.expanded_template_image) } + verify(exactly = 1) { any().setRemoteViewImage(MOCKED_IMAGE_URI, R.id.expanded_template_image) } verify { anyConstructed().setTextViewText(R.id.notification_body, MOCKED_BASIC_TEMPLATE_BODY) } verify { anyConstructed().setTextViewText(R.id.notification_body_expanded, MOCKED_BASIC_TEMPLATE_BODY_EXPANDED) } } diff --git a/scripts/version.sh b/scripts/version.sh deleted file mode 100755 index 903f14e8..00000000 --- a/scripts/version.sh +++ /dev/null @@ -1,137 +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" - -# NotificationBuilder files -NOTIFICATIONBUILDER_CONSTANTFILE=$ROOT_DIR"/code/notificationbuilder/src/main/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilder.kt" -NOTIFICATIONBUILDER_CONSTANTFILE_VERSION_REGEX="^ +private const val VERSION *= *" - -help() -{ - echo "" - echo "Usage: $0 -n COMPONENT_NAME -v VERSION -d DEPENDENCIES" - echo "" - echo -e " -v\t- Version to update or verify for the component. \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 $NAME version to $VERSION" - - # Replace version in Constants file - echo "Changing 'VERSION' to '$VERSION' in '$CONSTANTS_FILE'" - sed_platform -E "/$CONSTANTS_FILE_VERSION_REGEX/{s/$VERSION_REGEX/$VERSION/;}" $CONSTANTS_FILE - - # Replace version in gradle.properties - echo "Changing $GRADLE_TAG to '$VERSION' in '$GRADLE_PROPERTIES_FILE'" - sed_platform -E "/^$GRADLE_TAG/{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 $NAME version is $VERSION" - - if ! grep -E "$CONSTANTS_FILE_VERSION_REGEX\"$VERSION\"" "$CONSTANTS_FILE" >/dev/null; then - echo "'VERSION' does not match '$VERSION' in '$CONSTANTS_FILE'" - exit 1 - fi - - if ! grep -E "^$GRADLE_TAG=.*$VERSION" "$GRADLE_PROPERTIES_FILE" >/dev/null; then - echo "'version' 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 "n:v:d:u" opt -do - case "$opt" in - n ) NAME="$OPTARG" ;; - 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 "$NAME" ] || [ -z "$VERSION" ] -then - echo "********** USAGE ERROR **********" - echo "Some or all of the parameters are empty. See usage below:"; - help -fi - - -NAME_LC=$(echo "$NAME" | tr '[:upper:]' '[:lower:]') -NAME_UC=$(echo "$NAME" | tr '[:lower:]' '[:upper:]') - -eval CONSTANTS_FILE=\$$"$NAME_UC"_CONSTANTFILE -eval CONSTANTS_FILE_VERSION_REGEX=\$$"$NAME_UC"_CONSTANTFILE_VERSION_REGEX -GRADLE_TAG="$NAME_LC"Version - -echo "$LINE" -if [[ ${UPDATE} = "true" ]]; -then - update -else - verify -fi -echo "$LINE"