Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,9 @@ RunMaven() {
fi
}

cd rpg-custom-rules
wget https://binaries.sonarsource.com/CommercialDistribution/sonar-rpg-plugin/sonar-rpg-plugin-3.9.0.5001.jar
mv sonar-rpg-plugin-3.9.0.5001.jar ./lib/sonar-rpg-plugin-3.9.0.5001.jar
# We explicitly call validate here, to install the sonar-rpg-plugin jar ahead of packaging
mvn validate
RunMaven
cd ..

cd cobol-custom-rules
wget https://binaries.sonarsource.com/CommercialDistribution/sonar-cobol-plugin/sonar-cobol-plugin-4.3.0.3019.jar
mv sonar-cobol-plugin-4.3.0.3019.jar ./lib/sonar-cobol-plugin-4.3.0.3019.jar
wget https://binaries.sonarsource.com/CommercialDistribution/sonar-cobol-plugin/sonar-cobol-plugin-5.7.0.8061.jar
mv sonar-cobol-plugin-5.7.0.8061.jar ./lib/sonar-cobol-plugin-5.7.0.8061.jar
RunMaven
cd ..

cd jcl-custom-rules
wget https://binaries.sonarsource.com/CommercialDistribution/sonar-jcl-plugin/sonar-jcl-plugin-1.2.0.1148.jar
mv sonar-jcl-plugin-1.2.0.1148.jar ./lib/sonar-jcl-plugin-1.2.0.1148.jar
RunMaven
cd ..
4 changes: 2 additions & 2 deletions cobol-custom-rules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<version.logback>1.2.0</version.logback>

<sonar.version>6.7.4</sonar.version>
<sonarcobol.version>4.3.0.3019</sonarcobol.version>
<sonarcobol.version>5.7.0.8061</sonarcobol.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -67,7 +67,7 @@
<version>1.21.0.505</version>
<extensions>true</extensions>
<configuration>
<pluginKey>cobol-custom</pluginKey>
<pluginKey>cobolcustom</pluginKey>
<pluginName>COBOL Custom Rules</pluginName>
<pluginClass>com.mycompany.cobol.sample.CobolCustomRulesPlugin</pluginClass>
<sonarLintSupported>true</sonarLintSupported>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package com.mycompany.cobol.sample;

import com.mycompany.cobol.sample.checks.ForbiddenCopyRule;
import com.mycompany.cobol.sample.checks.ForbiddenCallRule;
import com.mycompany.cobol.sample.checks.IssueOnEachFileRule;
import com.mycompany.cobol.sample.checks.TrivialEvaluateRule;
Expand All @@ -42,7 +43,7 @@ public class CobolCustomCheckRepository implements CobolCheckRepository, RulesDe

// Change key and name to reflect your company rule repository.
// Don't use "cobol" key, it's the core repository.
private static final String REPOSITORY_KEY = "my-custom-cobol";
private static final String REPOSITORY_KEY = "customcobol";
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If dashes are used in the repository key, the scanner will crash.

private static final String REPOSITORY_NAME = "My Custom Cobol Analyzer";

// Must be "cobol"
Expand All @@ -56,6 +57,7 @@ public String getRepositoryKey() {
@Override
public Collection<Object> getCheckClassesOrObjects() {
return Arrays.asList(
ForbiddenCopyRule.class,
ForbiddenCallRule.class,
IssueOnEachFileRule.class,
TrivialEvaluateRule.class);
Expand All @@ -79,6 +81,7 @@ public void define(Context context) {

// Optionally define remediation costs
Map<String,String> remediationCosts = new HashMap<>();
remediationCosts.put("ForbiddenCopy", "5min");
remediationCosts.put("ForbiddenCall", "5min");
remediationCosts.put("IssueOnEachFile", "5min");
remediationCosts.put("TrivialEvaluate", "5min");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.mycompany.cobol.sample.checks;

import com.sonarsource.cobol.api.ast.CobolCheck;
import com.sonarsource.cobol.api.pp.CopyPreprocessorEvent;
import com.sonarsource.cobol.api.pp.CopyPreprocessorEventContext;
import org.sonar.check.Priority;
import org.sonar.check.Rule;

@Rule(key = "ForbiddenCopy",
name = "COPY statements should not be used",
priority = Priority.CRITICAL,
tags = {"bug"})
public class ForbiddenCopyRule extends CobolCheck implements CopyPreprocessorEvent {

private static final String MESSAGE = "Don't use COPY!";

@Override
public void onCopyPreprocessorEvent(CopyPreprocessorEventContext context) {
reportIssue(MESSAGE).on(context.tokens().get(0));
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<p>COPY should not be used</p>
<h2>Noncompliant Code Example</h2>
<pre>
TO DO
</pre>
<h2>Compliant Solution</h2>
<pre>
TO DO
</pre>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (C) 2009-2016 SonarSource SA
* All rights reserved
* mailto:contact AT sonarsource DOT com
*/
package com.mycompany.cobol.sample.checks;

import com.sonarsource.cobol.squid.CobolConfiguration;
import com.sonarsource.cobol.testing.checks.CobolCheckVerifier;
import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import org.junit.Test;

public class ForbiddenCopyRuleTest {

@Test
public void testVisitNode() {
ForbiddenCopyRule check = new ForbiddenCopyRule();
CobolConfiguration conf = CobolCheckVerifier.defaultConfig();
conf.setPreprocessorListeners(Collections.singletonList(check));
Comment on lines +20 to +21
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CheckVerifier does not register the rule automatically.

CobolCheckVerifier.verify(
new File("src/test/resources/checks/SRC/ForbiddenCopy.cbl"), conf, check);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
IDENTIFICATION DIVISION.
PROCEDURE DIVISION.
COPY MyCopyBook. *> Noncompliant
DISPLAY "FORBIDDEN42".