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;
}
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);
}
}
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);
}
}
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());
}
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);
}
Aggregations