Skip to content

Commit

Permalink
Merge pull request #1 from alexarchambault/develop
Browse files Browse the repository at this point in the history
Add bootstrap / lmcoursier / coursierapi modules
  • Loading branch information
alexarchambault authored Apr 13, 2021
2 parents 1e7f663 + 4118d82 commit 1bf85a7
Show file tree
Hide file tree
Showing 32 changed files with 658 additions and 161 deletions.
41 changes: 41 additions & 0 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,35 @@ object `windows-jni-utils` extends WindowsUtils with HasCSources with JniUtilsPu
def windowsJavaHome = sharedWindowsJavaHome()
}

object `windows-jni-utils-bootstrap` extends WindowsUtils with JniUtilsPublishModule {
def moduleDeps = Seq(
`windows-jni-utils`
)
}

object `windows-jni-utils-lmcoursier` extends WindowsUtils with JniUtilsPublishModule {
def moduleDeps = Seq(
`windows-jni-utils`
)
}

object `windows-jni-utils-coursierapi` extends WindowsUtils with JniUtilsPublishModule {
def moduleDeps = Seq(
`windows-jni-utils`
)
}

object `windows-jni-utils-tests` extends ScalaModule with JniUtilsPublishModule {
def scalaVersion = Scala.scala213
def moduleDeps = Seq(
`windows-jni-utils`
)
object test extends Tests {
def moduleDeps = super.moduleDeps ++ Seq(
`windows-jni-utils-bootstrap`,
`windows-jni-utils-lmcoursier`,
`windows-jni-utils-coursierapi`
)
def ivyDeps = Agg(
Deps.utest
)
Expand All @@ -36,6 +59,24 @@ object `windows-jni-utils-tests` extends ScalaModule with JniUtilsPublishModule
// compile these projects to generate or update JNI header files
object headers extends Module {
object `windows-jni-utils` extends WindowsUtils with GenerateHeaders
object `windows-jni-utils-bootstrap` extends WindowsUtils with GenerateHeaders {
def moduleDeps = Seq(
`windows-jni-utils`
)
def cDirectory = `windows-jni-utils`.cDirectory()
}
object `windows-jni-utils-lmcoursier` extends WindowsUtils with GenerateHeaders {
def moduleDeps = Seq(
`windows-jni-utils`
)
def cDirectory = `windows-jni-utils`.cDirectory()
}
object `windows-jni-utils-coursierapi` extends WindowsUtils with GenerateHeaders {
def moduleDeps = Seq(
`windows-jni-utils`
)
def cDirectory = `windows-jni-utils`.cDirectory()
}

implicit def millModuleBasePath: define.BasePath =
define.BasePath(super.millModuleBasePath.value / os.up)
Expand Down
7 changes: 5 additions & 2 deletions settings.sc
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ import org.codehaus.plexus.archiver.zip.ZipUnArchiver
import scala.concurrent.duration.Duration

trait GenerateHeaders extends JavaModule {
def cDirectory = T{
millSourcePath / "src" / "main" / "c"
}
def javacOptions = T{
val dest = millSourcePath / "src" / "main" / "c"
val dest = cDirectory()
Seq("-h", dest.toNIO.toAbsolutePath.toString)
}
def compile = T{
val res = super.compile()
val dir = millSourcePath / "src" / "main" / "c"
val dir = cDirectory()
val headerFiles = Seq(dir).flatMap { dir =>
if (os.isDir(dir))
os.walk(dir)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package coursier.bootstrap.launcher.jniutils;

import coursier.jniutils.LoadWindowsLibrary;
import coursier.jniutils.NativeApi;

public final class NativeCalls {

static native String terminalSizeNative();

static native String enableAnsiOutputNative();

static native byte[] GetUserEnvironmentVariableNative(byte[] key);
static native byte[] SetUserEnvironmentVariableNative(byte[] key, byte[] value);
static native byte[] DeleteUserEnvironmentVariableNative(byte[] key);

static native String GetKnownFolderPathNative(String rfid);


public static void setup() {
LoadWindowsLibrary.ensureInitialized();
NativeApi nativeApi = new NativeApi() {
public String terminalSize() {
return terminalSizeNative();
}

public String enableAnsiOutput() {
return enableAnsiOutputNative();
}

public byte[] GetUserEnvironmentVariable(byte[] key) {
return GetUserEnvironmentVariableNative(key);
}
public byte[] SetUserEnvironmentVariable(byte[] key, byte[] value) {
return SetUserEnvironmentVariableNative(key, value);
}
public byte[] DeleteUserEnvironmentVariable(byte[] key) {
return DeleteUserEnvironmentVariableNative(key);
}

public String GetKnownFolderPath(String rfid) {
return GetKnownFolderPathNative(rfid);
}
};
NativeApi.set(nativeApi);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package coursierapi.internal.jniutils;

import coursier.jniutils.LoadWindowsLibrary;
import coursier.jniutils.NativeApi;

public final class NativeCalls {

static native String terminalSizeNative();

static native String enableAnsiOutputNative();

static native byte[] GetUserEnvironmentVariableNative(byte[] key);
static native byte[] SetUserEnvironmentVariableNative(byte[] key, byte[] value);
static native byte[] DeleteUserEnvironmentVariableNative(byte[] key);

static native String GetKnownFolderPathNative(String rfid);


public static void setup() {
LoadWindowsLibrary.ensureInitialized();
NativeApi nativeApi = new NativeApi() {
public String terminalSize() {
return terminalSizeNative();
}

public String enableAnsiOutput() {
return enableAnsiOutputNative();
}

public byte[] GetUserEnvironmentVariable(byte[] key) {
return GetUserEnvironmentVariableNative(key);
}
public byte[] SetUserEnvironmentVariable(byte[] key, byte[] value) {
return SetUserEnvironmentVariableNative(key, value);
}
public byte[] DeleteUserEnvironmentVariable(byte[] key) {
return DeleteUserEnvironmentVariableNative(key);
}

public String GetKnownFolderPath(String rfid) {
return GetKnownFolderPathNative(rfid);
}
};
NativeApi.set(nativeApi);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package lmcoursier.internal.jniutils;

import coursier.jniutils.LoadWindowsLibrary;
import coursier.jniutils.NativeApi;

public final class NativeCalls {

static native String terminalSizeNative();

static native String enableAnsiOutputNative();

static native byte[] GetUserEnvironmentVariableNative(byte[] key);
static native byte[] SetUserEnvironmentVariableNative(byte[] key, byte[] value);
static native byte[] DeleteUserEnvironmentVariableNative(byte[] key);

static native String GetKnownFolderPathNative(String rfid);


public static void setup() {
LoadWindowsLibrary.ensureInitialized();
NativeApi nativeApi = new NativeApi() {
public String terminalSize() {
return terminalSizeNative();
}

public String enableAnsiOutput() {
return enableAnsiOutputNative();
}

public byte[] GetUserEnvironmentVariable(byte[] key) {
return GetUserEnvironmentVariableNative(key);
}
public byte[] SetUserEnvironmentVariable(byte[] key, byte[] value) {
return SetUserEnvironmentVariableNative(key, value);
}
public byte[] DeleteUserEnvironmentVariable(byte[] key) {
return DeleteUserEnvironmentVariableNative(key);
}

public String GetKnownFolderPath(String rfid) {
return GetKnownFolderPathNative(rfid);
}
};
NativeApi.set(nativeApi);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package coursier.jniutils

import coursier.jniutils.windowsansiterminal.WindowsAnsiTerminal

object AnsiTerminal {
def main(args: Array[String]): Unit = {
val verbose = args match {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package coursier.jniutils

import coursier.jniutils.windowsenvironmentvariables.WindowsEnvironmentVariables

object EnvironmentVariable {
def main(args: Array[String]): Unit =
args match {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package coursier.jniutils

import coursier.jniutils.windowsknownfolders.WindowsKnownFolders

object KnownFolders {
def main(args: Array[String]): Unit =
for (arg <- args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
package coursier.jniutils.tests

import coursier.jniutils.windowsknownfolders.WindowsKnownFolders
import coursier.jniutils.WindowsKnownFolders
import utest._

object WindowsKnownFoldersTests extends TestSuite {
val tests = Tests {
test {
test("default") synchronized {
coursier.jniutils.NativeApi.set(null);
WindowsKnownFolders.knownFolderPath("{3EB685DB-65F9-4CF6-A03A-E3EF65729F3D}")
}

test("bootstrap") synchronized {
coursier.bootstrap.launcher.jniutils.NativeCalls.setup()
WindowsKnownFolders.knownFolderPath("{3EB685DB-65F9-4CF6-A03A-E3EF65729F3D}")
}

test("lmcoursier") synchronized {
lmcoursier.internal.jniutils.NativeCalls.setup()
WindowsKnownFolders.knownFolderPath("{3EB685DB-65F9-4CF6-A03A-E3EF65729F3D}")
}

test("coursierapi") synchronized {
coursierapi.internal.jniutils.NativeCalls.setup()
WindowsKnownFolders.knownFolderPath("{3EB685DB-65F9-4CF6-A03A-E3EF65729F3D}")
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "coursier_bootstrap_launcher_jniutils_NativeCalls.h"
#include "coursier_jniutils_NativeCalls.h"

JNIEXPORT jstring JNICALL Java_coursier_bootstrap_launcher_jniutils_NativeCalls_terminalSizeNative
(JNIEnv *env, jclass class) {
return Java_coursier_jniutils_NativeCalls_terminalSizeNative(env, class);
}

JNIEXPORT jstring JNICALL Java_coursier_bootstrap_launcher_jniutils_NativeCalls_enableAnsiOutputNative
(JNIEnv *env, jclass class) {
return Java_coursier_jniutils_NativeCalls_enableAnsiOutputNative(env, class);
}

JNIEXPORT jbyteArray JNICALL Java_coursier_bootstrap_launcher_jniutils_NativeCalls_GetUserEnvironmentVariableNative
(JNIEnv *env, jclass class, jbyteArray key) {
return Java_coursier_jniutils_NativeCalls_GetUserEnvironmentVariableNative(env, class, key);
}

JNIEXPORT jbyteArray JNICALL Java_coursier_bootstrap_launcher_jniutils_NativeCalls_SetUserEnvironmentVariableNative
(JNIEnv *env, jclass class, jbyteArray key, jbyteArray value) {
return Java_coursier_jniutils_NativeCalls_SetUserEnvironmentVariableNative(env, class, key, value);
}

JNIEXPORT jbyteArray JNICALL Java_coursier_bootstrap_launcher_jniutils_NativeCalls_DeleteUserEnvironmentVariableNative
(JNIEnv *env, jclass class, jbyteArray key) {
return Java_coursier_jniutils_NativeCalls_DeleteUserEnvironmentVariableNative(env, class, key);
}

JNIEXPORT jstring JNICALL Java_coursier_bootstrap_launcher_jniutils_NativeCalls_GetKnownFolderPathNative
(JNIEnv *env, jclass class, jstring rfid) {
return Java_coursier_jniutils_NativeCalls_GetKnownFolderPathNative(env, class, rfid);
}

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

Loading

0 comments on commit 1bf85a7

Please sign in to comment.