You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GitCloneTaskTest.java 2.8KB

Persist minimal racy threshold and allow manual configuration To enable persisting the minimal racy threshold per FileStore add a new config option to the user global git configuration: - Config section is "filesystem" - Config subsection is concatenation of - Java vendor (system property "java.vendor") - Java version (system property "java.version") - FileStore's name, on Windows we use the attribute volume:vsn instead since the name is not necessarily unique. - separated by '|' e.g. "AdoptOpenJDK|1.8.0_212-b03|/dev/disk1s1" The same prefix is used as for filesystem timestamp resolution, so both values are stored in the same config section - The config key for minmal racy threshold is "minRacyThreshold" as a time value, supported time units are those supported by DefaultTypedConfigGetter#getTimeUnit - measure for 3 seconds to limit runtime which depends on hardware, OS and Java version being used If the minimal racy threshold is configured for a given FileStore the configured value is used instead of measuring it. When the minimal racy threshold was measured it is persisted in the user global git configuration. Rename FileStoreAttributeCache to FileStoreAttributes since this class is now declared public in order to enable exposing all attributes in one object. Example: [filesystem "AdoptOpenJDK|11.0.3|/dev/disk1s1"] timestampResolution = 7000 nanoseconds minRacyThreshold = 3440 microseconds Change-Id: I22195e488453aae8d011b0a8e3276fe3d99deaea Signed-off-by: Matthias Sohn <matthias.sohn@sap.com> Also-By: Marc Strapetz <marc.strapetz@syntevo.com>
4 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (C) 2011, Ketan Padegaonkar <KetanPadegaonkar@gmail.com> and others
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.ant.tasks;
  11. import static org.junit.Assert.assertTrue;
  12. import java.io.File;
  13. import java.io.IOException;
  14. import org.apache.tools.ant.BuildException;
  15. import org.apache.tools.ant.DefaultLogger;
  16. import org.apache.tools.ant.Project;
  17. import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
  18. import org.eclipse.jgit.lib.Repository;
  19. import org.eclipse.jgit.lib.RepositoryCache;
  20. import org.eclipse.jgit.util.FS;
  21. import org.junit.Before;
  22. import org.junit.Test;
  23. public class GitCloneTaskTest extends LocalDiskRepositoryTestCase {
  24. private GitCloneTask task;
  25. private Project project;
  26. private File dest;
  27. @Before
  28. public void before() throws IOException {
  29. dest = createTempFile();
  30. FS.getFileStoreAttributes(dest.toPath().getParent());
  31. project = new Project();
  32. project.init();
  33. enableLogging();
  34. project.addTaskDefinition("git-clone", GitCloneTask.class);
  35. task = (GitCloneTask) project.createTask("git-clone");
  36. task.setDest(dest);
  37. }
  38. @Test(expected = BuildException.class)
  39. public void shouldRaiseErrorOnNoUrl() throws Exception {
  40. task.execute();
  41. }
  42. @Test(expected = BuildException.class)
  43. public void shouldRaiseErrorOnEmptyUrl() throws Exception {
  44. task.setUri("");
  45. task.execute();
  46. }
  47. @Test(expected = BuildException.class)
  48. public void shouldRaiseErrorOnBadUrl() throws Exception {
  49. task.setUri("foo://bar");
  50. task.execute();
  51. }
  52. @Test(expected = BuildException.class)
  53. public void shouldRaiseErrorOnBadSourceURL() throws Exception {
  54. task.setUri("http://localhost:9090/does-not-exist.git");
  55. task.execute();
  56. }
  57. @Test
  58. public void shouldCloneAValidGitRepository() throws Exception {
  59. Repository repo = createBareRepository();
  60. File directory = repo.getDirectory();
  61. task.setUri("file://" + directory.getAbsolutePath());
  62. task.execute();
  63. assertTrue(RepositoryCache.FileKey.isGitRepository(new File(dest, ".git"), FS.DETECTED));
  64. }
  65. @Test
  66. public void shouldCreateABareCloneOfAValidGitRepository() throws Exception {
  67. Repository repo = createBareRepository();
  68. File directory = repo.getDirectory();
  69. task.setUri("file://" + directory.getAbsolutePath());
  70. task.setBare(true);
  71. task.execute();
  72. assertTrue(RepositoryCache.FileKey.isGitRepository(dest, FS.DETECTED));
  73. }
  74. private void enableLogging() {
  75. DefaultLogger logger = new DefaultLogger();
  76. logger.setOutputPrintStream(System.out);
  77. logger.setErrorPrintStream(System.err);
  78. logger.setMessageOutputLevel(Project.MSG_INFO);
  79. project.addBuildListener(logger);
  80. }
  81. }