Search in sources :

Example 1 with ConfigurationConflictException

use of com.devonfw.cobigen.api.exception.ConfigurationConflictException 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);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(java.nio.file.Path) ConfigurationConflictException(com.devonfw.cobigen.api.exception.ConfigurationConflictException) ContextConfigurationUpgrader(com.devonfw.cobigen.impl.config.upgrade.ContextConfigurationUpgrader) GeneratorProjectNotExistentException(com.devonfw.cobigen.eclipse.common.exceptions.GeneratorProjectNotExistentException) File(java.io.File) IProject(org.eclipse.core.resources.IProject) InvalidConfigurationException(com.devonfw.cobigen.api.exception.InvalidConfigurationException) ContextConfigurationVersion(com.devonfw.cobigen.impl.config.constant.ContextConfigurationVersion)

Example 2 with ConfigurationConflictException

use of com.devonfw.cobigen.api.exception.ConfigurationConflictException in project cobigen by devonfw.

the class ContextConfigurationReader method checkForConflict.

/**
 * Checks if a conflict with the old and modular configuration exists
 *
 * @param configRoot Path to root directory of the configuration
 * @param contextFile Path to context file of the configuration
 */
private void checkForConflict(Path configRoot, Path contextFile) {
    if (!loadContextFilesInSubfolder(configRoot).isEmpty()) {
        String message = "You are using an old configuration of the templates in addition to new ones. Please make sure this is not the case as both at the same time are not supported. For more details visit this wiki page: " + WikiConstants.WIKI_UPDATE_OLD_CONFIG;
        ConfigurationConflictException exception = new ConfigurationConflictException(contextFile, message);
        LOG.error("A conflict with the old and modular configuration exists", exception);
        throw exception;
    }
}
Also used : ConfigurationConflictException(com.devonfw.cobigen.api.exception.ConfigurationConflictException)

Aggregations

ConfigurationConflictException (com.devonfw.cobigen.api.exception.ConfigurationConflictException)2 InvalidConfigurationException (com.devonfw.cobigen.api.exception.InvalidConfigurationException)1 GeneratorProjectNotExistentException (com.devonfw.cobigen.eclipse.common.exceptions.GeneratorProjectNotExistentException)1 ContextConfigurationVersion (com.devonfw.cobigen.impl.config.constant.ContextConfigurationVersion)1 ContextConfigurationUpgrader (com.devonfw.cobigen.impl.config.upgrade.ContextConfigurationUpgrader)1 File (java.io.File)1 Path (java.nio.file.Path)1 IProject (org.eclipse.core.resources.IProject)1 IPath (org.eclipse.core.runtime.IPath)1