private static Map<String, FileData> constructFileDataMap(Map<String, WsProjectResponse.FileData> content) { Map<String, FileData> fileDataMap = new HashMap<>(); content.forEach((key, value) -> { FileData fd = new FileData(value.getHash(), value.getRevision()); fileDataMap.put(key, fd); }); return fileDataMap; } }
/** * 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; }
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; }
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; }
/** * 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; }
@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"); }
@Before public void setUp() { Date lastAnalysisDate = new Date(); repository = new SingleProjectRepository(Maps.newHashMap("/Abc.java", new FileData("123", "456")), lastAnalysisDate); }
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); }
@Before public void setUp() { Date lastAnalysisDate = new Date(); SingleProjectRepository repository1 = new SingleProjectRepository(Maps.newHashMap("/Abc.java", new FileData("123", "456")), lastAnalysisDate); SingleProjectRepository repository2 = new SingleProjectRepository(Maps.newHashMap("/Def.java", new FileData("567", "321")), lastAnalysisDate); Map<String, SingleProjectRepository> moduleRepositories = Maps.newHashMap("module1", repository1); moduleRepositories.put("module2", repository2); repository = new MultiModuleProjectRepository(moduleRepositories, lastAnalysisDate); }
@Before public void prepare() throws IOException { baseDir = temp.newFolder(); Path filepath = baseDir.toPath().resolve(FILE_PATH); Files.write(filepath, FILE_CONTENT.getBytes()); String md5sum = new FileMetadata() .readMetadata(Files.newInputStream(filepath), StandardCharsets.UTF_8, FILE_PATH) .hash(); tester.addFileData(FILE_PATH, new FileData(md5sum, "1.1")); }
.addFileData(filePath, new FileData(md5sum, null)) .setPreviousAnalysisDate(new Date())
private static Map<String, FileData> constructFileDataMap(Map<String, WsProjectResponse.FileData> content) { Map<String, FileData> fileDataMap = new HashMap<>(); content.forEach((key, value) -> { FileData fd = new FileData(value.getHash(), value.getRevision()); fileDataMap.put(key, fd); }); return fileDataMap; } }