Get SonarQube analysis results in JavaConsole - java

is it possible to get the results of a SonarQube analysis displayed in the JavaConsole?
For example, I installed SonarQube in Java/Maven. I can analyze my program and it uploads the results to localhost:9000. But can I get the number of "code-smells" or "bugs" in my console from the project when it got uploaded to localhost:9000?
I tried smth with
HttpGet httpGet = new HttpGet("http://localhost:9000/api/issues/search?pageSize=500&componentKeys=CODE_SMELLS");
But it seems like it does not work?
I tried to use the web/API but I don't understand the documentation. For example
web_api/api/measures
I don't know how to actually use it in the code I can not find an example or which method or so I have to use, to use the API.
Can someone maybe provide some example code or pseudocode for Java how I could retrieve results from the analysis?
I am fairly new to SonarQube and how to work with an API. So sorry about that.
I am using the newest SonarQube free edition, maven and IntelliJ

If you've installed the sonarlint plugin you get the lint tab next to console and terminal. Ctrl+Alt+s or Ctrl+Shift+s on your project at root and that will produce the results

On http://localhost:9000/api/webservices/list I could find all possible services and parameters.
This helped me a lot, for example:
http://localhost:9000/api/issues/search?componentKeys=myProjectKey&facets=types&facetMode=count

Related

RSocket-CLI: Unresolved reference: clientTransport

I ran into the error while starting the rsocket-cli:
The full log is here.
I did everything according to the README.md, but I got this error at the first step. It's the ./gradlew --console plain installDist.
What's the most interesting in the code this error looks like this:
I'm not sure but probably it can be important. I'm using the Shell: zsh 5.8.
rsocket-kotlin has a snapshot build, and due a 0.13.0 build sometime soon. It seems like the current TCP refactor relies on internal API.
I've raised https://github.com/rsocket/rsocket-kotlin/issues/163
In the meantime if you want websocket support I'd comment that out.
Also there is a rsocket-java CLI you can use if this is still blocking you https://github.com/making/rsc
Apologies and thanks for flagging.

Jenkinsfile syntax highlighting in Java project using IntelliJ IDEA

We already tried the approaches as listed below:
https://github.com/oliverlockwood/jenkinsfile-idea-plugin
https://st-g.de/2016/08/jenkins-pipeline-autocompletion-in-intellij
After having searched the web for many hours on multiple days, we still haven't found a helpful resource on this matter. Thus, it appears to make sense to ask a new question here.
We are developing our Java projects in IntelliJ idea and want to integrate our builds with Jenkins. When we create a Jenkinsfile in Idea, we do not get syntax highlighting or auto completion. Since we are new to Jenkins, those features would be really useful to us. How can we make Idea be more supportive with Jenkinsfiles?
If there is no way to get syntax highlighting and auto completion for a Jenkinsfile in IntelliJ IDEA, what other editors would be helpful?
Please note:
we are working with Java projects, not Groovy projects.
We've already tried the plugin https://github.com/oliverlockwood/jenkinsfile-idea-plugin. When the plugin is activated, the Jenkinsfile is recognized as such, but instead of syntax highlighting we get an error message, please see below.
pipeline {
agent { docker 'maven:3.3.3' }
stages {
stage('build') {
steps {
sh 'echo Hello, World!'
}
}
}
}
IntelliJ IDEA highlights the p of pipeline as error. The error message reads:
JenkinsTokenType.COMMENT, JenkinsTokenType.CRLF or
JenkinsTokenType.STEP_KEY expected, got 'p'
Thanks for any help!
If you want IDEA to recognize a Jenkinsfile as a Groovy file, then you can add the String "Jenkinsfile" as a valid file name pattern (normally contains file endings) for Groovy files. This is supported "out of the box" without requiring any additional Plugin (except the "Groovy" Plugin, but that is already part of IDEA).
To do that go to the settings menu, open the "Editor" item and then "File Types". Now select "Groovy" in the upper list and add "Jenkinsfile". You can also use a regex like "Jenkinsfile*" if you want to be more flexible regarding an optional file ending for the Jenkinsfile.
The setting should now look like this:
Your example now looks like this in IDEA (with the Dracula theme):
So IDEA now provides syntax highlighting and auto completion as far as I can tell. It suggests existing function/method names while writing, but I'm not a Groovy developer, thus I can't tell if some suggestions are missing.
At long last we found a solution that works for us and provides syntax highlighting and code completion for the Jenkinsfile present in an otherwise normal Java project in Idea.
The solution is taken from here, here (and from additional personal experiments / research)
Download the Groovy SDK (if you did not do so already) from the Groovy Page and configure it on your Java project. For help on this see here
Download the pipeline GDSL file from your Jenkins instance which should be available under a link like https://yourJenkinsInstance.tld/pipeline-syntax/gdsl, and add it to the classpath of your Java project. E.g. by creating a new folder src/main/jenkins, putting the pipeline gdsl file there and marking the folder as source root in IntelliJ Idea
Add "Jenkinsfile" as a valid file name pattern for groovy files as described here
To avoid the error message 'node' cannot be applied to '(groovy.lang.Closure<java.lang.Object>), you can add this line at the top of your Jenkinsfile:
// noinspection GroovyAssignabilityCheck
If you add
#!groovy​
header to your jenkinsfile then you should get groovy syntax highlighting in IDE.
Another option is to use a shabang on top of the Jenkinsfile like this #!/usr/bin/env groovy. Also you can try out gdsl: https://st-g.de/2016/08/jenkins-pipeline-autocompletion-in-intellij
but so far it doesn't support declarative pipelines: https://issues.jenkins-ci.org/browse/JENKINS-40127
Looking at the source code, it looks like COMMENTS are not defined (they are commented out in the code)
The STEP_KEY is defined as: STEP_NAME="sh" | "parallel"
I'm not sure the plugin does much more and it hasn't been updated in 2 years.
go to the settings menu, open the "Editor"--> "File Types". Now select "Groovy" in the upper list and add ".Jenkinsfile". You can also use a regex like ".Jenkinsfile" if you want to be more flexible regarding an optional file ending for the Jenkinsfile.
Jenkinsfile is a groovy like script, but normally IntelliJ map it to TextMate editor.
To do that go to the settings menu, open the "Editor" item and then "File Types". Now select "TextMate" in the upper list and add "Jenkinsfile". You can also use a regex like "Jenkinsfile*" if you want to be more flexible regarding an optional file ending for the Jenkinsfile.
Use sh like this and the error should go away (worked for me)...
steps {
sh """
echo 'Hello, World!'
"""
}

