Skip to content
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
20 changes: 17 additions & 3 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,20 @@ jobs:
steps:
- name: Checkout project sources
uses: actions/checkout@v3

- name: Set up JDK and Maven Central
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'
cache: 'gradle'
server-id: central
server-username: ${{ secrets.MAVEN_USERNAME }}
server-password: ${{ secrets.MAVEN_PASSWORD }}

- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Setup local.properties
run: |
cat << EOF >> local.properties
Expand All @@ -23,15 +35,17 @@ jobs:
contentType="${{ secrets.CONTENT_TYPE }}"
assetUid="${{ secrets.ASSET_UID }}"
EOF

- name: Gradle build and clean
run: |
./gradlew clean build
- name: Publish the SDK

- name: Publish to Maven Central
run: |
./gradlew publishAndReleaseToMavenCentral --no-configuration-cache
env:
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.mavenCentralUsername }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.mavenCentralPassword }}
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.signingInMemoryKey }}
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.signingInMemoryKeyId }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.signingInMemoryKeyPassword }}
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ buildscript {
}

dependencies {
//classpath "com.android.tools.build:gradle:8.2.1" //8.2.1
classpath 'com.android.tools.build:gradle:7.4.2'
classpath "com.android.tools.build:gradle:8.2.1"
classpath 'io.github.gradle-nexus:publish-plugin:2.0.0-rc-1'
classpath "org.jacoco:org.jacoco.core:$jacoco_version"
}
Expand Down
122 changes: 68 additions & 54 deletions contentstack/build.gradle
Original file line number Diff line number Diff line change
@@ -1,62 +1,20 @@
plugins {
id "com.vanniktech.maven.publish" version "0.27.0"
id "com.android.library"
id "com.vanniktech.maven.publish" version "0.33.0"
}

import com.vanniktech.maven.publish.SonatypeHost

android.buildFeatures.buildConfig true

mavenPublishing {
publishToMavenCentral(SonatypeHost.DEFAULT)
signAllPublications()
coordinates("com.contentstack.sdk", "android", "4.1.0")

pom {
name = "contentstack-android"
description = "The Content Delivery SDK facilitates the retrieval of content from your Contentstack account, enabling seamless delivery to your web or mobile properties.."
inceptionYear = "2018"
packaging 'aar'
url = "https://github.com/contentstack/contentstack-android"
licenses {
license {
name = "The MIT License"
url = "https://github.com/contentstack/contentstack-android/blob/master/LICENSE"
distribution = "https://github.com/contentstack/contentstack-android/blob/master/LICENSE"
}
}
developers {
developer {
id = "ishaileshmishra"
name = "contentstack"
url = "https://github.com/contentstack/contentstack-android"
}
}
scm {
url = "scm:git@github.com:contentstack/contentstack-android"
connection = "scm:git:git://github.com/contentstack/contentstack-android.git"
developerConnection = "scm:git@github.com:contentstack/contentstack-android.git"
}
}
}


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**')
}))
}
ext {
PUBLISH_GROUP_ID = 'com.contentstack.sdk'
PUBLISH_ARTIFACT_ID = 'android'
PUBLISH_VERSION = '4.1.0'
}

