How can I tell - in a standard Java program - if I'm running in GraalVM or not? - graalvm

I would like to enable my application to have additional features if the user is running under GraalVM. Since these days most people are not running GraalVM it is an extra set of steps (and a burden) to get it going just to run my application, so I don't want to require GraalVM. I want to just know I'm running under it so I can dynamically load some classes and/or choose to use some features.
Question is: How do I do this in some kind of "official" way? (I could just try to load the classes I want and see what happens, is that the best way?)

I'd probably do something like
boolean isGraalVm = System.getProperty("org.graalvm.home") != null;

To check if your code is running on GraalVM you can use the following method from the graal-sdk: Version.isRelease()
org.graalvm.home.Version.getCurrent().isRelease()
It's available in the library:
<dependency>
<groupId>org.graalvm.sdk</groupId>
<artifactId>graal-sdk</artifactId>
<version>20.2.0</version>
</dependency>
However your question could be about whether you're running in the native image or using the jit mode (I assume, because you talk about loading classes, etc).
In this case you want to use the ImageInfo class: https://www.graalvm.org/sdk/javadoc/index.html?org/graalvm/nativeimage/package-summary.html
which has methods like:
inImageBuildtimeCode() -- during the native image build
inImageRuntimeCode() -- during the runtime of a built native image, your code probably shouldn't load classes if this is true
etc.
The implementation sets/reads the PROPERTY_IMAGE_CODE_KEY property, so you can also check the value yourself if you don't want to bring in an extra jar.

Related

How do I test my GtkPrintBackend?

I am trying to develop my own GtkPrintBackend ,
taking help from here:
https://mail.gnome.org/archives/desktop-devel-list/2006-December/msg00069.html
I want to test my print backend( by making the print dialog use my backend instead). How do I do that?
That is, how do I make the Print dialog use my backend instead?
Answering my own question here since I figured out a workaround:
I installed jhbuild and built the gtk+ module using jhbuild.
The source code of the corresponding module is downloaded in ~/jhbuild/checkout/<module-name> .
Modify the print backends under ~jhbuild/checkout/gtk+/gtk/modules/printbackends/ directory, and rebuild it (Find instructions to do that here).
Now when you launch a gtk application from the jhbuild shell, it will use the modified backend instead of the system default one.

Pure Data windows:not supported, couldn't create

I am new to Pure Data and have no idea why the following are displayed after I clicked help:
I am using Windows 7 and pd-extended 0.43.4.
This error (xy ...could not crate) means that this abstraction or external failed to instantiate. It could be that you don't have it installed, or it is not in Pd's search path so it can't find it. In the patch you are opening those objects seem to be used. In your case that might be the help file.
This is an answer on the pd forum by user whale-av already,
whale-av:
[midiin] and [sysexin] are not supported in windows. Some people have written patches to get around the lack of sysex, and instead of midiin you can use [ctrlin] [notein] etc.
[powtorms~] [mstopow~] do not exist as far as I know even in vanilla for windows, and in the windows extended 0.43.4 release they do not. I remember seeing that they were in a Linux vanilla build, and in a very old Pd build for XP.... so you might be able to find them......... someone might have built them as an external that you could add to your pd/extra folder and then use them like any other object. If you have opened someone elses patch then it is possible that they used those objects in that patch, but you do not have them so they will not "create" and will just show the name in a red dotted box instead of a solid black outline.
[scalar] does not exist, but [scalar-help] does and that explains how to use scalars....... which use other objects but not [scalar]
So, basically, not all objects exist in all versions of Pd, and certainly not under all operating systems.

Auto-Detect Application "Type"

