Skip to content

Commit 1097f41

Browse files
Merge pull request #94 from contentstack/development
Development
2 parents f2dcd27 + 77d2b5d commit 1097f41

File tree

11 files changed

+142
-66
lines changed

11 files changed

+142
-66
lines changed

.github/workflows/publish-release.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,20 @@ jobs:
1010
steps:
1111
- name: Checkout project sources
1212
uses: actions/checkout@v3
13+
14+
- name: Set up JDK and Maven Central
15+
uses: actions/setup-java@v3
16+
with:
17+
java-version: '17'
18+
distribution: 'adopt'
19+
cache: 'gradle'
20+
server-id: central
21+
server-username: ${{ secrets.MAVEN_USERNAME }}
22+
server-password: ${{ secrets.MAVEN_PASSWORD }}
23+
1324
- name: Setup Gradle
1425
uses: gradle/gradle-build-action@v2
26+
1527
- name: Setup local.properties
1628
run: |
1729
cat << EOF >> local.properties
@@ -23,15 +35,17 @@ jobs:
2335
contentType="${{ secrets.CONTENT_TYPE }}"
2436
assetUid="${{ secrets.ASSET_UID }}"
2537
EOF
38+
2639
- name: Gradle build and clean
2740
run: |
2841
./gradlew clean build
29-
- name: Publish the SDK
42+
43+
- name: Publish to Maven Central
3044
run: |
3145
./gradlew publishAndReleaseToMavenCentral --no-configuration-cache
3246
env:
33-
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.mavenCentralUsername }}
34-
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.mavenCentralPassword }}
47+
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_USERNAME }}
48+
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_PASSWORD }}
3549
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.signingInMemoryKey }}
3650
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.signingInMemoryKeyId }}
3751
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.signingInMemoryKeyPassword }}

build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ buildscript {
1212
}
1313

1414
dependencies {
15-
//classpath "com.android.tools.build:gradle:8.2.1" //8.2.1
16-
classpath 'com.android.tools.build:gradle:7.4.2'
15+
classpath "com.android.tools.build:gradle:8.2.1"
1716
classpath 'io.github.gradle-nexus:publish-plugin:2.0.0-rc-1'
1817
classpath "org.jacoco:org.jacoco.core:$jacoco_version"
1918
}

contentstack/build.gradle

Lines changed: 68 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,20 @@
11
plugins {
2-
id "com.vanniktech.maven.publish" version "0.27.0"
32
id "com.android.library"
3+
id "com.vanniktech.maven.publish" version "0.33.0"
44
}
55

