Search in sources :

Example 1 with HibernateConsoleRuntimeException

use of org.hibernate.console.HibernateConsoleRuntimeException in project jbosstools-hibernate by jbosstools.

the class ClassLoaderHelper method getRawLocationFile.

private static File getRawLocationFile(IPath simplePath) {
    IResource member = ResourcesPlugin.getWorkspace().getRoot().findMember(simplePath);
    File file = null;
    if (member != null) {
        IPath rawLocation = member.getRawLocation();
        if (rawLocation == null) {
            rawLocation = member.getLocation();
            if (rawLocation == null) {
                throw new HibernateConsoleRuntimeException(HibernateConsoleMessages.ClassLoaderHelper_could_not_determine_physical_location_for + simplePath);
            }
        }
        file = rawLocation.toFile();
    } else {
        file = simplePath.toFile();
    }
    return file;
}
Also used : IPath(org.eclipse.core.runtime.IPath) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException) File(java.io.File) IResource(org.eclipse.core.resources.IResource)

Example 2 with HibernateConsoleRuntimeException

use of org.hibernate.console.HibernateConsoleRuntimeException in project jbosstools-hibernate by jbosstools.

the class ReloadConfigurationAction method doRun.

protected void doRun() {
    for (Iterator<?> i = getSelectedNonResources().iterator(); i.hasNext(); ) {
        try {
            Object node = i.next();
            if (node instanceof ConsoleConfiguration) {
                ConsoleConfiguration config = (ConsoleConfiguration) node;
                config.reset();
                updateState(config);
                viewer.refresh(node);
            }
        } catch (HibernateConsoleRuntimeException he) {
            HibernateConsolePlugin.getDefault().showError(viewer.getControl().getShell(), HibernateConsoleMessages.ReloadConfigurationAction_exception_while_start_hibernate, he);
        } catch (UnsupportedClassVersionError ucve) {
            HibernateConsolePlugin.getDefault().showError(viewer.getControl().getShell(), HibernateConsoleMessages.ReloadConfigurationAction_starting_hibernate_resulted_exception, ucve);
        }
    }
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException)

Example 3 with HibernateConsoleRuntimeException

use of org.hibernate.console.HibernateConsoleRuntimeException in project jbosstools-hibernate by jbosstools.

the class CodeGenerationLaunchDelegate method runExporters.

private IArtifactCollector runExporters(final ExporterAttributes attributes, final ExporterFactory[] exporterFactories, final Set<String> outputDirectories, final IProgressMonitor monitor) throws CoreException {
    monitor.beginTask(HibernateConsoleMessages.CodeGenerationLaunchDelegate_generating_code_for + attributes.getConsoleConfigurationName(), exporterFactories.length + 1);
    if (monitor.isCanceled())
        return null;
    ConsoleConfiguration cc = KnownConfigurations.getInstance().find(attributes.getConsoleConfigurationName());
    if (attributes.isReverseEngineer()) {
        monitor.subTask(HibernateConsoleMessages.CodeGenerationLaunchDelegate_reading_jdbc_metadata);
    }
    final IConfiguration cfg = buildConfiguration(attributes, cc, ResourcesPlugin.getWorkspace().getRoot());
    monitor.worked(1);
    if (monitor.isCanceled())
        return null;
    final IService service = cc.getHibernateExtension().getHibernateService();
    return (IArtifactCollector) cc.execute(new Command() {

        public Object execute() {
            IArtifactCollector artifactCollector = service.newArtifactCollector();
            // Global properties
            Properties props = new Properties();
            // $NON-NLS-1$
            props.put(CodeGenerationStrings.EJB3, "" + attributes.isEJB3Enabled());
            // $NON-NLS-1$
            props.put(CodeGenerationStrings.JDK5, "" + attributes.isJDK5Enabled());
            for (int i = 0; i < exporterFactories.length; i++) {
                monitor.subTask(exporterFactories[i].getExporterDefinition().getDescription());
                Properties globalProperties = new Properties();
                globalProperties.putAll(props);
                IExporter exporter;
                try {
                    exporter = exporterFactories[i].createConfiguredExporter(cfg, attributes.getOutputPath(), attributes.getTemplatePath(), globalProperties, outputDirectories, artifactCollector, service);
                } catch (CoreException e) {
                    throw new HibernateConsoleRuntimeException(HibernateConsoleMessages.CodeGenerationLaunchDelegate_error_while_setting_up + exporterFactories[i].getExporterDefinition(), e);
                }
                try {
                    exporter.start();
                } catch (HibernateException he) {
                    throw new HibernateConsoleRuntimeException(HibernateConsoleMessages.CodeGenerationLaunchDelegate_error_while_running + exporterFactories[i].getExporterDefinition().getDescription(), he);
                }
                monitor.worked(1);
            }
            return artifactCollector;
        }
    });
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) IArtifactCollector(org.jboss.tools.hibernate.runtime.spi.IArtifactCollector) CoreException(org.eclipse.core.runtime.CoreException) Command(org.hibernate.console.execution.ExecutionContext.Command) HibernateException(org.jboss.tools.hibernate.runtime.spi.HibernateException) IExporter(org.jboss.tools.hibernate.runtime.spi.IExporter) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) Properties(java.util.Properties) IService(org.jboss.tools.hibernate.runtime.spi.IService)

