Search in sources :

Example 61 with ILaunchConfiguration

use of org.eclipse.debug.core.ILaunchConfiguration in project jbosstools-hibernate by jbosstools.

the class CodeGenerationConsoleNameChange method perform.

/* (non-Javadoc)
	 * @see org.eclipse.ltk.core.refactoring.Change#perform(org.eclipse.core.runtime.IProgressMonitor)
	 */
@Override
public Change perform(IProgressMonitor pm) throws CoreException {
    String oldName = fLaunchConfiguration.getAttribute(HibernateLaunchConstants.ATTR_CONSOLE_CONFIGURATION_NAME, new String());
    ILaunchConfigurationWorkingCopy wc = fLaunchConfiguration.getWorkingCopy();
    wc.setAttribute(HibernateLaunchConstants.ATTR_CONSOLE_CONFIGURATION_NAME, newCCName);
    ILaunchConfiguration newLaunchConfig = wc.doSave();
    return new CodeGenerationConsoleNameChange(newLaunchConfig, oldName);
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)

Example 62 with ILaunchConfiguration

use of org.eclipse.debug.core.ILaunchConfiguration in project jbosstools-hibernate by jbosstools.

the class ExporterAttributesTest method checkCorrectLaunchConfigurationFile.

private void checkCorrectLaunchConfigurationFile(final String fileName) {
    // IWorkspace ws = ResourcesPlugin.getWorkspace();
    String str1, str2;
    ILaunchConfiguration launchConfig = loadLaunchConfigFromFile(fileName);
    Map<String, Object> attrMap = null;
    try {
        attrMap = launchConfig.getAttributes();
    } catch (CoreException e) {
        e.printStackTrace();
    }
    Assert.assertNotNull(attrMap);
    ExporterAttributes exporterAttributes = null;
    try {
        exporterAttributes = new ExporterAttributes(launchConfig);
    } catch (CoreException e) {
        e.printStackTrace();
    }
    Assert.assertNotNull(exporterAttributes);
    // check is configuration correct
    Assert.assertNull(exporterAttributes.checkExporterAttributes());
    List<ExporterFactory> exporterFactories = exporterAttributes.getExporterFactories();
    Set<ExporterFactory> selectedExporters = new HashSet<ExporterFactory>();
    selectedExporters.addAll(exporterFactories);
    Set<String> deletedExporterIds = new HashSet<String>();
    ILaunchConfigurationWorkingCopy launchConfigWC = null;
    try {
        launchConfigWC = launchConfig.getWorkingCopy();
    } catch (CoreException e) {
        e.printStackTrace();
    }
    Assert.assertNotNull(launchConfigWC);
    // 
    str1 = project.getSample(fileName);
    str1 = ResourceReadUtils.adjustXmlText(str1);
    // 
    Assert.assertNotNull(project);
    Assert.assertNotNull(project.getIProject());
    Assert.assertNotNull(project.getIProject().getFile(fileName));
    // 
    InputStream is = null;
    try {
        is = project.getIProject().getFile(fileName).getContents();
    } catch (CoreException e) {
        e.printStackTrace();
    }
    Assert.assertNotNull(is);
    str2 = ResourceReadUtils.readStream(is);
    str2 = ResourceReadUtils.adjustXmlText(str2);
    Assert.assertEquals(str1, str2);
    // update and save lc - so fileName from the project updated
    try {
        ExporterAttributes.saveExporterFactories(launchConfigWC, exporterFactories, selectedExporters, deletedExporterIds);
        launchConfigWC.doSave();
    } catch (CoreException e) {
        Assert.fail(e.getMessage());
    }
    // 
    is = null;
    try {
        is = project.getIProject().getFile(fileName).getContents();
    } catch (CoreException e) {
        e.printStackTrace();
    }
    Assert.assertNotNull(is);
    str2 = ResourceReadUtils.readStream(is);
    str2 = ResourceReadUtils.adjustXmlText(str2);
    Assert.assertEquals(str1, str2);
    // 
    IArtifactCollector artifactCollector = service.newArtifactCollector();
    ExporterAttributes expAttr = exporterAttributes;
    // Global properties
    Properties props = new Properties();
    // $NON-NLS-1$
    props.put(CodeGenerationStrings.EJB3, "" + expAttr.isEJB3Enabled());
    // $NON-NLS-1$
    props.put(CodeGenerationStrings.JDK5, "" + expAttr.isJDK5Enabled());
    consoleCfg.build();
    IConfiguration cfg = consoleCfg.getConfiguration();
    Assert.assertNotNull(cfg);
    Set<String> outputDirectories = new HashSet<String>();
    for (int i = 0; i < exporterFactories.size(); i++) {
        Properties globalProperties = new Properties();
        globalProperties.putAll(props);
        ExporterFactory ef = exporterFactories.get(i);
        // 
        Properties propsForTesting = new Properties();
        propsForTesting.putAll(globalProperties);
        propsForTesting.putAll(ef.getProperties());
        // 
        IExporter exporter = null;
        outputDirectories.clear();
        try {
            exporter = ef.createConfiguredExporter(cfg, expAttr.getOutputPath(), expAttr.getTemplatePath(), globalProperties, outputDirectories, artifactCollector, service);
        } catch (CoreException e) {
            e.printStackTrace();
        }
        Assert.assertNotNull(exporter);
        Assert.assertTrue(outputDirectories.size() > 0);
        Properties propsFromExporter = exporter.getProperties();
        String exporterDefinitionId = ef.getExporterDefinitionId();
        // test special handling for GenericExporter
        if (exporterDefinitionId.equals("org.hibernate.tools.hbmtemplate")) {
            // $NON-NLS-1$
            Assert.assertNull(propsFromExporter.getProperty(ExporterFactoryStrings.FILE_PATTERN));
            Assert.assertNull(propsFromExporter.getProperty(ExporterFactoryStrings.TEMPLATE_NAME));
            Assert.assertNull(propsFromExporter.getProperty(ExporterFactoryStrings.FOR_EACH));
            IGenericExporter ge = exporter.getGenericExporter();
            Assert.assertNotNull(ge);
            Assert.assertEquals(propsForTesting.getProperty(ExporterFactoryStrings.FILE_PATTERN), ge.getFilePattern());
            Assert.assertEquals(propsForTesting.getProperty(ExporterFactoryStrings.TEMPLATE_NAME), ge.getTemplateName());
        // to test GenericExporter should provide public getter but it doesn't
        // assertEquals(propsForTesting.getProperty(ExporterFactoryStrings.FOR_EACH), ge.getForEach());
        }
        // test special handling for Hbm2DDLExporter
        if (exporterDefinitionId.equals("org.hibernate.tools.hbm2ddl")) {
            // $NON-NLS-1$
            Assert.assertNull(propsFromExporter.getProperty(ExporterFactoryStrings.EXPORTTODATABASE));
            IHbm2DDLExporter ddlExporter = exporter.getHbm2DDLExporter();
            Assert.assertNotNull(ddlExporter);
        // to test Hbm2DDLExporter should provide public getter but it doesn't
        // assertEquals(propsForTesting.getProperty(ExporterFactoryStrings.EXPORTTODATABASE), ddlExporter.getExport());
        }
        // test special handling for QueryExporter
        if (exporterDefinitionId.equals("org.hibernate.tools.query")) {
            // $NON-NLS-1$
            Assert.assertNull(propsFromExporter.getProperty(ExporterFactoryStrings.QUERY_STRING));
            Assert.assertNull(propsFromExporter.getProperty(ExporterFactoryStrings.OUTPUTFILENAME));
        // IQueryExporter queryExporter = exporter.getQueryExporter();
        // to test QueryExporter should provide public getter but it doesn't
        // List<String> queryStrings = queryExporter.getQueries();
        // assertEquals(1, queryStrings.size());
        // assertEquals(propsForTesting.getProperty(ExporterFactoryStrings.QUERY_STRING), queryStrings.get(0));
        // assertEquals(propsForTesting.getProperty(ExporterFactoryStrings.OUTPUTFILENAME), queryExporter.getFileName());
        }
    // try {
    // exporter.start();
    // } catch (HibernateException he) {
    // he.printStackTrace();
    // }
    }
    Assert.assertTrue(artifactCollector.getFileTypes().size() == 0);
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) InputStream(java.io.InputStream) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) Properties(java.util.Properties) ExporterAttributes(org.hibernate.eclipse.launch.ExporterAttributes) CoreException(org.eclipse.core.runtime.CoreException) IArtifactCollector(org.jboss.tools.hibernate.runtime.spi.IArtifactCollector) IHbm2DDLExporter(org.jboss.tools.hibernate.runtime.spi.IHbm2DDLExporter) ExporterFactory(org.hibernate.eclipse.console.model.impl.ExporterFactory) IExporter(org.jboss.tools.hibernate.runtime.spi.IExporter) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) IGenericExporter(org.jboss.tools.hibernate.runtime.spi.IGenericExporter) HashSet(java.util.HashSet)

