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();
}
}
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();
}
}
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();
}
}
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;
}
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();
}
}
Aggregations