Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(bindings/java): prepare for automatically multiple platform deploy #2335

Merged
merged 32 commits into from
May 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
39b2ab9
stick to JDK 8
tisonkun May 25, 2023
c7ca7f4
tmp disable other workflows
tisonkun May 25, 2023
98c0097
try auto deploy
tisonkun May 25, 2023
8624033
tmp add this branch
tisonkun May 25, 2023
386969f
try add token
tisonkun May 25, 2023
9f5dca2
simplify properties resolve logic
tisonkun May 26, 2023
b9522f8
build with script
tisonkun May 26, 2023
0e2e73a
correct script
tisonkun May 26, 2023
fedec64
support cross compile for darwin
tisonkun May 26, 2023
e65bda0
deploy profile
tisonkun May 26, 2023
a4441ba
fixup
tisonkun May 26, 2023
8ba67a1
add support for more platforms
tisonkun May 26, 2023
9c9655d
fix typo
tisonkun May 26, 2023
e60aa7c
workaround pwsh issue
tisonkun May 26, 2023
b6b3cd4
add py dep
tisonkun May 26, 2023
088d129
workaround windows
tisonkun May 26, 2023
ea4970c
skip tests
tisonkun May 26, 2023
b0313fb
improve docs
tisonkun May 26, 2023
1a6b1f3
try with github package
tisonkun May 26, 2023
73253ef
add github repo info
tisonkun May 26, 2023
0a5857e
update meta
tisonkun May 26, 2023
e4ba7bd
Revert "tmp disable other workflows"
tisonkun May 26, 2023
d11e061
revert trigger
tisonkun May 26, 2023
c42114a
add docs
tisonkun May 26, 2023
d464cdc
fix license headers
tisonkun May 26, 2023
cd1a719
Merge branch 'main' into try-github-packages
tisonkun May 26, 2023
a44fee0
fix typo
tisonkun May 26, 2023
a9c1fec
fix classifier
tisonkun May 26, 2023
c3a1dc4
jar without classifier should produce a unknown result
tisonkun May 27, 2023
e301def
drop GH related stuff
tisonkun May 27, 2023
e0ee8fc
ci: trigger for core changes
tisonkun May 27, 2023
b19cb26
drop more GH things
tisonkun May 27, 2023
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
5 changes: 3 additions & 2 deletions .github/workflows/bindings_java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ on:
branches:
- main
paths:
- "core/**"
- "bindings/java/**"
- ".github/workflows/bindings_java.yml"
workflow_dispatch:
Expand All @@ -43,11 +44,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'
java-version: '8'
cache: 'maven'
- name: Build and test
working-directory: bindings/java
Expand Down
97 changes: 27 additions & 70 deletions bindings/java/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
# OpenDAL Java Bindings

## Usage

You can use the package by adding the dependency as following:

```xml
<dependencies>
<dependency>
<groupId>org.apache.opendal</groupId>
<artifactId>opendal-java</artifactId>
<version>0.1.0-SNAPSHOT</version>
<classifier>${os.detected.classifier}</classifier>
</dependency>
</dependencies>

<build>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.7.0</version>
</extension>
</extensions>
</build>
```

## Build

This project provides OpenDAL Java bindings with artifact name `opendal-java`. It depends on JDK 8 or later.