Example 63 with ILaunchConfiguration

use of org.eclipse.debug.core.ILaunchConfiguration in project jbosstools-hibernate by jbosstools.

the class ExporterAttributesTest method loadLaunchConfigFromFile.

private ILaunchConfiguration loadLaunchConfigFromFile(String fileName) {
    IPath path = new Path(fileName);
    IFile ifile = project.getIProject().getFile(path);
    ILaunchConfiguration launchConfig = launchManager.getLaunchConfiguration((IFile) ifile);
    return launchConfig;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath)

Example 64 with ILaunchConfiguration

use of org.eclipse.debug.core.ILaunchConfiguration in project jbosstools-hibernate by jbosstools.

the class AnalyzersCombo method populateComboBox.

protected void populateComboBox() {
    String projName = null;
    try {
        ILaunchConfiguration launchConfiguration = LaunchHelper.findHibernateLaunchConfig(this.consoleConfigName);
        // $NON-NLS-1$
        projName = launchConfiguration.getAttribute(IConsoleConfigurationLaunchConstants.PROJECT_NAME, "");
    } catch (CoreException e) {
        HibernateSearchConsolePlugin.getDefault().logError(e);
    }
    IJavaProject project = ProjectUtils.findJavaProject(projName);
    final IType analyzersType = ProjectUtils.findType(project, "org.apache.lucene.analysis.Analyzer");
    comboControl.getDisplay().syncExec(new Runnable() {

        public void run() {
            try {
                IType[] types = analyzersType.newTypeHierarchy(new NullProgressMonitor()).getAllSubtypes(analyzersType);
                List<String> typesList = new LinkedList<String>();
                for (IType type : types) {
                    try {
                        if (type.getMethod(type.getElementName(), new String[0]).isConstructor()) {
                            typesList.add(type.getFullyQualifiedName());
                            continue;
                        }
                    } catch (JavaModelException e) {
                        HibernateSearchConsolePlugin.getDefault().logInfo("Analuzer " + type.getFullyQualifiedName() + " doesn't have constrcutor with no parameters", e);
                    }
                    try {
                        if (type.getMethod(type.getElementName(), new String[] { "Lorg.apache.lucene.util.Version;" }).isConstructor()) {
                            typesList.add(type.getFullyQualifiedName());
                            continue;
                        }
                    } catch (JavaModelException e) {
                        HibernateSearchConsolePlugin.getDefault().logWarning("Analuzer " + type.getFullyQualifiedName() + " doesn't have constrcutor with Version as a parameter", e);
                    }
                }
                comboControl.setItems(typesList.toArray(new String[0]));
                comboControl.setText(DEFAULT_ANALYZER);
            } catch (JavaModelException e) {
                HibernateConsolePlugin.getDefault().log(e);
            }
        }
    });
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) JavaModelException(org.eclipse.jdt.core.JavaModelException) IJavaProject(org.eclipse.jdt.core.IJavaProject) CoreException(org.eclipse.core.runtime.CoreException) List(java.util.List) LinkedList(java.util.LinkedList) IType(org.eclipse.jdt.core.IType)

