private void cleanupParentDir(File gitDir) throws java.io.IOException { final File parentDir = gitDir.getParentFile(); if (parentDir.isDirectory() && parentDirIsEmpty(parentDir) && !parentDir.equals(getGitRepoContainerDir())) { FileUtils.delete(parentDir, FileUtils.RECURSIVE | FileUtils.RETRY); } }
public void cleanup() { FileUtils.deleteQuietly(path); JGitFileSystemProvider gitFsProvider = (JGitFileSystemProvider) FileSystemProviders.resolveProvider(URI.create("git://whatever")); gitFsProvider.shutdown(); FileUtils.deleteQuietly(gitFsProvider.getGitRepoContainerDir()); }
@After public void destroyGitFsProvider() throws IOException { if (provider == null) { // this would mean that setup failed. no need to clean up. return; } provider.shutdown(); if (provider.getGitRepoContainerDir() != null && provider.getGitRepoContainerDir().exists()) { FileUtils.delete(provider.getGitRepoContainerDir(), FileUtils.RECURSIVE); } }
@After public void destroyGitFsProvider() throws IOException { if (provider == null) { // this would mean that setup failed. no need to clean up. return; } provider.shutdown(); if (provider.getGitRepoContainerDir() != null && provider.getGitRepoContainerDir().exists()) { FileUtils.delete(provider.getGitRepoContainerDir(), FileUtils.RECURSIVE); } }
@AfterClass public static void cleanup() { FileUtils.deleteQuietly(path); JGitFileSystemProvider gitFsProvider = (JGitFileSystemProvider) FileSystemProviders.resolveProvider(URI.create("git://whatever")); gitFsProvider.shutdown(); FileUtils.deleteQuietly(gitFsProvider.getGitRepoContainerDir()); System.clearProperty("org.uberfire.nio.git.dir"); }
@AfterClass public static void cleanup() { FileUtils.deleteQuietly(path); JGitFileSystemProvider gitFsProvider = (JGitFileSystemProvider) FileSystemProviders.resolveProvider(URI.create("git://whatever")); gitFsProvider.shutdown(); FileUtils.deleteQuietly(gitFsProvider.getGitRepoContainerDir()); System.clearProperty("org.uberfire.nio.git.dir"); }
@AfterClass public static void cleanup() { FileUtils.deleteQuietly(path); JGitFileSystemProvider gitFsProvider = (JGitFileSystemProvider) FileSystemProviders.resolveProvider(URI.create("git://whatever")); gitFsProvider.shutdown(); FileUtils.deleteQuietly(gitFsProvider.getGitRepoContainerDir()); }
@AfterClass public static void cleanup() { FileUtils.deleteQuietly(path); JGitFileSystemProvider gitFsProvider = (JGitFileSystemProvider) FileSystemProviders.resolveProvider(URI.create("git://whatever")); gitFsProvider.shutdown(); FileUtils.deleteQuietly(gitFsProvider.getGitRepoContainerDir()); }
@AfterClass public static void cleanup() { FileUtils.deleteQuietly(path); JGitFileSystemProvider gitFsProvider = (JGitFileSystemProvider) FileSystemProviders.resolveProvider(URI.create("git://whatever")); gitFsProvider.shutdown(); FileUtils.deleteQuietly(gitFsProvider.getGitRepoContainerDir()); }
@AfterClass public static void cleanup() { FileUtils.deleteQuietly(path); JGitFileSystemProvider gitFsProvider = (JGitFileSystemProvider) FileSystemProviders.resolveProvider(URI.create("git://whatever")); gitFsProvider.shutdown(); FileUtils.deleteQuietly(gitFsProvider.getGitRepoContainerDir()); }
@Test public void testCreateANewDirectoryWithMigrationEnv() { final Map<String, ?> envMigrate = new HashMap<String, Object>() {{ put("init", Boolean.TRUE); put("migrate-from", URI.create("git://old")); }}; String newPath = "git://test/old"; final URI newUri = URI.create(newPath); provider.newFileSystem(newUri, envMigrate); provider.getFileSystem(newUri); assertThat(new File(provider.getGitRepoContainerDir(), "test/old" + ".git")).exists(); assertThat(provider.getFileSystem(newUri)).isNotNull(); } }
@Test public void testCreateANewDirectoryWithMigrationEnv() { final Map<String, ?> envMigrate = new HashMap<String, Object>() {{ put("init", Boolean.TRUE); put("migrate-from", URI.create("git://old")); }}; String newPath = "git://test/old"; final URI newUri = URI.create(newPath); provider.newFileSystem(newUri, envMigrate); provider.getFileSystem(newUri); assertThat(new File(provider.getGitRepoContainerDir(), "test/old" + ".git")).exists(); assertThat(provider.getFileSystem(newUri)).isNotNull(); } }
@Test public void testForkRepository() throws GitAPIException { String SOURCE = "testforkA/source"; String TARGET = "testforkB/target"; final Map<String, ?> env = new HashMap<String, Object>() {{ put(JGitFileSystemProviderConfiguration.GIT_ENV_KEY_INIT, "true"); }}; String sourcePath = "git://" + SOURCE; final URI sourceUri = URI.create(sourcePath); provider.newFileSystem(sourceUri, env); final Map<String, ?> forkEnv = new HashMap<String, Object>() {{ put(JGitFileSystemProviderConfiguration.GIT_ENV_KEY_DEFAULT_REMOTE_NAME, SOURCE); }}; String forkPath = "git://" + TARGET; final URI forkUri = URI.create(forkPath); final JGitFileSystem fs = (JGitFileSystem) provider.newFileSystem(forkUri, forkEnv); assertThat(((GitImpl) fs.getGit())._remoteList().call().get(0).getURIs().get(0).toString()) .isEqualTo(new File(provider.getGitRepoContainerDir(), SOURCE + ".git").toPath().toUri().toString()); }
try { if (this.isForkOrigin(origin)) { git = Git.fork(this.getGitRepoContainerDir(), origin, fsName,
@Test public void testForkRepository() throws GitAPIException { String SOURCE = "testforkA/source"; String TARGET = "testforkB/target"; final Map<String, ?> env = new HashMap<String, Object>() {{ put(JGitFileSystemProviderConfiguration.GIT_ENV_KEY_INIT, "true"); }}; String sourcePath = "git://" + SOURCE; final URI sourceUri = URI.create(sourcePath); provider.newFileSystem(sourceUri, env); final Map<String, ?> forkEnv = new HashMap<String, Object>() {{ put(JGitFileSystemProviderConfiguration.GIT_ENV_KEY_DEFAULT_REMOTE_NAME, SOURCE); }}; String forkPath = "git://" + TARGET; final URI forkUri = URI.create(forkPath); final JGitFileSystem fs = (JGitFileSystem) provider.newFileSystem(forkUri, forkEnv); assertThat(((GitImpl) fs.getGit())._remoteList().call().get(0).getURIs().get(0).toString()) .isEqualTo(new File(provider.getGitRepoContainerDir(), SOURCE + ".git").toPath().toUri().toString()); }
@Test public void testCreateFileIntoRepositoryWithFolder() throws IOException, GitAPIException { final Map<String, ?> env = new HashMap<String, Object>() {{ put("init", Boolean.TRUE); }}; String oldPath = "git://test/old"; final URI oldUri = URI.create(oldPath); final JGitFileSystem fs = (JGitFileSystem) provider.newFileSystem(oldUri, env); final Path path = provider.getPath(URI.create("git://master@test/old/some/path/myfile.txt")); provider.setAttribute(path, FileSystemState.FILE_SYSTEM_STATE_ATTR, FileSystemState.BATCH); final OutputStream outStream = provider.newOutputStream(path); assertThat(outStream).isNotNull(); outStream.write(("my cool content").getBytes()); outStream.close(); assertThat(new File(provider.getGitRepoContainerDir(), "test/old" + ".git")).exists(); int commitsCount = 0; for (RevCommit com : ((GitImpl) fs.getGit())._log().all().call()) { commitsCount++; } }
@Test public void testCreateFileIntoRepositoryWithFolder() throws IOException, GitAPIException { final Map<String, ?> env = new HashMap<String, Object>() {{ put("init", Boolean.TRUE); }}; String oldPath = "git://test/old"; final URI oldUri = URI.create(oldPath); final JGitFileSystem fs = (JGitFileSystem) provider.newFileSystem(oldUri, env); final Path path = provider.getPath(URI.create("git://master@test/old/some/path/myfile.txt")); provider.setAttribute(path, FileSystemState.FILE_SYSTEM_STATE_ATTR, FileSystemState.BATCH); final OutputStream outStream = provider.newOutputStream(path); assertThat(outStream).isNotNull(); outStream.write(("my cool content").getBytes()); outStream.close(); assertThat(new File(provider.getGitRepoContainerDir(), "test/old" + ".git")).exists(); int commitsCount = 0; for (RevCommit com : ((GitImpl) fs.getGit())._log().all().call()) { commitsCount++; } }
@Test public void testDeleteShouldRemoveEmptyParentDir() throws IOException { final URI doraRepo = URI.create("git://parentDir/dora-repo"); FileSystem doraFS = provider.newFileSystem(doraRepo, EMPTY_ENV); final File doraRepoDir = ((JGitFileSystemProxy) doraFS).getGit().getRepository().getDirectory(); final File parentDir = doraRepoDir.getParentFile(); final File gitProviderDir = provider.getGitRepoContainerDir(); final URI doraRepo1 = URI.create("git://parentDir/dora-repo1"); FileSystem doraFS1 = provider.newFileSystem(doraRepo1, EMPTY_ENV); final File dora1RepoDir = ((JGitFileSystemProxy) doraFS1).getGit().getRepository().getDirectory(); final File parentDir1 = doraRepoDir.getParentFile(); assertEquals(parentDir, parentDir1); provider.delete(doraFS.getPath(null)); assertFalse(doraRepoDir.exists()); assertTrue(parentDir.exists()); assertTrue(gitProviderDir.exists()); provider.delete(doraFS1.getPath(null)); assertFalse(dora1RepoDir.exists()); assertFalse(parentDir1.exists()); assertTrue(gitProviderDir.exists()); }
@Test public void testDeleteShouldRemoveEmptyParentDir() throws IOException { final URI doraRepo = URI.create("git://parentDir/dora-repo"); FileSystem doraFS = provider.newFileSystem(doraRepo, EMPTY_ENV); final File doraRepoDir = ((JGitFileSystemProxy) doraFS).getGit().getRepository().getDirectory(); final File parentDir = doraRepoDir.getParentFile(); final File gitProviderDir = provider.getGitRepoContainerDir(); final URI doraRepo1 = URI.create("git://parentDir/dora-repo1"); FileSystem doraFS1 = provider.newFileSystem(doraRepo1, EMPTY_ENV); final File dora1RepoDir = ((JGitFileSystemProxy) doraFS1).getGit().getRepository().getDirectory(); final File parentDir1 = doraRepoDir.getParentFile(); assertEquals(parentDir, parentDir1); provider.delete(doraFS.getPath(null)); assertFalse(doraRepoDir.exists()); assertTrue(parentDir.exists()); assertTrue(gitProviderDir.exists()); provider.delete(doraFS1.getPath(null)); assertFalse(dora1RepoDir.exists()); assertFalse(parentDir1.exists()); assertTrue(gitProviderDir.exists()); }