Search in sources :

Example 31 with RepoResult

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) {
    }
}
Also used : UniqueRepoQueue(com.searchcode.app.util.UniqueRepoQueue) RepoResult(com.searchcode.app.model.RepoResult)

Example 32 with RepoResult

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) {
    }
}
Also used : List(java.util.List) Singleton(com.searchcode.app.service.Singleton) RepoResult(com.searchcode.app.model.RepoResult) Collectors(java.util.stream.Collectors) UniqueRepoQueue(com.searchcode.app.util.UniqueRepoQueue) org.quartz(org.quartz) UniqueRepoQueue(com.searchcode.app.util.UniqueRepoQueue) RepoResult(com.searchcode.app.model.RepoResult)

Example 33 with RepoResult

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());
        }
    }
}
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 34 with RepoResult

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;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) RepoResult(com.searchcode.app.model.RepoResult)

Example 35 with RepoResult

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;
}
Also used : ArrayList(java.util.ArrayList) RepoResult(com.searchcode.app.model.RepoResult)

Aggregations

RepoResult (com.searchcode.app.model.RepoResult)59 Repo (com.searchcode.app.dao.Repo)13 ApiResponse (com.searchcode.app.dto.api.ApiResponse)9 RepoResultApiResponse (com.searchcode.app.dto.api.RepoResultApiResponse)9 Request (spark.Request)9 ValidatorResult (com.searchcode.app.model.ValidatorResult)8 ApiRouteService (com.searchcode.app.service.route.ApiRouteService)8 UniqueRepoQueue (com.searchcode.app.util.UniqueRepoQueue)8 Connection (java.sql.Connection)5 PreparedStatement (java.sql.PreparedStatement)5 SQLException (java.sql.SQLException)5 ResultSet (java.sql.ResultSet)4 ArrayList (java.util.ArrayList)3 RepositoryChanged (com.searchcode.app.dto.RepositoryChanged)2 RunningIndexJob (com.searchcode.app.dto.RunningIndexJob)2 File (java.io.File)2 Gson (com.google.gson.Gson)1 Data (com.searchcode.app.dao.Data)1 IndexBaseRepoJob (com.searchcode.app.jobs.repository.IndexBaseRepoJob)1 IndexFileRepoJob (com.searchcode.app.jobs.repository.IndexFileRepoJob)1