PollOperation implements FileCallable<PollingResult> { public PollingResult invoke(File file, VirtualChannel channel) throws IOException, InterruptedException { for (BuildRepository repo : repos) { Repository gitRepo = new FileRepositoryOperation(repo).invoke(file, channel); if (gitRepo == null) return PollingResult.BUILD_NOW; LsRemoteOperation op = new LsRemoteOperation(repo, gitRepo); ObjectId latest = op.call(); if (latest == null) return PollingResult.BUILD_NOW; ObjectId current = state.get(repo); if (current == null) return PollingResult.BUILD_NOW; if (!latest.equals(current)) return PollingResult.SIGNIFICANT; } return PollingResult.NO_CHANGES; } PollOperation(BuildRepositoryState baseline,
			List<BuildRepository> repos); PollingResult invoke(File file, VirtualChannel channel);  }
@Test public void emptyRepos() throws Exception { PollOperation op = new PollOperation(new BuildRepositoryState(), Collections.<BuildRepository> emptyList()); assertEquals(PollingResult.NO_CHANGES, op.invoke(null, null)); }
@Test public void emptyState() throws Exception { git.add("file.txt", "a"); BuildRepository repo = new BuildRepository(git.repo().getDirectory() .toURI().toString(), "refs/heads/master", null); CloneOperation clone = new CloneOperation(repo); File dir = git.tempDirectory(); assertNotNull(clone.invoke(dir, null)); PollOperation op = new PollOperation(new BuildRepositoryState(), Collections.singletonList(repo)); assertEquals(PollingResult.BUILD_NOW, op.invoke(dir, null)); }
@Test public void noRepo() throws Exception { BuildRepository repo = new BuildRepository("a", "master", null); PollOperation op = new PollOperation(new BuildRepositoryState(), Collections.singletonList(repo)); File dir = git.tempDirectory(); assertEquals(PollingResult.BUILD_NOW, op.invoke(dir, null)); }
@Test public void noChanges() throws Exception { RevCommit commit = git.add("file.txt", "a"); BuildRepository repo = new BuildRepository(git.repo().getDirectory() .toURI().toString(), "refs/heads/master", null); CloneOperation clone = new CloneOperation(repo); File dir = git.tempDirectory(); assertNotNull(clone.invoke(dir, null)); BuildRepositoryState state = new BuildRepositoryState(); state.put(repo, commit); PollOperation op = new PollOperation(state, Collections.singletonList(repo)); assertEquals(PollingResult.NO_CHANGES, op.invoke(dir, null)); }
@Test public void oneChange() throws Exception { RevCommit commit = git.add("file.txt", "a"); BuildRepository repo = new BuildRepository(git.repo().getDirectory() .toURI().toString(), "refs/heads/master", null); CloneOperation clone = new CloneOperation(repo); File dir = git.tempDirectory(); assertNotNull(clone.invoke(dir, null)); BuildRepositoryState state = new BuildRepositoryState(); state.put(repo, commit); PollOperation op = new PollOperation(state, Collections.singletonList(repo)); git.add("file2.txt", "b"); assertEquals(PollingResult.SIGNIFICANT, op.invoke(dir, null)); }