Skip to content

Commit

Permalink
Add coursierapi module
Browse files Browse the repository at this point in the history
  • Loading branch information
alexarchambault committed Apr 13, 2021
1 parent a161ad9 commit 4118d82
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 1 deletion.
15 changes: 14 additions & 1 deletion build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ object `windows-jni-utils-lmcoursier` extends WindowsUtils with JniUtilsPublishM
)
}

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(
Expand All @@ -40,7 +46,8 @@ object `windows-jni-utils-tests` extends ScalaModule with JniUtilsPublishModule
object test extends Tests {
def moduleDeps = super.moduleDeps ++ Seq(
`windows-jni-utils-bootstrap`,
`windows-jni-utils-lmcoursier`
`windows-jni-utils-lmcoursier`,
`windows-jni-utils-coursierapi`
)
def ivyDeps = Agg(
Deps.utest
Expand All @@ -64,6 +71,12 @@ object headers extends Module {
)
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
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
Expand Up @@ -19,5 +19,10 @@ object WindowsKnownFoldersTests extends TestSuite {
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}")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "coursierapi_internal_jniutils_NativeCalls.h"
#include "coursier_jniutils_NativeCalls.h"

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

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

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

JNIEXPORT jbyteArray JNICALL Java_coursierapi_internal_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_coursierapi_internal_jniutils_NativeCalls_DeleteUserEnvironmentVariableNative
(JNIEnv *env, jclass class, jbyteArray key) {
return Java_coursier_jniutils_NativeCalls_DeleteUserEnvironmentVariableNative(env, class, key);
}

JNIEXPORT jstring JNICALL Java_coursierapi_internal_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.

0 comments on commit 4118d82

Please sign in to comment.