SonarComponents { public File workDir() { ProjectDefinition current = projectDefinition; if(current == null) { return fs.workDir(); } while (current.getParent() != null) { current = current.getParent(); } return current.getWorkDir(); } SonarComponents(FileLinesContextFactory fileLinesContextFactory, FileSystem fs,
                         JavaClasspath javaClasspath, JavaTestClasspath javaTestClasspath,
                         CheckFactory checkFactory, SonarJavaIssueFilter postAnalysisIssueFilter);  SonarComponents(FileLinesContextFactory fileLinesContextFactory, FileSystem fs,
                         JavaClasspath javaClasspath, JavaTestClasspath javaTestClasspath, CheckFactory checkFactory,
                         @Nullable CheckRegistrar[] checkRegistrars, SonarJavaIssueFilter postAnalysisIssueFilter);  SonarComponents(FileLinesContextFactory fileLinesContextFactory, FileSystem fs,
                         JavaClasspath javaClasspath, JavaTestClasspath javaTestClasspath, CheckFactory checkFactory,
                         @Nullable ProjectDefinition projectDefinition, SonarJavaIssueFilter postAnalysisIssueFilter);  SonarComponents(FileLinesContextFactory fileLinesContextFactory, FileSystem fs,
                         JavaClasspath javaClasspath, JavaTestClasspath javaTestClasspath, CheckFactory checkFactory,
                         @Nullable CheckRegistrar[] checkRegistrars, @Nullable ProjectDefinition projectDefinition,
                         SonarJavaIssueFilter postAnalysisIssueFilter); void setSensorContext(SensorContext context); FileLinesContext fileLinesContextFor(InputFile inputFile); NewSymbolTable symbolizableFor(InputFile inputFile); NewHighlighting highlightableFor(InputFile inputFile); List<File> getJavaClasspath(); List<File> getJavaTestClasspath(); List<File> getJspClasspath(); void registerCheckClasses(String repositoryKey, Iterable<Class<? extends JavaCheck>> checkClasses); JavaCheck[] checkClasses(); Iterable<Checks<JavaCheck>> checks(); void registerTestCheckClasses(String repositoryKey, Iterable<Class<? extends JavaCheck>> checkClasses); Collection<JavaCheck> testCheckClasses(); List<JavaCheck> jspCodeVisitors(); RuleKey getRuleKey(JavaCheck check); void addIssue(InputComponent inputComponent, JavaCheck check, int line, String message, @Nullable Integer cost); void reportIssue(AnalyzerMessage analyzerMessage); boolean reportAnalysisError(RecognitionException re, InputFile inputFile); boolean isSonarLintContext(); List<String> fileLines(InputFile inputFile); String inputFileContents(InputFile inputFile); boolean analysisCancelled(); boolean shouldFailAnalysisOnException(); File workDir(); InputComponent project(); static final String FAIL_ON_EXCEPTION_KEY; }
@Test void base_and_work_directories() { File baseDir = new File(""); File workDir = new File("target"); SensorContextTester context = SensorContextTester.create(baseDir); DefaultFileSystem fs = context.fileSystem(); fs.setWorkDir(workDir.toPath()); SonarComponents sonarComponents = new SonarComponents(fileLinesContextFactory, fs, null, mock(JavaTestClasspath.class), checkFactory, null); assertThat(sonarComponents.workDir()).isEqualTo(workDir); }