Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONAR-6713 Load rules in global container
- Loading branch information
Showing
50 changed files
with
771 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/Rule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,74 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2014 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* SonarQube is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.batch.protocol.input; | |||
|
|||
import javax.annotation.CheckForNull; | |||
import javax.annotation.Nullable; | |||
|
|||
public class Rule { | |||
private final String key; | |||
private final String repo; | |||
private final String internalKey; | |||
private final String name; | |||
private final String severity; | |||
private final String lang; | |||
|
|||
public Rule(String ruleKey, String repositoryKey, String internalKey, String name, @Nullable String severity, @Nullable String language) { | |||
this.key = ruleKey; | |||
this.repo = repositoryKey; | |||
this.internalKey = internalKey; | |||
this.name = name; | |||
this.severity = severity; | |||
this.lang = language; | |||
} | |||
|
|||
public String ruleKey() { | |||
return key; | |||
} | |||
|
|||
public String repositoryKey() { | |||
return repo; | |||
} | |||
|
|||
public String internalKey() { | |||
return internalKey; | |||
} | |||
|
|||
public String name() { | |||
return name; | |||
} | |||
|
|||
/** | |||
* Is null on manual rules | |||
*/ | |||
@CheckForNull | |||
public String severity() { | |||
return severity; | |||
} | |||
|
|||
/** | |||
* Is null on manual rules | |||
*/ | |||
@CheckForNull | |||
public String language() { | |||
return lang; | |||
} | |||
|
|||
} |
45 changes: 45 additions & 0 deletions
45
sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/RulesSearchResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,45 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2014 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* SonarQube is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.batch.protocol.input; | |||
|
|||
import java.util.List; | |||
|
|||
import org.sonar.batch.protocol.GsonHelper; | |||
|
|||
public class RulesSearchResult { | |||
List<Rule> rules; | |||
|
|||
public List<Rule> getRules() { | |||
return rules; | |||
} | |||
|
|||
public void setRules(List<Rule> rules) { | |||
this.rules = rules; | |||
} | |||
|
|||
public String toJson() { | |||
return GsonHelper.create().toJson(this); | |||
} | |||
|
|||
public static RulesSearchResult fromJson(String json) { | |||
return GsonHelper.create().fromJson(json, RulesSearchResult.class); | |||
} | |||
|
|||
} |
56 changes: 56 additions & 0 deletions
56
sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/RulesSearchResultTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,56 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2014 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* SonarQube is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.batch.protocol.input; | |||
|
|||
import org.apache.commons.io.IOUtils; | |||
|
|||
import java.io.IOException; | |||
import java.net.URL; | |||
|
|||
import static org.assertj.core.api.Assertions.assertThat; | |||
|
|||
import org.sonar.test.JsonAssert; | |||
import org.assertj.core.util.Lists; | |||
import org.junit.Test; | |||
|
|||
public class RulesSearchResultTest { | |||
@Test | |||
public void testJsonParsing() { | |||
Rule rule1 = new Rule("squid:S1194", "squid", "S1194", "\"java.lang.Error\" should not be extended", "MAJOR", "java"); | |||
Rule rule2 = new Rule("squid:ObjectFinalizeOverridenCallsSuperFinalizeCheck", "squid", "ObjectFinalizeOverridenCallsSuperFinalizeCheck", | |||
"super.finalize() should be called at the end of Object.finalize() implementations", "BLOCKER", "java"); | |||
|
|||
RulesSearchResult rules = new RulesSearchResult(); | |||
rules.setRules(Lists.newArrayList(rule1, rule2)); | |||
|
|||
JsonAssert | |||
.assertJson(getClass().getResource("RulesSearchTest/expected.json")) | |||
.isSimilarTo(rules.toJson()); | |||
} | |||
|
|||
@Test | |||
public void testJsonParsingEmpty() throws IOException { | |||
URL resource = getClass().getResource("RulesSearchTest/empty.json"); | |||
String json = IOUtils.toString(resource); | |||
RulesSearchResult result = RulesSearchResult.fromJson(json); | |||
|
|||
assertThat(result.getRules()).isEmpty(); | |||
} | |||
} |
1 change: 1 addition & 0 deletions
1
...tch-protocol/src/test/resources/org/sonar/batch/protocol/input/RulesSearchTest/empty.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
{"total":3225,"p":30,"ps":500,"rules":[]} |
1 change: 1 addition & 0 deletions
1
...-protocol/src/test/resources/org/sonar/batch/protocol/input/RulesSearchTest/expected.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
{"total":290,"p":1,"ps":2,"rules":[{"key":"squid:S1194","internalKey":"S1194","repo":"squid","name":"\"java.lang.Error\" should not be extended","severity":"MAJOR","lang":"java"},{"key":"squid:ObjectFinalizeOverridenCallsSuperFinalizeCheck","internalKey":"ObjectFinalizeOverridenCallsSuperFinalizeCheck","repo":"squid","name":"super.finalize() should be called at the end of Object.finalize() implementations","severity":"BLOCKER","lang":"java"}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.