use of org.jboss.fuse.patch.management.PatchException in project fuse-karaf by jboss-fuse.
the class SimulateCommand method doExecute.
@Override
protected void doExecute(PatchService service) throws Exception {
Patch patch = service.getPatch(patchId);
if (patch == null) {
throw new PatchException("Patch '" + patchId + "' not found");
}
if (patch.isInstalled()) {
throw new PatchException("Patch '" + patchId + "' is already installed");
}
PatchResult result = service.install(patch, true);
// display(result);
}
use of org.jboss.fuse.patch.management.PatchException in project fuse-karaf by jboss-fuse.
the class GitPatchManagementServiceImpl method beginInstallation.
@Override
public String beginInstallation(PatchKind kind) {
try {
Git fork = gitPatchRepository.cloneRepository(gitPatchRepository.findOrCreateMainGitRepository(), true);
Ref installationBranch = null;
// let's pick up latest user changes
applyUserChanges(fork);
switch(kind) {
case ROLLUP:
// create temporary branch from the current baseline - rollup patch installation is a rebase
// of existing user changes on top of new baseline (more precisely - cherry pick)
RevTag currentBaseline = gitPatchRepository.findCurrentBaseline(fork);
installationBranch = gitPatchRepository.checkout(fork).setName(String.format("patch-install-%s", GitPatchRepository.TS.format(new Date()))).setCreateBranch(true).setStartPoint(currentBaseline.getTagName() + "^{commit}").call();
break;
case NON_ROLLUP:
// create temporary branch from main-patch-branch/HEAD - non-rollup patch installation is cherry-pick
// of non-rollup patch commit over existing user changes - we can fast forward when finished
installationBranch = gitPatchRepository.checkout(fork).setName(String.format("patch-install-%s", GitPatchRepository.TS.format(new Date()))).setCreateBranch(true).setStartPoint(gitPatchRepository.getMainBranchName()).call();
break;
}
pendingTransactionsTypes.put(installationBranch.getName(), kind);
pendingTransactions.put(installationBranch.getName(), fork);
return installationBranch.getName();
} catch (IOException | GitAPIException e) {
throw new PatchException(e.getMessage(), e);
}
}
use of org.jboss.fuse.patch.management.PatchException in project fuse-karaf by jboss-fuse.
the class GitPatchManagementServiceImpl method listPatches.
@Override
public List<Patch> listPatches(boolean details) throws PatchException {
List<Patch> patches = new LinkedList<>();
File[] patchDescriptors = patchesDir.listFiles((dir, name) -> name.endsWith(".patch") && new File(dir, name).isFile());
try {
if (patchDescriptors != null) {
for (File pd : patchDescriptors) {
Patch p = loadPatch(pd, details);
patches.add(p);
}
}
} catch (IOException e) {
throw new PatchException(e.getMessage(), e);
}
return patches;
}
use of org.jboss.fuse.patch.management.PatchException in project fuse-karaf by jboss-fuse.
the class GitPatchManagementServiceImpl method loadPatchData.
/**
* Reads content of patch descriptor into non-(yet)-managed patch data structure
* @param patchDescriptor
* @return
*/
private PatchData loadPatchData(File patchDescriptor) throws IOException {
Properties properties = new Properties();
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(patchDescriptor);
properties.load(inputStream);
boolean ok = properties.containsKey("id") && properties.containsKey("bundle.count");
if (!ok) {
throw new PatchException("Patch descriptor is not valid");
}
return PatchData.load(properties);
} finally {
Utils.closeQuietly(inputStream);
}
}
use of org.jboss.fuse.patch.management.PatchException in project fuse-karaf by jboss-fuse.
the class GitPatchManagementServiceImpl method loadPatch.
@Override
public Patch loadPatch(PatchDetailsRequest request) throws PatchException {
File descriptor = new File(patchesDir, request.getPatchId() + ".patch");
try {
Patch patch = loadPatch(descriptor, true);
if (patch == null) {
return null;
}
Git repo = gitPatchRepository.findOrCreateMainGitRepository();
List<DiffEntry> diff = null;
if (request.isFiles() || request.isDiff()) {
// fetch the information from git
ObjectId commitId = repo.getRepository().resolve(patch.getManagedPatch().getCommitId());
RevCommit commit = new RevWalk(repo.getRepository()).parseCommit(commitId);
diff = gitPatchRepository.diff(repo, commit.getParent(0), commit);
}
if (request.isBundles()) {
// it's already in PatchData
}
if (request.isFiles() && diff != null) {
for (DiffEntry de : diff) {
DiffEntry.ChangeType ct = de.getChangeType();
String newPath = de.getNewPath();
String oldPath = de.getOldPath();
switch(ct) {
case ADD:
patch.getManagedPatch().getFilesAdded().add(newPath);
break;
case MODIFY:
patch.getManagedPatch().getFilesModified().add(newPath);
break;
case DELETE:
patch.getManagedPatch().getFilesRemoved().add(oldPath);
break;
default:
break;
}
}
}
if (request.isDiff() && diff != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DiffFormatter formatter = new DiffFormatter(baos);
formatter.setContext(4);
formatter.setRepository(repo.getRepository());
for (DiffEntry de : diff) {
formatter.format(de);
}
formatter.flush();
patch.getManagedPatch().setUnifiedDiff(new String(baos.toByteArray(), "UTF-8"));
}
return patch;
} catch (IOException | GitAPIException e) {
throw new PatchException(e.getMessage(), e);
}
}
Aggregations