Sonar Configure - java

I installed Sonar Plugin on my eclipse, (i ran the server .../StartSonar.bat) and when I do test connection on LocalHost:9000 its okay (Connection Sucessfull). Now What should I do to associate my projects with sonar? I'm kind lost. I'm rookie.

If your projects are built with maven then all you need to do is run mvn sonar:sonar on your project root folder (where your pom.xml is located) and the report will get pushed to your sonar instance.
And also you need to have the sonar profile set up in your settings.xml. Example below:
<settings>
<profiles>
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!-- EXAMPLE FOR MYSQL -->
<sonar.jdbc.url>
jdbc:mysql://localhost:9000/sonar?useUnicode=true&characterEncoding=utf8
</sonar.jdbc.url>
<sonar.jdbc.driverClassName>com.mysql.jdbc.Driver</sonar.jdbc.driverClassName>
<sonar.jdbc.username>sonar</sonar.jdbc.username>
<sonar.jdbc.password>sonar</sonar.jdbc.password>
<!-- SERVER ON A REMOTE HOST -->
<sonar.host.url>http://localhost:9000</sonar.host.url>
</properties>
</profile>
</profile>
Read more here.

To use the plugin in Eclipse SonarQube you must have a sonarQube instance (server) installed, documentation on how to do can be found at the following link http://docs.sonarqube.org/display/SONAR/Setup+and+Upgrade.
Once you have performed an initial analysis of your code, either as maven says Tomasz or sonar-runner, (http://docs.sonarqube.org/display/SONAR/Analyzing+Source+Code) you can, with sonarqube plugin for Eclipse, set a reference to the server in the General preferences Eclipse Window -> Preferences -> SonarQube -> Servers and project level should "link" or refer to said first analysis located in your server.
Once you do this, every time you make an analysis of your code with SonarQube from Eclipse, it will connect to the server, the existing evidences will be brought and will do an incremental analysis of your code with respect to information collected on the remote analysis.

Related

Maven dependency : Failed to get sources. Instead, stub sources have been generated by the disassembler

when i'm navigating to a maven dependency class, i get a .class file with this comment on top and no doc is shown :
// Failed to get sources. Instead, stub sources have been generated by the disassembler.
// Implementation of methods is unavailable.
I don't have the issue with Java classes, only maven dependencies.
I have enabled download sources in the maven settings.xml and in the java extension pack settings.
Anyone has any idea how to solve this please ?
i had the same problem and i solve it,try this:
set settings.json in vscode,
"java.eclipse.downloadSources": true,"java.maven.downloadSources": true
add follow settings in settings.xml of maven:
<settings>
<!-- ... other settings omitted ... -->
<profiles>
<profile>
<id>downloadSources</id>
<properties>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>downloadSources</activeProfile>
</activeProfiles>
</settings>
3.reopen vscode and it will download javadoc
Could you try to set the "java.jdt.ls.java.home" manually? Set it to the JDK you installed on your computer.
Some people others had run across this kind of problem. It looks like an issue with the language server's embedded JRE.
I had this issue previously, and I couldn't change the language server's embedded JRE due the version being <17. The fix was adding the following line into settings.json.
"maven.terminal.useJavaHome": true

How to increase the number of connections in maven

How can I increase the number of http(s) connections a maven build will use to download and upload Artifacts from the repository (Artifactory or similar).
I have seen this page:
https://maven.apache.org/guides/mini/guide-http-settings.html
But it does not say what is the parameter and syntax to set it.
I am using Apache Maven 3.6.0
according to Maven documentation By default, Maven 2.1.0+ will download up to 5 artifacts (from different groups) at once. To change the size of the thread pool, start Maven using following switch option to change default value:
-Dmaven.artifact.threads
for example :
mvn -Dmaven.artifact.threads=1 verify
You may wish to set this option permanently, in which case you can use the MAVEN_OPTS environment variable. For example:
export MAVEN_OPTS=-Dmaven.artifact.threads=3
There is options for maven:
maven.artifact.threads for configuring parallel artifacst resolution
You can use it as is described on site:
https://maven.apache.org/guides/mini/guide-configuring-maven.html
You can also add this properties to your settings.xml so will be affected for all builds:
<settings>
<profiles>
<profile>
<id>props</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<maven.artifact.threads>10</maven.artifact.threads>
</properties>
</profile>
</profiles>
</settings>

How to run Junit test with a specific Category defined in a POM.xml using IntelliJ

I would like to know if using IntelliJ, is possible to run all test in the visual environment choosing a specific Junit category.
At the moment if you execute:
mvn clean test
you execute Fast Tests, but how to use IntelliJ to choose Slow or Fast?
Fragment of pom.xml
<profiles>
<profile>
<id>SlowTest</id>
<properties>
<testcase.groups>YOUR.PROJECT.test.categories.Slow</testcase.groups>
</properties>
</profile>
<profile>
<id>FastTest</id>
<properties>
<testcase.groups>YOUR.PROJECT.test.categories.Fast</testcase.groups>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles>
Many thanks in Advance
Juan Antonio
Your profiles are focusing the test run on specific categories. The JUnit Run/Debug configuration in IntelliJ also allows you to focus a JUnit run on a specific category.
You can access this configuration window from Run > Edit Configurations
Here's a screenshot showing a saved confoguiraiton named SlowTests which runs all tests having the category: com.stackoverflow.surefire.SlowTests:
You can save any such configuration by clicking on the file icon in the top left hand corner of this window and then that configuration will be available in the Run menu and you can even associate a keyboard short cut with it.
More information in the docs.
If you created your project using the pom.xml, in the "Maven Projects"-View you can activate the profiles you want to be active. There (Lifecycle) you can start the goal you want to be executed for each module as well.
How to get this: View->Tool Windows->Maven Projects

How can I run a Maven webapp in Eclipse when I use profiles to populate properties files at build time?

Here is an example profile in my POM:
<profiles>
<profile>
<id>QA</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<jdbc.url>jdbc:mysql://127.0.0.1:3306/SomeDB</jdbc.url>
<jdbc.username>webapp</jdbc.username>
<jdbc.password>somepassword</jdbc.password>
</properties>
</profile>
...
I then have a properties file in my resources folder like this:
jdbc.url = ${jdbc.url}
jdbc.username = ${jdbc.username}
jdbc.password = ${jdbc.password}
and finally I turn filtering on in my POM:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
...
This is actually a simplified example, but you get the idea. Basically when I run
mvn install -P QA
Maven will filter my app.properties file, replace all the placeholders with the values held in the profile, and deploy the populated properties file.
The problem with all of this is that I like to utilize the Servers mechanism in Eclipse, where I have Tomcat running within the IDE. My projects runs in this instance, and Eclipse takes care of updating, redeploying, etc. Maven is left out of the picture, however, during deployments within the IDE and this properties file never gets populated properly.
So, how can I continue running my project within the IDE, but have this properties file properly populated?
You can effectively run any Maven command (including ones with profiles) through the m2eclipse plugin. Also, m2eclipse works with WTP (which I believe is where the Servers tab comes from). I'm not certain on this part, but I've used it to deploy web apps to Tomcat within Eclipse for a Maven project.
Thanks Alex. I ended up installing Eclipse Integration for Apache Maven (Eclipse IAM), formerly Q for Eclipse
This plugin solved two problems: populating properties files during Publish to Server events in Eclipse and populating the WEB-INF/lib folder. Before, even though I was running mvn eclipse:eclipse to satisfy my Build Path in Eclipse, it was not publishing these dependencies to the embedded servers correctly. This plugin does that. Having solved these two issues, I don't see any other barriers to developing a Maven project in Eclipse using the embedded servers.

Stopping EntityResolver from using the internet in maven2 build?

Our build is a standard maven2 build running surefire on jdk 1.5. I know that some of the tests are connecting to the internet to resolve schemas/dtds because they use a loong time when the internet connection is down. How do I stop this ?
The connection is done by your tests while parsing some XML, not by maven itself. To check just start them outside of maven, i.e. in eclipse.
If you can control the files you parse, and it is acceptable, or just as a quick check, you could remove the definitions from your XMLs (a dirty hack). Better is however to configure the CatalogManager through a CatalogManager.properties file, where you could specify custom XML catalogs, e.i. pointing to the resources locally.
You should run it in offline mode. That's a -o on the command line.
Otherwise you could mirror the remote repository locally, and add the local repo to your settings.xml
<project>
...
<repositories>
<repository>
<id>my-internal-site</id>
<url>http://myserver/repo</url>
</repository>
</repositories>
...
</project>
edit: I could be answering the wrong question here, so please clarify.

Categories

Resources