Skip to content

Commit

Permalink
Merge branch 'master' into pr-3417
Browse files Browse the repository at this point in the history
  • Loading branch information
adangel committed Jul 31, 2021
2 parents 88547fc + 7f53758 commit 9221cf0
Show file tree
Hide file tree
Showing 111 changed files with 4,879 additions and 1,614 deletions.
17 changes: 17 additions & 0 deletions .ci/build.sh
Expand Up @@ -85,6 +85,23 @@ function build() {
pmd_ci_log_group_end

if pmd_ci_maven_isSnapshotBuild; then
if [ "${PMD_CI_MAVEN_PROJECT_VERSION}" != "7.0.0-SNAPSHOT" ]; then
pmd_ci_log_group_start "Executing PMD dogfood test with ${PMD_CI_MAVEN_PROJECT_VERSION}"
./mvnw versions:set -DnewVersion=${PMD_CI_MAVEN_PROJECT_VERSION}-dogfood -DgenerateBackupPoms=false
./mvnw verify --show-version --errors --batch-mode --no-transfer-progress "${PMD_MAVEN_EXTRA_OPTS[@]}" \
-DskipTests \
-Dmaven.javadoc.skip=true \
-Dmaven.source.skip=true \
-Dcheckstyle.skip=true \
-Ppmd-dogfood \
-Dpmd.dogfood.version=${PMD_CI_MAVEN_PROJECT_VERSION}
./mvnw versions:set -DnewVersion=${PMD_CI_MAVEN_PROJECT_VERSION} -DgenerateBackupPoms=false
pmd_ci_log_group_end
else
# current maven-pmd-plugin is not compatible with PMD 7 yet.
pmd_ci_log_info "Skipping PMD dogfood test with ${PMD_CI_MAVEN_PROJECT_VERSION}"
fi

pmd_ci_log_group_start "Executing build with sonar"
# Note: Sonar also needs GITHUB_TOKEN (!)
./mvnw \
Expand Down
28 changes: 15 additions & 13 deletions .ci/inc/regression-tester.inc
Expand Up @@ -70,19 +70,21 @@ function regression_tester_uploadBaseline() {
function regression_tester_executeDanger() {
pmd_ci_log_debug "${FUNCNAME[0]}"

# Create a corresponding remote branch locally
if ! git show-ref --verify --quiet "refs/heads/${PMD_CI_BRANCH}"; then
git fetch --no-tags --depth=1 origin "+refs/heads/${PMD_CI_BRANCH}:refs/remotes/origin/${PMD_CI_BRANCH}"
git branch "${PMD_CI_BRANCH}" "origin/${PMD_CI_BRANCH}"
pmd_ci_log_debug "Created local branch ${PMD_CI_BRANCH}"
fi
# Fetch more commits of the PR for danger and regression tester
git fetch --no-tags --depth=50 origin "+$(git rev-parse HEAD^2):"
# Fetch more commits from master branch for regression tester
if [[ "${PMD_CI_BRANCH}" != "master" ]]; then
git fetch --no-tags --depth=50 origin +master:
git branch master origin/master
fi
# git clone initially only fetched with depth 2. Danger and regression tester
# need more history, so we'll fetch more here
# and create local branches as well (${PMD_CI_BRANCH} and pr-fetch)

pmd_ci_log_info "Fetching 25 commits for ${PMD_CI_BRANCH} and pull/${PMD_CI_PULL_REQUEST_NUMBER}/head"
git fetch --no-tags --depth=25 origin "${PMD_CI_BRANCH}:${PMD_CI_BRANCH}" "pull/${PMD_CI_PULL_REQUEST_NUMBER}/head:pr-fetch"

# if the PR is older, base might have advanced more than 25 commits... fetch more, up to 150
for i in $(seq 1 3); do
if [ -z "$( git merge-base "${PMD_CI_BRANCH}" "pr-fetch" )" ]; then
pmd_ci_log_info "No merge-base yet - fetching more commits... (try $i)"
git fetch --no-tags --deepen=50 origin "${PMD_CI_BRANCH}:" "pull/${PMD_CI_PULL_REQUEST_NUMBER}/head:pr-fetch"
fi
done
pmd_ci_log_info "Merge base is: $( git merge-base "${PMD_CI_BRANCH}" "pr-fetch" )"

pmd_ci_log_info "Running danger on branch ${PMD_CI_BRANCH}"
bundle exec danger --verbose
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Expand Up @@ -45,7 +45,7 @@ jobs:
run: |
echo "LANG=en_US.UTF-8" >> $GITHUB_ENV
echo "MAVEN_OPTS=-Dmaven.wagon.httpconnectionManager.ttlSeconds=180 -Dmaven.wagon.http.retryHandler.count=3 -DautoReleaseAfterClose=true -DstagingProgressTimeoutMinutes=30" >> $GITHUB_ENV
echo "PMD_CI_SCRIPTS_URL=https://raw.githubusercontent.com/pmd/build-tools/14/scripts" >> $GITHUB_ENV
echo "PMD_CI_SCRIPTS_URL=https://raw.githubusercontent.com/pmd/build-tools/15/scripts" >> $GITHUB_ENV
- name: Check Environment
shell: bash
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/git-repo-sync.yml
Expand Up @@ -21,7 +21,7 @@ jobs:
shell: bash
run: |
echo "LANG=en_US.UTF-8" >> $GITHUB_ENV
echo "PMD_CI_SCRIPTS_URL=https://raw.githubusercontent.com/pmd/build-tools/14/scripts" >> $GITHUB_ENV
echo "PMD_CI_SCRIPTS_URL=https://raw.githubusercontent.com/pmd/build-tools/15/scripts" >> $GITHUB_ENV
- name: Sync
run: .ci/git-repo-sync.sh
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/troubleshooting.yml
Expand Up @@ -33,7 +33,7 @@ jobs:
run: |
echo "LANG=en_US.UTF-8" >> $GITHUB_ENV
echo "MAVEN_OPTS=-Dmaven.wagon.httpconnectionManager.ttlSeconds=180 -Dmaven.wagon.http.retryHandler.count=3 -DstagingProgressTimeoutMinutes=30" >> $GITHUB_ENV
echo "PMD_CI_SCRIPTS_URL=https://raw.githubusercontent.com/pmd/build-tools/14/scripts" >> $GITHUB_ENV
echo "PMD_CI_SCRIPTS_URL=https://raw.githubusercontent.com/pmd/build-tools/15/scripts" >> $GITHUB_ENV
- name: Check Environment
shell: bash
run: |
Expand Down
6 changes: 3 additions & 3 deletions Gemfile.lock
@@ -1,7 +1,7 @@
GEM
remote: https://rubygems.org/
specs:
addressable (2.7.0)
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
claide (1.0.3)
claide-plugins (0.9.2)
Expand Down Expand Up @@ -34,7 +34,7 @@ GEM
fugit (1.5.0)
et-orbi (~> 1.1, >= 1.1.8)
raabro (~> 1.4)
git (1.8.1)
git (1.9.1)
rchardet (~> 1.8)
kramdown (1.17.0)
liquid (5.0.1)
Expand Down Expand Up @@ -62,7 +62,7 @@ GEM
racc (1.5.2)
rchardet (1.8.0)
rouge (3.26.0)
rufus-scheduler (3.7.0)
rufus-scheduler (3.8.0)
fugit (~> 1.1, >= 1.1.6)
safe_yaml (1.0.5)
sawyer (0.8.2)
Expand Down
34 changes: 21 additions & 13 deletions docs/Gemfile.lock
@@ -1,13 +1,13 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (6.0.3.7)
activesupport (6.0.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
zeitwerk (~> 2.2, >= 2.2.2)
addressable (2.7.0)
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
coffee-script (2.4.1)
coffee-script-source
Expand All @@ -16,8 +16,8 @@ GEM
colorator (1.1.0)
commonmarker (0.17.13)
ruby-enum (~> 0.5)
concurrent-ruby (1.1.8)
dnsruby (1.61.5)
concurrent-ruby (1.1.9)
dnsruby (1.61.7)
simpleidn (~> 0.1)
em-websocket (0.5.2)
eventmachine (>= 0.12.9)
Expand All @@ -26,20 +26,28 @@ GEM
ffi (>= 1.15.0)
eventmachine (1.2.7)
execjs (2.8.1)
faraday (1.4.1)
faraday (1.5.1)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
faraday-httpclient (~> 1.0.1)
faraday-net_http (~> 1.0)
faraday-net_http_persistent (~> 1.1)
faraday-patron (~> 1.0)
multipart-post (>= 1.2, < 3)
ruby2_keywords (>= 0.0.4)
faraday-em_http (1.0.0)
faraday-em_synchrony (1.0.0)
faraday-excon (1.1.0)
faraday-httpclient (1.0.1)
faraday-net_http (1.0.1)
faraday-net_http_persistent (1.1.0)
ffi (1.15.0)
faraday-net_http_persistent (1.2.0)
faraday-patron (1.0.0)
ffi (1.15.3)
forwardable-extended (2.6.0)
gemoji (3.0.1)
github-pages (214)
github-pages-health-check (= 1.17.0)
github-pages (215)
github-pages-health-check (= 1.17.2)
jekyll (= 3.9.0)
jekyll-avatar (= 0.7.0)
jekyll-coffeescript (= 1.1.1)
Expand Down Expand Up @@ -82,7 +90,7 @@ GEM
nokogiri (>= 1.10.4, < 2.0)
rouge (= 3.26.0)
terminal-table (~> 1.4)
github-pages-health-check (1.17.0)
github-pages-health-check (1.17.2)
addressable (~> 2.3)
dnsruby (~> 1.60)
octokit (~> 4.0)
Expand Down Expand Up @@ -209,14 +217,14 @@ GEM
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
mercenary (0.3.6)
mini_portile2 (2.5.1)
mini_portile2 (2.5.3)
minima (2.5.1)
jekyll (>= 3.5, < 5.0)
jekyll-feed (~> 0.9)
jekyll-seo-tag (~> 2.1)
minitest (5.14.4)
multipart-post (2.1.1)
nokogiri (1.11.5)
nokogiri (1.11.7)
mini_portile2 (~> 2.5.0)
racc (~> 1.4)
octokit (4.21.0)
Expand All @@ -234,7 +242,7 @@ GEM
ruby-enum (0.9.0)
i18n
ruby2_keywords (0.0.4)
rubyzip (2.3.0)
rubyzip (2.3.2)
safe_yaml (1.0.5)
sass (3.7.4)
sass-listen (~> 4.0.0)
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/pmd/userdocs/cli_reference.md
Expand Up @@ -196,7 +196,7 @@ Example:
* [apex](pmd_rules_apex.html) (Salesforce Apex)
* [java](pmd_rules_java.html)
* Supported Versions: 1.3, 1.4, 1.5, 5, 1.6, 6, 1.7, 7, 1.8, 8, 9, 1.9, 10, 1.10, 11, 12,
13, 14, 14-preview, 15 (default), 15-preview
13, 14, 15, 16, 16-preview, 17 (default), 17-preview
* [ecmascript](pmd_rules_ecmascript.html) (JavaScript)
* [jsp](pmd_rules_jsp.html)
* [modelica](pmd_rules_modelica.html)
Expand Down
12 changes: 12 additions & 0 deletions docs/pages/pmd/userdocs/tools/tools.md
Expand Up @@ -20,6 +20,18 @@ With Codacy you have PMDJava analysis out-of-the-box, and it is free for open so
* Source code: [https://github.com/codacy/codacy-pmdjava](https://github.com/codacy/codacy-pmdjava)
* Maintainer: Codacy

### Code Inspector

[Code Inspector](https://www.code-inspector.com) automates code review, check your code quality and helps you manage your technical debt.
It is integrated with GitHub, GitLab and Bitbucket. The platform also analyzes code directly in your IDE using its integration
plugins for VS Code and IntelliJ, providing a consistent analysis along your development cycle (from the IDE to the CI/CD pipeline).

Code Inspector uses PMD to check Java and Apex code.

* Homepage: [https://www.code-inspector.com](https://www.code-inspector.com)
* Documentation: [https://doc.code-inspector.com](https://doc.code-inspector.com)


## IDE Integrations

### Summary
Expand Down
112 changes: 112 additions & 0 deletions docs/pages/release_notes.md
Expand Up @@ -14,20 +14,132 @@ This is a {{ site.pmd.release_type }} release.

### New and noteworthy

#### Java 17 Support

This release of PMD brings support for Java 17. PMD supports [JEP 409: Sealed Classes](https://openjdk.java.net/jeps/409)
which has been promoted to be a standard language feature of Java 17.

PMD also supports [JEP 406: Pattern Matching for switch (Preview)](https://openjdk.java.net/jeps/406) as a preview
language feature. In order to analyze a project with PMD that uses these language features, you'll need to enable
it via the environment variable `PMD_JAVA_OPTS` and select the new language version `17-preview`:

export PMD_JAVA_OPTS=--enable-preview
./run.sh pmd -language java -version 17-preview ...

Note: Support for Java 15 preview language features have been removed. The version "15-preview" is no longer available.

#### New rules

This release ships with 3 new Java rules.

* {% rule java/bestpractices/PrimitiveWrapperInstantiation %} reports usages of primitive wrapper
constructors. They are deprecated since Java 9 and should not be used.

```xml
<rule ref="category/java/bestpractices.xml/PrimitiveWrapperInstantiation" />
```

The rule is part of the quickstart.xml ruleset.

* {% rule java/bestpractices/SimplifiableTestAssertion %} suggests rewriting
some test assertions to be more readable.

```xml
<rule ref="category/java/bestpractices.xml/SimplifiableTestAssertion" />
```

The rule is part of the quickstart.xml ruleset.

* {% rule java/errorprone/ReturnEmptyCollectionRatherThanNull %} suggests returning empty collections / arrays
instead of null.

```xml
<rule ref="category/java/errorprone.xml/ReturnEmptyCollectionRatherThanNull" />
```

The rule is part of the quickstart.xml ruleset.

#### Renamed rules

* The Java rule {% rule java/errorprone/MissingBreakInSwitch %} has been renamed to
{% rule java/errorprone/ImplicitSwitchFallThrough %} (category error prone) to better reflect the rule's
purpose: The rule finds implicit fall-through cases in switch statements, which are most
likely unexpected. The old rule name described only one way how to avoid a fall-through,
namely using `break` but `continue`, `throw` and `return` avoid a fall-through
as well. This enables us to improve this rule in the future.

#### Deprecated rules

* The following Java rules are deprecated and removed from the quickstart ruleset,
as the new rule {% rule java/bestpractices/SimplifiableTestAssertion %} merges
their functionality:
* {% rule java/bestpractices/UseAssertEqualsInsteadOfAssertTrue %}
* {% rule java/bestpractices/UseAssertNullInsteadOfAssertTrue %}
* {% rule java/bestpractices/UseAssertSameInsteadOfAssertTrue %}
* {% rule java/bestpractices/UseAssertTrueInsteadOfAssertEquals %}
* {% rule java/design/SimplifyBooleanAssertion %}

* The Java rule {% rule java/errorprone/ReturnEmptyArrayRatherThanNull %} is deprecated and removed from
the quickstart ruleset, as the new rule {% rule java/errorprone/ReturnEmptyCollectionRatherThanNull %}
supersedes it.

* The following Java rules are deprecated and removed from the quickstart ruleset,
as the new rule {% rule java/bestpractices/PrimitiveWrapperInstantiation %} merges
their functionality:
* {% rule java/performance/BooleanInstantiation %}
* {% rule java/performance/ByteInstantiation %}
* {% rule java/performance/IntegerInstantiation %}
* {% rule java/performance/LongInstantiation %}
* {% rule java/performance/ShortInstantiation %}

* The Java rule {% rule java/performance/UnnecessaryWrapperObjectCreation %} is deprecated
with no planned replacement before PMD 7. In it's current state, the rule is not useful
as it finds only contrived cases of creating a primitive wrapper and unboxing it explicitly
in the same expression. In PMD 7 this and more cases will be covered by a
new rule `UnnecessaryBoxing`.

### Fixed Issues

* apex
* [#3201](https://github.com/pmd/pmd/issues/3201): \[apex] ApexCRUDViolation doesn't report Database class DMLs, inline no-arg object instantiations and inline list initialization
* [#3329](https://github.com/pmd/pmd/issues/3329): \[apex] ApexCRUDViolation doesn't report SOQL for loops
* core
* [#1603](https://github.com/pmd/pmd/issues/1603): \[core] Language version comparison
* [#3377](https://github.com/pmd/pmd/issues/3377): \[core] NPE when specifying report file in current directory in PMD CLI
* [#3387](https://github.com/pmd/pmd/issues/3387): \[core] CPD should avoid unnecessary copies when running with --skip-lexical-errors
* java-bestpractices
* [#2908](https://github.com/pmd/pmd/issues/2908): \[java] Merge Junit assertion simplification rules
* [#3235](https://github.com/pmd/pmd/issues/3235): \[java] UseTryWithResources false positive when closeable is provided as a method argument or class field
* java-errorprone
* [#3361](https://github.com/pmd/pmd/issues/3361): \[java] Rename rule MissingBreakInSwitch to ImplicitSwitchFallThrough
* [#3382](https://github.com/pmd/pmd/pull/3382): \[java] New rule ReturnEmptyCollectionRatherThanNull
* java-performance
* [#3420](https://github.com/pmd/pmd/issues/3420): \[java] NPE in `InefficientStringBuffering` with Records

### API Changes

#### Experimental APIs

* The AST types and APIs around Sealed Classes are not experimental anymore:
* {% jdoc !!java::lang.java.ast.ASTClassOrInterfaceDeclaration#isSealed() %},
{% jdoc !!java::lang.java.ast.ASTClassOrInterfaceDeclaration#isNonSealed() %},
{% jdoc !!java::lang.java.ast.ASTClassOrInterfaceDeclaration#getPermittedSubclasses() %}
* {% jdoc java::lang.java.ast.ASTPermitsList %}

#### Internal API

Those APIs are not intended to be used by clients, and will be hidden or removed with PMD 7.0.0.
You can identify them with the `@InternalApi` annotation. You'll also get a deprecation warning.

* The inner class {% jdoc !!core::cpd.TokenEntry.State %} is considered to be internal API.
It will probably be moved away with PMD 7.

### External Contributions

* [#3367](https://github.com/pmd/pmd/pull/3367): \[apex] Check SOQL CRUD on for loops - [Jonathan Wiesel](https://github.com/jonathanwiesel)
* [#3373](https://github.com/pmd/pmd/pull/3373): \[apex] Add ApexCRUDViolation support for database class, inline no-arg object construction DML and inline list initialization DML - [Jonathan Wiesel](https://github.com/jonathanwiesel)
* [#3385](https://github.com/pmd/pmd/pull/3385): \[core] CPD: Optimize --skip-lexical-errors option - [Woongsik Choi](https://github.com/woongsikchoi)
* [#3388](https://github.com/pmd/pmd/pull/3388): \[doc] Add Code Inspector in the list of tools - [Julien Delange](https://github.com/juli1)

{% endtocmaker %}

Expand Up @@ -20,6 +20,7 @@
import net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression;
import net.sourceforge.pmd.lang.apex.ast.ASTModifierNode;
import net.sourceforge.pmd.lang.apex.ast.ASTNewKeyValueObjectExpression;
import net.sourceforge.pmd.lang.apex.ast.ASTNewObjectExpression;
import net.sourceforge.pmd.lang.apex.ast.ASTParameter;
import net.sourceforge.pmd.lang.apex.ast.ASTReferenceExpression;
import net.sourceforge.pmd.lang.apex.ast.ASTSoqlExpression;
Expand Down Expand Up @@ -164,6 +165,13 @@ public static String getFQVariableName(final ASTNewKeyValueObjectExpression vari
return sb.toString();
}

public static String getFQVariableName(final ASTNewObjectExpression variable) {
StringBuilder sb = new StringBuilder()
.append(variable.getDefiningType()).append(":")
.append(variable.getType());
return sb.toString();
}

public static boolean isSystemLevelClass(ASTUserClass node) {
List<String> interfaces = node.getInterfaceNames();
return interfaces.stream().anyMatch(Helper::isAllowed);
Expand Down

0 comments on commit 9221cf0

Please sign in to comment.