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());
}
}
}
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);
}
Aggregations