]> source.dussan.org Git - sonarqube.git/commitdiff
Revert "SONAR-21195 Fix issues raised by SonarQube"
authorMatteo Mara <matteo.mara@sonarsource.com>
Fri, 22 Dec 2023 09:28:19 +0000 (10:28 +0100)
committersonartech <sonartech@sonarsource.com>
Fri, 22 Dec 2023 20:03:01 +0000 (20:03 +0000)
This reverts commit 68c20adec31385cc56a6532883c3328947742522.

sonar-core/src/main/java/org/sonar/classloader/ClassloaderBuilder.java
sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumIT.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/SpringScannerContainer.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/language/DefaultLanguagesRepository.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/DirectoryFileVisitor.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ProjectFilePreprocessor.java

index 078c5025b34d06ca310b65fe7ba8b3704659a5d8..26f66d33a06942a706449c975305b8a9bf90b5e0 100644 (file)
@@ -117,7 +117,13 @@ public class ClassloaderBuilder {
       throw new IllegalStateException(String.format("The classloader '%s' already exists in the list of previously created classloaders."
         + " Can not create it twice.", key));
     }
-    ClassRealm realm = AccessController.doPrivileged((PrivilegedAction<ClassRealm>) () -> new ClassRealm(key, baseClassloader));
+    //TODO: to be checked, the other version of the code is not building
+    ClassRealm realm = AccessController.doPrivileged(new PrivilegedAction<ClassRealm>() {
+      @Override
+      public ClassRealm run() {
+        return new ClassRealm(key, baseClassloader);
+      }
+    });
     realm.setStrategy(LoadingOrder.PARENT_FIRST.strategy);
     newRealmsByKey.put(key, new NewRealm(realm));
     return this;
index cfb6d5454586385b39127db49bbde74f55668885..66f35f9cfa874f843a42898f0380ab0027ca4b88 100644 (file)
@@ -133,7 +133,7 @@ public class FileSystemMediumIT {
         .put("sonar.sources", "src")
         .build())
       .execute())
-      .isInstanceOf(MessageException.class);
+        .isInstanceOf(MessageException.class);
   }
 
   @Test
@@ -695,8 +695,8 @@ public class FileSystemMediumIT {
         .put("sonar.sources", "src,src/sample.xoo")
         .build())
       .execute())
-      .isInstanceOf(MessageException.class)
-      .hasMessage("File src/sample.xoo can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files");
+        .isInstanceOf(MessageException.class)
+        .hasMessage("File src/sample.xoo can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files");
   }
 
   // SONAR-9574
@@ -714,8 +714,8 @@ public class FileSystemMediumIT {
         .put("module1.sonar.sources", "src")
         .build())
       .execute())
-      .isInstanceOf(MessageException.class)
-      .hasMessage("File module1/src/sample.xoo can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files");
+        .isInstanceOf(MessageException.class)
+        .hasMessage("File module1/src/sample.xoo can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files");
   }
 
   // SONAR-5330
@@ -870,7 +870,7 @@ public class FileSystemMediumIT {
     File srcDir = new File(baseDir, "src");
     srcDir.mkdir();
 
-    tester.addLanguage("xoo3", "xoo3", false, ".xoo3");
+    tester.addLanguage("xoo3", "xoo3",false,  ".xoo3");
 
     writeFile(srcDir, "sample.xoo3", "Sample xoo\ncontent");
     writeFile(srcDir, "sample2.xoo3", "Sample xoo 2\ncontent");
@@ -1236,7 +1236,7 @@ public class FileSystemMediumIT {
         .build())
       .execute();
 
-    assertAnalysedFiles(result, "src/srcSubDir/srcSub.xoo");
+    assertAnalysedFiles(result,  "src/srcSubDir/srcSub.xoo");
   }
 
   @Test
index 104e6958eaacc547fcdab52b48c39bd3c92fc9e6..38972c9507126e516defe4961929cd07df76e225 100644 (file)
@@ -328,10 +328,10 @@ public class SpringScannerContainer extends SpringComponentContainer {
     });
 
     BranchConfiguration branchConfig = getComponentByType(BranchConfiguration.class);
