Skip to content

Commit

Permalink
Merge branch 'adangel-support-pmd7'
Browse files Browse the repository at this point in the history
  • Loading branch information
ChuckJonas committed Aug 24, 2023
2 parents 036a08b + 30851c8 commit bc306a3
Show file tree
Hide file tree
Showing 68 changed files with 7,083 additions and 3,378 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to the VS Code Apex PMD will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.6.0]
### Change
- Upgraded to PMD7!
- WARNING: PMD6 is no longer supported via `pmdBinPath` setting. If you receive an error, please clear this setting!

## [0.5.9]
### Change
- added ability to run on `xml` files
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Allows you to run [Apex Static Analysis](https://pmd.github.io/latest/index.html
- `priorityErrorThreshold`: Determines at what priority level 'errors' will be added. Anything less will be a warning or hint
- `priorityWarnThreshold`: Determines at what priority level 'warnings' will be added. Anything less will be a hint
- `enableCache`: Creates a cache file for PMD to run faster. Will create a .pmdCache file in your workspace
- `pmdBinPath` (prev. `pmdPath`) (optional): set to override the default pmd binaries. This should point to the PMD folder which contains folders `lib` and `bin`. Most likely it is called `libexec`.
- `pmdBinPath` (prev. `pmdPath`) (optional): set to override the default pmd binaries. This should point to the PMD folder which contains folders `lib` and `bin`. Most likely it is called `libexec`. **WARNING: Since `v0.6.0`, this extension no longer supports PMD 6x. If you receive an error, please clear this setting!**
- `additionalClassPaths` (optional): set of paths to be appended to classpath. Used to find jar files containing custom rule definitions. Can be absolute or relative to workspace.
- `commandBufferSize` Size of buffer used to collect PMD command output (MB), may need to be increased for very large projects
- `jrePath` (Optional) Path to JRE (Folder that contains which contains `bin/java`)
Expand Down Expand Up @@ -62,7 +62,7 @@ If you want to use your own [custom rules](https://pmd.github.io/latest/pmd_user

1. `git clone`
1. `npm install`
1. debug -> "launch extension"
1. debug -> `run extension`

### Upgrading PMD

Expand Down
6 changes: 0 additions & 6 deletions bin/pmd/bin/ast-dump.bat

This file was deleted.

6 changes: 0 additions & 6 deletions bin/pmd/bin/bgastviewer.bat

This file was deleted.

6 changes: 0 additions & 6 deletions bin/pmd/bin/cpd.bat

This file was deleted.

6 changes: 0 additions & 6 deletions bin/pmd/bin/cpdgui.bat

This file was deleted.

51 changes: 0 additions & 51 deletions bin/pmd/bin/designer.bat

This file was deleted.

6 changes: 0 additions & 6 deletions bin/pmd/bin/designerold.bat

This file was deleted.

111 changes: 51 additions & 60 deletions bin/pmd/bin/run.sh → bin/pmd/bin/pmd
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
#!/bin/bash

usage() {
echo "Usage:"
echo " $(basename $0) <application-name> [-h|-v] ..."
echo ""
echo "application-name: valid options are: $(valid_app_options)"
echo "-h print this help"
echo "-v display PMD's version"
}

valid_app_options () {
echo "pmd, cpd, cpdgui, designer, bgastviewer, designerold, ast-dump"
}

is_cygwin() {
case "$(uname)" in
CYGWIN*|MINGW*)
Expand Down Expand Up @@ -60,19 +47,18 @@ java_heapsize_settings() {


set_lib_dir() {
if [ -z ${LIB_DIR} ]; then
if [ -z "${LIB_DIR}" ]; then
# Allow for symlinks to this script
if [ -L $0 ]; then
if [ -L "$0" ]; then
local script_real_loc=$(readlink "$0")
else
local script_real_loc=$0
fi
local script_dir=$(dirname "${script_real_loc}")
local cwd="${PWD}"

cd "${script_dir}/../lib"
pushd "${script_dir}/../lib" >/dev/null
readonly LIB_DIR=$(pwd -P)
cd "${cwd}"
popd >/dev/null
fi
}

Expand All @@ -82,24 +68,55 @@ check_lib_dir() {
fi
}

set_conf_dir() {
if [ -z ${CONF_DIR} ]; then
# Allow for symlinks to this script
if [ -L $0 ]; then
local script_real_loc=$(readlink "$0")
else
local script_real_loc=$0
fi
local script_dir=$(dirname "${script_real_loc}")

pushd "${script_dir}/../conf" >/dev/null
readonly CONF_DIR=$(pwd -P)
popd >/dev/null
fi
}

check_conf_dir() {
if [ ! -e "${CONF_DIR}" ]; then
echo "The configuration directory [${CONF_DIR}] does not exist"
fi
}

function script_exit() {
echo $1 >&2
echo "$1" >&2
exit 1
}

function check_java() {
java -version >/dev/null 2>&1
if [ $? -ne 0 ]; then
script_exit "No java executable found in PATH"
fi
}

determine_java_version() {
local full_ver=$(java -version 2>&1)
# java_ver is eg "18" for java 1.8, "90" for java 9.0, "100" for java 10.0.x
readonly java_ver=$(echo $full_ver | sed -n '{
# java_ver is eg "80" for java 1.8, "90" for java 9.0, "100" for java 10.0.x
readonly java_ver=$(echo "$full_ver" | sed -n '{
# replace early access versions, e.g. 11-ea with 11.0.0
s/-ea/.0.0/
# replace versions such as 10 with 10.0.0
s/version "\([0-9]\{1,\}\)"/version "\1.0.0"/
# replace old java versions 1.x.* (java 1.7, java 1.8) with x.*
s/version "1\.\(.*\)"/version "\1"/
# extract the major and minor parts of the version
s/^.* version "\(.*\)\.\(.*\)\..*".*$/\1\2/p
s/^.* version "\([0-9]\{1,\}\)\.\([0-9]\{1,\}\).*".*$/\1\2/p
}')
# java_vendor is either java (oracle) or openjdk
readonly java_vendor=$(echo $full_ver | sed -n -e 's/^\(.*\) version .*$/\1/p')
readonly java_vendor=$(echo "$full_ver" | sed -n -e 's/^\(.*\) version .*$/\1/p')
}

jre_specific_vm_options() {
Expand Down Expand Up @@ -138,9 +155,9 @@ jre_specific_vm_options() {

function add_pmd_classpath() {
if [ -n "$classpath" ]; then
classpath="$classpath:${LIB_DIR}/*"
classpath="$classpath:${CONF_DIR}:${LIB_DIR}/*"
else
classpath="${LIB_DIR}/*"
classpath="${CONF_DIR}:${LIB_DIR}/*"
fi
}

Expand All @@ -157,54 +174,28 @@ function add_openjfx_classpath() {
then
script_exit "The environment variable JAVAFX_HOME is missing."
else
# The wildcard will include only jar files, but we need to access also
# property files such as javafx.properties that lay bare in the dir
if [ -n "$classpath" ]; then
classpath="$classpath:${JAVAFX_HOME}/lib/*"
classpath="$classpath:${JAVAFX_HOME}/lib/*:${JAVAFX_HOME}/lib/"
else
classpath="${JAVAFX_HOME}/lib/*"
classpath="${JAVAFX_HOME}/lib/*:${JAVAFX_HOME}/lib/"
fi
fi
fi
fi
}

readonly APPNAME="${1}"
if [ -z "${APPNAME}" ]; then
usage
exit 1
fi
shift

case "${APPNAME}" in
"pmd")
readonly CLASSNAME="net.sourceforge.pmd.PMD"
;;
"cpd")
readonly CLASSNAME="net.sourceforge.pmd.cpd.CPD"
;;
"designer")
readonly CLASSNAME="net.sourceforge.pmd.util.fxdesigner.DesignerStarter"
;;
"designerold")
readonly CLASSNAME="net.sourceforge.pmd.util.designer.Designer"
;;
"bgastviewer")
readonly CLASSNAME="net.sourceforge.pmd.util.viewer.Viewer"
;;
"cpdgui")
readonly CLASSNAME="net.sourceforge.pmd.cpd.GUI"
;;
"ast-dump")
readonly CLASSNAME="net.sourceforge.pmd.util.treeexport.TreeExportCli"
;;
*)
echo "${APPNAME} is NOT a valid application name, valid options are:$(valid_app_options)"
;;
esac

