Skip to content

Commit

Permalink
Fix migration issue with setEnv
Browse files Browse the repository at this point in the history
  • Loading branch information
warunalakshitha committed Jul 27, 2023
1 parent d8cec4e commit c9006ae
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 27 deletions.
8 changes: 8 additions & 0 deletions ballerina/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ dependencies {
externalJars(group: 'io.ballerina.stdlib', name: 'io-native', version: "${stdlibIoVersion}") {
transitive = false
}
externalJars(group: 'org.burningwave', name: 'core', version: "${burningwaveCoreVersion}") {
transitive = false
}
externalJars(group: 'io.github.toolfactory', name: 'jvm-driver', version: "${toolfactoryJvmDriverVersion}") {
transitive = false
}
}

apply plugin: 'io.ballerina.plugin'
Expand All @@ -83,6 +89,8 @@ task updateTomlFiles {
newConfig = newConfig.replace("@toml.version@", tomlVersion)
newConfig = newConfig.replace("@io.native.version@", stdlibNativeIoVersion)
newConfig = newConfig.replace("@io.version@", stdlibIoVersion)
newConfig = newConfig.replace("@burningwave.core.version@", burningwaveCoreVersion)
newConfig = newConfig.replace("@toolfactory.jvmdriver.version@", toolfactoryJvmDriverVersion)
ballerinaTomlFile.text = newConfig
setExecPath(configTOMLFile,distributionBinPath)
}
Expand Down
2 changes: 1 addition & 1 deletion ballerina/tests/Config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[os]
bal_exec_path = "@exec.path@"
bal_exec_path = "/Users/waruna/Dev/jdk17/module-ballerina-system/target/ballerina-runtime/bin/bal"
6 changes: 1 addition & 5 deletions ballerina/tests/os_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ import ballerina/io;

configurable string bal_exec_path = ?;

@test:Config {
enable:false
}
@test:Config {}
function testGetEnv() {
string expectedValue = getExpectedValidEnv();
test:assertEquals(getEnv("JAVA_HOME"), expectedValue);
Expand Down Expand Up @@ -53,7 +51,6 @@ function setEnvDataProvider() returns (string[][]) {
}

@test:Config {
enable: false,
dataProvider: setEnvDataProvider
}
function testSetEnv(string key, string value) {
Expand Down Expand Up @@ -94,7 +91,6 @@ function unsetEnvDataProvider() returns (string[][]) {
}

@test:Config {
enable: false,
dataProvider: unsetEnvDataProvider
}
function testUnsetEnv(string key, string value) {
Expand Down
12 changes: 12 additions & 0 deletions build-config/resources/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,15 @@ groupId = "io.ballerina.stdlib"
artifactId = "os-test-utils"
version = "@toml.version@"
path = "../test-utils/build/libs/[email protected]@.jar"

[[platform.java17.dependency]]
groupId = "org.burningwave"
artifactId = "core"
version = "@burningwave.core.version@"
path = "./lib/[email protected]@.jar"

[[platform.java17.dependency]]
groupId = "io.github.toolfactory"
artifactId = "jvm-driver"
version = "@toolfactory.jvmdriver.version@"
path = "./lib/[email protected]@.jar"
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ shadowJarVersion=7.1.2
undercouchDownloadVersion=5.4.0
researchgateReleaseVersion=2.8.0
puppycrawlCheckstyleVersion=10.12.0
burningwaveCoreVersion=12.62.7
toolfactoryJvmDriverVersion=9.4.3


ballerinaLangVersion=2201.8.0-20230726-132400-5c2e50ed
ballerinaLangVersion=2201.8.0-20230726-145300-b2bdf796
stdlibIoVersion=1.5.0
1 change: 1 addition & 0 deletions native/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies {
implementation group: 'org.ballerinalang', name: 'ballerina-runtime', version: "${ballerinaLangVersion}"
implementation group: 'org.slf4j', name: 'slf4j-api', version: "${slf4jVersion}"
implementation group: 'io.ballerina.stdlib', name: 'io-native', version: "${stdlibIoVersion}"
implementation group: 'org.burningwave', name: 'core', version: "${burningwaveCoreVersion}"
checkstyle project(":checkstyle")
checkstyle "com.puppycrawl.tools:checkstyle:${puppycrawlCheckstyleVersion}"
}
Expand Down
25 changes: 5 additions & 20 deletions native/src/main/java/io/ballerina/stdlib/os/nativeimpl/SetEnv.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package io.ballerina.stdlib.os.nativeimpl;

import io.ballerina.runtime.api.values.BString;
import sun.misc.Unsafe;
import org.burningwave.core.assembler.StaticComponentContainer;

import java.lang.reflect.Field;
import java.security.AccessController;
Expand All @@ -39,6 +39,10 @@ private SetEnv() {

}

static {
StaticComponentContainer.Modules.exportPackageToAllUnnamed("java.base", "java.util");
}

@SuppressWarnings("unchecked")
public static Object setEnv(BString key, Object value) {
Map<String, String> env = null;
Expand All @@ -58,11 +62,6 @@ public static Object setEnv(BString key, Object value) {
return ErrorGenerator.createError("Error while accessing the environment variable map", e);
}
}
try {
disableAccessWarning();
} catch (Exception e) {
return ErrorGenerator.createError("Error disabling illegal access warnings", e);
}
Field finalField = field;
AccessController.doPrivileged((PrivilegedAction) () -> {
finalField.setAccessible(true);
Expand All @@ -80,18 +79,4 @@ public static Object setEnv(BString key, Object value) {
}
return null;
}

@SuppressWarnings("unchecked")
private static void disableAccessWarning() throws Exception {
Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
AccessController.doPrivileged((PrivilegedAction) () -> {
theUnsafe.setAccessible(true);
return null;
});
Unsafe u = (Unsafe) theUnsafe.get(null);

Class<?> cls = Class.forName("jdk.internal.module.IllegalAccessLogger");
Field logger = cls.getDeclaredField("logger");
u.putObjectVolatile(cls, u.staticFieldOffset(logger), null);
}
}
1 change: 1 addition & 0 deletions native/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
requires org.slf4j;
requires io.ballerina.stdlib.io;
requires jdk.unsupported;
requires org.burningwave.core;
exports io.ballerina.stdlib.os.nativeimpl;
exports io.ballerina.stdlib.os.utils;
}
3 changes: 3 additions & 0 deletions native/src/main/resources/burningwave.static.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
managed-logger.repository.enabled=false
background-executor.all-tasks-monitoring.logger.enabled=false
banner.hide=true

0 comments on commit c9006ae

Please sign in to comment.