Skip to content

Commit

Permalink
secp-api/secp-bouncy: backport to Java 8
Browse files Browse the repository at this point in the history
* IDEs see modules as Java 9
* apiModuleJavaCompatibility property is used with org.beryx.jar Gradle
  plugin to create Java 8 JARs with module-info on official builds
* Remove all usages of Java 9 API

Developers of secp-jdk using IDEs will need to be aware that the
actual requirements are Java 8 API. But mistakes will be caught by
CI.
  • Loading branch information
msgilligan committed Feb 26, 2025
1 parent 4b49c82 commit 8d68d1d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ jobs:
- name: Install secp256k1 with Nix
run: nix profile install nixpkgs#secp256k1
- name: Build with Gradle
run: ./gradlew build
run: ./gradlew -PapiModuleJavaCompatibility=8 build
- name: Run Java & Kotlin Examples
run: ./gradlew run runEcdsa
run: ./gradlew -PapiModuleJavaCompatibility=8 run runEcdsa


build_nix:
Expand All @@ -59,4 +59,4 @@ jobs:
- name: Install secp256k1 with Nix
run: nix profile install nixpkgs#secp256k1
- name: Build in Nix development shell
run: nix develop -c gradle build run runEcdsa
run: nix develop -c gradle -PapiModuleJavaCompatibility=8 build run runEcdsa
4 changes: 2 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ nixos-devshell:
- echo "experimental-features = nix-command flakes" >> /etc/nix/nix.conf
- nix profile install nixpkgs#secp256k1
script:
- nix develop .#minimum -c gradle build run runEcdsa
- nix develop .#minimum -c gradle -PapiModuleJavaCompatibility=8 build run runEcdsa
cache:
key: "${CI_COMMIT_REF_SLUG}"
paths:
Expand All @@ -26,4 +26,4 @@ trixie-gradlew:
- echo "experimental-features = nix-command flakes" >> /etc/nix/nix.conf
- nix profile install nixpkgs#secp256k1
script:
- ./gradlew build run runEcdsa
- ./gradlew -PapiModuleJavaCompatibility=8 build run runEcdsa
7 changes: 6 additions & 1 deletion secp-api/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
plugins {
id 'java-library'
id 'org.beryx.jar' version '2.0.0'
}

tasks.withType(JavaCompile).configureEach {
options.release = 9
options.release = (findProperty('apiModuleJavaCompatibility') ?: 8) as int
}

ext.moduleName = 'org.bitcoinj.secp.api'

moduleConfig {
version = project.version
}

dependencies {
api("org.jspecify:jspecify:1.0.0")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Predicate;

/**
Expand Down Expand Up @@ -65,18 +66,22 @@ static Secp256k1Provider find() {
*/
static Optional<Secp256k1Provider> findFirst(Predicate<Secp256k1Provider> filter) {
ServiceLoader<Secp256k1Provider> loader = ServiceLoader.load(Secp256k1Provider.class);
return loader.stream()
.map(ServiceLoader.Provider::get)
.filter(filter)
.findFirst();
Secp256k1Provider provider = null;
for (Secp256k1Provider p : loader) {
if (filter.test(p)) {
provider = p;
break;
}
}
return Optional.ofNullable(provider);
}

/**
* Find the default provider. This is currently the "ffm" provider.
* @param provider a candidate provider
* @return true if it should be "found"
*/
private static boolean defaultFilter(Secp256k1Provider provider) {
/* private */ static boolean defaultFilter(Secp256k1Provider provider) {
return provider.name().equals("ffm");
}
}
7 changes: 6 additions & 1 deletion secp-bouncy/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
plugins {
id 'java-library'
id 'org.beryx.jar' version '2.0.0'
}

tasks.withType(JavaCompile).configureEach {
options.release = 9
options.release = (findProperty('apiModuleJavaCompatibility') ?: 9) as int
}

ext.moduleName = 'org.bitcoinj.secp.bouncy'

moduleConfig {
version = project.version
}

dependencies {
api project(':secp-api')
api 'org.bouncycastle:bcprov-jdk18on:1.78.1' // TODO: Make this a non-API dependency, see BouncyPrivKey
Expand Down

0 comments on commit 8d68d1d

Please sign in to comment.