Skip to content

Commit

Permalink
Merge branch 'release/3.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasPohl committed Oct 17, 2023
2 parents e9e799d + f03dc13 commit fad69d4
Show file tree
Hide file tree
Showing 25 changed files with 509 additions and 8 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -53,7 +53,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -67,4 +67,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ This open source plugin can be used to analyze the ESQL-sourcecode of IBM App Co

## History

- 3.5.0 - Parsing of COMMIT and ROLLBACK statements and rules for them
- 3.4.0 - New coverage format, bugfixes, Sonar 9.4
- 3.3.0 - Upgrade to SonarQube 8.9
- 3.0.0 - Bugfixes, upgrade to sonar SonarQube 7.9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public static List<Class<?>> getChecks() {
CommentRegularExpressionCheck.class,
CommentedCodeCheck.class,
CommentsCheck.class,
CommitCheck.class,
ConditionParenthesisCheck.class,
CyclomaticComplexityCheck.class,
DeclareCombineCheck.class,
Expand Down Expand Up @@ -91,6 +92,7 @@ public static List<Class<?>> getChecks() {
PropagateConsistencyCheck.class,
PropagateToLabelCheck.class,
RecursionCheck.class,
RollbackCheck.class,
RoutineCommentsCheck.class,
RoutineWithExcessiveReturnsCheck.class,
SelectAllCheck.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Sonar ESQL Plugin
* Copyright (C) 2013-2023 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.exxeta.iss.sonar.esql.check;

import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitorCheck;
import com.exxeta.iss.sonar.esql.tree.impl.statement.CommitStatementTreeImpl;
import org.sonar.check.Rule;

@Rule(key="Commit")
public class CommitCheck extends DoubleDispatchVisitorCheck {

public static final String MESSAGE = "COMMIT should not be called explicitly. Otherwise the messageflow can't handle the transaction.";
@Override
public void visitCommitStatement(CommitStatementTreeImpl tree) {
addIssue(tree.commitKeyword(), MESSAGE);
super.visitCommitStatement(tree);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Sonar ESQL Plugin
* Copyright (C) 2013-2023 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.exxeta.iss.sonar.esql.check;

import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitorCheck;
import com.exxeta.iss.sonar.esql.tree.impl.statement.RollbackStatementTreeImpl;
import org.sonar.check.Rule;

@Rule(key="Rollback")
public class RollbackCheck extends DoubleDispatchVisitorCheck {

public static final String MESSAGE = "ROLLBACK should not be called explicitly. Otherwise the messageflow can't handle the transaction.";
@Override
public void visitRollbackStatement(RollbackStatementTreeImpl tree) {
addIssue(tree.rollbackKeyword(), MESSAGE);
super.visitRollbackStatement(tree);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<p>Avoid using the COMMIT statement in ESQL code, as it can undermine the transaction
handling mechanism of the message flow. Instead, consider restructuring the flow
to handle smaller transactions or committing all changes at once. This approach
helps ensure that the transaction handling mechanism operates correctly and reliably,
without risking unexpected behavior or data loss. By avoiding the use of COMMIT statements,
you can help maintain the integrity and consistency of the message flow's data.</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"title": "COMMIT should not be used.",
"type": "CODE_SMELL",
"status": "ready",
"remediation": {
"func": "Constant\/Issue",
"constantCost": "20min"
},
"tags": [
"bad-practice"
],
"defaultSeverity": "Major"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<p>Avoid using the ROLLBACK statement in ESQL code, as it can undermine the transaction
handling mechanism of the message flow. Instead, consider using the THROW statement to
raise an exception and trigger a rollback of the entire message flow. This approach helps
ensure that the transaction handling mechanism operates correctly and reliably, without
risking unexpected behavior or data loss.</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"title": "ROLLBACK should not be used.",
"type": "CODE_SMELL",
"status": "ready",
"remediation": {
"func": "Constant\/Issue",
"constantCost": "20min"
},
"tags": [
"bad-practice"
],
"defaultSeverity": "Major"
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"CaseWithoutElse",
"CommentedCode",
"Comments",
"Commit",
"CyclomaticComplexity",
"DeleteFromWithoutWhere",
"DeprecatedMethod",
Expand Down Expand Up @@ -40,6 +41,7 @@
"OneStatementPerLine",
"ParameterWithDirection",
"PassThruStatement",
"Rollback",
"PropagateConsistency",
"PropagateToLabel",
"RoutineWithExcessiveReturns",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.exxeta.iss.sonar.esql.check;

import com.exxeta.iss.sonar.esql.checks.verifier.EsqlCheckVerifier;
import java.io.File;
import org.junit.jupiter.api.Test;

class CommitCheckTest {

@Test
void test() {

EsqlCheckVerifier.issues(new RollbackCheck(), new File("src/test/resources/commitRollback.esql"))
.next().atLine(5).withMessage("ROLLBACK should not be called explicitly. Otherwise the messageflow can't handle the transaction.")
.noMore();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.exxeta.iss.sonar.esql.check;

import com.exxeta.iss.sonar.esql.checks.verifier.EsqlCheckVerifier;
import java.io.File;
import org.junit.jupiter.api.Test;

class RollbackCheckTest {

@Test
void test() {

EsqlCheckVerifier.issues(new CommitCheck(), new File("src/test/resources/commitRollback.esql"))
.next().atLine(6).withMessage("COMMIT should not be called explicitly. Otherwise the messageflow can't handle the transaction.")
.noMore();
}
}
9 changes: 9 additions & 0 deletions esql-checks/src/test/resources/commitRollback.esql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE COMPUTE MODULE CommitRollback

CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
ROLLBACK;
COMMIT;
END;

END MODULE;
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public enum EsqlNonReservedKeyword implements TokenType, GrammarRuleKey {
CHAR("CHAR"),
CHARACTER("CHARACTER"),
CLR("CLR"),
COMMIT("COMMIT"),
COMPUTE("COMPUTE"),
CONDITION("CONDITION"),
CONSTANT("CONSTANT"),
Expand Down Expand Up @@ -170,6 +171,7 @@ public enum EsqlNonReservedKeyword implements TokenType, GrammarRuleKey {
RESULT("RESULT"),
RETURN("RETURN"),
RETURNS("RETURNS"),
ROLLBACK("ROLLBACK"),
ROW("ROW"),
SAMEFIELD("SAMEFIELD"),
SCHEMA("SCHEMA"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package com.exxeta.iss.sonar.esql.api.tree;

import com.exxeta.iss.sonar.esql.tree.impl.statement.CommitStatementTreeImpl;
import com.exxeta.iss.sonar.esql.tree.impl.statement.RollbackStatementTreeImpl;
import java.util.stream.Stream;

import com.exxeta.iss.sonar.esql.api.tree.statement.JavaClassloaderServiceTree;
Expand Down Expand Up @@ -266,7 +268,9 @@ public enum Kind implements GrammarRuleKey, Kinds {
VARIABLE_REFERENCE(VariableReferenceTree.class),
LIST_CONSTRUCTOR_FUNCTION(ListConstructorFunctionTree.class),
NULLABLE(NullableTree.class),
JAVA_CLASSLOADER_SERVICE(JavaClassloaderServiceTree.class);
JAVA_CLASSLOADER_SERVICE(JavaClassloaderServiceTree.class),
ROLLBACK_STATEMENT(RollbackStatementTreeImpl.class),
COMMIT_STATEMENT(CommitStatementTreeImpl.class);

final Class<? extends Tree> associatedInterface;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Sonar ESQL Plugin
* Copyright (C) 2013-2023 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.exxeta.iss.sonar.esql.api.tree.statement;

import com.exxeta.iss.sonar.esql.api.tree.FieldReferenceTree;
import com.exxeta.iss.sonar.esql.api.tree.lexical.SyntaxToken;

public interface CommitStatementTree extends StatementTree{

SyntaxToken commitKeyword();
FieldReferenceTree databaseReference();
SyntaxToken semi();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Sonar ESQL Plugin
* Copyright (C) 2013-2023 Thomas Pohl and EXXETA AG
* http://www.exxeta.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.exxeta.iss.sonar.esql.api.tree.statement;

import com.exxeta.iss.sonar.esql.api.tree.FieldReferenceTree;
import com.exxeta.iss.sonar.esql.api.tree.lexical.SyntaxToken;

public interface RollbackStatementTree extends StatementTree{

SyntaxToken rollbackKeyword();
FieldReferenceTree databaseReference();
SyntaxToken semi();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package com.exxeta.iss.sonar.esql.api.visitors;

import com.exxeta.iss.sonar.esql.tree.impl.statement.CommitStatementTreeImpl;
import com.exxeta.iss.sonar.esql.tree.impl.statement.RollbackStatementTreeImpl;
import java.util.Iterator;
import java.util.List;

Expand Down Expand Up @@ -606,4 +608,10 @@ public void javaClassloaderService(JavaClassloaderServiceTree tree){
scanChildren(tree);
}

public void visitRollbackStatement(RollbackStatementTreeImpl tree) {
scanChildren(tree);
}
public void visitCommitStatement(CommitStatementTreeImpl tree) {
scanChildren(tree);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
import com.exxeta.iss.sonar.esql.tree.impl.statement.BeginEndStatementTreeImpl;
import com.exxeta.iss.sonar.esql.tree.impl.statement.CallStatementTreeImpl;
import com.exxeta.iss.sonar.esql.tree.impl.statement.CaseStatementTreeImpl;
import com.exxeta.iss.sonar.esql.tree.impl.statement.CommitStatementTreeImpl;
import com.exxeta.iss.sonar.esql.tree.impl.statement.ControlsTreeImpl;
import com.exxeta.iss.sonar.esql.tree.impl.statement.CreateFunctionStatementTreeImpl;
import com.exxeta.iss.sonar.esql.tree.impl.statement.CreateModuleStatementTreeImpl;
Expand Down Expand Up @@ -131,6 +132,7 @@
import com.exxeta.iss.sonar.esql.tree.impl.statement.ResultSetTreeImpl;
import com.exxeta.iss.sonar.esql.tree.impl.statement.ReturnStatementTreeImpl;
import com.exxeta.iss.sonar.esql.tree.impl.statement.ReturnTypeTreeImpl;
import com.exxeta.iss.sonar.esql.tree.impl.statement.RollbackStatementTreeImpl;
import com.exxeta.iss.sonar.esql.tree.impl.statement.RoutineBodyTreeImpl;
import com.exxeta.iss.sonar.esql.tree.impl.statement.SetColumnTreeImpl;
import com.exxeta.iss.sonar.esql.tree.impl.statement.SetStatementTreeImpl;
Expand Down Expand Up @@ -453,7 +455,7 @@ private StatementTree OTHER_STATEMENT() {
}

private StatementTree DATABASE_UPDATE_STATEMENT() {
return b.firstOf(DELETE_FROM_STATEMENT(), INSERT_STATEMENT(), PASSTHRU_STATEMENT(), UPDATE_STATEMENT());
return b.firstOf(COMMIT_STATEMENT(), DELETE_FROM_STATEMENT(), INSERT_STATEMENT(), PASSTHRU_STATEMENT(), ROLLBACK_STATEMENT(), UPDATE_STATEMENT());
}

private StatementTree NODE_INTERACTION_STATEMENT() {
Expand Down Expand Up @@ -1097,7 +1099,15 @@ public NameClausesTreeImpl NAME_CLAUSES(){
)
));
}


public CommitStatementTreeImpl COMMIT_STATEMENT(){
return b.<CommitStatementTreeImpl>nonterminal(Kind.COMMIT_STATEMENT).is (f.commitStatement(
b.token(EsqlNonReservedKeyword.COMMIT),b.optional(FIELD_REFERENCE()),
b.token(EsqlLegacyGrammar.EOS)
));
}


public DeleteFromStatementTreeImpl DELETE_FROM_STATEMENT(){
return b.<DeleteFromStatementTreeImpl>nonterminal(Kind.DELETE_FROM_STATEMENT).is (f.deleteFromStatement(
b.token(EsqlNonReservedKeyword.DELETE),b.token(EsqlReservedKeyword.FROM),FIELD_REFERENCE(),
Expand Down Expand Up @@ -1125,7 +1135,13 @@ public PassthruStatementTreeImpl PASSTHRU_STATEMENT(){
)), b.token(EsqlLegacyGrammar.EOS)
));
}


public RollbackStatementTreeImpl ROLLBACK_STATEMENT(){
return b.<RollbackStatementTreeImpl>nonterminal(Kind.ROLLBACK_STATEMENT).is (f.rollbackStatement(
b.token(EsqlNonReservedKeyword.ROLLBACK),b.optional(FIELD_REFERENCE()),
b.token(EsqlLegacyGrammar.EOS)
));
}
public UpdateStatementTreeImpl UPDATE_STATEMENT(){
return b.<UpdateStatementTreeImpl>nonterminal(Kind.UPDATE_STATEMENT).is(f.updateStatement(
b.token(EsqlNonReservedKeyword.UPDATE),
Expand Down
Loading

0 comments on commit fad69d4

Please sign in to comment.