Example usage for org.eclipse.jgit.util FS_POSIX FS_POSIX

List of usage examples for org.eclipse.jgit.util FS_POSIX FS_POSIX

Introduction

In this page you can find the example usage for org.eclipse.jgit.util FS_POSIX FS_POSIX.

Prototype

protected FS_POSIX() 

Source Link

Document

Default constructor.

Usage

From source file:org.uberfire.io.impl.BatchTest.java

License:Apache License

@Test
public void hooksShouldBeCalledOnBatch() throws IOException {

    final File hooksDir = CommonIOServiceDotFileTest.createTempDirectory();
    System.setProperty("org.uberfire.nio.git.hooks", hooksDir.getAbsolutePath());

    writeMockHook(hooksDir, "post-commit");

    JGitFileSystemProvider provider = (JGitFileSystemProvider) FileSystemProviders
            .resolveProvider(URI.create("git://hook-fs/"));

    final AtomicInteger postCommitHookCalled = new AtomicInteger();

    provider.setDetectedFS(new FS_POSIX() {
        @Override//from  w  w w.j av  a2 s. c o  m
        public ProcessResult runHookIfPresent(Repository repox, String hookName, String[] args)
                throws JGitInternalException {
            if (hookName.equals(PostCommitHook.NAME)) {
                postCommitHookCalled.incrementAndGet();
                return new ProcessResult(1, ProcessResult.Status.OK);
            }
            return new ProcessResult(ProcessResult.Status.NOT_PRESENT);
        }
    });

    ioService.newFileSystem(URI.create("git://hook-fs/"), new HashMap<>());

    Path init = ioService.get(URI.create("git://hook-fs/init.file"));

    ioService.write(init, "setupFS!");

    ioService.startBatch(init.getFileSystem());

    ioService.write(init, "onBatch!");

    ioService.endBatch();

    assertEquals(2, postCommitHookCalled.get());
}

From source file:org.uberfire.java.nio.fs.jgit.JGitFileSystemProviderHookTest.java

License:Apache License

/**
 * Tests if defined hook was executed or not.
 * @param gitRepoName Name of test git repository that is created for committing changes.
 * @param testedHookName Tested hook name. This hook is checked for its execution.
 * @param wasExecuted Expected hook execution state. If true, test expects that defined hook is executed.
 *                    If false, test expects that defined hook is not executed.
 * @throws IOException// w ww.  ja v a2s  . c o m
 */
private void testHook(final String gitRepoName, final String testedHookName, final boolean wasExecuted)
        throws IOException {
    final URI newRepo = URI.create("git://" + gitRepoName);

    final AtomicBoolean hookExecuted = new AtomicBoolean(false);
    final FileSystem fs = provider.newFileSystem(newRepo, EMPTY_ENV);

    provider.setDetectedFS(new FS_POSIX() {
        @Override
        public ProcessResult runHookIfPresent(Repository repox, String hookName, String[] args)
                throws JGitInternalException {
            if (hookName.equals(testedHookName)) {
                hookExecuted.set(true);
            }
            return null;
        }
    });

    assertThat(fs).isNotNull();

    final Path path = provider
            .getPath(URI.create("git://user_branch@" + gitRepoName + "/some/path/myfile.txt"));

    final OutputStream outStream = provider.newOutputStream(path);
    assertThat(outStream).isNotNull();
    outStream.write("my cool content".getBytes());
    outStream.close();

    final InputStream inStream = provider.newInputStream(path);

    final String content = new Scanner(inStream).useDelimiter("\\A").next();

    inStream.close();

    assertThat(content).isNotNull().isEqualTo("my cool content");

    if (wasExecuted) {
        assertThat(hookExecuted.get()).isTrue();
    } else {
        assertThat(hookExecuted.get()).isFalse();
    }
}