Search in sources :

Example 1 with IndexFileRepoJob

use of com.searchcode.app.jobs.repository.IndexFileRepoJob in project searchcode-server by boyter.

the class AdminRouteService method checkIndexStatus.

public String checkIndexStatus(Request request, Response response) {
    if (request.queryParams().contains("reponame")) {
        String reponame = request.queryParams("reponame");
        String reposLocation = Properties.getProperties().getProperty(Values.REPOSITORYLOCATION, Values.DEFAULTREPOSITORYLOCATION);
        IndexBaseRepoJob indexBaseRepoJob = new IndexFileRepoJob();
        RepoResult repoResult = Singleton.getRepo().getRepoByName(reponame);
        String indexStatus = Values.EMPTYSTRING;
        if (repoResult != null) {
            indexStatus = repoResult.getData().indexStatus;
        }
        if (indexBaseRepoJob.checkIndexSucess(reposLocation + "/" + reponame) || "success".equals(indexStatus)) {
            return "Indexed ✓";
        }
        if ("indexing".equals(indexStatus)) {
            return "Indexing...";
        }
    }
    return Values.EMPTYSTRING;
}
Also used : IndexFileRepoJob(com.searchcode.app.jobs.repository.IndexFileRepoJob) IndexBaseRepoJob(com.searchcode.app.jobs.repository.IndexBaseRepoJob) RepoResult(com.searchcode.app.model.RepoResult)

Example 2 with IndexFileRepoJob

use of com.searchcode.app.jobs.repository.IndexFileRepoJob in project searchcode-server by boyter.

the class IndexFileRepoJobTest method testGetCodeOwner.

public void testGetCodeOwner() {
    IndexFileRepoJob fileRepoJob = new IndexFileRepoJob();
    String codeOwner = fileRepoJob.getCodeOwner(null, null, null, null, null);
    assertThat(codeOwner).isEqualTo("File System");
}
Also used : IndexFileRepoJob(com.searchcode.app.jobs.repository.IndexFileRepoJob)

Example 3 with IndexFileRepoJob

use of com.searchcode.app.jobs.repository.IndexFileRepoJob in project searchcode-server by boyter.

the class IndexFileRepoJobTest method testGetFileLocationFilename.

public void testGetFileLocationFilename() {
    IndexFileRepoJob fileRepoJob = new IndexFileRepoJob();
    fileRepoJob.repoName = "repo";
    String fileLocationFilename = fileRepoJob.getFileLocationFilename(".git/filename", "./repo/");
    assertThat(fileLocationFilename).isEqualTo("repo.git/filename");
    fileLocationFilename = fileRepoJob.getFileLocationFilename("./repo/.git/filename", "./repo/");
    assertThat(fileLocationFilename).isEqualTo("repo.git/filename");
}
Also used : IndexFileRepoJob(com.searchcode.app.jobs.repository.IndexFileRepoJob)

Example 4 with IndexFileRepoJob

use of com.searchcode.app.jobs.repository.IndexFileRepoJob in project searchcode-server by boyter.

the class EndToEndITCase method testEndToEndFilePath.

