Example usage for org.eclipse.jgit.lib Repository close

List of usage examples for org.eclipse.jgit.lib Repository close

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Repository close.

Prototype

@Override
public void close() 

Source Link

Document

Decrement the use count, and maybe close resources.

Usage

From source file:com.gitblit.tests.JGitUtilsTest.java

License:Apache License

@Test
public void testDocuments() throws Exception {
    Repository repository = GitBlitSuite.getTicgitRepository();
    List<String> extensions = Arrays.asList(new String[] { ".mkd", ".md" });
    List<PathModel> markdownDocs = JGitUtils.getDocuments(repository, extensions);
    List<PathModel> allFiles = JGitUtils.getDocuments(repository, null);
    repository.close();
    assertTrue(markdownDocs.size() > 0);
    assertTrue(allFiles.size() > markdownDocs.size());
}

From source file:com.gitblit.tests.JGitUtilsTest.java

License:Apache License

@Test
public void testRevlog() throws Exception {
    assertTrue(JGitUtils.getRevLog(null, 0).size() == 0);
    List<RevCommit> commits = JGitUtils.getRevLog(null, 10);
    assertEquals(0, commits.size());//from w ww  .  ja v  a 2s  . c om

    Repository repository = GitBlitSuite.getHelloworldRepository();
    // get most recent 10 commits
    commits = JGitUtils.getRevLog(repository, 10);
    assertEquals(10, commits.size());

    // test paging and offset by getting the 10th most recent commit
    RevCommit lastCommit = JGitUtils.getRevLog(repository, null, 9, 1).get(0);
    assertEquals(lastCommit, commits.get(9));

    // grab the two most recent commits to java.java
    commits = JGitUtils.getRevLog(repository, null, "java.java", 0, 2);
    assertEquals(2, commits.size());

    // grab the commits since 2008-07-15
    commits = JGitUtils.getRevLog(repository, null, new SimpleDateFormat("yyyy-MM-dd").parse("2008-07-15"));
    assertEquals(12, commits.size());
    repository.close();
}

From source file:com.gitblit.tests.JGitUtilsTest.java

License:Apache License

@Test
public void testRevLogRange() throws Exception {
    Repository repository = GitBlitSuite.getHelloworldRepository();
    List<RevCommit> commits = JGitUtils.getRevLog(repository, "fbd14fa6d1a01d4aefa1fca725792683800fc67e",
            "85a0e4087b8439c0aa6b1f4f9e08c26052ab7e87");
    repository.close();
    assertEquals(14, commits.size());//from w  ww  .  ja v  a  2s.  c om
}

From source file:com.gitblit.tests.JGitUtilsTest.java

License:Apache License

@Test
public void testSearchRevlogs() throws Exception {
    assertEquals(0, JGitUtils.searchRevlogs(null, null, "java", SearchType.COMMIT, 0, 0).size());
    List<RevCommit> results = JGitUtils.searchRevlogs(null, null, "java", SearchType.COMMIT, 0, 3);
    assertEquals(0, results.size());//from  w w  w.ja  v  a 2 s.  c om

    // test commit message search
    Repository repository = GitBlitSuite.getHelloworldRepository();
    results = JGitUtils.searchRevlogs(repository, null, "java", SearchType.COMMIT, 0, 3);
    assertEquals(3, results.size());

    // test author search
    results = JGitUtils.searchRevlogs(repository, null, "timothy", SearchType.AUTHOR, 0, -1);
    assertEquals(1, results.size());

    // test committer search
    results = JGitUtils.searchRevlogs(repository, null, "mike", SearchType.COMMITTER, 0, 10);
    assertEquals(10, results.size());

    // test paging and offset
    RevCommit commit = JGitUtils.searchRevlogs(repository, null, "mike", SearchType.COMMITTER, 9, 1).get(0);
    assertEquals(results.get(9), commit);

    repository.close();
}

From source file:com.gitblit.tests.JGitUtilsTest.java

License:Apache License

