Search in sources :

Example 36 with GitContext

use of io.fabric8.api.GitContext in project fabric8 by jboss-fuse.

the class DummyBatchingProgressMonitor method modifyVersionDescription.

@Override
public String modifyVersionDescription(final Version version, String description) {
    GitContext context = newGitWriteContext(version.getId());
    final Map<String, String> attributes = version.getAttributes();
    attributes.put(Version.DESCRIPTION, description);
    IllegalStateAssertion.assertNotNull(version, "version");
    LockHandle writeLock = aquireWriteLock();
    try {
        assertValid();
        LOGGER.debug("Updating version: {}", version);
        GitOperation<String> gitop = new GitOperation<String>() {

            public String call(Git git, GitContext context) throws Exception {
                String versionId = version.getId();
                GitHelpers.checkoutTag(git, GitHelpers.ROOT_TAG);
                createOrCheckoutVersion(git, version.getId());
                setVersionAttributes(git, context, versionId, attributes);
                context.commitMessage("Create version: " + version);
                Set<String> alreadyProcessedProfiles = new HashSet<String>();
                for (Profile profile : version.getProfiles()) {
                    createOrUpdateProfile(context, null, profile, alreadyProcessedProfiles);
                }
                return versionId;
            }
        };
        return executeInternal(context, null, gitop);
    } finally {
        writeLock.unlock();
    }
}
Also used : LockHandle(io.fabric8.api.LockHandle) Git(org.eclipse.jgit.api.Git) GitContext(io.fabric8.api.GitContext) Profile(io.fabric8.api.Profile)

Example 37 with GitContext

use of io.fabric8.api.GitContext in project fabric8 by jboss-fuse.

the class DummyBatchingProgressMonitor method createVersion.

@Override
public String createVersion(GitContext context, final Version version) {
    IllegalStateAssertion.assertNotNull(version, "version");
    LockHandle writeLock = aquireWriteLock();
    try {
        assertValid();
        LOGGER.debug("Create version: {}", version);
        GitOperation<String> gitop = new GitOperation<String>() {

            public String call(Git git, GitContext context) throws Exception {
                String versionId = version.getId();
                IllegalStateAssertion.assertNull(checkoutProfileBranch(git, context, versionId, null), "Version already exists: " + versionId);
                GitHelpers.checkoutTag(git, GitHelpers.ROOT_TAG);
                createOrCheckoutVersion(git, version.getId());
                setVersionAttributes(git, context, versionId, version.getAttributes());
                context.commitMessage("Create version: " + version);
                Set<String> alreadyProcessedProfiles = new HashSet<String>();
                for (Profile profile : version.getProfiles()) {
                    createOrUpdateProfile(context, null, profile, alreadyProcessedProfiles);
                }
                return versionId;
            }
        };
        return executeInternal(context, null, gitop);
    } finally {
        writeLock.unlock();
    }
}
Also used : LockHandle(io.fabric8.api.LockHandle) Git(org.eclipse.jgit.api.Git) GitContext(io.fabric8.api.GitContext) Profile(io.fabric8.api.Profile)

Example 38 with GitContext

use of io.fabric8.api.GitContext 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)

Example 39 with GitContext

use of io.fabric8.api.GitContext in project fabric8 by jboss-fuse.

the class DummyBatchingProgressMonitor method createOrUpdateProfile.

private String createOrUpdateProfile(GitContext context, Profile lastProfile, Profile profile, Set<String> profiles) throws IOException, GitAPIException {
    assertWriteLock();
    String versionId = profile.getVersion();
    String profileId = profile.getId();
    if (!profiles.contains(profileId)) {
        // Process parents first
        for (String parentId : profile.getParentIds()) {
            // skip if parent has been already visited
            if (!profiles.contains(parentId)) {
                Profile parent = getProfileFromCache(profile.getVersion(), parentId);
                IllegalStateAssertion.assertNotNull(parent, "Parent profile does not exist: " + parentId);
            }
        }
        if (lastProfile == null) {
            LOGGER.debug("Create {}", Profiles.getProfileInfo(profile));
        } else {
            LOGGER.debug("Update {}", profile);
            LOGGER.debug("Update {}", Profiles.getProfileDifference(lastProfile, profile));
        }
        // Create the profile branch & directory
        if (lastProfile == null) {
            createProfileDirectoryAfterCheckout(context, versionId, profileId);
        }
        // FileConfigurations
        Map<String, byte[]> fileConfigurations = profile.getFileConfigurations();
        setFileConfigurations(context, versionId, profileId, fileConfigurations);
        // A warning commit message if there has been none yet
        if (context.getCommitMessage().length() == 0) {
            context.commitMessage("WARNING - Profile with no content: " + versionId + "/" + profileId);
        }
        // Mark this profile as processed
        profiles.add(profileId);
    }
    return profileId;
}
Also used : Profile(io.fabric8.api.Profile)

Example 40 with GitContext

use of io.fabric8.api.GitContext in project fabric8 by jboss-fuse.

the class DummyBatchingProgressMonitor method importProfiles.

@Override
public void importProfiles(final String versionId, final List<String> profileZipUrls) {
    IllegalStateAssertion.assertNotNull(versionId, "versionId");
    IllegalStateAssertion.assertNotNull(profileZipUrls, "profileZipUrls");
    LockHandle writeLock = aquireWriteLock();
    try {
        assertValid();
        GitOperation<String> gitop = new GitOperation<String>() {

            public String call(Git git, GitContext context) throws Exception {
                // TODO(tdi): Is it correct to implicitly create the version?
                createOrCheckoutVersion(git, versionId);
                // checkoutRequiredProfileBranch(git, versionId, null);
                return doImportProfiles(git, context, profileZipUrls);
            }
        };
        executeWrite(gitop, versionId);
    } finally {
        writeLock.unlock();
    }
}
Also used : LockHandle(io.fabric8.api.LockHandle) Git(org.eclipse.jgit.api.Git) GitContext(io.fabric8.api.GitContext)

Aggregations

GitContext (io.fabric8.api.GitContext)41 Git (org.eclipse.jgit.api.Git)22 DefaultPullPushPolicy (io.fabric8.git.internal.DefaultPullPushPolicy)18 Test (org.junit.Test)18 LockHandle (io.fabric8.api.LockHandle)15 ArrayList (java.util.ArrayList)13 File (java.io.File)12 Ref (org.eclipse.jgit.lib.Ref)11 IOException (java.io.IOException)9 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)8 PushResult (org.eclipse.jgit.transport.PushResult)8 PersonIdent (org.eclipse.jgit.lib.PersonIdent)7 FabricException (io.fabric8.api.FabricException)5 Profile (io.fabric8.api.Profile)4 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 GitVersion (io.fabric8.api.commands.GitVersion)2 GitDataStore (io.fabric8.git.GitDataStore)2 GitService (io.fabric8.git.GitService)2 PushPolicyResult (io.fabric8.git.PullPushPolicy.PushPolicyResult)2 GitOperation (io.fabric8.git.internal.GitOperation)2