use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.
the class EnqueueFileRepositoryJob method execute.
public void execute(JobExecutionContext context) throws JobExecutionException {
if (!Singleton.getSharedService().getBackgroundJobsEnabled()) {
return;
}
try {
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
UniqueRepoQueue repoQueue = Singleton.getUniqueFileRepoQueue();
// Get all of the repositories and enqueue them
List<RepoResult> repoResultList = Singleton.getRepo().getAllRepo();
Singleton.getLogger().info("Adding repositories to be indexed. " + repoResultList.size());
for (RepoResult rr : repoResultList) {
switch(rr.getScm().toLowerCase()) {
case "file":
Singleton.getLogger().info("Adding to FILE queue " + rr.getName() + " " + rr.getScm());
repoQueue.add(rr);
break;
default:
Singleton.getLogger().info("Unable to determine job type for " + rr.getName());
break;
}
}
} catch (Exception ex) {
}
}
use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.
the class EnqueueRepositoryJob method execute.
public void execute(JobExecutionContext context) throws JobExecutionException {
if (!Singleton.getSharedService().getBackgroundJobsEnabled()) {
return;
}
try {
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
UniqueRepoQueue repoGitQueue = Singleton.getUniqueGitRepoQueue();
UniqueRepoQueue repoSvnQueue = Singleton.getUniqueSvnRepoQueue();
// Get all of the repositories and enqueue them
List<RepoResult> repoResultList = Singleton.getRepo().getAllRepo();
Singleton.getLogger().info("Adding repositories to be indexed. " + repoResultList.size());
// Filter out those queued to be deleted
List<String> persistentDelete = Singleton.getDataService().getPersistentDelete();
List<RepoResult> collect = repoResultList.stream().filter(x -> !persistentDelete.contains(x.getName())).collect(Collectors.toList());
for (RepoResult rr : collect) {
switch(rr.getScm().toLowerCase()) {
case "git":
Singleton.getLogger().info("Adding to GIT queue " + rr.getName() + " " + rr.getScm());
repoGitQueue.add(rr);
break;
case "svn":
Singleton.getLogger().info("Adding to SVN queue " + rr.getName() + " " + rr.getScm());
repoSvnQueue.add(rr);
break;
default:
Singleton.getLogger().info("Unable to determine SCM type for " + rr.getName() + " " + rr.getScm());
break;
}
}
} catch (Exception ex) {
}
}
use of com.searchcode.app.model.RepoResult 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.model.RepoResult in project searchcode-server by boyter.
the class Repo method getPagedRepo.
@Override
public synchronized List<RepoResult> getPagedRepo(int offset, int pageSize) {
List<RepoResult> repoResults = new ArrayList<>();
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = this.dbConfig.getConnection();
stmt = conn.prepareStatement("select rowid,name,scm,url,username,password,source,branch,data from repo order by rowid desc limit ?, ?;");
stmt.setInt(1, offset);
stmt.setInt(2, pageSize);
rs = stmt.executeQuery();
while (rs.next()) {
int rowId = rs.getInt("rowid");
String repoName = rs.getString("name");
String repoScm = rs.getString("scm");
String repoUrl = rs.getString("url");
String repoUsername = rs.getString("username");
String repoPassword = rs.getString("password");
String repoSource = rs.getString("source");
String repoBranch = rs.getString("branch");
String repoData = rs.getString("data");
repoResults.add(new RepoResult(rowId, repoName, repoScm, repoUrl, repoUsername, repoPassword, repoSource, repoBranch, repoData));
}
} catch (SQLException ex) {
Singleton.getLogger().severe(" caught a " + ex.getClass() + "\n with message: " + ex.getMessage());
} finally {
Singleton.getHelpers().closeQuietly(rs);
Singleton.getHelpers().closeQuietly(stmt);
}
return repoResults;
}
use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.
the class Repo method searchRepo.
@Override
public synchronized List<RepoResult> searchRepo(String searchTerms) {
List<RepoResult> repoResults = this.getAllRepo();
List<RepoResult> matchRepoResults = new ArrayList<RepoResult>();
String[] split = searchTerms.toLowerCase().split(" ");
for (RepoResult rr : repoResults) {
boolean isMatch = false;
for (String term : split) {
if (rr.toString().toLowerCase().contains(term)) {
isMatch = true;
} else {
isMatch = false;
}
}
if (isMatch) {
matchRepoResults.add(rr);
}
}
if (matchRepoResults.size() > 100) {
matchRepoResults = matchRepoResults.subList(0, 100);
}
return matchRepoResults;
}
Aggregations