Search in sources :

Example 36 with RepositoryNotFoundException

use of org.eclipse.jgit.errors.RepositoryNotFoundException in project POL-POM-5 by PlayOnLinux.

the class GitRepository method fetchInstallableApplications.

@Override
public synchronized List<CategoryDTO> fetchInstallableApplications() {
    LOGGER.info(String.format("Begin fetching process of git-repository '%s' in '%s'", this.gitRepositoryUri, gitRepositoryLocation.getAbsolutePath()));
    boolean folderExists = gitRepositoryLocation.exists();
    // check that the repository folder exists
    if (!folderExists) {
        LOGGER.info(String.format("Creating new folder '%s' for git-repository '%s'", gitRepositoryLocation.getAbsolutePath(), this.gitRepositoryUri));
        if (!gitRepositoryLocation.mkdirs()) {
            LOGGER.error(String.format("Couldn't create folder for git repository '%s' at '%s'", this.gitRepositoryUri, gitRepositoryLocation.getAbsolutePath()));
            return Collections.emptyList();
        }
    }
    List<CategoryDTO> result = Collections.emptyList();
    try {
        Git gitRepository = null;
        /*
             * if the repository folder previously didn't exist, clone the
             * repository now
             */
        if (!folderExists) {
            LOGGER.info(String.format("Cloning git-repository '%s' to '%s'", this.gitRepositoryUri, gitRepositoryLocation.getAbsolutePath()));
            gitRepository = Git.cloneRepository().setURI(this.gitRepositoryUri.toString()).setDirectory(gitRepositoryLocation).call();
        } else /*
             * otherwise open the folder and pull the newest updates from the
             * repository
             */
        {
            LOGGER.info(String.format("Opening git-repository '%s' at '%s'", this.gitRepositoryUri, gitRepositoryLocation.getAbsolutePath()));
            gitRepository = Git.open(gitRepositoryLocation);
            LOGGER.info(String.format("Pulling new commits from git-repository '%s' to '%s'", this.gitRepositoryUri, gitRepositoryLocation.getAbsolutePath()));
            gitRepository.pull().call();
        }
        // close repository to free resources
        gitRepository.close();
        result = localRepositoryFactory.createInstance(this.gitRepositoryLocation, this.gitRepositoryUri).fetchInstallableApplications();
    } catch (RepositoryNotFoundException | GitAPIException e) {
        LOGGER.error(String.format("Folder '%s' is no git-repository", gitRepositoryLocation.getAbsolutePath()), e);
    } catch (IOException e) {
        LOGGER.error(String.format("An unknown error occured", e));
    }
    return result;
}
Also used : CategoryDTO(org.phoenicis.repository.dto.CategoryDTO) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Git(org.eclipse.jgit.api.Git) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) IOException(java.io.IOException)

Aggregations

RepositoryNotFoundException (org.eclipse.jgit.errors.RepositoryNotFoundException)36 Repository (org.eclipse.jgit.lib.Repository)20 IOException (java.io.IOException)17 Project (com.google.gerrit.reviewdb.client.Project)14 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)11 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)9 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)8 MetaDataUpdate (com.google.gerrit.server.git.MetaDataUpdate)7 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)7 AuthException (com.google.gerrit.extensions.restapi.AuthException)5 Change (com.google.gerrit.reviewdb.client.Change)5 Ref (org.eclipse.jgit.lib.Ref)5 RevWalk (org.eclipse.jgit.revwalk.RevWalk)5 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)4 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)4 NoSuchChangeException (com.google.gerrit.server.project.NoSuchChangeException)4 File (java.io.File)4 ObjectId (org.eclipse.jgit.lib.ObjectId)4 ProjectControl (com.google.gerrit.server.project.ProjectControl)3 ArrayList (java.util.ArrayList)3