public void checkout(File baseDir, Revision revision, SubprocessExecutionContext execCtx) { InMemoryStreamConsumer output = ProcessOutputStreamConsumer.inMemoryConsumer(); this.updateTo(output, baseDir, new RevisionContext(revision), execCtx); }
public void mockRevisionContext() { String mockRevision = "11111"; Revision revision = mock(Revision.class); when(revision.getRevision()).thenReturn(mockRevision); revisionContext = mock(RevisionContext.class); when(revisionContext.getLatestRevision()).thenReturn(revision); }
public void updateTo(ConsoleOutputStreamConsumer outputStreamConsumer, File baseDir, RevisionContext revisionContext, final SubprocessExecutionContext execCtx) { Revision revision = revisionContext.getLatestRevision(); try { outputStreamConsumer.stdOutput(format("[%s] Start updating %s at revision %s from %s", GoConstants.PRODUCT_NAME, updatingTarget(), revision.getRevision(), url)); File workingDir = execCtx.isServer() ? baseDir : workingdir(baseDir); GitCommand git = git(outputStreamConsumer, workingDir, revisionContext.numberOfModifications() + 1, execCtx); git.fetch(outputStreamConsumer); unshallowIfNeeded(git, outputStreamConsumer, revisionContext.getOldestRevision(), baseDir); git.resetWorkingDir(outputStreamConsumer, revision); outputStreamConsumer.stdOutput(format("[%s] Done.\n", GoConstants.PRODUCT_NAME)); } catch (Exception e) { bomb(e); } }
public BuildCommand updateTo(String baseDir, RevisionContext revisionContext) { Revision revision = revisionContext.getLatestRevision(); String workingDir = material.workingdir(new File(baseDir)).getPath(); UrlArgument url = material.getUrlArgument(); return compose( echoWithPrefix("Start updating %s at revision %s from %s", material.updatingTarget(), revision.getRevision(), url.forDisplay()), secret(url.forCommandline(), url.forDisplay()), cloneIfNeeded(workingDir, revisionContext.numberOfModifications() + 1), fetchRemote(workingDir), unshallowIfNeeded(workingDir, revision, new Integer[]{GitMaterial.UNSHALLOW_TRYOUT_STEP, Integer.MAX_VALUE}), resetWorkingCopy(workingDir, revision), echoWithPrefix("Done.\n")); }
public RevisionContext toRevisionContext() { return new RevisionContext(getRevision(), getOldestRevision(), numberOfModifications()); }
public BuildCommand updateTo(String baseDir, RevisionContext revisionContext) { Revision revision = revisionContext.getLatestRevision(); String workingDir = material.workingdir(new File(baseDir)).getPath(); return compose( secret(material.getPassword()), execTfsCheckout(material, revision, workingDir) ); }
@Test public void shouldCleanWorkingDir() throws Exception { P4Material material = p4Fixture.material(VIEW); updateTo(material, new RevisionContext(REVISION_2), JobResult.Passed); File tmpFile = new File(workingDir, "shouldBeDeleted"); FileUtils.writeStringToFile(tmpFile, "testing", UTF_8); assert(tmpFile.exists()); updateTo(material, new RevisionContext(REVISION_2), JobResult.Passed); assert(!tmpFile.exists()); }
public void updateTo(ConsoleOutputStreamConsumer outputStreamConsumer, File baseDir, RevisionContext revisionContext, final SubprocessExecutionContext execCtx) { Revision revision = revisionContext.getLatestRevision(); File workingDir = execCtx.isServer() ? baseDir : workingdir(baseDir); LOGGER.debug("[TFS] Updating to revision: {} in workingdirectory {}", revision, workingDir); outputStreamConsumer.stdOutput(format("[%s] Start updating %s at revision %s from %s", GoConstants.PRODUCT_NAME, updatingTarget(), revision.getRevision(), url)); tfs(execCtx).checkout(workingDir, revision); LOGGER.debug("[TFS] done with update"); outputStreamConsumer.stdOutput(format("[%s] Done.\n", GoConstants.PRODUCT_NAME)); }
@Test public void shouldUpdateToSpecificRevision() throws Exception { updateTo(hgMaterial, new RevisionContext(REVISION_0), JobResult.Passed); File end2endFolder = new File(workingFolder, "end2end"); assertThat(end2endFolder.listFiles().length, is(3)); updateTo(hgMaterial, new RevisionContext(REVISION_1), JobResult.Passed); assertThat(end2endFolder.listFiles().length, is(4)); }
public void updateTo(ConsoleOutputStreamConsumer outputStreamConsumer, File baseDir, RevisionContext revisionContext, final SubprocessExecutionContext execCtx) { Revision revision = revisionContext.getLatestRevision(); File workingDir = execCtx.isServer() ? baseDir : workingdir(baseDir); LOGGER.debug("Updating to revision: {} in workingdirectory {}", revision, workingDir); outputStreamConsumer.stdOutput(format("[%s] Start updating %s at revision %s from %s", GoConstants.PRODUCT_NAME, updatingTarget(), revision.getRevision(), url)); boolean shouldDoFreshCheckout = !workingDir.isDirectory() || isRepositoryChanged(workingDir); if (shouldDoFreshCheckout) { freshCheckout(outputStreamConsumer, new SubversionRevision(revision), workingDir); } else { cleanupAndUpdate(outputStreamConsumer, new SubversionRevision(revision), workingDir); } LOGGER.debug("done with update"); outputStreamConsumer.stdOutput(format("[%s] Done.\n", GoConstants.PRODUCT_NAME)); }
@Test public void shouldNotFailIfDestDoesNotExist() throws Exception { FileUtils.deleteDirectory(workingDir); assert(!workingDir.exists()); P4Material material = p4Fixture.material(VIEW); updateTo(material, new RevisionContext(REVISION_2), JobResult.Passed); assert(workingDir.exists()); }
public void updateTo(ConsoleOutputStreamConsumer outputConsumer, File baseDir, RevisionContext revisionContext, final SubprocessExecutionContext execCtx) { File workingDir = execCtx.isServer() ? baseDir : workingdir(baseDir); boolean cleaned = cleanDirectoryIfRepoChanged(workingDir, outputConsumer); String revision = revisionContext.getLatestRevision().getRevision(); try { outputConsumer.stdOutput(format("[%s] Start updating %s at revision %s from %s", GoConstants.PRODUCT_NAME, updatingTarget(), revision, serverAndPort)); p4(workingDir, outputConsumer).sync(parseLong(revision), cleaned, outputConsumer); outputConsumer.stdOutput(format("[%s] Done.\n", GoConstants.PRODUCT_NAME)); } catch (Exception e) { bomb(e); } }
@Test public void shouldSyncToSpecifiedRevision() throws Exception { P4Material material = p4Fixture.material(VIEW); updateTo(material, new RevisionContext(REVISION_2), JobResult.Passed); assertThat(workingDir.listFiles().length, is(7)); updateTo(material, new RevisionContext(REVISION_3), JobResult.Passed); assertThat(workingDir.listFiles().length, is(6)); }
public BuildCommand updateTo(String baseDir, RevisionContext revisionContext) { String workingDir = material.workingdir(new File(baseDir)).getPath(); String revision = revisionContext.getLatestRevision().getRevision(); this.clientName = material.clientName(new File(workingDir)); return compose( secret(material.getPassword()), loginIfUsingTickets(), constructClient(workingDir, clientName), cleanWorkingDir(workingDir), echo(format("[%s] Start updating %s at revision %s from %s", GoConstants.PRODUCT_NAME, material.updatingTarget(), revision, material.getServerAndPort())), sync(workingDir, revision), echo(format("[%s] Done.\n", GoConstants.PRODUCT_NAME)) ); }
@Test public void shouldUpdateToDestinationFolder() throws Exception { svnMaterial.setFolder("dest"); updateTo(svnMaterial, new RevisionContext(revision), JobResult.Passed); assertThat(new File(workingDir, "dest").exists(), is(true)); assertThat(new File(workingDir, "dest/.svn").exists(), is(true)); }
public void updateTo(ConsoleOutputStreamConsumer outputStreamConsumer, File baseDir, RevisionContext revisionContext, final SubprocessExecutionContext execCtx) { Revision revision = revisionContext.getLatestRevision(); try { outputStreamConsumer.stdOutput(format("[%s] Start updating %s at revision %s from %s", GoConstants.PRODUCT_NAME, updatingTarget(), revision.getRevision(), url.forDisplay())); File workingDir = execCtx.isServer() ? baseDir : workingdir(baseDir); hg(workingDir, outputStreamConsumer).updateTo(revision, outputStreamConsumer); outputStreamConsumer.stdOutput(format("[%s] Done.\n", GoConstants.PRODUCT_NAME)); } catch (Exception e) { bomb(e); } }
@Test public void shouldUpdateToDestinationFolder() throws Exception { hgMaterial.setFolder("dest"); updateTo(hgMaterial, new RevisionContext(REVISION_0), JobResult.Passed); File end2endFolder = new File(workingFolder, "dest/end2end"); assertThat(new File(workingFolder, "dest").exists(), is(true)); assertThat(end2endFolder.exists(), is(true)); }
@Test public void shouldUpdateTheTfsMaterial() throws Exception { TfsExecutor tfsExecutor = new TfsExecutor() { @Override protected TfsMaterial createMaterial(String url, String username, String password, String domain, String projectPath) { assertThat(url, is("some url")); assertThat(username, is("username")); assertThat(password, is("password")); assertThat(domain, is("domain")); assertThat(projectPath, is("project path")); return tfsMaterial; } }; boolean result = tfsExecutor.execute(buildCommand, buildSession); ArgumentCaptor<RevisionContext> revisionCaptor = ArgumentCaptor.forClass(RevisionContext.class); ArgumentCaptor<File> workingDirCaptor = ArgumentCaptor.forClass(File.class); verify(tfsMaterial).updateTo(any(ConsoleOutputStreamConsumer.class), workingDirCaptor.capture(), revisionCaptor.capture(), any(SubprocessExecutionContext.class)); assertThat(revisionCaptor.getValue().getLatestRevision().getRevision(), is("revision1")); assertThat(workingDirCaptor.getValue(), is(workingDir)); assertThat(result, is(true)); }
@Test public void shouldCleanDirtyFilesUponUpdate() throws IOException { String repositoryUrl = new GitTestRepo(temporaryFolder).projectRepositoryUrl(); GitMaterial material = new GitMaterial(repositoryUrl, true); updateTo(material, new RevisionContext(REVISION_4), JobResult.Passed); File shouldBeRemoved = new File(workingDir, "shouldBeRemoved"); assertTrue(shouldBeRemoved.createNewFile()); updateTo(material, new RevisionContext(REVISION_4), JobResult.Passed); assertThat(shouldBeRemoved.exists(), is(false)); }
public BuildCommand updateTo(String baseDir, RevisionContext revisionContext) { Revision revision = revisionContext.getLatestRevision(); String workingDir = material.workingdir(new File(baseDir)).getPath(); UrlArgument url = material.getUrlArgument(); return compose( secret(url.forCommandline(), url.forDisplay()), echoWithPrefix("Start updating %s at revision %s from %s", material.updatingTarget(), revision.getRevision(), url.forDisplay()), cloneIfNeeded(workingDir), pull(workingDir), update(workingDir, revision), echoWithPrefix("Done.\n")); }