use of com.devonfw.cobigen.impl.config.upgrade.ContextConfigurationUpgrader in project cobigen by devonfw.
the class UpgradeTestdataConfigurations method upgradeTestdataConfigurations.
/**
* Utility test to automatically migrate test configurations for CobiGen.
*/
@Test
@Ignore("Just a script to maintain test data after upgrading configurations. Should be run with caution!")
public void upgradeTestdataConfigurations() {
File root = new File("src/test/resources/testdata/");
LinkedList<File> workingset = Lists.newLinkedList();
List<File> rootChildren = Arrays.asList(root.listFiles());
workingset.addAll(rootChildren);
LOG.debug("Adding {} files to worklist.", rootChildren.size());
while (!workingset.isEmpty()) {
File current = workingset.pop();
if (current.isDirectory() && !current.getName().equals("upgrade")) {
List<File> children = Arrays.asList(current.listFiles());
workingset.addAll(children);
LOG.debug("Adding {} files to worklist.", children.size());
} else if (current.getName().equals("context.xml")) {
if (!current.toPath().getParent().getFileName().toString().startsWith("faulty")) {
LOG.debug("Upgrading ContextConfiguration: {}", current.toPath());
new ContextConfigurationUpgrader().upgradeConfigurationToLatestVersion(current.toPath().getParent(), BackupPolicy.NO_BACKUP);
current.toPath().resolveSibling("context.bak.xml").toFile().delete();
}
} else if (current.getName().equals("templates.xml")) {
if (!current.toPath().getParent().getFileName().toString().startsWith("faulty")) {
LOG.debug("Upgrading TemplateConfiguration: {}", current.toPath());
new TemplateConfigurationUpgrader().upgradeConfigurationToLatestVersion(current.toPath().getParent(), BackupPolicy.NO_BACKUP);
current.toPath().resolveSibling("templates.bak.xml").toFile().delete();
}
}
}
LOG.debug("DONE.");
}
use of com.devonfw.cobigen.impl.config.upgrade.ContextConfigurationUpgrader in project cobigen by devonfw.
the class HealthCheckDialog method execute.
/**
* Executes the simple health check, checking configuration project existence, validity of context configuration, as
* well as validity of the current workbench selection as generation input.
*/
public void execute() {
String firstStep = "1. CobiGen configuration project '" + ResourceConstants.CONFIG_PROJECT_NAME + "'... ";
String secondStep = "\n2. CobiGen context configuration '" + ConfigurationConstants.CONTEXT_CONFIG_FILENAME + "'... ";
String healthyCheckMessage = "";
IProject generatorConfProj = null;
try {
// refresh and check context configuration
ResourcesPluginUtil.refreshConfigurationProject();
// check configuration project existence in workspace
generatorConfProj = ResourcesPluginUtil.getGeneratorConfigurationProject();
this.report = performHealthCheckReport();
if (generatorConfProj != null && generatorConfProj.getLocationURI() != null) {
CobiGenFactory.create(generatorConfProj.getLocationURI());
} else {
File templatesDirectory = CobiGenPaths.getTemplatesFolderPath().toFile();
File jarPath = TemplatesJarUtil.getJarFile(false, templatesDirectory);
boolean fileExists = jarPath.exists();
if (!fileExists) {
MessageDialog.openWarning(Display.getDefault().getActiveShell(), "Warning", "Not Downloaded the CobiGen Template Jar");
}
}
healthyCheckMessage = firstStep + "OK.";
healthyCheckMessage += secondStep;
boolean healthyCheckWarning = false;
if (this.report.getNumberOfErrors() == 0) {
healthyCheckMessage += "OK.";
} else {
healthyCheckMessage += "INVALID.";
healthyCheckWarning = true;
}
openSuccessDialog(healthyCheckMessage, healthyCheckWarning);
} catch (GeneratorProjectNotExistentException e) {
LOG.warn("Configuration project not found!", e);
healthyCheckMessage = firstStep + "NOT FOUND!\n" + "=> Please import the configuration project into your workspace as stated in the " + "documentation of CobiGen or in the one of your project.";
PlatformUIUtil.openErrorDialog(healthyCheckMessage, null);
} catch (ConfigurationConflictException e) {
healthyCheckMessage = "An unexpected error occurred! Templates were in a conflicted state.";
healthyCheckMessage += "\n\nNo automatic upgrade of the context configuration possible.";
PlatformUIUtil.openErrorDialog(healthyCheckMessage, e);
LOG.error(healthyCheckMessage, e);
} catch (InvalidConfigurationException e) {
// Won't be reached anymore
healthyCheckMessage = firstStep + "OK.";
healthyCheckMessage += secondStep + "INVALID!";
if (generatorConfProj != null && generatorConfProj.getLocationURI() != null) {
Path configurationProject = Paths.get(generatorConfProj.getLocationURI());
ContextConfigurationVersion currentVersion = new ContextConfigurationUpgrader().resolveLatestCompatibleSchemaVersion(configurationProject);
if (currentVersion != null) {
// upgrade possible
healthyCheckMessage += "\n\nAutomatic upgrade of the context configuration available.\n" + "Detected: " + currentVersion + " / Currently Supported: " + ContextConfigurationVersion.getLatest();
this.report = openErrorDialogWithContextUpgrade(healthyCheckMessage, configurationProject, BackupPolicy.ENFORCE_BACKUP);
healthyCheckMessage = MessageUtil.enrichMsgIfMultiError(healthyCheckMessage, this.report);
if (!this.report.containsError(RuntimeException.class)) {
// re-run Health Check
Display.getCurrent().asyncExec(new Runnable() {
@Override
public void run() {
execute();
}
});
}
} else {
healthyCheckMessage += "\n\nNo automatic upgrade of the context configuration possible. " + "Maybe just a mistake in the context configuration?";
healthyCheckMessage += "\n\n=> " + e.getMessage();
healthyCheckMessage = MessageUtil.enrichMsgIfMultiError(healthyCheckMessage, this.report);
PlatformUIUtil.openErrorDialog(healthyCheckMessage, null);
}
} else {
healthyCheckMessage += "\n\nCould not find configuration.";
PlatformUIUtil.openErrorDialog(healthyCheckMessage, null);
}
LOG.warn(healthyCheckMessage, e);
} catch (Throwable e) {
healthyCheckMessage = "An unexpected error occurred! Templates were not found.";
if (this.report != null && healthyCheckMessage != null) {
healthyCheckMessage = MessageUtil.enrichMsgIfMultiError(healthyCheckMessage, this.report);
}
PlatformUIUtil.openErrorDialog(healthyCheckMessage, e);
LOG.error(healthyCheckMessage, e);
}
}
use of com.devonfw.cobigen.impl.config.upgrade.ContextConfigurationUpgrader in project cobigen by devonfw.
the class UpgradeTestdataConfigurations method upgradeTestdataConfigurations.
/**
* Utility test to upgrade test configurations. Should be run with caution and just on purpose!
*/
@Test
@Ignore("Just a script to maintain test data after upgrading configurations. Should be run with caution!")
public void upgradeTestdataConfigurations() {
File root = new File("src/test/resources/testdata/");
LinkedList<File> workingset = Lists.newLinkedList();
List<File> rootChildren = Arrays.asList(root.listFiles());
workingset.addAll(rootChildren);
LOG.debug("Adding {} files to worklist.", rootChildren.size());
while (!workingset.isEmpty()) {
File current = workingset.pop();
if (current.isDirectory() && !current.getName().equals("upgrade")) {
List<File> children = Arrays.asList(current.listFiles());
workingset.addAll(children);
LOG.debug("Adding {} files to worklist.", children.size());
} else if (current.getName().equals("context.xml")) {
if (!current.toPath().getParent().getFileName().toString().startsWith("faulty")) {
LOG.debug("Upgrading ContextConfiguration: {}", current.toPath());
new ContextConfigurationUpgrader().upgradeConfigurationToLatestVersion(current.toPath().getParent(), BackupPolicy.BACKUP_IF_POSSIBLE);
current.toPath().resolveSibling("context.bak.xml").toFile().delete();
}
} else if (current.getName().equals("templates.xml")) {
if (!current.toPath().getParent().getFileName().toString().startsWith("faulty")) {
LOG.debug("Upgrading TemplateConfiguration: {}", current.toPath());
new TemplateConfigurationUpgrader().upgradeConfigurationToLatestVersion(current.toPath().getParent(), BackupPolicy.BACKUP_IF_POSSIBLE);
current.toPath().resolveSibling("templates.bak.xml").toFile().delete();
}
}
}
LOG.debug("DONE.");
}
use of com.devonfw.cobigen.impl.config.upgrade.ContextConfigurationUpgrader in project cobigen by devonfw.
the class UpgradeTestdataConfigurations method upgradeTestdataConfigurations.
/**
* Just a script to maintain test data after upgrading configurations. Should be run with caution!
*/
@Test
@Ignore
public void upgradeTestdataConfigurations() {
File root = new File("src/test/resources/testdata/");
LinkedList<File> workingset = Lists.newLinkedList();
List<File> rootChildren = Arrays.asList(root.listFiles());
workingset.addAll(rootChildren);
LOG.debug("Adding {} files to worklist.", rootChildren.size());
while (!workingset.isEmpty()) {
File current = workingset.pop();
if (current.isDirectory() && !current.getName().equals("upgrade")) {
List<File> children = Arrays.asList(current.listFiles());
workingset.addAll(children);
LOG.debug("Adding {} files to worklist.", children.size());
} else if (current.getName().equals("context.xml")) {
if (!current.toPath().getParent().getFileName().toString().startsWith("faulty")) {
LOG.debug("Upgrading ContextConfiguration: {}", current.toPath());
new ContextConfigurationUpgrader().upgradeConfigurationToLatestVersion(current.toPath().getParent(), BackupPolicy.BACKUP_IF_POSSIBLE);
current.toPath().resolveSibling("context.bak.xml").toFile().delete();
}
} else if (current.getName().equals("templates.xml")) {
if (!current.toPath().getParent().getFileName().toString().startsWith("faulty")) {
LOG.debug("Upgrading TemplateConfiguration: {}", current.toPath());
new TemplateConfigurationUpgrader().upgradeConfigurationToLatestVersion(current.toPath().getParent(), BackupPolicy.BACKUP_IF_POSSIBLE);
current.toPath().resolveSibling("templates.bak.xml").toFile().delete();
}
}
}
LOG.debug("DONE.");
}
use of com.devonfw.cobigen.impl.config.upgrade.ContextConfigurationUpgrader in project cobigen by devonfw.
the class HealthCheckImpl method upgradeContextConfiguration.
@Override
public HealthCheckReport upgradeContextConfiguration(Path configurationFolder, BackupPolicy backupPolicy) throws BackupFailedException {
ContextConfigurationUpgrader contextConfigurationUpgrader = new ContextConfigurationUpgrader();
contextConfigurationUpgrader.upgradeConfigurationToLatestVersion(configurationFolder, backupPolicy);
return this.healthCheckReport;
}
Aggregations