Author: dgeraskov
Date: 2009-02-09 04:26:58 -0500 (Mon, 09 Feb 2009)
New Revision: 13538
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/JPAPostInstallFasetListener.java
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/META-INF/MANIFEST.MF
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/plugin.xml
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateFactory.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-3664
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/META-INF/MANIFEST.MF
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/META-INF/MANIFEST.MF 2009-02-09
04:09:54 UTC (rev 13537)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/META-INF/MANIFEST.MF 2009-02-09
09:26:58 UTC (rev 13538)
@@ -13,7 +13,8 @@
org.eclipse.jdt.launching;bundle-version="3.4.0",
org.eclipse.debug.core;bundle-version="3.4.0",
org.eclipse.emf.ecore;bundle-version="2.4.0",
- org.eclipse.jdt.core;bundle-version="3.4.0"
+ org.eclipse.jdt.core;bundle-version="3.4.0",
+ org.eclipse.wst.common.project.facet.core;bundle-version="1.3.0"
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-Vendor: %Bundle-Vendor.0
Export-Package: org.jboss.tools.hibernate.jpt.core.internal,
Modified: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/plugin.xml
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/plugin.xml 2009-02-09
04:09:54 UTC (rev 13537)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/plugin.xml 2009-02-09
09:26:58 UTC (rev 13538)
@@ -11,5 +11,12 @@
id="hibernate"
label="Hibernate"/>
</extension>
+ <extension
+ point="org.eclipse.wst.common.project.facet.core.listeners">
+ <listener
+
class="org.jboss.tools.hibernate.jpt.core.internal.JPAPostInstallFasetListener"
+ eventTypes="POST_INSTALL">
+ </listener>
+ </extension>
</plugin>
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateFactory.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateFactory.java 2009-02-09
04:09:54 UTC (rev 13537)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateFactory.java 2009-02-09
09:26:58 UTC (rev 13538)
@@ -41,30 +41,4 @@
return new HibernatePersistenceUnit(parent, persistenceUnit);
}
-
- @Override
- public JpaDataSource buildJpaDataSource(JpaProject jpaProject, String
connectionProfileName) {
- try {
- buildConsoleConfiguration(jpaProject, connectionProfileName);
- } catch (CoreException e) {
- //logErrorMessage("Can't create console configuration for project " +
jpaProject.getName(), e);
- }
- return super.buildJpaDataSource(jpaProject, connectionProfileName);
- }
-
- protected void buildConsoleConfiguration(JpaProject jpaProject, String
connectionProfileName) throws CoreException{
- if (connectionProfileName == null || connectionProfileName.length() == 0) return;
- ILaunchManager lm = DebugPlugin.getDefault().getLaunchManager();
- ILaunchConfigurationType lct =
lm.getLaunchConfigurationType(ICodeGenerationLaunchConstants.CONSOLE_CONFIGURATION_LAUNCH_TYPE_ID);
- ILaunchConfigurationWorkingCopy wc = lct.newInstance(null, jpaProject.getName());
-
- wc.setAttribute(IConsoleConfigurationLaunchConstants.CONFIGURATION_FACTORY,
ConfigurationMode.JPA.toString());
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,
jpaProject.getName());
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, true );
- wc.setAttribute(IConsoleConfigurationLaunchConstants.FILE_MAPPINGS,
(List<String>)null);
- //wc.setAttribute(IConsoleConfigurationLaunchConstants.CONNECTION_PROFILE_NAME,
connectionProfileName);
- wc.setAttribute(IConsoleConfigurationLaunchConstants.USE_JPA_PROJECT_PROFILE,
"true");//$NON-NLS-1$
-
- wc.doSave();
- }
}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/JPAPostInstallFasetListener.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/JPAPostInstallFasetListener.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/JPAPostInstallFasetListener.java 2009-02-09
09:26:58 UTC (rev 13538)
@@ -0,0 +1,99 @@
+package org.jboss.tools.hibernate.jpt.core.internal;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Pattern;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
+import org.eclipse.jpt.core.JptCorePlugin;
+import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectEvent;
+import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectListener;
+import org.eclipse.wst.common.project.facet.core.events.IProjectFacetActionEvent;
+import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectEvent.Type;
+import
org.hibernate.console.preferences.ConsoleConfigurationPreferences.ConfigurationMode;
+import org.hibernate.eclipse.console.utils.ProjectUtils;
+import org.hibernate.eclipse.launch.ICodeGenerationLaunchConstants;
+import org.hibernate.eclipse.launch.IConsoleConfigurationLaunchConstants;
+
+public class JPAPostInstallFasetListener implements IFacetedProjectListener {
+
+ public void handleEvent(IFacetedProjectEvent event) {
+ if (event.getType() == Type.POST_INSTALL){
+ IProject project = event.getProject().getProject();
+ IProjectFacetActionEvent pEvent = (IProjectFacetActionEvent)event;
+ if (pEvent.getProjectFacet().getId().equals(JptCorePlugin.FACET_ID)
+ && HibernatePlatform.ID.equals(JptCorePlugin.getJpaPlatformId(project))){
+ if (checkPreConditions(project)){
+ buildConsoleConfiguration(project);
+ }
+ }
+ }
+ }
+
+ /**
+ *
+ * @param project
+ * @return true if need to create new ConsoleConfiguration, false - otherwise.
+ */
+ protected boolean checkPreConditions(IProject project){
+ try {
+ ILaunchConfiguration lc = getLaunchConfiguration(project);
+ if (lc != null){
+ ProjectUtils.toggleHibernateOnProject(project, true, lc.getName());
+ return false;
+ }
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ return true;
+ }
+
+ private ILaunchConfiguration getLaunchConfiguration(IProject project) throws
CoreException{
+ ILaunchManager lm = DebugPlugin.getDefault().getLaunchManager();
+ ILaunchConfigurationType lct =
lm.getLaunchConfigurationType(ICodeGenerationLaunchConstants.CONSOLE_CONFIGURATION_LAUNCH_TYPE_ID);
+ List<ILaunchConfiguration> configs = new
ArrayList<ILaunchConfiguration>();
+ for (int i = 0; i < lm.getLaunchConfigurations(lct).length; i++){
+ ILaunchConfiguration lc = lm.getLaunchConfigurations(lct)[i];
+ if (project.getName().equals(
+ lc.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,
""))){//lc uses this project
+ if (project.getName().equals(lc.getName())) return lc;
+ configs.add(lc);
+ }
+ }
+ //select best launch configuration "projectName (1)"
+ Pattern p = Pattern.compile(project.getName() + " \\(\\d+\\)");
+ for (int i = 0; i < configs.size(); i++) {
+ ILaunchConfiguration lc = configs.get(i);
+ if (p.matcher(lc.getName()).matches()) return lc;
+ }
+ return configs.size() > 0 ? configs.get(0) : null;
+ }
+
+ protected void buildConsoleConfiguration(IProject project){
+ ILaunchManager lm = DebugPlugin.getDefault().getLaunchManager();
+ ILaunchConfigurationType lct =
lm.getLaunchConfigurationType(ICodeGenerationLaunchConstants.CONSOLE_CONFIGURATION_LAUNCH_TYPE_ID);
+ String launchName = lm.generateUniqueLaunchConfigurationNameFrom(project.getName());
+ ILaunchConfigurationWorkingCopy wc;
+ try {
+ wc = lct.newInstance(null, launchName);
+ wc.setAttribute(IConsoleConfigurationLaunchConstants.CONFIGURATION_FACTORY,
ConfigurationMode.JPA.toString());
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,
project.getName());
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, true );
+ wc.setAttribute(IConsoleConfigurationLaunchConstants.FILE_MAPPINGS,
(List<String>)null);
+ wc.setAttribute(IConsoleConfigurationLaunchConstants.USE_JPA_PROJECT_PROFILE,
"true");//$NON-NLS-1$
+
+ wc.doSave();
+ ProjectUtils.toggleHibernateOnProject(project, true, launchName);
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
Property changes on:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/JPAPostInstallFasetListener.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native