private void checkProject(boolean isIssueMode) { if (isIssueMode) { if (!project.exists()) { LOG.warn("Project doesn't exist on the server. All issues will be marked as 'new'."); } else if (project.lastAnalysisDate() == null) { LOG.warn("No analysis has been found on the server for this project. All issues will be marked as 'new'."); } } } }
/** * 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 continueOnError() { when(wsClient.call(any(WsRequest.class))).thenThrow(IllegalStateException.class); ProjectRepositories proj = loader.load(PROJECT_KEY, false, null); assertThat(proj.exists()).isEqualTo(false); }
public LocalIssueTracking(DefaultInputProject project, Tracker<TrackedIssue, ServerIssueFromWs> tracker, ServerLineHashesLoader lastLineHashes, ActiveRules activeRules, ServerIssueRepository serverIssueRepository, ProjectRepositories projectRepositories, DefaultAnalysisMode mode) { this.project = project; this.tracker = tracker; this.lastLineHashes = lastLineHashes; this.serverIssueRepository = serverIssueRepository; this.mode = mode; this.activeRules = activeRules; this.hasServerAnalysis = projectRepositories.lastAnalysisDate() != null; }
@Test public void testProjectDoesntExist() { when(projectRepo.exists()).thenReturn(false); when(loader.loadDefault(anyString())).thenReturn(response); when(props.property(QualityProfiles.SONAR_PROFILE_PROP)).thenReturn("profile"); QualityProfiles qps = qualityProfileProvider.provide(loader, projectRepo, props); assertResponse(qps); verify(loader).loadDefault(anyString()); verifyNoMoreInteractions(loader); }
private boolean isTherePreviousAnalysis() { return getComponentByType(ProjectRepositories.class).lastAnalysisDate() != null; }
@Test public void testAssociated() { when(mode.isIssues()).thenReturn(false); when(loader.load(eq("key"), eq(false), any())).thenReturn(project); ProjectRepositories repo = provider.provide(loader, props, mode, branchConfiguration); assertThat(repo.exists()).isEqualTo(true); assertThat(repo.lastAnalysisDate()).isNotNull(); verify(mode, times(1)).isIssues(); verify(props).getKeyWithBranch(); verify(loader).load(eq("key"), eq(false), eq(null)); verifyNoMoreInteractions(loader, props, mode); } }
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 testProfilePropDefault() { when(projectRepo.exists()).thenReturn(false); when(loader.loadDefault(eq("custom"))).thenReturn(response); when(props.property(QualityProfiles.SONAR_PROFILE_PROP)).thenReturn("custom"); when(props.properties()).thenReturn(ImmutableMap.of(QualityProfiles.SONAR_PROFILE_PROP, "custom")); QualityProfiles qps = qualityProfileProvider.provide(loader, projectRepo, props); assertResponse(qps); verify(loader).loadDefault(eq("custom")); verifyNoMoreInteractions(loader); assertThat(logTester.logs(LoggerLevel.WARN)).contains("Ability to set quality profile from command line using '" + QualityProfiles.SONAR_PROFILE_PROP + "' is deprecated and will be dropped in a future SonarQube version. Please configure quality profile used by your project on SonarQube server."); }
public LocalIssueTracking(DefaultInputProject project, Tracker<TrackedIssue, ServerIssueFromWs> tracker, ServerLineHashesLoader lastLineHashes, ActiveRules activeRules, ServerIssueRepository serverIssueRepository, ProjectRepositories projectRepositories, DefaultAnalysisMode mode) { this.project = project; this.tracker = tracker; this.lastLineHashes = lastLineHashes; this.serverIssueRepository = serverIssueRepository; this.mode = mode; this.activeRules = activeRules; this.hasServerAnalysis = projectRepositories.lastAnalysisDate() != null; }
private void checkProject(boolean isIssueMode) { if (isIssueMode) { if (!project.exists()) { LOG.warn("Project doesn't exist on the server. All issues will be marked as 'new'."); } else if (project.lastAnalysisDate() == null) { LOG.warn("No analysis has been found on the server for this project. All issues will be marked as 'new'."); } } } }
@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() { MockitoAnnotations.initMocks(this); qualityProfileProvider = new QualityProfilesProvider(); when(props.getKeyWithBranch()).thenReturn("project"); when(projectRepo.exists()).thenReturn(true); response = new ArrayList<>(1); response.add(QualityProfile.newBuilder().setKey("profile").setName("profile").setLanguage("lang").setRulesUpdatedAt(DateUtils.formatDateTime(new Date())).build()); }
private boolean isTherePreviousAnalysis() { return getComponentByType(ProjectRepositories.class).lastAnalysisDate() != 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; }
public QualityProfiles provide(QualityProfileLoader loader, ProjectRepositories projectRepositories, ScannerProperties props) { if (this.profiles == null) { List<QualityProfile> profileList; Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG); if (!projectRepositories.exists()) { profileList = loader.loadDefault(getSonarProfile(props)); } else { profileList = loader.load(props.getKeyWithBranch(), getSonarProfile(props)); } profiler.stopInfo(); profiles = new QualityProfiles(profileList); } return profiles; }
/** * 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; }
public QualityProfiles provide(QualityProfileLoader loader, ProjectRepositories projectRepositories, ScannerProperties props) { if (this.profiles == null) { List<QualityProfile> profileList; Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG); if (!projectRepositories.exists()) { profileList = loader.loadDefault(getSonarProfile(props)); } else { profileList = loader.load(props.getKeyWithBranch(), getSonarProfile(props)); } profiler.stopInfo(); profiles = new QualityProfiles(profileList); } return profiles; }
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; }