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