Skip to content

Commit aaedccc

Browse files
Merge branch 'dev-latest' into sync
2 parents db83eb6 + b552b74 commit aaedccc

File tree

40 files changed

+1025
-134
lines changed

40 files changed

+1025
-134
lines changed

Jenkinsfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ pipeline {
2222
"-PpreferredUsername=$MVN_REPO_LOGIN_USR " +
2323
"-PpreferredPassword=$MVN_REPO_LOGIN_PSW " +
2424
"-PversionPostFix=$versionPostfix"
25+
// Note: for key use Jenkins secret file with PGP key as text in ASCII-armored format.
26+
ORG_GRADLE_PROJECT_signingKeyFile = credentials('objectbox_signing_key')
27+
ORG_GRADLE_PROJECT_signingKeyId = credentials('objectbox_signing_key_id')
28+
ORG_GRADLE_PROJECT_signingPassword = credentials('objectbox_signing_key_password')
2529
}
2630

2731
options {
@@ -54,6 +58,7 @@ pipeline {
5458
"--tests io.objectbox.FunctionalTestSuite " +
5559
"--tests io.objectbox.test.proguard.ObfuscatedEntityTest " +
5660
"--tests io.objectbox.rx.QueryObserverTest " +
61+
"--tests io.objectbox.rx3.QueryObserverTest " +
5762
"spotbugsMain assemble"
5863
}
5964
}