How do I get code coverage from XSpec

I am using XSpec at work for XSL unit tests. I see XSpec as a coverage option but I cannot get it to work. I get this error:
"Transformation failed: Failed to load com.jenitennison.xslt.tests.XSLTCoverageTr
aceListener
Testing with SAXON 9.1.0.7"
I am having a tough time finding recent information about XSpec. Can any one point me in the right direction? Thanks!
Code coverage in XSpec is currently not working. I posted a pull request that should fix the code coverage: https://github.com/expath/xspec/pull/80. If you want to fix it in your version of XSpec before the next release, look at the commit changes in files xspec.sh and XSLTCoverageTraceListener.java (see https://github.com/expath/xspec/pull/80/files).
Note that code coverage now works only with SaxonEE and SaxonPE (not Saxon HE) as the Java class requires extension functions which are only available with these two versions of Saxon.

Overtone Livecoding with Emacs/Slime/Swank/cake - Could not locate overtone.live__init.class

I am trying to use emacs and slime to connect to swank to live code using Overtone. I have the whole thing pretty much working, but when i try to run
(ns foo
(:use [overtone.live]
[overtone.inst.synth]))
(definst bar [] (saw 220))
I get the error 'Could not locate overtone/live__inti.class or overtone/live.clj on classpath:' Which i gather basically means that the class files are not where it is looking for them. I am not sure what to do to fix this.
Important note: Slime/Swank/Cake are deprecated means of connecting Overtone and Emacs. Instead, consider using nREPL via Leiningen 2+ and CIDER
it looks like you haven't got the Overtone jar on the classpath. Things to check:
You have overtone-X-Y-X.jar in your project's lib directory
Your project isn't called Overtone (that can cause issues with tools like lein)
Finally, you might want to take a look at this setup video: http://vimeo.com/25190186 which describes the process of getting an Overtone dev environment setup.
Good luck and come join the mailing list and share your thoughts: http://groups.google.com/group/overtone
Have you tried confirming that overtone is in your java classpath?
(System/getProperty "java.class.path")
It's most likely a temporary fix, as I'm just getting my feet wet with clojure and overtone, but I included overtone as a global dependecy in my ~/.cake directory and installed it with:
cake deps --global
Additionally, I'd reccomend updating to the latest version of overtone as it looks like the vimeo link is a few versions behind what is currently reflected on clojars:
http://clojars.org/overtone

