Author: dgeraskov
Date: 2008-01-15 09:35:56 -0500 (Tue, 15 Jan 2008)
New Revision: 5692
Added:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingDiagrammTest.java
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/META-INF/MANIFEST.MF
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/HibernateNatureAddTest.java
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/HibernateNatureRemoveTest.java
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/MappingTestProject.java
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/ProjectUtil.java
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/TestSet.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1596
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/META-INF/MANIFEST.MF
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/META-INF/MANIFEST.MF 2008-01-15
14:34:36 UTC (rev 5691)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/META-INF/MANIFEST.MF 2008-01-15
14:35:56 UTC (rev 5692)
@@ -28,7 +28,8 @@
org.eclipse.wst.xml.core,
org.eclipse.wst.xml.ui,
org.apache.ant,
- org.eclipse.ui.views
+ org.eclipse.ui.views,
+ org.jboss.tools.hibernate.ui.view
Eclipse-LazyStart: true
Bundle-Activator: org.hibernate.eclipse.console.test.HibernateConsoleTestPlugin
Eclipse-RegisterBuddy: org.hibernate.eclipse
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/HibernateNatureAddTest.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/HibernateNatureAddTest.java 2008-01-15
14:34:36 UTC (rev 5691)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/HibernateNatureAddTest.java 2008-01-15
14:35:56 UTC (rev 5692)
@@ -26,7 +26,7 @@
*
*/
public class HibernateNatureAddTest extends TestCase {
- public void testEnableHibernateNature() throws BackingStoreException, CoreException {
+ public void testHibernateNatureAdd() throws BackingStoreException, CoreException {
MappingTestProject project = MappingTestProject.getTestProject();
IJavaProject prj = project.getIJavaProject();
IScopeContext scope = new ProjectScope(prj.getProject() );
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/HibernateNatureRemoveTest.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/HibernateNatureRemoveTest.java 2008-01-15
14:34:36 UTC (rev 5691)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/HibernateNatureRemoveTest.java 2008-01-15
14:35:56 UTC (rev 5692)
@@ -23,7 +23,7 @@
*
*/
public class HibernateNatureRemoveTest extends TestCase {
- public void testEnableHibernateNature() throws BackingStoreException, CoreException {
+ public void testHibernateNatureRemove() throws BackingStoreException, CoreException {
MappingTestProject project = MappingTestProject.getTestProject();
IJavaProject prj = project.getIJavaProject();
ProjectUtils.removeProjectNature(prj.getProject(),
"org.hibernate.eclipse.console.hibernateNature", new NullProgressMonitor() );
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/MappingTestProject.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/MappingTestProject.java 2008-01-15
14:34:36 UTC (rev 5691)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/MappingTestProject.java 2008-01-15
14:35:56 UTC (rev 5692)
@@ -15,6 +15,7 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import org.eclipse.core.resources.IFile;
@@ -46,6 +47,8 @@
public class MappingTestProject{
public static final String SRC_FOLDER = "src";
+
+ public static final String LIB_FOLDER = "lib";
private static MappingTestProject singleton= null;
@@ -53,6 +56,7 @@
public static String PROJECT_NAME = "MappingTestProject";
public static String RESOURCE_PATH = "res/project/";
+ public static String RES_LIB_FNAME = ".lib";
private static FileFilter fileFilter = new FileFilter(){
public boolean accept(File pathname) {
@@ -65,6 +69,11 @@
if (pathname.getName().charAt(0) == '.') return false;
return pathname.isDirectory();
}};
+
+ private static FileFilter jarFilter = new FileFilter(){
+ public boolean accept(File pathname) {
+ return !pathname.isDirectory() || pathname.getName().endsWith(".jar");
+ }};
private IProject project;
private IJavaProject javaProject;
@@ -108,13 +117,15 @@
IPath resourcePath = new Path(RESOURCE_PATH);
File resourceFolder = resourcePath.toFile();
if (!resourceFolder.exists())
- throw new RuntimeException("Folder " + RESOURCE_PATH + " does not
found!");
+ throw new RuntimeException("Folder " + RESOURCE_PATH + " not
found!");
- IPackageFragmentRoot sourceFolder = buildSourceFolder(project, javaProject);
- recursiveCopyFiles(resourceFolder, (IFolder) sourceFolder.getResource());
+ IPackageFragmentRoot sourceFolder = createSourceFolder(project, javaProject);
+ recursiveCopyFiles(resourceFolder, (IFolder) sourceFolder.getResource());
+ List<IPath> libs = copyLibs(resourceFolder);
+ generateClassPath(libs, sourceFolder);
project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, new NullProgressMonitor());
- }
-
+ }
+
private void recursiveCopyFiles(File src, IFolder dst){
File[] files = src.listFiles(fileFilter);
for (int i = 0; i < files.length; i++) {
@@ -147,6 +158,47 @@
}
}
+ private List<IPath> copyLibs(File res) throws CoreException {
+ IFolder dst = project.getFolder(LIB_FOLDER);
+ if (!dst.exists()){
+ dst.create(false, true, null);
+ javaProject.getPackageFragmentRoot(dst);
+ }
+
+ File libFolder = new File(res.getAbsolutePath()+"/" + RES_LIB_FNAME);
+ if ( !libFolder.exists() )
+ throw new RuntimeException("Folder " + RESOURCE_PATH + RES_LIB_FNAME +
" not found!");
+
+
+ List<IPath> libs = new ArrayList<IPath>();
+
+ File[] files = libFolder.listFiles(jarFilter);
+ for (int i = 0; i < files.length; i++) {
+ File file = files[i];
+ if (!file.exists()) continue;
+ IFile iFile = dst.getFile(file.getName());
+ try {
+ iFile.create(new FileInputStream(file), true, null);
+ libs.add(iFile.getFullPath());
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ continue;
+ }
+ }
+ return libs;
+ }
+
+ private void generateClassPath(List<IPath> libs, IPackageFragmentRoot
sourceFolder) throws JavaModelException{
+ List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();
+ //entries.addAll(Arrays.asList(javaProject.getRawClasspath()));
+ for (IPath lib_path : libs) {
+ entries.add(JavaCore.newLibraryEntry(lib_path, null, null));
+ }
+ entries.add(JavaCore.newSourceEntry(sourceFolder.getPath()));
+ entries.add(JavaCore.newContainerEntry(JRE_CONTAINER));
+ javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[0]), null);
+ }
+
private IProject buildNewProject(String projectName) {
// get a project handle
@@ -195,16 +247,16 @@
}
- private IPackageFragmentRoot buildSourceFolder(IProject project,
+ private IPackageFragmentRoot createSourceFolder(IProject project,
IJavaProject javaProject) throws CoreException {
IFolder folder = project.getFolder(SRC_FOLDER);
if (!folder.exists()){
folder.create(false, true, null);
IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(folder);
- IClasspathEntry[] newEntries = { JavaCore
+ /*IClasspathEntry[] newEntries = { JavaCore
.newSourceEntry(root.getPath()) , JavaCore
.newContainerEntry(JRE_CONTAINER)};
- javaProject.setRawClasspath(newEntries, null);
+ javaProject.setRawClasspath(newEntries, null);*/
return root;
}
return javaProject.getPackageFragmentRoot(folder);
Added:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingDiagrammTest.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingDiagrammTest.java
(rev 0)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingDiagrammTest.java 2008-01-15
14:35:56 UTC (rev 5692)
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.eclipse.console.test.mappingproject;
+
+import java.lang.reflect.Field;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.internal.ErrorEditorPart;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.console.KnownConfigurations;
+import org.hibernate.eclipse.console.workbench.ConfigurationWorkbenchAdapter;
+import org.hibernate.eclipse.console.workbench.ConsoleConfigurationWorkbenchAdapter;
+import org.hibernate.mapping.PersistentClass;
+import org.jboss.tools.hibernate.ui.view.views.OpenDiagramActionDelegate;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class OpenMappingDiagrammTest extends TestCase {
+ public void testOpenMappingDiagramm() throws Throwable{
+ KnownConfigurations knownConfigurations = KnownConfigurations.getInstance();
+ final ConsoleConfiguration consCFG =
knownConfigurations.find(ProjectUtil.ConsoleCFGName);
+ assertNotNull(consCFG);
+ consCFG.reset();
+ Object[] configs = new ConsoleConfigurationWorkbenchAdapter().getChildren(consCFG);
+ assertTrue(configs[0] instanceof Configuration);
+ Object[] persClasses = new ConfigurationWorkbenchAdapter().getChildren(configs[0]);
+ if (persClasses.length > 0){
+ for (int i = 0; i < persClasses.length; i++) {
+ assertTrue(persClasses[0] instanceof PersistentClass);
+ PersistentClass persClass = (PersistentClass) persClasses[i];
+ try {
+ IEditorPart editor = new OpenDiagramActionDelegate().openEditor(persClass,
consCFG);
+ ProjectUtil.throwExceptionIfItOccured(editor);
+ } catch (PartInitException e) {
+ fail("Error opening Mapping Diagramm for class " +
persClass.getNodeName()
+ + ".\n"+ e.getMessage());
+ }
+ }
+ }
+ //close all editors
+ }
+
+
+}
Property changes on:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingDiagrammTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/ProjectUtil.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/ProjectUtil.java 2008-01-15
14:34:36 UTC (rev 5691)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/ProjectUtil.java 2008-01-15
14:35:56 UTC (rev 5692)
@@ -10,14 +10,20 @@
******************************************************************************/
package org.hibernate.eclipse.console.test.mappingproject;
+import java.lang.reflect.Field;
+
import org.apache.tools.ant.filters.StringInputStream;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.internal.ErrorEditorPart;
import org.hibernate.console.preferences.ConsoleConfigurationPreferences;
import org.hibernate.eclipse.console.wizards.ConsoleConfigurationCreationWizard;
import org.hibernate.mapping.PersistentClass;
@@ -34,7 +40,9 @@
.append("\"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd\">\n");
private static final StringBuilder XML_CFG_START = new
StringBuilder("<hibernate-configuration>\n")
- .append("<session-factory>\n");
+ .append("<session-factory>\n")
+ .append("<property name=\"hibernate.dialect\">")
+ .append("org.hibernate.dialect.PostgreSQLDialect</property>");
private static final StringBuilder XML_CFG_END = new
StringBuilder("</session-factory>\n")
.append("</hibernate-configuration>\n");
@@ -104,5 +112,42 @@
}
}
+ /**
+ * Sometimes we have exceptions while opening editors.
+ * IDE catches this exceptions and opens ErrorEditorPart instead of
+ * our editor. To be sure that editor opened without exception use this method.
+ * It gets occurred exception from the editor if it was and passes it up.
+ *
+ * @param editor
+ * @throws Throwable
+ */
+ public static void throwExceptionIfItOccured(IEditorPart editor) throws Throwable {
+ if (editor instanceof ErrorEditorPart){
+ Class<ErrorEditorPart> clazz = ErrorEditorPart.class;
+ Field field;
+ try {
+ field = clazz.getDeclaredField("error");
+
+ field.setAccessible(true);
+
+ Object error = field.get(editor);
+ if (error instanceof IStatus) {
+ IStatus err_status = (IStatus) error;
+ if (err_status.getSeverity() == Status.ERROR){
+ throw err_status.getException();
+ }
+ }
+ // catch close means that exception occurred but we can't get it
+ } catch (SecurityException e) {
+ throw new RuntimeException("Can't get exception from ErrorEditorPart. "
+ e.getMessage());
+ } catch (NoSuchFieldException e) {
+ throw new RuntimeException("Can't get error field from ErrorEditorPart.
" + e.getMessage());
+ } catch (IllegalArgumentException e) {
+ throw new RuntimeException("Can't get error field from ErrorEditorPart.
" + e.getMessage());
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException("Can't get error field from ErrorEditorPart.
" + e.getMessage());
+ }
+ }
+ }
}
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/TestSet.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/TestSet.java 2008-01-15
14:34:36 UTC (rev 5691)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/TestSet.java 2008-01-15
14:35:56 UTC (rev 5692)
@@ -33,13 +33,14 @@
}
- private static void addTestsPackSetUp(TestSuite suite){
+ private static void addTestsPackSetUp(TestSuite suite){
suite.addTestSuite( UpdateConfigurationTest.class );
}
private static void addPackTests(TestSuite suite){
suite.addTestSuite( OpenSourceFileTest.class );
suite.addTestSuite( OpenMappingFileTest.class );
+ suite.addTestSuite( OpenMappingDiagrammTest.class );
}
private static void addTestsPackTearDown(TestSuite suite){