Most projects want to have a consistent code style and to follow some conventions and best practices
in the industry, there are multiple tools that can help with analyzing the code and telling if the
code respects the standards or the code style or not.
These tools typically do a static code analysis as the inspection is performed on the files in the project
without actually rewinding the code, without compiling it and so on.
This is in contrast with dynamic analyses which will actually run the code in order to perform some
inspections.
There are many tools that serve many purposes, and one of these tools that can be used for Java projects
is PMed.
PMG can help find and use variables, problematic code blocks and overall to enforce the generally accepted
best practices in the already has a large set of predefined rules, which will also allow you to configure
or add new rules as needed.
PMed is already installed in the Java project.
Let me show you exactly how it works.
In order to run PMed from the terminal, all I have to do is to use the gradle rapper.
And called a tasks PMed, Maine, which will test the Maine code, but also PMed test, which will test
the test classes which are available here.
It will be able to see here Maine and test.
These are two Java specific packages.
You will see in this case that the bill was successful and there are no issues whatsoever with the code
in order to know if this actually works.
We need to find a rule to write the code that will break that rule and to see if everything works.
I am inside the Java rules in best practices, and you will see here only and best practices that are
quite a few rules that we can use.
I'm interested in system print line, which is often used for debugging, and we don't want to have
something like that inside here.
I'm going to copy this and I'm going to place it inside a code just to demonstrate how that works.
The court order application is in insource main Java and there's a package name under here, multiple
classes.
I'm going to go inside the car's application.
Extend the code block here.
And simply paste the code.
If you go back to the terminal and Rwanda, gradle, griper wheat, pmed, Amane ampm to test.
You won't see the build still successful.
Now, the command that we executed is still successful.
This is because we haven't properly configured that are all set currently.
Going back to the documentation, you will see here that for system print line, we can use this tool
by referencing this rule.
So we first have to reference it.
In the project, in the route part of the project, you will find here the PMed ruleset, that X amount.
These are all the rules that we have created here, because I have specified here some custom rules
we need to define again, which rules we actually want to use.
I'm going to paste inside here this system print line rule and we'll save it.
And then we're rewriting this.
We'll see here that there's a violation and that their report has been generated.
We can view the contents of this report, which is an example, by hovering over the file and clicking
the browser, you will see that a report is not very nice.
But it still tells us that in this file card application that Java on line 10, we have used system
out print line.
So at the very simple level, this is how static court analyses can help projects maintain a healthy
state and to ensure that all the developers working on the project adhere to a predefined set of rules.