public void testEndToEndFilePath() throws IOException {
    CodeSearcher cs = new CodeSearcher();
    File directoryWithFiles = TestHelpers.createDirectoryWithFiles("EndToEndFileTest");
    IndexFileRepoJob indexFileRepoJob = new IndexFileRepoJob();
    // Index created files
    indexFileRepoJob.indexDocsByPath(Paths.get(directoryWithFiles.toString()), "ENDTOENDTEST", "", directoryWithFiles.toString(), false);
    SearchResult searchResult = cs.search("endtoendtestfile", 0);
    assertThat(searchResult.getCodeResultList().size()).isEqualTo(3);
    CodeResult codeResult1 = searchResult.getCodeResultList().stream().filter(x -> x.getFileName().equals("EndToEndTestFile1.php")).findFirst().get();
    CodeResult codeResult2 = searchResult.getCodeResultList().stream().filter(x -> x.getFileName().equals("EndToEndTestFile2.py")).findFirst().get();
    CodeResult codeResult3 = searchResult.getCodeResultList().stream().filter(x -> x.getFileName().equals("EndToEndTestFile3.java")).findFirst().get();
    assertThat(codeResult1.getCode().get(0)).isEqualTo("EndToEndTestFile EndToEndTestFile1");
    assertThat(codeResult2.getCode().get(0)).isEqualTo("EndToEndTestFile EndToEndTestFile2");
    assertThat(codeResult3.getCode().get(0)).isEqualTo("EndToEndTestFile EndToEndTestFile3");
    // Delete a single file
    String codeId = searchResult.getCodeResultList().get(0).getCodeId();
    Singleton.getCodeIndexer().deleteByCodeId(codeId);
    searchResult = cs.search("endtoendtestfile".toLowerCase(), 0);
    assertThat(searchResult.getCodeResultList().size()).isEqualTo(2);
    codeResult1 = searchResult.getCodeResultList().stream().filter(x -> x.getFileName().equals("EndToEndTestFile2.py")).findFirst().get();
    codeResult2 = searchResult.getCodeResultList().stream().filter(x -> x.getFileName().equals("EndToEndTestFile3.java")).findFirst().get();
    assertThat(codeResult1.getCode().get(0)).isEqualTo("EndToEndTestFile EndToEndTestFile2");
    assertThat(codeResult2.getCode().get(0)).isEqualTo("EndToEndTestFile EndToEndTestFile3");
    // Delete file from disk then index to ensure it is removed from the index
    File toDelete = new File(directoryWithFiles.toString() + "/EndToEndTestFile2.py");
    toDelete.delete();
    indexFileRepoJob.indexDocsByPath(Paths.get(directoryWithFiles.toString()), "ENDTOENDTEST", "", directoryWithFiles.toString(), true);
    searchResult = cs.search("endtoendtestfile", 0);
    assertThat(searchResult.getCodeResultList().size()).isEqualTo(2);
    codeResult1 = searchResult.getCodeResultList().stream().filter(x -> x.getFileName().equals("EndToEndTestFile1.php")).findFirst().get();
    codeResult2 = searchResult.getCodeResultList().stream().filter(x -> x.getFileName().equals("EndToEndTestFile3.java")).findFirst().get();
    assertThat(codeResult1.getCode().get(0)).isEqualTo("EndToEndTestFile EndToEndTestFile1");
    assertThat(codeResult2.getCode().get(0)).isEqualTo("EndToEndTestFile EndToEndTestFile3");
    // Delete everything
    Singleton.getCodeIndexer().deleteByReponame("ENDTOENDTEST");
    searchResult = cs.search("endtoendtestfile".toLowerCase(), 0);
    assertThat(searchResult.getCodeResultList().size()).isEqualTo(0);
}
Also used : IndexFileRepoJob(com.searchcode.app.jobs.repository.IndexFileRepoJob) IndexSvnRepoJob(com.searchcode.app.jobs.repository.IndexSvnRepoJob) SearchResult(com.searchcode.app.dto.SearchResult) Singleton(com.searchcode.app.service.Singleton) RepositoryChanged(com.searchcode.app.dto.RepositoryChanged) FileUtils(org.apache.commons.io.FileUtils) IndexGitRepoJob(com.searchcode.app.jobs.repository.IndexGitRepoJob) TestHelpers(com.searchcode.app.TestHelpers) Values(com.searchcode.app.config.Values) CodeIndexer(com.searchcode.app.service.CodeIndexer) CodeResult(com.searchcode.app.dto.CodeResult) CodeSearcher(com.searchcode.app.service.CodeSearcher) java.io(java.io) Paths(java.nio.file.Paths) AssertionsForInterfaceTypes.assertThat(org.assertj.core.api.AssertionsForInterfaceTypes.assertThat) Properties(com.searchcode.app.util.Properties) TestCase(junit.framework.TestCase) IndexFileRepoJob(com.searchcode.app.jobs.repository.IndexFileRepoJob) Path(java.nio.file.Path) CodeResult(com.searchcode.app.dto.CodeResult) SearchResult(com.searchcode.app.dto.SearchResult) CodeSearcher(com.searchcode.app.service.CodeSearcher)

Aggregations

IndexFileRepoJob (com.searchcode.app.jobs.repository.IndexFileRepoJob)4 TestHelpers (com.searchcode.app.TestHelpers)1 Values (com.searchcode.app.config.Values)1 CodeResult (com.searchcode.app.dto.CodeResult)1 RepositoryChanged (com.searchcode.app.dto.RepositoryChanged)1 SearchResult (com.searchcode.app.dto.SearchResult)1 IndexBaseRepoJob (com.searchcode.app.jobs.repository.IndexBaseRepoJob)1 IndexGitRepoJob (com.searchcode.app.jobs.repository.IndexGitRepoJob)1 IndexSvnRepoJob (com.searchcode.app.jobs.repository.IndexSvnRepoJob)1 RepoResult (com.searchcode.app.model.RepoResult)1 CodeIndexer (com.searchcode.app.service.CodeIndexer)1 CodeSearcher (com.searchcode.app.service.CodeSearcher)1 Singleton (com.searchcode.app.service.Singleton)1 Properties (com.searchcode.app.util.Properties)1 java.io (java.io)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 TestCase (junit.framework.TestCase)1 FileUtils (org.apache.commons.io.FileUtils)1 AssertionsForInterfaceTypes.assertThat (org.assertj.core.api.AssertionsForInterfaceTypes.assertThat)1