@Test
public void testZip() throws Exception {
    assertFalse(CompressionUtils.zip(null, null, null, null, null));
    Repository repository = GitBlitSuite.getHelloworldRepository();
    File zipFileA = new File(GitBlitSuite.REPOSITORIES, "helloworld.zip");
    FileOutputStream fosA = new FileOutputStream(zipFileA);
    boolean successA = CompressionUtils.zip(repository, null, null, Constants.HEAD, fosA);
    fosA.close();//w  w  w  .ja  v a2s .  c  om

    File zipFileB = new File(GitBlitSuite.REPOSITORIES, "helloworld-java.zip");
    FileOutputStream fosB = new FileOutputStream(zipFileB);
    boolean successB = CompressionUtils.zip(repository, null, "java.java", Constants.HEAD, fosB);
    fosB.close();

    repository.close();
    assertTrue("Failed to generate zip file!", successA);
    assertTrue(zipFileA.length() > 0);
    zipFileA.delete();

    assertTrue("Failed to generate zip file!", successB);
    assertTrue(zipFileB.length() > 0);
    zipFileB.delete();
}

From source file:com.gitblit.tests.JGitUtilsTest.java

License:Apache License

@Test
public void testPlots() throws Exception {
    Repository repository = GitBlitSuite.getTicgitRepository();
    PlotWalk pw = new PlotWalk(repository);
    PlotCommitList<PlotLane> commits = new PlotCommitList<PlotLane>();
    commits.source(pw);/*from  www.  j av a2s .c  o m*/
    commits.fillTo(25);
    for (PlotCommit<PlotLane> commit : commits) {
        System.out.println(commit);
    }
    repository.close();
}

From source file:com.gitblit.tests.JnaUtilsTest.java

License:Apache License

@Test
public void testGetFilemode() throws IOException {
    if (JnaUtils.isWindows()) {
        try {//ww w.jav a 2  s  . c  om
            JnaUtils.getFilemode(GitBlitSuite.REPOSITORIES);
        } catch (UnsupportedOperationException e) {
        }
    } else {
        String repositoryName = "NewJnaTestRepository.git";
        Repository repository = JGitUtils.createRepository(GitBlitSuite.REPOSITORIES, repositoryName);
        File folder = FileKey.resolve(new File(GitBlitSuite.REPOSITORIES, repositoryName), FS.DETECTED);
        assertTrue(folder.exists());

        int mode = JnaUtils.getFilemode(folder);
        assertTrue(mode > 0);
        assertEquals(JnaUtils.S_IFDIR, (mode & JnaUtils.S_IFMT)); // directory
        assertEquals(JnaUtils.S_IRUSR | JnaUtils.S_IWUSR | JnaUtils.S_IXUSR, (mode & JnaUtils.S_IRWXU)); // owner full access

        mode = JnaUtils.getFilemode(folder.getAbsolutePath() + "/config");
        assertTrue(mode > 0);
        assertEquals(JnaUtils.S_IFREG, (mode & JnaUtils.S_IFMT)); // directory
        assertEquals(JnaUtils.S_IRUSR | JnaUtils.S_IWUSR, (mode & JnaUtils.S_IRWXU)); // owner full access

        repository.close();
        RepositoryCache.close(repository);
        FileUtils.deleteDirectory(repository.getDirectory());
    }
}

From source file:com.gitblit.tests.JnaUtilsTest.java

License:Apache License

