Response
stringlengths 8
2k
| Instruction
stringlengths 18
2k
| Prompt
stringlengths 14
160
|
---|---|---|
You are reading whole lines from your CSV to a PCollection on strings. That's most likely not enough for you.What you want to do is toSplit whole string into multiple strings relevant to columnsFilter PCollection to values that contain something in required column. [1]Apply Count [2][1]https://beam.apache.org/releases/javadoc/2.2.0/org/apache/beam/sdk/transforms/Filter.html[2]https://beam.apache.org/releases/javadoc/2.0.0/org/apache/beam/sdk/transforms/Count.htmlShareFollowansweredJan 21, 2020 at 17:52Mikhail GryzykhinMikhail Gryzykhin10666 bronze badgesAdd a comment|
|
I need to read a csv file into DataFlow that represents a table, perform a GroupBy transformation to get the number of elements that are in a specific column, and then write that number to a BigQuery table along with the original file.So far I've gotten the first step - reading the file from my storage bucket and I've called a transformation, but I don't know how to get the count for a single column since the csv has 16.public class StarterPipeline {
private static final Logger LOG = LoggerFactory.getLogger(StarterPipeline.class);
public static void main(String[] args) {
Pipeline p = Pipeline.create(PipelineOptionsFactory.fromArgs(args).withValidation().create());
PCollection<String> lines = p.apply("ReadLines", TextIO.read().from("gs://bucket/data.csv"));
PCollection<String> grouped_lines = lines.apply(GroupByKey())
PCollection<java.lang.Long> count = grouped_lines.apply(Count.globally())
p.run();
}
}
|
How do I read a .csv file into a GCP Dataflow and then get the count for a specific column and write it to BigQuery?
|
You can the Postman API to import OpenAPI definitions by POSTing a file or string to theimport/{{importType}}endpointand appending/?workspace={workspaceId}to the url.The workspace parameter isn't documented.ShareFollowansweredDec 3, 2020 at 16:30Nick HammondNick Hammond31322 silver badges1313 bronze badgesAdd a comment|
|
is there a way to import to our private workspace new environment files using an api for a CI/CD process?
|
API to import collection and environment to postman
|
Found the issue. While configuring the shared library repo in Jenkins Global Configuration, fill in the link without .git in the end.For example, usehttps://github.com/arghyadeep-k/jenkins-shared-libraryand nothttps://github.com/arghyadeep-k/jenkins-shared-library.git.And, then invoke the functions in your Jenkinsfile asnode{
checkOut.call()
}ShareFolloweditedDec 28, 2019 at 6:47answeredDec 26, 2019 at 5:19ArghyaArghya24011 silver badge1616 bronze badgesAdd a comment|
|
I have a shared pipeline librarycode. The library is loaded implicitly in my Jenkins and I'm calling one of the methods using the following code in my Jenkinsfile:node {
CheckOut {}
}I've also tried usingCheckOut.call()&CheckOut.call([:],{})but to no avail.
Keep getting the following error:hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: CheckOut.call() is applicable for argument types: (org.jenkinsci.plugins.workflow.cps.CpsClosure2) values: [org.jenkinsci.plugins.workflow.cps.CpsClosure2@668faf1f]
Possible solutions: call(), wait(), any(), wait(long), main([Ljava.lang.String;), any(groovy.lang.Closure)P.S. - The error is not specific to one function and is happening for all the other functions of the library as well.
|
groovy.lang.MissingMethodException: No signature of method: Why is this error coming for Jenkins Shared Pipeline library?
|
You have to delete the PersistentVolume called mysql-pv-volume from your namespace or use an other name instead.'kubectl delete pv'command allows you to delete PersistentVolume .$ kubectl delete pv mysql-pv-volumeThen you will be able to install your app$ helm install refund-robot .ShareFollowansweredDec 23, 2019 at 17:05Ridae HAMDANIRidae HAMDANI69622 gold badges77 silver badges1818 bronze badgesAdd a comment|
|
I'm having trouble upgrading helm chart from a pipeline.
I runhelm install --name refund-robot .from the root directory on my local machine to install the helm chart for the first time.
Later I have a pipeline where I update docker image and trigger helm upgrade.
In my pipeline I run this command:helm upgrade --install refund-robot .but I keep getting this error:Release "refund-robot" does not exist. Installing it now.
65 Error: rendered manifests contain a resource that already exists. Unable to continue with install: existing resource conflict: kind: PersistentVolume, namespace: , name: mysql-pv-volumeWhich is fair enough. I then tried runninghelm upgrade refund-robot .and I got:Error: UPGRADE FAILED: "refund-robot" has no deployed releasesHow can I make this work from my pipeline? Do I need to share some config with the pipeline?
What's the best way to approach this?
|
Helm install locally but upgrade in pipeline?
|
I don't believe there's a "grammar file" - the types are defined in code. For example, the top level pipeline is definedhereas:type Config struct {
Groups GroupConfigs `yaml:"groups" json:"groups" mapstructure:"groups"`
Resources ResourceConfigs `yaml:"resources" json:"resources" mapstructure:"resources"`
ResourceTypes ResourceTypes `yaml:"resource_types" json:"resource_types" mapstructure:"resource_types"`
Jobs JobConfigs `yaml:"jobs" json:"jobs" mapstructure:"jobs"`
}Theatc.Config.Validate()command is also based on code - not an external grammar.You could probably reason through those source files to determine the structure. Itmightbe possible togenerate a jsonschema from the go typesand then use that.ShareFollowansweredJan 4, 2020 at 3:28phillbakerphillbaker1,5381111 silver badges2222 bronze badgesAdd a comment|
|
I couldn't find it online after a little bit of searching, so i'm asking it here. Is there a 'reference' bnf grammar file for yaml file of concourse's pipeline ? As a side project, I'm trying to create an IntelliJ plugin that could do syntax highlight and auto completion for CI/CD Concourse pipelines, and would try to avoid manually retyping all that grammar to minimize error risk and time.
|
Is there an official Concourse pipeline grammar?
|
pipeline should put in jsonhttps://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.htmllikePOST _bulk{ "index" : { "_index" : "test", "_id" : "1" ,"pipeline":"pipeline-name"} }
{ "field1" : "value1" }ShareFollowansweredJan 2, 2020 at 9:43user2098849user209884923144 silver badges99 bronze badges71You're right. The actual problem was that pipeline aren't supported for updates at all, only index.–micahJan 2, 2020 at 16:34That's true @micah and how do you work around it finally?–puppylpgOct 5, 2022 at 4:03@puppylpg I solved it in application. All of my updates funneled through a custom ingest pipeline where I could add logic to bump the LUA timestamp for all update records–micahOct 5, 2022 at 17:26@micah Thanks, and what about batch update? Seems that you didn't leverage bulk to update?–puppylpgOct 6, 2022 at 6:17@puppylpg We did. All updates went to a queue, a process collected them in batches, modified the documents (bumped LUA timestamp), then sent a bulk update request to Elasticsearch.–micahOct 6, 2022 at 15:19|Show2more comments
|
I'm unable to get elasticsearch to use my defined pipeline when making bulk updates. It works fine with bulk indexes, but not bulk updates.My pipeline-PUT _ingest/pipeline/subscriber_pipeline
{
"description" : "Sets the document last_updated time",
"processors" : [
{
"script" : {
"lang" : "painless",
"inline" : """
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
df.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date = new Date();
ctx.last_updated = df.format(date);
"""
}
}
]
}My bulk update request-POST subscribers/_bulk?pipeline=subscriber_pipeline
{"update":{"_index":"subscribers","_type":"subscriber","_id":"abcdefg","retry_on_conflict":20,"pipeline":"subscriber_pipeline"}}
{"doc":{"domain_id":100,"subscribed_date":"2019-12-18T23:27:12","subscribed_url":"https://acme.com/"},"doc_as_upsert":true}Are pipelines not supported for update and bulk update operations?
|
Elasticsearch Not Using Pipeline In Bulk Updates
|
Sadly symbolic link doesn't exist in Cloud Storage. For achieving what you want, you have to handle this manually with these 2 steps at the end of your job:# delete the previous existing latest directory
- name: 'gcr.io/cloud-builders/gsutil'
args: ['-m', 'rm', '-r', 'gs://testing-reports/latest']
# copy the most recent file into the latest directory
- name: 'gcr.io/cloud-builders/gsutil'
args: ['-m', 'cp', '-r', 'gs://testing-reports/$BUILD_ID', 'gs://testing-reports/latest']ShareFollowansweredDec 10, 2019 at 21:10guillaume blaquiereguillaume blaquiere71.2k33 gold badges5151 silver badges8686 bronze badges0Add a comment|
|
Mycloudbuild.yamlconsists of:steps:
- name: maven:3.6.0-jdk-8-slim
entrypoint: 'mvn'
args: ["clean","install","-PgenericApiSuite","-pl", "api-testing", "-am", "-B"]
- name: 'gcr.io/cloud-builders/gsutil'
args: ['-m', 'cp', '-r', '/workspace/api-testing/target/cucumber-html-reports', 'gs://testing-reports/$BUILD_ID']But every time it runs now my bucket shows the reports with itsbuild_id.Is there a way I can keep the latest report separate from the rest?
|
How to keep latest version of cloudbuild.yaml seperate in the cloud storage
|
You can define a super-set of all the stages and then run only the stages you need, like this:pipeline {
agent any
stages {
stage('Always') {
steps {
...
}
}
stage('Only when Four') {
when {
environment name: 'CHOICE', value: 'four'
beforeAgent true
}
steps {
...
}
}
}
}ShareFollowansweredDec 4, 2019 at 11:34MaratCMaratC6,56922 gold badges2121 silver badges2828 bronze badges1Thank you for your answer. I will try this out. @MaratC–Kanaga Manikandan GopalMay 8, 2020 at 7:30Add a comment|
|
Based on the parameter selected (Eg. choice - in this case), need to scale up/down the pipeline stages.if(choice.equals("four")){
pipeline{
<4 stages>
}
}else{
pipeline{
<3 stages>
}
}Is it possible to implement something like this?
|
How to scale up/down the stages in Jenkins Pipeline, based on the choice parameter we are selecting?
|
This is aFAQ. You can put//NOSONARat the end of the line triggering the warning.//NOSONARFor most languages, SonarQube supports the use of the generic mechanism://NOSONARat the end of the line of the issue. This will suppress all issues - now and in the future - that might be raised on the line.I prefer using the FindBugs mechanism though, which consists in adding the @SuppressFBWarnings annotation:@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
value = "NAME_OF_THE_FINDBUGS_RULE_TO_IGNORE",
justification = "Why you choose to ignore it")ShareFolloweditedMar 12, 2021 at 5:36ryenus16.3k55 gold badges6161 silver badges6464 bronze badgesansweredJun 10, 2012 at 20:48JB NizetJB Nizet685k9292 gold badges1.2k1.2k silver badges1.3k1.3k bronze badges72Agreed. However, I'm not sure if Sonar correctly interprets@SuppressFBWarnings(added to avoid clashes withjava.lang.SuppressWarnings) and also ignores it.–Marcel StörJul 17, 2013 at 6:39AFAIK, Sonar uses FindBugs. So if FindBugs handles these annotations, I don't see why they wouldn't work when running FindBugs through Sonar. Shouldn't be hard to test anyway.–JB NizetJul 17, 2013 at 6:414The FAQ link is outdated. Here is the newFAQ–wirednikoMay 21, 2015 at 19:5716Could you please provide other link to a SonarQube FAQ? I see a login form instead of FAQ–Win4sterMar 12, 2018 at 10:54docs.sonarqube.org/latest/faq/#header-1–LaloiOct 25, 2021 at 8:45|Show2more comments
|
Is it possible to turn off sonar (www.sonarsource.org) measurements for specific blocks of code, which one doesn't want to be measured?An example is the "Preserve Stack Trace" warning which Findbugs outputs. When leaving the server, I might well want to only pass the message back to the client, not including the actual exception which I just caught, if that exception is unknown to the client (because the client doesn't have the JAR in which that exception was contained for example).
|
Turning Sonar off for certain code
|
Try something like this:sonar.exclusions=src/java/test/**ShareFolloweditedApr 19, 2018 at 7:02Vishal Yadav3,64233 gold badges2525 silver badges4242 bronze badgesansweredJul 26, 2015 at 15:59Juan HernandezJuan Hernandez2,03111 gold badge1010 silver badges22 bronze badges66Assure to use the Ant fileglob pattern for wildcards. Here is a good explanation:stackoverflow.com/a/86915/748524–StephanFeb 9, 2016 at 9:25Here is command line options definitiondocs.sonarqube.org/display/SONAR/…–N0dGrand87Jul 28, 2017 at 12:318Anyone who sees this, make sure you havesrc/test/javainstead ofsrc/java/test/.–FarazDec 3, 2018 at 14:06How to exclude methods in c#–nature vetriDec 5, 2018 at 7:061The folder structure also matters : for example :/webapp/**/* will exclude all files under webapp directory. The "" is for directory and "" is for file. If you just have **/webapp/then it won't exclude the folders under webapp folder.–Smart CoderJun 26, 2020 at 15:52|Show1more comment
|
I am trying to exclude a directory from being analyzed by Sonar. I have the following properties defined in mysonar-project.propertiesfile:sonar.sources=src/java
sonar.exclusions=src/java/test/****/*.javaThe directory structure I have is:src/java/dig
src/java/test/digWhen I run the sonar-runner I get the following info:INFO - Excluded sources:
INFO - src/java/test/**/*.java
INFO - Excluded tests:
INFO - **/package-info.javaBut when I check the result of the analysis all the packages inside the test directory are still there.I just need to tell Sonar to not analyze the test directory and any packages inside it.
|
SonarQube Exclude a directory
|
You have 2 ways to delete a project:If you are an admin of the project, you can delete it from its configuration actions=> See"Deleting a project" in the "Project Administration" documentation pageIf you are a SonarQube administrator, then you can also delete a project from the "Project Management" page=> See"Project Management/Project Existence" documentation pageShareFolloweditedJun 9, 2021 at 4:56Ian W4,63722 gold badges1919 silver badges3939 bronze badgesansweredDec 6, 2010 at 16:03Shawn VaderShawn Vader12.3k1111 gold badges5353 silver badges6262 bronze badges3Was having the same problem. Thanks for the screenshot, that really helped.–Wim DeblauweAug 31, 2011 at 15:343don't forget to log as an admin–Pascal DimassimoSep 17, 2012 at 23:49This info is outdated ... see answer below for v3.3 of sonar.–DH4Jan 16, 2013 at 19:47Add a comment|
|
Does anyone know how to delete a project from a SonarQube server?Thanks,
Ronen.
|
Delete a project from SonarQube
|
This can be solved by various ways, I suggest better go forkubectl describe pod podnamename, you now might see the cause of why the service that you've been trying is failing. In my case, I've found that some of my key-values were missing from the configmap while doing the deployment.ShareFolloweditedJul 17, 2019 at 21:43David Mohundro12.1k55 gold badges4141 silver badges4545 bronze badgesansweredMar 11, 2019 at 12:00Anirban HazarikaAnirban Hazarika1,36111 gold badge88 silver badges33 bronze badges0Add a comment|
|
I am trying to runSonarqubeservice using the followinghelm chart.So the set-up is like it starts a MySQL and Sonarqube service in the minikube cluster and Sonarqube service talks to the MySQL service to dump the data.When I dohelm installfollowed bykubectl get podsI see theMySQLpod status asrunning, but theSonarqubepod status shows asCreateContainerConfigError. I reckon it has to do with the mounting volume thingy:link. Although I am not quite sure how to fix it (pretty new to Kubernetes environment and till learning :) )
|
Pod status as CreateContainerConfigError in Minikube cluster
|
Squale(free)KalistickMetrixWareCastShareFolloweditedDec 23, 2013 at 3:42John M. Wright4,54711 gold badge4444 silver badges6262 bronze badgesansweredOct 8, 2010 at 10:22Julien HoarauJulien Hoarau49.4k2020 gold badges130130 silver badges117117 bronze badgesAdd a comment|
|
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened,visit the help centerfor guidance.Closed12 years ago.We in our organization are trying to implement a source code quality management tool. SonarQube is one such tool that we have come across, and it's quite full of features and is phenomenal. We want to compare it with its peers, if there are any, before we actually implement it.Are there any good contenders to Sonar's capabilities and features?
|
Are there any Quality Management tools other than SonarQube [closed]
|
As already mentioned, this is due to a break in JaCoCo maven plugin code.
You can (temporarily) specify the version in your jenkins maven command like:clean org.jacoco:jacoco-maven-plugin:<version>:prepare-agent installe.g.clean org.jacoco:jacoco-maven-plugin:0.7.4.201502262128:prepare-agent installThis was the workaround that helped us. But like most people, I'm still waiting for the fix to come.ShareFollowansweredMay 26, 2015 at 19:10deketimdeketim85966 silver badges66 bronze badges41Nice trick, in environment with many subprojects that was cleanest solution so far–PadvinderMay 26, 2015 at 20:191This is fixed in the latest version of the SonarQube Java PlugIn–thomas.mc.workJul 16, 2015 at 14:051I'm still getting this error with SonarQube 5.1.1. How to force the latest SonarQube Java Plugin?–davidfmathesonJul 23, 2015 at 13:453Had to update the Java Plugin within my SonarQube instance <SONAR_URL>/updatecenter/updates–davidfmathesonJul 23, 2015 at 14:18Add a comment|
|
I'm using SonarQube for code quality control and suddenly builds that would otherwise pass can't be analyzed and fails.[INFO] [00:00:03.630] Analysing /mySuperProject/target/jacoco.exec ->
java.io.IOException: Incompatible version 1007When I invoke maven build with debug switch, this cause is revealedCaused by: java.io.IOException: Incompatible version 1007.
at org.jacoco.core.data.ExecutionDataReader.readHeader(ExecutionDataReader.java:127)
at org.jacoco.core.data.ExecutionDataReader.readBlock(ExecutionDataReader.java:107)
at org.jacoco.core.data.ExecutionDataReader.read(ExecutionDataReader.java:87)
at org.sonar.plugins.jacoco.AbstractAnalyzer.readExecutionData(AbstractAnalyzer.java:134)
at org.sonar.plugins.jacoco.AbstractAnalyzer.analyse(AbstractAnalyzer.java:107)While inspecting jacoco ExecutionDataReader, I found that exception is thrown fromif (version != ExecutionDataWriter.FORMAT_VERSION) {
throw new IOException(format("Incompatible version %x.",Integer.valueOf(version)));
}and from ExecutionDataWriter I've found out/** File format version, will be incremented for each incompatible change. */
public static final char FORMAT_VERSION = 0x1007;What is thisincompatible changeand why does it happen?
Any ideas how to fix this challenge?
|
JaCoCo SonarQube incompatible version 1007
|
Integer.valueOfimplements a cache for the values-128to+127. See the last paragraph of the Java Language Specification, section 5.1.7, which explains the requirements for boxing (usually implemented in terms of the.valueOfmethods).http://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.1.7ShareFolloweditedAug 9, 2021 at 18:57Djordje Nedovic6611010 silver badges2222 bronze badgesansweredJun 4, 2010 at 13:29Brett KailBrett Kail33.7k22 gold badges8686 silver badges9191 bronze badges4i know, it was somewhere in the unboxing, but i could find the section. thanks–LB40Jun 4, 2010 at 13:441That section doesn't say anything explicit about valueOf. Boxing is usually implemented in terms of valueOf, but that's not required. Also, it's allowed to also cache values outside that range. That's only a minimum range for boxing.–Matthew FlaschenJun 4, 2010 at 13:4522Just for completeness, also note that on Sun VMs, the maximum value of the cache is user-configurable using-XX:AutoBoxCacheMax=...–Mark PetersJun 4, 2010 at 14:475@MarkPeters for extra completeness ;-) that feature has only been available since a recent update of Sun Java 6 (I think update 14 or so).–JesperJun 4, 2010 at 22:59Add a comment|
|
I was usingSonarto make my code cleaner, and it pointed out that I'm usingnew Integer(1)instead ofInteger.valueOf(1). Because it seems thatvalueOfdoes not instantiate a new object so is more memory-friendly. How canvalueOfnot instantiate a new object? How does it work? Is this true for all integers?
|
New Integer vs valueOf
|
The reason is that the Sonar Maven Plugin is hosted at theCodehaus Mojo projectand benefits from the groupId "org.codehaus.mojo". This allows to use the shortcut "sonar:sonar" instead of "org.codehaus.mojo:sonar-maven-plugin::sonar" (see the section "Configuring Maven to Search for Plugins" of theMaven documentation)ShareFollowansweredMar 5, 2013 at 21:52Simon BrandhofSimon Brandhof5,13611 gold badge2222 silver badges2828 bronze badges43Still don't get it.. Why does having the groupId "org.codehaus.mojo" let us use the shortcut?–ZhenyaMar 12, 2015 at 17:344@levgen org.apache.maven.plugins and org.codehaus.mojo are special group ids. See the last section ofmaven.apache.org/guides/introduction/…–Simon BrandhofMar 13, 2015 at 13:257This does not answer the question as to howmvn sonar:sonarexecutes while the plugin is not mentioned in pom ? I think the OP did not wanted to ask about howsonaris resolved.–Number945May 7, 2019 at 7:011@BreakingBenjamin your question seems to be about Maven itself, but not about SonarQube.–Simon BrandhofMay 8, 2019 at 8:22Add a comment|
|
I have a Maven web project in my repo.I am a Maven noob but still I understand the fact that there are plugins which we need to configure only then we could run plugin specific commands.Facts:I have a sonar server running on my local machine at port 9000.I have not added any sonar specific plugin in my POM.xmlReference:http://www.sonarsource.org/we-had-a-dream-mvn-sonarsonar/Observation:But still when I runmvn sonar:sonarin my project from command line it works fine.Matter of the fact isI have NOT configured sonar plugin in my POM.xml Even then from where the hell Maven is picking up and understanding "sonar:sonar" goal/command?Question / curiosity:I don't want the working knowledge of sonar itself. I want to know whymvn sonar:sonarworks without configuring a sonar plugin in my pom.xmlWHY and how?
|
Why does the Maven command "mvn sonar:sonar" work without any plugin configuration in my "pom.xml"?
|
You're running your Maven steps in the wrong order:clean- delete all previous build outputsonar:sonar- run analysis (which requires build output)deploy- build &etc...Try this instead:mvn clean deploy sonar:sonarNow if you're about to object that you don't want to actually "deploy" the jar until/unless the changed code passes the Quality Gate, well... that requires a different workflow:mvn clean package sonar:sonar
// check quality gate status
// if (qualityGateOk) { deploy }The particulars of those last two steps will depend on your CI infrastructure. But for Jenkins, step #2 iswell documentedShareFolloweditedJan 3, 2018 at 15:34answeredOct 27, 2017 at 13:58G. Ann - SonarSource TeamG. Ann - SonarSource Team22.5k44 gold badges4242 silver badges8484 bronze badges313Usually amvn clean packageis enough to do asonar:sonarafterwards...and install is not really necessary..–khmarbaiseOct 27, 2017 at 14:00Thx @khmarbaise. Updated–G. Ann - SonarSource TeamOct 27, 2017 at 14:09actually, only compile is just fine - in my case tests take really long, so it was the best. and you don't need to add anything to pom.xml if you edit Maven settings–LineAug 10, 2018 at 17:42Add a comment|
|
I am struggling with an error with a multi-modules project, the struture is simple, it looks like this :root
module a
module b
module c
pom.xmlAfter using the maven command line :clean sonar:sonar deployI have this error :Failed to execute goal
org.sonarsource.scanner.maven:sonar-maven-plugin:3.3.0.603:sonar
(default-cli) on project X : Please provide compiled classes of your
project with sonar.java.binaries property -> [Help 1]EDIT : Here is the structure of mypom.xml<?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">
<groupId>groupeId</groupId>
<artifactId>artifactId</artifactId>
<version>version</version>
<packaging>pom</packaging>
<name>${project.artifactId}-parent</name>
<description>description</description>
<build>
<plugins>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.3.0.603</version>
</plugin>
</plugins>
</build>
<modules>
<module>module a</module>
<module>module b</module>
<module>module c</module>
</modules>
</project>
|
Please provide compiled classes of your project with sonar.java.binaries
|
Here is an updated answer as of August 2014 for some that are aimed or work well with Scala.Personally I think the JVM or Java ones end up with far too many false positives, or have inspections that are aimed mostly at Java specific classes. For example, since in Scala we don't tend to use the Java Collections, all the findbugs collection based inspections are not needed. Another example is the inspections for use of static fields which are irrelevant in Scala.Scalastylehttps://github.com/scalastyle/scalastyleScapegoathttps://github.com/sksamuel/scalac-scapegoat-pluginWart removerhttps://github.com/typelevel/wartremoverLinterhttps://github.com/HairyFotr/linterCPDhttps://github.com/sbt/cpd4sbtAbidehttps://github.com/scala/scala-abideCodacy-scalametahttps://github.com/codacy/codacy-scalametaShareFolloweditedJan 6, 2017 at 12:51answeredAug 4, 2014 at 11:00sksamuelsksamuel16.3k88 gold badges6060 silver badges110110 bronze badges1Does anyone out of above able to configure with Azure CI/CD pipelines?–Ashish-BeJovialMar 16, 2021 at 18:26Add a comment|
|
Closed.This question is seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. It does not meetStack Overflow guidelines. It is not currently accepting answers.We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.Closedlast month.The community reviewed whether to reopen this questionlast monthand left it closed:Original close reason(s) were not resolvedImprove this questionI saw a StackOverflow question regarding static analysis in Scala, but that one was answered in 2009. As you know, the Scala tools are changing very rapidly.I was therefore wondering if someone familiar with the current state of static analysis tools in Scala could tell me if there's, say, a Findbugs equivalent for Scala. I found that Findbugs issues many unnecessary warnings for Scala, probably having to do with the way the "object" singleton compiles to bytecode, due to traits, etc. I heard that Scalastyle is not only a Scala version of Java's CheckStyle, that it also includes bits of Findbugs and PMD. But if it doesn't implement all of Findbugs and/or PMD, then are there other tools that supplement it? Or, is Scalastyle good not only for style checking, but is it good for improving code quality?Also, what about Scala's integration with, say, Sonar? Is the Scala Sonar plugin (which works with Scalastyle) reliable?
|
What's the current state of static analysis tools for Scala? [closed]
|
If you useSonarScanner CLIwith Docker, you may have this error because the SonarScanner container can not access to the Sonar UI container.Note that you will have the same error with a simple curl from another container:docker run --rm byrnedo/alpine-curl 127.0.0.1:9000
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
curl: (7) Failed to connect to 127.0.0.1 port 8080: Connection refusedThe solution is to connect the SonarScanner container to the samedocker networkof your sonar instance, for instance with--network=host:docker run --network=host -e SONAR_HOST_URL='http://127.0.0.1:9000' --user="$(id -u):$(id -g)" -v "$PWD:/usr/src" sonarsource/sonar-scanner-cli(other parameters of this command comes from theSonarScanner CLI documentation)ShareFollowansweredDec 3, 2019 at 19:09roipoussiereroipoussiere5,44033 gold badges3131 silver badges4242 bronze badgesAdd a comment|
|
when running the following command:
cmd /c C:\sonar-runner-2.4\bin\sonar-runner.bat(sonar runner is installed on the build machine)
i get the following errors:ERROR: Sonar server 'http://localhost:9000' can not be reachedERROR: Error during Sonar runner executionERROR: java.net.ConnectException: Connection refused: connectERROR: Caused by: Connection refused: connectwhat can cause these errors?Hi dinesh,this is my sonar-runner.properties file:sonar.projectKey=NDM
sonar.projectName=NDM
sonar.projectVersion=1.0
sonar.visualstudio.solution=NDM.sln
#sonar.sourceEncoding=UTF-8
sonar.web.host:sonarqube
sonar.web.port=9000
# Enable the Visual Studio bootstrapper
sonar.visualstudio.enable=true
# Unit Test Results
sonar.cs.vstest.reportsPaths=TestResults/*.trx
# Required only when using SonarQube < 4.2
sonar.language=cs
sonar.sources=.As you can see i set the sonar.web.host:sonarqube
sonar.web.port=9000 but when i run sonar-runner.bat i still get theERROR: Sonar server 'http://localhost:9000' can not be reached - why is it still looking for localhost:9000and not sonarqube:9000 as i set?i saw that in the log of sonar-runner.bat there the following line:
INFO: Work directory: D:\sTFS\26091\Sources\NDM\Source..sonarwhile my solution is in D:\sTFS\26091\Sources\NDM\Source\could this be the problem?thanks,
Guy
|
ERROR: Sonar server 'http://localhost:9000' can not be reached
|
Here are some resources to get you startedhttps://www.wrightfully.com/setting-up-sonar-analysis-for-c-projects/- See Step 6: The sonar-project.properties file.https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+ScannerThere are also some sample projects on github, you can refer to the project.properties files there as well,https://github.com/SonarSource/sonar-scanning-examplesShareFolloweditedApr 15, 2018 at 8:49answeredDec 4, 2015 at 8:10TechtwaddleTechtwaddle1,66311 gold badge1515 silver badges1111 bronze badges29The first link is quite out of date now, and the second one is not very detailed. This, although old, is more informative:devopsschool.com/tutorial/sonarqube/sonarqube-properties.html.–Ed GrahamJan 15, 2021 at 16:013The second link, even though it looks very official, is dead. Note that sonar actually recommends using the gui and not the .properties for configuration:community.sonarsource.com/t/…–julaineOct 20, 2022 at 10:21Add a comment|
|
I have very little exposure to SonarQube but have been asked to make a document explaining how to set up / use "sonar-project.properties file". Any information or input would be greatly appreciated.
|
How do I use, or set up sonar-project.properties file?
|
The call tous.toString()is redundant,toString()method will be called regardless the configured log level. You should pass onlyusas an argument toinfowithout anifstatement.logger.info("Log this: {}", us);ShareFolloweditedJun 5, 2017 at 10:00Olezt1,68811 gold badge1717 silver badges3131 bronze badgesansweredJun 2, 2017 at 14:18Tibor BlenessyTibor Blenessy4,3123030 silver badges3737 bronze badges32Is this answer really correct? In my case the warning is raised by using the same syntax in the answer.–funder7Jul 7, 2020 at 15:19@Funder can you share full code sample in gist or with some other online service? I can look into it–Tibor BlenessyJul 9, 2020 at 14:59here we go @Tibor Blenessygist.github.com/funder7/928484ff56b5db999d8472a931db14c4. I've included the class received by the method, in case you need it. Thank you!–funder7Jul 10, 2020 at 9:22Add a comment|
|
The following part of code raises a major bug at SonarQube :
"Invoke method(s) only conditionally."How am I supposed to fix this?if(us != null){
logger.info("Log this: {}", us.toString());
}
|
SonarQube: Invoke method(s) only conditionally
|
If you are not using any command-line arguments ,then you could avoid mentioning the args parameter in the run method .Like the below code.@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class);
}
}This will remove sonarqube hotspot issue.ShareFollowansweredMar 16, 2020 at 7:24sachinsachin1,30011 gold badge1414 silver badges2424 bronze badges0Add a comment|
|
SonarQube is just showing a Critical security issue in the very basic Spring Boot application. In the main method.@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}SonarQube wants me toMake sure that command line arguments are used safely here.I searched this on both StackOverflow and Google, and I am surprised that I couldn't find any single comment about this issue. I am almost sure that there are some security checks inside theSpringApplication.runmethod already. And also, I don't even remember that anyone sanitizes the main method arguments before callingSpringApplication.run. I simply want to tag it asfalse positiveand move on.Part of this question is also asked here:SonarQube shows a secuirty error in Spring Framework controllers and in Spring Framework Application main classIs it false positive?
|
SonarQube rule: "Using command line arguments is security-sensitive" in Spring Boot application
|
If you have a java project, you must create a sonar-project.properties file in the folder where you execute sonar runner. You must define the following properties inside this file:# Required metadata
sonar.projectKey=java-sonar-runner-simple
sonar.projectName=Simple Java project analyzed with the SonarQube Runner
sonar.projectVersion=1.0
# Comma-separated paths to directories with sources (required)
sonar.sources=src
# Language
sonar.language=java
# Encoding of the source files
sonar.sourceEncoding=UTF-8Hope this helps,ShareFollowansweredApr 24, 2014 at 8:09albciffalbciff18.3k44 gold badges6666 silver badges9090 bronze badges2Thanks for this. FYI: I'm using Jenkins 2.10 with Sonar Scanner 2.6.1: the paths in valuesrcare relative to the Jenkins job workspace; in the job configuration,Path to project propertiesis a relative path to the file (not the folder).–groverboyAug 9, 2016 at 4:06This need doesn't apply to Maven or Gradle projects–G. Ann - SonarSource TeamMay 26, 2017 at 14:52Add a comment|
|
Learning how to use SonarQube and was doing a quick install fromhereGot all the way down to step 5. My build fails when I execute:
C:\sonar-runner\bin\sonar-runner.batI get the following error:INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
Total time: 7.572s
Final Memory: 8M/223M
INFO: ------------------------------------------------------------------------
ERROR: Error during Sonar runner execution
ERROR: Unable to execute Sonar
ERROR: Caused by: You must define the following mandatory properties for 'Unknown': sonar.projectKey, sonar.projectName, sonar.projectVersion, sonar.sources
ERROR:
ERROR: To see the full stack trace of the errors, re-run SonarQube Runner with the -e switch.
ERROR: Re-run SonarQube Runner using the -X switch to enable full debug logging.Anyone encountered a similar situation and resolved?
|
Sonar Setup Undefined Mandatory Properties
|
I have found the answer here:False Positive option don't appear on projectsThe issue is that although the admin LDAP group I belong to was granted "Administer System" rights in Global Permissions, it also needs to be added excplicitly to Project Permissions (either per project, or to the default template).ShareFolloweditedMay 23, 2017 at 12:17CommunityBot111 silver badgeansweredApr 16, 2015 at 9:51RCrossRCross4,98844 gold badges4545 silver badges4242 bronze badges1Note that the minimal permission required isAdminister Issuesas per theanswerbelow.–Dennis T --Reinstate Monica--May 9, 2019 at 19:19Add a comment|
|
I've recently installed SonarQube 5.0.1, but I can't find where to mark issues as false-positive. In the drop-down box where this option used to be, the only option is "Link to JIRA", and I'm signed in as admin.Is this feature now provided as part of an optional plugin?EDIT: I have added a screenshot of exactly what I see in the UI.
|
Sonarqube 5 - how do I mark false-positive?
|
You can set the "sonar.forceAuthentication" to "true" in the web admin interface:Seehttp://docs.sonarqube.org/display/SONAR/Authenticationfor more details.ShareFolloweditedAug 29, 2016 at 16:36user111538,67655 gold badges4848 silver badges5151 bronze badgesansweredMay 30, 2013 at 6:45Fabrice - SonarSource TeamFabrice - SonarSource Team26.6k33 gold badges6363 silver badges5858 bronze badges0Add a comment|
|
I have installed Sonar 3.5.1 and want to disable anonymous users access to the web console.
I went to Security page and deleted Anyone from users and codeviewers roles.
However, when I visit the web console without authentication I am still able to see "Welcome to Sonar Dashboard" page, whereas I expected to be redirected to the login page.Is it possible to completely disallow unauthenticated users to see any content except the login page?
|
Disallow anonymous users to access Sonar
|
You have to remove this rule in the quality profile that you are using to analyse your project.Please refer to the documentation that describes all this:Quality Profiles in Sonar.ShareFolloweditedJul 15, 2022 at 15:25Ryan3,16566 gold badges3232 silver badges4848 bronze badgesansweredMay 6, 2013 at 13:44Fabrice - SonarSource TeamFabrice - SonarSource Team26.6k33 gold badges6363 silver badges5858 bronze badges32where is this quality profile?on localhost:9000,i am getting a profile and rules list but no option for disable a rule.–Ankit GuptaDec 15, 2014 at 11:48@Ankit you need to login to see the Deactivation button–DerrickOct 18, 2016 at 7:49how to disable those from .net project. I want to add that rule in dotsettings file. i have added rules which i dont want in dotsettings file. can you please help?–Sushil MateDec 15, 2016 at 17:58Add a comment|
|
I want to disable a rule from Sonar so it doesn't show the results in the web page.
In my case I want to hide (or not capture) the results about trailing comments.Is it posible to configure it somewhere?Thanks.
|
Disable rule in sonar
|
You could run a script that does:cat lcov.info | egrep "^(SF|DA|BRDA):" > lcov.info.new; mv lcov.info.new lcov.info.With that I get:SF:./app/scripts/app.js
DA:2,1
DA:20,1
DA:29,0
DA:34,0ShareFollowansweredMar 5, 2017 at 23:46DorianDorian23.3k99 gold badges123123 silver badges116116 bronze badgesAdd a comment|
|
I've configured Karma to report the coverage of my JavaScript code. Here is the part of the configuration in thekarma.conf.jsfile:coverageReporter: {
reporters: [
{
type: 'html',
dir: 'build/karma/coverage'
},
{
type: 'lcov',
dir: 'build/karma/coverage',
subdir: '.'
},
{
type: 'cobertura',
dir: 'build/karma/coverage'
}
]
},Mylcov.infofile has the following format:TN:
SF:./app/scripts/app.js
FN:16,(anonymous_1)
FN:26,(anonymous_2)
FNF:2
FNH:1
FNDA:1,(anonymous_1)
FNDA:0,(anonymous_2)
DA:2,1
DA:20,1
DA:29,0
DA:34,0
LF:4
LH:2
BRF:0
BRH:0
end_of_recordUnfortunately,the Sonarqube JavaScript pluginonly considers the lines that start withSF:,DA:orBRDA:(cfLCOVParser).Due to that, the LCOV HTML report (made by Istanbul) gives me a higher code coverage than Sonar on the same data.Is there a way to change the format of thelcov.infogenerated?If I look inIstanbul code, I can imagine the meaning of the different labels:BRF,BRH,BRDAare forbranches.FN,FNF,FNH,FNDAare forfunctions.LN,LF,LHare forlines.*Fis the total, while*His the covered information.The difference between the Istanbul and Sonar coverage seems to be due to the fact that the latter completely ignores the Functions and Branches coverage.Any idea to solve that?
|
How to change the format of the LCOV report executed by Karma?
|
Summing up the above mentioned answers and also adding one point to it.To exclude a project from SonarQube Analysis from csproj we can achieve by adding the below code in .csproj of that project<PropertyGroup>
<!-- Exclude the project from analysis -->
<SonarQubeExclude>true</SonarQubeExclude>
</PropertyGroup>To exclude a file from a project<ItemGroup>
<SonarQubeSetting Include="sonar.coverage.exclusions">
<Value>**/FileName.cs</Value>
</SonarQubeSetting>
</ItemGroup>And for multiple files<ItemGroup>
<SonarQubeSetting Include="sonar.coverage.exclusions">
<Value>**/FileName1.cs, **/FileName2.cs</Value>
</SonarQubeSetting>
</ItemGroup>Also can refer this forregex patternsusedShareFolloweditedSep 17, 2019 at 11:03answeredSep 17, 2019 at 10:53Naveen R KumarNaveen R Kumar69677 silver badges77 bronze badgesAdd a comment|
|
Sonarqube allows for individual files to be excluded from code coverage by adding patterns in thesonar.coverage.exclusionskey. This can be done on a project level by adding them in the UI and even in a .csproj file by specifying aSonarQubeSettingelement. I.e.<SonarQubeSetting Include="sonar.coverage.exclusions">
<Value>**/*.cs</Value>
</SonarQubeSetting>However, both of these approaches don't seem to work. Playing with the patterns, as specified in the SonarQubedocumentationdoesn't provide the desired result. I'm also aware of the existence of theSonarQubeExcludeMSBuild property, but I don't want to go down that path as it would exclude my project from all other analysis.Is there another possibility that I'm missing? Or is it simply not possible to exclude all of the classes within a project from code coverage?
|
How to make Sonarqube exclude a .NET (C#) project from coverage measures
|
Answer is very simple:"Runner"is the old name for"Scanner".Everything you need to know about the different SonarQube Scanners is available on theScannerspart of the official documentation.If you're stuck toJava 7, then you can use:SonarQube Runner (sonar-runner) up to version 5.5 of SonarQubeSonarQube Scanner (sonar-scanner) 2.6.1ShareFolloweditedApr 19, 2018 at 7:08Vishal Yadav3,64233 gold badges2525 silver badges4242 bronze badgesansweredOct 4, 2016 at 12:34Fabrice - SonarSource TeamFabrice - SonarSource Team26.6k33 gold badges6363 silver badges5858 bronze badges0Add a comment|
|
What is the difference btw Sonar Runner and Sonar Scanner?.And which version of "Sonarqube" and Sonar runner is required for JDK7?
|
SonarQube Runner vs Scanner
|
As dotnet core projects (.csproj) will not have<ProjectGuid>...</ProjectGuid>tag specified in the default template this needs to be manually added.So you need to edit the .csproj file like this:<PropertyGroup>
<!-- other properties here -->
<!-- SonarQube needs this -->
<ProjectGuid>{E2CEBBAF-6DF7-41E9-815D-9AD4CF90C844}</ProjectGuid>Make sure to place your own GUID inside the<ProjectGuid>...</ProjectGuid>TagShareFollowansweredMay 23, 2018 at 4:18DanielDaniel9,6591212 gold badges5252 silver badges6868 bronze badges101create a new one using e.g.guidgenerator.com/online-guid-generator.aspx–DanielJul 13, 2018 at 12:171So there is absolutely no connection between this GUID and the ones in the .sln file–KobekJul 13, 2018 at 12:533Correct. There is no Connection.–DanielJul 13, 2018 at 13:243Powershell to fix it write-host "<ProjectGuid>{$([guid]::NewGuid().ToString().ToUpper())}</ProjectGuid>"–Patrik LindströmSep 6, 2018 at 13:211Thank you so much for your guidance. This is a very critical issue which has no proper solution. I have checked all possible way but didn't get proper solution. Applying your solution, i get to know this issue belongs to VS2017. Before that i was feeling so helpless. Thanks again to post a very useful solution for us.–SapnanduMay 17, 2020 at 10:41|Show5more comments
|
When you are building a dotnet core project with SonarQube you may be facing the error in the log:WARNING: The following projects do not have a valid ProjectGuid and were not built using a valid solution (.sln) thus will be skipped from analysis...What should you do?
|
The following projects do not have a valid ProjectGuid and were not built using a valid solution (.sln) thus will be skipped from analysis
|
Issue was in the wrapper.conf where the java wrapper command was not getting resolved. It worked if I give the absolute path - ‘wrapper.java.command=/path/to/my/jdk/bin/java’This could be an issue with an environment on a host.. not sure.Few things that helped me in troubleshooting this -log level changed to DEBUG in wrapper.confcomments given in the wrapper.conf!Thanks all for chiming in! Appreciate your inputs.ShareFollowansweredApr 10, 2015 at 22:50RishiRishi6,00977 gold badges3535 silver badges4545 bronze badges4This solution worked for my installation on ubuntu 14 and sonarqube 5.1.2.–AmitabhAug 12, 2015 at 12:46@Amitabh Good to know-) StackOverflow is awesome.–RishiAug 12, 2015 at 17:374I've usedwrapper.java.command=%JAVA_HOME%/bin/javato avoid absolute path.–Grzegorz Adam KowalskiJul 7, 2016 at 14:40On MacOS, i needed copy the wrapper.conf file and past on the same path of wrapper exec, with wrapper.java.command=/Library/Java/JavaVirtualMachines/jdk-15.0.2.jdk/Contents/Home/bin/java–Lucas SimõesJan 20, 2021 at 15:38Add a comment|
|
I am facing strange issue with sonarqube 5.0.1 , one one of the machine it is not starting. Here is the error log - sonar.log ---> Wrapper Started as Daemon
Launching a JVM...
Unable to start JVM: No such file or directory (2)
JVM exited while loading the application.
JVM Restarts disabled. Shutting down.
<-- Wrapper StoppedMachine is x86_64 GNU/Linux - Centos 5.1.this box has java installed -$java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)The same sonarqube package works on another machine.Any idea what could be the issue here?Thanks.
|
Error in sonar startup, Unable to start JVM: No such file or directory (2)
|
I found the solution -The maven plugin I have included has configuration of Jacoco's destfile and datafile as${basedir}/target/coverage-reports/jacoco-unit.execbut by default sonar reads at${basedir}/target/jacoco.exec. I changed the default at http://localhost:9000/settings?category=javaRef:Sonar Code CoverageCouldn't find the working reference link. Here is aux link:Baeldung Sonar and jacocoShareFolloweditedNov 25, 2021 at 8:53answeredMay 25, 2017 at 8:50Tarun MagantiTarun Maganti3,18633 gold badges3838 silver badges6666 bronze badges42Reference link is dead–coler-jJun 18, 2019 at 20:011Life saver! Thank you for posting.–cadebeFeb 8, 2020 at 21:28Did you re-run sonarqube for the changes to take effect??–Taranmeet SinghDec 5, 2021 at 14:12I don't actually remember, it was 4.5 years ago. Please check the documentation. I tried looking for it, couldn't find.–Tarun MagantiDec 5, 2021 at 18:14Add a comment|
|
I'm running sonarqube with maven.I have installed it using followingway.
Usingbrew, I installedmysqlandsonar.When I run I get 7 critical bugs but the code coverage for 88 tests is zeroWhen I run it with IntelliJ's tools, I get the following results. (not zero!)This is when I check Jacoco results directly. In$base_direc/target/jacoco/index.htmlThe same code when run with sonar-scannerThis is my maven configurationMy~/.m2/settings.xmlEdit 1:
I have found this in logs.Edit2:
I have edited~/.m2/settings.xmladded<properties>
<sonar.host.url>http://localhost:9000/</sonar.host.url>
</properties>Edited/usr/local/Cellar/sonarqube/6.3.1/libexec/conf/sonar.propertiesaddedsonar.host.url=http://localhost:9000/Edited/usr/local/etc/sonar-scanner.propertiesadded -sonar.host.url=http://localhost:9000/Ran the application in all above ways and the results were same, i.e, I could see Jacoco results but not in sonar.Is it possible that if bugs are found sonar refuses to do code coverage?!
|
Sonarqube is not showing code coverage after running
|
I had the same issue when using sonar maven plugin and jacoco test reports.mvn sonar:sonarrelies on an existintig jacoco report, when the source code was changed (lines had been removed), but the test report wasn't updated this error occurred. Runningmvn clean test sonar:sonarsolved it.ShareFollowansweredJan 9, 2017 at 16:50DonDon1,14488 silver badges1515 bronze badges1True. I got the same problem and the cause was also an outdated jacoco report.–dokasparMay 12, 2017 at 6:39Add a comment|
|
[07:43:57]W: [Step 1/1] ERROR: Error during SonarQube Scanner execution[07:43:57]W: [Step 1/1] ERROR: Line 523 is out of range in the file
src/main/java/com/company/package/File.java
(lines: 522)For some reason Sonarqube is reporting an error on line 523 but there is only 522 lines in the source file ?I saw this on a previous file, but when I added a blank line to the end of it the problem went away, this file already has a blank line at the end of it.
|
Sonarqube scan error with line out of range?
|
Running sonar withmvn sonar:sonar -Dsonar.jdbc.url=jdbc:h2:tcp://ipaddr:9092/sonar -Dsonar.host.url=http://ipaddr:9000,where ipaddr is your remote host, seems to work.ShareFollowansweredFeb 1, 2013 at 15:01teknopaulteknopaul6,61722 gold badges3030 silver badges2424 bronze badges11also changed the sonar server config to use actual host name instead of localhost–RaulMay 29, 2013 at 11:36Add a comment|
|
I have maven installed on my local machine and I'm trying to test out Sonar installed on a remote box.I found a few post online to configuresettings.xml(maven\config\settings.xml)and append a profile entry...which I did but does not work<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!-- SERVER ON A REMOTE HOST -->
<sonar.host.url>http://remotebox:9000</sonar.host.url>
</properties>
</profile>What is the cli way? I tried several options but nothing worked.I tried:mvn sonar:sonar http://remotebox:9000What is the correct syntax?Thanks in advance.
DamianPS. this works fine on the remote box where both maven and sonar are installed...i just want to try it my box to the remote box.
|
maven connecting to Sonar
|
NOTE:This property is deprecated since version 4.3 and should not be used anymore.From thedocumentation, there is an option to skip module usingsonar.skippedModulesYou could also do this from the sonar admin page as documented in the Skipping Modules sectionhere.ShareFolloweditedJun 29, 2017 at 20:25Jmini9,32133 gold badges5656 silver badges8080 bronze badgesansweredApr 10, 2014 at 7:30RaghuramRaghuram52.1k1111 gold badges112112 silver badges123123 bronze badges112Note that :" This property is deprecated since version 4.3 and should not be used anymore."–gontardNov 10, 2014 at 14:10Add a comment|
|
I have many(Let say 10 (A, B, C...)) eclipse plugin which is maven based.I have one master pom file which includes all other plugin projects.
now by building master file withsonar:sonargoal it will build all the plugins.So my question:Is there is any way so that I can exclude some plugin let say A and C.?
|
How to exclude some maven project from sonar analysis
|
Since SonarQube 4.0, you can defineissue exclusion patternsbased on rule key and file path pattern.On previous versions, you can rely upon theSwitch Off Violations plugin.ShareFolloweditedApr 5, 2022 at 18:18Sjeiti2,54811 gold badge3131 silver badges3434 bronze badgesansweredJan 14, 2014 at 9:03MithfindelMithfindel4,64811 gold badge2323 silver badges3232 bronze badges33Great, thanks. A note for future folks that land on this page: the rule key pattern is <repository>:<key>–user153275Jan 14, 2014 at 16:304@mith The link is broken. Please make your answer self contained.–1010Dec 1, 2015 at 14:18docs.sonarqube.org/x/JQAWdoesn't work.–user674669Sep 7, 2023 at 9:39Add a comment|
|
I've got a project I'm working on and some of the files violate some of the rules, but in ways that are not real issues, and are thus distracting noise. However, I don't want to disable these rules globally, and I would prefer not to have to mark 'em as false positives one by one.Is there a way to disable Sonar rules for specific files, and if so, how?
|
How to disable Sonar rules for specific files?
|
First try to stop the SonarStart.bat by using Ctrl+c as suggested , and then try to open localhost:9000 ( or whichever port you configured sonar server).If it is still opening then go to task manager and search forwrapper.exeservice and stop the service, if no service or app is found then goto:Task manager>Details> and stop all java.exe process.Note: If you running many java applications, right-click the java.exe and choose goto service, and stop only those java.exe that belongs to AppX deployment.ShareFollowansweredJul 14, 2019 at 21:26PDHidePDHide18.9k22 gold badges3737 silver badges5050 bronze badgesAdd a comment|
|
I use sonarqube 4.3 and I can't find a script to stop sonar in windowsx86-64.It's awkward to haveStartSonar.batand nothing to stop.When I use it on in linux-x86-64 I can use./sonar.sh stop.I saw that there was aStartNTService.batand aStoptNTService.batbut i don't want to install sonar as a service.
|
Stop sonar on window 64
|
Shortly, leak period is time frame (usually since last release), where specified criteria are measured on newly added code. This allows to focus on quality of fresh code and stop the accumulation of technical debt.The "leak" concept is explained in documentation herehttps://docs.sonarqube.org/display/SONAR/Fixing+the+Water+LeakUpdateSonarSource has fleshed-out and updated the terminology / philosophy:https://sonarqube.org/features/clean-as-you-code.ShareFolloweditedDec 5, 2019 at 19:26G. Ann - SonarSource Team22.5k44 gold badges4242 silver badges8484 bronze badgesansweredJan 9, 2017 at 15:24Tibor BlenessyTibor Blenessy4,3123030 silver badges3737 bronze badges0Add a comment|
|
I'm new in SonarQube I started reading documentation but a lot of time a found"The leak period"but I didn't found anything about it can someone explain me what it means.
|
What does the "leak period" mean in sonarQube?
|
Coverage is a subtle ;-) mix of the line and the branch coverage.You can find the formula on ourmetric description page:coverage = (CT + CF + LC)/(2*B + EL)
where
CT - branches that evaluated to "true" at least once
CF - branches that evaluated to "false" at least once
LC - lines covered (lines_to_cover - uncovered_lines)
B - total number of branches (2*B = conditions_to_cover)
EL - total number of executable lines (lines_to_cover)ShareFolloweditedAug 1, 2022 at 15:40Julian35.1k2323 gold badges125125 silver badges182182 bronze badgesansweredJul 19, 2012 at 14:05Fabrice - SonarSource TeamFabrice - SonarSource Team26.6k33 gold badges6363 silver badges5858 bronze badges1awesome, I was unable to find that page via google... THanks!–Bartosz RadaczyńskiJul 19, 2012 at 14:24Add a comment|
|
I know what the difference is between line and branch coverage, but what is the difference between code coverage and line coverage? Is the former instruction coverage?
|
What is the difference between code coverage and line coverage in sonar
|
I believe the only syntax supported for Python (assuming itissupported) isthe NOSONAR comment, so#NOSONARor# NOSONARat the end of the line where you want to ignore issues.Unfortunately, this is a global issue suppression: it killsallissues on the line, not just those from a specific rule.ShareFolloweditedOct 1, 2022 at 4:03Gino Mempin27.2k2929 gold badges107107 silver badges149149 bronze badgesansweredJun 3, 2016 at 11:28G. Ann - SonarSource TeamG. Ann - SonarSource Team22.5k44 gold badges4242 silver badges8484 bronze badges628Is it possible to suppress specific rules in 2020?–Matthew MoisenMay 10, 2020 at 18:3032or maybe in 2021?–The HogMar 16, 2021 at 10:0321or perhaps in 2022?–m000Jan 3, 2022 at 20:3527or would be in 2023? - am time travelling–nightlytrailsJan 18, 2022 at 13:487or maybe in 2024 ?–forzagreenJan 9 at 12:29|Show1more comment
|
How can I ignore SonarQube warnings in Python codeIn Java, I can use@SuppressWarnings("squid:S1166")Where the ID is the SonarQube rule ID. But what syntax should I use in Python?I've tried# noinspection python:S1313but it didn't work.To be clear, I'm looking for a solution in python code. NOT JAVA.
|
Ignore SonarQube warnings in python
|
You might want to look atthis part of the Sonar documentation, specifically at the sonar.branch parameter. It seems to be designed for what you want to do, and is working that way for us.ShareFolloweditedMar 4, 2015 at 16:16andref4,4793434 silver badges4646 bronze badgesansweredJul 17, 2014 at 13:23Dennis S.Dennis S.2,1111414 silver badges1515 bronze badges102Works for us, too. I tried usingsonar.projectKey, but that is not carried to submodules.–ChristophTFeb 6, 2017 at 10:1810SonarQube documentation now states that the sonar.branch is deprecated from SQ 6.6–Jeroen PotNov 14, 2017 at 16:142Apparently, they have some branch support in the Developer edition. Tough luck...–kapDec 11, 2017 at 15:332@heroin: The doc of the plugin doesn't explicitly say so does it? Anyhow I found there is a GPL plugingithub.com/s-pw/sonar-branch-community(untested)–s.DanielApr 26, 2018 at 11:503The sonar-branch-community plugin seems to be no longer available. Is there any alternative?–PabiJul 9, 2018 at 21:28|Show5more comments
|
I know that there is no "new project" button on SonarQube UI. However, I have two branches of the same project that I want to do analysis on. The thing is that since the project names are the same, SonarQube will upload the analysis results of the two branches into the same project on SonarQube Server. How do I configure SonarQube so that one branch will upload analysis results to one project and the other branch will upload results to another project on SonarQube server?
|
SonarQube - analyzing branches of the same project
|
"Lines to Cover" are the total lines in your "production" code that you should, in a so-called perfect world, have tests for. This is every line in source code files, which is not a comment, blank or similar non-code line.In the real world, your tests will only cover some of these. The lines that are missed are the "Uncovered Lines".In other words, you can express "Coverage" as:"Coverage" = 100% - 100 * "Uncovered Lines" / "Lines to Cover"ShareFolloweditedSep 19, 2018 at 13:20TafT2,90466 gold badges3434 silver badges5454 bronze badgesansweredSep 19, 2018 at 12:06MureinikMureinik302k5353 gold badges319319 silver badges362362 bronze badges23Oh, so Line to Cover is more similar to a Lines of Code (LOC) count. I was reading it as it is the number of lines that need to be covered (hence it being very similar to uncovered lines). Thank you for the clarification. I suggested an emphasis edit to make it so that it is really, really obvious what the part I read wrong actually means.–TafTSep 19, 2018 at 13:222Lines to cover are similar to ncloc (non commenting LOC). But not exactly the same. For example in Java, annotations, or interface declarations are counted in ncloc, but not in lines to cover.–Julien H. - SonarSource TeamSep 21, 2018 at 8:23Add a comment|
|
I am looking at the Coverage report within the Measures tab of a SonarQube analysed C++ project. On that page my summary information is as follows:What are the differences between the "Lines to Cover" and "Uncovered Lines" metrics?I have looked onthe sonarqube website's Metric Definitions pagebut the two entries there to do not help me.Lines to cover- Number of lines of code which could be covered by unit tests (for example, blank lines or full comments lines are not considered as lines to cover).Uncovered lines- Number of lines of code which are not covered by unit tests.The way that reads, I would expect that Uncovered Lines would be a higher count than the Lines to cover number, as the former might include blank lines. If sonarqube understood the code somewhat it might also exclude exception handling from the "could be covered by unit tests" number as well.The given numbers are clearly a reverse of that, so I must not be understanding the meaning correctly.I have some unit tests run as part of the CI system and their code coverage is compilated using both lcov and gcov. The lcov data is passed through genhtml to make separate coverage report which currently gives data in some cases, so I may have partial misconfiguration issue adding to the confusion.
|
In SonarQube what is the difference in meaning between the "Lines to Cover" and "Uncovered Lines" metrics?
|
I had the same error where my sonarqube server was behind an nginx proxy.413==Request entity too largeas @jeroen-heier said.I applied a change to my nginx configuration like thisserver {
...
client_max_body_size 20M;
....
}to allow requests to be 20 megabytes, and that fixed it.ShareFollowansweredSep 21, 2016 at 15:29Peter MouncePeter Mounce4,18544 gold badges3535 silver badges6767 bronze badges12Tip#1: The http-server is not shown in sonar's configuration files. You can check if your sonar server is using nginx by runningsudo server nginx stopand seeing if the url is reachable. Tip#2: In stead ofserver {}it can also be ahttporlocationblock. Look at thedocumentationfor more info.–Leon S.Feb 27, 2017 at 9:56Add a comment|
|
I've recently installed the latest version ofJenkins,SonarQube 6.0(running on a separate server) and when theJenkins jobattempts to uploadsonar scannerresults to theSonarQube server, I get the following error:'ERROR: Error during Sonar runner execution
org.sonar.runner.impl.RunnerException: Unable to execute Sonar
at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:91)
at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:75)
at java.security.AccessController.doPrivileged(Native Method)
at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69)
at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)
at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102)
at org.sonar.runner.api.Runner.execute(Runner.java:100)
at org.sonar.runner.Main.executeTask(Main.java:70)
at org.sonar.runner.Main.execute(Main.java:59)
at org.sonar.runner.Main.main(Main.java:53)
Caused by: org.sonarqube.ws.client.HttpException: Error 413 on http://****`What could be the cause?An error in the sonar-project properties?
|
How to resolve "HttpException: Error 413" (SonarQube)
|
You have to use the double asterisk pattern to recursively exclude all sub-folders and files:sonar.exclusions=test/**, node_modules/**A single asterisk matches only the files on that specific folder (no recursion).ShareFollowansweredAug 17, 2016 at 16:13Pedro PennaPedro Penna1,13711 gold badge1515 silver badges2424 bronze badges11Can we exclude files only from code coverage and check for issues?–Shanika EdiriweeraJan 1, 2020 at 8:16Add a comment|
|
I have a sonar-project.properties file, which specifies how sonar-runner inspects the the folder structure, which files to inspect, which files to ignore etc.I cannot successfully determine however how to exclude multiple paths successfully.Here is the sonar-project.properties file:sonar.projectKey=C3S-web
sonar.projectName=C3S-sonar-web
sonar.projectVersion=0.0.1
sonar.sources=.
sonar.tests=test
sonar.language=js
sonar.profile=Sonar way
sonar.exclusions=test/*, node_modules/*
sonar.dynamicAnalysis=reuseReports
sonar.javascript.jstest.reportsPath=coverage
sonar.javascript.lcov.reportPath=coverage/lcov-reportthe line I am having trouble with is:sonar.exclusionslisting multiple paths does not work, with or without a comma, or in quotes either.
|
Properties file exclude multiple paths
|
Each Sonar profile publishes it's Checkstyle, FIndbugs and PMD configuration under thepermalinkstab.Assuming you've got Sonar installed locally, the following link shows the configuration files used by the "Sonar Way" profile:http://localhost:9000/profiles/permalinks/2ShareFollowansweredNov 16, 2011 at 21:02Mark O'ConnorMark O'Connor76.6k1010 gold badges140140 silver badges186186 bronze badgesAdd a comment|
|
My company has sonar set up to with various plugins (PMD,FindBugs,CheckStyle), and although it is very useful as is (it runs after every Jenkins build that was triggered by a check-in toSVN), I would like it if I could run these various plugins on my local machine before I check the code in.We have a set of rules already set up inSonar, so ideally I would like to be able to export that ruleset, perhaps do somemungingof the data, and then import the resulting rules into my IDE (Netbeans 7.0.1) into the respective plugins. Is there any way to do this? I've searched all over and short of going through and manually adding each rule to the various plugins, there doesn't appear to be a way to do this. Is there something I'm missing?TL;DR(Summary): I'd like to export a profile from sonar and import the rule settings into thePMD,Findbugs, andCheckStyleplugins inNetbeans.
|
How to export FindBugs/PMD/Checkstyle rules from Sonar and import into Netbeans
|
There is a parameter in StyleLint for that situation:"rules": {
"selector-type-no-unknown": [true, { "ignoreTypes": ["/^mat-/","/^retrace-/"] }]
}ShareFollowansweredNov 17, 2020 at 2:39Kavinda SenarathneKavinda Senarathne1,8971313 silver badges1515 bronze badges23In which file do I change these rules...and where do I find this file?–Dhritiman Tamuli SaikiaMar 6, 2021 at 4:39@DhritimanTamuliSaikia read the docs onconfiguration.–Paul Razvan BergNov 17, 2021 at 11:58Add a comment|
|
I am running sonarqube's CSS analyzer over my Angular 7 project and it is marking all references to material2 elements in my scss as critical bugs.For example:Unexpected unknown type selector "mat-form-field"How do I add exceptions for selectors with the "mat-" prefix using the sonar-project.properties file?I've tried a number of different variations on what I've foundherebut I've been unable to find an example of this done in a properties file.I'm looking for something like this:sonar.css.selector-type-no-unknown.ignoreTypes=["/^mat-/"]
|
Sonarqube css: How to disable "Unexpected unknown type" rule for selectors with prefix "pr-"
|
I realized that first I should have written directory name Like below to exclude all folders and file on that directory:sonar.exclusions=utility/Excel/**/*Second I should have used comma separated directory names to exclude more than one directory:sonar.exclusions=utility/Excel/**/* , utility/mailer/**/*ShareFollowansweredAug 29, 2016 at 5:05Fatemeh RostamiFatemeh Rostami1,07711 gold badge1515 silver badges2727 bronze badges33thanks for the comma separation information. It saved me a day.–SanthoshMMay 24, 2017 at 16:062ok I just wanna throw out that it's really confusingsonar.sourcesuses path relative to sonar-project.properties, and apparentlysonar.exclusionsdoesn't? ugh took me forever. thanks, never would have tried that–ColeJan 3, 2018 at 2:01how to exclude multiple files?–Shankar S BavanMay 13, 2023 at 8:19Add a comment|
|
I have excluded the directory in my project properties but sonar doesn't exclude it. Can anyone help me to find problem?sonar.sources=./
sonar.exclusions=./utility/Excel/**
|
Directory excluding in sonar-project.properties file doesn't work (for me)
|
You have to edit the<install_directory>/conf/wrapper.conffile and update thewrapper.java.commandproperty to point to the JDK you want.Everything is documented in thiswrapper.conffile.ShareFollowansweredDec 19, 2014 at 10:24Fabrice - SonarSource TeamFabrice - SonarSource Team26.6k33 gold badges6363 silver badges5858 bronze badges11FYI, For macOS with Homebrew, the location is/usr/local/opt/sonarqube/libexec/conf/wrapper.conf.–Jin KwonJan 3, 2020 at 3:29Add a comment|
|
Is there a way to start the SonarQube server (v. 3.7.4) with an specific jdk?My case: My java-home is set to jdk 1.8, but SonarQube server has some known problems with 1.8. So I want to start the server with jdk 1.7 (without setting my java-home to 1.7).
I couldn't find anything in the bat-files.OS: Windows 7; SonarQube server version: 3.7.4
|
start SonarQube server with specific jdk
|
We would need to set the right version of Java. In sonarqube-5.6, change the property in the filesonarqube-5.6/conf/wrapper.confwrapper.java.commandtowrapper.java.command=/mypath/jdk1.8.0_73/bin/javaFor Windows may need to edit fromwrapper.java.command=javatowrapper.java.command=mypath\Java\jdk1.8.0_92\bin\javaShareFolloweditedJun 15, 2017 at 20:28pal4life3,29055 gold badges3636 silver badges5757 bronze badgesansweredJun 30, 2016 at 4:11mmukhemmukhe6681010 silver badges2222 bronze badges1how do I find the java path? Turns out 1 uses where Java in windows. Usually its in program files.–pal4lifeJun 15, 2017 at 20:00Add a comment|
|
I got a problem at SonarQube starting! In fact, it doesn't start and I don't get more informations only :--> Wrapper Started as Daemon
Launching a JVM...
Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org
Copyright 1999-2006 Tanuki Software, Inc. All Rights Reserved.
WrapperSimpleApp: Unable to locate the class org.sonar.application.App: java.lang.UnsupportedClassVersionError: org/sonar/application/App : Unsupported major.minor version 51.0
WrapperSimpleApp Usage:
java org.tanukisoftware.wrapper.WrapperSimpleApp {app_class} [app_arguments]
Where:
app_class: The fully qualified class name of the application to run.
app_arguments: The arguments that would normally be passed to the
application.
<-- Wrapper StoppedCan someone help me?
|
SonarQube does not start
|
I'm assuming this is a warning (not using the value returned byorElseThrow()shouldn't be an error).If you wish to eliminate that warning, useisPresent()instead:if (!itemList.stream().filter(i->orderItemId.equals(i.getId())).findAny().isPresent()) {
throw new BadRequestException("12345","Item Not Found");
}or just avoid usingOptionals, and useanyMatch()instead:if (!itemList.stream().anyMatch(i->orderItemId.equals(i.getId()))) {
throw new BadRequestException("12345","Item Not Found");
}ShareFolloweditedMar 28, 2018 at 11:31answeredMar 28, 2018 at 10:47EranEran390k5555 gold badges708708 silver badges776776 bronze badges5Using empty() seems not the correct way.How ever the second option anyMatch() is the perfect solution for this.Thank you.–Baji ShaikMar 28, 2018 at 11:179for the first solution, I believe you're looking for!itemList.stream().filter(i->orderItemId.equals(i.getId())).findAny().isPresent()but the better solution would be to useitemList.stream().noneMatch(i->orderItemId.equals(i.getId()))–Ousmane D.Mar 28, 2018 at 11:28@Aominè yep, for some reason I was sure there was anempty()method that indicates whether an existing Optional is empty.–EranMar 28, 2018 at 11:316…and eliminate thelogical notby usingnoneMatchin the first place.–HolgerMar 28, 2018 at 12:095My opinion is that this is not a solution changing your code with a simplyorElseThrowto something else only because a false positive warning.–SaljackAug 26, 2020 at 14:10Add a comment|
|
When I am scanning code with sonar lint the following code shows the bug as "The return value of "orElseThrow" must be used"itemList.stream()
.filter(item -> orderItemId.equals(item.getId()))
.findAny()
.orElseThrow(() -> new BadRequestException("12345","Item Not Found"));This is just for a validation purpose no need to return anything from this statement. need to validate whether the item exists or not.FYI: Eclipse showing a quick fix as squid:S2201Anybody have any idea how to resolve this bug?
|
The return value of "orElseThrow" must be used
|
I had the same problem and found a very different solution, perhaps because I'm having a hard time swallowing the previous answers / comments. With 10 million lines of code (that's more code than is in an F16 fighter jet), if you have a 100 characters per line (a crazy size), you could load the whole code base into 1GB of memory. I set it 8GB of memory and it still failed. Why?Answer: Because the community Sonar C++ scanner seems to have a bug where it picks up ANY file with the letter 'c' in its extension. That includes .doc, .docx, .ipch, etc. Hence, the reason it's running out of memory is because it's trying to read some file that it thinks is 300mb of pure code but really it should be ignored.Solution: Find the extensions used by all of the files in your project (see more here):dir /s /b | perl -ne 'print $1 if m/\.([^^.\\\\]+)$/' | sort -u | grep cThen add these other extensions as exclusions in your sonar.properties file:sonar.exclusions=**/*.doc,**/*.docx,**/*.ipchThen set your memory limits back to regular amounts.%JAVA_EXEC% -Xmx1024m -XX:MaxPermSize=512m -XX:ReservedCodeCacheSize=128m %SONAR_RUNNER_OPTS% ...ShareFolloweditedMay 23, 2017 at 12:01CommunityBot111 silver badgeansweredDec 9, 2013 at 22:05Ryan ShillingtonRyan Shillington24k1515 gold badges9696 silver badges112112 bronze badgesAdd a comment|
|
I am deploying a large Java project on Sonar using "Findbugs" as profile and getting the error below:Caused by: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError:
Java heap spaceWhat i have tried to resolve this:Replaced %SONAR_RUNNER_OPTS% with -Xms256m -Xmx1024m to increase the heap size in sonar-runner bat file.Put "sonar.findbugs.effort" parameter as "Min" in Sonar global parameters.But both of above methods didn't work for me.
|
Sonar - OutOfMemoryError: Java heap space
|
You can use the "sonar.exclusions" property to exclude source files using patterns: seehttp://docs.sonarqube.org/display/SONAR/Analysis+ParametersShareFolloweditedDec 26, 2014 at 20:57answeredFeb 25, 2013 at 12:45Fabrice - SonarSource TeamFabrice - SonarSource Team26.6k33 gold badges6363 silver badges5858 bronze badges44thank you one more time! I just figured it out. I used "folder", instead of "folder/**" to exclude folder, subfolder and files and it, obviously, had no effect.–mr.nothingFeb 25, 2013 at 12:48+1 This is obviously the correct answer - I will delete mine (although I got some reputation points ;-))–FrVaBeFeb 25, 2013 at 12:532Just to point out that if you want to specify several exclusions, separate them with commas.–AlfergonApr 5, 2014 at 17:51Folks, if I add/folder/shall I expect thatallsub-folders from the folder will be ignored too?–rafa.ferreiraSep 6, 2016 at 20:42Add a comment|
|
I look through the Internet and tried a million diferent ways, but didn't find an answer.Is there any way to exclude some folders with source files from the Sonar analysis, when I use maven to launch it (e.g. mvn sonar:sonar)?
|
Exclude folder from analysis
|
I found only two disadvantages in the field injection.Hard to inject mocks when the object is under test. (Can be resolved with@InjectMocksfrom Mockito)Circle dependencies. If beanAdepends on beanBand beanBneeds beanA. If you have the constructor injection it easy to find it.ShareFolloweditedJan 24, 2020 at 15:33savepopulation11.8k44 gold badges5656 silver badges8181 bronze badgesansweredMar 25, 2019 at 14:57dehasidehasi2,68411 gold badge2020 silver badges3232 bronze badges2It's easy to find it, of course, but circular injection problems might only occur through the constructor variant.–Florian R. KleinJun 1, 2022 at 12:[email protected] It's sort-of the other way round: With constructor injection, it's impossible to have a circular injection so you can't have problems; with field inject, it's possible that the injected object isn't fully initialized yet but the class may already use it (think lifecycle callbacks that happen during initialization). Cyclic dependencies are extremely nasty because by necessity, there is at least one object that is partially initialized (the cyclic link is still null), and this can give you very weird errors during startup that just vanish after init.–toolforgerAug 10, 2022 at 15:45Add a comment|
|
This question already has answers here:Why use constructor over setter injection in CDI?(3 answers)Closed3 years ago.When injecting any services, I have two choices :Field injection:@Inject
private MyService myService;orConstructor injection:private MyService myService;
@Inject
public ClassWhereIWantToInject(MyService mySerivce){
this.myService = myService;
}Why isConstructor injectionbetter thanField injection?
|
Constructor injection vs Field injection [duplicate]
|
As described in thedocumentation page(see "Project analyzed with Maven 3"), the plugin you have to use isorg.codehaus.mojo:sonar-maven-plugin, not the internal one(s).ShareFolloweditedJan 15, 2016 at 16:51agabrys8,89833 gold badges3535 silver badges7575 bronze badgesansweredJan 19, 2015 at 14:53Fabrice - SonarSource TeamFabrice - SonarSource Team26.6k33 gold badges6363 silver badges5858 bronze badges4And, how do we correlate the version numbers between the org.codehaus.sonar and org.codehaus.mojo sonar-maven-plugins?–Russ JacksonJun 17, 2015 at 18:39Let's say that the "org.codehaus.mojo:sonar-maven-plugin" used to be a facade plugin to the internal ones in order to not have dependencies to SonarQube API. It detects which version of the internal plugins to use thanks to a WS call to the server to know which version of SonarQube is installed. I say "used to be a facade" because in upcoming SQ 5.2, the internal plugins will no longer be required and therefore are removed from the code base.–Fabrice - SonarSource TeamJun 18, 2015 at 8:443How about theorg.codehaus.sonar:sonar-maven-plugin? Is that a Maven2 only plugin?–GijsSep 17, 2015 at 16:051Now, it's:org.sonarsource.scanner.maven:sonar-maven-plugin–ValijonAug 15, 2020 at 9:53Add a comment|
|
I am wondering which sonar-maven-plugin in which version I should use.
As far as I know there is aorg.codehaus.mojoversion and two org.codehaus.sonar versions (sonar-maven3-plugin,sonar-maven-plugin).As far as I understand the sonar-maven3-plugin is now deprecated and the org.codehaus.sonar:sonar-maven-plugin should be used instead. However those org.codehaus.sonar version are tied to a certain version of the sonar server, therefore it makes probably no sense to use them directly.
To be able to deal with this there is the org.codehaus.mojo:sonar-maven-plugin which checks which sonar version the server has and from there checks which org.codehaus.sonar:sonar-maven-plugin to use.So in order to have a maven pom that is independent of the Sonar Server Version one should probably use theorg.sonar.mojo:sonar-maven-plugin:RELEASEversion to be safe.Did I get this right?Any further things to consider?Thanks
|
Which sonar-maven-plugin version to use?
|
According towikipedia:Afferent Couplings (Ca):The number of classes in other packages that depend upon classes within the package is an indicator of the package's responsibility. Afferent = incoming.Efferent Couplings (Ce):The number of classes in other packages that the classes in the package depend upon is an indicator of the package's dependence on externalities. Efferent = outgoing.So, if you have classes (or packages or whatever) with the following structure:class Foo {
Quux q;
}
class Bar {
Quux q;
}
class Quux {
// ...
}ThenFooandBareach have oneefferentcoupling, andQuuxhas twoafferentcouplings.ShareFolloweditedAug 3, 2015 at 23:52lbalazscs17.6k77 gold badges4343 silver badges5050 bronze badgesansweredMar 7, 2013 at 14:02millimoosemillimoose39.5k1111 gold badges8585 silver badges137137 bronze badges2is Afferent coupling a better indicator of single responsibility principle being practiced?–user20358Apr 22, 2017 at 19:502@user20358 - I'm not the best architect, but I don't think it indicates much. A class with too many afferent couplings could be used a lot because it does too much. Or it could just be handling some sort of crosscutting concern - logging, ORM unit of work, things like that.–millimooseApr 23, 2017 at 12:58Add a comment|
|
Code quality metric tool likeSonardoes provide the ability to drill down to a class and find out the number of:Afferent (incoming) couplingsEfferent (outgoing) couplingsWhat are these two parameters? Can you please describe with a simple contrived example?
|
What is the difference between afferent couplings and efferent couplings of a class?
|
sonar.coverage.exclusionsexcludes some files from the test coverage metrics but those files are still analyzed: other metrics, duplications, coding rules...sonar.exclusionscompletely excludes some files from the analysis: those files don't appear at all in SonarQube.Seehttps://docs.sonarqube.org/latest/project-administration/narrowing-the-focus/sonar.exclusionsandsonar.coverage.exclusionsare standard property names for SonarQube. I don't know how the tool you use feeds these properties to the analysis based on your configuration file.ShareFollowansweredMar 1, 2019 at 9:17Pierre-YvesPierre-Yves1,5061111 silver badges1616 bronze badgesAdd a comment|
|
What is the difference betweencoverage_exclusionsvsexclusionsin sonar? example:"sonar": {
"exclusions": "gulpfile.js, ...",
"coverage_exclusions": "gulpfile.js, ..., server/models/*.js",
"quality_gate": "...",
"server_id": "SONAR-main"
},
|
What is the difference between coverage_exclusions vs exclusions in sonar?
|
I am using Maven and ExtJS 4.1 in my project. I have managed to run the analysis only on my source code by putting these lines in mypom.xml:<properties>
<sonar.language>js</sonar.language>
<sonar.exclusions>extjs/**</sonar.exclusions>
</properties>
<build>
<sourceDirectory>src/main/webapp</sourceDirectory>
</build>I don't know whether you're using Maven as well, but perhaps this will give you some hints.ShareFolloweditedApr 5, 2017 at 9:52dur16.3k2525 gold badges8383 silver badges130130 bronze badgesansweredSep 11, 2012 at 19:50Andrea BergiaAndrea Bergia5,51222 gold badges2424 silver badges3939 bronze badgesAdd a comment|
|
If you look at this site analysing JavaScript with Sonar you see that there are lots of errors reported on the JavaScript libraries.http://nemo.sonarsource.org/drilldown/violations/jquery?rids%5B%5D=421365&severity=MAJORHow can I prevent Sonar reporting the errors in the JavaScript libraries that I am using (since I can't fix any issues)?At the same time, if I do manage to exclude the library, I don't want errors like "undefined variables" to appear in my files because they are referencing the JavaScript library.If it makes any difference, I am using ExtJS 4.0.
|
Exclude JavaScript libraries from Sonar
|
SonarQube is telling you that this portion of the code contains duplicated logic. This doesn't necessarily mean that the code itself is copy-pasted, but that, conceptually, the exact same thing is happening at multiple places. In this case, the logic of returning aStringvalue with regard to theintvalue is clearly repeated.A simple solution here:String[] array = { "One", "Two", "Three", "Four", "Five", "Six" };
if (i >= 1 && i <= array.length) {
return array[i - 1];
}ShareFollowansweredMar 5, 2017 at 20:19TunakiTunaki135k4646 gold badges355355 silver badges431431 bronze badges31I do not know how Sonar can detect "duplicated logic" but the solution looks the right one.–John DonnMar 5, 2017 at 20:491Literals are ignored in copy paste detection. So if you "blank" int literals and string literals... the code is duplicated.–benzonicoMar 6, 2017 at 9:304so complexity is preffered over any duplication by sonar's detection?–Eaton EmmerichJun 15, 2023 at 13:19Add a comment|
|
I just run sonar scanner on the sample Sonar project. It gives me the message that there is "duplicated code on lines 7-20". Can anyone explain this?
|
Where is the Sonar "duplicated code" here?
|
This works for me.- name: check sonar web is up
uri:
url: http://sonarhost:9000/sonar/api/system/status
method: GET
return_content: yes
status_code: 200
body_format: json
register: result
until: result.json.status == "UP"
retries: 10
delay: 30Notice thatresultis a ansible dictionary and when you setreturn_content=yesthe response is added to this dictionary and is accessible usingjsonkeyAlso ensure you have indented the task properly as shown above.ShareFollowansweredOct 25, 2016 at 9:57HafizHafiz5,01144 gold badges2121 silver badges2828 bronze badges3This is nice, the fact that result comes in as an Ansible dictionary and there's a Jinja2 JSON parser already there to extract info from it.–oceanOct 25, 2016 at 10:151@Halfiz Thank you, thank you, thank you. My until: condition was not working and it was the indentation that was biting me.–TJASep 16, 2019 at 0:08Is it somehow possible using content? For some reason content does not work (probably because of some escaping issues). Could you check that if you have time?–Mohammed NoureldinMay 17, 2023 at 20:15Add a comment|
|
I have a service call that returns system status injsonformat. I want to use the ansibleURImodule to make the call and then inspect the response to decide whether the system is up or down{"id":"20161024140306","version":"5.6.1","status":"UP"}This would be thejsonthat is returnedThis is the ansible task that makes a call:- name: check sonar web is up
uri:
url: http://sonarhost:9000/sonar/api/system/status
method: GET
return_content: yes
status_code: 200
body_format: json
register: dataQuestion is how can I accessdataand inspect it as per ansible documentation this is how we store results of a call. I am not sure of the final step which is to check the status.
|
How to inspect a json response from Ansible URI call
|
Have a look at the post here:https://github.com/SonarSource/sonar-csharp/issues/958and follow the advice in the bottom:The problem it's caused by /d:sonar.source="Project" or /d:sonar.tests="Project.Tests", just remove and works.It works for me.ShareFollowansweredMar 6, 2018 at 4:00civic.LiListercivic.LiLister2,1171616 silver badges1414 bronze badges0Add a comment|
|
I have just upgraded to SonarQube 6.4 and at the same time moved to mysql. Whenever I try to parse a particular solution I get the message:can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test filesI am running the scanner through VSTS using the new SonarQube tasks. I have also tried to pass the -X flag to SQ but it is not getting through the VSTS task. I have also upped the mysql max packet to 512M and restarted both mysql and Sonar servers. I'm at a loss
|
Sonar fails with can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files
|
Now, i do not usehttp://shields.iobut directly thehttps://sonarcloud.ioweb site.[](https://sonarcloud.io/dashboard/index/com.github.noraui:noraui)
[](https://sonarcloud.io/component_measures/metric/coverage/list?id=com.github.noraui:noraui)
[](https://sonarcloud.io/component_measures/metric/reliability_rating/list?id=com.github.noraui%3Anoraui)
[](https://sonarcloud.io/component_measures/metric/security_rating/list?id=com.github.noraui%3Anoraui)ShareFolloweditedJun 21, 2018 at 19:48answeredDec 11, 2017 at 17:09Stéphane GRILLONStéphane GRILLON11.4k1212 gold badges9090 silver badges169169 bronze badges11This won't work. Check for the new apis below.stackoverflow.com/a/54266444/1097600–SorterJan 19, 2019 at 11:12Add a comment|
|
I have com.github.xxxxxx:xxxxxx Maven repository and I want add shields badge but I have a invalid badge:https://img.shields.io/sonar/https/sonarqube.com/com.github.noraui:noraui/tech_debt.svgSonarqube xxxxxx project page:https://sonarqube.com/dashboard?id=com.github.xxxxxx%3AxxxxxxI find a OK sample from an other sonar server:https://img.shields.io/sonar/http/sonar.qatools.ru/ru.yandex.qatools.allure:allure-core/coverage.svghttps://img.shields.io/sonar/http/sonar.qatools.ru/ru.yandex.qatools.allure:allure-core/tech_debt.svg
|
Add SonarQube coverage via shields.io badge
|
There are two things to consider here.You can adjust this rule in Sonar and increase the number of authorized parameters. Say put it 10 instead of default (?) 7.UPD: the advice below is based on the old question version. It might be not applicable to the new question context any more.But generally you should reconsider your method interface. Having many arguments means that something can be wrong in your architecture and theSingle responsibility principlemight be broken.Say in your particular example, I would expect, that you can have an aggregate classOrder:public class Order {
private CountryCode countryCode;
private String orderId;
private User user;
private String orderId;
private String item;
private List<Person> persons;
private ShippingAddress address;
private PaymentMethod payment;
private Product product;
// ...
}Which is much logical to manage instead of dealing with many parameters. Then your issues will be solved automatically:@GetMapping
public void updateSomething(Order order) { ... }ShareFolloweditedMar 28, 2018 at 13:09answeredMar 28, 2018 at 13:03AndremoniyAndremoniy34.4k2121 gold badges137137 silver badges246246 bronze badges1Mark Seemann has a nice article discussing this in more detail:blog.ploeh.dk/2010/02/02/RefactoringtoAggregateServices–openshacMar 7, 2019 at 9:56Add a comment|
|
When I am scanning code with sonar lint the following code shows the bug as "Method has 8 parameters, which is greater than 7 authorized"@PutMapping("/something")
public List<SomeList> updateSomeThing(@PathVariable final SomeCode code,
@PathVariable final SomeId id,
@PathVariable final String testId,
@PathVariable final String itemId,
@RequestBody final List<Test> someList,
@RequestHeader("test") final String testHeader,
final HttpServletRequest request,
final SomeHeaders someHeaders)Note: This is a controller method we can not skip any parametersFYI: Eclipse showing a quick fix as squid:S00107Anybody have any idea how to resolve this bug?
|
Method has 8 parameters, which is greater than 7 authorized
|
you don't really need a plugin.
make something like this in your.gitlab-ci.ymlstages:
- build
build_master:
image: maven
stage: build
artifacts:
paths:
- target/*.jar
script:
- mvn package sonar:sonar -Dsonar.host.url=https://sonar.yourdomain.tld/
only:
- masterand every master push will be tested!
(this is for a Java project...)ShareFollowansweredMay 17, 2017 at 7:57JoergiJoergi1,54533 gold badges4040 silver badges8585 bronze badges3This answer is quite limited. How about Windows? How about C# or C++? How about UI links in both tools, if not analysis results displayed in GitLab UI?–IvanNov 13, 2017 at 16:532Hey Ivan, I'm pretty sure you can build all other things this way too. For Windows stuff I was using the last time the PowerShell image.–JoergiNov 13, 2017 at 16:571That won't be that easy, trust me. Calling a SonarQube runner is only one aspect of the question. No Windows Docker image would have a SonarQube runner installed. No GitLab version for the moment allows to use Docker executor in Windows gitlab-runner. There's no free official SonarQube plugin for C++ - but lots of options. Much more manual work. Then another side of the question - UI integration, as I mentioned above.–IvanNov 13, 2017 at 17:03Add a comment|
|
I am pretty new to Development community and specifically to DevOps practices , as a part of project we are trying to integrate SonarQube with Gitlab , did some R& D on SonarQube and Git CI ( Continuous Integration ) and look like plugin is released for Github and SonarQube whereas not for Gitlab.How realistic is it to configure GitLab with SonarQube for inspecting code quality for every pull request and what will be the best practice to integrate these two piece.Thanks
|
Gitlab integration with SonarQube
|
SonarQube 5.6 requires at least Java 8 (seerequirements). Note that this is not a just a requirement on the server side, it's also required on the client side where analysis are ran.Likeagabrysmentioned in his comment, theUnsupported major.minoris a classic Java error (seethis thread).ShareFolloweditedMay 23, 2017 at 11:54CommunityBot111 silver badgeansweredJun 8, 2016 at 6:10Nicolas B.Nicolas B.7,2631818 silver badges2929 bronze badgesAdd a comment|
|
Environment details:SonarQube 5.6Apache Maven 3.3.9Java version: 1.7.0_09I integrated SonarQube plugin with java maven project like in pom.xml<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.0.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>While executing goal:mvn sonar:sonar -Dsonar.host.url=<url>Getting exception:[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.0.2:sonar (default-cli) on project example-java-maven:
Execution default-cli of goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.0.2:sonar failed:
An API incompatibility was encountered while executing org.sonarsource.scanner.maven:sonar-maven-plugin:3.0.2:sonar:
java.lang.UnsupportedClassVersionError: org/sonar/batch/bootstrapper/EnvironmentInformation:
Unsupported major.minor version 52.0
[ERROR] -----------------------------------------------------
[ERROR] realm = plugin>org.sonarsource.scanner.maven:sonar-maven-plugin:3.0.2
|
java.lang.UnsupportedClassVersionError: org/sonar/batch/bootstrapper/EnvironmentInformation : Unsupported major.minor version 52.0
|
The issue that SonarQube is reporting is a false positive and should be ignored.SonarQube's FAQlists some options for removing false positives:False-Positive and Won't FixYou can mark individual issues as False Positive or Won't Fix through the issues interface. However, this solution doesn't work across branches - you'll have to re-mark the issue False Positive for each branch under analysis. So an in-code approach may be preferable if multiple branches of a project are under analysis://NOSONARYou can use the mechanism embedded in rules engine (//NOPMD...) or the generic mechanism implemented in SonarQube: put //NOSONAR at the end of the line of the issue. This will suppress the issue.Switch Off IssuesYou can review an issue to flag it as false positive directly from the user interface.ShareFollowansweredMay 6, 2016 at 13:02Andy WilkinsonAndy Wilkinson113k2424 gold badges268268 silver badges249249 bronze badges18While //NOSONAR works, it disables all sonar checks although only for that line. Alternative is to specifically disable check for a single rule; which in this case you can do by adding@SuppressWarnings("squid:S2095")on your main method.–NikhilWanpalOct 15, 2016 at 13:57Add a comment|
|
I have blocker issue "Close this "ConfigurableApplicationContext"" in main methodpublic static void main(String[] args)
{
SpringApplication.run(MyApplication.class, args);
}I've tried code from SonarQube examplepublic static void main(String[] args)
{
ConfigurableApplicationContext context = null;
try
{
context = SpringApplication.run(MyApplication.class, args);
}
finally
{
if (context != null) {
context.close();
}
}
}but it closes the context right after starting.How to fix this issue?
|
SonarQube "Close this ConfigurableApplicationContext" in Spring Boot project
|
You can of course do a simplemvn sonar:sonar, this will work.On the other side, there's the SonarQube plugin for Jenkins that will make the configuration easier. For instance you will be able to define information about your SonarQube server (URL, DB user and password) or your multiple SonarQube servers in a single place (the configuration section of Jenkins) so that you don't have to repeat it everywhere.The plugin also offers the ability to run a SonarQube analysis on the fly (without Maven): you just have to provide some mandatory properties (likesonar.projectKeyandsonar.projectVersionfor instance) and the plugin will start the Java Standalone Runner transparently for you (this is helpful mostly for other languages than Java which don't rely on Maven for their build).So if you're just making some tests, you don't really need this plugin. But if you're setting up a production instance of Jenkins, then it's best to use the SonarQube plugin.ShareFolloweditedJul 2, 2020 at 17:07Lii11.8k99 gold badges6565 silver badges8989 bronze badgesansweredMay 21, 2012 at 15:45Fabrice - SonarSource TeamFabrice - SonarSource Team26.6k33 gold badges6363 silver badges5858 bronze badges1I would like to point out that the Jenkins sonar plugin is actually calling the same maven goal behind the scenes. One nasty side effect of this is the Jenkins invocation does not share the same environment as when specified in the build step.–jbruniMar 15, 2018 at 23:33Add a comment|
|
I want to launch SonarQube analysis with Jenkins for a Maven 2 project. I first used the goalsonar:sonarin the build configuration.But I just found the SonarQube plugin for Jenkins. Why use it? Is it a better practice and why?
|
Why use SonarQube plugin for Jenkins rather than simply use maven goal sonar:sonar?
|
As noted in the comments, all you have to do is remove the rules from your profile or edit them to lower their priority. You need the Global Administer Quality Profiles permission to do that. Once you're logged in with that permission, go to the Rules interface, search for a rule you want to deactivate, select the rule, click on it, and Deactivate it from the relevant profile.ShareFollowansweredAug 23, 2016 at 21:11G. Ann - SonarSource TeamG. Ann - SonarSource Team22.5k44 gold badges4242 silver badges8484 bronze badges0Add a comment|
|
We recently started usingSonarQube. We have found some rules that are suggested by SonarQube but we want to ignore them or give them a low priority and even configure the time suggested by SonarQube. For e.gWe want to avoid the rule (and/or configure the priority and time suggested by SonarQube) forDocument this public class. andComplete the task associated to this TODO comment.I couldn’t find a way to configure this rules to be ignored. We want this kind of rules to be ignored for the whole project not specific classes.Configuring this values would help us to have a better time estimation to fix major issues and give low priority for the rules like the above two. We are using SonarQube 6I appericiate your advice.
|
How can we ignore some SonarQube rules in Java?
|
It sayshereNP: Possible null pointer dereference (NP_NULL_ON_SOME_PATH)There is a branch of statement that, if executed, guarantees that a null value will be dereferenced, which would generate a NullPointerException when the code is executed. Of course, the problem might be that the branch or statement is infeasible and that the null pointer exception can't ever be executed; deciding that is beyond the ability of FindBugs.If you would have posted some code it would be easier to answer.EDITI don't see a lot of documentation but here is oneexample! Hope this helps!ShareFolloweditedOct 23, 2015 at 18:15cwallenpoole80.8k2626 gold badges129129 silver badges168168 bronze badgesansweredSep 3, 2012 at 5:14Bharat SinhaBharat Sinha14.1k77 gold badges4242 silver badges6464 bronze badges3My code is very complicated and also i changed my code and it fixed but i did not understand this findbugs rule.–Saeed ZarinfamSep 3, 2012 at 5:29Well than as it saysThere is a branch of statement that, if executed, guarantees that a null value will be dereferenced, which would generate a NullPointerException when the code is executed.means you potentially are assigning anullto a variable and using it again which might cause an exception.–Bharat SinhaSep 3, 2012 at 5:31Please give me a sample code. I read this description before !–Saeed ZarinfamSep 3, 2012 at 6:19Add a comment|
|
I am using Sonar and I have got this kind of violation from it for a peace of my code:Correctness - Possible null pointer dereferenceHas anyone know about this rule in findbugs? I searched a lot but I can not find a good sample code (in Java) which describe this rule, unfortunately findbugs site did not have any sample code or good description about this rule.Why does this violation appear?
|
What is the meaning of Possible null pointer dereference in findbug?
|
Godin's answeris correct but there is now a way to add that annotation automatically.In order to do this you can create alombok.configfile in the root of your project and add this line in it:lombok.addLombokGeneratedAnnotation = trueFull detailshere. As detailed in the documentation:Lombok can be configured to add @lombok.Generated annotations to all generated nodes where possible; useful for JaCoCo (which has built in support), or other style checkers and code coverage tools:
lombok.addLombokGeneratedAnnotation = trueShareFollowansweredMar 25, 2020 at 17:29Vlad SchnakovszkiVlad Schnakovszki8,49466 gold badges8181 silver badges114114 bronze badgesAdd a comment|
|
I use jacoco for coverage report. When I look at the jacoco report, coverage seems to be good. But in Sonarqube, the coverage is low because it says that@Dataannotation from lombok is not cover by test.Compiled classes is mark as@Generatedbut it's not ignored by Sonar.How can I make exclude@Dataof the analysis ?
|
Sonarqube bad coverage because of lombok @Data
|
Currently there is no way to use the connected mode which allows the user to configure (enable/disable) the rules on the SonarLint.According to the discussion on the SonarLint Google Group.It's very likely that this feature will be added soon (within the
year), as we already started developing it for other flavors of
SonarLint (Eclipse).This feature is currently in work in progress and can be trackedhereShareFollowansweredApr 4, 2018 at 17:30ShellZeroShellZero4,4851212 gold badges3939 silver badges5858 bronze badges13This feature works for user settings, but doesnotwork for workspace settings. This is very frustrating, because some rules might be appropriate for one repo, but not another. Also, makes management of large teams difficult, as one would need to make sure that the user settings are the same for all users.–CNadJul 23, 2020 at 16:57Add a comment|
|
I have installed sonar lint extension on my visual studio code editor and I was wondering if there is a way to enable or disable the rules which are used by the analyzer? There is a way to do it in Visual Studio and Eclipse but I couldn't find a way to enable or disable the rules on Visual Studio Code.I do have SonarQube running on my local server where I can disable and enable the rules from the Admin UI page. If there is a way to configure the SonarLint with the server, that would be cool. But I am not sure how to do it. If anyone does, please point me in a right direction.
|
How to configure the rule set of SonarLint in Visual Studio Code?
|
It means that there are cyclical dependencies between packages and files.Ideally, you want dependencies to flow in one direction - this allows you to make changes and predict their impact. For instance, if your "user interface" package depends on the "business logic" package, but nothing depends on the "user interface" package, you should be able to make changes to the user interface without breaking anything outside that package. A cyclical dependency means (for instance) the user interface package depends on the business logic package, but the business logic package also depends on the user interface package. Now if you change the user interface, you might break the business logic layer - which in turn might affect something totally unrelated in the user interface.The idea of "layering" software, and having dependencies flow in a single direction between layers is designed to remove this tangle.You can very often reduce this tangling by moving classes from one package to another.Tangling is usually an architecture/design problem.ShareFollowansweredMar 10, 2013 at 11:50Neville KuytNeville Kuyt29.3k22 gold badges3939 silver badges5252 bronze badgesAdd a comment|
|
I have the following data on one of the 7 axes (See the second picture) after running aSonaranalysis on my project. What information can be decoded from this data? Also which of the axes in the diagram below does this data pertain to?
|
What does package tangle index data indicate in Sonar?
|
You can do it only withsonar.sourcesproperty or with thesonar.exclusionsandsonar.inclusionsproperties.Example:MySrcFolder
src1
src2
src3
src4If you want to analyze onlysrc1andsrc3then,1)sonar.sources=MySrcFolder/src1,MySrcFolder/src3OR2)sonar.sources=MySrcFolder
sonar.exclusions=src2/**,src4/**OR3)sonar.sources=MySrcFolder
sonar.inclusions=src1/**,src3/**Following rules are applied in theexclusionsandinclusionsproperties:* Match zero or more characters
** Match zero or more directories
? Match a single character
file: Prefix to define a pattern based on absolute pathFor more details:http://docs.sonarqube.org/display/SONAR/Narrowing+the+FocusShareFolloweditedJul 23, 2015 at 6:04answeredMay 5, 2014 at 6:31L. LangóL. Langó1,09977 silver badges1111 bronze [email protected]ó Can we use inclusions and exclusions together? Or we can only use one of them at a time?–Coder12345Feb 28, 2019 at 21:25@kav12345 I can only guess, I did not use this feature for a long time. Probably you can, but I do not know which one has the higher priority. Usually exclusions are stronger.–L. LangóMar 1, 2019 at 9:14Add a comment|
|
I am using OCLint on an Objective C project to obtain a SonarQube profile.Now my IOS Objective C project contains a src directory with multiple sub src directories. In mysonar-project.propertiesfile there is a following entrysonar.sources=MySrcFolder/Now within this src folder i want to run the sonar profile on multiple subfolders and exclude some third party src folders. Can anyone help me with this ? As it stands now, sonar runs the profile on all src in any of the above folders subfolders ?
|
Sonar project-properties file
|
SonarQube marked this line as an error, becausejava.util.Listdoesn't implementjava.io.Serializable.java.util.ArrayListis serializable, but thebondAxeMarkQuoteUpdatesisprotectedso somebody can assign other non-serializable list to it (e.g. in a subclass).To solve the problem you can:make the field astransient, but it will be ignored during serializationmake the field asprivate, so SonarQube can verify that nobody assigned non-serializable list to itchange the field type to serializable type (e.g.java.util.ArrayList)ShareFollowansweredMay 13, 2017 at 11:07agabrysagabrys8,89833 gold badges3535 silver badges7575 bronze badges313Mark the field as private is not helping. Sonar still shows this as a bug.–DherikJan 2, 2018 at 18:01@Dherik Please create a new StackOverflow question and include your code.–agabrysJan 7, 2018 at 13:10Hi @agabrys. I discover the problem, I will introduce a new answer for the question–DherikJan 7, 2018 at 20:39Add a comment|
|
I have a java class that implements serializable and I'm assuming the variable within the class would also be serialized but SonarQube is complaining to me that it is not.My snippet of code is shown below:
|
Why is SonarQube giving a transient/private error when class is Serialized?
|
According toSonarQube Analysis Parameters:sonar.projectKeyThe project key that is unique for each project.
Allowed characters are: letters, numbers, '-', '_', '.' and ':', with at least one non-digit.When using Maven, it is automatically set to<groupId>:<artifactId>.Therefore, remove yoursonar.projectKeyconfiguration and it should work.(I have been through the same loop).ShareFolloweditedJun 20, 2020 at 9:12CommunityBot111 silver badgeansweredApr 26, 2017 at 7:46Steve CSteve C19.1k55 gold badges3535 silver badges3737 bronze badges2Is there a way to override this key to use our own?–3AKApr 22, 2018 at 6:326This doesn't answer the question. Overriding the key is sometimes necessary (if unable to create projects with arbitrary names in SonarQube, for example). In that case, how would you manage the sub-modules?–Rick MoritzJan 15, 2019 at 14:18Add a comment|
|
I am using sonar-maven-plugin 3.2 and maven 3.3.9. In the parent POM, I have the sonar.projectKey maven property defined. The value is in effect, I can see it from the printout of sonar. But the mvn sonar:sonar step fails, because the maven modules use the same project key value, because the maven property has the same value in all modules. Sonar gives the error:Project '...' can't have 2 modules with the following key: ...Is there really no way to have a single sonar project that contains all maven modules? Are all modules must be really different sonar projects?I am aware that I could use the branch property asa hack, but I would like to avoid doing that. If there is a way to have a maven multi module project in sonar with a single project key, containing all maven modules, that would be the best...
|
Sonar maven plugin: same project key for all modules does not work?
|
If you separate the common part to an own project you can add a newQuality Profilein Sonar (where you deactivated these rules) and assign it to your common project.Apart from that you can use the// NOSONARcomment to supress a warning on a single line (seeFAQ).ShareFolloweditedSep 10, 2020 at 8:16answeredJul 15, 2011 at 17:56FrVaBeFrVaBe48.6k1717 gold badges126126 silver badges161161 bronze badges53Sonar 2.5 introduced a "SuppressWarning" annotation which also useful for switching off analysisjira.codehaus.org/browse/SONAR-1760–Mark O'ConnorJul 16, 2011 at 12:06Unfortunately, annotations are among those newer features that are not supported on Blackberry.–FixpointJul 21, 2011 at 8:48As to the NOSONAR comment, there are too many violations to comment them all.–FixpointJul 21, 2011 at 8:481So follow the original advice and create a new more permissive quality profile in Sonar. You can make this the default for all projects.–Mark O'ConnorJul 25, 2011 at 11:56I'm getting a 404 on your last link–jcollumSep 3, 2020 at 17:14Add a comment|
|
We have an Android/Blackberry project with a common part. That part, obviously, is written to compile to both Android and Blackberry targets, and, consequently, cannot use some of the newer Java features (e.g., Integer.valueOf). I'd like to skip some of the rules specifically for that part. Is there a way to do this?
|
In Sonar, how to prevent checking some rules in some packages?
|
This Link:https://modess.io/npath-complexity-cyclomatic-complexity-explained/explains it very well as:The NPath complexity of a method is the number of acyclic execution paths through that method.This means you should avoid long functions with a lot of (nested) if/else statements.So my advice would be:Split your functions into smaller onesEliminate useless if/else-statements where possibleShareFolloweditedJun 8, 2016 at 7:21answeredJul 10, 2014 at 7:20JohannesDienstJohannesDienst46544 silver badges1111 bronze badges14The NPath complexity of a method is the number of acyclic execution paths through that method or The simple explanation is that how many "paths" there are in the flow of your code in the function.–Wolverine789Jul 10, 2014 at 7:34Add a comment|
|
In this line:public Map getAll(BusinessTargetPK pkBusinessTargetId) throws ExceptionI am getting this error:NPath Complexity is 32,768 (max allowed is 200)And in this line:public Map getAll( Long RLE_ROLE_ID ) throws Exception {I get this error:The method getAll() has an NPath complexity of 2048I am completely unaware of what isNPath Complexityand what it means.Can someone give advice how to avoid this type of error?
|
What is NPath Complexity and how to avoid it?
|
There are plenty of plugins on GitHub.For example:sonar-web-frontend-pluginfor many front end technologies including AngularJS and TypeScript but is a bit old. It analyzes the scanners' reports.SonarTsPluginfor TypeScript and so Angular 2. It directly performs an analysis.SonarTSis the official SonarSource plugin for TypeScript.ShareFolloweditedDec 22, 2017 at 9:27answeredJun 9, 2017 at 11:35begarcobegarco75677 silver badges2121 bronze badges3Thanks! :-) I thougth there was no one, as i havent seen any at the update center settings tab–TCeaJun 12, 2017 at 13:03There is now the official SonarQube plugin for TS.–begarcoDec 22, 2017 at 9:24SonarTs (which is the same as the plugin) will check TypeScript rules but will not detect Angular anti-patterns.–JulienDJan 11, 2019 at 9:23Add a comment|
|
I am new with Sonar and I have recently installed SonarQube 6.3
I couldnt find any plugin for AngularJS neither Angular2.Is there any way to have an Angular scanner? Any plans to release one for SonarQube 6.X?Thanks a lot
|
Angular2 plugin for SonarQube 6.x
|
I added the script as post step command, so after build succeeded the script check quality gates and breaks the job if they are not ok.ShareFollowansweredMay 17, 2016 at 12:08rraderrrader35111 gold badge22 silver badges1111 bronze badges1what If you need some build steps to be skipped depending on the quality gate result? e.g. generation of maven artifacts, release creation etc. would you put all this in post release steps?–NicolasWMay 4, 2018 at 14:17Add a comment|
|
How to fail maven goal sonar:sonar based on quality gates rules?
I run it for local builds, for CI I already wrote a script according tohttp://docs.sonarqube.org/display/SONAR/Breaking+the+CI+BuildSo, if quality gates validation fails then goal also should fails
|
How to fail maven goal sonar:sonar based on quality gates
|
With.csprojnow being thede-facto formatof.Net Coresolutions, SonarQube support of such solutions comes with theSonarQube Scanner for MSBuild v2.3.ShareFollowansweredMay 2, 2017 at 9:24Nicolas B.Nicolas B.7,2631818 silver badges2929 bronze badges1There is one important piece of information missing on the docs. ¿What MSBuild version is to be linked? For me, my project was .NET 4.6.1 using MSBuild 15.0. I just needed to set correctly the MSBuild using the new PATH. I that was it.–Ramon GonzalezFeb 28, 2018 at 21:00Add a comment|
|
SonarQube has an MSBuild runner but .NET Core uses dotnet.exe to compile and msbuild just wraps that. I have tried using the MSBuild runner with no success against my ASP.NET Core solution. Using SonarQube Scanner works kind of.Any suggestions on how I can utilize SonarQube with .NET Core? The static code analysis is what I am looking for.
|
Running SonarQube against an ASP.Net Core solution/project
|
According to thedocumentationSonarQube usesbasic authentication. Try:curl -u admin:SuPeRsEcReT "https://sonar.mydomain.com/api/resources?resource=com.mydomain.project:MY&metrics=ncloc&format=json"Obviously the mechanism for passing these credentials is dependent on how you are invoking the API.This should also work from the web browser. Try logging into the Webui, your browser will normally cache the credentials.ShareFolloweditedMar 8, 2014 at 6:55answeredMar 7, 2014 at 21:11Mark O'ConnorMark O'Connor76.6k1010 gold badges140140 silver badges186186 bronze badges3Thanks, Mark. Do you know: is this basic authentication?–pbxMar 8, 2014 at 1:00The documentation states that SonarQube uses basic authentication–Mark O'ConnorMar 8, 2014 at 6:56I am getting 404 when am running via jenkins container. either curl or python–AhmFMMar 27, 2023 at 22:55Add a comment|
|
When I try to call:https://sonar.mydomain.com/api/resources?resource=com.mydomain.project:MY&metrics=ncloc&format=jsonI get{"err_code":401,"err_msg":"Unauthorized"}How do I pass my credentials?
|
How do I pass credentials to Sonar API calls?
|
Actually it is quite simple to let the sonar runner analyze multiple projects as long as they are in the same file system. Just put a properties file in a directory that is not to far away from the projects. Then declare each of your projects in this properties file.Lets assume you have 4 projects in dev/general/BasicStuff, dev/service/CoolStuff, dev/utility/UtilStuff and dev/display/FrameWorkStuff.As described inhereWay #2 you create a file in dev which contains the linesonar.modules=BasicStuff,CoolStuff,UtilStuff,FrameWorkStuffAnd for each of the "modules" a line likeBasicStuff.sonar.projectBaseDir=general/BasicStuff
CoolStuff.sonar.projectBaseDir=service/CoolStuffInside the project directories you in turn create a file which contains the other needed information, e.g.sonar.projectName=BasicStuff
sonar.sources=srcIf you start sonar runner with the top level properties as target you get a comprehensive result which shows metrics across the projects as well as allowing you to drill into each of them.Hope this was what you were looking for.ShareFolloweditedJun 28, 2016 at 22:47Julian Cardenas4,94722 gold badges1111 silver badges1010 bronze badgesansweredMay 13, 2013 at 18:58Christoph GrimmerChristoph Grimmer4,25844 gold badges4141 silver badges6464 bronze badges1Incredibly useful. I tweaked this to work with a Jenkins/Sonar build and it saved a ton of time. Only had to create one build job instead of 11.–MichaelJul 10, 2017 at 19:04Add a comment|
|
I am trying to run sonar-runner to analyze multiple Java projects in one go. According to thedocumentationit is just a matter of creating asonar-project.propertiesfile for each project. But it is not clear to me where exactly I have to put these sonar-project.properties files.I tried to add multiple .properties files in the$SONAR_RUNNER_HOME/conffolder but the runner does not seem to pick them up. It only sees the sonar-project.properties file.Any suggestions on how to run sonar-runner for multiple projects?
|
Setup sonar-runner for multiple java projects
|
Use thesonar.exclusionsproperty for this:<properties>
<sonar.exclusions>**/*generated*</sonar.exclusions>
</properties>ShareFolloweditedJul 12, 2013 at 20:08Philippe Blayo10.8k1414 gold badges4848 silver badges6666 bronze badgesansweredDec 4, 2012 at 15:04KeppilKeppil45.9k88 gold badges9898 silver badges119119 bronze badges0Add a comment|
|
How to exclude generated code from sonar processing and reporting?I tried toexclude**/*generated*but packages likeorg.blayo.generatedare still in report:<plugin>
...
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<excludes>**/*generated*</excludes>Edit:The right regular expression was**/generated/*.java
|
Exclude generated code in sonar
|
Also had this issue, and pytest was not producing a properly formatted coverage report what sonarqube could utilize. I rancoverage xml -iafter pytest produced the coverage report, and this command produces a properly formatted coverage report which sonarqube understands.ShareFolloweditedMay 10, 2017 at 14:29Nikolay Kostov16.7k2323 gold badges8888 silver badges125125 bronze badgesansweredMay 10, 2017 at 14:12Will RubelWill Rubel15111 silver badge33 bronze badges23Note that if you install the pytest-cov plugin, than you can get the equivalent by passing--cov-report xml:/path/to/your/coverage.xmlto pytest directly.–Adam ParkinSep 7, 2018 at 21:153Using pytest 4.5 and pytest-cov 2.7.1 and --cov-report xml:coverage.xml still did not produce test coverage lines on sonar scanner–vfrank66May 30, 2019 at 17:07Add a comment|
|
I'm running a pretty simple set of python projects through sonar-runner and am having issues getting tests to show up.I'm running Sonar 3.2.1, with Python Plugin 1.1. The coverage report is generated previously.I have the following set:sonar.dynamicAnalysis=reuseReports
sonar.core.codeCoveragePlugin=cobertura
sonar.python.coverage.reportPath=coverage.xmlNo matter what I do at this point, the coverage does not show up.My tests are in the same folder as my sources... could that be the issue? Is there a requirement for how source code is laid out for the coverage report to get analayzed properly by sonar?Edit: Adding a few more notes...It is a multiproject python instance. I have three projects in there. Everything else seems to show up properly on the sonar report. I'v defined the base and source directories for each and the coverage.xml file has been pre-generated into the base directories of each.The coverage widget shows up but shows:Code coverage
-
Unit test success
0 testsI'm also seeing when I run sonar-runner:10:04:29.641 INFO p.PhasesTimeProfiler - Sensor PythonCoverageSensor...
10:04:29.642 INFO .p.c.CoberturaParser - Parsing report '/home/jenkins/jobs/myproject/workspace/trunk/src/python/coverage.xml'
10:04:29.883 INFO p.PhasesTimeProfiler - Sensor PythonCoverageSensor done: 242 ms
|
Test/Test Coverage with Python in Sonar not showing up?
|
From thedocumentation:You can either:define property<sonar.skip>true</sonar.skip>in thepom.xmlof the module you want to excludeuse build profiles to exclude some module (like for integration tests)use Advanced Reactor Options (such as "-pl"). For example }mvn sonar:sonar -pl !module2ShareFolloweditedJan 20, 2017 at 19:39Camilo Silva8,50344 gold badges4343 silver badges6161 bronze badgesansweredMay 15, 2015 at 14:24David RACODON - QA ConsultantDavid RACODON - QA Consultant3,99311 gold badge1313 silver badges1414 bronze badges36Only linking some documentation is not that helpful. Especially as in this case the page does not exist anymore. I would suggest to paste the important part and add the link for additional info.–MartinJan 26, 2016 at 12:343I updated the answer with the up-to-date link and also quoted the relevant part from the documentation.–Grey PantherApr 1, 2016 at 7:371Link to documentation is broken–shrxSep 29, 2021 at 9:28Add a comment|
|
I have a multi module Maven project. I need to exclude one of the sub module from sonar anlaysis.I run the mvn sonar:sonar from parent directory.Is there a way to specify the exclusions in pom file or do we need to configure it in sonar qube.
|
How to skip a sub module in a sonar analysis in a multi module java project
|
So how can I fix this warning ?You can use a type parameter for your class :public class GridModelHolder<T> {
private List<T> gridModel;
public List<T> getGridModel() {
return gridModel;
}
}The client code can then decide what type ofListGridModelHolderholds :GridModelHolder<String> gridModelHolder = new GridModelHolder<String>(new ArrayList<String>);However, if you insist on using raw types, you can either suppress the warnings or simply have a List of objects (Neither of these are recommended)@SuppressWarnings("unchecked")
public class GridModelHolder {
private List gridModel;
public List getGridModel() {
return gridModel;
}
}ORpublic class GridModelHolder {
private List<Object> gridModel;
public List<Object> getGridModel() {
return gridModel;
}
}ShareFolloweditedJul 8, 2015 at 10:49answeredMay 30, 2015 at 7:21Chetan KingerChetan Kinger15.1k66 gold badges4747 silver badges8383 bronze badgesAdd a comment|
|
private List gridModel;
public List getGridModel() {
return gridModel;
}Eclipse shows a warning:List is a raw type. References to generic type List should be parameterized.Changing the code to below will remove the warningprivate List<?> gridModel;
public List<?> getGridModel() {
return gridModel;
}However the above code shows a Major pitfall error in SonarQube which says:Remove usage of generic wildcard type. Generic wildcard types should not be used in return parametersSo how can I fix this warning?I see asimilar question herebut could not find the solution .UsingClass<? extends Object>did not remove Sonar warning.
|
Java wildcard generic as return warning in Eclipse and SonarQube
|
For the sonar-maven-plugin it works the same. Just add these two properties to the pom file:<project xmlns="...>
...
<properties>
<sonar.analysis.mode>preview</sonar.analysis.mode>
<sonar.issuesReport.html.enable>true</sonar.issuesReport.html.enable>
</properties>
...
</project>results will be in the target/sonar folderShareFollowansweredOct 12, 2017 at 18:11Georg MoserGeorg Moser68077 silver badges1616 bronze badges15Is this still valid for Community Edition Version 7.5?–OPTIMUSMar 11, 2019 at 13:16Add a comment|
|
I am using SonarQube 5.6.3. How can I create a SonarQube analysis details report as a PDF form, an excel report, or an html formatted report?No plugin seems to be available for this.I was unable to generate an html file using below configuration:sonar.issuesReport.html.enable = true
sonar.issuesReport.html.location = c:\
sonar.issuesReport.html.name = sampleHow can I export these details from SonarQube?
|
How to export results as a PDF report?
|
You can use dynamic service injection in the component. In that case it will have one parameter and you can inject as many service as you want.import { Component, Injector } from '@angular/core';
import { MyService } from './my.service';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
name = 'Angular';
myService : MyService;
constructor(private injector : Injector){
this.myService = injector.get<MyService>(MyService);
}
}ShareFolloweditedApr 14, 2021 at 12:54E_net428.8k1313 gold badges108108 silver badges146146 bronze badgesansweredApr 14, 2021 at 12:22Abhinav KumarAbhinav Kumar2,94311 gold badge1818 silver badges3030 bronze badges2Thank you for quick response. It's working!–Vaibhav GaikwadApr 19, 2021 at 4:349Mind that, this is just a hack that works but not a proper solution. Ideally you should design your component in a way that it should not have that many dependencies.–KrishnaAug 4, 2021 at 12:17Add a comment|
|
My angular app showing above error message when it pass thought sonar scan. Is there any way to fixed it.I want to pass 8 or 9 dependency but sonar lint not allowing. Is there any alternate way to make it possible?
|
Angular - Sonar - Constructor has too many parameters (8). Maximum allowed is 7
|
The propertieshttps.proxyHostandhttps.proxyPortare finally supported in SonarQube 5.5. Thanks Alix for the feedback.https://jira.sonarsource.com/browse/SONAR-7429ShareFollowansweredMar 10, 2016 at 22:31Simon BrandhofSimon Brandhof5,13611 gold badge2222 silver badges2828 bronze badgesAdd a comment|
|
Recently, SonarQube uses the bintray repository for package distribution,in https(seeupdate-center.properties).Using the update center behind a proxy, some updates are found but when upgrade, error (here for xml plugin) :Fail to download the plugin (xml, version 1.3) from https://sonarsource.bintray.com/Distribution/sonar-xml-plugin/sonar-xml-plugin-1.3.jar (error is : Fail to download: https://sonarsource.bintray.com/Distribution/sonar-xml-plugin/sonar-xml-plugin-1.3.jar (no proxy))The SonarQube:DefaultHttpDownloaderseems not supporthttps.proxyXXX properties.Is there today a mean to use the update center for these plugins ?@SonarSource : This feature could be supported insonar.propertiesfor the future ? Or declare http url for bintray repository (but evil) ?Thanks
|
Update center behind proxy : howto with https bintray repository?
|
As far as I remember - file would be populated during shutdown of Tomcat.ShareFollowansweredOct 2, 2011 at 19:48GodinGodin10.1k33 gold badges4141 silver badges7878 bronze badges2Ok, I will try that this week, and return to you.–Romain LinsolasOct 5, 2011 at 6:37If you don't want to shutdown your server, like we do, Cobertura has a coberturaFlush webapp that can be called usinghost:port/coberturaFlush/flushCobertura. Be sure to have your cobertura jar loaded by the same classloader.–DormouseMar 11, 2014 at 20:05Add a comment|
|
I want to measure the code coverage of integration tests using theJaCoCoand Sonar tools.For that, I start my Tomcat 5.5 configured with the JaCoCo agent in order to get the dump file from JaCoCo.Thus, I set theJAVA_OPTSfor that:set JAVA_OPTS=-Xrs -XX:MaxPermSize=256m -XX:PermSize=256m -XX:NewRatio=3 -Xms512m -Xmx1024m -XX:+UseParallelGC -javaagent:C:\dev\servers\jacoco-agent.jar=destfile=C:\dev\servers\jacoco.exec,append=true,includes=my.application.*When I start Tomcat, theC:\dev\servers\jacoco.execfile is generated, but no data is filled.Is there something I forgot in the configuration of my server?Regards.
|
Getting code coverage of my application using JaCoCo Java agent on Tomcat
|
It is not possible to deactivate a rule inherited from a parent quality profile.ShareFollowansweredJan 14, 2014 at 12:43Fabrice - SonarSource TeamFabrice - SonarSource Team26.6k33 gold badges6363 silver badges5858 bronze badges53Any evolutions/plans since this answer ?–meroursSep 21, 2015 at 12:394This is an old question, but with SQ 6.6 it seems it is still impossible to deactivate an inherited rule. Same question as the previous comment: any plans to make this possible ? Thanks–lbndevOct 25, 2017 at 16:35You should just change how it is called : it's not "inheritance" you are doing, it's "links". Or you can implement real inheritance like in object languages of course.–TristanFeb 11, 2020 at 16:16This continues to be a problem in 8.1–YeikelMar 8, 2022 at 16:11That’s not actually true. You can leverage the SonarProperties file to turn OFF any rule in your project. Here is a perfect example on GitHub of someone doing just this.github.com/simgrid/simgrid/blob/master/sonar-project.properties–WaxhawApr 14, 2022 at 21:10Add a comment|
|
Using SonarQube, we wish to create a new quality profile from an existing profile, but deactivate a couple of the rules. The GUI allows us to modify the severity of inherited rules, but not deactivate the rules.Is there any way to achieve this?A workaround is to copy the profile and modify it, but we wish to retain the link to the original profile so that our inherited profile picks up any changes that are made to the original profile.
|
SonarQube - how to deactivate inherited rule in quality profile?
|
But this code works correctly in Spring 4.3.20. Is this rule actual
for Spring 4.3.20?Yes. SonarLint is correct. Self-invocation cannot make@Transactionalto take effect. It does not change even in Spring 5. That is how Spring AOP works (refer todocs). Your codes works most probably because you start another transaction insideitemDao(May be you have another@Transactionalmarked onItemDao#addItems()).if I make the second method as package-private, the SonarLint warning
disappears... Why?Don't know why. Maybe it is a bug. As mentioned in thisrule, it should give you warning when mark@Transactionalin private method.ShareFolloweditedFeb 7, 2019 at 8:30answeredFeb 7, 2019 at 6:04Ken ChanKen Chan88.2k2626 gold badges145145 silver badges177177 bronze badges13Sorry for digging out this question but I don't understand why is this a problem with "blocker" severity? In my opinion it just should warn that if you expect @Transactional to work when you call second method, you're wrong. But it states that it "will result in runtime exceptions because Spring only "sees" the caller and makes no provisions for properly invoking the callee". Which is totally incorrect. At least I've never faced any runtime exceptions in such cases. You just work with transaction created in first method (if there is one). Could you elaborate on this?–mykolaSep 22, 2021 at 15:41Add a comment|
|
This question already has answers here:@Transactional method called from another method doesn't obtain a transaction(4 answers)Closed5 years ago.I have the following code:@Service
public class ItemService {
...
public void addItems(@Nonnull DocumentDTO dto) throws Exception {
// some code that takes some time to process
...
addItems(dto.getDocId(), items);
}
@Transactional
public void addItems(long docId, @Nonnull List<Item> items) {
itemDao.addItems(docId, items);
}
}The first method is not @Transactional and it calls the second one with @Transactional.
SonarLint tool states that "Methods should not call same-class methods with incompatible "@Transactional" values" (https://rules.sonarsource.com/java/RSPEC-2229)But this code works correctly in Spring 4.3.20. Is this rule actual for Spring 4.3.20?P.S. Interesting, if I make the second method as package-private, the SonarLint warning disappears... Why?
|
Calling @Transactional method from non-transactional method in Spring 4.3 [duplicate]
|
Documented? Why, yes. Yes they are:https://docs.sonarqube.org/latest/user-guide/metric-definitions/Specifically, Security and Reliability ratings are based on the severity of the worst open issue in that domain:E - BlockerD - CriticalC - MajorB - MinorA - Info or no open issuesFor Maintainability the rating is based on the ratio of the size of the code base to the estimated time to fix all open Maintainability issues:<=5% of the time that has already gone into the application, the rating is Abetween 6 to 10% the rating is a Bbetween 11 to 20% the rating is a Cbetween 21 to 50% the rating is a Danything over 50% is an EThe size of the code base is calculated by the number of lines whereThe value of the cost to develop a line of code is 0.06 days.ShareFolloweditedNov 1, 2022 at 16:46CrazyPyro3,38733 gold badges3131 silver badges3939 bronze badgesansweredJun 20, 2017 at 12:27G. Ann - SonarSource TeamG. Ann - SonarSource Team22.5k44 gold badges4242 silver badges8484 bronze badgesAdd a comment|
|
On Project Dashbord you see below on different attributes."D"Security Ratingon New Code
is worse than A"C"Reliability Ratingon New Code
is worse than ADo we have measure criteria documented ?
|
How SonarQube A, B C,D and E Rating Calculated?
|
Go inkarma.conf.jsand add a type lcov in reportersreporters: [ { type: 'lcov' } ]ShareFolloweditedJun 18, 2023 at 0:21desertnaut59k2929 gold badges145145 silver badges168168 bronze badgesansweredJun 30, 2021 at 9:01TanguyPeeTanguyPee20122 silver badges33 bronze badges16This worked perfectly thanks a lot. My full path wascoverageReporter: { reporters: [ { type: 'lcov' }] }–Kevin OswaldoApr 13, 2022 at 14:02Add a comment|
|
I am running ng test in starter angular 10 project with code-coverage option. Coverage folder is generating properly, but i cant find lcov.info. I need this file for SonarQube.
|
lcov.info file in karma, angular not generating
|
Yes, there is still no plugin for ESLint, and this is part of the strategy, but in the other direction.In fact, our first plugins were for external analyzers, and over time we realized that simply aggregating other tools' results didn't truly serve the community because that community was coming to us with rule bugs, requests and suggestions for improvement - and all we could do was refer them on the tools' makers.So we started writing our own rules instead for better responsiveness and, we believe, enhanced accuracy.I urge you to take the rules you feel are missing to the SonarQube Google GroupEditThe strategy has come full circle. SonarJS nowimports ESLint reports.ShareFolloweditedJul 13, 2022 at 12:21answeredSep 21, 2015 at 8:01G. Ann - SonarSource TeamG. Ann - SonarSource Team22.5k44 gold badges4242 silver badges8484 bronze badges41It seems that the situation is evolving :jira.sonarsource.com/browse/MMF-1231–manuc66May 25, 2018 at 21:591Latest update to the plugin SonarJS (v5.0 – Oct 04, 2018) now imports issues found by eslint plugindocs.sonarqube.org/display/PLUG/SonarJS–Rob WellsJan 8, 2019 at 10:33I wonder... would it not be better to just have Sonar run with the EsLint config as much as possible? Just a thought.–Mig82Nov 30, 2020 at 9:15Hi the links are broken could you please have a look?–anand_v.singhJul 13, 2022 at 10:02Add a comment|
|
We have determined our rules, which should be used for JavaScript code, with ESLint. Nowwe want to integrate ESLint to SonarQubeas we did it before the same way with Checkstyle for JavaCode.Under the following link it is described why SonarQube doesn't want to provide a plugin for ESLint:http://www.sonarqube.org/sonarqube-javascript-plugin-why-compete-with-jslint-and-jshint/Is there still no plugin fir ESLint in SonarQube?Isn't this part of a marketing strategy? There is also a plugin for Checkstyle, FindBugs etc... Why does SonarQube suddenly stop to support the integration of other code analysing tools?
|
SonarQube: Integrate ESLint for JavaScript in SonarQube?
|
First, analysis will scaneveryline ofeveryfile.Let's sayI'm using a recent version of SonarQubeI've set the leak period (this can be configured at the global and project levels) to 30 daysThat means that anylineof code addedor updatedwithin the last 30 days is considered "new" and thus, "in the leak period".If I make a commit that adds a bug, it's marked as a bug in "new code".If I change a line with an existing bug but don't fix the bug (Why???) then I have an "old" bug on "new" code. Since the assumption is that you'll "clean as you code" (including fixing the old issues in the code you're working on) no work has been put in to "properly" handling this case.ShareFollowansweredApr 19, 2018 at 12:41G. Ann - SonarSource TeamG. Ann - SonarSource Team22.5k44 gold badges4242 silver badges8484 bronze badges26FYI to set this for a given project, go to Administration -> General -> (Scroll down to) "New Code Period"–Roy TrueloveJun 7, 2019 at 17:171so what is "leak period" vs "new code period"? Im so confused. I dont understand what I should be setting new code period and leak period to because I dont know how they are surfaced in sonarqube metrics or reports–red888Jun 5, 2020 at 14:18Add a comment|
|
Re the default quality gate, strangely, we are unclear of the definition “new code”!To illustrate, let’s say we change a file by adding new code. Is default sonar quality gate analysis done on only the new lines of code or the whole file?
We are unclear but suspect it is the whole file! I’m being told by colleagues that projects are failing quality gate because files with pre-existing blockers etc. were touched/changed.Any clarification would be much appreciated.
|
sonarqube "new code" definition
|
About Sonar side:yes, theScala Sonar Plugindevelopment is currently stalled. It was initiated by the community, but nobody has offered to take it over yet. If there are some volunteers, we'll be glad to guide and help them.concerning the support of several languages inside a single project, support will be coming in Sonar. I can't give you a roadmap for it, but we're currently thinking about how to add this support in Sonar in the next releases, so this is a short term issue.ShareFollowansweredSep 13, 2012 at 9:07Fabrice - SonarSource TeamFabrice - SonarSource Team26.6k33 gold badges6363 silver badges5858 bronze badges14 years on and still no word on Scala support for Sonar. Last word from Freddy Mallet was simply to confirm the obvious:groups.google.com/forum/#!topic/sonarqube/MkcW9tFG8UY–RCrossOct 21, 2016 at 13:04Add a comment|
|
I'm trying to set up simple code coverage reports for a team coding in mixed Scala/Java at approx. a 90/10 ratio and running into some serious roadblocks. I've previously set up & administrated Sonar to great success with a Java-only team, but it doesn't appear to be an option.Sonar w/Scala plugin is buggy and appears to support Scala-only projects, not mixed ones.SCCT integrates with our maven build, but fails out with false-negative test failures repeatedly.Undercover has been my best luck so far; It's integrated with our maven build & generates reports, but they aren't archived or hosted anywhere as they would be with Sonar. There also appears to be no central index to make it simple to navigate the generated reports.I've read the answers here on StackOverflow, but they largely date back to 2010 and suggest that no decent solution is available. Has this changed?Is there something obvious I'm missing?
|
Is there a Sonar-level code coverage equivalent for Scala?
|
In SonarQube v4, go to your project's dashboard and then to Project Configuration \ Settings (top right under the Search box).Click the SCM Activity link in the Category list and change the "Activation of..." drop down to false.You can change the default on the global settings page.ShareFollowansweredFeb 17, 2015 at 13:10Paul MedcraftPaul Medcraft1,3961111 silver badges2323 bronze badges21though this doesn't help if the project was never created automatically. I used gouessej's solution which worked for me :)–dasLortFeb 10, 2016 at 15:53It also works for Sonarqube version 7.1 - Go to Administration->Configuration->SCM and set to Disable–Sergio GabariJun 6, 2018 at 15:04Add a comment|
|
When i run the jenkins task i get the following error17:12:49.738 INFO - Sensor SCM Sensor...
17:12:49.847 INFO - SCM provider for this project is: svn
17:12:49.847 INFO - Retrieve SCM blame information...
17:12:49.863 INFO - 843 files to be analyzed
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
Total time: 1:11.026s
Final Memory: 31M/214M
INFO: ------------------------------------------------------------------------
ERROR: Error during Sonar runner execution
ERROR: Unable to execute Sonar
ERROR: Caused by: The svn blame command [svn blame --xml --non-interactive -x -w src/com/musigma/muPDNA/RESTClient/ServiceClient.as] failed: svn: E215004:When i try to delete the .svn folder and run the sonar runner, it works fine. I have tried to ignore the svn files and svn folder, also i have tried to disable the blame option in the sonar but without any possible outcome.Which is the right way to do this ??its not mentioned anywhere. I want to eliminate the error caused by blame(svn) but I don't want to delete the ".svn" folder before the analysis(which is the only way i'm able to get it working)
|
Error in jenkins during sonar analysis caused by svn blame
|
Updated:(16th Nov 2020 onwards)Remove olderpod 'Fabric' & pod 'Crashlytics'from Podfile. Add following dependencies.# Add the pod for Firebase Crashlytics
pod 'Firebase/Crashlytics'
# Recommended: Add the Firebase pod for Google Analytics
pod 'Firebase/Analytics'Older :Please check whether you are using latest Crashlytics & Fabric library.pod 'Fabric', '~> 1.10.2'
pod 'Crashlytics', '~> 3.14.0'Next Step:update your podfile with these podsThen runpod installNow, build the project, it should work.ShareFolloweditedNov 20, 2020 at 13:52answeredMar 31, 2020 at 17:02Milan KamilyaMilan Kamilya2,24811 gold badge3232 silver badges4545 bronze badges0Add a comment|
|
[31merror: could not complete submission of dSYM at /Users/XXUSERXX/Library/Developer/Xcode/DerivedData/ProjectName-flcoueeibbfifebpxptgzctdsqel/Build/Intermediates.noindex/ArchiveIntermediates/ProjectNameAlpha/BuildProductsPath/ProjectNameAlpha-iphoneos/ProjectName.app.dSYM:
Error Domain=com.crashlytics.mac.error-domain.process-dsym Code=4 "This version of OSX is not able to perform the necessary dSYM transformations."
UserInfo={NSLocalizedFailureReason=This version of OSX is not able to perform the necessary dSYM transformations.}
[0m Command PhaseScriptExecution failed with a nonzero exit code
** ARCHIVE FAILED **I'm getting the above error message when I upgraded my MAC Mini (Catalina) latest (16 GB RAM) and XCode to latest version.
I'm working with Jenkins to run test cases for IOS and ones test cases are generated then it will get uploaded to Sonar Qube server.Things Which I've tired.Restarting MAC mini, Closed XCode, Checked XCode configuration like "Debug information format" set to Yes,"Debug information format" to "DWARF with dSYM file".Earlier it was working fine after update it is not generating the build, Fastlane is not installed.Thanks
|
This version of OSX is not able to perform the necessary dSYM transformations
|
I end up adding all of the following attributes in order to avoid Sonar complaining about this vulnerability:DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
//REDHAT
//https://www.blackhat.com/docs/us-15/materials/us-15-Wang-FileCry-The-New-Age-Of-XXE-java-wp.pdf
factory.setAttribute(XMLConstants.FEATURE_SECURE_PROCESSING, true);
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
//OWASP
//https://cheatsheetseries.owasp.org/cheatsheets/XML_External_Entity_Prevention_Cheat_Sheet.html
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
// Disable external DTDs as well
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
// and these as well, per Timothy Morgan's 2014 paper: "XML Schema, DTD, and Entity Attacks"
factory.setXIncludeAware(false);
factory.setExpandEntityReferences(false);
DocumentBuilder builder = factory.newDocumentBuilder();ShareFolloweditedOct 18, 2023 at 13:04Miss Chanandler Bong4,1921010 gold badges2828 silver badges3737 bronze badgesansweredJan 14, 2020 at 14:48chompchomp1,35211 gold badge1414 silver badges3333 bronze badgesAdd a comment|
|
I ran my java code against sonarqube and I got 'Disable XML external entity (XXE) processing' as vulnerability. I spend some time on google to resolve the issue. I have been trying alot of approach but nothing is working for me. I don't know what I'm missingMy Code:final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
docFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
docFactory.setFeature(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
docFactory.setFeature(XMLInputFactory.SUPPORT_DTD, false);
docFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
docFactory.setFeature("http://xml.org/sax/features/external-general-entities", false);
docFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
docFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
final DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
final Document doc = docBuilder.parse(filepath);I'm using java 1.8, Any help is appreciated. Thanks
|
how to fix 'Disable XML external entity (XXE) processing' vulnerabilities in java
|
Sonarqube cannot guarantee that the two calls toid.asInteger()returns the same object, e.g. because multi-threading might have changed the value ofidbetween the two calls, so it is correctly stating that the presence hasn't been adequately tested.Change code to assign to a local variable first, to ensure thatisPresent()andget()are called on the same object:private boolean isValidId(Id id) {
Optional<Integer> idAsInteger = id.asInteger();
return idAsInteger.isPresent() && idAsInteger.get() >= BASE_ID;
}ShareFolloweditedNov 6, 2018 at 21:06answeredNov 6, 2018 at 20:44AndreasAndreas157k1313 gold badges155155 silver badges250250 bronze badges313Multi-threading isn't even needed: two calls to the same method are not guaranteed to return the same thing, and I'm not sure Sonar is able to guarantee that asInteger() is idempotent.–JB NizetNov 6, 2018 at 20:461@Andreas excellent point, 1+, but I would completely write that as a single statement though–EugeneNov 6, 2018 at 20:473@JBNizet Sonar can never guaranty any properties of a method in a different class, as it can’t even guaranty that the implementation will be the same at runtime. The only exceptions would be well known (JDK) methods with a precisely defined contract or formal contracts expressed as annotations.–HolgerNov 7, 2018 at 7:15Add a comment|
|
I run SonarQube to check my code and I found a case which I don't understand the reported error.My code is:private static final int BASE_ID = 100_000_000;
private boolean isValidId(Id id) {
return id.asInteger().isPresent() && id.asInteger().get() >= BASE_ID;
}The methodasIntegerreturnsOptional<Integer>The error that I am getting from sonarqube isCall "Optional#isPresent()" before accessing the value.in the return line.I understand that the code is ok as the second part of theifwon’t get executed if the first one is false. I know that this can be solved with a.filter(..).isPresent()but I like it more this way.Any ideas why would this happen?
|
Calling Optional#isPresent() in single line is reported as not called
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.