Example 4 with HibernateConsoleRuntimeException

use of org.hibernate.console.HibernateConsoleRuntimeException in project jbosstools-hibernate by jbosstools.

the class ConsoleConfigurationJavaClasspathTab method isValid.

public boolean isValid(ILaunchConfiguration launchConfig) {
    if (!super.isValid(launchConfig)) {
        return false;
    }
    if (lastValidatedLaunchConfig != null && lastValidatedLaunchConfig.contentsEqual(launchConfig)) {
        setErrorMessage(lastErrorMessage);
        return lastRes;
    }
    setErrorMessage(null);
    setMessage(null);
    boolean resUserClasses = false, resExistArchive = true;
    IRuntimeClasspathEntry[] entries;
    try {
        entries = JavaRuntime.computeUnresolvedRuntimeClasspath(launchConfig);
        for (int i = 0; i < entries.length; i++) {
            IRuntimeClasspathEntry entry = entries[i];
            if (entry.getClasspathProperty() == IRuntimeClasspathEntry.USER_CLASSES || (entry.getClasspathProperty() == IRuntimeClasspathEntry.MODULE_PATH && entry.getType() == IRuntimeClasspathEntry.PROJECT) || entry.getClasspathProperty() == IRuntimeClasspathEntry.CLASS_PATH) {
                resUserClasses = true;
                if (entry.getType() == IRuntimeClasspathEntry.ARCHIVE) {
                    if (!entry.getPath().toFile().exists()) {
                        resExistArchive = false;
                        String out = NLS.bind(HibernateConsoleMessages.ConsoleConfigurationTabGroup_archive_classpath_entry_does_not_exist, entry.getPath().toString());
                        setErrorMessage(out);
                    }
                }
            }
        }
    } catch (CoreException e) {
    // Ignore as the exception occurs if the selected project is not java project
    // We'll show warning to the user later
    }
    if (!resUserClasses) {
        setErrorMessage(HibernateConsoleMessages.ConsoleConfigurationTabGroup_classpath_must_be_set_or_restored_to_default);
    }
    if (resUserClasses && resExistArchive) {
        boolean flagTryToBuild = true;
        final ConsoleConfiguration ccTest = new ConsoleConfiguration(new EclipseLaunchConsoleConfigurationPreferences(launchConfig));
        if (configurationFileWillBeCreated) {
            // exception to resolve the file
            try {
                ccTest.getConfigXMLFile();
            } catch (HibernateConsoleRuntimeException ex) {
                flagTryToBuild = false;
            }
        }
        if (flagTryToBuild) {
            try {
                ccTest.buildWith(null, false);
            } catch (Exception ex) {
                resUserClasses = false;
                setErrorMessage(ex.getMessage());
            }
            // accurate reset for ccTest after buildWith, should avoid possible "leaks"
            try {
                ccTest.reset();
            } catch (Exception ex) {
                if (resUserClasses) {
                    resUserClasses = false;
                    setErrorMessage(ex.getMessage());
                }
            }
            try {
                lastValidatedLaunchConfig = launchConfig.getWorkingCopy();
            } catch (CoreException e1) {
                lastValidatedLaunchConfig = null;
            }
        }
    }
    final boolean res = resUserClasses && resExistArchive;
    if (lastValidatedLaunchConfig != null) {
        lastErrorMessage = getErrorMessage();
        lastRes = res;
    }
    return res;
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) CoreException(org.eclipse.core.runtime.CoreException) EclipseLaunchConsoleConfigurationPreferences(org.hibernate.eclipse.console.EclipseLaunchConsoleConfigurationPreferences) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException) IRuntimeClasspathEntry(org.eclipse.jdt.launching.IRuntimeClasspathEntry) CoreException(org.eclipse.core.runtime.CoreException) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException)

