Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Add Static code analysis tool to ESH build #3995

Merged
merged 5 commits into from
Sep 5, 2017

Conversation

svilenvul
Copy link
Contributor

@svilenvul svilenvul commented Aug 9, 2017

Closes #2437

Before merging:

@@ -16,4 +16,6 @@
<!-- Eclipse SmartHome specific suppressions-->
<!-- These bundles are generated trough XText -->
<suppress files=".+org.eclipse.smarthome.model.+" checks="RequireBundleCheck|ExportInternalPackageCheck|ManifestPackageVersionCheck|ImportExportedPackagesCheck"/>
<!-- Some source files have different headers -->
<suppress files=".+org.eclipse.smarthome.automation.+" checks="HeaderCheck"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want to suppress checks or rather update the automation bundles to adhere to our guidelines?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because we currently have a different arrangement for the license header of the automation component.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, tnx.

@@ -218,7 +218,7 @@ class HueBridgeHandlerOSGiTest extends AbstractHueOSGiTest {
}

@Test
void 'assert that a status configuration message for missing bridge IP is properly returned (IP is an empty string)'() {
void 'assert that a status configuration message for missing bridge IP is properly returned - IP is an empty string'() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you create a separate PR for that change?
I expect that it will be okay to change the long groovy names.

@@ -197,7 +197,7 @@ class HueBridgeHandlerOSGiTest extends AbstractHueOSGiTest {
}

@Test
void 'assert that a status configuration message for missing bridge IP is properly returned (IP is null)'() {
void 'assert that a status configuration message for missing bridge IP is properly returned - IP is null'() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you create a separate PR for that change?
I expect that it will be okay to change the long groovy names.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, of course.

@@ -78,7 +78,7 @@ public static void assertValidItemName(String itemName) throws IllegalArgumentEx

public static State convertToAcceptedState(State state, Item item) {
if (state == null) {
LOGGER.error("A conversion of null was requested", new NullPointerException("state should not be null"));
LOGGER.error("A conversion of null was requested", new NullPointerException("state should not be null")); // NOPMD
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the exact PMD warning that is suppressed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #3888

@kaikreuzer kaikreuzer added the CQ label Aug 9, 2017
@kaikreuzer
Copy link
Contributor

Created CQ 13980 for the tool dependency.

@kaikreuzer
Copy link
Contributor

Woah, that was quick: The CQ is already approved!

@kaikreuzer kaikreuzer removed the CQ label Aug 9, 2017
svilenvul pushed a commit to MusalaSoft/smarthome that referenced this pull request Aug 10, 2017
See eclipse-archived#3995

Signed-off-by: Svilen Valkanov <svilen.valkanov@musala.com>
svilenvul pushed a commit to MusalaSoft/smarthome that referenced this pull request Aug 10, 2017
See eclipse-archived#3995
Fix typos eclipse-archived#3969 (review)

Signed-off-by: Svilen Valkanov <svilen.valkanov@musala.com>
@svilenvul svilenvul mentioned this pull request Aug 10, 2017
kaikreuzer pushed a commit that referenced this pull request Aug 10, 2017
See #3995
Fix typos #3969 (review)

Signed-off-by: Svilen Valkanov <svilen.valkanov@musala.com>
kaikreuzer pushed a commit that referenced this pull request Aug 10, 2017
See #3995

Signed-off-by: Svilen Valkanov <svilen.valkanov@musala.com>
svilenvul pushed a commit to MusalaSoft/smarthome that referenced this pull request Aug 10, 2017
See eclipse-archived#3995

Signed-off-by: Svilen Valkanov <svilen.valkanov@musala.com>
kaikreuzer pushed a commit that referenced this pull request Aug 10, 2017
See #3995

Signed-off-by: Svilen Valkanov <svilen.valkanov@musala.com>
svilenvul pushed a commit to MusalaSoft/smarthome that referenced this pull request Aug 11, 2017
The plugin exports annotations for FindBugs(SpotBugs).

See eclipse-archived#4016 (comment)
See eclipse-archived#3995

Signed-off-by: Svilen Valkanov <svilen.valkanov@musala.com>
svilenvul pushed a commit to MusalaSoft/smarthome that referenced this pull request Aug 11, 2017
The plugin exports annotations for FindBugs(SpotBugs).

See eclipse-archived#4016 (comment)
See eclipse-archived#3995

Signed-off-by: Svilen Valkanov <svilen.valkanov@musala.com>
@svilenvul
Copy link
Contributor Author

The latest build fails with the hue binding. After the update of the XML things schema, the build should be green :-).

@svilenvul
Copy link
Contributor Author

@kaikreuzer

Friday the only remaining errors were caused from the .xsd file that is not up to date - #3963.

Should I ignore these errors or wait for the update of the schema file ?

@kaikreuzer
Copy link
Contributor

Wait for the schema file - it should be up to date now! I retrigger Travis...

@svilenvul
Copy link
Contributor Author

Retrigger Travis.

@svilenvul svilenvul closed this Aug 14, 2017
@svilenvul svilenvul reopened this Aug 14, 2017
@svilenvul
Copy link
Contributor Author

The build failed after 49 mins :

...
Still running (49 of 60): ./.build.sh
Still running (50 of 60): ./.build.sh

The job exceeded the maximum time limit for jobs, and has been terminated.

@kaikreuzer I guess the build is too slow with the static-analysis-tool added.

@sjsf
Copy link
Contributor

sjsf commented Aug 15, 2017

I restarted it once again, just to make sure it was not caused by a slow repository, but the result was the same. That's indeed not so good news...
The global timeout for travis builds indeed is 50 minutes (see https://docs.travis-ci.com/user/customizing-the-build#Build-Timeouts), so there is nothing much we can do about it.
The build until now took something just above 20 minutes. Is it at least plausible that the code analysis adds that much to it? Sounds like a lot, so I'm wondering whether something went seriously wrong or not...

@svilenvul
Copy link
Contributor Author

svilenvul commented Aug 15, 2017

When we talk about speed/performance, FindBugs is always the main suspected :-) .

mvn static-code-analysis:findbugs
....
[INFO] Total time: 18:46 min
[INFO] Finished at: 2017-08-15T11:45:17+03:00
[INFO] Final Memory: 238M/1127M

Checkstyle checks are taking 06:32 min and PMD 02:41 min (and this includes the resolving of different repositories, actually the time is less).

I guess we can speed it up a bit if we tweak the configuration of FindBugs a little bit, but I am not sure if it will be enough.

I would appreciate help here.

@svilenvul
Copy link
Contributor Author

@kaikreuzer, I guess it is up to you.

Please let me know what do you think about disabling the FindBugs checks for the ESH repository.

What we are going to do in this situation ?

@kaikreuzer
Copy link
Contributor

Okay, then I missed some news. AFAIK you prefer a split of core and extensions -- some time ago.

No, you are only always underestimating my pragmatism. While I agree that it would be nice to have it in a separate repo and also to version it separately from the core, I have learned from having openHAB split into several repos what overhead this means in terms of build & release management. After all, we duplicate the number of build jobs, the repos to update for new tools like the static code analysis or other upgrades, the efforts on doing releases and the number of issue trackers (while people today already never know where to post something).
Seeing that we didn't manage to do an official release for a long time let's me doubt that we are in a position to think about separate versioning of core and extensions (which would imho be the main reason for a repo split).

Please let me know what do you think about disabling the FindBugs checks for the ESH repository.

I don't think that genereally disabling valuable checks is an option. We should rather think about how to reduce the situations, where we execute them. I would claim that the build time of the nightly job on our hudson is not an issue, so I would prefer to have it executing the full test/check suite.

Wrt Travis, I am not sure what our options are. If you could add a parameter which deactivates the FindBugs checks and we set that in the Travis configuration only, it might be an acceptable compromise.

@svilenvul svilenvul changed the title [WIP] Add Static code analysis tool to ESH build Add Static code analysis tool to ESH build Aug 18, 2017
@svilenvul
Copy link
Contributor Author

svilenvul commented Aug 18, 2017

Great, I have deactivated the FindBugs checks only in Travis.

This has caused some errors in the report generation goal, but they are already fixed with this commit.

I have also managed to generate a combined report for the whole repository, so maybe it is better to release new version first and then add it to the ESH build.

@kaikreuzer
Copy link
Contributor

so maybe it is better to release new version first and then add it to the ESH build.

New version 0.3.0 has been released - do you want to update the PR accordingly? I think we would be good to merge then!

@svilenvul svilenvul force-pushed the static-code-analysis branch 3 times, most recently from cbbf304 to 3676fc0 Compare September 4, 2017 09:19
@svilenvul
Copy link
Contributor Author

@kaikreuzer, I have rebased and updated the PR.

Do you think we should add a few sentences for the tool in the ESH documentation like we have done this in the openHAB docs - http://docs.openhab.org/developers/development/bindings.html#static-code-analysis ? Where would be the best place for that - maybe in the Coding Guidelines ?

@kaikreuzer
Copy link
Contributor

Yes, I guess the coding guidelines are the best place for it.

Signed-off-by: Svilen Valkanov <svilen.valkanov@musala.com>
@svilenvul
Copy link
Contributor Author

@kaikreuzer, I am ready with the updates on this PR.

Copy link
Contributor

@maggu2810 maggu2810 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wounder about the repositories and plugin repositories that has been added. Do you really need all of them?


The Eclipse SmartHome Maven build includes [tooling for static code analysis](https://github.com/openhab/static-code-analysis) that will validate your code against the Coding Guidelines and some additional best practices. Information about the checks can be found [here](https://github.com/openhab/static-code-analysis/blob/master/docs/included-checks.md).

The tool will generate an idividual report for each binding that you can find in `../your_binding_directory/target/code-analysis/report.html` file and a report for the whole build that contains links to the individual reports in the `../smarthome/target/summary_report.html`. The tool categorizes the found issues by priority: 1(error),2(warning) or 3(info). If any error is found within your code the Maven build will end with failure. You will receive detailed information (path to the file, line and message) listing all problems with Prioriry 1 on the console.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not only about bindings but every bundle that is build (for each binding => for each bundle). And to be fair it would be not only be used for bundles, but for every artifact in the reactor, so "for each artifact" would be correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment it will be used only on bundles - there are two profiles in this PR that activate the tool for bundles and bindings (the one is obsolete now, I will remove it). Initially the idea was to have separate rulesets included in each profile, but this changed over time.

Activating the checks for each artifact is not tested well enough, some of the OSGi specific checks might have problems with that.


The Eclipse SmartHome Maven build includes [tooling for static code analysis](https://github.com/openhab/static-code-analysis) that will validate your code against the Coding Guidelines and some additional best practices. Information about the checks can be found [here](https://github.com/openhab/static-code-analysis/blob/master/docs/included-checks.md).

The tool will generate an idividual report for each binding that you can find in `../your_binding_directory/target/code-analysis/report.html` file and a report for the whole build that contains links to the individual reports in the `../smarthome/target/summary_report.html`. The tool categorizes the found issues by priority: 1(error),2(warning) or 3(info). If any error is found within your code the Maven build will end with failure. You will receive detailed information (path to the file, line and message) listing all problems with Prioriry 1 on the console.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you add a ../ in front of the path.
Normally you call mvn ... in the root of the reactor and IMHO the relative paths should be relative to the root.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I was wondering how to be more precise here, but without much success. I will change it to relative to the root of the reactor.

pom.xml Outdated
</pluginRepository>
<pluginRepository>
<id>buchen-maven-repo</id>
<url>http://buchen.github.io/maven-repo</url>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hasen't this one been removed previously by intention?
Why do you add it again?

pom.xml Outdated
<id>eclipse</id>
<name>Eclipse Snapshot Repository</name>
<layout>default</layout>
<url>https://repo.eclipse.org/content/repositories/snapshots/</url>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been removed some days ago, why do you need the Eclipse Snapshot Repository?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I see I only need both JFrog repositories (one for the plugin and one for its dependencies) , I will remove the others.

Svilen Valkanov added 3 commits September 4, 2017 16:17
Signed-off-by: Svilen Valkanov <svilen.valkanov@musala.com>
Signed-off-by: Svilen Valkanov <svilen.valkanov@musala.com>
Signed-off-by: Svilen Valkanov <svilen.valkanov@musala.com>
@svilenvul
Copy link
Contributor Author

I hope I have answered all questions. Do you have any other concerns ?

pom.xml Outdated
</profiles>

<pluginRepositories>
<pluginRepository>
<id>openhab-artifactory-release</id>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the official repo for the releases is "jcenter" at https://jcenter.bintray.com/.

It probably makes sense that I also request to have it published to Maven central, then we would not at all need a specific repo here.

</pluginRepositories>

<repositories>
<repository>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the pluginRepository enough? Why do we need it as a dependency repository as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, I haven't taught about that much until you asked.
The tool(as a Maven plugin) internally starts the Maven plugins for Checkstyle, PMD and FindBugs and adds itself as a dependency to these plugins, so the included custom checks that are contained there are available in the classpath.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test if it also works without it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I tested it, it is not working without this repository.

pom.xml Outdated
</profiles>

<pluginRepositories>
<pluginRepository>
<id>JCenter Repository</id>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id should imho rather be "jcenter"

pom.xml Outdated

<repositories>
<repository>
<id>openhab-artifactory-release</id>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id should be "jcenter"

Signed-off-by: Svilen Valkanov <svilen.valkanov@musala.com>
@kaikreuzer
Copy link
Contributor

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Static Code Analysis Checks
6 participants