-
-
Save linghengqian/c8ada946edcef6a08b5a7270e2494f59 to your computer and use it in GitHub Desktop.
Runs Mockito on Graal VM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -x | |
set -e | |
if [[ -z $1 ]]; then | |
echo "Specify location of Graal VM as first argument" | |
exit 1 | |
fi | |
$1/bin/gu install native-image | |
rm -rf META-INF sample sample.build_artifacts.txt Sample.* *.jar | |
echo "public class Sample { | |
public static void main(String[] args) { | |
Sample sample = org.mockito.Mockito.mock(Sample.class); | |
org.mockito.Mockito.when(sample.m()).thenReturn(\"Hello Graal!\"); | |
System.out.println(sample.getClass()); | |
System.out.println(sample.m()); | |
} | |
public String m() { return null; } | |
}" > Sample.java | |
wget -O bytebuddy.jar https://search.maven.org/remotecontent?filepath=net/bytebuddy/byte-buddy/1.12.10/byte-buddy-1.12.10.jar | |
wget -O mockito.jar https://search.maven.org/remotecontent?filepath=org/mockito/mockito-core/4.5.0/mockito-core-4.5.0.jar | |
wget -O objenesis.jar https://search.maven.org/remotecontent?filepath=org/objenesis/objenesis/3.2/objenesis-3.2.jar | |
export dependencies=bytebuddy.jar:mockito.jar:objenesis.jar:. | |
$1/bin/javac -cp $dependencies Sample.java | |
$1/bin/java -agentlib:native-image-agent=config-output-dir=META-INF/native-image,experimental-class-define-support -cp $dependencies Sample | |
$1/bin/native-image --no-fallback -cp $dependencies \ | |
--rerun-class-initialization-at-runtime=\ | |
net.bytebuddy.ClassFileVersion,\ | |
net.bytebuddy.utility.dispatcher.JavaDispatcher,\ | |
net.bytebuddy.utility.Invoker\$Dispatcher \ | |
--initialize-at-build-time=\ | |
net.bytebuddy.description.method.MethodDescription\$InDefinedShape\$AbstractBase\$ForLoadedExecutable,\ | |
net.bytebuddy.description.type.TypeDescription\$AbstractBase,\ | |
net.bytebuddy.description.type.TypeDescription\$ForLoadedType,\ | |
net.bytebuddy.description.method.MethodDescription\$ForLoadedMethod,\ | |
net.bytebuddy.implementation.bind.annotation.Argument\$BindingMechanic,\ | |
net.bytebuddy.implementation.bind.annotation.Argument\$BindingMechanic\$1,\ | |
net.bytebuddy.implementation.bind.annotation.Argument\$BindingMechanic\$2,\ | |
net.bytebuddy.implementation.bind.annotation.Super\$Instantiation\$2 \ | |
Sample | |
./sample |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment