SonarQube plugin: how to get property value from command line -D - gradle

I am new to sonar plugin development. I wrote a plugin and add PropertyDefine to context. And then I wanna get my property value passed by
gradle sonarqube -Dmy.proper.name=xxx
I don't know what are the next steps? Plz help.
Thanks.

All -D parameters can be get by using java.lang.System class:
String valueOrNull = System.getProperty("my.proper.name");
or
String valueOrDefault = System.getProperty("my.proper.name", "defaultValue");

Hi #agabrys thanks for your answer. But I found out that if you wanna get the property from Scanner side, you need make a PostJob like class to deal with it. I didn't clearly know that so I didn't know why I couldn't get that property. Thanks anyway.

Related

How to programatically evaluate expression(spel/variable reference) used in annotation?

Say that I have use case for finding method annotated via say #Scheduled(cron = "${variable}"), and I'd like to know the value of "cron" parameter. If I check via reflection, no surprise, I will find there value "${variable}".
Can someone share link/snipet how to evaluate variables/spel expression present in annotation? I found some answers, but neither of them worked.
Just to extend #crizzis answer, maybe filling the missing part.
Fist you need to inject/autowire ConfigurableBeanFactory beanFactory;. Looking at implementation of ExpressionValueMethodArgumentResolver and it's parent AbstractNamedValueMethodArgumentResolver it seems to me, that full code which does variable substitution and spell needs one more line:
BeanExpressionResolver beanExpressionResolver = beanFactory.getBeanExpressionResolver();
String expressionWithSubstitutedVariables = beanFactory.resolveEmbeddedValue(expression);
Object resultWithResolvedSPEL = beanExpressionResolver.evaluate(expressionWithSubstitutedVariables, new BeanExpressionContext(beanFactory, null));
then string like #{!${some-boolean-variable} ? 'a' : 'b'} was correctly evaluated for me. Not sure if this is the way-to-go as I don't know spring well, but this worked for me.
I'm sure there are a couple of ways, but the easiest is probably:
beanFactory.getBeanExpressionResolver().evaluate(
"${variable}",
new BeanExpressionContext(beanFactory, null))

How to return CKEditorFuncNum?

$funcNum = $_GET['CKEditorFuncNum'] ; is not returning the number.
I tried creating the upload.php for ckeditor uploadimage plugin according to
https://stackoverflow.com/a/44553006/8719001 (sorry can't add comments yet)
which includes echo "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction($funcNum, '$url', '$message');</script>";
However when I drop images it doesn't work and in the console I get the Response Text which doesn't show any funcNumber:
"<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction(, 'https://example.com/upload/test.jpg', '');</script>"
I think this might be part of filebrowser plugin?
Which I have enabled and also declared $settings['filebrowserUploadUrl'] =
Try to setup config.js insert config.filebrowserUploadMethod = 'form';,if you got CKEditor additional arguments empty,(CKEditor,langCode,CKEditorFuncNum). There are some errors occur,
Incorrect server response. and [CKEDITOR] Error code: filetools-response-error..
please refer,https://github.com/ckeditor/ckeditor-dev/issues/1894
This is the version problem.
I tried 2 hours and couldn't get the parameter CKEditorFuncNum with java like you.
After I changed my 4.9.1 version to 4.7.3, it worked.

Can't disable placeholderReplacement for flyway in gradle?

Simple issue.
I am trying to disable placeholderReplacement in flyway. I am using gradle.
My config has this in it:
flyway {
placeholderReplacement = false
outOfOrder = true
locations=['filesystem:./db/migration']
...
}
When I do this, I get the following error:
Error occurred while executing flywayMigrate
No signature of method: org.flywaydb.core.Flyway.setPlaceholderReplacement() is applicable for argument types: (java.lang.String) values: [false]
Possible solutions: setPlaceholderReplacement(boolean), isPlaceholderReplacement()
I'm pretty new to gradle and groovy, but I could not figure out how to get past this issue. I've tried adding single and double quotes and changing casing on the property. Also tried explicitly casting "false" to a boolean.
Other than that, I am at a loss. I am setting other boolean properties just fine, such as outOfOrder, but it only blows up on placeholderReplacement which makes me think that it might be an issue on the flyway side. I am following the examples from the flyway website line for line.
Any ideas?
This is a known issue (https://github.com/flyway/flyway/issues/1001) that has been fixed for 4.0 (due out this month).

Xtext get the absolute path of the generated files

I want to access the file generated by Xtext to compile it automatically. So I need its absolute path. It's enough to get the absolute path of the current project at run-time. Any idea how I can get it?
I am working inside the "MyDslGenerator" Class. I tried to get it from the "resource" in
override void doGenerate(Resource resource, IFileSystemAccess fsa)
but couldn't find it.
Help is highly appreciated.
I ended up using this code:
var uri = (fsa as IFileSystemAccessExtension2).getURI(fileName)
maybe you can use the Interface org.eclipse.xtext.generator.IFileSystemAccessExtension2. the passed IFileSystemAccess may implement this interface too.

Maven archetype required property number

I have a Maven archtype that use a requiredProperty that contains a number, but the velocity variable are string. So, in my template I can't test if this property is greater than a number:
#if( $myVar gt 5 )
I have tested the following solution without success.
I've also tried this:
#set( $intVar = Integer.parseInt($myVar) )
That's also fail at the archetype generation.
Any advice?
You can't reference classes from Velociy, so Integer.parseInt won't work. However, since in Java any static method can be called as an instance method, and Velocity is just Java in disguise, you can call parseInt on any integer. So you can try this trick:
#if ($myVar.length().parseInt($myVar) gt 5)
You're getting hold of an integer starting from the one variable that you're assuming you have, $myVar.
I have implemented user input validation based on a regular expression provided in the archetype descriptor :
https://issues.apache.org/jira/browse/ARCHETYPE-487
hopefully it will solve this issue for future versions of the maven archetype plugin.

Resources