JavaClasspath extends AbstractJavaClasspath { @Override protected void init() { if (!initialized) { validateLibraries = fs.hasFiles(fs.predicates().all()); Profiler profiler = Profiler.create(LOG).startInfo("JavaClasspath initialization"); initialized = true; binaries = new ArrayList<>(getFilesFromProperty(JavaClasspathProperties.SONAR_JAVA_BINARIES)); Set<File> libraries = getFilesFromProperty(JavaClasspathProperties.SONAR_JAVA_LIBRARIES); if (binaries.isEmpty() && libraries.isEmpty() && useDeprecatedProperties()) { throw new AnalysisException( "sonar.binaries and sonar.libraries are not supported since version 4.0 of the SonarSource Java Analyzer, please use sonar.java.binaries and sonar.java.libraries instead"); } if (binaries.isEmpty() && hasMoreThanOneJavaFile()) { if(isSonarLint()) { LOG.warn("sonar.java.binaries is empty, please double check your configuration"); } else { throw new AnalysisException("Your project contains .java files, please provide compiled classes with sonar.java.binaries property," + " or exclude them from the analysis with sonar.exclusions property."); } } elements = new ArrayList<>(binaries); if (libraries.isEmpty() && hasJavaSources()) { String warning = "Bytecode of dependencies was not provided for analysis of source files, " + "you might end up with less precise results. Bytecode can be provided using sonar.java.libraries property."; LOG.warn(warning); analysisWarnings.addUnique(warning); } elements.addAll(libraries); profiler.stopInfo(); } } JavaClasspath(Configuration settings, FileSystem fs, AnalysisWarningsWrapper analysisWarnings);  JavaClasspath(Configuration settings, FileSystem fs);   }
@Test void register_warning_for_missing_bytecode_when_libraries_empty_and_have_java_sources() { javaClasspath = createJavaClasspath(); javaClasspath.init(); assertThat(javaClasspath.getFilesFromProperty(JavaClasspathProperties.SONAR_JAVA_LIBRARIES)).isEmpty(); assertThat(javaClasspath.hasJavaSources()).isTrue(); String warning = "Bytecode of dependencies was not provided for analysis of source files, " + "you might end up with less precise results. Bytecode can be provided using sonar.java.libraries property."; verify(analysisWarnings).addUnique(eq(warning)); }
@Test void do_not_register_warning_for_missing_bytecode_when_wrapper_not_injected() { javaClasspath = new JavaClasspath(settings.asConfig(), fs); javaClasspath.init(); assertThat(javaClasspath.getFilesFromProperty(JavaClasspathProperties.SONAR_JAVA_LIBRARIES)).isEmpty(); assertThat(javaClasspath.hasJavaSources()).isTrue(); verifyZeroInteractions(analysisWarnings); }