Thanks to [rust-maven-plugin](https://github.com/questdb/rust-maven-plugin), we can use Maven to build both Rust dynamic lib and JAR files with one command now:
You can use Maven to build both Rust dynamic lib and JAR files with one command now:

```shell
mvn clean package
mvn clean package -DskipTests=true
```

## Run tests
Expand All @@ -20,74 +45,6 @@ You can run tests with the following command:
mvn clean verify
```

## Deploy snapshots

To deploy snapshots, you need to configure your GPG signing key and loacl Maven settings.

### GPG

1. Download GPG from http://www.gnupg.org/download/ or any other method.
2. Generate [PGP code signing keys](https://infra.apache.org/release-signing.html#generate).

> **Note**: When doing a release you will be asked for your PGP password multiple times unless you set up the gpg-agent. Mac users have reported trouble getting gpg-agent to work. You can also set your gpg-password in the Maven settings file (see below).

### Maven Settings

Your Maven settings (`$HOME/.m2/settings.xml`) file should have the following:

```xml
<settings>
...
<servers>
...
<server>
<id>apache.website.svnpub</id>
<username>Your Apache Username</username>
<privateKey>${user.home}/.ssh/id_rsa</privateKey>
</server>

<server>
<id>apache.releases.https</id>
<username>Your Apache Username</username>
<password>APACHE-PASSWORD-ENCODED</password>
</server>

<server>
<id>apache.snapshots.https</id>
<username>Your Apache Username</username>
<password>APACHE-PASSWORD-ENCODED</password>
</server>
...
</servers>

<profiles>
<profile>
<properties>
...
<gpg.keyname>id-of-your-pgp-key</gpg.keyname>
<gpg.passphrase>your-pgp-password</gpg.passphrase> <!-- use this if gpg-agent doesn't work for you -->
...
</properties>
...
</profile>
...
</profiles>
...
</settings>
```

> **Note**: You can store encrypted passwords your settings.xml if you want. Read the details here: http://maven.apache.org/guides/mini/guide-encryption.html

### Deploy

Thanks to the [ASF Parent POM](https://maven.apache.org/pom/asf/), deploy a snapshot version requires only an oneliner:

```shell
mvn -P apache-release deploy
```

> **Note**: Please ensure that the project version of `opendal-java` in the `pom.xml` file ends with `-SNAPSHOT`.

## Todos

- [ ] ReadMe for usage
Expand Down
82 changes: 25 additions & 57 deletions bindings/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@
<properties>
<!-- This value is for Reproducible Builds. It will be updated by Maven Release Plugin during releases. -->
<project.build.outputTimestamp>10</project.build.outputTimestamp>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<questdb.version>1.0.0</questdb.version>
<!-- Use camelCase instead of separating by dots to workaround PowerShell parsing. -->
<jniClassifier>${os.detected.classifier}</jniClassifier>

<questdb.version>1.0.0</questdb.version>
<maven-surefire-plugin.version>3.0.0</maven-surefire-plugin.version>

<build-helper-maven-plugin.version>3.3.0</build-helper-maven-plugin.version>
<exec-maven-plugin.version>3.1.0</exec-maven-plugin.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -109,6 +109,12 @@
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
Expand All @@ -126,22 +132,23 @@

<plugins>
<plugin>
<groupId>org.questdb</groupId>
<artifactId>rust-maven-plugin</artifactId>
<version>${questdb.version}</version>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<version>${exec-maven-plugin.version}</version>
<executions>
<execution>
<id>opendal-java</id>
<id>compile-native-code</id>
<phase>compile</phase>
<goals>
<goal>build</goal>
<goal>exec</goal>
</goals>
<configuration>
<path>${project.basedir}</path>
<release>true</release>
<copyTo>${project.build.directory}/classes/native/${os.detected.classifier}</copyTo>
<extraArgs>
<extraArg>--color=always</extraArg>
</extraArgs>
<executable>python3</executable>
<arguments>
<argument>${project.basedir}/tools/build.py</argument>
<argument>--classifier</argument>
<argument>${jniClassifier}</argument>
</arguments>
</configuration>
</execution>
</executions>
Expand All @@ -151,46 +158,6 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>prepare-filtered-java-source</id>
<goals>
<goal>copy-resources</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<outputDirectory>${project.build.directory}/generated-sources/java</outputDirectory>
<resources>
<resource>
<directory>src/main/java-filtered</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${build-helper-maven-plugin.version}</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand All @@ -200,6 +167,7 @@
<id>default-jar</id>
<configuration>
<excludes>
<exclude>bindings.properties</exclude>
<exclude>native/**</exclude>
</excludes>
</configuration>
Expand All @@ -211,7 +179,7 @@
<goal>jar</goal>
</goals>
<configuration>
<classifier>${os.detected.classifier}</classifier>
<classifier>${jniClassifier}</classifier>
</configuration>
</execution>
</executions>
Expand Down

This file was deleted.

64 changes: 64 additions & 0 deletions bindings/java/src/main/java/org/apache/opendal/Environment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.opendal;

import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.util.Properties;

public enum Environment {
INSTANCE;

public static final String UNKNOWN = "<unknown>";
private String classifier = UNKNOWN;
private String projectVersion = UNKNOWN;

static {
ClassLoader classLoader = Environment.class.getClassLoader();
try (InputStream is = classLoader.getResourceAsStream("bindings.properties")) {
final Properties properties = new Properties();
properties.load(is);
INSTANCE.classifier = properties.getProperty("jniClassifier", UNKNOWN);
INSTANCE.projectVersion = properties.getProperty("project.version", UNKNOWN);
} catch (IOException e) {
throw new UncheckedIOException("cannot load environment properties file", e);
}
}

/**
* Returns the classifier of the compiled environment.
*
* @return The classifier of the compiled environment.
*/
public static String getClassifier() {
return INSTANCE.classifier;
}

/**
* Returns the version of the code as String.
*
* @return The project version string.
*/
public static String getVersion() {
return INSTANCE.projectVersion;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ public static void loadLibrary() {
}

if (libraryLoaded.compareAndSet(LibraryState.NOT_LOADED, LibraryState.LOADING)) {
JarJniLoader.loadLib(NativeObject.class, "/native", "opendal_java", Platform.CLASSIFIER);
JarJniLoader.loadLib(
NativeObject.class,
"/native",
"opendal_java",
Environment.getClassifier());
libraryLoaded.set(LibraryState.LOADED);
return;
}
Expand Down
19 changes: 19 additions & 0 deletions bindings/java/src/main/resources/bindings.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

jniClassifier=${jniClassifier}
project.version=${project.version}
Loading