does sonarqube pull request analysis needs compiled java code - java

I am working on a Java project and looking to deploy SonarQube on every PR also on our feature branches (not just main) as part of our shift-left strategy. However, we don't want to have to compile Java code every time. Is it possible to run Sonarqube pull request analysis without having compiled java code?
I looked at SQ docs and could not find specifics on how pull request analysis works: https://docs.sonarqube.org/9.7/analyzing-source-code/pull-request-analysis/
Also, looking at other docs, Sonarqube says (https://docs.sonarqube.org/latest/analyzing-source-code/languages/java/)
Java analysis and bytecode Compiled .class files are required for java projects with more than one java file. If not provided properly, analysis will fail with the message:
Your project contains .java files, please provide compiled classes with sonar.java.binaries property, or exclude them from the analysis with sonar.exclusions property.

Related

How to execute a java Programm/File send over Network during runtime

The Problem I am trying to solve is how to execute a Java file (.java extension) or a whole jar (.jar) during runtime from within a java program. The Class / Jar will be sent over Network in order to distribute workload.
My question is what is the best approach. It should be possible to quickly type some code in GUI and let it be executed and/or write large bulk of code in a file and let it be executed. Thus, I need to Compile it and then run it.
So what would be the best approach to this problem in Java ?
PS: sorry for my bad englisch
the Java world relies on Maven heavily to distribute packages: https://maven.apache.org/
Create a .jar file distribution with maven: https://www.mkyong.com/maven/how-to-create-a-jar-file-with-maven/
Publish this .jar file to maven central: https://maven.apache.org/repository/index.html
From there, you can re-import it in your client code.

JMeter external JSR223 java edited in Intellij

I'd like to reach that point where I have a development environment with the following attributes:
JMeter tests consist of JSR 233 scripts mainly
JSR 233 scripts are written in Java
I can edit the java code in IntelliJ
the project is a maven project
So far I could do everything from the list above except IntelliJ support. So, I add a JSR 233 PreProcessor script to the test using JMeter GUI, I setup the script path. When I create the .java file and start to edit in Intellij following examples IntelliJ gets crazy, since the code is not enclosed in a class {}. As a result I can't leverage on IntelliJs capabilities and great support in java.
Is there any way to configure IntelliJ to support these script files?
I double checked how the example Java code is stored in the jmx file, and it is not enclosed in a class {}.
Why not Groovy? you might ask. The reason is that, when I made a mistake in groovy script it doesn't cause build failure, it will give me a runtime error. I consider this not effective enough, however groovy is plan C.
Plan B is all java code gets into an external jar and will be included in minimal groovy script.
I would really appreciate if you could help with answers or any articles probably answers my question.
Java scripting code is actually running Beanshell language
You have BeanShell Box plugin that support your requirement in Intellij
Adds a BeanShell toolbox allowing you to write snippets of both Java and BeanShell code.
Benshell file extension is .bsh usually

Validating a jar made by Eclipse outside of Eclipse

I have a Java application I've developed in Eclipse. To package it into a .jar, I simply run File->Export->Runnable JAR file with copy jar files into sub folder selected.
For deployment, I turn over the compiled jar file along with my source code and the deployment team packages it up and deploys it to our systems. One of the responsiblities of the deployment team is to verify that the source code that is turned over compiles into the binary that is turned over with it. This is the only Java program the deployment team works with so they don't have Eclipse available to import my source code and validate it against what I provided them. For the time being, they have just been taking my word for it, but that needs to change. They will need to compile the code on their own and make sure it matches what I've given them.
How would they go about doing this? I suppose one option is to get all of them up and running Eclipse, but that seems like an overkill. Is there something they can run outside of Eclipse without having Eclipse installed to generate a jar file that they could validate is the same as what I've provided?
Thank you for any assistance.
First, how can they tell that what you supplied "matches"? That doesn't really make sense.
What they really want to do is to build their own deployment artifacts from your source. They can either set up Eclipse and use that as their build tool, or you and they can agree to use a build tool such as Maven or Gradle. These tools integrate with Eclipse, but they are designed to run stand-alone or as part of a tool like Hudson or Bamboo, which will perform build on a schedule or when a VCS is updated.
A client used Maven and Bamboo, along with the rest of the Atlassian suite, to handle enormous builds based on contributions of more than 100 developers. That included running JUnit tests, test coverage, and code quality tools.

Problems generating ant scripts for java when linking to Rhino

When I try to build my project using ant, I get:
"java.lang.NoClassDefFoundError: sun/org/mozilla/javascript/internal/Scriptable"
This stems from my usage of Rhino (the bundled java-script that comes with Oracle JDK)
When I build the project with eclipse, everything works fine.
The ant file I am using was generated by eclipse, and works fine except for the java-script dependencies.
These dependencies are located in the RT.jar that comes with the oracle JDK.
I have tried both jdk6_0_u41 and jdk7, and both give the same results: success in eclipse, fail with ant.
I have tried to build on both ubuntu 10, and 12
I have seen two other suggestions which seem unacceptible to me:
One thread suggested copying RT.jar into the project lib directory. (RT is entire java runtime! )
Another thread suggested that I shouldn't use:sun/org/mozilla/javascript/internal. But since I am doing advanced manipulation (Calling object methods, registering callbacks, etc) I see no alternative to using the sun.org.mozilla.javascript.internal family of classes.
A comment from Oracle's site:
Users should not write code that depends on internal JDK implementation classes. Such classes are internal implementation
details of the JDK and subject to change without notice.
This is not a compiler issue. javac is behaving correctly, according
to the information provided in ct.sym.
The issue belongs with those who decide what should be available with
(and what should be hidden by) ct.sym
You may suggest to include Rhino's jar to your project and repoint it on original's Rhino classes where 'internals' are not hidden from users

Linking to generated Java protobuf code in Eclipse

Here's the workflow that I'm trying to build
compile my proto files using a script, putting the generated src in a specified directory
link to the generated classes in Eclipse
compile my project
I am easily able to do this for C++ using Eclipse CDT: In my project I choose File->New->Other and choose File under General. Then I click on Advanced and select link to system file.
I haven't discovered how to do this for Java, though. Once answer here suggests creating another project with the generated code and make that a dependency to my project. This works but seems redundant.
Is there a way to directly link the generated protobuf Java classes to my project?
Well Java doesn't really have a "link" phase. Your two options are really:
Build the generated code outside Eclipse, and then add a reference to the relevant directory or jar file
Include the generated code within Eclipse (e.g. by having a source path which includes the directory containing your generated code) and get Eclipse to build it along with the rest of your code.
I suspect that the first option will make it easier to keep the generated code well away from your real source, but the second option may make it easier to browse the generated source, and package everything up.

Categories