is_cygwin

check_java

set_lib_dir
check_lib_dir
set_conf_dir
check_conf_dir

convert_cygwin_vars

Expand All @@ -218,4 +209,4 @@ cygwin_paths

java_heapsize_settings

java ${HEAPSIZE} ${PMD_JAVA_OPTS} $(jre_specific_vm_options) -cp "${classpath}" "${CLASSNAME}" "$@"
java ${HEAPSIZE} ${PMD_JAVA_OPTS} $(jre_specific_vm_options) -cp "${classpath}" net.sourceforge.pmd.cli.PmdCli "$@"
77 changes: 75 additions & 2 deletions bin/pmd/bin/pmd.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,79 @@
@echo off
rem make all variables local to not add new global environment variables to the current cmd session
setlocal
set TOPDIR="%~dp0.."
set OPTS=
set MAIN_CLASS=net.sourceforge.pmd.PMD
set COMMAND=%1
set MAIN_CLASS=net.sourceforge.pmd.cli.PmdCli

java %PMD_JAVA_OPTS% -classpath %TOPDIR%\lib\* %OPTS% %MAIN_CLASS% %*
rem check whether java is available at all
java -version > nul 2>&1 || (
echo No java executable found in PATH
exit /b 1
)

rem sets the jver variable to the java version, eg 90 for 9.0.1+x or 80 for 1.8.0_171-b11 or 110 for 11.0.6.1
rem sets the jvendor variable to either java (oracle) or openjdk
for /f tokens^=1^,3^,4^,5^ delims^=.-_+^"^ %%j in ('java -version 2^>^&1 ^| findstr /c:"version"') do (
set jvendor=%%j
if %%l EQU ea (
set /A "jver=%%k0"
) else (
if %%k EQU 1 (
rem for java version 1.7.x, 1.8.x, ignore the first 1.
set /A "jver=%%l%%m"
) else (
set /A "jver=%%k%%l"
)
)
)

