How to export and import a set of rules selected from the predefined rules in the rules configuration of the Eclipse Plugin PMD? - import

I am using the plugin PMD for Eclipse and have zeroed in on a set of rules preexisting in my PMD rules configuration. I want to share these set of rules with my team mates . But when i try and export the Rules from PMD, it either exports only one rule OR if I use Ctrl + A on all the rules, it exports the rules but doesn't remember which rule was checked and which was unchecked.
Deleting rules that are not useful and then exporting only selected rules leads to hardcoding of the loaction of the XML file in the rule set .
For Example, If my xml file is stored in location X in my local directory,
the rulesets become
<rule ref="X/custom_PMD_rules.xml/AbstractClassWithoutAbstractMethod"/>
What is the correct way of sharing a set of rules in a team in PMD? I was able to share the rules in Checkstyle and code templates using simple export and import. Then why not in PMD.

I use an XML ruleset file to share rules with teammates. The ruleset can use a relative path to refer to other files. Or if all the rules are in one file, you can just import them to Eclipse and the location doesn't matter.

Related

How to use rule templates in Kie Workbench?

I have installled and have deployed a few rules files to kie server using drools workbench. But now I want to use template files to be used and create drl files out it and then deploy those rules witk kie workbench. I have found an option to add template file such as Guided Rule Template. But the source cannot be edited. Usually when we define templates files we start with a template header. A sample template file is shown below.
template header
frequency
memory
power
package com.myspace.test;
import com.myspace.test.GPU;
template "power-for-gpu"
rule "Choice recommended power supply for GPU_#{row.rowNumber}"
when
$gpu : GPU(frequency ==#{frequency}, memory== #{memory})
then
$gpu.setPower(#{power})
end
end template
but the Guided Rule Template doesn't seems to be in the above manner. It starts with package and no template header can be found or created default. There is no option for defining variables. Its generated source looks like rule file and not template. Is there anyway to define and use templates in kie workbench.

Drools guided rule editor and Eclipse Project

I have created a java project in eclipse which automatically picks up
all the .drl files from an external directory and executes all the
rules in that directory .So this enables the execution of dynamic
addition of new rules at anytime.
Now, instead of creating a new drool file and add it into that
directory, i want to use the guided rule editor to help non technical
users to add new rules into that directory.
I have started on with drools-workbench, but still i have no idea how
to integrate this eclipse project with the guided rule editor feature
available in drools-wb.
Is there any way in which i can export this project into the drools
workbench. If that is possible, then how can i deploy this directory
which contains all the .drl files into drools-wb and how these .drl
files can be used in the guided rule editor.
If your existing project is a maven project then you can import that project into drools-workbench, but there should be some required files(project.import,..etc) need to available specific to drools-workbench those should be available into project. We cant download any specific rule file from drools-workbench, workbench will create jar file which contains all the assets(rules and BPMN files), you can add this jar into classpath and create kieSession from there through which you can execute rules.

Xtext cross-reference across all files in project

I am making a very simple DSL with xtext. A project will contain files that either define a message name, or reference to one. I have included a simplified example:
Grammar:
Model:
statements+=(MessageDefinition | MessageUsage)*;
MessageDefinition:
'[MESSAGE_DEF]' name=ID;
MessageUsage:
'[MESSAGE_USAGE]' usage=[MessageDefinition];
File1.ex:
[MESSAGE_DEF] EXAMPLE_1
[MESSAGE_DEF] EXAMPLE_2
[MESSAGE_USAGE] EXAMPLE_1
File2.ex:
[MESSAGE_USAGE] EXAMPLE_2
In this example the cross-reference from EXAMPLE_1 works such that "Open Declaration" on the usage takes me to the definition. However, the cross-reference on EXAMPLE_2 does not work. I think the default scoping rules prevents different files from sharing references.
What do i need to add so that all the files in a project share the same global scope for cross-references?
Additional information:
The option "Build Automatically" is enabled in the runtime project.
The .project file includes a buildCommand for xtextBuilder and a
nature for xtextNature.
I am only attempting to use the IDE
cross-referencing functionality, there is no generation of code.
All of the files in the runtime project exist in the same folder.
The project was created using "Xtext Project" in the standard wizard, I have only edited the grammar from the pre-generated code, everything else is as-per the defaults. I thought I would need to add some custom scoping behaviour/rules to load all files into the global scope, but I am not sure how this is supposed to be done?
it will work fine with your grammar and scoping if you
have build automatically enabled in your runtime workspace
the project you model in has xtext nature and xtext builder enabled (right-click -> configure -> ...)
if it is a java project model files have to reside in a source folder or a package within the source folder

How to export FindBugs/PMD/Checkstyle rules from Sonar and import into Netbeans

My company has sonar set up to with various plugins (PMD, FindBugs, CheckStyle), and although it is very useful as is (it runs after every Jenkins build that was triggered by a check-in to SVN), I would like it if I could run these various plugins on my local machine before I check the code in.
We have a set of rules already set up in Sonar, so ideally I would like to be able to export that ruleset, perhaps do some munging of the data, and then import the resulting rules into my IDE (Netbeans 7.0.1) into the respective plugins. Is there any way to do this? I've searched all over and short of going through and manually adding each rule to the various plugins, there doesn't appear to be a way to do this. Is there something I'm missing?
TL;DR (Summary): I'd like to export a profile from sonar and import the rule settings into the PMD, Findbugs, and CheckStyle plugins in Netbeans.
Each Sonar profile publishes it's Checkstyle, FIndbugs and PMD configuration under the permalinks tab.
Assuming you've got Sonar installed locally, the following link shows the configuration files used by the "Sonar Way" profile:
http://localhost:9000/profiles/permalinks/2
You don't need your own Sonar installation. You can get the configuration of any of Sonar's built-in Quality Profiles from Sonar's Nemo site:
There are about a dozen Java Quality Profiles. A commonly used profile - Sonar way with Findbugs - is available at:
http://nemo.sonarsource.org/rules_configuration/index/135
The initial Profile view just lists all the rules. Don't use the "Download" link on that view. That just gives you a CSV listing of the merged rules across all tools. Helpful for review, but not what you're asking for.
To export the tool-specific configuration, select the Permalinks tab/view. Those links return the configuration file in the form expected by each tool. For example, here's the link for the FindBugs XML configuration file:
http://nemo.sonarsource.org/profiles/export?format=findbugs&language=java&name=Sonar%2520way%2520with%2520Findbugs
SonarLint is the newer plugin and it doesn't support Checkstyle/PMD/FindBugs profiles anymore. Everything has to be migrated to squid rules and configured on the SonarQube server under Quality Profiles. You need to connect to the server using connected mode and set your custom quality profile as default so that local analysis would show issues related to your quality profile.
More information about SonarLint Plugin and connected mode can be found at
http://www.sonarlint.org/eclipse/index.html#Connected
Another simple mechanism is to use : Backing up / Restoring a Profile
See : http://docs.sonarqube.org/display/SONAR/Profile+Existence+Edits
Taking backup from an instance(source) will give you a backup.xml file on your local machine and then on another instance(destination) you can restore it.

Eclipse Checkstyle with configuration and SuppressionFilter on server

I have configured my Eclipse to use a remote checkstyle configuration that is located on a server, which I reach via HTTP. This works fine, but the configuration contains:
<module name="SuppressionFilter">
<property name="file" value="${basedir}/checkstyle-filter.xml"/>
</module>
So I try to set an additional property "basedir" which points to the same directory where the configuration is. When I try to run checkstyle on a project I get an error: cannot initialize module SuppressionsFilter - Cannot set property 'file' in module SuppressionFilter to 'http://"my Url "/checkstyle-filter.xml'
Any suggestions on how to configure Eclipse to use the checkstyle configuration from the server even though it has that it contains the SuppressionFilter? I do not want to put a checkstyle-filter in each project...
This is currently not possible as reported in Remote Configuration Files cannot use a SuppressionFilter - ID: 2018081. Actually, the problem is in Checkstyle which uses a java.io.File object for the external SuppressionFilter file (and thus setting a value starting with http:// won't work). There is a feature request on Checkstyle to change this (see Allow remote references to additional file configuration - ID: 2018608). But don't expect these changes to occur very soon (unless if you start working hard on it :)
That being said, while I perfectly understand the need for a corporate wide checkstyle configuration file, I'm more surprised by the need for a shared SuppressionFilter file. After all, its content is project specific, isn't it? So, I think that you should actually use another property, for example ${workspace} (or your own property, my understanding of Expanding property placeholders is that using a .properties file is supposed to work with a Remote Configuration too) and ask each project to provide its own file with its SuppressionFilter that would be referenced from the workspace. Based on convention, that should work.
Actually, you can use a suppression filter. I have it setup this way with a remote config using the 5.6 eclipse checkstyle plugin. Just put the suppression file in the same remote directory as the checkstyle.xml file and then use the following:
<property name="file" value="${config_loc}/suppression.xml" />
It will then work with eclipse. Basically just replace ${base_dir} with ${config_loc}
I wasn't able to add a patch to the original feature request, so I created a new feature request here: https://sourceforge.net/tracker/?func=detail&atid=397081&aid=3485185&group_id=29721
I've implemented this functionality as I needed it to be able to corporate-wide disable certain checks for unit tests and Eclipse-generated NLS classes.
I've tested it with the 5.5 version of eclipse-cs by patching the jar file for the plugin and it works quite well.