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
10 changes: 10 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,13 @@ allprojects {
project.ext.set("javaPrefix", "com_epam_deltix_dfp_NativeImpl_")
project.ext.set("javaMathPrefix", "com_epam_deltix_dfpmath_NativeMathImpl_")
}

def rUser = findProperty('SONATYPE_NEXUS_USERNAME') ?: System.getenv('SONATYPE_NEXUS_USERNAME') ?: "FakeUser"
def rPass = findProperty('SONATYPE_NEXUS_PASSWORD') ?: System.getenv('SONATYPE_NEXUS_PASSWORD') ?: "FakePass"

tasks.register('uploadArtifactsToCentralPortal', com.epam.deltix.buildsrc.SonatypeCentralPortalUploadRepositoryTask) {
portalUsername.set(rUser)
portalPassword.set(rPass)
groupId.set('com.epam.deltix')
snapshotRelease.set(!version.endsWith("SNAPSHOT"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,9 @@ public void run() throws IOException, InterruptedException {
}

String userNameAndPassword = portalUsername.get() + ":" + portalPassword.get();
String basicAuth = Base64.getEncoder().encodeToString(userNameAndPassword.getBytes(StandardCharsets.US_ASCII));
String bearer = "Bearer " + basicAuth;

String bearer = Base64.getEncoder().encodeToString(userNameAndPassword.getBytes(StandardCharsets.US_ASCII));
URI apiUri = URI.create(CENTRAL_PORTAL_OSSRH_API_URI);

String repositoryKey = findOpenRepository(apiUri, bearer);
uploadRepositoryToPortal(apiUri, bearer, repositoryKey);
dropRepository(apiUri, bearer, repositoryKey);
Expand All @@ -123,27 +122,26 @@ private String findOpenRepository(URI apiUri, String bearer) throws IOException
conn.setConnectTimeout(CONNECTION_TIMEOUT);
conn.setReadTimeout(CONNECTION_TIMEOUT);
conn.setRequestMethod("GET");
conn.setRequestProperty("Authorization", bearer);
conn.setRequestProperty("Authorization", "Bearer " + bearer);

int status = conn.getResponseCode();
String body = readBody(conn);

if (status != 200) {
throw new IllegalStateException("Failed to query repositories: " +
"status=" + status + ", response=" + body);
}

final JSONArray repositories = new JSONObject(body).getJSONArray("repositories");
JSONArray repositories = new JSONObject(body).getJSONArray("repositories");
if (repositories.isEmpty()) {
throw new IllegalStateException("No open repositories found!");
}

String repositoryKey = null;
final String group = groupId.get();
String group = groupId.get();
for (int i = 0; i < repositories.length(); i++) {
final JSONObject repo = (JSONObject) repositories.get(i);
JSONObject repo = (JSONObject) repositories.get(i);
if ("open".equals(repo.getString("state"))) {
final String key = repo.getString("key");
String key = repo.getString("key");
if (key.contains(group)) {
repositoryKey = key;
break;
Expand All @@ -163,13 +161,12 @@ private static void uploadRepositoryToPortal(URI apiUri, String bearer, String r
conn.setConnectTimeout(CONNECTION_TIMEOUT);
conn.setReadTimeout(CONNECTION_TIMEOUT);
conn.setRequestMethod("POST");
conn.setRequestProperty("Authorization", bearer);
conn.setRequestProperty("Authorization", "Bearer " + bearer);
conn.setDoOutput(true);
conn.getOutputStream().close(); // no body
conn.getOutputStream().close();

int status = conn.getResponseCode();
String body = readBody(conn);

if (status != 200) {
throw new IllegalStateException("Failed to upload repository: repository_key=" + repositoryKey + ", status=" + status + ", response=" + body);
}
Expand All @@ -181,11 +178,10 @@ private static void dropRepository(URI apiUri, String bearer, String repositoryK
conn.setConnectTimeout(CONNECTION_TIMEOUT);
conn.setReadTimeout(CONNECTION_TIMEOUT);
conn.setRequestMethod("DELETE");
conn.setRequestProperty("Authorization", bearer);
conn.setRequestProperty("Authorization", "Bearer " + bearer);

int status = conn.getResponseCode();
String body = readBody(conn);

if (status != 204) {
throw new IllegalStateException("Failed to drop repository: repository_key=" + repositoryKey + ", status=" + status + ", response=" + body);
}
Expand All @@ -195,17 +191,20 @@ private static String readBody(HttpURLConnection conn) throws IOException {
InputStream stream;
try {
stream = (conn.getResponseCode() < 400) ? conn.getInputStream() : conn.getErrorStream();
if (stream == null) return "";
if (stream == null) {
return "";
}
} catch (IOException e) {
return "";
}
BufferedReader in = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8));

StringBuilder body = new StringBuilder();
String line;
while ((line = in.readLine()) != null) {
body.append(line);
try (BufferedReader in = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))) {
String line;
while ((line = in.readLine()) != null) {
body.append(line);
}
}
in.close();
return body.toString();
}
}
9 changes: 0 additions & 9 deletions java/dfp-math/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import com.epam.deltix.buildsrc.SonatypeCentralPortalUploadRepositoryTask

ext.isReleaseVersion = !version.endsWith("SNAPSHOT")

apply plugin: 'java'
Expand Down Expand Up @@ -111,13 +109,6 @@ publishing {
}
}

tasks.register('uploadArtifactsToCentralPortal', SonatypeCentralPortalUploadRepositoryTask) {
portalUsername.set(rUser)
portalPassword.set(rPass)
groupId.set('com.epam.deltix')
snapshotRelease.set(!isReleaseVersion)
}

if (isReleaseVersion) {
signing {
def signingKey = findProperty('SIGNING_PRIVATE_KEY') ?: System.getenv('SIGNING_PRIVATE_KEY') ?: "FakeUser"
Expand Down
9 changes: 0 additions & 9 deletions java/dfp/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import com.epam.deltix.buildsrc.SonatypeCentralPortalUploadRepositoryTask

ext.isReleaseVersion = !version.endsWith("SNAPSHOT")

apply plugin: 'java'
Expand Down Expand Up @@ -116,13 +114,6 @@ publishing {
}
}

tasks.register('uploadArtifactsToCentralPortal', SonatypeCentralPortalUploadRepositoryTask) {
portalUsername.set(rUser)
portalPassword.set(rPass)
groupId.set('com.epam.deltix')
snapshotRelease.set(!isReleaseVersion)
}

if (isReleaseVersion) {
signing {
def signingKey = findProperty('SIGNING_PRIVATE_KEY') ?: System.getenv('SIGNING_PRIVATE_KEY') ?: "FakeUser"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ public static boolean isIdentical(@Decimal final long a, final Object b) {
*/
public static boolean equals(@Decimal final long a, final Object b) {
return (b == null && NULL == a)
|| (b instanceof Decimal64 && equals(a, ((Decimal64) b).value));
|| (b instanceof Decimal64 && equals(a, ((Decimal64) b).value))
|| (b instanceof Long && equals(a, (long) b));
}

/**
Expand Down
13 changes: 13 additions & 0 deletions java/dfp/src/test/java/com/epam/deltix/dfp/JavaImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.math.MathContext;
import java.math.RoundingMode;
import java.security.SecureRandom;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

import static com.epam.deltix.dfp.Decimal64Utils.*;
Expand Down Expand Up @@ -1099,4 +1101,15 @@ public void issue91ToFloatString() throws IOException {
}
}
}

@Test
public void issue110BoxedEquals() {
Map<String, Long> cache = new HashMap<>();
@Decimal long val = Decimal64Utils.fromDouble(0.5);
cache.put("val", val);
@Decimal long val2 = Decimal64Utils.fromDouble(0.5);
assertTrue(val2 == cache.get("val"));
assertTrue(Decimal64Utils.compareTo(val2, cache.get("val")) == 0);
assertTrue(Decimal64Utils.equals(val2, cache.get("val")));
}
}