Search in sources :

Example 6 with RepositoryChanged

use of com.searchcode.app.dto.RepositoryChanged in project searchcode-server by boyter.

the class IndexBaseRepoJob method execute.

/**
     * The main method used for finding jobs to index and actually doing the work
     */
public void execute(JobExecutionContext context) throws JobExecutionException {
    Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
    JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
    this.LOWMEMORY = Boolean.parseBoolean(jobDataMap.get("LOWMEMORY").toString());
    String repoLocations = jobDataMap.get("REPOLOCATIONS").toString();
    if (!isEnabled() || !this.sharedService.getBackgroundJobsEnabled()) {
        return;
    }
    if (this.codeIndexer.shouldPauseAdding()) {
        Singleton.getLogger().info("Pausing parser.");
        return;
    }
    // Pull the next repo to index from the queue
    RepoResult repoResult = this.getNextQueuedRepo().poll();
    if (repoResult != null && Singleton.getRunningIndexRepoJobs().containsKey(repoResult.getName()) == false) {
        this.haveRepoResult = true;
        Singleton.getLogger().info("Indexing " + repoResult.getName());
        repoResult.getData().indexStatus = "indexing";
        repoResult.getData().jobRunTime = Instant.now();
        Singleton.getRepo().saveRepo(repoResult);
        try {
            Singleton.getRunningIndexRepoJobs().put(repoResult.getName(), new RunningIndexJob("Indexing", Singleton.getHelpers().getCurrentTimeSeconds()));
            this.checkCloneSuccess(repoResult.getName(), repoLocations);
            String repoGitLocation = repoLocations + "/" + repoResult.getName() + "/.git/";
            File file = new File(repoGitLocation);
            boolean existingRepo = file.exists();
            boolean useCredentials = repoResult.getUsername() != null && !repoResult.getUsername().isEmpty();
            RepositoryChanged repositoryChanged;
            if (existingRepo) {
                repositoryChanged = this.updateExistingRepository(repoResult.getName(), repoResult.getUrl(), repoResult.getUsername(), repoResult.getPassword(), repoLocations, repoResult.getBranch(), useCredentials);
            } else {
                repositoryChanged = this.getNewRepository(repoResult.getName(), repoResult.getUrl(), repoResult.getUsername(), repoResult.getPassword(), repoLocations, repoResult.getBranch(), useCredentials);
            }
            // Write file indicating we have sucessfully cloned
            this.createCloneUpdateSuccess(repoLocations + "/" + repoResult.getName());
            this.triggerIndex(repoResult, repoResult.getName(), repoResult.getUrl(), repoLocations, repoGitLocation, existingRepo, repositoryChanged);
        } finally {
            // Clean up the job
            Singleton.getRunningIndexRepoJobs().remove(repoResult.getName());
        }
    }
}
Also used : RunningIndexJob(com.searchcode.app.dto.RunningIndexJob) RepositoryChanged(com.searchcode.app.dto.RepositoryChanged) JobDataMap(org.quartz.JobDataMap) File(java.io.File) RepoResult(com.searchcode.app.model.RepoResult)

Example 7 with RepositoryChanged

use of com.searchcode.app.dto.RepositoryChanged in project searchcode-server by boyter.

the class EndToEndITCase method testEndToEndGitDelta.

