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

Update project to JDK 22 and JEP 454 #61

Merged
merged 8 commits into from
Mar 21, 2024
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: 21
java-version: 22
distribution: 'zulu'
cache: 'maven'
- name: Setup fuse
Expand All @@ -35,7 +35,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: 21
java-version: 22
distribution: 'zulu'
cache: 'maven'
- name: Setup fuse
Expand All @@ -59,7 +59,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: 21
java-version: 22
distribution: 'zulu'
cache: 'maven'
- name: Setup fuse
Expand All @@ -83,7 +83,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-java@v4
with:
java-version: 21
java-version: 22
distribution: 'zulu'
cache: 'maven'
- name: Cache SonarCloud packages
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-central.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
ref: "refs/tags/${{ github.event.inputs.tag }}"
- uses: actions/setup-java@v4
with:
java-version: 21
java-version: 22
distribution: 'zulu'
cache: 'maven'
server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml
Comment on lines 15 to 21
Copy link

@coderabbitai coderabbitai bot Mar 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [27-27]

Using variable interpolation ${{...}} with github context data in a run: step could potentially introduce security risks. Consider using an intermediate environment variable to store the data and use it in the run: script.

- run: mvn versions:set -B -DnewVersion=${{ github.event.inputs.tag }}
+ env:
+   TAG_VERSION: ${{ github.event.inputs.tag }}
+ run: mvn versions:set -B -DnewVersion="$TAG_VERSION"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good hint, but out of scope of this PR

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@overheadhunter, understood and respect your decision on the scope of this PR. The security aspect of variable interpolation is indeed important, but addressing it at the right time is equally crucial. Would you like me to open a GitHub issue to track this for future consideration? This way, it won't be forgotten and can be addressed when it's more appropriate.

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-github.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: 21
java-version: 22
distribution: 'zulu'
cache: 'maven'
gpg-private-key: ${{ secrets.RELEASES_GPG_PRIVATE_KEY }} # Value of the GPG private key to import
Expand Down
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/HelloWorldFileSystem.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/HelloWorldFileSystem__Windows_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/PosixMirrorFileSystem__Linux_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/PosixMirrorFileSystem__fuse_t_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/RandomFileSystem.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/WindowsMirrorFileSystem.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

# jFUSE

