Search in sources :

Example 16 with IArtifactCollector

use of org.jboss.tools.hibernate.runtime.spi.IArtifactCollector in project jbosstools-hibernate by jbosstools.

the class ConsoleExtension method launchExporters.

public Map<String, File[]> launchExporters(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
    Assert.isNotNull(configuration);
    Assert.isNotNull(monitor);
    ExporterAttributes attributes = new ExporterAttributes(configuration);
    List<ExporterFactory> exporterFactories = attributes.getExporterFactories();
    for (Iterator<ExporterFactory> iter = exporterFactories.iterator(); iter.hasNext(); ) {
        ExporterFactory exFactory = iter.next();
        if (!exFactory.isEnabled(configuration)) {
            iter.remove();
        }
    }
    try {
        Set<String> outputDirectories = new HashSet<String>();
        ExporterFactory[] exporters = exporterFactories.toArray(new ExporterFactory[exporterFactories.size()]);
        IArtifactCollector collector = runExporters(attributes, exporters, outputDirectories, monitor);
        for (String path : outputDirectories) {
            CodeGenerationUtils.refreshOutputDir(path);
        }
        // eclipse will format the uptodate files!
        if (collector != null) {
            Map<String, File[]> map = new HashMap<String, File[]>();
            Set<String> types = collector.getFileTypes();
            for (String type : types) {
                File[] files = collector.getFiles(type.toString());
                map.put(type, files);
            }
            return map;
        }
    } catch (Exception e) {
        throw new CoreException(HibernatePlugin.throwableToStatus(e, 666));
    } catch (NoClassDefFoundError e) {
        throw new CoreException(HibernatePlugin.throwableToStatus(new HibernateConsoleRuntimeException(HibernateConsoleMessages.CodeGenerationLaunchDelegate_received_noclassdeffounderror, e), 666));
    } finally {
        monitor.done();
    }
    return null;
}
Also used : HashMap(java.util.HashMap) ExporterAttributes(org.hibernate.eclipse.launch.ExporterAttributes) CoreException(org.eclipse.core.runtime.CoreException) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException) HibernateException(org.jboss.tools.hibernate.runtime.spi.HibernateException) IArtifactCollector(org.jboss.tools.hibernate.runtime.spi.IArtifactCollector) CoreException(org.eclipse.core.runtime.CoreException) ExporterFactory(org.hibernate.eclipse.console.model.impl.ExporterFactory) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException) File(java.io.File) HashSet(java.util.HashSet)

Example 17 with IArtifactCollector

use of org.jboss.tools.hibernate.runtime.spi.IArtifactCollector in project jbosstools-hibernate by jbosstools.

the class CoreMappingTestHelper method testHbmExportExceptionTest.