android {
//namespace "com.contentstack.sdk"
namespace "com.contentstack.sdk"
compileSdk 34 // Using latest stable Android SDK version
buildFeatures {
buildConfig true
}
packagingOptions {
exclude("META-INF/DEPENDENCIES")
exclude("META-INF/LICENSE")
Expand Down Expand Up @@ -97,7 +55,6 @@ android {
keyPassword 'android'
}
}
compileSdk 30
defaultConfig {
// Required when setting minSdkVersion to 20 or lower
multiDexEnabled true
Expand Down Expand Up @@ -204,4 +161,61 @@ tasks.register('createJar', Jar) {
include 'com/contentstack/'
//include 'META-INF/'
}
createJar.dependsOn(clearJar, unzip, build)
createJar.dependsOn(clearJar, unzip, build)

mavenPublishing {
// Configure the Maven Central publishing target
publishToMavenCentral("CENTRAL_PORTAL")

// Sign all publications
signAllPublications()

coordinates(PUBLISH_GROUP_ID, PUBLISH_ARTIFACT_ID, PUBLISH_VERSION)

pom {
name = "contentstack-android"
description = "The Content Delivery SDK facilitates the retrieval of content from your Contentstack account, enabling seamless delivery to your web or mobile properties.."
inceptionYear = "2018"
packaging 'aar'
url = "https://github.com/contentstack/contentstack-android"
licenses {
license {
name = "The MIT License"
url = "https://github.com/contentstack/contentstack-android/blob/master/LICENSE"
distribution = "https://github.com/contentstack/contentstack-android/blob/master/LICENSE"
}
}
developers {
developer {
id = "ishaileshmishra"
name = "contentstack"
url = "https://github.com/contentstack/contentstack-android"
}
}
scm {
url = "scm:git@github.com:contentstack/contentstack-android"
connection = "scm:git:git://github.com/contentstack/contentstack-android.git"
developerConnection = "scm:git@github.com:contentstack/contentstack-android.git"
}
}
}

tasks.register('jacocoTestReport', JacocoReport) {
dependsOn('testDebugUnitTest', 'createDebugCoverageReport')
reports {
html.required = true
}
}

// Configure jacocoTestReport after evaluation when classDirectories is available
project.afterEvaluate {
tasks.named('jacocoTestReport', JacocoReport) {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, exclude: [
'**com/contentstack/okhttp**',
'**com/contentstack/okio**',
'**com/contentstack/txtmark**'
])
}))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Contentstack {
private static Contentstack instance;

private Contentstack(Context context) {
throw new IllegalStateException("Private constructor not allowed");
throw new IllegalStateException(ErrorMessages.PRIVATE_CONSTRUCTOR_NOT_ALLOWED);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.contentstack.sdk;

/**
* Contains all error messages used across the SDK.
* Centralizing messages here makes it easier to maintain and update them.
*/
public final class ErrorMessages {
private ErrorMessages() {
throw new IllegalStateException("Utility class - do not instantiate");
}

// Constructor related errors
public static final String PRIVATE_CONSTRUCTOR_NOT_ALLOWED =
"This class does not support private constructors. Use a public constructor to create an instance.";
public static final String UTILITY_CLASS_INSTANTIATION =
"This is a utility class and cannot be instantiated";
public static final String NODE_TO_HTML_INSTANTIATION =
"Failed to create an instance of NodeToHTML, you can directly access the methods of this class";

// Input validation errors
public static final String NULL_OR_EMPTY_INPUT =
"The input value cannot be null or empty. Provide a valid string to continue.";

// Network and parsing errors
public static final String ENCODING_ERROR =
"The system encountered an encoding issue while processing your request. Try again or contact support.";
public static final String JSON_PARSING_ERROR =
"We couldn't process the response due to a data formatting issue. Try again or contact support if the problem persists.";

// Cache related errors
public static final String CACHE_INITIALIZATION_ERROR =
"Failed to initialize cache. The application will continue without caching.";
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* <code>
* public void processInput(String input) throws InvalidInputException {
* if (input == null || input.isEmpty()) {
* throw new InvalidInputException("Input cannot be null or empty");
* throw new InvalidInputException(ErrorMessages.NULL_OR_EMPTY_INPUT);
* }
* // Process the input here
* }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
String jsonString = new String(response.data, "UTF-8");
return Response.success(new JSONObject(jsonString), HttpHeaderParser.parseCacheHeaders(response));
} catch (UnsupportedEncodingException e) {
return Response.error(new ParseError(e));
return Response.error(new ParseError(new UnsupportedEncodingException(ErrorMessages.ENCODING_ERROR)));
} catch (JSONException je) {
return Response.error(new ParseError(je));
return Response.error(new ParseError(new JSONException(ErrorMessages.JSON_PARSING_ERROR)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class NodeToHTML {
private NodeToHTML() {
throw new IllegalStateException("Could not create instance of NodeToHTML");
throw new IllegalStateException(ErrorMessages.NODE_TO_HTML_INSTANTIATION);
}
public static String textNodeToHTML(JSONObject nodeText, Option renderOption) {
String text = nodeText.optString("text");
Expand Down
12 changes: 11 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
android.useAndroidX=true
android.enableJetifier=true
android.enableR8.fullMode=false
org.gradle.jvmargs=-XX:MaxMetaspaceSize=512m
org.gradle.jvmargs=-XX:MaxMetaspaceSize=512m
android.suppressUnsupportedCompileSdk=34

# Maven Central Publishing Configuration
# These values should be provided by environment variables in CI
# For new Central Portal, use Portal Token instead of username/password
mavenCentralUsername=
mavenCentralPassword=
signing.keyId=
signing.password=
signing.secretKeyRingFile=
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
#distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
#distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
6 changes: 6 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ dependencyResolutionManagement {
}
rootProject.name = "contentstack-android"
include ':contentstack'

gradle.beforeProject { project ->
if (project.name == "contentstack") {
project.ext.ANDROID_VARIANT_TO_PUBLISH = "release"
}
}
Loading