diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index dddfde6..822801f 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -5,22 +5,28 @@ on: [push, pull_request, workflow_dispatch] jobs: build: runs-on: ubuntu-latest + env: GRADLE_OPTS: "-Dorg.gradle.jvmargs=-XX:MaxMetaspaceSize=512m" SONAR_JDK: "11" + strategy: matrix: java-version: [ 11, 15 ] + steps: - uses: actions/checkout@v2 with: fetch-depth: 0 + - name: Set up JDK ${{ matrix.java-version }} uses: actions/setup-java@v1 with: java-version: ${{ matrix.java-version }} + - name: Grant execute permission for gradlew run: chmod +x gradlew + - name: Cache SonarCloud packages if: matrix.java-version == env.SONAR_JDK uses: actions/cache@v1 @@ -28,6 +34,7 @@ jobs: path: ~/.sonar/cache key: ${{ runner.os }}-sonar restore-keys: ${{ runner.os }}-sonar + - name: Cache Gradle packages uses: actions/cache@v2 with: @@ -37,14 +44,17 @@ jobs: key: ${{ runner.os }}-gradle-${{ matrix.java-version }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} restore-keys: | ${{ runner.os }}-gradle-${{ matrix.java-version }}- + - name: Test with Gradle run: ./gradlew build check --stacktrace + - name: SonarCloud if: success() && matrix.java-version == env.SONAR_JDK env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} run: ./gradlew sonarqube + - name: Cleanup Gradle Cache run: | rm -f ~/.gradle/caches/modules-2/modules-2.lock diff --git a/build.gradle.kts b/build.gradle.kts index 1f101d5..de43e50 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,7 +11,7 @@ plugins { id("java") id("maven-publish") id("org.jetbrains.dokka") version "1.4.32" - id("org.sonarqube") version "3.2.0" + id("org.sonarqube") version "3.3" id("signing") kotlin("jvm") version "1.5.10" } @@ -118,8 +118,25 @@ tasks { } } + val copyToDeploy by registering(Copy::class) { + from(configurations.runtimeClasspath) { + exclude("annotations-*.jar") + } + from(jar) + into(deployDir) + } + + register("deploy") { + description = "Copies all needed files to the $deployDir directory." + group = PublishingPlugin.PUBLISH_TASK_GROUP + dependsOn(build, jar) + outputs.dir(deployDir) + inputs.files(copyToDeploy) + mustRunAfter(clean) + } + "sonarqube" { - dependsOn("jacocoTestReport") + dependsOn(jacocoTestReport) } } diff --git a/examples/src/main/java/com/example/CryptoPriceSample.java b/examples/src/main/java/com/example/CryptoPriceSample.java index d5c6f89..2855b6e 100644 --- a/examples/src/main/java/com/example/CryptoPriceSample.java +++ b/examples/src/main/java/com/example/CryptoPriceSample.java @@ -38,7 +38,10 @@ public class CryptoPriceSample { System.out.println("The current " + buyPrice.getBase() + " buy price is " + buyPrice.getAmount() + " in " + buyPrice.getCurrency()); - } catch (CryptoException | IOException e) { + } catch (CryptoException e) { + System.err.println("HTTP Status Code: " + e.getStatusCode()); + System.err.println(e.getMessage()); + } catch (IOException e) { System.err.println(e.getMessage()); } } diff --git a/examples/src/main/kotlin/com/example/CryptoPriceExample.kt b/examples/src/main/kotlin/com/example/CryptoPriceExample.kt index b57f7f5..6130ea5 100644 --- a/examples/src/main/kotlin/com/example/CryptoPriceExample.kt +++ b/examples/src/main/kotlin/com/example/CryptoPriceExample.kt @@ -1,28 +1,38 @@ package com.example +import net.thauvin.erik.crypto.CryptoException import net.thauvin.erik.crypto.CryptoPrice.Companion.apiCall import net.thauvin.erik.crypto.CryptoPrice.Companion.spotPrice import net.thauvin.erik.crypto.CryptoPrice.Companion.toPrice +import java.io.IOException + fun main(@Suppress("UNUSED_PARAMETER") args: Array) { - // Get current Bitcoin spot price. - val price = spotPrice("BTC") - println("The current Bitcoin price is ${price.toCurrency()}") + try { + // Get current Bitcoin spot price. + val price = spotPrice("BTC") + println("The current Bitcoin price is ${price.toCurrency()}") - println() - - // Get current Ethereum spot price in Pound sterling. - val gbpPrice = spotPrice("ETH", "GBP") - println("The current Ehtereum price is ${gbpPrice.toCurrency()}") + println() + + // Get current Ethereum spot price in Pound sterling. + val gbpPrice = spotPrice("ETH", "GBP") + println("The current Ehtereum price is ${gbpPrice.toCurrency()}") - // Get current Litecoin spot price in Euro. - val euroPrice = spotPrice("LTC", "EUR") - println("The current Litecoin price is ${euroPrice.toCurrency()}") + // Get current Litecoin spot price in Euro. + val euroPrice = spotPrice("LTC", "EUR") + println("The current Litecoin price is ${euroPrice.toCurrency()}") - println() - - // Get current Bitcoin buy price using API. - // See: https://developers.coinbase.com/api/v2#get-buy-price - val buyPrice = apiCall(listOf("prices", "BTC-USD", "buy"), emptyMap()).toPrice() - println("The current ${buyPrice.base} buy price is ${buyPrice.amount} in ${buyPrice.currency}") + println() + + // Get current Bitcoin buy price using API. + // See: https://developers.coinbase.com/api/v2#get-buy-price + val buyPrice = apiCall(listOf("prices", "BTC-USD", "buy"), emptyMap()).toPrice() + println("The current ${buyPrice.base} buy price is ${buyPrice.amount} in ${buyPrice.currency}") + } catch (e: CryptoException) { + System.err.println("HTTP Status Code: ${e.statusCode}") + System.err.println(e.message) + } catch (e: IOException) { + System.err.println(e.message) + } } diff --git a/src/main/kotlin/net/thauvin/erik/crypto/CryptoException.kt b/src/main/kotlin/net/thauvin/erik/crypto/CryptoException.kt index 47302d8..38dc96f 100644 --- a/src/main/kotlin/net/thauvin/erik/crypto/CryptoException.kt +++ b/src/main/kotlin/net/thauvin/erik/crypto/CryptoException.kt @@ -1,5 +1,5 @@ /* - * CryptoExtension.kt + * CryptoException.kt * * Copyright (c) 2021, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. @@ -37,7 +37,8 @@ package net.thauvin.erik.crypto */ @Suppress("unused") class CryptoException : Exception { - var statusCode = NO_STATUS + var statusCode: Int + private set /** Constructs a new exception with the specified status code, message and cause. */ constructor(statusCode: Int = NO_STATUS, message: String, cause: Throwable) : super(message, cause) { @@ -56,7 +57,6 @@ class CryptoException : Exception { companion object { const val NO_STATUS = -1 - private const val serialVersionUID = 1L } }