public void testHbmExportExceptionTest(String packageName) throws Exception {
    String projectName = testProject.getIProject().getName();
    String pathName = "/" + projectName + "/src/" + packageName.replace('.', '/');
    IPackageFragment testPackage = testProject.getIJavaProject().findPackageFragment(new Path(pathName));
    try {
        Object[] persClassesInit = getPersistenceClasses(true);
        final ConsoleConfiguration consCFG = getConsoleConfig();
        IConfiguration config = consCFG.getConfiguration();
        // delete old hbm files
        Assert.assertNotNull(testPackage);
        int nDeleted = 0;
        if (testPackage.getNonJavaResources().length > 0) {
            Object[] ress = testPackage.getNonJavaResources();
            for (int i = 0; i < ress.length; i++) {
                if (ress[i] instanceof IFile) {
                    IFile res = (IFile) ress[i];
                    if (res.getName().endsWith(".hbm.xml")) {
                        // $NON-NLS-1$
                        res.delete(true, false, null);
                        nDeleted++;
                    }
                }
            }
        }
        String[] versions = ServiceLookup.getVersions();
        IService service = ServiceLookup.findService(versions[0]);
        File srcFolder = testProject.getIProject().getFolder(TestProject.SRC_FOLDER).getLocation().toFile();
        IHibernateMappingExporter hce = service.newHibernateMappingExporter(config, srcFolder);
        try {
            hce.start();
            IArtifactCollector collector = service.newArtifactCollector();
            collector.formatFiles();
            try {
                // build generated configuration
                testPackage.getResource().refreshLocal(IResource.DEPTH_INFINITE, null);
                testPackage.getJavaProject().getProject().build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
                ConsoleConfigUtils.customizeCfgXmlForPack(testPackage);
                Assert.assertNotNull(consCFG);
                consCFG.reset();
                consCFG.build();
                Assert.assertTrue(consCFG.hasConfiguration());
                consCFG.getConfiguration().buildMappings();
                config = consCFG.getConfiguration();
            } catch (CoreException e) {
                String out = NLS.bind(TestConsoleMessages.UpdateConfigurationTest_error_customising_file_for_package, new Object[] { ConsoleConfigUtils.CFG_FILE_NAME, testPackage.getPath(), e.getMessage() });
                Assert.fail(out);
            }
        } catch (Exception e) {
            throw e;
        // throw (Exception)e.getCause();
        }
        // 
        Object[] persClassesReInit = getPersistenceClasses(false);
        // 
        int nCreated = 0;
        if (testPackage.getNonJavaResources().length > 0) {
            Object[] ress = testPackage.getNonJavaResources();
            for (int i = 0; i < ress.length; i++) {
                if (ress[i] instanceof IFile) {
                    IFile res = (IFile) ress[i];
                    if (res.getName().endsWith(".hbm.xml")) {
                        // $NON-NLS-1$
                        nCreated++;
                    }
                }
            }
        }
        // 
        Assert.assertTrue(persClassesInit.length == persClassesReInit.length);
        Assert.assertTrue(nCreated > 0);
        Assert.assertTrue(nDeleted >= 0 && persClassesInit.length > 0);
        Assert.assertTrue(nCreated <= persClassesInit.length);
    } catch (Exception e) {
        // $NON-NLS-1$ //$NON-NLS-2$
        String newMessage = "\nPackage " + testPackage.getElementName() + ":";
        throw new WrapperException(newMessage, e);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) IFile(org.eclipse.core.resources.IFile) JavaModelException(org.eclipse.jdt.core.JavaModelException) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) FileNotFoundException(java.io.FileNotFoundException) IArtifactCollector(org.jboss.tools.hibernate.runtime.spi.IArtifactCollector) CoreException(org.eclipse.core.runtime.CoreException) IHibernateMappingExporter(org.jboss.tools.hibernate.runtime.spi.IHibernateMappingExporter) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IService(org.jboss.tools.hibernate.runtime.spi.IService)

Example 18 with IArtifactCollector

use of org.jboss.tools.hibernate.runtime.spi.IArtifactCollector in project jbosstools-hibernate by jbosstools.

the class MappingTestHelper method testHbmExportExceptionTest.

public void testHbmExportExceptionTest() throws Exception {
    String projectName = testProject.getIProject().getName();
    String pathName = "/" + projectName + "/src/" + packageName.replace('.', '/');
    IPackageFragment testPackage = testProject.getIJavaProject().findPackageFragment(new Path(pathName));
    try {
        Object[] persClassesInit = getPersistenceClasses(true);
        final ConsoleConfiguration consCFG = getConsoleConfig();
        IConfiguration config = consCFG.getConfiguration();
        // delete old hbm files
        Assert.assertNotNull(testPackage);
        int nDeleted = 0;
        if (testPackage.getNonJavaResources().length > 0) {
            Object[] ress = testPackage.getNonJavaResources();
            for (int i = 0; i < ress.length; i++) {
                if (ress[i] instanceof IFile) {
                    IFile res = (IFile) ress[i];
                    if (res.getName().endsWith(".hbm.xml")) {
                        // $NON-NLS-1$
                        res.delete(true, false, null);
                        nDeleted++;
                    }
                }
            }
        }
        String[] versions = ServiceLookup.getVersions();
        IService service = ServiceLookup.findService(versions[0]);
        File srcFolder = testProject.getIProject().getFolder(TestProject.SRC_FOLDER).getLocation().toFile();
        IHibernateMappingExporter hce = service.newHibernateMappingExporter(config, srcFolder);
        try {
            hce.start();
            IArtifactCollector collector = service.newArtifactCollector();
            collector.formatFiles();
            try {
                // build generated configuration
                testPackage.getResource().refreshLocal(IResource.DEPTH_INFINITE, null);
                testPackage.getJavaProject().getProject().build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
                ConsoleConfigUtils.customizeCfgXmlForPack(testPackage);
                Assert.assertNotNull(consCFG);
                consCFG.reset();
                consCFG.build();
                Assert.assertTrue(consCFG.hasConfiguration());
                consCFG.getConfiguration().buildMappings();
                config = consCFG.getConfiguration();
            } catch (CoreException e) {
                String out = NLS.bind(TestConsoleMessages.UpdateConfigurationTest_error_customising_file_for_package, new Object[] { ConsoleConfigUtils.CFG_FILE_NAME, testPackage.getPath(), e.getMessage() });
                Assert.fail(out);
            }
        } catch (Exception e) {
            // throw (Exception)e.getCause();
            throw e;
        }
        // 
        Object[] persClassesReInit = getPersistenceClasses(false);
        // 
        int nCreated = 0;
        if (testPackage.getNonJavaResources().length > 0) {
            Object[] ress = testPackage.getNonJavaResources();
            for (int i = 0; i < ress.length; i++) {
                if (ress[i] instanceof IFile) {
                    IFile res = (IFile) ress[i];
                    if (res.getName().endsWith(".hbm.xml")) {
                        // $NON-NLS-1$
                        nCreated++;
                    }
                }
            }
        }
        // 
        Assert.assertTrue(persClassesInit.length == persClassesReInit.length);
        Assert.assertTrue(nCreated > 0);
        Assert.assertTrue(nDeleted >= 0 && persClassesInit.length > 0);
        Assert.assertTrue(nCreated <= persClassesInit.length);
    } catch (Exception e) {
        // $NON-NLS-1$ //$NON-NLS-2$
        String newMessage = "\nPackage " + testPackage.getElementName() + ":";
        throw new WrapperException(newMessage, e);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) IFile(org.eclipse.core.resources.IFile) JavaModelException(org.eclipse.jdt.core.JavaModelException) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) FileNotFoundException(java.io.FileNotFoundException) IArtifactCollector(org.jboss.tools.hibernate.runtime.spi.IArtifactCollector) CoreException(org.eclipse.core.runtime.CoreException) IHibernateMappingExporter(org.jboss.tools.hibernate.runtime.spi.IHibernateMappingExporter) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IService(org.jboss.tools.hibernate.runtime.spi.IService)

