From add44bd7865cacd26fd389f15b8235433fc852dc Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 30 Nov 2023 17:42:57 +0530 Subject: [PATCH] Null issue fixed and removed secret credentials --- build.gradle | 6 +- contentstack/build.gradle | 204 +++++++++++++++--- .../com/contentstack/sdk/AssetsModel.java | 2 +- .../contentstack/sdk/CSHttpConnection.java | 5 +- .../java/com/contentstack/sdk/Config.java | 27 ++- .../com/contentstack/sdk/Contentstack.java | 7 +- .../main/java/com/contentstack/sdk/Stack.java | 4 +- .../com/contentstack/sdk/TestActivity.java | 19 +- progaurd-rules.pro | 1 + scripts/publish-module.gradle | 5 +- scripts/publish-root.gradle | 32 +-- 11 files changed, 241 insertions(+), 71 deletions(-) create mode 100644 progaurd-rules.pro diff --git a/build.gradle b/build.gradle index 4fffe10f..626364a5 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,10 @@ buildscript { ext.jacoco_version = '0.8.8' repositories { - maven { url "https://plugins.gradle.org/m2/" } + maven { + url = uri("https://storage.googleapis.com/r8-releases/raw") + url "https://plugins.gradle.org/m2/" + } google() mavenCentral() } @@ -10,6 +13,7 @@ buildscript { classpath "com.android.tools.build:gradle:7.2.2" //7.0.4 classpath 'io.github.gradle-nexus:publish-plugin:1.1.0' classpath "org.jacoco:org.jacoco.core:$jacoco_version" + classpath "com.android.tools:r8:8.1.56" } } diff --git a/contentstack/build.gradle b/contentstack/build.gradle index c086f8d9..f85e7c28 100755 --- a/contentstack/build.gradle +++ b/contentstack/build.gradle @@ -1,48 +1,200 @@ -apply plugin: 'com.android.library' -apply plugin: 'jacoco' +plugins { + id 'signing' + id 'maven-publish' + id 'com.android.library' + id 'jacoco' +} + +def localProperties = new Properties() +localProperties.load(new FileInputStream(rootProject.file("local.properties"))) + +group = 'com.contentstack.sdk' +version = '3.12.4-SNAPSHOT' + + +//publishing { +// publications { +// mavenJava(MavenPublication) { +// artifactId = 'android' +// versionMapping { +// usage('java-api') { +// fromResolutionOf('runtimeClasspath') +// } +// usage('java-runtime') { +// fromResolutionResult() +// } +// } +// pom { +// +// name = 'contentstack-android' +// packaging 'aar' +// artifactId "android" +// description = 'Android SDK for Contentstack Content Delivery API, Contentstack is a headless CMS with an API-first approach' +// url = 'https://github.com/contentstack/contentstack-android' +// +// scm { +// url 'https://github.com/contentstack/contentstack-android/' +// connection 'scm:git@github.com:contentstack/contentstack-android' +// developerConnection 'scm:git@github.com:contentstack/contentstack-android.git' +// } +// +// licenses { +// license { +// name 'The MIT License' +// url 'http://www.opensource.org/licenses/mit-license.php' +// distribution 'repo' +// } +// } +// developers { +// developer { +// id 'ishaileshmishra' +// name 'Shailesh Mishra' +// email 'mobile@contentstack.com' +// } +// } +// } +// } +// } +// repositories { +// maven { +// def releasesRepoUrl = layout.buildDirectory.dir('repos/releases') +// def snapshotsRepoUrl = layout.buildDirectory.dir('repos/snapshots') +// url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl +// } +// } +//} -apply from: "${rootProject.projectDir}/scripts/publish-module.gradle" +//signing { +// sign publishing.publications.mavenJava +//} + + +//javadoc { +// if (JavaVersion.current().isJava9Compatible()) { +// options.addBooleanOption('html5', true) +// } +//} + + +tasks.register('jacocoTestReport', JacocoReport) { +// dependsOn['testDebugUnitTest', 'createDebugCoverageReport'] + reports { + html.enabled = true + } +// afterEvaluate { +// classDirectories.setFrom(files(classDirectories.files.collect { +// fileTree(dir: it, exclude: '**com/contentstack/okhttp**') +// fileTree(dir: it, exclude: '**com/contentstack/okio**') +// fileTree(dir: it, exclude: '**com/contentstack/txtmark**') +// })) +// } +} android { - compileSdk 33 + packagingOptions { + exclude 'META-INF/DEPENDENCIES' + exclude 'META-INF/LICENSE.md' + exclude 'META-INF/LICENSE-notice.md' + exclude 'META-INF/license.txt' + exclude 'META-INF/NOTICE' + exclude 'META-INF/NOTICE.txt' + exclude 'META-INF/notice.txt' + exclude 'META-INF/ASL2.0' + exclude("META-INF/*.kotlin_module") + } + testOptions { + unitTests.all { + jacoco { + includeNoLocationClasses = true + } + } + } + signingConfigs { + debug { + storeFile file("/Users/shaileshmishra/keystore/release.keystore") + storePassword 'android' + keyAlias 'androiddebugkey' + keyPassword 'android' + } + release { + storeFile file("/Users/shaileshmishra/keystore/release.keystore") + storePassword 'android' + keyAlias 'androiddebugkey' + keyPassword 'android' + } + } + compileSdk 26 defaultConfig { - minSdk 19 - targetSdk 33 + minSdkVersion 19 versionCode 1 versionName "1.0" - multiDexEnabled true - vectorDrawables.useSupportLibrary = true - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - signingConfig signingConfigs.debug + useLibrary 'org.apache.http.legacy' + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + signingConfig signingConfigs.release } + buildTypes { - def localProperties = new Properties() - localProperties.load(new FileInputStream(rootProject.file("local.properties"))) + debug { + debuggable true + testCoverageEnabled true + buildConfigField "String", "host", localProperties['host'] + buildConfigField "String", "APIKey", localProperties['APIKey'] + buildConfigField "String", "deliveryToken", localProperties['deliveryToken'] + buildConfigField "String", "environment", localProperties['env'] + buildConfigField "String", "contentTypeUID", localProperties['contentType'] + buildConfigField "String", "assetUID", localProperties['assetUid'] + } + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } } + flavorDimensions "default" + lintOptions { abortOnError false } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } - - testOptions { - unitTests.all { - jacoco { - includeNoLocationClasses = true - } - } - unitTests.returnDefaultValues = true - } } +repositories { +// flatDir { dirs 'libs' } +// mavenCentral() +// mavenLocal() +} + +configurations { archives } dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'androidx.appcompat:appcompat:1.6.1' + configurations.configureEach { resolutionStrategy.force 'com.android.support:support-annotations:23.1.0' } + implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation 'com.contentstack.sdk:utils:1.2.6' +// implementation 'com.android.support:appcompat-v7:26.1.0' +// implementation 'com.android.support:support-v4:26.1.0' implementation 'com.android.volley:volley:1.2.1' - implementation 'androidx.test:core:1.5.0' + implementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test.ext:junit:1.1.5' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' + androidTestImplementation 'androidx.test:core:1.5.0' + coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4' + + androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.2', { + exclude group: 'com.android.support', module: 'support-annotations' + }) +} +tasks.register('clearJar', Delete) { delete 'build/libs/Contentstack.jar' } +tasks.register('unzip', Copy) { + def zipFile = file('build/intermediates/intermediate-jars/release/classes.jar') + def outputDir = file("${buildDir}/contentstack-jar") + from zipTree(zipFile) + into outputDir } +tasks.register('createJar', Jar) { + archivesBaseName = "contentstack.jar" + from('build/contentstack-jar/') + include 'com/contentstack/' + include 'META-INF/' +} +createJar.dependsOn(clearJar, unzip, build) + java { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 diff --git a/contentstack/src/main/java/com/contentstack/sdk/AssetsModel.java b/contentstack/src/main/java/com/contentstack/sdk/AssetsModel.java index 1ba82a22..ad68003b 100644 --- a/contentstack/src/main/java/com/contentstack/sdk/AssetsModel.java +++ b/contentstack/src/main/java/com/contentstack/sdk/AssetsModel.java @@ -11,7 +11,7 @@ */ class AssetsModel { - List objects = new ArrayList(); + List objects = new ArrayList<>(); public AssetsModel(JSONObject jsonObject, boolean isFromCache) { jsonObject = !isFromCache && jsonObject.opt("response") == null ? jsonObject : jsonObject.optJSONObject("response"); diff --git a/contentstack/src/main/java/com/contentstack/sdk/CSHttpConnection.java b/contentstack/src/main/java/com/contentstack/sdk/CSHttpConnection.java index 73f8d3a0..cc87e7b1 100755 --- a/contentstack/src/main/java/com/contentstack/sdk/CSHttpConnection.java +++ b/contentstack/src/main/java/com/contentstack/sdk/CSHttpConnection.java @@ -2,7 +2,6 @@ import android.text.TextUtils; import android.util.ArrayMap; -import android.util.Log; import com.android.volley.DefaultRetryPolicy; import com.android.volley.VolleyError; @@ -209,7 +208,7 @@ private String getParams(HashMap params) { } } catch (Exception e1) { - SDKUtil.showLog(TAG, "--------------------getQueryParam--||" + e1.toString()); + SDKUtil.showLog(TAG, "-getQueryParam--||" + e1.toString()); } } @@ -239,7 +238,7 @@ public void send() { } headers.put("Content-Type", "application/json"); headers.put("User-Agent", defaultUserAgent()); - headers.put("X-User-Agent", "contentstack-android/" + SDKConstant.SDK_VERSION); + headers.put("X-User-Agent", "contentstack-delivery-android/" + SDKConstant.SDK_VERSION); jsonObjectRequest = new JSONUTF8Request(requestId, url, requestJSON, response -> { this.responseJSON = response; if (this.responseJSON != null) { diff --git a/contentstack/src/main/java/com/contentstack/sdk/Config.java b/contentstack/src/main/java/com/contentstack/sdk/Config.java index 9711d67b..226a6a24 100755 --- a/contentstack/src/main/java/com/contentstack/sdk/Config.java +++ b/contentstack/src/main/java/com/contentstack/sdk/Config.java @@ -2,6 +2,9 @@ import android.text.TextUtils; + +import javax.validation.constraints.NotNull; + /** * Set Configuration for stack instance creation. * @@ -13,6 +16,7 @@ public class Config { protected String VERSION = "v3"; protected String environment = null; protected String branch = null; + protected String[] earlyAccess = null; /** @@ -43,13 +47,13 @@ public void setBranch(String branch) { * *

Example For Different Regions:
*
-     *               {@code
-     *               config.setRegion(ContentstackRegion.US);
-     *               config.setRegion(ContentstackRegion.EU);
-     *               config.setRegion(ContentstackRegion.AZURE_EU);
-     *               config.setRegion(ContentstackRegion.AZURE_NA);
-     *               }
-     *               
+ * {@code + * config.setRegion(ContentstackRegion.US); + * config.setRegion(ContentstackRegion.EU); + * config.setRegion(ContentstackRegion.AZURE_EU); + * config.setRegion(ContentstackRegion.AZURE_NA); + * } + * */ public ContentstackRegion setRegion(ContentstackRegion region) { this.region = region; @@ -61,6 +65,15 @@ public ContentstackRegion getRegion() { return this.region; } + public String[] getEarlyAccess() { + return this.earlyAccess; + } + + public Config earlyAccess(@NotNull String[] earlyAccess) { + this.earlyAccess = earlyAccess; + return this; + } + public enum ContentstackRegion {US, EU, AZURE_NA, AZURE_EU} /** diff --git a/contentstack/src/main/java/com/contentstack/sdk/Contentstack.java b/contentstack/src/main/java/com/contentstack/sdk/Contentstack.java index 19a7be25..22433a47 100755 --- a/contentstack/src/main/java/com/contentstack/sdk/Contentstack.java +++ b/contentstack/src/main/java/com/contentstack/sdk/Contentstack.java @@ -7,10 +7,11 @@ import com.android.volley.RequestQueue; import com.android.volley.toolbox.Volley; -import org.jetbrains.annotations.NotNull; import java.io.File; +import javax.validation.constraints.NotNull; + /** * Contains all Contentstack SDK Classes And Methods. * @@ -87,6 +88,10 @@ private static Stack initializeStack(Context appContext, String apiKey, String d if (config.getBranch() != null) { stack.setHeader("branch", config.getBranch()); } + if (config.getEarlyAccess() != null && config.getEarlyAccess().length > 0) { + String eaValues = String.join(",", config.earlyAccess).replace("\"", ""); + stack.setHeader("x-header-ea", eaValues); + } stack.setConfig(config); initializeCache(appContext); return stack; diff --git a/contentstack/src/main/java/com/contentstack/sdk/Stack.java b/contentstack/src/main/java/com/contentstack/sdk/Stack.java index 1671fb38..3ba27756 100755 --- a/contentstack/src/main/java/com/contentstack/sdk/Stack.java +++ b/contentstack/src/main/java/com/contentstack/sdk/Stack.java @@ -4,8 +4,6 @@ import android.text.TextUtils; import android.util.ArrayMap; import android.util.Log; - -import org.jetbrains.annotations.NotNull; import org.json.JSONException; import org.json.JSONObject; @@ -23,6 +21,8 @@ import java.util.Objects; import java.util.TimeZone; +import javax.validation.constraints.NotNull; + /** * To fetch stack level information of your application from Contentstack server. *

diff --git a/contentstack/src/main/java/com/contentstack/sdk/TestActivity.java b/contentstack/src/main/java/com/contentstack/sdk/TestActivity.java index 93f38c2a..c4c516c6 100755 --- a/contentstack/src/main/java/com/contentstack/sdk/TestActivity.java +++ b/contentstack/src/main/java/com/contentstack/sdk/TestActivity.java @@ -1,18 +1,13 @@ package com.contentstack.sdk; -import android.os.Bundle; - -import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; - /** * @author Contentstack.com, Inc */ -public class TestActivity extends AppCompatActivity { - - @Override - protected void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - } -} +//public class TestActivity extends AppCompatActivity { +// +// @Override +// protected void onCreate(@Nullable Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// } +//} diff --git a/progaurd-rules.pro b/progaurd-rules.pro new file mode 100644 index 00000000..74e3df95 --- /dev/null +++ b/progaurd-rules.pro @@ -0,0 +1 @@ +-dontwarn java.lang.invoke.StringConcatFactory \ No newline at end of file diff --git a/scripts/publish-module.gradle b/scripts/publish-module.gradle index 8b2f8df1..cdeda6d7 100644 --- a/scripts/publish-module.gradle +++ b/scripts/publish-module.gradle @@ -5,7 +5,7 @@ apply plugin: 'signing' ext { PUBLISH_GROUP_ID = 'com.contentstack.sdk' PUBLISH_ARTIFACT_ID = 'android' - PUBLISH_VERSION = '3.12.4-SNAPSHOT' + PUBLISH_VERSION = '3.12.4' POM_NAME = 'contentstack-android' WEBSITE = 'http://www.contentstack.com' PUBLISH_DESCRIPTION = 'The Content Delivery SDK is used to retrieve content from your Contentstack account and deliver it to your web or mobile properties.' @@ -44,7 +44,8 @@ afterEvaluate { if (project.plugins.findPlugin("com.android.library")) { //from components.release } else { - artifact("$buildDir/libs/${project.getName()}-${version}.jar") + //artifact("$buildDir/libs/${project.getName()}-${version}.jar") + artifact("$buildDir/outputs/aar/contentstack-release.aar") } artifact androidSourcesJar pom { diff --git a/scripts/publish-root.gradle b/scripts/publish-root.gradle index b7092b5b..be00e247 100644 --- a/scripts/publish-root.gradle +++ b/scripts/publish-root.gradle @@ -15,12 +15,24 @@ if (secretPropsFile.exists()) { nexusPublishing { repositories { + sonatype { + stagingProfileId = sonatypeStagingProfileId + username = ossrhUsername + password = ossrhPassword + nexusUrl.set(uri("https://oss.sonatype.org/service/local/")) + snapshotRepositoryUrl.set(uri("https://oss.sonatype.org/content/repositories/snapshots/")) + if (project.version.endsWith('-SNAPSHOT')) { + snapshotRepositoryUrl.set(uri("https://oss.sonatype.org/content/repositories/snapshots")) + } else { + nexusUrl.set(uri("https://oss.sonatype.org/service/local/")) + } + } + // sonatype { // stagingProfileId = sonatypeStagingProfileId // username = ossrhUsername // password = ossrhPassword -// nexusUrl.set(uri("https://oss.sonatype.org/service/local/")) -// snapshotRepositoryUrl.set(uri("https://oss.sonatype.org/content/repositories/snapshots/")) +// // if (project.version.endsWith('-SNAPSHOT')) { // snapshotRepositoryUrl.set(uri("https://oss.sonatype.org/content/repositories/snapshots")) // } else { @@ -32,21 +44,9 @@ nexusPublishing { // stagingProfileId = sonatypeStagingProfileId // username = ossrhUsername // password = ossrhPassword -// -// if (project.version.endsWith('-SNAPSHOT')) { -// snapshotRepositoryUrl.set(uri("https://oss.sonatype.org/content/repositories/snapshots")) -// } else { -// nexusUrl.set(uri("https://oss.sonatype.org/service/local/")) -// } +// //nexusUrl.set(uri("https://oss.sonatype.org/service/local/")) +// snapshotRepositoryUrl.set(uri("https://oss.sonatype.org/content/repositories/snapshots/")) // } - sonatype { - stagingProfileId = sonatypeStagingProfileId - username = ossrhUsername - password = ossrhPassword - //nexusUrl.set(uri("https://oss.sonatype.org/service/local/")) - snapshotRepositoryUrl.set(uri("https://oss.sonatype.org/content/repositories/snapshots/")) - } - } }