Example 5 with HibernateConsoleRuntimeException

use of org.hibernate.console.HibernateConsoleRuntimeException in project jbosstools-hibernate by jbosstools.

the class ConsoleExtension method runExporters.

private IArtifactCollector runExporters(final ExporterAttributes attributes, final ExporterFactory[] exporterFactories, final Set<String> outputDirectories, final IProgressMonitor monitor) throws CoreException {
    monitor.beginTask(HibernateConsoleMessages.CodeGenerationLaunchDelegate_generating_code_for + attributes.getConsoleConfigurationName(), exporterFactories.length + 1);
    if (monitor.isCanceled())
        return null;
    ConsoleConfiguration cc = KnownConfigurations.getInstance().find(attributes.getConsoleConfigurationName());
    if (attributes.isReverseEngineer()) {
        monitor.subTask(HibernateConsoleMessages.CodeGenerationLaunchDelegate_reading_jdbc_metadata);
    }
    final IConfiguration cfg = buildConfiguration(attributes, cc, ResourcesPlugin.getWorkspace().getRoot());
    monitor.worked(1);
    if (monitor.isCanceled())
        return null;
    return (IArtifactCollector) cc.execute(new Command() {

        public Object execute() {
            IArtifactCollector artifactCollector = hibernateExtension.getHibernateService().newArtifactCollector();
            // Global properties
            Properties props = new Properties();
            props.put(CodeGenerationStrings.EJB3, // $NON-NLS-1$
            "" + attributes.isEJB3Enabled());
            props.put(CodeGenerationStrings.JDK5, // $NON-NLS-1$
            "" + attributes.isJDK5Enabled());
            for (int i = 0; i < exporterFactories.length; i++) {
                monitor.subTask(exporterFactories[i].getExporterDefinition().getDescription());
                Properties globalProperties = new Properties();
                globalProperties.putAll(props);
                IExporter exporter;
                try {
                    exporter = exporterFactories[i].createConfiguredExporter(cfg, attributes.getOutputPath(), attributes.getTemplatePath(), globalProperties, outputDirectories, artifactCollector, hibernateExtension.getHibernateService());
                } catch (CoreException e) {
                    throw new HibernateConsoleRuntimeException(HibernateConsoleMessages.CodeGenerationLaunchDelegate_error_while_setting_up + exporterFactories[i].getExporterDefinition(), e);
                }
                try {
                    exporter.start();
                } catch (HibernateException he) {
                    throw new HibernateConsoleRuntimeException(HibernateConsoleMessages.CodeGenerationLaunchDelegate_error_while_running + exporterFactories[i].getExporterDefinition().getDescription(), he);
                }
                monitor.worked(1);
            }
            return artifactCollector;
        }
    });
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) IArtifactCollector(org.jboss.tools.hibernate.runtime.spi.IArtifactCollector) CoreException(org.eclipse.core.runtime.CoreException) Command(org.hibernate.console.execution.ExecutionContext.Command) HibernateException(org.jboss.tools.hibernate.runtime.spi.HibernateException) IExporter(org.jboss.tools.hibernate.runtime.spi.IExporter) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) Properties(java.util.Properties)

Aggregations

HibernateConsoleRuntimeException (org.hibernate.console.HibernateConsoleRuntimeException)19 File (java.io.File)8 CoreException (org.eclipse.core.runtime.CoreException)7 Properties (java.util.Properties)5 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)5 IOException (java.io.IOException)4 HibernateException (org.jboss.tools.hibernate.runtime.spi.HibernateException)3 IArtifactCollector (org.jboss.tools.hibernate.runtime.spi.IArtifactCollector)3 IExporter (org.jboss.tools.hibernate.runtime.spi.IExporter)3 FileInputStream (java.io.FileInputStream)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 QueryPage (org.hibernate.console.QueryPage)2 Command (org.hibernate.console.execution.ExecutionContext.Command)2 ExporterFactory (org.hibernate.eclipse.console.model.impl.ExporterFactory)2 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)2