6-
import com.vanniktech.maven.publish.SonatypeHost
7-
8-
android.buildFeatures.buildConfig true
9-
10-
mavenPublishing {
11-
publishToMavenCentral(SonatypeHost.DEFAULT)
12-
signAllPublications()
13-
coordinates("com.contentstack.sdk", "android", "4.1.0")
14-
15-
pom {
16-
name = "contentstack-android"
17-
description = "The Content Delivery SDK facilitates the retrieval of content from your Contentstack account, enabling seamless delivery to your web or mobile properties.."
18-
inceptionYear = "2018"
19-
packaging 'aar'
20-
url = "https://github.com/contentstack/contentstack-android"
21-
licenses {
22-
license {
23-
name = "The MIT License"
24-
url = "https://github.com/contentstack/contentstack-android/blob/master/LICENSE"
25-
distribution = "https://github.com/contentstack/contentstack-android/blob/master/LICENSE"
26-
}
27-
}
28-
developers {
29-
developer {
30-
id = "ishaileshmishra"
31-
name = "contentstack"
32-
url = "https://github.com/contentstack/contentstack-android"
33-
}
34-
}
35-
scm {
36-
url = "scm:[email protected]:contentstack/contentstack-android"
37-
connection = "scm:git:git://github.com/contentstack/contentstack-android.git"
38-
developerConnection = "scm:[email protected]:contentstack/contentstack-android.git"
39-
}
40-
}
41-
}
42-
43-
44-
tasks.register('jacocoTestReport', JacocoReport) {
45-
dependsOn['testDebugUnitTest', 'createDebugCoverageReport']
46-
reports {
47-
html.enabled = true
48-
}
49-
afterEvaluate {
50-
classDirectories.setFrom(files(classDirectories.files.collect {
51-
fileTree(dir: it, exclude: '**com/contentstack/okhttp**')
52-
fileTree(dir: it, exclude: '**com/contentstack/okio**')
53-
fileTree(dir: it, exclude: '**com/contentstack/txtmark**')
54-
}))
55-
}
6+
ext {
7+
PUBLISH_GROUP_ID = 'com.contentstack.sdk'
8+
PUBLISH_ARTIFACT_ID = 'android'
9+
PUBLISH_VERSION = '4.1.0'
5610
}
5711

5812
android {
59-
//namespace "com.contentstack.sdk"
13+
namespace "com.contentstack.sdk"
14+
compileSdk 34 // Using latest stable Android SDK version
15+
buildFeatures {
16+
buildConfig true
17+
}
6018
packagingOptions {
6119
exclude("META-INF/DEPENDENCIES")
6220
exclude("META-INF/LICENSE")
@@ -97,7 +55,6 @@ android {
9755
keyPassword 'android'
9856
}
9957
}
100-
compileSdk 30
10158
defaultConfig {
10259
// Required when setting minSdkVersion to 20 or lower
10360
multiDexEnabled true
@@ -204,4 +161,61 @@ tasks.register('createJar', Jar) {
204161
include 'com/contentstack/'
205162
//include 'META-INF/'
206163
}
207-
createJar.dependsOn(clearJar, unzip, build)
164+
createJar.dependsOn(clearJar, unzip, build)
165+
166+
mavenPublishing {
167+
// Configure the Maven Central publishing target
168+
publishToMavenCentral("CENTRAL_PORTAL")
169+
170+
// Sign all publications
171+
signAllPublications()
172+
173+
coordinates(PUBLISH_GROUP_ID, PUBLISH_ARTIFACT_ID, PUBLISH_VERSION)
174+
175+
pom {
176+
name = "contentstack-android"
177+
description = "The Content Delivery SDK facilitates the retrieval of content from your Contentstack account, enabling seamless delivery to your web or mobile properties.."
178+
inceptionYear = "2018"
179+
packaging 'aar'
180+
url = "https://github.com/contentstack/contentstack-android"
181+
licenses {
182+
license {
183+
name = "The MIT License"
184+
url = "https://github.com/contentstack/contentstack-android/blob/master/LICENSE"
185+
distribution = "https://github.com/contentstack/contentstack-android/blob/master/LICENSE"
186+
}
187+
}
188+
developers {
189+
developer {
190+
id = "ishaileshmishra"
191+
name = "contentstack"
192+
url = "https://github.com/contentstack/contentstack-android"
193+
}
194+
}
195+
scm {
196+
url = "scm:[email protected]:contentstack/contentstack-android"
197+
connection = "scm:git:git://github.com/contentstack/contentstack-android.git"
198+
developerConnection = "scm:[email protected]:contentstack/contentstack-android.git"
199+
}
200+
}
201+
}
202+
203+
tasks.register('jacocoTestReport', JacocoReport) {
204+
dependsOn('testDebugUnitTest', 'createDebugCoverageReport')
205+
reports {
206+
html.required = true
207+
}
208+
}
209+
210+
// Configure jacocoTestReport after evaluation when classDirectories is available
211+
project.afterEvaluate {
212+
tasks.named('jacocoTestReport', JacocoReport) {
213+
classDirectories.setFrom(files(classDirectories.files.collect {
214+
fileTree(dir: it, exclude: [
215+
'**com/contentstack/okhttp**',
216+
'**com/contentstack/okio**',
217+
'**com/contentstack/txtmark**'
218+
])
219+
}))
220+
}
221+
}

contentstack/src/main/java/com/contentstack/sdk/Contentstack.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class Contentstack {
2727
private static Contentstack instance;
2828

2929
private Contentstack(Context context) {
30-
throw new IllegalStateException("Private constructor not allowed");
30+
throw new IllegalStateException(ErrorMessages.PRIVATE_CONSTRUCTOR_NOT_ALLOWED);
3131
}
3232

3333
/**
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.contentstack.sdk;
2+
3+
/**
4+
* Contains all error messages used across the SDK.
5+
* Centralizing messages here makes it easier to maintain and update them.
6+
*/
7+
public final class ErrorMessages {
8+
private ErrorMessages() {
9+
throw new IllegalStateException("Utility class - do not instantiate");
10+
}
11+
12+
// Constructor related errors
13+
public static final String PRIVATE_CONSTRUCTOR_NOT_ALLOWED =
14+
"This class does not support private constructors. Use a public constructor to create an instance.";
15+
public static final String UTILITY_CLASS_INSTANTIATION =
16+
"This is a utility class and cannot be instantiated";
17+
public static final String NODE_TO_HTML_INSTANTIATION =
18+
"Failed to create an instance of NodeToHTML, you can directly access the methods of this class";
19+
20+
// Input validation errors
21+
public static final String NULL_OR_EMPTY_INPUT =
22+
"The input value cannot be null or empty. Provide a valid string to continue.";
23+
24+
// Network and parsing errors
25+
public static final String ENCODING_ERROR =
26+
"The system encountered an encoding issue while processing your request. Try again or contact support.";
27+
public static final String JSON_PARSING_ERROR =
28+
"We couldn't process the response due to a data formatting issue. Try again or contact support if the problem persists.";
29+
30+
// Cache related errors
31+
public static final String CACHE_INITIALIZATION_ERROR =
32+
"Failed to initialize cache. The application will continue without caching.";
33+
}

contentstack/src/main/java/com/contentstack/sdk/InvalidInputException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* <code>
1414
* public void processInput(String input) throws InvalidInputException {
1515
* if (input == null || input.isEmpty()) {
16-
* throw new InvalidInputException("Input cannot be null or empty");
16+
* throw new InvalidInputException(ErrorMessages.NULL_OR_EMPTY_INPUT);
1717
* }
1818
* // Process the input here
1919
* }

contentstack/src/main/java/com/contentstack/sdk/JSONUTF8Request.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
2424
String jsonString = new String(response.data, "UTF-8");
2525
return Response.success(new JSONObject(jsonString), HttpHeaderParser.parseCacheHeaders(response));
2626
} catch (UnsupportedEncodingException e) {
27-
return Response.error(new ParseError(e));
27+
return Response.error(new ParseError(new UnsupportedEncodingException(ErrorMessages.ENCODING_ERROR)));
2828
} catch (JSONException je) {
29-
return Response.error(new ParseError(je));
29+
return Response.error(new ParseError(new JSONException(ErrorMessages.JSON_PARSING_ERROR)));
3030
}
3131
}
3232

contentstack/src/main/java/com/contentstack/sdk/NodeToHTML.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
public class NodeToHTML {
66
private NodeToHTML() {
7-
throw new IllegalStateException("Could not create instance of NodeToHTML");
7+
throw new IllegalStateException(ErrorMessages.NODE_TO_HTML_INSTANTIATION);
88
}
99
public static String textNodeToHTML(JSONObject nodeText, Option renderOption) {
1010
String text = nodeText.optString("text");

gradle.properties

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
android.useAndroidX=true
22
android.enableJetifier=true
33
android.enableR8.fullMode=false
4-
org.gradle.jvmargs=-XX:MaxMetaspaceSize=512m
4+
org.gradle.jvmargs=-XX:MaxMetaspaceSize=512m
5+
android.suppressUnsupportedCompileSdk=34
6+
7+
# Maven Central Publishing Configuration
8+
# These values should be provided by environment variables in CI
9+
# For new Central Portal, use Portal Token instead of username/password
10+
mavenCentralUsername=
11+
mavenCentralPassword=
12+
signing.keyId=
13+
signing.password=
14+
signing.secretKeyRingFile=

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
33
#distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
44
#distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip
5-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
5+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
66
networkTimeout=10000
77
validateDistributionUrl=true
88
zipStoreBase=GRADLE_USER_HOME

0 commit comments

Comments
 (0)