Skip to content

Commit dff232e

Browse files
committed
Add natives module
1 parent ae5644b commit dff232e

5 files changed

Lines changed: 228 additions & 0 deletions

File tree

java/ceffx-natives/pom.xml

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>com.techsenger.ceffx</groupId>
6+
<artifactId>ceffx</artifactId>
7+
<version>1.0.0-SNAPSHOT</version>
8+
</parent>
9+
10+
<groupId>com.techsenger.ceffx</groupId>
11+
<artifactId>ceffx-natives</artifactId>
12+
<packaging>jar</packaging>
13+
<name>CEFFX - Natives</name>
14+
<description>Native libraries module</description>
15+
16+
<profiles>
17+
<profile>
18+
<id>linux</id>
19+
<activation>
20+
<os>
21+
<name>Linux</name>
22+
</os>
23+
</activation>
24+
<properties>
25+
<natives.classifier>linux</natives.classifier>
26+
<natives.lib.dir>${basedir}/../native/build/src/Release</natives.lib.dir>
27+
</properties>
28+
</profile>
29+
<profile>
30+
<id>mac</id>
31+
<activation>
32+
<os>
33+
<name>Mac OS X</name>
34+
<arch>x86_64</arch>
35+
</os>
36+
</activation>
37+
<properties>
38+
<natives.classifier>mac</natives.classifier>
39+
<natives.lib.dir>${basedir}/../native/build/src/Release</natives.lib.dir>
40+
</properties>
41+
</profile>
42+
<profile>
43+
<id>mac-aarch64</id>
44+
<activation>
45+
<os>
46+
<name>Mac OS X</name>
47+
<arch>aarch64</arch>
48+
</os>
49+
</activation>
50+
<properties>
51+
<natives.classifier>mac-aarch64</natives.classifier>
52+
<natives.lib.dir>${basedir}/../native/build/src/Release</natives.lib.dir>
53+
</properties>
54+
</profile>
55+
<profile>
56+
<id>windows</id>
57+
<activation>
58+
<os>
59+
<family>windows</family>
60+
</os>
61+
</activation>
62+
<properties>
63+
<natives.classifier>win</natives.classifier>
64+
<natives.lib.dir>${basedir}/../native/build/src/Release</natives.lib.dir>
65+
</properties>
66+
</profile>
67+
</profiles>
68+
69+
<build>
70+
<plugins>
71+
<plugin>
72+
<groupId>org.apache.maven.plugins</groupId>
73+
<artifactId>maven-resources-plugin</artifactId>
74+
<executions>
75+
<execution>
76+
<id>copy-native-libs</id>
77+
<phase>generate-resources</phase>
78+
<goals>
79+
<goal>copy-resources</goal>
80+
</goals>
81+
<configuration>
82+
<outputDirectory>${project.build.outputDirectory}/native/libs</outputDirectory>
83+
<resources>
84+
<resource>
85+
<directory>${natives.lib.dir}</directory>
86+
<includes>
87+
<include>libceffx.so</include>
88+
<include>libceffx.dylib</include>
89+
<include>ceffx.dll</include>
90+
<include>ceffx_helper</include>
91+
<include>ceffx_helper.exe</include>
92+
<include>ceffx Helper.app/**</include>
93+
</includes>
94+
<filtering>false</filtering>
95+
</resource>
96+
</resources>
97+
</configuration>
98+
</execution>
99+
</executions>
100+
</plugin>
101+
<plugin>
102+
<groupId>org.apache.maven.plugins</groupId>
103+
<artifactId>maven-assembly-plugin</artifactId>
104+
<executions>
105+
<execution>
106+
<id>native-assembly</id>
107+
<phase>package</phase>
108+
<goals>
109+
<goal>single</goal>
110+
</goals>
111+
<configuration>
112+
<descriptors>
113+
<descriptor>src/assembly/native.xml</descriptor>
114+
</descriptors>
115+
<finalName>${project.artifactId}-${project.version}</finalName>
116+
<appendAssemblyId>true</appendAssemblyId>
117+
</configuration>
118+
</execution>
119+
</executions>
120+
</plugin>
121+
</plugins>
122+
</build>
123+
</project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">
4+
<id>${natives.classifier}</id>
5+
<formats>
6+
<format>jar</format>
7+
</formats>
8+
<includeBaseDirectory>false</includeBaseDirectory>
9+
<fileSets>
10+
<fileSet>
11+
<directory>${project.build.outputDirectory}</directory>
12+
<outputDirectory>/</outputDirectory>
13+
</fileSet>
14+
<fileSet>
15+
<directory>${basedir}/../../native/build/src/Release/</directory>
16+
<outputDirectory>native/libs</outputDirectory>
17+
<includes>
18+
<include>libceffx.so</include>
19+
<include>libceffx.dylib</include>
20+
<include>ceffx.dll</include>
21+
<include>ceffx_helper</include>
22+
<include>ceffx_helper.exe</include>
23+
<include>ceffx Helper.app/**</include>
24+
</includes>
25+
</fileSet>
26+
</fileSets>
27+
</assembly>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2026 Pavel Castornii.
3+
*
4+
* Licensed under the BSD 3-Clause License. See LICENSE file for details.
5+
*/
6+
7+
package com.techsenger.ceffx.natives;
8+
9+
import java.io.IOException;
10+
import java.net.URI;
11+
import java.net.URISyntaxException;
12+
import java.net.URL;
13+
import java.nio.file.FileSystem;
14+
import java.nio.file.FileSystems;
15+
import java.nio.file.Files;
16+
import java.nio.file.Path;
17+
import java.nio.file.StandardCopyOption;
18+
import java.util.Collections;
19+
import java.util.stream.Stream;
20+
21+
/**
22+
*
23+
* @author Pavel Castornii
24+
*/
25+
public final class NativeExtractor {
26+
27+
private NativeExtractor() {
28+
}
29+
30+
public static void extract(Path targetDir) throws IOException {
31+
Files.createDirectories(targetDir);
32+
URL resourceUrl = NativeExtractor.class.getResource("/native/libs");
33+
if (resourceUrl == null) {
34+
throw new IOException("Native libs not found in jar");
35+
}
36+
URI uri;
37+
try {
38+
uri = resourceUrl.toURI();
39+
} catch (URISyntaxException e) {
40+
throw new IOException("Failed to get URI for native libs", e);
41+
}
42+
if ("jar".equals(uri.getScheme())) {
43+
try (FileSystem fs = FileSystems.newFileSystem(uri, Collections.emptyMap())) {
44+
Path source = fs.getPath("/native/libs");
45+
copyDirectory(source, targetDir);
46+
}
47+
} else {
48+
copyDirectory(Path.of(uri), targetDir);
49+
}
50+
}
51+
52+
private static void copyDirectory(Path source, Path targetDir) throws IOException {
53+
try (Stream<Path> stream = Files.walk(source)) {
54+
for (Path entry : (Iterable<Path>) stream::iterator) {
55+
Path relative = source.relativize(entry);
56+
Path target = targetDir.resolve(relative.toString());
57+
if (Files.isDirectory(entry)) {
58+
Files.createDirectories(target);
59+
} else {
60+
Files.copy(entry, target, StandardCopyOption.REPLACE_EXISTING);
61+
if (!target.toString().endsWith(".dll") && !target.toString().endsWith(".plist")) {
62+
target.toFile().setExecutable(true);
63+
}
64+
}
65+
}
66+
}
67+
}
68+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright 2026 Pavel Castornii.
3+
*
4+
* Licensed under the BSD 3-Clause License. See LICENSE file for details.
5+
*/
6+
7+
module com.techsenger.ceffx.natives {
8+
exports com.techsenger.ceffx.natives;
9+
}

java/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,6 @@
9797
<modules>
9898
<module>ceffx-core</module>
9999
<module>ceffx-demo</module>
100+
<module>ceffx-natives</module>
100101
</modules>
101102
</project>

0 commit comments

Comments
 (0)