Search in sources :

Example 31 with ConsoleConfiguration

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

the class OneParentConfigPropertyTesterTest method testSameConfig.

@Test
public void testSameConfig() {
    ConsoleConfiguration consoleConfiguration = mock(ConsoleConfiguration.class);
    TreePath treePath1 = new TreePath(new Object[] { consoleConfiguration });
    TreePath treePath2 = new TreePath(new Object[] { consoleConfiguration });
    ITreeSelection receiver = new TreeSelection(new TreePath[] { treePath1, treePath2 });
    OneParentConfigPropertyTester propertyTester = new OneParentConfigPropertyTester();
    assertTrue(propertyTester.test(receiver, "doesn't matter", null, null));
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreePath(org.eclipse.jface.viewers.TreePath) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreeSelection(org.eclipse.jface.viewers.TreeSelection) OneParentConfigPropertyTester(org.jboss.tools.hibernate.search.property.testers.OneParentConfigPropertyTester) Test(org.junit.Test)

Example 32 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration 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 33 with ConsoleConfiguration

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

the class CodeGenerationSettingsTab method getService.

private IService getService() {
    String ccn = consoleConfigurationName.getText();
    // $NON-NLS-1$
    if (ccn == null || "".equals(ccn))
        return null;
    ConsoleConfiguration cc = KnownConfigurations.getInstance().find(ccn);
    if (cc == null)
        return null;
    return cc.getHibernateExtension().getHibernateService();
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration)

Example 34 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration 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) {
                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 35 with ConsoleConfiguration

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

the class RenameResourceParticipant method createChange.

/* (non-Javadoc)
	 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#createChange(org.eclipse.core.runtime.IProgressMonitor)
	 */
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
    ILaunchConfiguration[] configs = HibernateRefactoringUtil.getAffectedConsoleConfigs(fResource.getFullPath());
    List<Change> changes = new ArrayList<Change>();
    Change change = null;
    for (int i = 0; i < configs.length; i++) {
        ConsoleConfiguration cc = KnownConfigurations.getInstance().find(configs[i].getName());
        if (cc != null) {
            cc.reset();
        }
        change = new LaunchConfigurationResourceNameChange(configs[i], fResource.getFullPath(), fResource.getParent().getFullPath().append(getArguments().getNewName()));
        changes.add(change);
    }
    configs = HibernateRefactoringUtil.getAffectedCodeGenerationConfigs(fResource.getFullPath());
    for (int i = 0; i < configs.length; i++) {
        change = new CodeGenerationResourceNameChange(configs[i], fResource.getFullPath(), fResource.getParent().getFullPath().append(getArguments().getNewName()));
        changes.add(change);
    }
    return HibernateRefactoringUtil.createChangesFromList(changes, getName());
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) ArrayList(java.util.ArrayList) Change(org.eclipse.ltk.core.refactoring.Change)

Aggregations

ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)107 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)19 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)17 CoreException (org.eclipse.core.runtime.CoreException)16 PartInitException (org.eclipse.ui.PartInitException)13 IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)12 KnownConfigurations (org.hibernate.console.KnownConfigurations)11 JavaModelException (org.eclipse.jdt.core.JavaModelException)10 TreePath (org.eclipse.jface.viewers.TreePath)10 Test (org.junit.Test)10 File (java.io.File)9 ArrayList (java.util.ArrayList)9 FileNotFoundException (java.io.FileNotFoundException)8 IPath (org.eclipse.core.runtime.IPath)8 TreeSelection (org.eclipse.jface.viewers.TreeSelection)8 IService (org.jboss.tools.hibernate.runtime.spi.IService)8 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)7 IEditorPart (org.eclipse.ui.IEditorPart)7 ConsoleConfigurationPreferences (org.hibernate.console.preferences.ConsoleConfigurationPreferences)7 GridLayout (org.eclipse.swt.layout.GridLayout)6