I build four different "types" of applications with my framework:
1) Windows Services
2) Normal Applications
3) Service Applications (a normal application with the functionality of a Windows Service but with a local GUI console and an ability to auto-upgrade)
4) Remote GUI Consoles
Now I can detect, through code, if the application is a Windows Service. But currently to detect between the others I use DEFINES that need to be added to the project file. I would like find an alternate way that does not rely on DEFINES if possible. My initial thoughts are to use the Comments field of the project's version info.
Any ideas?
Edit: I am after a general technique that works regardless of how I "type" my applications. At the moment I use DEFINES from the project configuration, which works, but makes the code slightly messier than using "if" code switches, and because it is stored in the .dproj file, can be hidden from view.
Solution: From David's suggestion I initially used the conditional defines (and any other information such as whether the application was running as a Windows Service) to map all applications to one of the 4 application types, stored in a globally accessible object. Unless linking files that made no sense to include with a particular application type, I replaced almost all of my conditional compilation flags with code, which significantly improved the readability of the code. There are a few other "tweaks" I implemented, but that was the basic implementation.
Depending how you are using the Application global variable you can detect if you application is a Service, a VCL or a console App checking the type of this global variable. for consoles app you can use the System.IsConsole variable.
function ApplicationIsService(Component:TComponent):Boolean;
begin
Result:=Component.ClassName='TServiceApplication';
end;
function ApplicationIsVcl(Component:TComponent):Boolean;
begin
Result:=Component.ClassName='TApplication';
end;
and you can use like this
if ApplicationIsVcl(Application) then
//do something
else
if ApplicationIsService(Application) then
//do something else
else
if IsConsole then
//do another thing
It sounds like each project has a single app type so it seems logical to differentiate in either the .dpr file or the .dproj files.
Call a function to set a private global variable from the .dpr file.
Or use a conditional defined in the .dproj as you do now.
If it was me I'd stick to a conditional but use the trick of converting it into a Delphi enum with a shared helper method to make it read better.

Why is WSCript object not known to my script that's controlled by a custom IScriptControl?

I am using someone else's library that provides its own scripting host instance, it appears.
This lib provides me with functions to define the type of scripting language such as "jscript" and "vbscript", and I can supply it with script code and have that executed, with passing arguments in and back. So, basically, it works.
However, when I try to access the "WScript" object, I get an exception saying that this keyword is undefined.
The developer, not knowing much about this either (he only made this lib for me because I do not want to deal with Windows SDKs right now), told me that he is using "IScriptControl" for this.
Oh, and the lib also provides flags to allow "only safe subset" and "allow UI", which I set to false and true, respectively.
Does that ring a bell with anyone? Do a user of IScriptControl have to take extra steps in order to make a WScript object available? Or, can he use IScriptControl in a way that this is supplied automatically, just as when running the same script from wscript.exe?
Basically, all I need is the WScript.CreateObject function in order to access another app's API via COM.
I don't know why WScript is not known, but I suspect it is because the script host doesn't provide it. Maybe only wscript.exe does this.
If you are using Javascript, to create an object you can use new ActiveXObject(). If you are using VBScript, you can just use CreateObject.
See this article for some background.

I want to use EtherPad (or a clone). My site is running Ruby on Rails. API or local install?

I'd like to utilize an etherpad interface on my website. Two questions:
1) is there any site with an etherpad api that I could just call remotely?
2) if not, how much trouble is it to install scala and have the two run concurrently?
Thanks
Check out http://piratepad.net and http://ietherpad.com
And you can embed those etherpad instances using a simple iframe as suggested here: http://etherpad.com/ep/blog/posts/embedding-etherpad
There doesn't seem to be a proper API yet for more robust interactions.
The original etherpad.com has now gone away but at that link there is a list of clones.
The instructions for embedding etherpads seems to have gone away with the rest of etherpad.com but I believe it's as simple as this:
<div id="ep">
<iframe src="http://etherpad.com/foo?fullScreen=1"></iframe>
</div>
Replace "etherpad.com" with whatever clone you're using, "foo" with the name of your pad, and you may or may not want to change that fullScreen=1 to fullScreen=0 (or leave it off altogether).
Installing scala might mean a few things:
Installing the SDK (i.e. scalac)
Installing the runtime
Assuming you mean the runtime, scala runs entirely on the Java Virtual Machine (JVM) so assuming you have 1.5+ JVM installed, you can run scala programs on it easily (Scala just compiles down to bytecode, after all). All a scala program requires is a few JARs on the classpath (scala-library and scala-compiler)
Now there is a better solution Etherpad Lite it is easily installable and embedable. See http://etherpad.org

Resources