Set "jreopts="
rem oracle java 9 and 10 has javafx included as a module
if /I %jvendor% == java (
if %jver% GEQ 90 (
if %jver% LSS 110 (
rem enable reflection
SETLOCAL EnableDelayedExpansion
rem java9 and java10 from oracle contain javafx as a module
rem open internal module of javafx to reflection (for our TreeViewWrapper)
set "jreopts=--add-opens javafx.controls/javafx.scene.control.skin=ALL-UNNAMED"
rem The rest here is for RichtextFX
set "jreopts=!jreopts! --add-opens javafx.graphics/javafx.scene.text=ALL-UNNAMED"
set "jreopts=!jreopts! --add-opens javafx.graphics/com.sun.javafx.scene.text=ALL-UNNAMED"
set "jreopts=!jreopts! --add-opens javafx.graphics/com.sun.javafx.text=ALL-UNNAMED"
set "jreopts=!jreopts! --add-opens javafx.graphics/com.sun.javafx.geom=ALL-UNNAMED"
rem Warn of remaining illegal accesses
set "jreopts=!jreopts! --illegal-access=warn"
)
)
)

set "_needjfxlib=0"
if [%COMMAND%] == [designer] (
if /I %jvendor% == openjdk set _needjfxlib=1
if /I %jvendor% == java (
if %jver% GEQ 110 set _needjfxlib=1
)
)
if %_needjfxlib% EQU 1 (
if %jver% LSS 100 (
echo For openjfx at least java 10 is required.
exit /b 1
)
if not defined JAVAFX_HOME (
echo The environment variable JAVAFX_HOME is missing.
exit /b 1
)
rem The wildcard will include only jar files, but we need to access also
rem property files such as javafx.properties that lay bare in the dir
set pmd_classpath=%TOPDIR%\conf;%TOPDIR%\lib\*;%JAVAFX_HOME%\lib\*;%JAVAFX_HOME%\lib\
) else (
set pmd_classpath=%TOPDIR%\conf;%TOPDIR%\lib\*
)

if defined CLASSPATH (
set pmd_classpath=%CLASSPATH%;%pmd_classpath%
)

java %PMD_JAVA_OPTS% %jreopts% -classpath %pmd_classpath% %OPTS% %MAIN_CLASS% %*
Loading

0 comments on commit bc306a3

Please sign in to comment.