Zero-Dependency Java bindings for FUSE using [JEP 442](https://openjdk.org/jeps/442).
Zero-Dependency Java bindings for FUSE using [JEP 454](https://openjdk.org/jeps/454).

## Status

This is currently an experimental library requiring JDK 21. As long as the [Foreign Function & Memory API](https://openjdk.org/jeps/442) is incubating, the required JDK will increase.
Older JDK versions are *not supported*. Please refer to an older version of this lib, if you are interested in using it with an older JDK. Older versions will not receive patches or any kind of support, though!
This lib makes use of the [Foreign Function & Memory API](https://openjdk.org/jeps/454), requiring at least JDK 22.
Older JDK versions are *not supported*. Please refer to an older version of this lib, if you are interested in using it with an older JDK (with `--enable-preview`). Older versions will not receive patches or any kind of support, though!

We attempt to support libfuse 3.x on Linux and Windows while also remaining compatible with libfuse 2.x on macOS, leading to some compromises in the API.

Expand Down Expand Up @@ -97,7 +97,6 @@ During runtime, you will need to add allow native access from platform-specific
java -p path/to/mods \
-m com.example.mymodule/com.example.mymodule \
--enable-native-access=org.cryptomator.jfuse.mac \
--enable-preview
```

## Supported Platforms
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class MemoryUtils {

@Nullable
public static String toUtf8StringOrNull(MemorySegment string, long offset) {
return MemorySegment.NULL.equals(string) ? null : string.getUtf8String(offset);
return MemorySegment.NULL.equals(string) ? null : string.getString(offset);
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class MemoryUtilsTest {
void testValidSegmentReturnsString() {
try (var arena = Arena.ofConfined()) {
var address = arena.allocate(4);
address.setUtf8String(0, "abc");
address.setString(0, "abc");
String result = MemoryUtils.toUtf8StringOrNull(address);
Assertions.assertEquals("abc", result);
}
Expand All @@ -26,7 +26,7 @@ void testValidSegmentReturnsString() {
void testValidSegmentReturnsStringAtOffset() {
try (var arena = Arena.ofConfined()) {
var address = arena.allocate(10);
address.setUtf8String(5, "abc");
address.setString(5, "abc");
String result = MemoryUtils.toUtf8StringOrNull(address, 5);
Assertions.assertEquals("abc", result);
}
Expand Down
2 changes: 1 addition & 1 deletion jfuse-examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Assuming you have built the parent project (`mvn package`), you can run these examples directly from the shell.

These examples require JDK 19 or newer. You may want to adjust paths, such as the `java.library.path`.
These examples require JDK 22 or newer. You may want to adjust paths, such as the `java.library.path`.

### Running the hello world example:

Expand Down
4 changes: 2 additions & 2 deletions jfuse-linux-aarch64/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>@{surefire.jacoco.args} -javaagent:${net.bytebuddy:byte-buddy-agent:jar} --enable-preview --enable-native-access=org.cryptomator.jfuse.linux.aarch64</argLine>
<argLine>@{surefire.jacoco.args} -javaagent:${net.bytebuddy:byte-buddy-agent:jar} --enable-native-access=org.cryptomator.jfuse.linux.aarch64</argLine>
</configuration>
</plugin>
</plugins>
Expand Down Expand Up @@ -81,7 +81,7 @@
<plugin>
<groupId>io.github.coffeelibs</groupId>
<artifactId>jextract-maven-plugin</artifactId>
<version>0.3.0</version>
<version>0.4.0</version>
<configuration>
<executable>/Users/sebastian/git/github.com/openjdk/jextract/build/jextract/bin/jextract</executable>
<headerSearchPaths>${linux.headerSearchPath}</headerSearchPaths>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@
import java.lang.foreign.MemorySegment;
import java.util.function.Consumer;

record DirFillerImpl(MemorySegment buf, fuse_fill_dir_t callback, Arena arena) implements DirFiller {

DirFillerImpl(MemorySegment buf, MemorySegment callback, Arena arena) {
this(buf, fuse_fill_dir_t.ofAddress(callback, arena), arena);
}
record DirFillerImpl(MemorySegment buf, MemorySegment callback, Arena arena) implements DirFiller {

@Override
public int fill(String name, Consumer<Stat> statFiller, long offset, int flags) {
var statSegment = stat.allocate(arena);
statFiller.accept(new StatImpl(statSegment));
return callback.apply(buf, arena.allocateUtf8String(name), statSegment, offset, flags);
return fuse_fill_dir_t.invoke(callback, buf, arena.allocateFrom(name), statSegment, offset, flags);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.cryptomator.jfuse.linux.aarch64.extr.fuse3.fuse_file_info;
import org.jetbrains.annotations.Nullable;

import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
import java.nio.file.StandardOpenOption;
import java.util.EnumSet;
Expand All @@ -24,34 +23,29 @@ record FileInfoImpl(MemorySegment segment) implements FileInfo {
private static final int O_DSYNC = fcntl_h.O_DSYNC();

/**
* Factory method to map native memory to an {@link FileInfo} object
* Null-safe factory method to map native memory to an {@link FileInfo} object
*
* @param address the {@link MemorySegment} representing the starting address
* @param scope the {@link Arena} in which this object will be alive
* @return an {@link FileInfo} object or {@code null} if {@code address} is a NULL pointer
*/
@Nullable
public static FileInfoImpl of(MemorySegment address, Arena scope) {
return MemorySegment.NULL.equals(address) ? null : new FileInfoImpl(address, scope);
}

public FileInfoImpl(MemorySegment address, Arena scope) {
this(fuse_file_info.ofAddress(address, scope));
public static FileInfoImpl ofNullable(MemorySegment address) {
return MemorySegment.NULL.equals(address) ? null : new FileInfoImpl(address);
}

@Override
public long getFh() {
return fuse_file_info.fh$get(segment);
return fuse_file_info.fh(segment);
}

@Override
public void setFh(long fh) {
fuse_file_info.fh$set(segment, fh);
fuse_file_info.fh(segment, fh);
}

@Override
public int getFlags() {
return fuse_file_info.flags$get(segment);
return fuse_file_info.flags(segment);
}

@Override
Expand Down Expand Up @@ -91,7 +85,7 @@ public Set<StandardOpenOption> getOpenFlags() {

@Override
public long getLockOwner() {
return fuse_file_info.lock_owner$get(segment);
return fuse_file_info.lock_owner(segment);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,35 @@ record FuseArgs(MemorySegment args, MemorySegment cmdLineOpts) {
@Override
public String toString() {
var sb = new StringBuilder();
var argc = fuse_args.argc$get(args);
var argv = fuse_args.argv$get(args);
var argc = fuse_args.argc(args);
var argv = fuse_args.argv(args);
for (int i = 0; i < argc; i++) {
var cString = argv.getAtIndex(ValueLayout.ADDRESS, i).reinterpret(Long.MAX_VALUE);
sb.append("arg[").append(i).append("] = ").append(cString.getUtf8String(0)).append(", ");
sb.append("arg[").append(i).append("] = ").append(cString.getString(0)).append(", ");
}
sb.append("mountPoint = ").append(mountPoint().getUtf8String(0));
sb.append("debug = ").append(fuse_cmdline_opts.debug$get(cmdLineOpts));
sb.append("mountPoint = ").append(mountPoint().getString(0));
sb.append("debug = ").append(fuse_cmdline_opts.debug(cmdLineOpts));
sb.append("singlethreaded = ").append(!multithreaded());
return sb.toString();
}

public MemorySegment mountPoint() {
return fuse_cmdline_opts.mountpoint$get(cmdLineOpts);
return fuse_cmdline_opts.mountpoint(cmdLineOpts);
}

public boolean multithreaded() {
return fuse_cmdline_opts.singlethread$get(cmdLineOpts) == 0;
return fuse_cmdline_opts.singlethread(cmdLineOpts) == 0;
}

public int cloneFd() {
return fuse_cmdline_opts.clone_fd$get(cmdLineOpts);
return fuse_cmdline_opts.clone_fd(cmdLineOpts);
}

public int maxIdleThreads() {
return fuse_cmdline_opts.max_idle_threads$get(cmdLineOpts);
return fuse_cmdline_opts.max_idle_threads(cmdLineOpts);
}

public int maxThreads() {
return fuse_cmdline_opts.max_threads$get(cmdLineOpts);
return fuse_cmdline_opts.max_threads(cmdLineOpts);
}
}
Loading