PMD command running multiple rules at once from Shell - java

I'm trying out PMD on some Java source code.
I understand from the Terminal window on my Mac (Unix shell), the syntax is like so:
pmd.sh html|xml|text|vbhtml rulesetfile1[,rulesetfile2[,..]]
But the question is, what are the names rulesetfile1, 2 ... n...
I mean I've seen this list on the website:
http://pmd.sourceforge.net/rules/index.html
But how does this correlate to the comma separated list I can supply from running the shell command?
Can someone point me to a cross-reference so I can correlate the two?
Cheers.

This should be available in the ruleset folder of pmd installation. Here is the link to the folder in PMD's source repository.

Related

Error while loading shared libraries: libjli.so in Java

I have ElementaryOS installed. I am running Processing IDE in the terminal by running ./processing in the processing-3.3.4 directory. I'm getting this error:
java: error while loading shared libraries: libjli.so: cannot open shared object file: No such file or directory
This is a known issue that is being worked on. As of this moment, it doesn't look like they have released a fix, so I would try the previous version.
In the future, I recommend searching with Google for the specific error you're getting before posting to a forum. It can be hard to know what to search for, so here's an explanation of my process.
First I tried searching for "elementary os" processing cannot open shared object file "libjli.so" but since that didn't give me anything obvious, I assumed that this is not a widespread problem with Elementary OS. Note that I put quotes around "elementary os" and "libjli.so". This ensures that Google treats these as phrases, so pages with the word "elementary" and the word "os" will not match unless those two words are side-by-side.
Next I searched for processing ide cannot open shared object file "libjli.so" which gave me a link to the main Issues page on the github project. On that page, I searched for libjli.so which gave me one result, which is the issue I linked here.
I hope that helps you in the future.
Download Java SE Development Kit 8u192 in your home directory (click "Accept License Agreement")
Extract (in terminal):
tar xzvf ~/jdk-8u192-linux-x64.tar.gz
Create the symbolic links:
sudo ln -s -f ~/jdk1.8.0_192/bin/* /usr/bin/
Test:
java -version

Display JavaDocs on GitHub

I'm looking for a way to convert the javadocs from my open source project (generated in Eclipse) to GitHub MarkDown, or come up with some other simple solution to display my documentation on GitHub (shy of simply adding a docs directory). Is there a simple solution for this? Can I simply point the GitHub README.md to my docs directory? Is there something more elegant? I have been striking out on Google.
I don't think it's possible to make a usable Javadoc with MarkDown. The best solution is probably to commit the Javadoc you generated on the gh-pages branch (or in the docs/ directory depending on the settings of your project). It will be available at :
http://username.github.io/projectname
Here is an example from one of my projects:
http://ebourg.github.io/jsign/apidocs/
Currently you can also host your Javadoc with Github Pages from not only a gh-pages branch, but directly from the /docs folder within your master branch. You can check the help section on this topic, here (also check attached image below).
Also, there's a project on Github that targets some conversion of Javadoc to Markdown (have not tried it yet, just leaving the reference).
Do NOT check Javadocs into the source control for your project
Especially not into the master branch! I followed the other answers to this question for about a year before deciding it was a really bad idea. Why?
It made it too difficult to review diffs. I even made a script (see below) to update only the Javadoc pages that substantially changed, but it still was a mess.
It fooled IntelliJ's refactoring tools. I just tried to change .x() to .getX() and had to approve/reject every "x" in the Javadocs. Maybe I forgot to exclude the folder in IntelliJ, but if you ever use sed/grep/find on your project, you have to remember to exclude it every time.
It adds a bunch of data in git that just shouldn't be there, potentially making pull and clone commands take longer... FOREVER! Even if you later "remove" the folder, it's still stored in git.
Where should javadocs go?
It's probably best to post them on https://javadoc.io/, your web site, or AWS or heroku. If you must check javadoc into source control, make a separate project just for Javadocs so you'll never need to look at the diff. You can follow other people's answers for how to do this.
"I read your post, but I'm doing it anyway"
Here's my script to update fewer javadocs. It only copies files with substantial changes from the target/apidocs folder to the docs/apidocs folder. It also adds new files and deletes no longer used ones. I think I used poor names, newfile and oldfile, but it works. I mean, it wasn't enough to justify checking javadoc into my project's source control, but it helps.
#!/usr/bin/env bash
# -I means ignore lines matching a regular expression
# -q means "quiet" - only tell whether files differ or not
# -r means "recursive" - explore subdirectories
# -N means "treat absent files as empty" which makes absent files show up in Quiet mode.
diff -I '<!-- Generated by javadoc ' \
-I '<meta name="date" content="' \
-I '<title>' \
-I 'parent.document.title=' \
-N \
-qr \
docs/apidocs/ target/apidocs/ > target/javadocPatch.txt
# Now read in the output file created by the previous command and
# Update only files that have substantial changes.
while read ignore1 oldfile ignore2 newfile ignore3
do
if [ ! -f "$oldfile" ]
then
echo "Added $oldfile"
echo -n >$oldfile
cp -fu $newfile $oldfile
elif [ ! -f "$newfile" ]
then
echo "Deleted $newfile"
rm $newfile
else
echo "cp -fu $newfile $oldfile"
cp -fu $newfile $oldfile
fi
done < "target/javadocPatch.txt"
It might be a bit off topic but I believe what OP is looking for is a mechanism to automatically make javadoc available as a new version of the project is published.
If this is the case, then you can try: http://javadoc.io
It's a free service hosting javadocs for open source project, currently supporting maven central and bintray (jcenter).
You can generate a link to the latest version of your project. For example, this link https://javadoc.io/doc/org.springframework/spring-core always point to the latest version of spring-core, which is 5.2.0.RELEASE at the time I write this answer.
Declaimer: I run javadoc.io

Testing ANTLR Grammar

So I've been making a grammar in Eclipse with ANTLR v3.4 and I've made one that works and I want to make sure when I edit it everything still works. I can go into the interpretter everytime but that seems like a huge waste of time.
Questions:
I've read about gunit but the link it gives to download gUnit:
( http://antlr.org/hudson/job/gUnit/org.antlr$gunit/lastSuccessfulBuild/ ) doesn't work. How can I get gUnit.
What is the best way to test grammars? Is it actually gUnit or should I just do java tests like jUnit tests?
The question is old, but I'm leaving a reference for completeness:
For me, the gUnit was useless. So I managed to find how test only the Lexer and then, only the parser.
I answered it here: https://stackoverflow.com/a/53884851/976948
Basically, there are links for 2 articles about how to test it:
Unit test for Lexer
Unit test for Parser
I recently completed two ANTLR3 assignments (I'm working on my Master's in Computer Science) using Eclipse. I found no single document that had a process for installing, configuring, writing, and debugging a grammar in Eclipse. So, after working through various issues, I found the easiest thing to do was to stay in Eclipse for testing.
To use the process I have come to use (outlined below) you must first have the ANTLR IDE v2.1.2 installed. Add it right from inside Eclipse Indigo: http://antlrv3ide.sourceforge.net/updates. This site also has some useful doc on using the ANTLR IDE. Once installed, the IDE has to be configured. Video tutorials are a bit out of date but helpful. See a detailed how to guide on configuring ANTLR IDE in Eclipse. The main configuration item is the java output folder. Do this in Eclipse by going to Windows, Preferences, ANTLR, Code Generator, check Project relative folder and in the Output folder name box type a folder name (mine is called "antlr-java", others use "generated").
Test/Debug Process for ANTLR in Eclipse Indigo with ANTLR IDE
After a new project is created, right-click it, select Configure, Convert to
ANTLR Project...
Create the grammar in a .g file and save it. Note: filename has to match grammar name.
If there are significant errors, debug the grammar. Eclipse shows the ANTLR error(s)
and what line(s) are affected. At first, these errors seem hard to understand but
they can be worked through by using various resources:
- The Definitive ANTLR Reference by Terence Parr the guy who wrote ANTLR
- the ANTLR Reference Manual
- google the error; many times you will end up here at stackoverflow;
in particular, Bart Kiers is both knowledgeable and helpful (Bart: thx for
the help you didn't know you gave me)
On the first save after the serious ANTLR errors are resolved, the java output folder you
configured in Eclipse will be created and a java file in that folder will also be created.
Right-click on the java output folder, select Build Path, Use As a Source Folder. This
tells Eclipse where to look for the project's java source.
There are likely to be errors in the new java file. Select it, then search through looking
for java errors. Go back to your grammar or java file(s), correct the errors, and re-save
the grammar until both grammar and java files are error free, then run it.
From this point on, it's the usual modify-run-debug cycle.
The only other Eclipse change I needed was to create a few Run Configurations for testing
command line parameters.
You can download gUnit there but I think there is no latest version...
Try Jarvana... Latest version there is 3.4: http://repo1.maven.org/maven2/org/antlr/gunit/3.4/gunit-3.4.jar
#Dave Newton is right. As of ANTLR v3.1, gUnit is included in the main ANTLR Tool jar as is stated there.
I didn't know for gUnit till now. It looks great for grammar testing, but I think that JUnit tests will do their job to...
This is the first time I heard of gUinit and read up on it. (I don't use ANTLR much.) It sounds interesting, but half useless.
My approach to validating grammars is to actually validate the the entire parser with "normal" unit tests. The thing is, you should have unit tests in place anyway and the tests that check for grammar regression you just add it there. The thing is in my experience that most errors come in semantic analysis and reduction and not the grammar.

How can I set VM options in a Java Netbeans Platform Modular Project?

I have a Netbeans Platform modular project, not a regular Java project. I want to set VM options to increase memory, but under the "properties" dialog, there is no way to do this for a modular Netbeans platform project. This has cost me huge amounts of time and I still have not found a good way to set the VM args.
Does anyone know how to set VM args using a Netbeans platform modular project, when compiling and running the program in Netbeans 7? Given the amount of trouble, I am almost ready to give up on Netbeans to create modular applications.
It is quite easy, in fact. Just modify project.properties file to include the following line:
Edited:
run.args.extra=-J-Xmx768m
Of course, you can include any other JVM options there.
Enjoy.
I was finally able to solve this based on information at https://web.archive.org/web/20130830023832/http://activeintelligence.org/blog/archive/gephi-increasing-xmx-memory-in-netbeans/
What I did was modify the project.properties file, as JB said, but the correct way to do it was to add a -J before the args. E.g.,
run.args.extra=-J-Xms256m -J-Xmx756m
That did it! Not sure why it took 3 months to figure that out. Definitely a fail for the Netbeans documentation. They should really make this editable from the properties menu instead of making users hunt through nondescript config files!
I thought i'll put some contribution on this topic, When I was developing a netbeans platform application i also faced the same problem, I added run.args.extra=-J-Xmx768m
and updated my project.properties file but it didn't ! But when i added run.args.extra=-J-Xmx768m in my platform.properties file then it worked, again this only works when i was in development environment. When I packeged the application for windows the problem remained same my min heap size was 24m and max is 64m. Then I found out that if I update and add default_options="--branding my_project -J-Xms64m -J-Xmx1G" in my_project.conf in my installed directory C:\Program Files\my_project\etc then run my application and checked the ide log i can now see the change. By the way i wasn't lucky enough to see even the run node when i right click and go to the project properties dialogue in netbeans 7.0.1. Its upto netbeans dream team to make us feel lucky.
I had this issue and after some digging around and reading a lot of docs I was able to deduce that most of those values were coming from templates in the harness.
So if you go to your IDE_home/harness/etc/ you will find the "app.conf" file. This file is renamed during a distro build and the "app.conf" becomes your "application name.conf". Edit this file with the default values you would like in you application.
In my case I replaced the line that read:
default_options="--branding ${branding.token} -J-Xms24m -Xmx64m"
with
default_options="--branding ${branding.token} -J-Xms64m -Xmx512m" as my application was needing more memory. By changing the template I dont have to touch every deployment and change the memory CLI for the VM.
Hope this helps!
For maven projects:
As described in this question, you can use etcConfFile parameter of nbm-maven-plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>nbm-maven-plugin</artifactId>
<configuration>
<etcConfFile>src/main/resources/app.conf</etcConfFile>
</configuration>
</plugin>
More info: Geertjan's Blog
you have to add these lines to your project properties file.
<target name="build-launchers" depends="suite.build-launchers">
<replace file="build/launcher/etc/${app.name}.conf" token="--branding graphsimulator -J-Xms24m -J-Xmx64m" value="--branding graphsimulator -J-Xms128m -J-Xmx512m"/>
</target>
If you want to use Netbeans to set the VM options without bothering about which file to edit, here we go:
Run -> Set project configuration -> VM Options
Add your option in the corresponding text box for example: -Xms10m
To answer user1156544 doubt:

Group and counting a String in Ant

I have the following problem. I have something like 300 Eclipse Plugins. Now, as part of an ant script I want to read all MANIFEST.MF files and then look for the execution environment string.
Bundle-RequiredExecutionEnvironment: J2SE-1.4
Now, this string has several possible values. I want to create a report that lists the execution environment for each plug-in. That part is not really a problem as I can use some kind of regexp to obtain it.
My problem is that I want also to create some kind of summary for tracking changes at a glance, something like:
JS2E-1.4: 50 Plugins
JS2E-1.5: 150 Plugins
JS2E-1.6: 74 Plugins
Anyone has some suggestions on how could I go around this?
EDIT: Reason for using ANT is that I want to integrate it with a nightly build script
I would definitively go for hard-coded Ant task and decompose the problem in two tasks:
the first task takes a jar file and outputs a plugin-info.xml file that contains various infos, like the environment
the second task parses all these xml files and creates an XML summary report
This will of course generate (n+1) XML files for n plugins and some will find this way too much.
The nice end effect with that approach is that you can generate either detail or aggregated reports very easily (with some XSLT magic.) or even graphs.
If i were to do it myself, i probably would just write a perl script.
If it has to be done from Ant, i would write an Ant Task to do it.
I would suggest just printing each executable environment on System.out and then post process with "|sort| uniq -c".
You can use the math task from the ant-contrib project
I had to do it, I'd probably go for some shell script or custom code

Categories