From f105c25012c5a1a19cc6d26510a6eeb6afdf5541 Mon Sep 17 00:00:00 2001 From: Taylor Bockman Date: Mon, 14 May 2018 09:25:59 -0700 Subject: [PATCH] First OSSRH config (#6) --- CONTRIBUTING.md | 3 - README.md | 21 ++++++ build.gradle | 88 +++++++++++++++++++++- .../com/sigmaflare/binancej/BaseBinanceApi.java | 11 ++- .../java/com/sigmaflare/binancej/HttpRequests.java | 4 + 5 files changed, 114 insertions(+), 13 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c099be1..81f13c7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -44,8 +44,6 @@ maintain, and track please use the format `-`. * ``: I could use either `ag` (for "angrygoats") or `tb` (for "Taylor Bockman"). Both allow someone to quickly know who owns the branch. * ``: If the ticket/feature has an associated issue/ticket number please include it in the branch name. Otherwise an accurate description of the feature is sufficient. - - ## Testing We operate a strict TDD shop here. As a result, any PR submitted without tests for anything but _the most trivial_ of @@ -62,7 +60,6 @@ gradle test from the root of the project. - ## Code Standards Clean Java is good Java. As all of us know Java can get unnecessarily verbose at times, and in order to keep readability diff --git a/README.md b/README.md index b6a9a0c..d7a0c55 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,22 @@ A Java 8 implementation of the [Binance API Specification](https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md). +## Getting BinanceJ + +### Maven + +``` + + com.sigmaflare + binancej + 1.0.2 + +``` + +### Gradle + +`compile group: 'com.sigmaflare', name: 'binancej', version: '1.0.2'` + ## Licensing BinanceJ is released under the MIT license. @@ -50,6 +66,11 @@ component so you can check the specifics against the [Binance Error Documentatio In the event an unknown error occurs, the code will throw an `UnexpectedErrorException`. These are generally complete showstoppers. +## Notes + +Be sure to call `close` on the API container class (`GeneralUtilities`, `MarketData`, etc) in order to close the +`CloseableHttpClient` resource. + ## Examples ### Server alive check with ping diff --git a/build.gradle b/build.gradle index 262a8c0..4f296e3 100644 --- a/build.gradle +++ b/build.gradle @@ -1,13 +1,46 @@ plugins { // Apply the java-library plugin to add support for Java Library id 'java-library' - id 'com.github.ethankhall.semantic-versioning' version "1.1.0" apply true + id 'maven' + id 'signing' +} + + +group = "com.sigmaflare" +archivesBaseName = "binancej" +version = '1.0.2-SNAPSHOT' +ext.isReleaseVersion = !version.endsWith("SNAPSHOT") + +// Add default values for OSSRH +if (!project.hasProperty("ossrhUsername")) { + ext.ossrhUsername = "" +} + +if(!project.hasProperty("ossrhPassword")) { + ext.ossrhPassword = "" } -project.version.with { major = 1; minor= 0; patch = 1 } sourceCompatibility = 1.8 +repositories { + mavenCentral() +} + +task javadocJar(type: Jar) { + classifier = 'javadoc' + from javadoc +} + +task sourcesJar(type: Jar) { + classifier = 'sources' + from sourceSets.main.allSource +} + +artifacts { + archives javadocJar, sourcesJar +} + dependencies { compile group: 'org.projectlombok', name: 'lombok', version: '1.16.20' compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.9.5' @@ -25,7 +58,54 @@ dependencies { testCompile group: 'org.mockito', name: 'mockito-core', version: '2.18.3' } -repositories { - mavenCentral() +signing { + sign configurations.archives +} + + +tasks.withType(Sign) { + onlyIf { isReleaseVersion } } +uploadArchives { + repositories { + mavenDeployer { + beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } + + repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") { + authentication(userName: ossrhUsername, password: ossrhPassword) + } + + snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") { + authentication(userName: ossrhUsername, password: ossrhPassword) + } + + pom.project { + name 'BinanceJ' + packaging 'jar' + // optionally artifactId can be defined here + description 'A java implementation of the Binance API Specification' + url 'https://github.com/angrygoats/binancej' + + scm { + url 'https://github.com/angrygoats/binancej' + } + + licenses { + license { + name 'MIT License' + url 'https://opensource.org/licenses/MIT' + } + } + + developers { + developer { + id 'angrygoats' + name 'Taylor Bockman' + email 'tbockman@xchg.sh' + } + } + } + } + } +} diff --git a/src/main/java/com/sigmaflare/binancej/BaseBinanceApi.java b/src/main/java/com/sigmaflare/binancej/BaseBinanceApi.java index 07c89ae..a986d6d 100644 --- a/src/main/java/com/sigmaflare/binancej/BaseBinanceApi.java +++ b/src/main/java/com/sigmaflare/binancej/BaseBinanceApi.java @@ -7,6 +7,7 @@ import org.apache.http.impl.client.HttpClientBuilder; import java.io.IOException; + public abstract class BaseBinanceApi { protected final String apiKey; protected final String secretKey; @@ -26,13 +27,11 @@ public abstract class BaseBinanceApi { this.closeableHttpClient = closeableHttpClient; } - + /** + * Closes the CloseableHttpClient instance. + * @throws IOException If closing fails + */ public void close() throws IOException { closeableHttpClient.close(); } - - @Override - protected void finalize() throws IOException { - close(); - } } diff --git a/src/main/java/com/sigmaflare/binancej/HttpRequests.java b/src/main/java/com/sigmaflare/binancej/HttpRequests.java index aabd4e1..c3ca5f3 100644 --- a/src/main/java/com/sigmaflare/binancej/HttpRequests.java +++ b/src/main/java/com/sigmaflare/binancej/HttpRequests.java @@ -90,6 +90,10 @@ public final class HttpRequests { /** * A simple function to consolidate the creation of common HTTP exceptions + * @param statusCode The status code to build the exception for + * @param error The ServiceError object returned from Binance to use to build the exception + * @return A BinanceServiceException based on the provided statusCode argument + * @throws IllegalArgumentException If the statusCode is below 400 */ public static BinanceServiceException buildHttpException(int statusCode, ServiceError error) { if(statusCode < 400) {