Search in sources :

Example 1 with GeneratorProjectNotExistentException

use of com.devonfw.cobigen.eclipse.common.exceptions.GeneratorProjectNotExistentException in project cobigen by devonfw.

the class HealthCheckDialog method openSuccessDialog.

/**
 * Open up a success dialog with the given message, which provides the ability to perform an advanced health check in
 * addition.
 *
 * @param healthyCheckMessage message to be shown to the user
 * @param warn if the message box should be displayed as a warning
 */
private void openSuccessDialog(String healthyCheckMessage, boolean warn) {
    MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(), HealthCheckDialogs.DIALOG_TITLE, null, healthyCheckMessage, warn ? MessageDialog.WARNING : MessageDialog.INFORMATION, new String[] { "Advanced Health Check", "OK" }, 1);
    dialog.setBlockOnOpen(true);
    int result = dialog.open();
    if (result == 0) {
        try {
            // check configuration project existence in workspace
            this.report = performHealthCheckReport();
            AdvancedHealthCheckDialog advancedHealthCheckDialog = new AdvancedHealthCheckDialog(this.report, this.healthCheck);
            advancedHealthCheckDialog.setBlockOnOpen(false);
            advancedHealthCheckDialog.open();
        } catch (GeneratorProjectNotExistentException e) {
            LOG.warn("Configuration project not found!", e);
            String s = "=> Please import the configuration project into your workspace as stated in the " + "documentation of CobiGen or in the one of your project.";
            PlatformUIUtil.openErrorDialog(s, e);
        } catch (CoreException e) {
            LOG.error("An eclipse internal exception occurred while retrieving the configuration folder resource.", e);
            String s = "An eclipse internal exception occurred while retrieving the configuration folder resource.";
            PlatformUIUtil.openErrorDialog(s, e);
        }
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) GeneratorProjectNotExistentException(com.devonfw.cobigen.eclipse.common.exceptions.GeneratorProjectNotExistentException) MessageDialog(org.eclipse.jface.dialogs.MessageDialog)

Example 2 with GeneratorProjectNotExistentException

use of com.devonfw.cobigen.eclipse.common.exceptions.GeneratorProjectNotExistentException in project cobigen by devonfw.

the class ResourcesPluginUtil method processJar.

/**
 * Process Jar method is responsible for unzip the source Jar and create new CobiGen_Templates folder structure at
 * /main/CobiGen_Templates location
 *
 * @param fileName Name of source jar file downloaded
 * @throws IOException {@link IOException} occurred
 * @throws MalformedURLException {@link MalformedURLException} occurred
 */
public static void processJar(String fileName) throws MalformedURLException, IOException {
    String pathForCobigenTemplates = "";
    IPath ws = ResourcesPluginUtil.getWorkspaceLocation();
    try {
        pathForCobigenTemplates = ws.toPortableString() + (((ResourcesPluginUtil.getGeneratorConfigurationProject() != null) && (ResourcesPluginUtil.getGeneratorConfigurationProject().getLocation() != null)) ? ResourcesPluginUtil.getGeneratorConfigurationProject().getLocation() : StringUtils.EMPTY);
    } catch (GeneratorProjectNotExistentException e1) {
        LOG.warn("Configuration project not found!", e1);
        String s = "=> Probably there was an error while downloading the templates. " + "Please try to update them and try again.";
        PlatformUIUtil.openErrorDialog(s, e1);
    } catch (CoreException e) {
        MessageDialog.openWarning(Display.getDefault().getActiveShell(), "Warning", "Could not refresh the CobiGen configuration project automatically. " + "Please try it again manually");
        LOG.warn("Configuration project refresh failed", e);
    }
    FileSystem fileSystem = FileSystems.getDefault();
    Path cobigenFolderPath = null;
    if (fileSystem != null && fileSystem.getPath(pathForCobigenTemplates) != null) {
        cobigenFolderPath = fileSystem.getPath(pathForCobigenTemplates);
    }
    try {
        ExtractTemplatesUtil.extractTemplates(cobigenFolderPath.resolve(ConfigurationConstants.COBIGEN_TEMPLATES), false);
    } catch (Exception e) {
        LOG.error("An exception occurred while processing Jar files to create CobiGen_Templates folder", e);
        PlatformUIUtil.openErrorDialog("An exception occurred while processing Jar file to create CobiGen_Templates folder", e);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(java.nio.file.Path) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) GeneratorProjectNotExistentException(com.devonfw.cobigen.eclipse.common.exceptions.GeneratorProjectNotExistentException) FileSystem(java.nio.file.FileSystem) CoreException(org.eclipse.core.runtime.CoreException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) GeneratorProjectNotExistentException(com.devonfw.cobigen.eclipse.common.exceptions.GeneratorProjectNotExistentException)

Example 3 with GeneratorProjectNotExistentException

use of com.devonfw.cobigen.eclipse.common.exceptions.GeneratorProjectNotExistentException 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)

Aggregations

GeneratorProjectNotExistentException (com.devonfw.cobigen.eclipse.common.exceptions.GeneratorProjectNotExistentException)3 Path (java.nio.file.Path)2 CoreException (org.eclipse.core.runtime.CoreException)2 IPath (org.eclipse.core.runtime.IPath)2 ConfigurationConflictException (com.devonfw.cobigen.api.exception.ConfigurationConflictException)1 InvalidConfigurationException (com.devonfw.cobigen.api.exception.InvalidConfigurationException)1 ContextConfigurationVersion (com.devonfw.cobigen.impl.config.constant.ContextConfigurationVersion)1 ContextConfigurationUpgrader (com.devonfw.cobigen.impl.config.upgrade.ContextConfigurationUpgrader)1 File (java.io.File)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 FileSystem (java.nio.file.FileSystem)1 IProject (org.eclipse.core.resources.IProject)1 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)1