build.gradle

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
buildscript {
22
ext {
33
// Typically, only edit those two:
4-
def objectboxVersionNumber = '2.5.2' // without "-SNAPSHOT", e.g. '2.5.0' or '2.4.0-RC'
4+
def objectboxVersionNumber = '2.6.0' // without "-SNAPSHOT", e.g. '2.5.0' or '2.4.0-RC'
55
def objectboxVersionRelease = false // set to true for releasing to ignore versionPostFix to avoid e.g. "-dev" versions
66

77
// version post fix: '-<value>' or '' if not defined; e.g. used by CI to pass in branch name
@@ -20,6 +20,9 @@ buildscript {
2020
ob_native_dep = "io.objectbox:objectbox-$objectboxPlatform:$nativeVersion"
2121

2222
junit_version = '4.13'
23+
mockito_version = '3.3.3'
24+
kotlin_version = '1.3.72'
25+
dokka_version = '0.10.1'
2326

2427
println "version=$ob_version"
2528
println "objectboxNativeDependency=$ob_native_dep"
@@ -34,6 +37,8 @@ buildscript {
3437
}
3538

3639
dependencies {
40+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
41+
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
3742
classpath "gradle.plugin.com.github.spotbugs.snom:spotbugs-gradle-plugin:4.0.5"
3843
}
3944
}
@@ -64,9 +69,16 @@ def projectNamesToPublish = [
6469
'objectbox-java-api',
6570
'objectbox-java',
6671
'objectbox-kotlin',
67-
'objectbox-rxjava'
72+
'objectbox-rxjava',
73+
'objectbox-rxjava3'
6874
]
6975

76+
def hasSigningProperties() {
77+
return (project.hasProperty('signingKeyId')
78+
&& project.hasProperty('signingKeyFile')
79+
&& project.hasProperty('signingPassword'))
80+
}
81+
7082
configure(subprojects.findAll { projectNamesToPublish.contains(it.name) }) {
7183
apply plugin: 'maven'
7284
apply plugin: 'signing'
@@ -82,8 +94,9 @@ configure(subprojects.findAll { projectNamesToPublish.contains(it.name) }) {
8294
}
8395

8496
signing {
85-
if (project.hasProperty('signing.keyId') && project.hasProperty('signing.password') &&
86-
project.hasProperty('signing.secretKeyRingFile')) {
97+
if (hasSigningProperties()) {
98+
String signingKey = new File(signingKeyFile).text
99+
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
87100
sign configurations.archives
88101
} else {
89102
println "Signing information missing/incomplete for ${project.name}"
@@ -104,6 +117,10 @@ configure(subprojects.findAll { projectNamesToPublish.contains(it.name) }) {
104117
} else if (preferredRepo != null
105118
&& project.hasProperty('preferredUsername')
106119
&& project.hasProperty('preferredPassword')) {
120+
if (!hasSigningProperties()) {
121+
throw new InvalidUserDataException("To upload to repo signing is required.")
122+
}
123+
107124
configuration = configurations.deployerJars
108125

109126
// replace placeholders
@@ -129,7 +146,7 @@ configure(subprojects.findAll { projectNamesToPublish.contains(it.name) }) {
129146

130147
println "Uploading archives to $sonatypeRepositoryUrl."
131148
} else {
132-
println "WARNING: preferredRepo NOT set, can not upload archives."
149+
println "WARNING: preferredRepo or credentials NOT set, can not upload archives."
133150
}
134151

135152
pom.project {

objectbox-java-api/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
apply plugin: 'java'
1+
apply plugin: 'java-library'
22

33
sourceCompatibility = JavaVersion.VERSION_1_8
44
targetCompatibility = JavaVersion.VERSION_1_8
55

66
task javadocJar(type: Jar, dependsOn: javadoc) {
7-
classifier = 'javadoc'
7+
archiveClassifier.set('javadoc')
88
from 'build/docs/javadoc'
99
}
1010

1111
task sourcesJar(type: Jar) {
1212
from sourceSets.main.allSource
13-
classifier = 'sources'
13+
archiveClassifier.set('sources')
1414
}
1515

1616
artifacts {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package io.objectbox.annotation;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
/**
9+
* Defines the Java code of the default value to use for a property, when getting an existing entity and the database
10+
* value for the property is null.
11+
* <p>
12+
* Currently only {@code @DefaultValue("")} is supported.
13+
*/
14+
@Retention(RetentionPolicy.CLASS)
15+
@Target({ElementType.FIELD})
16+
public @interface DefaultValue {
17+
String value();
18+
}

objectbox-java/build.gradle

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
apply plugin: 'java'
1+
apply plugin: 'java-library'
22
apply plugin: "com.github.spotbugs"
33

44
sourceCompatibility = JavaVersion.VERSION_1_8
55
targetCompatibility = JavaVersion.VERSION_1_8
66

77
dependencies {
8-
compile fileTree(include: ['*.jar'], dir: 'libs')
9-
compile project(':objectbox-java-api')
10-
compile 'org.greenrobot:essentials:3.0.0-RC1'
11-
compile 'com.google.flatbuffers:flatbuffers-java:1.11.1'
12-
compile 'com.google.code.findbugs:jsr305:3.0.2'
8+
api project(':objectbox-java-api')
9+
implementation 'org.greenrobot:essentials:3.0.0-RC1'
10+
implementation 'com.google.flatbuffers:flatbuffers-java:1.12.0'
11+
api 'com.google.code.findbugs:jsr305:3.0.2'
1312
}
1413

1514
spotbugs {
@@ -102,13 +101,13 @@ task packageJavadocForWeb(type: Zip, dependsOn: javadocForWeb) {
102101
}
103102

104103
task javadocJar(type: Jar, dependsOn: javadoc) {
105-
classifier = 'javadoc'
104+
archiveClassifier.set('javadoc')
106105
from 'build/docs/javadoc'
107106
}
108107

109108
task sourcesJar(type: Jar) {
110109
from sourceSets.main.allSource
111-
classifier = 'sources'
110+
archiveClassifier.set('sources')
112111
}
113112

114113
artifacts {

objectbox-java/src/main/java/io/objectbox/BoxStore.java

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,31 @@
6262
public class BoxStore implements Closeable {
6363

6464
/** On Android used for native library loading. */
65-
@Nullable public static Object context;
66-
@Nullable public static Object relinker;
65+
@Nullable private static Object context;
66+
@Nullable private static Object relinker;
6767

6868
/** Change so ReLinker will update native library when using workaround loading. */
69-
public static final String JNI_VERSION = "2.5.1";
69+
public static final String JNI_VERSION = "2.6.0-RC";
7070

71-
private static final String VERSION = "2.5.2-2020-02-10";
71+
private static final String VERSION = "2.6.0-2020-04-30";
7272
private static BoxStore defaultStore;
7373

7474
/** Currently used DB dirs with values from {@link #getCanonicalPath(File)}. */
7575
private static final Set<String> openFiles = new HashSet<>();
7676
private static volatile Thread openFilesCheckerThread;
7777

78+
@Nullable
79+
@Internal
80+
public static synchronized Object getContext() {
81+
return context;
82+
}
83+
84+
@Nullable
85+
@Internal
86+
public static synchronized Object getRelinker() {
87+
return relinker;
88+
}
89+
7890
/**
7991
* Convenience singleton instance which gets set up using {@link BoxStoreBuilder#buildDefault()}.
8092
* <p>
@@ -304,16 +316,19 @@ static boolean isFileOpen(final String canonicalPath) {
304316
synchronized (openFiles) {
305317
if (!openFiles.contains(canonicalPath)) return false;
306318
}
307-
if (openFilesCheckerThread == null || !openFilesCheckerThread.isAlive()) {
319+
Thread checkerThread = BoxStore.openFilesCheckerThread;
320+
if (checkerThread == null || !checkerThread.isAlive()) {
308321
// Use a thread to avoid finalizers that block us
309-
openFilesCheckerThread = new Thread(() -> {
322+
checkerThread = new Thread(() -> {
310323
isFileOpenSync(canonicalPath, true);
311-
openFilesCheckerThread = null; // Clean ref to itself
324+
BoxStore.openFilesCheckerThread = null; // Clean ref to itself
312325
});
313-
openFilesCheckerThread.setDaemon(true);
314-
openFilesCheckerThread.start();
326+
checkerThread.setDaemon(true);
327+
328+
BoxStore.openFilesCheckerThread = checkerThread;
329+
checkerThread.start();
315330
try {
316-
openFilesCheckerThread.join(500);
331+
checkerThread.join(500);
317332
} catch (InterruptedException e) {
318333
e.printStackTrace();
319334
}

objectbox-java/src/main/java/io/objectbox/BoxStoreBuilder.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.io.OutputStream;
2828
import java.lang.reflect.Method;
2929
import java.util.ArrayList;
30+
import java.util.Arrays;
3031
import java.util.List;
3132

3233
import javax.annotation.Nonnull;
@@ -107,10 +108,11 @@ private BoxStoreBuilder() {
107108
/** Called internally from the generated class "MyObjectBox". Check MyObjectBox.builder() to get an instance. */
108109
@Internal
109110
public BoxStoreBuilder(byte[] model) {
110-
this.model = model;
111111
if (model == null) {
112112
throw new IllegalArgumentException("Model may not be null");
113113
}
114+
// Future-proofing: copy to prevent external modification.
115+
this.model = Arrays.copyOf(model, model.length);
114116
}
115117

116118
/**

objectbox-java/src/main/java/io/objectbox/DebugFlags.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 ObjectBox Ltd. All rights reserved.
2+
* Copyright 2020 ObjectBox Ltd. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.objectbox.converter;
2+
3+
import javax.annotation.Nullable;
4+
5+
/**
6+
* Used as a converter if a property is annotated with {@link io.objectbox.annotation.DefaultValue @DefaultValue("")}.
7+
*/
8+
public class NullToEmptyStringConverter implements PropertyConverter<String, String> {
9+
10+
@Override
11+
public String convertToDatabaseValue(String entityProperty) {
12+
return entityProperty;
13+
}
14+
15+
@Override
16+
public String convertToEntityProperty(@Nullable String databaseValue) {
17+
if (databaseValue == null) {
18+
return "";
19+
}
20+
return databaseValue;
21+
}
22+
}

objectbox-java/src/main/java/io/objectbox/internal/NativeLibraryLoader.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,22 +181,22 @@ private static void checkUnpackLib(String filename) {
181181
}
182182

183183
private static boolean loadLibraryAndroid() {
184-
if (BoxStore.context == null) {
184+
if (BoxStore.getContext() == null) {
185185
return false;
186186
}
187187

188188
//noinspection TryWithIdenticalCatches
189189
try {
190190
Class<?> context = Class.forName("android.content.Context");
191-
if (BoxStore.relinker == null) {
191+
if (BoxStore.getRelinker() == null) {
192192
// use default ReLinker
193193
Class<?> relinker = Class.forName("com.getkeepsafe.relinker.ReLinker");
194194
Method loadLibrary = relinker.getMethod("loadLibrary", context, String.class, String.class);
195-
loadLibrary.invoke(null, BoxStore.context, OBJECTBOX_JNI, BoxStore.JNI_VERSION);
195+
loadLibrary.invoke(null, BoxStore.getContext(), OBJECTBOX_JNI, BoxStore.JNI_VERSION);
196196
} else {
197197
// use custom ReLinkerInstance
198-
Method loadLibrary = BoxStore.relinker.getClass().getMethod("loadLibrary", context, String.class, String.class);
199-
loadLibrary.invoke(BoxStore.relinker, BoxStore.context, OBJECTBOX_JNI, BoxStore.JNI_VERSION);
198+
Method loadLibrary = BoxStore.getRelinker().getClass().getMethod("loadLibrary", context, String.class, String.class);
199+
loadLibrary.invoke(BoxStore.getRelinker(), BoxStore.getContext(), OBJECTBOX_JNI, BoxStore.JNI_VERSION);
200200
}
201201
} catch (NoSuchMethodException e) {
202202
return false;

0 commit comments

Comments
 (0)