use of io.fabric8.api.VersionSequence in project fabric8 by jboss-fuse.
the class VersionCreateAction method doExecute.
@Override
protected Object doExecute() throws Exception {
String latestVersion = null;
ProfileService profileService = fabricService.adapt(ProfileService.class);
List<String> versions = profileService.getVersions();
if (versions.size() > 0) {
latestVersion = versions.get(versions.size() - 1);
}
if (versionId == null) {
IllegalStateAssertion.assertNotNull(latestVersion, "Cannot default the new version name as there are no versions available");
VersionSequence sequence = new VersionSequence(latestVersion);
versionId = sequence.next().getName();
}
// TODO we maybe want to choose the version which is less than the 'name' if it was specified
// e.g. if you create a version 1.1 then it should use 1.0 if there is already a 2.0
String sourceId = null;
if (parentVersion == null) {
sourceId = latestVersion;
} else {
IllegalStateAssertion.assertTrue(profileService.hasVersion(parentVersion), "Cannot find parent version: " + parentVersion);
sourceId = parentVersion;
}
Version targetVersion;
if (sourceId != null) {
Map<String, String> attributes = new HashMap<String, String>(Collections.singletonMap(Version.PARENT, sourceId));
if (description != null) {
attributes.put(Version.DESCRIPTION, description);
}
targetVersion = profileService.createVersionFrom(sourceId, versionId, attributes);
System.out.println("Created version: " + versionId + " as copy of: " + sourceId);
} else {
VersionBuilder builder = VersionBuilder.Factory.create(versionId);
if (description != null) {
builder.addAttribute(Version.DESCRIPTION, description);
}
targetVersion = profileService.createVersion(builder.getVersion());
System.out.println("Create version: " + versionId);
}
if (defaultVersion == Boolean.TRUE) {
fabricService.setDefaultVersionId(targetVersion.getId());
}
return null;
}
use of io.fabric8.api.VersionSequence in project fabric8 by jboss-fuse.
the class FabricManager method createVersion.
@Override
public Map<String, Object> createVersion() {
Version latestVersion = getLatestVersion();
VersionSequence sequence = new VersionSequence(latestVersion.getId());
return createVersion(sequence.next().getName());
}
use of io.fabric8.api.VersionSequence in project fabric8 by jboss-fuse.
the class FabricManager method applyPatches.
@Override
public void applyPatches(List<String> files, String sourceId, String targetId, String proxyUser, String proxyPassword) {
List<File> patchFiles = new ArrayList<File>();
for (String fileName : files) {
File file = new File(fileName);
if (file.exists()) {
patchFiles.add(file);
} else {
LOG.warn("Patch file does not exist, skipping: {}", fileName);
}
}
if (patchFiles.isEmpty()) {
LOG.warn("No valid patches to apply");
throw new FabricException("No valid patches to apply");
}
if (targetId == null || targetId.equals("")) {
Version latestVersion = getLatestVersion();
VersionSequence sequence = new VersionSequence(latestVersion.getId());
targetId = sequence.next().getName();
}
Version targetVersion = profileService.createVersionFrom(sourceId, targetId, null);
File currentPatchFile = null;
try {
for (File file : patchFiles) {
currentPatchFile = file;
if (!file.isFile()) {
LOG.info("File is a directory, skipping: {}", file);
continue;
}
LOG.info("Applying patch file {}", file);
fabricService.getPatchService().applyPatch(targetVersion, file.toURI().toURL(), proxyUser, proxyPassword);
LOG.info("Successfully applied {}", file);
}
} catch (Throwable t) {
LOG.warn("Failed to apply patch file {}", currentPatchFile, t);
profileService.deleteVersion(targetId);
throw new FabricException("Failed to apply patch file " + currentPatchFile, t);
}
for (File file : patchFiles) {
try {
LOG.info("Deleting patch file {}", file);
boolean deleted = file.delete();
if (!deleted) {
LOG.warn("Failed to delete patch file {}", file);
}
} catch (Throwable t) {
LOG.warn("Failed to delete patch file {} due to {}", file, t);
}
}
}
Aggregations