-    if (branchConfig.branchType() == BranchType.PULL_REQUEST && LOG.isInfoEnabled()) {
+    if (branchConfig.branchType() == BranchType.PULL_REQUEST) {
       LOG.info("Pull request {} for merge into {} from {}", branchConfig.pullRequestKey(), pullRequestBaseToDisplayName(branchConfig.targetBranchName()),
         branchConfig.branchName());
-    } else if (branchConfig.branchName() != null && LOG.isInfoEnabled()) {
+    } else if (branchConfig.branchName() != null) {
       LOG.info("Branch name: {}", branchConfig.branchName());
     }
 
index c3505ebbfbf3db26858c15538e896d14072f1424..09007278bd1a76b4bb2dcd14367fbce5ebb12eb4 100644 (file)
@@ -30,7 +30,6 @@ import java.util.stream.Collectors;
 import javax.annotation.CheckForNull;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import javax.annotation.concurrent.Immutable;
 import org.sonar.api.Startable;
 import org.sonar.api.config.Configuration;
 import org.sonar.api.resources.Languages;
@@ -41,7 +40,6 @@ import org.sonarqube.ws.client.GetRequest;
  * Languages repository using {@link Languages}
  * @since 4.4
  */
-@Immutable
 public class DefaultLanguagesRepository implements LanguagesRepository, Startable {
   private static final Logger LOG = LoggerFactory.getLogger(DefaultLanguagesRepository.class);
   private static final String LANGUAGES_WS_URL = "/api/languages/list";
@@ -77,8 +75,9 @@ public class DefaultLanguagesRepository implements LanguagesRepository, Startabl
   }
 
   private Language populateFileSuffixesAndPatterns(SupportedLanguageDto lang) {
-    lang.setFileSuffixes(getFileSuffixes(lang.getKey()));
-    lang.setFilenamePatterns(getFilenamePatterns(lang.getKey()));
+    String propertyFragment = PROPERTY_FRAGMENT_MAP.getOrDefault(lang.getKey(), lang.getKey());
+    lang.setFileSuffixes(properties.getStringArray(String.format("sonar.%s.file.suffixes", propertyFragment)));
+    lang.setFilenamePatterns(properties.getStringArray(String.format("sonar.%s.file.patterns", propertyFragment)));
     if (lang.filenamePatterns() == null && lang.getFileSuffixes() == null) {
       LOG.debug("Language '{}' cannot be detected as it has neither suffixes nor patterns.", lang.getName());
     }
@@ -86,15 +85,7 @@ public class DefaultLanguagesRepository implements LanguagesRepository, Startabl
   }
 
   private String[] getFileSuffixes(String languageKey) {
-    return getPropertyForLanguage("sonar.%s.file.suffixes", languageKey);
-  }
-
-  private String[] getFilenamePatterns(String languageKey) {
-    return getPropertyForLanguage("sonar.%s.file.patterns", languageKey);
-  }
-
-  private String[] getPropertyForLanguage(String propertyPattern, String languageKey) {
-    String propName = String.format(propertyPattern, PROPERTY_FRAGMENT_MAP.getOrDefault(languageKey, languageKey));
+    String propName = String.format("sonar.%s.file.suffixes", PROPERTY_FRAGMENT_MAP.getOrDefault(languageKey, languageKey));
     return properties.getStringArray(propName);
   }
 
index e99b966d6c8d0d7847e3140d3438f3140566481f..eec0ed9c8d077b6b249d27feb91306dff08db71b 100644 (file)
@@ -47,8 +47,7 @@ public class DirectoryFileVisitor implements FileVisitor<Path> {
   private final InputModuleHierarchy inputModuleHierarchy;
   private final InputFile.Type type;
 
-  DirectoryFileVisitor(FileVisitAction fileVisitAction, DefaultInputModule module, ModuleExclusionFilters moduleExclusionFilters,
-    InputModuleHierarchy inputModuleHierarchy, InputFile.Type type) {
+  DirectoryFileVisitor(FileVisitAction fileVisitAction, DefaultInputModule module, ModuleExclusionFilters moduleExclusionFilters, InputModuleHierarchy inputModuleHierarchy, InputFile.Type type) {
     this.fileVisitAction = fileVisitAction;
     this.module = module;
     this.moduleExclusionFilters = moduleExclusionFilters;
index 4fd5eda7a252dc5dc151f281daf26e1a52dfdf85..54d4f2b8d6c57a53ed0dae15880bc5d03dab0939 100644 (file)
@@ -54,6 +54,7 @@ import static java.util.Collections.singletonList;
 public class ProjectFilePreprocessor {
 
   private static final Logger LOG = LoggerFactory.getLogger(ProjectFilePreprocessor.class);
+  private static final String TELEMETRY_STEP_NAME = "file.preprocessing";
 
   private final AnalysisWarnings analysisWarnings;
   private final IgnoreCommand ignoreCommand;
@@ -112,13 +113,17 @@ public class ProjectFilePreprocessor {
       pluralizeWithCount("preprocessed file", totalFilesPreprocessed)));
 
     int excludedFileByPatternCount = exclusionCounter.getByPatternsCount();
-    if ((projectExclusionFilters.hasPattern() || excludedFileByPatternCount > 0) && LOG.isInfoEnabled()) {
-      LOG.info("{} ignored because of inclusion/exclusion patterns", pluralizeWithCount("file", excludedFileByPatternCount));
+    if (projectExclusionFilters.hasPattern() || excludedFileByPatternCount > 0) {
+      if (LOG.isInfoEnabled()) {
+        LOG.info("{} ignored because of inclusion/exclusion patterns", pluralizeWithCount("file", excludedFileByPatternCount));
+      }
     }
 
     int excludedFileByScmCount = exclusionCounter.getByScmCount();
-    if (useScmExclusion && LOG.isInfoEnabled()) {
-      LOG.info("{} ignored because of scm ignore settings", pluralizeWithCount("file", excludedFileByScmCount));
+    if (useScmExclusion) {
+      if (LOG.isInfoEnabled()) {
+        LOG.info("{} ignored because of scm ignore settings", pluralizeWithCount("file", excludedFileByScmCount));
+      }
     }
   }