Fatal error by Java runtime environment

I am executing a junit test case
I got the following error,
A fatal error has been detected by the Java Runtime Environment:
Internal Error (classFileParser.cpp:3174), pid=2680, tid=2688
Error: ShouldNotReachHere()
JRE version: 6.0_18-b07
Java VM: Java HotSpot(TM) Client VM (16.0-b13 mixed mode windows-x86 )
Can any body please suggest the solution to resolve
I got the same problem, but with alot of googling I found the answer! See this page
Quote from the link:
# An unexpected error has been detected by Java Runtime Environment:
#
# Internal Error (classFileParser.cpp:2924), pid=5364, tid=6644
# Error: ShouldNotReachHere
That's because we are using Android's JUnit stub implementation. Go to Run -> Run As -> Run configurations again and in the recently created JUnit configuration Classpath's Bootstrap Entries remove Android Library
Then Add Library, using Advanced... button, and add JRE System Library and JUnit 3
Apply and Run
Try this, it worked for me.
You'll need to take this up with Sun -- looks like a JVM bug to me. If it's reproducible, you should be able to run java in such a way as to generate more details (e.g. -verbose, etc). If you can reduce it to a minimal case that triggers the bug (source code always helps!), that also goes a very long way.
http://java.sun.com/developer/technicalArticles/bugreport_howto/index.html
http://bugreport.sun.com/bugreport/crash.jsp
In the meantime, you might want to try it with a different JVM implementation (maybe even an older patch level of the Sun JRE).
Go to Run As -> Run Configurations... and select the configuration you are using.
Select the Class Path tab and select BootStrap Entries.
Click on Advance, then Add Library and select JRE System Library.
Bring it up and make it the first entry in the BootstrapEntries List.
Apply and Run...
Another possible explanation: hardware failure. Ruled out if you can reproduce the error on different machines.
I resolved this by
Quit eclipse
Delete the bin and gen directories in your project
Start eclipse
Rebuild your project
I just recently found solution for this issue that was posted by devdanke:
"As of 11-July-2010 and Android 2.1, the work around I use is to segregate tests into different classes. Any test(s) that don't call any Android APIs go into their own classes. For each of these classes, I remove the reference to Android in their Run Configurations, Classpath tab."
The problem with having it configured class by class is then is not possible to run all tests in project. Better approach is creating 2 test projects with different sets of libraries.
Standard Android JUnit Test project can be created following link, and sample test class looks like:
import android.test.AndroidTestCase;
public class ConverterTest extends AndroidTestCase {
public void testConvert() {
assertEquals("one", "one");
}
}
Then JUnit Test project can be converted from Android JUnit Test project by removing Android Library from project build path, and adding JRE System Library, and JUnit 3 library, and sample test class looks like:
import junit.framework.TestCase;
public class ConverterTest extends TestCase{
public void testConvert() {
assertEquals("one", "one");
}
}
I have had a similar problem, I found it was because I had generated a new activity with a main[] stub entry. Once I deleted the main[] code from the new activity templatye the error went away.
YMMV
This could be a JVM bug; see #Zac's answer. But it could also be that your junit test case is causing a corrupted bytecode file to be loaded. Try rebuilding all your .class files, and if that does not fix the problem try refetching any external libraries that your code depends on.
Do you run on a supported platform (Windows, one of a few Linux versions?) If not, that is the first to try.
If you ARE on a supported platform, then downgrade to _17 and see if THAT helps.
Then make a bug report to Sun and hope they will fix it someday (unless you want to give them money for fixing it faster).
Go to Run As -> Run Configurations->classpath->BootStrap Entries
Click on Advance, then Add Library and select JRE System Library as a first entry.
Apply and Run...
I am not sure whether you were able to reach the solution for your problem or not but your question just popped up while I was searching for the solution for the same problem I am facing. And I got one solution from the stack itself, so just thought to share a link with you if that aids you by any means. The link is as below:
Can't run JUnit 4 test case in Eclipse Android project
Another possible reason (for future references):
I had accidentally copied in a main method in my code, causing Eclipse to recognize the project as a java application, thus launching it with that configuration.
To solve it I went into Run > Run Configurations... and then changed from my presumed main in java application to the main activity of my android application simply by choosing it in the left column.

Categories

Resources