Example 19 with IArtifactCollector

use of org.jboss.tools.hibernate.runtime.spi.IArtifactCollector in project jbosstools-hibernate by jbosstools.

the class FacadeFactoryTest method testCreateArtifactCollector.

@Test
public void testCreateArtifactCollector() {
    ArtifactCollector artifactCollector = new ArtifactCollector();
    IArtifactCollector facade = facadeFactory.createArtifactCollector(artifactCollector);
    Assert.assertSame(artifactCollector, ((IFacade) facade).getTarget());
}
Also used : IArtifactCollector(org.jboss.tools.hibernate.runtime.spi.IArtifactCollector) IArtifactCollector(org.jboss.tools.hibernate.runtime.spi.IArtifactCollector) ArtifactCollector(org.hibernate.tool.hbm2x.ArtifactCollector) Test(org.junit.Test)

Example 20 with IArtifactCollector

use of org.jboss.tools.hibernate.runtime.spi.IArtifactCollector in project jbosstools-hibernate by jbosstools.

the class ExporterFacadeTest method testSetArtifactCollector.

@Test
public void testSetArtifactCollector() {
    ArtifactCollector ac = new ArtifactCollector();
    IArtifactCollector artifactCollector = new AbstractArtifactCollectorFacade(FACADE_FACTORY, ac) {
    };
    exporterFacade.setArtifactCollector(artifactCollector);
    Assert.assertEquals("setArtifactCollector", methodName);
    Assert.assertArrayEquals(new Object[] { ac }, arguments);
}
Also used : AbstractArtifactCollectorFacade(org.jboss.tools.hibernate.runtime.common.AbstractArtifactCollectorFacade) IArtifactCollector(org.jboss.tools.hibernate.runtime.spi.IArtifactCollector) ArtifactCollector(org.hibernate.tool.hbm2x.ArtifactCollector) IArtifactCollector(org.jboss.tools.hibernate.runtime.spi.IArtifactCollector) Test(org.junit.Test)

Aggregations

IArtifactCollector (org.jboss.tools.hibernate.runtime.spi.IArtifactCollector)27 ArtifactCollector (org.hibernate.tool.hbm2x.ArtifactCollector)20 Test (org.junit.Test)20 AbstractArtifactCollectorFacade (org.jboss.tools.hibernate.runtime.common.AbstractArtifactCollectorFacade)8 CoreException (org.eclipse.core.runtime.CoreException)7 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)6 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)5 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)4 File (java.io.File)3 Properties (java.util.Properties)3 IFile (org.eclipse.core.resources.IFile)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 JavaModelException (org.eclipse.jdt.core.JavaModelException)3 HibernateConsoleRuntimeException (org.hibernate.console.HibernateConsoleRuntimeException)3 HibernateException (org.jboss.tools.hibernate.runtime.spi.HibernateException)3 IExporter (org.jboss.tools.hibernate.runtime.spi.IExporter)3 IHibernateMappingExporter (org.jboss.tools.hibernate.runtime.spi.IHibernateMappingExporter)3 IService (org.jboss.tools.hibernate.runtime.spi.IService)3 FileNotFoundException (java.io.FileNotFoundException)2 HashSet (java.util.HashSet)2