Search in sources :

Example 1 with EclipseLaunchConsoleConfigurationPreferences

use of org.hibernate.eclipse.console.EclipseLaunchConsoleConfigurationPreferences in project jbosstools-hibernate by jbosstools.

the class CodeGenExternalProcessExecutionTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    this.project = new LaunchConfigTestProject2();
    final String fileNameConsoleConfig = LaunchConfigTestProject2.LAUNCH_CONSOLE_CONFIG_TEST_FILE;
    ILaunchConfiguration launchConfig = loadLaunchConfigFromFile(fileNameConsoleConfig);
    final EclipseLaunchConsoleConfigurationPreferences cfgprefs = new EclipseLaunchConsoleConfigurationPreferences(launchConfig);
    consoleCfg = new ConsoleConfiguration(cfgprefs);
    KnownConfigurations.getInstance().addConfiguration(consoleCfg, true);
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) EclipseLaunchConsoleConfigurationPreferences(org.hibernate.eclipse.console.EclipseLaunchConsoleConfigurationPreferences) LaunchConfigTestProject2(org.hibernate.eclipse.console.test.project.LaunchConfigTestProject2)

Example 2 with EclipseLaunchConsoleConfigurationPreferences

use of org.hibernate.eclipse.console.EclipseLaunchConsoleConfigurationPreferences 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 3 with EclipseLaunchConsoleConfigurationPreferences

use of org.hibernate.eclipse.console.EclipseLaunchConsoleConfigurationPreferences in project jbosstools-hibernate by jbosstools.

the class EclipseLaunchConsoleConfigurationPreferencesTest method testCloseStream.

/**
 * test method for eclipseLaunchConsoleConfigurationPreferences.getProperties
 * @throws CoreException
 */
public void testCloseStream() throws CoreException {
    final ILaunchConfiguration launchConfiguration = context.mock(ILaunchConfiguration.class);
    final EclipseLaunchConsoleConfigurationPreferences eclipseLaunchConsoleConfigurationPreferences = new EclipseLaunchConsoleConfigurationPreferences(launchConfiguration);
    final String propertiesFilePath = getPropertiesFilePath();
    context.checking(new Expectations() {

        {
            allowing(launchConfiguration).getAttribute(IConsoleConfigurationLaunchConstants.PROPERTY_FILE, (String) null);
            will(returnValue(propertiesFilePath));
        }
    });
    Properties properties = eclipseLaunchConsoleConfigurationPreferences.getProperties();
    assertNotNull(properties);
    assertTrue(properties.size() == 1);
    context.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) EclipseLaunchConsoleConfigurationPreferences(org.hibernate.eclipse.console.EclipseLaunchConsoleConfigurationPreferences) Properties(java.util.Properties)

Aggregations

EclipseLaunchConsoleConfigurationPreferences (org.hibernate.eclipse.console.EclipseLaunchConsoleConfigurationPreferences)3 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)2 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)2 Properties (java.util.Properties)1 CoreException (org.eclipse.core.runtime.CoreException)1 IRuntimeClasspathEntry (org.eclipse.jdt.launching.IRuntimeClasspathEntry)1 HibernateConsoleRuntimeException (org.hibernate.console.HibernateConsoleRuntimeException)1 LaunchConfigTestProject2 (org.hibernate.eclipse.console.test.project.LaunchConfigTestProject2)1 Expectations (org.jmock.Expectations)1