Skip to content

Commit

Permalink
Revert "LineNumbers displaying on Issue mulesoft-catalyst#15"
Browse files Browse the repository at this point in the history
This reverts commit 8eaba57.
  • Loading branch information
ca-stefan-cordes committed Dec 3, 2020
1 parent 8eaba57 commit b640c61
Show file tree
Hide file tree
Showing 10 changed files with 6 additions and 105 deletions.
5 changes: 0 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@
<!-- mandatory scope -->
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.sonarsource.analyzer-commons</groupId>
<artifactId>sonar-xml-parsing</artifactId>
<version>1.12.0.632</version>
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom2</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void validate(XPathProcessor xpathValidator, Map<RuleKey, List<NewIssue>>
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -44,44 +35,8 @@ public void validate(XPathProcessor xpathValidator, Map<RuleKey, List<NewIssue>>
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);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

}
1 change: 0 additions & 1 deletion src/main/resources/mule3.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
1 change: 0 additions & 1 deletion src/main/resources/mule4.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
6 changes: 2 additions & 4 deletions src/test/resources/rules-3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,15 @@
</rule>
<rule id="10" name="HTTP Listener should use HTTPS protocol"
description="HTTP Listener should use HTTPS protocol"
severity="MAJOR" type="vulnerability"
locationHint="//*[local-name()='listener-config']">
severity="MAJOR" type="vulnerability">
count(//mule:mule/http:listener-config)=0
or
//mule:mule/http:listener-config/@protocol='HTTPS'
</rule>
<rule id="11"
name="HTTP Listener should use a specific port property"
description="HTTP Listener should use a specific port property"
severity="MAJOR" type="code_smell"
locationHint="//*[local-name()='listener-config']">
severity="MAJOR" type="code_smell">
count(//mule:mule/http:listener-config)=0
or
//mule:mule/http:listener-config/@port='${https.port}' or
Expand Down
6 changes: 2 additions & 4 deletions src/test/resources/rules-4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,15 @@
</rule>
<rule id="7" name="HTTP Listener should use HTTPS protocol"
description="HTTP Listener should use HTTPS protocol"
severity="MAJOR" type="vulnerability"
locationHint="//*[local-name()='listener-config']">
severity="MAJOR" type="vulnerability">
count(//mule:mule/http:listener-config)=0
or
//mule:mule/http:listener-config/http:listener-connection/@protocol='HTTPS'
</rule>
<rule id="8"
name="HTTP Listener should use a specific port property"
description="HTTP Listener should use a specific port property"
severity="MAJOR" type="code_smell"
locationHint="//*[local-name()='listener-config']">
severity="MAJOR" type="code_smell">
count(//mule:mule/http:listener-config)=0
or
//mule:mule/http:listener-config/http:listener-connection/@port='${https.port}'
Expand Down

0 comments on commit b640c61

Please sign in to comment.