public void testEndToEndGitDelta() throws IOException {
    CodeSearcher cs = new CodeSearcher();
    IndexGitRepoJob indexGitRepoJob = new IndexGitRepoJob();
    File directoryWithFiles = TestHelpers.createDirectoryWithFiles("EndToEndGitTest");
    this.runCommand(directoryWithFiles.toString(), this.GITPATH, "init", ".");
    this.runCommand(directoryWithFiles.toString(), this.GITPATH, "add", ".");
    this.runCommand(directoryWithFiles.toString(), this.GITPATH, "commit", "-m", "\"First commit\"");
    // Clone from the above into a new directory
    File tempPath = TestHelpers.clearAndCreateTempPath("EndToEndGitCloneTest");
    this.runCommand(tempPath.toString(), this.GITPATH, "clone", directoryWithFiles.toString(), "EndToEndGitTest");
    // Index
    indexGitRepoJob.indexDocsByPath(Paths.get(tempPath.toString()), "EndToEndGitTest", "", tempPath.toString(), false);
    SearchResult searchResult = cs.search("endtoendtestfile", 0);
    assertThat(searchResult.getCodeResultList().size()).isEqualTo(3);
    // Update the source
    TestHelpers.createFile(directoryWithFiles, "EndToEndTestFile4.cpp", "EndToEndTestFile EndToEndTestFile4");
    this.runCommand(directoryWithFiles.toString(), this.GITPATH, "add", ".");
    this.runCommand(directoryWithFiles.toString(), this.GITPATH, "commit", "-m", "\"Add new\"");
    // Index and lets dance
    RepositoryChanged repositoryChanged = indexGitRepoJob.updateExistingRepository("EndToEndGitTest", "repoRemoteLocation", "", "", tempPath.toString(), "", false);
    String repoGitLocation = tempPath.toString() + "/" + "EndToEndGitTest";
    Path docDir = Paths.get(repoGitLocation);
    indexGitRepoJob.indexDocsByDelta(docDir, "EndToEndGitTest", tempPath.toString(), "", repositoryChanged);
    searchResult = cs.search("endtoendtestfile", 0);
    assertThat(searchResult.getCodeResultList().size()).isEqualTo(4);
    // Update the source
    this.runCommand(directoryWithFiles.toString(), this.GITPATH, "rm", "EndToEndTestFile4.cpp");
    this.runCommand(directoryWithFiles.toString(), this.GITPATH, "commit", "-m", "\"Baleted\"");
    // Index and lets dance
    repositoryChanged = indexGitRepoJob.updateExistingRepository("EndToEndGitTest", "repoRemoteLocation", "", "", tempPath.toString(), "", false);
    repoGitLocation = tempPath.toString() + "/" + "EndToEndGitTest";
    docDir = Paths.get(repoGitLocation);
    indexGitRepoJob.indexDocsByDelta(docDir, "EndToEndGitTest", tempPath.toString(), "", repositoryChanged);
    searchResult = cs.search("endtoendtestfile", 0);
    assertThat(searchResult.getCodeResultList().size()).isEqualTo(3);
    Singleton.getCodeIndexer().deleteByReponame("EndToEndGitTest");
    searchResult = cs.search("endtoendtestfile".toLowerCase(), 0);
    assertThat(searchResult.getCodeResultList().size()).isEqualTo(0);
}
Also used : Path(java.nio.file.Path) RepositoryChanged(com.searchcode.app.dto.RepositoryChanged) SearchResult(com.searchcode.app.dto.SearchResult) CodeSearcher(com.searchcode.app.service.CodeSearcher) IndexGitRepoJob(com.searchcode.app.jobs.repository.IndexGitRepoJob)

Aggregations

RepositoryChanged (com.searchcode.app.dto.RepositoryChanged)7 IndexGitRepoJob (com.searchcode.app.jobs.repository.IndexGitRepoJob)2 RepoResult (com.searchcode.app.model.RepoResult)2 InvalidPathException (java.nio.file.InvalidPathException)2 Git (org.eclipse.jgit.api.Git)2 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)2 UsernamePasswordCredentialsProvider (org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider)2 RunningIndexJob (com.searchcode.app.dto.RunningIndexJob)1 SearchResult (com.searchcode.app.dto.SearchResult)1 CodeSearcher (com.searchcode.app.service.CodeSearcher)1 SharedService (com.searchcode.app.service.SharedService)1 UniqueRepoQueue (com.searchcode.app.util.UniqueRepoQueue)1 File (java.io.File)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 CloneCommand (org.eclipse.jgit.api.CloneCommand)1 PullCommand (org.eclipse.jgit.api.PullCommand)1