diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 94721d0..caa974b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -3,84 +3,101 @@ name: Publish Package on: push: branches: [ main ] + release: + types: [created] jobs: - publish: + build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - - name: Set up JDK 11 + + - name: Set up JDK 17 uses: actions/setup-java@v3 with: - java-version: '11' + java-version: '17' distribution: 'temurin' - cache: 'maven' - server-id: github - settings-path: ${{ github.workspace }} + cache: maven - - name: Notify Build Start - uses: 8398a7/action-slack@v3 - with: - status: custom - fields: repo,message,commit,workflow - custom_payload: | - { - "text": "🚀 Starting build and publish for notificationapi-java-server-sdk", - "attachments": [{ - "color": "good", - "fields": [ - { - "title": "Repository", - "value": "{repo}", - "short": true - }, - { - "title": "Commit", - "value": "{commit}", - "short": true - } - ] - }] - } - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + - name: Import GPG key + run: | + # Setup GPG directory + mkdir -p ~/.gnupg + chmod 700 ~/.gnupg - - name: Build with Maven - run: mvn -B package --file pom.xml - - - name: Run tests - run: mvn -B test --file pom.xml - - - name: Check code style - run: mvn -B checkstyle:check --file pom.xml - - - name: Generate Javadoc - run: mvn -B javadoc:javadoc --file pom.xml - - - name: Publish to GitHub Packages - run: mvn --batch-mode deploy - env: - GITHUB_TOKEN: ${{ secrets.PACKAGES_TOKEN }} - - - name: Notify Success - if: success() - uses: 8398a7/action-slack@v3 - with: - status: ${{ job.status }} - fields: repo,message,commit,workflow,took - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_SUCCESS_WEBHOOK_URL }} + # Write key to file + echo "${{ secrets.GPG_PRIVATE_KEY }}" > ~/private.key + + # Import the key + gpg --batch --import ~/private.key + + # Clean up + rm ~/private.key + + # Extract key ID from the imported key + GPG_KEY_ID=$(gpg --list-secret-keys --keyid-format LONG | grep sec | awk '{print $2}' | cut -d'/' -f2) + echo "Imported GPG key ID: $GPG_KEY_ID" + echo "GPG_KEY_ID=$GPG_KEY_ID" >> $GITHUB_ENV - - name: Notify Failure - if: failure() - uses: 8398a7/action-slack@v3 - with: - status: ${{ job.status }} - fields: repo,message,commit,workflow,took + - name: Build and Publish with Maven env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_FAILED_WEBHOOK_URL }} \ No newline at end of file + OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} + OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }} + GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} + run: | + # Create settings.xml file + mkdir -p ~/.m2 + cat > ~/.m2/settings.xml << EOF + + + + + central + \${env.OSSRH_USERNAME} + \${env.OSSRH_TOKEN} + + + gpg.passphrase + \${env.GPG_PASSPHRASE} + + + + + gpg + + \${env.GPG_KEY_ID} + \${env.GPG_PASSPHRASE} + gpg + + + + central + + true + + + \${env.OSSRH_USERNAME} + \${env.OSSRH_TOKEN} + + + + + gpg + central + + + EOF + + # Debug GPG configuration + echo "Using GPG key ID: $GPG_KEY_ID" + gpg --list-keys $GPG_KEY_ID + + # Set environment variables and run Maven with debug for GPG + export OSSRH_USERNAME=${{ secrets.OSSRH_USERNAME }} + export OSSRH_TOKEN="${{ secrets.OSSRH_TOKEN }}" + export GPG_PASSPHRASE=${{ secrets.GPG_PASSPHRASE }} + + mvn clean deploy -Dgpg.keyname=$GPG_KEY_ID -Dgpg.passphrase=$GPG_PASSPHRASE -Dcentral.username=$OSSRH_USERNAME -Dcentral.password=$OSSRH_TOKEN --settings ~/.m2/settings.xml diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 2b5874c..46ae5a6 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -20,6 +20,12 @@ jobs: java-version: ${{ matrix.java }} distribution: 'temurin' cache: 'maven' + server-id: central + server-username: ${{ secrets.OSSRH_USERNAME }} + server-password: ${{ secrets.OSSRH_TOKEN }} + gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} + gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }} + settings-path: ${{ github.workspace }} - name: Build with Maven run: mvn -B package --file pom.xml @@ -31,4 +37,5 @@ jobs: run: mvn -B checkstyle:check --file pom.xml - name: Generate Javadoc - run: mvn -B javadoc:javadoc --file pom.xml \ No newline at end of file + run: mvn -B javadoc:javadoc --file pom.xml + \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..99f25b5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,35 @@ +# Maven +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +.mvn/wrapper/maven-wrapper.jar + +# IDE files +.idea/ +*.iml +.vscode/ +.project +.classpath +.settings/ + +# Compiled files +*.class +*.jar +*.war +*.ear +*.zip +*.tar.gz +*.rar + +# Logs +*.log + +# OS specific +.DS_Store +Thumbs.db \ No newline at end of file diff --git a/README.md b/README.md index e239cd9..0be7294 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This is the official Java Server SDK for [NotificationAPI](https://www.notificat ## Installation -Add the following dependency to your `pom.xml` file: +Add the following dependency to your project's `pom.xml`: ```xml @@ -82,7 +82,3 @@ try (NotificationApi api = new NotificationApi(clientId, clientSecret)) { - Java 11 or later - Maven or Gradle build system - -## License - -This project is licensed under the MIT License - see the LICENSE file for details. \ No newline at end of file diff --git a/checkstyle.xml b/checkstyle.xml new file mode 100644 index 0000000..afec21e --- /dev/null +++ b/checkstyle.xml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 4e0f610..b96f11d 100644 --- a/pom.xml +++ b/pom.xml @@ -1,86 +1,76 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.notificationapi notificationapi-java-server-sdk - 0.1.0 + 0.1.12 jar + NotificationAPI Java Server SDK - Java Server SDK for NotificationAPI + NotificationAPI Java Server SDK - A Java SDK for integrating with NotificationAPI services https://github.com/notificationapi-com/notificationapi-java-server-sdk - - - MIT License - http://www.opensource.org/licenses/mit-license.php - - - - - - github - GitHub Packages - https://maven.pkg.github.com/notificationapi-com/notificationapi-java-server-sdk - - - - UTF-8 11 11 - 10.12.3 + UTF-8 + - - org.apache.httpcomponents - httpclient - 4.5.14 - + com.fasterxml.jackson.core jackson-databind 2.15.2 - - - org.junit.jupiter - junit-jupiter - 5.9.2 - test - + + - org.mockito - mockito-core - 5.3.1 - test + org.apache.httpcomponents + httpclient + 4.5.14 + + + + The Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + + + Mohammad Asadi + NotificationAPI + https://notificationapi.com + + + + + + scm:git:git://github.com/notificationapi-com/notificationapi-java-server-sdk.git + scm:git:ssh://github.com:notificationapi-com/notificationapi-java-server-sdk.git + https://github.com/notificationapi-com/notificationapi-java-server-sdk + HEAD + + + - - org.apache.maven.plugins - maven-compiler-plugin - 3.11.0 - - ${maven.compiler.source} - ${maven.compiler.target} - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.1.0 - + org.apache.maven.plugins maven-source-plugin - 3.3.0 + 3.2.1 attach-sources @@ -90,6 +80,8 @@ + + org.apache.maven.plugins maven-javadoc-plugin @@ -103,19 +95,39 @@ + + + + org.apache.maven.plugins + maven-gpg-plugin + 3.1.0 + + + sign-artifacts + verify + + sign + + + gpg.passphrase + + --pinentry-mode + loopback + --digest-algo + SHA512 + + + + + + + org.apache.maven.plugins maven-checkstyle-plugin - 3.3.0 - - - com.puppycrawl.tools - checkstyle - ${checkstyle.version} - - + 3.6.0 - google_checks.xml + checkstyle.xml UTF-8 true true @@ -131,6 +143,23 @@ + + + + org.sonatype.central + central-publishing-maven-plugin + 0.7.0 + true + + central + + ${env.MAVEN_USERNAME} + ${env.MAVEN_PASSWORD} + + true + published + + - \ No newline at end of file + \ No newline at end of file diff --git a/settings.xml b/settings.xml new file mode 100644 index 0000000..627afdd --- /dev/null +++ b/settings.xml @@ -0,0 +1,28 @@ + + + + + central + ${env.MAVEN_USERNAME} + ${env.MAVEN_PASSWORD} + + + gpg.passphrase + ${env.GPG_PASSPHRASE} + + + + + gpg + + ${env.GPG_KEY_NAME} + ${env.GPG_PASSPHRASE} + + + + + gpg + + \ No newline at end of file diff --git a/src/main/java/com/notificationapi/NotificationApi.java b/src/main/java/com/notificationapi/NotificationApi.java index 525bc0f..dcf92a0 100644 --- a/src/main/java/com/notificationapi/NotificationApi.java +++ b/src/main/java/com/notificationapi/NotificationApi.java @@ -6,7 +6,13 @@ import org.apache.http.HttpHeaders; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; -import org.apache.http.client.methods.*; +import org.apache.http.client.methods.HttpDelete; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPatch; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpPut; +import org.apache.http.client.methods.HttpRequestBase; +import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; diff --git a/src/main/java/com/notificationapi/examples/package-info.java b/src/main/java/com/notificationapi/examples/package-info.java new file mode 100644 index 0000000..b260491 --- /dev/null +++ b/src/main/java/com/notificationapi/examples/package-info.java @@ -0,0 +1,5 @@ +/** + * Contains example code demonstrating the usage of NotificationAPI Java Server SDK. + * These examples show how to integrate and use various features of the SDK. + */ +package com.notificationapi.examples; \ No newline at end of file diff --git a/src/main/java/com/notificationapi/exception/package-info.java b/src/main/java/com/notificationapi/exception/package-info.java new file mode 100644 index 0000000..bdbf61c --- /dev/null +++ b/src/main/java/com/notificationapi/exception/package-info.java @@ -0,0 +1,5 @@ +/** + * Contains exception classes used by the NotificationAPI Java Server SDK. + * These classes handle various error conditions that may occur during API operations. + */ +package com.notificationapi.exception; \ No newline at end of file diff --git a/src/main/java/com/notificationapi/model/package-info.java b/src/main/java/com/notificationapi/model/package-info.java new file mode 100644 index 0000000..5fb3826 --- /dev/null +++ b/src/main/java/com/notificationapi/model/package-info.java @@ -0,0 +1,5 @@ +/** + * Contains model classes used by the NotificationAPI Java Server SDK. + * These classes represent the data structures used for requests and responses. + */ +package com.notificationapi.model; \ No newline at end of file diff --git a/src/main/java/com/notificationapi/package-info.java b/src/main/java/com/notificationapi/package-info.java new file mode 100644 index 0000000..12863a3 --- /dev/null +++ b/src/main/java/com/notificationapi/package-info.java @@ -0,0 +1,5 @@ +/** + * The main package for NotificationAPI Java Server SDK. + * This package contains the core functionality for interacting with NotificationAPI's services. + */ +package com.notificationapi; \ No newline at end of file