/** * If possible, get the status of the provided file without initializing metadata of the file. * * @return null if it was not possible to get the status without calculating metadata */ @CheckForNull public InputFile.Status getStatusWithoutMetadata(String moduleKeyWithBranch, DefaultInputFile inputFile) { FileData fileDataPerPath = projectRepositories.fileData(moduleKeyWithBranch, inputFile); if (fileDataPerPath == null) { return checkChanged(ADDED, inputFile); } String previousHash = fileDataPerPath.hash(); if (StringUtils.isEmpty(previousHash)) { return checkChanged(ADDED, inputFile); } return null; }
InputFile.Status status(String moduleKeyWithBranch, DefaultInputFile inputFile, String hash) { FileData fileDataPerPath = projectRepositories.fileData(moduleKeyWithBranch, inputFile); if (fileDataPerPath == null) { return checkChanged(ADDED, inputFile); } String previousHash = fileDataPerPath.hash(); if (StringUtils.equals(hash, previousHash)) { return SAME; } if (StringUtils.isEmpty(previousHash)) { return checkChanged(ADDED, inputFile); } return checkChanged(CHANGED, inputFile); }
@Test public void readRealResponse() throws IOException { InputStream is = getTestResource("project.protobuf"); WsTestUtil.mockStream(wsClient, "/batch/project.protobuf?key=org.sonarsource.github%3Asonar-github-plugin&issues_mode=true", is); DefaultInputFile file = mock(DefaultInputFile.class); when(file.getModuleRelativePath()).thenReturn("src/test/java/org/sonar/plugins/github/PullRequestIssuePostJobTest.java"); ProjectRepositories proj = loader.load("org.sonarsource.github:sonar-github-plugin", true, null); FileData fd = proj.fileData("org.sonarsource.github:sonar-github-plugin", file); assertThat(fd.revision()).isEqualTo("27bf2c54633d05c5df402bbe09471fe43bd9e2e5"); assertThat(fd.hash()).isEqualTo("edb6b3b9ab92d8dc53ba90ab86cd422e"); }
private List<InputFile> collectFilesToBlame(ScannerReportWriter writer) { if (configuration.forceReloadAll()) { LOG.warn("Forced reloading of SCM data for all files."); } List<InputFile> filesToBlame = new LinkedList<>(); for (DefaultInputFile f : componentStore.allFilesToPublish()) { if (configuration.forceReloadAll() || f.status() != Status.SAME) { addIfNotEmpty(filesToBlame, f); } else if (!branchConfiguration.isShortOrPullRequest()) { // File status is SAME so that mean fileData exists FileData fileData = projectRepositories.fileData(componentStore.findModule(f).getKeyWithBranch(), f); if (StringUtils.isEmpty(fileData.revision())) { addIfNotEmpty(filesToBlame, f); } else { askToCopyDataFromPreviousAnalysis((DefaultInputFile) f, writer); } } } return filesToBlame; }
/** * If possible, get the status of the provided file without initializing metadata of the file. * * @return null if it was not possible to get the status without calculating metadata */ @CheckForNull public InputFile.Status getStatusWithoutMetadata(String moduleKeyWithBranch, DefaultInputFile inputFile) { FileData fileDataPerPath = projectRepositories.fileData(moduleKeyWithBranch, inputFile); if (fileDataPerPath == null) { return checkChanged(ADDED, inputFile); } String previousHash = fileDataPerPath.hash(); if (StringUtils.isEmpty(previousHash)) { return checkChanged(ADDED, inputFile); } return null; }
InputFile.Status status(String moduleKeyWithBranch, DefaultInputFile inputFile, String hash) { FileData fileDataPerPath = projectRepositories.fileData(moduleKeyWithBranch, inputFile); if (fileDataPerPath == null) { return checkChanged(ADDED, inputFile); } String previousHash = fileDataPerPath.hash(); if (StringUtils.equals(hash, previousHash)) { return SAME; } if (StringUtils.isEmpty(previousHash)) { return checkChanged(ADDED, inputFile); } return checkChanged(CHANGED, inputFile); }
private List<InputFile> collectFilesToBlame(ScannerReportWriter writer) { if (configuration.forceReloadAll()) { LOG.warn("Forced reloading of SCM data for all files."); } List<InputFile> filesToBlame = new LinkedList<>(); for (DefaultInputFile f : componentStore.allFilesToPublish()) { if (configuration.forceReloadAll() || f.status() != Status.SAME) { addIfNotEmpty(filesToBlame, f); } else if (!branchConfiguration.isShortOrPullRequest()) { // File status is SAME so that mean fileData exists FileData fileData = projectRepositories.fileData(componentStore.findModule(f).getKeyWithBranch(), f); if (StringUtils.isEmpty(fileData.revision())) { addIfNotEmpty(filesToBlame, f); } else { askToCopyDataFromPreviousAnalysis((DefaultInputFile) f, writer); } } } return filesToBlame; }