Example 65 with ILaunchConfiguration

use of org.eclipse.debug.core.ILaunchConfiguration in project jbosstools-hibernate by jbosstools.

the class LaunchHelper method findFilteredHibernateLaunchConfigs.

/**
 * UI elements should use this method as it does filtering of launch configuration related
 * to deleted or closed projects if the settings are set.
 * @return
 * @throws CoreException
 */
public static ILaunchConfiguration[] findFilteredHibernateLaunchConfigs() throws CoreException {
    ILaunchConfiguration[] allHibernateLaunchConfigurations = findHibernateLaunchConfigs();
    List<ILaunchConfiguration> launchConfigurations = new ArrayList<ILaunchConfiguration>();
    for (ILaunchConfiguration config : allHibernateLaunchConfigurations) {
        if (DebugUIPlugin.doLaunchConfigurationFiltering(config))
            launchConfigurations.add(config);
    }
    return launchConfigurations.toArray(new ILaunchConfiguration[launchConfigurations.size()]);
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) ArrayList(java.util.ArrayList)

Aggregations

ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)275 CoreException (org.eclipse.core.runtime.CoreException)100 ILaunchConfigurationWorkingCopy (org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)79 Test (org.junit.Test)72 ILaunchConfigurationType (org.eclipse.debug.core.ILaunchConfigurationType)51 ILaunchManager (org.eclipse.debug.core.ILaunchManager)41 ArrayList (java.util.ArrayList)37 ILaunch (org.eclipse.debug.core.ILaunch)37 IPath (org.eclipse.core.runtime.IPath)20 IProject (org.eclipse.core.resources.IProject)19 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)17 IStatus (org.eclipse.core.runtime.IStatus)16 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)16 IEditorPart (org.eclipse.ui.IEditorPart)15 IProcess (org.eclipse.debug.core.model.IProcess)14 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)14 IFile (org.eclipse.core.resources.IFile)13 Status (org.eclipse.core.runtime.Status)13 CachegrindViewPart (org.eclipse.linuxtools.internal.valgrind.cachegrind.CachegrindViewPart)13 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)11