-
Notifications
You must be signed in to change notification settings - Fork 301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
apply replace on property xxx: original value 'null' with '' #457
Comments
Thank you for reporting this! <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>test</name>
<groupId>de.test</groupId>
<artifactId>test</artifactId>
<version>1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<sonar.projectKey>${project.groupId}:${project.artifactId}:${git.branch}</sonar.projectKey>
</properties>
<build>
<plugins>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>4.0.1-SNAPSHOT</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<injectAllReactorProjects>true</injectAllReactorProjects>
<runOnlyOnce>true</runOnlyOnce>
<skipPoms>false</skipPoms>
<includeOnlyProperties>
<includeOnlyProperty>^git.branch$</includeOnlyProperty>
</includeOnlyProperties>
<verbose>true</verbose>
<!-- see: https://github.com/git-commit-id/maven-git-commit-id-plugin/issues/413 -->
<replacementProperties>
<replacementProperty>
<property>sonar.projectKey</property>
<token>.*</token>
<value>${project.groupId}:${project.artifactId}:${git.branch}</value>
<regex>false</regex>
</replacementProperty>
</replacementProperties>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>package</phase>
<configuration>
<target>
<echo>===========================================================================</echo>
<echo>${sonar.projectKey}</echo>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project> Can you double check what ends up in sonar? Regardless what shows up, I still wonder why this works....the bug can be traced down inside the PropertiesReplacer where such specific replacements results in the following call-chain: For the last If I'm not mistaken to fix this the if (content == null or content..isEmpty()) { return value; } |
according to my tests, the property gets set wrongly:
this means that the explicitly set value of the property is overwritten with the empty string. |
I ran some debugging locally and I think I fixed the general issue already. What might work in this case is an ability to reset the property or to force an overwrite. Not sure if we would get the Perhaps this idea could look something along the lines of: <replacementProperty>
<property>sonar.projectKey</property>
<token>.*</token>
<value>${project.groupId}:${project.artifactId}:${git.branch}</value>
<regex>false</regex>
<transformationRules>
<transformationRule>
<apply>BEFORE</apply>
<action>SET_TO_EMPTY_STRING</action>
</transformationRule>
</transformationRules>
</replacementProperty> or <replacementProperty>
<property>sonar.projectKey</property>
<token>.*</token>
<value>${project.groupId}:${project.artifactId}:${git.branch}</value>
<regex>false</regex>
<fullOverwrite>true</fullOverwrite> # perhaps we can call it 'forceValueEvaluation' too
</replacementProperty> To some extend I would claim this goes against the ideology to have the ability to run the project Could you perhaps elaborate on your use-case why it would make sense to store the git-commit on the ====
|
Hi, btw, many thanks for the great and fast support. we are migrating an old Sonar 5 server to Sonar 8, and we had always had the GIt-Branch name in the many thanks for your help so far |
We have exactly the same problem. Of course, there is a way around this by obtaining commercial version of Sonar which has branch analysis. |
IMHO pointing to a 'commercial' version is the last thing I want to do. The plugin has now a
Essentially what this means is that I now need to clone sonar code and understand exactly what the plugin is doing 'wrong'...or what sonar does not like in the way the plugin operates....a big OOF. May I also point to sonar's analysis-parameters that indicate at least two interesting ones: And apologies to post all the questions here, but I noticed that my docker image 'only' has the 7.9.1.27448 version and it's unclear what version it comes with...so I need to find time to dig into deeper into sonar code and install sonar myself.... (eta when I find time is on the weekend) Edit:
Perhaps is https://github.com/mc1arke/sonarqube-community-branch-plugin what you need here?? |
Thank You really much for pointing out sonarqube-community-branch-plugin. I was not aware of that and it's exactly what we need. I installed it and our problem is now resolved. By referencing to 'commercial' version I tried to be sarcastic. |
…nerates and displays an empty property
Thanks again for the report. IMHO fiddling with As per sonar's analysis-parameters I would suggest to attempt to use So from the perspective of the plugin it is 'fixed' because there was indeed a display and generation issue. |
sorry for the late reply. |
at the end, i am setting the branch name from the shell to sonars plugin:
easy and robust, if you do not forget to set the parameter... |
Hello, |
Description
I have the same use case than #413, i want to use
git.branch
insonar.projektKey
.for that i am trying to use:
but i get:
Expected behavior
i expect that
git.branch
gets replaced insonar.projectKey
Additional context
mvn git-commit-id:revision
here the whole pom.xml to reproduce the problem:
and the Output of
mvn git-commit-id:revision
:what can be wrong?
many thanks
The text was updated successfully, but these errors were encountered: