Skip to content

Commit

Permalink
Merge pull request #4605 from adangel:issue-3973-apex-jorje
Browse files Browse the repository at this point in the history
[apex] Update jorje #4605
  • Loading branch information
adangel committed Sep 28, 2023
2 parents 347d599 + 4d185d5 commit c2b2a32
Show file tree
Hide file tree
Showing 26 changed files with 255 additions and 148 deletions.
14 changes: 14 additions & 0 deletions docs/pages/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ for all.</p>
This section lists the most important changes from the last release candidate.
The remaining section describes the complete release notes for 7.0.0.

#### New and Noteworthy

##### Apex Jorje Updated

With the new version of Apex Jorje, the new language constructs like User Mode Database Operations
can be parsed now. PMD should now be able to parse Apex code up to version 59.0 (Winter '23).

#### Fixed issues

* miscellaneous
Expand All @@ -58,6 +65,8 @@ The remaining section describes the complete release notes for 7.0.0.
* [#4294](https://github.com/pmd/pmd/issues/4294): \[doc] Migration Guide for upgrading PMD 6 ➡️ 7
* [#4303](https://github.com/pmd/pmd/issues/4303): \[doc] Document new property framework
* [#4521](https://github.com/pmd/pmd/issues/4521): \[doc] Website is not mobile friendly
* apex
* [#3973](https://github.com/pmd/pmd/issues/3973): \[apex] Update parser to support new 'as user' keywords (User Mode for Database Operations)
* apex-design
* [#4596](https://github.com/pmd/pmd/issues/4596): \[apex] ExcessivePublicCount ignores properties
* apex-security
Expand Down Expand Up @@ -356,6 +365,10 @@ Contributors: [Wener](https://github.com/wener-tiobe) (@wener-tiobe)
literals were ignored. The new option additional ignores identifiers as well in sequences.
* See [PR #4470](https://github.com/pmd/pmd/pull/4470) for details.

#### Changed: Apex Jorje Updated

With the new version of Apex Jorje, the new language constructs like User Mode Database Operations
can be parsed now. PMD should now be able to parse Apex code up to version 59.0 (Winter '23).

#### Changed: Rule properties

Expand Down Expand Up @@ -607,6 +620,7 @@ Language specific fixes:
* [#1648](https://github.com/pmd/pmd/issues/1648): \[apex,vf] Remove CodeClimate dependency
* [#1750](https://github.com/pmd/pmd/pull/1750): \[apex] Remove apex statistical rules
* [#2836](https://github.com/pmd/pmd/pull/2836): \[apex] Remove Apex ProjectMirror
* [#3973](https://github.com/pmd/pmd/issues/3973): \[apex] Update parser to support new 'as user' keywords (User Mode for Database Operations)
* [#4427](https://github.com/pmd/pmd/issues/4427): \[apex] ApexBadCrypto test failing to detect inline code
* apex-design
* [#2667](https://github.com/pmd/pmd/issues/2667): \[apex] Integrate nawforce/ApexLink to build robust Unused rule
Expand Down
5 changes: 5 additions & 0 deletions docs/pages/release_notes_pmd7.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ Related issue: [[core] Explicitly name all language versions (#4120)](https://gi
literals were ignored. The new option additional ignores identifiers as well in sequences.
* See [PR #4470](https://github.com/pmd/pmd/pull/4470) for details.

### Changed: Apex Jorje Updated

With the new version of Apex Jorje, the new language constructs like User Mode Database Operations
can be parsed now. PMD should now be able to parse Apex code up to version 59.0 (Winter '23).

## 🌟 New and changed rules

### New Rules
Expand Down
17 changes: 6 additions & 11 deletions pmd-apex-jorje/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</parent>

<properties>
<apex.jorje.version>2021-10-08-631b8c</apex.jorje.version>
<apex.jorje.version>2023-06-05-c27a5d</apex.jorje.version>
</properties>

<build>
Expand Down Expand Up @@ -48,7 +48,7 @@
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>3.3.0</version> <!-- apex jorje actually depends on 3.2.0 (https://github.com/forcedotcom/salesforcedx-vscode/commit/631b8cfb85cff5e989bfea13bca681b6cedcb003) -->
<version>3.3.0</version> <!-- apex jorje actually depends on 3.2.0 (https://github.com/forcedotcom/salesforcedx-vscode/commit/c27a5d6c91b494f4797e3c1d8782152b091e6233) -->
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
Expand All @@ -58,7 +58,7 @@
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<!-- apex jorje actually depends on 2.7 (https://github.com/forcedotcom/salesforcedx-vscode/commit/631b8cfb85cff5e989bfea13bca681b6cedcb003) -->
<!-- apex jorje actually depends on 2.7 (https://github.com/forcedotcom/salesforcedx-vscode/commit/c27a5d6c91b494f4797e3c1d8782152b091e6233) -->
</dependency>
<dependency>
<groupId>com.google.errorprone</groupId>
Expand All @@ -68,7 +68,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<!-- apex jorje actually depends on 26.0-jre (https://github.com/forcedotcom/salesforcedx-vscode/commit/631b8cfb85cff5e989bfea13bca681b6cedcb003) -->
<!-- apex jorje actually depends on 26.0-jre (https://github.com/forcedotcom/salesforcedx-vscode/commit/c27a5d6c91b494f4797e3c1d8782152b091e6233) -->
</dependency>
<dependency>
<groupId>com.google.j2objc</groupId>
Expand All @@ -94,17 +94,12 @@
<artifactId>animal-sniffer-annotations</artifactId>
<version>1.14</version>
</dependency>
<dependency>
<groupId>org.openjdk.jol</groupId>
<artifactId>jol-core</artifactId>
<version>0.4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<!-- apex jorje actually depends on 1.7.20 (https://github.com/forcedotcom/salesforcedx-vscode/commit/631b8cfb85cff5e989bfea13bca681b6cedcb003) -->
<!-- apex jorje actually depends on 1.7.20 (https://github.com/forcedotcom/salesforcedx-vscode/commit/c27a5d6c91b494f4797e3c1d8782152b091e6233) -->
</dependency>
<!-- apex jorje actually depends on 1.17 (https://github.com/forcedotcom/salesforcedx-vscode/commit/631b8cfb85cff5e989bfea13bca681b6cedcb003)
<!-- apex jorje actually depends on 1.17 (https://github.com/forcedotcom/salesforcedx-vscode/commit/c27a5d6c91b494f4797e3c1d8782152b091e6233)
however, it is not really needed, so we don't add it here as a dependency,
so that it doesn't end up in pmd-dist
-->
Expand Down
2 changes: 1 addition & 1 deletion pmd-apex-jorje/repo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Apex Reference:

<https://resources.docs.salesforce.com/sfdc/pdf/salesforce_apex_language_reference.pdf>

In order to download the jar file, minimize it and add a the jar files to the local repo, use the following script:
In order to download the jar file, minimize it and add the jar files to the local repo, use the following script:

./create-local-repo.sh

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
#Sat Jun 24 18:50:10 CEST 2023
apex-jorje-lsp-minimized-2023-06-05-c27a5d.jar>=
apex-jorje-lsp-minimized-2023-06-05-c27a5d.pom>=
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<modelVersion>4.0.0</modelVersion>
<groupId>apex</groupId>
<artifactId>apex-jorje-lsp-minimized</artifactId>
<version>2021-10-08-631b8c</version>
<version>2023-06-05-c27a5d</version>
<description>POM was created from install:install-file</description>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<groupId>apex</groupId>
<artifactId>apex-jorje-lsp-minimized</artifactId>
<versioning>
<release>2021-10-08-631b8c</release>
<release>2023-06-05-c27a5d</release>
<versions>
<version>2021-10-08-631b8c</version>
<version>2023-06-05-c27a5d</version>
</versions>
<lastUpdated>20211014081008</lastUpdated>
<lastUpdated>20230624165009</lastUpdated>
</versioning>
</metadata>
32 changes: 26 additions & 6 deletions pmd-apex-jorje/repo/create-local-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,39 @@ function download() {
}


#
# Unfortunately, jorje is provided as a blob, which seems to be a jar-with-dependencies
# kind of thing. We try to keep only the apex related classes and delete anything that has
# been added into the big apex-jorje-lsp-jar. The deleted classes will be added as dependencies again.
#
# We unfortunately need to keep some classes in com.google.common (guava), since jorje seems
# to have added classes there, which are not in the official guava packages.
#
function minimize() {
unzip -d temp ${FILENAME}
pushd temp
find . -not -path "." \
-and -not -path ".." \
-and -not -path "./apex" \
find . -type f \
-and -not -path "./apex/*" \
-and -not -path "./StandardApex*" \
-and -not -path "./messages*" \
-and -not -path "./com" \
-and -not -path "./com/google" \
-and -not -path "./com/google/common*" \
-and -not -path "./com/google/common/collect/ConcatenatedLists*" \
-and -not -path "./com/google/common/collect/MoreLists*" \
-and -not -path "./com/google/common/collect/MoreMaps*" \
-and -not -path "./com/google/common/collect/MoreSets*" \
-and -not -path "./com/google/common/collect/PairList*" \
-and -not -path "./com/google/common/collect/SingleAppendList*" \
-and -not -path "./com/google/common/collect/SinglePrependList*" \
-and -not -path "./com/google/common/collect/WellBehavedMap*" \
-and -not -path "./com/google/common/graph/ConfigurableMutableGraph*" \
-and -not -path "./com/google/common/graph/ConfigurableMutableNetwork*" \
-and -not -path "./com/google/common/graph/ConfigurableMutableValueGraph*" \
-and -not -path "./com/google/common/graph/ConfigurableNetwork*" \
-and -not -path "./com/google/common/graph/ConfigurableValueGraph*" \
-and -not -path "./com/google/common/reflect/Element*" \
-and -not -path "./com/google/common/util/concurrent/AbstractCheckedFuture*" \
-print0 | xargs -0 rm -rf
# delete empty directories
find . -depth -type d -empty -delete
popd
jar --create --file ${FILENAME_MINIMIZED} -C temp/ .
rm -rf temp
Expand Down
4 changes: 4 additions & 0 deletions pmd-apex/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
<artifactId>commons-lang3</artifactId>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public ApexLanguageModule() {
.addVersion("54")
.addVersion("55")
.addVersion("56")
.addDefaultVersion("57"));
.addVersion("57")
.addVersion("58")
.addDefaultVersion("59"));
}

public static ApexLanguageModule getInstance() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import apex.jorje.semantic.ast.statement.DmlDeleteStatement;

public final class ASTDmlDeleteStatement extends AbstractApexNode<DmlDeleteStatement> {
public final class ASTDmlDeleteStatement extends AbstractDmlStatement<DmlDeleteStatement> {

ASTDmlDeleteStatement(DmlDeleteStatement dmlDeleteStatement) {
super(dmlDeleteStatement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import apex.jorje.semantic.ast.statement.DmlInsertStatement;

public final class ASTDmlInsertStatement extends AbstractApexNode<DmlInsertStatement> {
public final class ASTDmlInsertStatement extends AbstractDmlStatement<DmlInsertStatement> {

ASTDmlInsertStatement(DmlInsertStatement dmlInsertStatement) {
super(dmlInsertStatement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import apex.jorje.semantic.ast.statement.DmlMergeStatement;

public final class ASTDmlMergeStatement extends AbstractApexNode<DmlMergeStatement> {
public final class ASTDmlMergeStatement extends AbstractDmlStatement<DmlMergeStatement> {

ASTDmlMergeStatement(DmlMergeStatement dmlMergeStatement) {
super(dmlMergeStatement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import apex.jorje.semantic.ast.statement.DmlUndeleteStatement;

public final class ASTDmlUndeleteStatement extends AbstractApexNode<DmlUndeleteStatement> {
public final class ASTDmlUndeleteStatement extends AbstractDmlStatement<DmlUndeleteStatement> {

ASTDmlUndeleteStatement(DmlUndeleteStatement dmlUndeleteStatement) {
super(dmlUndeleteStatement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import apex.jorje.semantic.ast.statement.DmlUpdateStatement;

public final class ASTDmlUpdateStatement extends AbstractApexNode<DmlUpdateStatement> {
public final class ASTDmlUpdateStatement extends AbstractDmlStatement<DmlUpdateStatement> {

ASTDmlUpdateStatement(DmlUpdateStatement dmlUpdateStatement) {
super(dmlUpdateStatement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import apex.jorje.semantic.ast.statement.DmlUpsertStatement;

public final class ASTDmlUpsertStatement extends AbstractApexNode<DmlUpsertStatement> {
public final class ASTDmlUpsertStatement extends AbstractDmlStatement<DmlUpsertStatement> {

ASTDmlUpsertStatement(DmlUpsertStatement dmlUpsertStatement) {
super(dmlUpsertStatement);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/

package net.sourceforge.pmd.lang.apex.ast;

import java.util.Optional;

import org.apache.commons.lang3.reflect.FieldUtils;

import apex.jorje.semantic.ast.AstNode;
import apex.jorje.semantic.ast.expression.VariableExpression;

public abstract class AbstractDmlStatement<T extends AstNode> extends AbstractApexNode<T> {
protected AbstractDmlStatement(T node) {
super(node);
}

public Optional<String> getRunAsMode() {
try {
Optional<VariableExpression> runAsMode = (Optional<VariableExpression>) FieldUtils.readField(node, "runAsModeVariable", true);
return runAsMode.map(v -> v.getIdentifier().getValue());
} catch (IllegalArgumentException | ReflectiveOperationException e) {
// ignored
return Optional.empty();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -363,4 +363,9 @@ public boolean isNamespaceGuardNamespace(Namespace arg0) {
public boolean doesLightningWebComponentExist(String var1) {
return false;
}

@Override
public boolean doesStaticResourceExist(String s) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import net.sourceforge.pmd.lang.apex.ast.ASTUserClass;
import net.sourceforge.pmd.lang.apex.ast.ASTVariableDeclaration;
import net.sourceforge.pmd.lang.apex.ast.ASTVariableExpression;
import net.sourceforge.pmd.lang.apex.ast.AbstractDmlStatement;
import net.sourceforge.pmd.lang.apex.ast.ApexNode;
import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
import net.sourceforge.pmd.lang.apex.rule.internal.Helper;
Expand Down Expand Up @@ -261,39 +262,67 @@ private boolean hasAccessLevelArgument(ASTMethodCallExpression node) {
return false;
}

private boolean hasRunAsMode(AbstractDmlStatement<?> node) {
return node.getRunAsMode().isPresent();
}

@Override
public Object visit(ASTDmlInsertStatement node, Object data) {
if (hasRunAsMode(node)) {
return data;
}

checkForCRUD(node, data, IS_CREATEABLE);
return data;
}

@Override
public Object visit(ASTDmlDeleteStatement node, Object data) {
if (hasRunAsMode(node)) {
return data;
}

checkForCRUD(node, data, IS_DELETABLE);
return data;
}

@Override
public Object visit(ASTDmlUndeleteStatement node, Object data) {
if (hasRunAsMode(node)) {
return data;
}

checkForCRUD(node, data, IS_UNDELETABLE);
return data;
}

@Override
public Object visit(ASTDmlUpdateStatement node, Object data) {
if (hasRunAsMode(node)) {
return data;
}

checkForCRUD(node, data, IS_UPDATEABLE);
return data;
}

@Override
public Object visit(ASTDmlUpsertStatement node, Object data) {
if (hasRunAsMode(node)) {
return data;
}

checkForCRUD(node, data, IS_CREATEABLE);
checkForCRUD(node, data, IS_UPDATEABLE);
return data;
}

@Override
public Object visit(ASTDmlMergeStatement node, Object data) {
if (hasRunAsMode(node)) {
return data;
}

checkForCRUD(node, data, IS_MERGEABLE);
return data;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class LanguageVersionTest extends AbstractLanguageVersionTest {

static Collection<TestDescriptor> data() {
return Arrays.asList(
TestDescriptor.defaultVersionIs(ApexLanguageModule.getInstance(), "57")
TestDescriptor.defaultVersionIs(ApexLanguageModule.getInstance(), "59")
);
}
}

0 comments on commit c2b2a32

Please sign in to comment.