Search in sources :

Example 1 with PushPolicyResult

use of io.fabric8.git.PullPushPolicy.PushPolicyResult in project fabric8 by jboss-fuse.

the class DummyBatchingProgressMonitor method executeInternal.

private <T> T executeInternal(GitContext context, PersonIdent personIdent, GitOperation<T> operation) {
    if (context.isRequirePull() || context.isRequireCommit()) {
        assertWriteLock();
    } else {
        assertReadLock();
    }
    // [FABRIC-887] Must set the TCCL to the classloader that loaded GitDataStore as we need the classloader
    // that could load this class, as jgit will load resources from classpath using the TCCL
    // and that requires the TCCL to the classloader that could load GitDataStore as the resources
    // jgit requires are in the same bundle as GitDataSource (eg embedded inside fabric-git)
    ClassLoader tccl = Thread.currentThread().getContextClassLoader();
    try {
        ClassLoader gitcl = GitDataStoreImpl.class.getClassLoader();
        Thread.currentThread().setContextClassLoader(gitcl);
        LOGGER.trace("Setting ThreadContextClassLoader to {} instead of {}", gitcl, tccl);
        Git git = getGit();
        Repository repository = git.getRepository();
        if (personIdent == null) {
            personIdent = new PersonIdent(repository);
        }
        if (context.isRequirePull()) {
            doPullInternal(context, getCredentialsProvider(), false, gitTimeout);
        }
        T result = operation.call(git, context);
        if (context.isRequireCommit()) {
            doCommit(git, context);
            Object cacheKey = context.getCacheKey();
            if (cacheKey == null || cacheKey.equals(GitHelpers.MASTER_BRANCH)) {
                versionCache.invalidateAll();
            } else {
                versionCache.invalidate(cacheKey);
            }
            notificationRequired = true;
        }
        if (context.isRequirePush()) {
            PushPolicyResult pushResult = doPushInternal(context, getCredentialsProvider());
            if (!pushResult.getRejectedUpdates().isEmpty()) {
                Exception gitex = pushResult.getLastException();
                throw new IllegalStateException("Push rejected: " + pushResult.getRejectedUpdates().values(), gitex);
            }
        }
        return result;
    } catch (Exception e) {
        throw FabricException.launderThrowable(e);
    } finally {
        LOGGER.trace("Restoring ThreadContextClassLoader to {}", tccl);
        Thread.currentThread().setContextClassLoader(tccl);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Git(org.eclipse.jgit.api.Git) PersonIdent(org.eclipse.jgit.lib.PersonIdent) PushPolicyResult(io.fabric8.git.PullPushPolicy.PushPolicyResult) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException) FabricException(io.fabric8.api.FabricException) KeeperException(org.apache.zookeeper.KeeperException) MalformedURLException(java.net.MalformedURLException)

Example 2 with PushPolicyResult

use of io.fabric8.git.PullPushPolicy.PushPolicyResult in project fabric8 by jboss-fuse.

the class DummyBatchingProgressMonitor method doPush.

@Override
public Iterable<PushResult> doPush(Git git, GitContext context) throws Exception {
    IllegalArgumentAssertion.assertNotNull(git, "git");
    IllegalArgumentAssertion.assertNotNull(context, "context");
    LockHandle writeLock = aquireWriteLock();
    try {
        assertValid();
        LOGGER.debug("External call to push");
        PushPolicyResult pushResult = doPushInternal(context, getCredentialsProvider());
        return pushResult.getPushResults();
    } finally {
        writeLock.unlock();
    }
}
Also used : LockHandle(io.fabric8.api.LockHandle) PushPolicyResult(io.fabric8.git.PullPushPolicy.PushPolicyResult)

Aggregations

PushPolicyResult (io.fabric8.git.PullPushPolicy.PushPolicyResult)2 FabricException (io.fabric8.api.FabricException)1 LockHandle (io.fabric8.api.LockHandle)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 KeeperException (org.apache.zookeeper.KeeperException)1 Git (org.eclipse.jgit.api.Git)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 PersonIdent (org.eclipse.jgit.lib.PersonIdent)1 Repository (org.eclipse.jgit.lib.Repository)1