I am using Intellij IDEA and Grails as my application framework.
My application is mainly on Groovy.
I am trying to add external custom argument as an external parameter to my application.
I have opened the Edit Configurations... and tried different ways to add custom arguments in the VM options, and inside the Program Arguments, but with no success.
Here is an example to one try I did:
I added
-Dcustom.arg=100
to the VM options.
I would like to know if it is possible to inject external variable by using the Application configuration?If yes, how should it be done?
It should be done by adding a new program argument to the Edit configuration --> Program Arguments:
Just add a new value of the custom argument such as: externalArg.
And in the application code, find the section read those properties.
For example:
Properties props = System.properties
String propValue = props.get("sun.java.command").toString()
the propValue contains all the Program Arguments and specifically the externalArg parameter you have inserted.
Another option can be done by inserting the variable into the Edit configuration --> VM Options. When using grails, the parameter should look like that:
-Dgrails.externalVariable=3
Reading the externalVariable inside the application is done by:
Object externalVariable = System.getProperties().get("grails.externalVariable")
Note:
Both of those 2 options give the same result.
Using each one of the options should be related to the variable concept.
If you wish to have the externalVariable as a program argument insert the parameter into the Program Arguments.
If you wish to have the externalVariable as a Virtual machine parameter insert the parameter into the VM Options.
Related
I'm working with some legacy code that uses ParamCount() and ParamStr() in various places, and now I need to provide different values than those that were actually passed as command line variables.
The simplest solution would be to programmatically add/modify the existing command line parameters, since the alternative is to change A LOT of the legacy code to accept function parameters rather than directly accessing ParamCount() and ParamStr().
Is this possible? Can I somehow add/modify parameters from within the program itself so that ParamCount() ParamStr() will pick up my new/modified parameters?
Edit, clarification of the legacy code:
The legacy code makes some database requests, using where arguments from the command line (and sanitizing them). This is fine in 99.9% of all cases, as these arguments are fundamental for the purpose of the legacy units. However, I'm working on a new feature that "breaks the mold", where one of these fundamental arguments are unknown and need to be fetched from the database and provided internally.
Yes, I could search and replace, but my objective here is to not touch the legacy code, as it's in a unit that is shared among many different programs.
Restarting the program and/or executing a new copy of it from itself is one solution, but seems a bit risky and cumbersome. This is a production program that executes on a server and needs to be as simple and robust as possible.
Is this possible? Can I somehow add/modify parameters from within the program itself so that ParamCount() ParamStr() will pick up my new/modified parameters?
Technically yes, but it is not something that the RTL itself exposes functionality for, so you will have to implement it manually.
Since you are working with legacy code, I'm assuming you are working on Windows only. In which case, ParamStr() and ParamCount() parse the string returned by the Win32 API GetCommandLine() function in kernel32.dll.
So, one option is to simply hook the GetCommandLine() function itself at runtime, such as with Microsoft's Detours, or other similar library. Then your hook can return whatever string you want 1.
1: for that matter, you could just hook ParamCount() and ParamStr() instead, and make them return whatever you want.
Another option - which requires messing around with lower-level memory that you don't own, and I don't advise doing this - is to obtain a pointer to the PEB structure of the calling process. You can obtain that pointer using NTQueryInformationProcess(ProcessBasicInformation). The PEB contains a ProcessParameters field, which is a pointer to an RTL_USER_PROCESS_PARAMETERS struct, which contains the actual CommandLine string as a UNICODE_STRING struct. If your altered string is less then, or equal to, the length of the original command line string, you can just alter the content of the ProcessParameters.CommandLine in-place. Otherwise, you would have to allocate new memory to hold your altered string and then update ProcessParameters.CommandLine to point at that new memory.
As per documentation, I am creating a new custom field type in atlassian-plugin.xml using the SDK CLI. Now I want to use that new custom field type and create a custom field in another module when the plugin is enabled. However, that module is throwing null pointer exceptions, because the new type is not yet available. The class implementing the type is not annotated as a component - it only gets scanned by spring. It appears the class is instantiated by Jira some time after the plugin has been enabled. How do I know when it is safe to use the new type?
You can go with "/rest/api/2/field" POST option for creating custom fields.
Please refer the URL :
https://docs.atlassian.com/software/jira/docs/api/REST/7.6.1/#api/2/field-createCustomField
I have the following type in my grammar:
TestSuite:
'TestSuite:' name = ID
'Type:' type = SuiteType;
enum SuiteType:
INTERNAL='1' | EXTERNAL='2';
I would like to read an xml file whenever the property gets a (new) value since I use the contents of that xml file for validation and content completion. Depending on the value of the property, the xml that will be read will be different.
How would you trigger an action that would read the value of a property of a type from the runtime environment's DSL instance?
You could maybe try adding an EMF Adapter to all TestSuite instances such that upon a Notification that changes your 'type' feature to a particular value, the XML file of your choice is read and acted upon.
this blog post seems to do the trick: at the end of the linking phase, an Adapter (this is EMF vocabulary, basically a Listener) can be registered for your TestSuite instances.
Then in your Adapter implementation, you can filter whether you need to react using the methods of Notification such as getFeature().
Since you mention you want to do this for content completion and validation, you may need to do all of this in the scoping / validation phases of Xtext. You will probably have a bit of "lag" upon hitting ctrl+space for auto-completion if your IDE needs to find and parse your XML file, but that's to be expected I guess...
I'm trying to create a DXL script that will take all the objects from select set of modules and combine them into a new module which will then be exported to Excel.
The issue I'm having is I can't figure out how to get objects from a module that isn't open. I'm open to any method but I've been trying to use ModuleHandles. Most of the examples I've seen are for moving objects within the current module.
You need two variables of type Module, one for the source module (e.g. mSrc), one for the target module (mTgt). Use the command read for opening the source module and setting the resulting handle to mSrc. Use edit (or create) for opening the target module and setting the resulting handle to mTgt.
Then use a variable of type Object for iterating over all objects of mSrc (for oSrc in mSrc or perhaps ... in entire mSrc, depending on how the views in your source modules are set up), create objects in the target module (to a variable oTgt of type Object) copy the object attributes that you need from oSrc to oTgt. For the latter there is a function copyAttribute_ in copyops.inc.
If you want to replicate the hierarchy of the source module, you will need loops of type for Object in Object and commands like create after create below etc.
Perhaps there are already scripts available in IBMs DXL Forum or on some of the web sites that provide a solution for your problem.
I have an C# dll project for which I have to store the runtime settings in an external XML file, and this dll will be used in an ASP.NET/ASP.NET MVC application for which I also have to store the runtime settings in a external file.
Which IoC container can be used to create an object with the runtime settings loaded from a specific external file (or app.config/web.config), and also works for web applications running in medium trust? Any howto/tutorial would be greatly appreciated.
So far I've found only this articles:
Use Castle Windsor to Read Your Config Files Automatically
Getting rid of strings (3): take your app settings to the next level
Update
I'm sending mails from my dll to a variable number of SMTP servers, based on the current record type. For type A I'm using a given SMTP server+port, for type B I'm using an alternate set of server+port values. Of course, I want to be able to modify those values after deployment, so I store them in a XML file.
If I'm storing the SMTP settings as a SMTPConfiguration class with 2 properties (SMTPServer as String and SMTPPort as Int32), is it possible to return from an IoC container the required object based on the given record type, and what is the best way to read the runtime settings in order to build the returning object?
Update2
Let's say I'm storing in the configuration file the following parameters: ASMTPServer, BSMTPServer, ASMTPPort, BSMTPPort.
I can use Castle DictionaryAdapter to read all those settings as properties of an AppConfiguration class.
What is the recommended method to specify that the required SMTPConfiguration class should use ASMTPServer and ASMTPPort values if I'm using a type A record as a parameter (and should use BSMTPServer and BSMTPPort values if I'm using a type B record as a parameter) ? Also, how can I specify that the AppConfiguration is required in this process?
Is there a pattern for initializing objects created wth a DI container
Windsor Config Parameters With Non-Primitive Types