From b640c61407873b1abb72aff30632937eb88dddbc Mon Sep 17 00:00:00 2001
From: Stefan CORDES <50696194+ca-stefan-cordes@users.noreply.github.com>
Date: Thu, 3 Dec 2020 17:49:00 +0100
Subject: [PATCH] Revert "LineNumbers displaying on Issue #15"
This reverts commit 8eaba57dd81152b87544571a7c7b2fe8275302f9.
---
pom.xml | 5 --
.../sonarqube/rule/MuleRulesDefinition.java | 8 ----
.../rule/scope/ApplicationStrategyScope.java | 2 +-
.../rule/scope/FileStrategyScope.java | 47 +------------------
.../rule/scope/SonarXmlCheckHelper.java | 19 --------
.../services/tools/validation/rules/Rule.java | 16 -------
src/main/resources/mule3.properties | 1 -
src/main/resources/mule4.properties | 1 -
src/test/resources/rules-3.xml | 6 +--
src/test/resources/rules-4.xml | 6 +--
10 files changed, 6 insertions(+), 105 deletions(-)
delete mode 100644 src/main/java/com/mulesoft/services/tools/sonarqube/rule/scope/SonarXmlCheckHelper.java
diff --git a/pom.xml b/pom.xml
index 3fb1e1e..e620c8b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -36,11 +36,6 @@
provided
-
- org.sonarsource.analyzer-commons
- sonar-xml-parsing
- 1.12.0.632
-
org.jdom
jdom2
diff --git a/src/main/java/com/mulesoft/services/tools/sonarqube/rule/MuleRulesDefinition.java b/src/main/java/com/mulesoft/services/tools/sonarqube/rule/MuleRulesDefinition.java
index 33b8ef5..c38c34a 100644
--- a/src/main/java/com/mulesoft/services/tools/sonarqube/rule/MuleRulesDefinition.java
+++ b/src/main/java/com/mulesoft/services/tools/sonarqube/rule/MuleRulesDefinition.java
@@ -36,7 +36,6 @@ public interface PARAMS {
String CATEGORY = "category";
String SCOPE = "scope";
String XPATH = "xpath-expression";
- String XPATH_LOCATION_HINT = "xpath-location-hint";
}
@Override
@@ -98,13 +97,8 @@ private void addRuleTemplate(NewRepository repository, String language) {
.setType(RuleParamType.STRING);
x1Rule.createParam(PARAMS.XPATH).setDescription(prop.getProperty("rule.template.parameter.xpath"))
.setType(RuleParamType.STRING);
- x1Rule.createParam(PARAMS.XPATH_LOCATION_HINT).setDescription(prop.getProperty("rule.template.parameter.xpathlocationhint"))
- .setType(RuleParamType.STRING);
x1Rule.createParam(PARAMS.SCOPE).setDescription(prop.getProperty("rule.template.parameter.scope"))
.setType(RuleParamType.STRING);
-
- logger.info("addRuleTemplate x1Rule="+x1Rule);
-
}
private void addRule(NewRepository repository, Ruleset ruleset,
@@ -119,8 +113,6 @@ private void addRule(NewRepository repository, Ruleset ruleset,
x1Rule.addTags(language);
x1Rule.createParam(PARAMS.CATEGORY).setDefaultValue(ruleset.getCategory()).setType(RuleParamType.STRING);
x1Rule.createParam(PARAMS.XPATH).setDefaultValue(rule.getValue()).setType(RuleParamType.STRING);
- logger.info("LocationHint="+rule.getLocationHint()+" for "+rule.getName());
- x1Rule.createParam(PARAMS.XPATH_LOCATION_HINT).setDefaultValue(rule.getLocationHint()).setType(RuleParamType.STRING);
if (rule.getApplies() != null) {
x1Rule.createParam(PARAMS.SCOPE).setDefaultValue(rule.getApplies()).setType(RuleParamType.STRING);
}
diff --git a/src/main/java/com/mulesoft/services/tools/sonarqube/rule/scope/ApplicationStrategyScope.java b/src/main/java/com/mulesoft/services/tools/sonarqube/rule/scope/ApplicationStrategyScope.java
index 2b9e7da..86f4645 100644
--- a/src/main/java/com/mulesoft/services/tools/sonarqube/rule/scope/ApplicationStrategyScope.java
+++ b/src/main/java/com/mulesoft/services/tools/sonarqube/rule/scope/ApplicationStrategyScope.java
@@ -37,7 +37,7 @@ public void validate(XPathProcessor xpathValidator, Map>
String ruleId = rule.ruleKey().toString();
boolean valid = xpathValidator.processXPath(rule.param(MuleRulesDefinition.PARAMS.XPATH).trim(),
rootElement, Boolean.class).booleanValue();
- logger.info("Validation Result: " + valid + " : File: " + t.filename() + " :Rule:" + rule.ruleKey()+" internalKey="+rule.internalKey());
+ logger.info("Validation Result: " + valid + " : File: " + t.filename() + " :Rule:" + rule.ruleKey());
if (!valid && !valids.contains(ruleId) && !issues.containsKey(rule.ruleKey())) {
NewIssue newIssue = context.newIssue().forRule(rule.ruleKey());
NewIssueLocation primaryLocation = newIssue.newLocation().on(t);
diff --git a/src/main/java/com/mulesoft/services/tools/sonarqube/rule/scope/FileStrategyScope.java b/src/main/java/com/mulesoft/services/tools/sonarqube/rule/scope/FileStrategyScope.java
index 2642c45..89428ac 100644
--- a/src/main/java/com/mulesoft/services/tools/sonarqube/rule/scope/FileStrategyScope.java
+++ b/src/main/java/com/mulesoft/services/tools/sonarqube/rule/scope/FileStrategyScope.java
@@ -9,11 +9,6 @@
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;
-
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathExpressionException;
-import javax.xml.xpath.XPathFactory;
-
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.rule.ActiveRule;
import org.sonar.api.batch.sensor.SensorContext;
@@ -23,10 +18,6 @@
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
-import org.sonarsource.analyzer.commons.xml.XmlFile;
-import org.sonarsource.analyzer.commons.xml.XmlTextRange;
-import org.w3c.dom.Node;
-
import com.mulesoft.services.tools.sonarqube.rule.MuleRulesDefinition;
import com.mulesoft.services.xpath.XPathProcessor;
@@ -44,44 +35,8 @@ public void validate(XPathProcessor xpathValidator, Map>
rootElement, Boolean.class).booleanValue();
logger.info("Validation Result: " + valid + " : File: " + t.filename() + " :Rule:" + rule.ruleKey());
if (!valid) {
-
- XmlTextRange textRange;
- try {
- // see org.sonarsource.analyzer.commons.xml.checks.SonarXmlCheck.reportIssue(Node, String)
- SonarXmlCheckHelper tempSonarXmlCheckHelper = new SonarXmlCheckHelper();
- XmlFile xmlFile = XmlFile.create(t);
- tempSonarXmlCheckHelper.scanFile(context, rule.ruleKey(), xmlFile); // just to fill the properties
- String locationFindingXPath = rule.param(MuleRulesDefinition.PARAMS.XPATH_LOCATION_HINT).trim();
- if (locationFindingXPath == null || locationFindingXPath.length()==0) {
- logger.info("No locationFindingXPath:params="+rule.params());
- textRange = null;
- } else {
- Node locationElement = (Node)XPathFactory.newInstance().newXPath().compile(locationFindingXPath).evaluate(xmlFile.getDocument().getFirstChild(), XPathConstants.NODE);
- if (locationElement == null) {
- textRange= null;
- logger.warn("Did not find node for "+locationFindingXPath);
- } else {
- textRange = XmlFile.nodeLocation(locationElement);
- logger.info("Found textRange="+textRange);
- }
- }
- } catch (RuntimeException | XPathExpressionException e) {
- logger.error("Ignore",e);
- textRange= null;
- }
-
NewIssue newIssue = context.newIssue().forRule(rule.ruleKey());
- NewIssueLocation primaryLocation;
- if (textRange == null) {
- primaryLocation = newIssue.newLocation().on(t);
- } else {
- primaryLocation = newIssue.newLocation().on(t) .at(t.newRange(
- textRange.getStartLine(),
- textRange.getStartColumn(),
- textRange.getEndLine(),
- textRange.getEndColumn()));
- }
-
+ NewIssueLocation primaryLocation = newIssue.newLocation().on(t);
newIssue.at(primaryLocation);
addIssue(issues, rule, newIssue);
}
diff --git a/src/main/java/com/mulesoft/services/tools/sonarqube/rule/scope/SonarXmlCheckHelper.java b/src/main/java/com/mulesoft/services/tools/sonarqube/rule/scope/SonarXmlCheckHelper.java
deleted file mode 100644
index 92e0d4f..0000000
--- a/src/main/java/com/mulesoft/services/tools/sonarqube/rule/scope/SonarXmlCheckHelper.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.mulesoft.services.tools.sonarqube.rule.scope;
-
-import org.sonarsource.analyzer.commons.xml.XmlFile;
-import org.sonarsource.analyzer.commons.xml.checks.SonarXmlCheck;
-
-/**
- *
- */
-public class SonarXmlCheckHelper extends SonarXmlCheck {
-
- /**
- *
- */
- @Override
- public void scanFile(XmlFile aFile) {
- // nothing to do
- }
-
-}
diff --git a/src/main/java/com/mulesoft/services/tools/validation/rules/Rule.java b/src/main/java/com/mulesoft/services/tools/validation/rules/Rule.java
index e76c8b0..100b7f0 100644
--- a/src/main/java/com/mulesoft/services/tools/validation/rules/Rule.java
+++ b/src/main/java/com/mulesoft/services/tools/validation/rules/Rule.java
@@ -99,8 +99,6 @@ public class Rule {
protected String applies;
@XmlAttribute(name = "type")
protected String type;
- @XmlAttribute(name = "locationHint")
- private String locationHint;
/**
* Gets the value of the value property.
@@ -271,18 +269,4 @@ public void setType(String value) {
this.type = value;
}
- /**
- *
- */
- public String getLocationHint() {
- return locationHint;
- }
-
- /**
- * @see #locationHint
- */
- public void setLocationHint(String aLocationHint) {
- locationHint = aLocationHint;
- }
-
}
diff --git a/src/main/resources/mule3.properties b/src/main/resources/mule3.properties
index 41ef58b..cfe0014 100644
--- a/src/main/resources/mule3.properties
+++ b/src/main/resources/mule3.properties
@@ -19,7 +19,6 @@ rule.template.name=Track issues on Mule 3
rule.template.description=Rule Template for mule 3
rule.template.parameter.scope=The scope of the rules. It should either file or application
rule.template.parameter.xpath=XPath expression to be evaluated
-rule.template.parameter.xpathlocationhint=XPath expression to find the node
rule.template.parameter.category=Category of the rule
diff --git a/src/main/resources/mule4.properties b/src/main/resources/mule4.properties
index 1546441..a5b3247 100644
--- a/src/main/resources/mule4.properties
+++ b/src/main/resources/mule4.properties
@@ -19,7 +19,6 @@ rule.template.name=Track issues on Mule 4
rule.template.description=Rule Template for mule 4
rule.template.parameter.scope=The scope of the rules. It should either file or application
rule.template.parameter.xpath=XPath expression to be evaluated
-rule.template.parameter.xpathlocationhint=XPath expression to find the node
rule.template.parameter.category=Category of the rule
diff --git a/src/test/resources/rules-3.xml b/src/test/resources/rules-3.xml
index 90e4619..8c7ae73 100644
--- a/src/test/resources/rules-3.xml
+++ b/src/test/resources/rules-3.xml
@@ -140,8 +140,7 @@
+ severity="MAJOR" type="vulnerability">
count(//mule:mule/http:listener-config)=0
or
//mule:mule/http:listener-config/@protocol='HTTPS'
@@ -149,8 +148,7 @@
+ severity="MAJOR" type="code_smell">
count(//mule:mule/http:listener-config)=0
or
//mule:mule/http:listener-config/@port='${https.port}' or
diff --git a/src/test/resources/rules-4.xml b/src/test/resources/rules-4.xml
index 6b8f02e..75bc092 100644
--- a/src/test/resources/rules-4.xml
+++ b/src/test/resources/rules-4.xml
@@ -97,8 +97,7 @@
+ severity="MAJOR" type="vulnerability">
count(//mule:mule/http:listener-config)=0
or
//mule:mule/http:listener-config/http:listener-connection/@protocol='HTTPS'
@@ -106,8 +105,7 @@
+ severity="MAJOR" type="code_smell">
count(//mule:mule/http:listener-config)=0
or
//mule:mule/http:listener-config/http:listener-connection/@port='${https.port}'