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; }
@Override public void storeProperty(String key, String value) { contextPropertiesCache.put(key, value); }
@Override public MetricsRepository load() { List<Metric> metrics = new ArrayList<>(); try { loadFromPaginatedWs(metrics); } catch (Exception e) { throw new IllegalStateException("Unable to load metrics", e); } return new MetricsRepository(metrics); }
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; }
@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(); 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); }
@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); }
@CheckForNull public FileData fileData(String moduleKeyWithBranch, DefaultInputFile inputFile) { if (this instanceof SingleProjectRepository) { return ((SingleProjectRepository) this).fileData(inputFile.getProjectRelativePath()); } else { return ((MultiModuleProjectRepository) this).fileData(moduleKeyWithBranch, inputFile.getModuleRelativePath()); } }
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'."); } } } }
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(); repository = new SingleProjectRepository(Maps.newHashMap("/Abc.java", new FileData("123", "456")), lastAnalysisDate); }
@Test public void testProvide() { when(loader.load("project", null)).thenReturn(response); QualityProfiles qps = qualityProfileProvider.provide(loader, projectRepo, props); assertResponse(qps); verify(loader).load("project", null); verifyNoMoreInteractions(loader); }
@Test public void load_gets_profiles_for_specified_project_and_profile_name() throws IOException { WsTestUtil.mockStream(wsClient, "/api/qualityprofiles/search.protobuf?projectKey=foo", createStreamOfProfiles("qp")); WsTestUtil.mockStream(wsClient, "/api/qualityprofiles/search.protobuf?profileName=bar", createStreamOfProfiles("qp")); underTest.load("foo", "bar"); verifyCalledPath("/api/qualityprofiles/search.protobuf?projectKey=foo"); verifyCalledPath("/api/qualityprofiles/search.protobuf?profileName=bar"); }
@Override public MetricsRepository load() { return new MetricsRepository(metrics); }
@Test public void load_gets_all_profiles_for_specified_project() throws IOException { prepareCallWithResults(); underTest.load("foo", null); verifyCalledPath("/api/qualityprofiles/search.protobuf?projectKey=foo"); }
@Test public void loadDefault_gets_all_default_profiles() throws IOException { prepareCallWithResults(); underTest.loadDefault(null); verifyCalledPath("/api/qualityprofiles/search.protobuf?defaults=true"); }
@Test public void loadDefault_gets_profiles_with_specified_name() throws IOException { WsTestUtil.mockStream(wsClient, "/api/qualityprofiles/search.protobuf?defaults=true", createStreamOfProfiles("qp")); WsTestUtil.mockStream(wsClient, "/api/qualityprofiles/search.protobuf?profileName=foo", createStreamOfProfiles("qp")); underTest.loadDefault("foo"); verifyCalledPath("/api/qualityprofiles/search.protobuf?defaults=true"); verifyCalledPath("/api/qualityprofiles/search.protobuf?profileName=foo"); }
public MetricsRepository provide(MetricsRepositoryLoader loader) { if (metricsRepository == null) { Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG); metricsRepository = loader.load(); profiler.stopInfo(); } return metricsRepository; } }
@Test public void load_throws_MessageException_if_no_profiles_are_available_for_specified_project() throws IOException { prepareCallWithEmptyResults(); exception.expect(MessageException.class); exception.expectMessage("No quality profiles"); underTest.load("project", null); verifyNoMoreInteractions(wsClient); }
@Test public void load_encodes_url_parameters() throws IOException { WsTestUtil.mockStream(wsClient, "/api/qualityprofiles/search.protobuf?projectKey=foo%232", createStreamOfProfiles("qp")); WsTestUtil.mockStream(wsClient, "/api/qualityprofiles/search.protobuf?profileName=bar%232", createStreamOfProfiles("qp")); underTest.load("foo#2", "bar#2"); verifyCalledPath("/api/qualityprofiles/search.protobuf?projectKey=foo%232"); verifyCalledPath("/api/qualityprofiles/search.protobuf?profileName=bar%232"); }