I would like to make it so that I can Run a PMD check as an external tool from withing intellij 14.x
The only documentation I can find is old and outdated based on pmd 4.x. How do I get it working correctly? Is anyone out there using PMD as an external Tool? I tried downloading the built in PMD plugin but when I pointed it to my custom_pmd_ruleset.xml it ignored it entirely --> perhaps the plugin is broken.
The command line parser has changed in PMD 5.0.1, but the documentation was never updated unfortunately. These are the changes:
args[0] is now -dir
args[1] is now -format
args[2] is now -rulesets
When you -format ideaj, it also needs three more arguments. Those report format specific arguments are now specified with -property {name}={value}:
args[3] is now -property sourcePath
args[4] is now -property classAndMethodName
args[5] is now -property singleFileName
The example command line given in the PMD 4 documentation used parameters:
"$FilePath$" # args[0]
ideaj # args[1]
unusedcode,imports # args[2]
"$Sourcepath$" # args[3]
$FileClass$.method # args[4]
$FileName$ # args[5]
Notice that the 4th argument was actually wrong in the documentation, $FileClass.method should be $FileClass$.method.
So in PMD 5, this is:
pmd \
-dir "$FilePath$" \
-format ideaj \
-rulesets "unusedcode,imports" \
-property sourcePath="$Sourcepath$" \
-property classAndMethodName="$FileClass$.method" \
-property singleFileName="$FileName$
You can configure IntelliJ like this:
File > Settings
Tools > External Tools
Add a new external tool:
Name: PMD (or anything you like)
Description: PMD source code analyzer (or anything you like)
Options: Synchronize files after execution; Open console
Show in: Main menu; Editor menu; Project views; Search results
Program: path/to/pmd-bin-5.8.1/bin/run.sh
Parameters: pmd -dir "$FilePath$" -format ideaj -rulesets "unusedcode,imports" -property sourcePath="$Sourcepath$" -property classAndMethodName="$FileClass$.method" -property singleFileName="$FileName$
Working Directory: $ProjectFileDir$
After a fair bit of research, here's what worked for me:
And here's the classpath part that's super long and cut off in the image:
-cp "C:\Users\nate\.m2\repository\commons-io\commons-io\2.4\commons-io-2.4.jar;C:\Users\nate\.m2\repository\org\apache\commons\commons-lang3\3.3.2\commons-lang3-3.3.2.jar;C:\Users\nate\.m2\repository\net\sourceforge\pmd\pmd-core\5.3.2\pmd-core-5.3.2.jar;C:\Users\nate\.m2\repository\net\sourceforge\pmd\pmd-java\5.3.2\pmd-java-5.3.2.jar;C:\Users\nate\.m2\repository\asm\asm\3.1\asm-3.1.jar;C:\Users\nate\.m2\repository\jaxen\jaxen\1.1.1\jaxen-1.1.1.jar;C:\Users\nate\.m2\repository\com\beust\jcommander\1.48\jcommander-1.48.jar" net.sourceforge.pmd.PMD -R "$ModuleFileDir$\src\test\resources\custom-pmd-rules.xml" -d "$FileDirRelativeToProjectRoot$/$FileName$"
Hopefully that saves someone some time getting it working. Enjoy.
Related
I have been using Github actions to build and publish a docker image to the Github Container Registry according to the Documentation. I am getting an inconsistency behavior when I pull the new image and test it locally.
I have a CMake project in C++ that runs a simple hello world with an INTERFACE and SHARED library.
When I build a docker image locally and test it, this is the output (which is working fine):
*************************************
*** DBSCAN Cluster Segmentation ***
*************************************
--cloudfile: required.
Usage: program [options]
Optional arguments:
-h --help shows help message and exits [default: false]
-v --version prints version information and exits [default: false]
--cloudfile input cloud file [required]
--octree-res octree resolution [default: 120]
--eps epsilon value [default: 40]
--minPtsAux minimum auxiliar points [default: 5]
--minPts minimum points [default: 5]
-o --output-dir output dir to save clusters [default: "-"]
--ext cluster output extension [pcd, ply, txt, xyz] [default: "pcd"]
-d --display display clusters in the pcl visualizer [default: false]
--cal-eps calculate the value of epsilon with the distance to the nearest n points [default: false]
In Github Actions I am using this workflow:
name: Demo Push
on:
push:
# Publish `master` as Docker `latest` image.
branches: ["test-github-packages"]
# Publish `v1.2.3` tags as releases.
tags:
- v*
# Run tests for any PRs.
pull_request:
env:
IMAGE_NAME: dbscan-octrees
jobs:
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
push:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout#v3
with:
submodules: recursive
- name: Build image
run: docker build --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" .
- name: Test image
run: |
docker run --rm \
--env="DISPLAY" \
--env="QT_X11_NO_MITSHM=1" \
--volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
dbscan-octrees:latest
- name: Log in to registry
# This is where you will update the PAT to GITHUB_TOKEN
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
- name: Push image
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:latest
docker push $IMAGE_ID:latest
The compilation and test steps are working fine with no errors (check this run). The problem is with the newly generated image after the push to the Github Container registry since when I pulled it locally to test it, the program is crashing with an "Illegal Instruction (core dumped)" error. I have tried to debug to find the problem and there is not a compilation error, link error, or something like that. I found out that this might be related to the linking part of the SHARED library, but it is strange because if the image is working when is built in the Github Action runner, I don't understand why fails the pushed image.
I found this post where the error might be something related to Github that changes the container during the installation.
Hope someone can help me with this.
This is the output in the Test image step on the workflow:
workflow
This is the error after pulling the newly generated image and testing it locally: error
I have even compared the bad binary file (Github version in the docker image) with the good version (Compiled version locally) using ghex, and the binary file generated by GitHub after pushing a new image is a little bigger than the good one.
binary comparision
binary sizes
Issue
CPU AVX instruction set not supported by local PC
Solution
Enable compilation flags in CMake to disable AVX support
Description
After digging using analysis tools for binaries files, debugging, etc. I discovered that the problem was related to the AVX CPU support in the GitHub action runner. My Computer does not support AVX optimized instructions, so I have to enable a compilation flag for my shared libraries in order to disable AVX support. This compilation flag will tell the Github Action runner to compile the project with no AVX CPU support or CPU optimizations which is the standard environment in GitHub Actions.
Analysis tools:
ldd binary
strace binary <-- this one allows me to identify the SIGEV_SIGNAL error code
container-diff
log error
Using the strace tool I got the next error:
--- SIGILL {si_signo=SIGILL, si_code=ILL_ILLOPN, si_addr=0x55dcd7324bc0} ---
+++ killed by SIGILL (core dumped) +++
Illegal instruction (core dumped)
This error allowed me to find the error code and after searching on the internet I found a solution to my specific problem since my project was using Point cloud Library (PCL), I compiled my project with -mno-avx, according to this post.
Solution
In the CMakeList.txt file for each SHARED library define the next compilation flag:
target_compile_options(${PROJECT_NAME} PUBLIC -mno-avx)
New issue
I have resolved the major issue, but now one of my shared libraries has the same error. I will try to fix it with one of these (I think) flags.
After making a lot of tests and using CPU-X software and detecting the proper architecture-specific options in my PC with the following command via GCC:
gcc -march=native -E -v - </dev/null 2>&1 | grep cc1
output:
/usr/lib/gcc/x86_64-linux-gnu/9/cc1 -E -quiet -v -imultiarch
x86_64-linux-gnu - -march=haswell -mmmx -mno-3dnow -msse -msse2
-msse3 -mssse3 -mno-sse4a -mcx16 -msahf -mmovbe -mno-aes -mno-sha
-mpclmul -mpopcnt -mabm -mno-lwp -mno-fma -mno-fma4 -mno-xop
-mno-bmi -mno-sgx -mno-bmi2 -mno-pconfig -mno-wbnoinvd -mno-tbm
-mno-avx -mno-avx2 -msse4.2 -msse4.1 -mlzcnt -mno-rtm -mno-hle
-mrdrnd -mno-f16c -mfsgsbase -mno-rdseed -mno-prfchw -mno-adx
-mfxsr -mno-xsave -mno-xsaveopt -mno-avx512f -mno-avx512er
-mno-avx512cd -mno-avx512pf -mno-prefetchwt1 -mno-clflushopt
-mno-xsavec -mno-xsaves -mno-avx512dq -mno-avx512bw -mno-avx512vl
-mno-avx512ifma -mno-avx512vbmi -mno-avx5124fmaps
-mno-avx5124vnniw -mno-clwb -mno-mwaitx -mno-clzero -mno-pku
-mno-rdpid -mno-gfni -mno-shstk -mno-avx512vbmi2 -mno-avx512vnni
-mno-vaes -mno-vpclmulqdq -mno-avx512bitalg -mno-avx512vpopcntdq
-mno-movdiri -mno-movdir64b -mno-waitpkg -mno-cldemote
-mno-ptwrite --param l1-cache-size=32
--param l1-cache-line-size=64 --param l2-cache-size=3072
-mtune=haswell -fasynchronous-unwind-tables
-fstack-protector-strong -Wformat -Wformat-security
-fstack-clash-protection -fcf-protection
Final solution
I have fixed the execution error with the following flags in my SHARED library:
# MMX, SSE(1, 2, 3, 3S, 4.1, 4.2), CLMUL, RdRand, VT-x, x86-64
target_compile_options(${PROJECT_NAME} PRIVATE -Wno-cpp
-mmmx
-msse
-msse2
-msse3
-mssse3
-msse4.2
-msse4.1
-mno-sse4a
-mno-avx
-mno-avx2
-mno-fma
-mno-fma4
-mno-f16c
-mno-xop
-mno-bmi
-mno-bmi2
-mrdrnd
-mno-3dnow
-mlzcnt
-mfsgsbase
-mpclmul
)
Now, the docker image stored in the GitHub Container Registry is working as expected on my local PC.
Related posts
What is the proper architecture-specific options (-m) for Sandy Bridge based Pentium?
using cmake to make a library without sse support (windows version)
https://github.com/PointCloudLibrary/pcl/issues/5248
Compile errors with Assembler messages
https://github.com/PointCloudLibrary/pcl/issues/1837
I am completely new to Kotlin, and I am trying to run the Kotlin REPL.
Following this, and considering I am using OS X, and I have tried this:
$ /usr/local/bin/kotlinc-jvm
which is equivalent to:
$ kotlinc-jvm
Then in the following link, I found that a nicer way to run it is:
$ kotlinc
Is there any differences between this two commands, and which one should I choose?
If you look inside the kotlinc-jvm files, they actually just launch the kotlinc that's in the same folder they are in, and pass any arguments they were started with to it:
kotlinc-jvm for Unix:
#!/usr/bin/env bash
# (License here)
DIR="${BASH_SOURCE[0]%/*}"
: ${DIR:="."}
"${DIR}"/kotlinc "$#"
kotlinc-jvm.bat for Windows:
#echo off
rem (License here)
call %~dps0kotlinc.bat %*
I'm not sure why kotlinc-jvm is there in this form, it's basically just a very simple redirect. I'd just use kotlinc.
I git clone souce code from code.google.com
when i set guava-tests module benchmark as maven source root ,but it's also error
how to solve it?
see the picture
follow Frank advice I change to bechmark maked as a "Test Source Root"
but the Idea dislplay can't resolve symbol BeforeExperiment,but my .m2/repository
has the jar .see the first screenshot.
when i exec ,the result is below ,it is empty.
caliper jar tf 1.0-beta-1/caliper-1.0-beta-1.jar|grep -E com.google.caliper.BeforeExperiment |sort
caliper jar tf 0.5-rc1/caliper-0.5-rc1.jar|grep -E com.google.caliper.BeforeExperiment |sort
caliper jar tf 1.0-beta-1/caliper-1.0-beta-1.jar|grep -E com.google.caliper.BeforeExperiment |sort
The guava-tests/benchmark directory is currently not set as a source root in the Maven configuration because it won't build. That said, we just need to push a new version of Caliper to Maven Central that includes the new annotations and such, and I think that should be happening sometime soon.
No publicly available version of Caliper contains the com.google.caliper.BeforeExperiment class.
You can compare the result of the following class searches on search.maven.org for yourself:
com.google.caliper.BeforeExperiment
com.google.caliper.Benchmark
You can also check what's in your jar:
$ jar tf ~/.m2/repository/com/google/caliper/caliper/0.5-rc1/caliper-0.5-rc1.jar | \
grep -E com.google.caliper.B | sort
com/google/caliper/Benchmark.class
$
Or using the most recent "release" of Caliper:
$ jar tf caliper-1.0-beta-1.jar | grep -E com.google.caliper.B | sort
com/google/caliper/Benchmark.class
$
I was looking for an example on how to config OCLint or how to get it running. I made a search but nothing. Here at Stack Overflow there are just 3 posts related, just naming the library and on google just the official OCLint.org
The oficial docs says:
[user#localhost ~]$ oclint -help
OVERVIEW: OCLint, a static code analysis tool for Objective-C and related languages
USAGE: oclint [options] <input files>
OPTIONS:
-D <macro> - Predefine the specified macro
-F <directory> - Add directory to framework include search path
-I <directory> - Add directory to include search path
-R <directory> - Add directory to rule loading path
-arch <arch_name> - Specify which architecture (e.g. ppc, i386, x86_64, armv7) the compilation
should targets.
-help - Display available options (-help-hidden for more)
-include <file> - Include file before parsing
-isysroot <directory> - Add directory to SYSTEM include search path
-o <file> - Write output to <file>
-rc <paramemter>=<value> - Change the baheviour of rules
-stats - Enable statistics output from program
Choose report type:
-text - Plain text report
-html - HTML formatted report
-version - Display the version of this program
-x <value> - Input language type
But I would like a better explanation about macro (-D), and which path to choose for -I, -F, -R and what should I point at. A code example as
$ oclint path/to/file.m -D something -I something -F something -R something
And the output expected from that would be great.
Basically you just give oclint whatever you give to your compiler.
Alternatively, you may want to try oclint-xcodebuild if you are not familiar with compiler flags. This is a Python script that extracts flags from your Xcode build log file. See the usage here.
Is there any plugin for task management ( bug tracking, issues) to use with xcode? Or there's any plugin api that one can create plugins for it?
There really isnt anything that I know of that is as good as mylyn to intergrate with bugzilla or trac. If you found anything, please let me know!
The best way I know of to document issues or things is to put a //TODO: or //FIXME: in your code. Then when Xcode compiles you can run a local shell script to post warnings for you
Its here: (Targets --> --> BUILD PHASES --> Run Scripts (See Screenshot)
Put this script at the end of your Build Phases :
KEYWORDS="FIXME|TODO:|FIXME:|\?\?\?:|\!\!\!:"
find ${SRCROOT} \( -name "*.h" -or -name "*.m" \) -print0 | \
xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | \
perl -p -e "s/($KEYWORDS)/ warning: \$1/"
Lastly there is the infamous
#pragma mark YOURTEXTHERE
Good Luck!
Here is a wishlist of things people want: https://stackoverflow.com/questions/2025605/wishlist-for-objective-c-ide-xcode
Screenshot:
I've been using the Run Script build phase for a while now and modified it so the generated build warnings directly link to the file and line where the keyword has been found.
The solution is just to print a line which matches the ones Xcode knows how to parse:
{filename}:{line}:{character}: warning: {The content of the warning}.
So the script looks like that:
KEYWORDS="FIXME|TODO:|FIXME:|\?\?\?:|\!\!\!:\#todo\#warning"
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" \) -exec egrep -Hno "($KEYWORDS).*\$" {} \; | \
sed -e 's/^\([^:]\{1,\}\):\([0-9]\{1,\}\):\(.*\)$/\1:\2:1: warning: \3/'
Note that I also included #todo and #warning in the keywords as I often use javadoc/doxygen comments.
Bertrand
I made a Xcode plugin for this --> http://github.com/trawor/XToDo