@Test
public void testSetFilemode() throws IOException {
    if (JnaUtils.isWindows()) {
        try {//from  ww  w.  j av  a2  s. co m
            JnaUtils.getFilemode(GitBlitSuite.REPOSITORIES);
        } catch (UnsupportedOperationException e) {
        }
    } else {
        String repositoryName = "NewJnaTestRepository.git";
        Repository repository = JGitUtils.createRepository(GitBlitSuite.REPOSITORIES, repositoryName);
        File folder = FileKey.resolve(new File(GitBlitSuite.REPOSITORIES, repositoryName), FS.DETECTED);
        assertTrue(folder.exists());

        File path = new File(folder, "refs");
        int mode = JnaUtils.getFilemode(path);
        assertTrue(mode > 0);
        assertEquals(JnaUtils.S_IFDIR, (mode & JnaUtils.S_IFMT)); // directory
        assertEquals(JnaUtils.S_IRUSR | JnaUtils.S_IWUSR | JnaUtils.S_IXUSR, (mode & JnaUtils.S_IRWXU)); // owner full access

        mode |= JnaUtils.S_ISGID;
        mode |= JnaUtils.S_IRWXG;
        int ret = JnaUtils.setFilemode(path, mode);
        assertEquals(0, ret);
        mode = JnaUtils.getFilemode(path);
        assertTrue(mode > 0);
        assertEquals(JnaUtils.S_ISGID, (mode & JnaUtils.S_ISGID)); // set-gid-bit set
        assertEquals(JnaUtils.S_IRGRP | JnaUtils.S_IWGRP | JnaUtils.S_IXGRP, (mode & JnaUtils.S_IRWXG)); // group full access

        path = new File(folder, "config");
        mode = JnaUtils.getFilemode(path.getAbsolutePath());
        assertTrue(mode > 0);
        assertEquals(JnaUtils.S_IFREG, (mode & JnaUtils.S_IFMT)); // directory
        assertEquals(JnaUtils.S_IRUSR | JnaUtils.S_IWUSR, (mode & JnaUtils.S_IRWXU)); // owner full access

        mode |= (JnaUtils.S_IRGRP | JnaUtils.S_IWGRP);
        ret = JnaUtils.setFilemode(path.getAbsolutePath(), mode);
        assertEquals(0, ret);
        mode = JnaUtils.getFilemode(path.getAbsolutePath());
        assertTrue(mode > 0);
        assertEquals(JnaUtils.S_IRGRP | JnaUtils.S_IWGRP, (mode & JnaUtils.S_IRWXG)); // group full access

        repository.close();
        RepositoryCache.close(repository);
        FileUtils.deleteDirectory(repository.getDirectory());
    }
}

From source file:com.gitblit.tests.LuceneExecutorTest.java

License:Apache License

@Test
public void testIndex() {
    // reindex helloworld
    Repository repository = GitBlitSuite.getHelloworldRepository();
    RepositoryModel model = newRepositoryModel(repository);
    lucene.reindex(model, repository);/*from w w  w.  j  a  v  a  2 s .  c o m*/
    repository.close();

    SearchResult result = lucene.search("type:blob AND path:bit.bit", 1, 1, model.name).get(0);
    assertEquals("Mike Donaghy", result.author);
    result = lucene.search("type:blob AND path:clipper.prg", 1, 1, model.name).get(0);
    assertEquals("tinogomes", result.author);

    // reindex JGit
    repository = GitBlitSuite.getJGitRepository();
    model = newRepositoryModel(repository);
    lucene.reindex(model, repository);
    repository.close();
}

From source file:com.gitblit.tests.LuceneExecutorTest.java

License:Apache License

@Test
public void testQuery() throws Exception {
    // 2 occurrences on the master branch
    Repository repository = GitBlitSuite.getHelloworldRepository();
    RepositoryModel model = newRepositoryModel(repository);
    repository.close();

    List<SearchResult> results = lucene.search("ada", 1, 10, model.name);
    assertEquals(2, results.size());//from w  w  w  .j av  a2 s.  co m
    for (SearchResult res : results) {
        assertEquals("refs/heads/master", res.branch);
    }

    // author test
    results = lucene.search("author: tinogomes AND type:commit", 1, 10, model.name);
    assertEquals(2, results.size());

    // blob test
    results = lucene.search("type: blob AND \"import std.stdio\"", 1, 10, model.name);
    assertEquals(1, results.size());
    assertEquals("d.D", results.get(0).path);

    // commit test
    repository = GitBlitSuite.getJGitRepository();
    model = newRepositoryModel(repository);
    repository.close();

    results = lucene.search("\"initial jgit contribution to eclipse.org\"", 1, 10, model.name);
    assertEquals(1, results.size());
    assertEquals("Git Development Community", results.get(0).author);
    assertEquals("1a6964c8274c50f0253db75f010d78ef0e739343", results.get(0).commitId);
    assertEquals("refs/heads/master", results.get(0).branch);

    // hash id tests
    results = lucene.search("type:commit AND commit:1a6964c8274c50f0253db75f010d78ef0e739343", 1, 10,
            model.name);
    assertEquals(1, results.size());

    results = lucene.search("type:commit AND commit:1a6964c8274*", 1, 10, model.name);
    assertEquals("Shawn O. Pearce", results.get(0).committer);
    assertEquals(1, results.size());

    // annotated tag test
    results = lucene.search("I663208919f297836a9c16bf458e4a43ffaca4c12", 1, 10, model.name);
    assertEquals(1, results.size());
    assertEquals("[v1.3.0.201202151440-r]", results.get(0).tags.toString());
}