File tree Expand file tree Collapse file tree 3 files changed +31
-10
lines changed
main/java/com/github/_1c_syntax/bsl/sonar/ext_issues
test/java/com/github/_1c_syntax/bsl/sonar/ext_issues Expand file tree Collapse file tree 3 files changed +31
-10
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,6 @@ repositories {
1919 mavenLocal()
2020 mavenCentral()
2121 maven(" https://central.sonatype.com/repository/maven-snapshots" )
22- maven(" https://repo.maven.apache.org/maven2" )
2322}
2423
2524val sonarQubeVersion = " 25.4.0.105899"
Original file line number Diff line number Diff line change @@ -53,7 +53,6 @@ public RulesFileReader(String[] filePaths) {
5353 *
5454 * @param resourceName Имя ресурса-файла
5555 * @param filePaths Массив путей к загружаемым файлам
56- *
5756 * @return Список прочитанных файлов-описаний
5857 */
5958 public static List <RulesFile > getRulesFiles (String resourceName , String [] filePaths ) {
@@ -88,21 +87,21 @@ private static Optional<RulesFile> getRulesFile(String json) {
8887 .configure (MapperFeature .ACCEPT_CASE_INSENSITIVE_PROPERTIES , true )
8988 .build ();
9089 try {
91- return Optional .of (objectMapper .readValue (json , RulesFile .class ));
90+ var data = objectMapper .readValue (json , RulesFile .class );
91+ if (data != null && data .rules () == null ) { // пустой конфиг может прочитаться, но нам это содержимое не нужно
92+ data = null ;
93+ }
94+ return Optional .ofNullable (data );
9295 } catch (IOException e ) {
9396 LOGGER .error ("Can't serialize json rules to object" , e );
9497 return Optional .empty ();
9598 }
9699 }
97100
98101 private Optional <RulesFile > getNext () {
99- if (hasMore ()) {
100- Optional <RulesFile > rules = getRulesFromFile ();
101- current ++;
102- return rules ;
103- }
104-
105- return Optional .empty ();
102+ Optional <RulesFile > rules = getRulesFromFile ();
103+ current ++;
104+ return rules ;
106105 }
107106
108107 private boolean hasMore () {
Original file line number Diff line number Diff line change @@ -89,4 +89,27 @@ void testExternalFile() {
8989 assertThat (repository .rules ()).hasSize (285 );
9090 assertThat (repository .rules ()).allMatch (rule -> rule .name ().length () < 200 );
9191 }
92+
93+ @ Test
94+ void testExternalFileWithErrors () {
95+ // все должно отработать, несмотря на отсутствующие и битые файлы
96+ var fakeRulePath = new File ("fake.json" );
97+ var noRulePath = new File ("src/test/resources/examples/.bsl-language-server.json" );
98+ var noConfigPath = new File ("src/test/resources/examples/highlight.bsl" );
99+ var config = new MapSettings ()
100+ .setProperty (reporter .getEnabledKey (), true )
101+ .setProperty (reporter .getRulesPathsKey (), fakeRulePath .getAbsolutePath ()
102+ + "," + noRulePath .getAbsolutePath ()
103+ + "," + noConfigPath .getAbsolutePath ())
104+ .asConfig ();
105+ var ruleDefinition = new RuleDefinitionsContainer (config );
106+ var context = new RulesDefinition .Context ();
107+ ruleDefinition .define (context );
108+
109+ assertThat (context .repositories ()).hasSize (1 );
110+ var repository = context .repository (reporter .getRepositoryKey ());
111+ assertThat (repository ).isNotNull ();
112+ assertThat (repository .rules ()).hasSize (281 );
113+ assertThat (repository .rules ()).allMatch (rule -> rule .name ().length () < 200 );
114+ }
92115}
You can’t perform that action at this time.
0 commit comments