[hibernate-commits] Hibernate SVN: r20838 - in jpamodelgen/trunk/src: test/java and 2 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Fri Oct 15 06:07:05 EDT 2010


Author: hardy.ferentschik
Date: 2010-10-15 06:07:04 -0400 (Fri, 15 Oct 2010)
New Revision: 20838

Added:
   jpamodelgen/trunk/src/test/java/DefaultPackageEntity.java
   jpamodelgen/trunk/src/test/java/DefaultPackageTest.java
Modified:
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/ClassWriter.java
   jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util/CompilationTest.java
   jpamodelgen/trunk/src/test/suite/unit-tests.xml
Log:
METAGEN-40 Taking care of entities in default package

Modified: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/ClassWriter.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/ClassWriter.java	2010-10-14 17:33:31 UTC (rev 20837)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/ClassWriter.java	2010-10-15 10:07:04 UTC (rev 20838)
@@ -62,8 +62,10 @@
 			OutputStream os = fo.openOutputStream();
 			PrintWriter pw = new PrintWriter( os );
 
-			pw.println( "package " + metaModelPackage + ";" );
-			pw.println();
+			if ( !metaModelPackage.isEmpty() ) {
+				pw.println( "package " + metaModelPackage + ";" );
+				pw.println();
+			}
 			pw.println( entity.generateImports() );
 			pw.println( body );
 
@@ -166,7 +168,12 @@
 	}
 
 	private static String getFullyQualifiedClassName(MetaEntity entity, String metaModelPackage) {
-		return metaModelPackage + "." + entity.getSimpleName() + META_MODEL_CLASS_NAME_SUFFIX;
+		String fullyQualifiedClassName = "";
+		if ( !metaModelPackage.isEmpty() ) {
+			fullyQualifiedClassName = fullyQualifiedClassName + metaModelPackage + ".";
+		}
+		fullyQualifiedClassName = fullyQualifiedClassName + entity.getSimpleName() + META_MODEL_CLASS_NAME_SUFFIX;
+		return fullyQualifiedClassName;
 	}
 
 	private static String writeGeneratedAnnotation(MetaEntity entity) {

Added: jpamodelgen/trunk/src/test/java/DefaultPackageEntity.java
===================================================================
--- jpamodelgen/trunk/src/test/java/DefaultPackageEntity.java	                        (rev 0)
+++ jpamodelgen/trunk/src/test/java/DefaultPackageEntity.java	2010-10-15 10:07:04 UTC (rev 20838)
@@ -0,0 +1,30 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+/**
+ * @author Hardy Ferentschik
+ */
+ at Entity
+public class DefaultPackageEntity {
+	@Id
+	private long id;
+}
+
+

Added: jpamodelgen/trunk/src/test/java/DefaultPackageTest.java
===================================================================
--- jpamodelgen/trunk/src/test/java/DefaultPackageTest.java	                        (rev 0)
+++ jpamodelgen/trunk/src/test/java/DefaultPackageTest.java	2010-10-15 10:07:04 UTC (rev 20838)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// $Id:$
+
+import org.testng.annotations.Test;
+
+import org.hibernate.jpamodelgen.test.util.CompilationTest;
+
+import static org.hibernate.jpamodelgen.test.util.TestUtil.assertMetamodelClassGeneratedFor;
+
+/**
+ * Test for METAGEN-40
+ *
+ * @author Hardy Ferentschik
+ */
+public class DefaultPackageTest extends CompilationTest {
+	@Test
+	public void testMetaModelGeneratedForEntitiesInDefaultPackage() {
+		assertMetamodelClassGeneratedFor( DefaultPackageEntity.class );
+	}
+
+	@Override
+	protected String getPackageNameOfCurrentTest() {
+		return null;
+	}
+}
+
+

Modified: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util/CompilationTest.java
===================================================================
--- jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util/CompilationTest.java	2010-10-14 17:33:31 UTC (rev 20837)
+++ jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util/CompilationTest.java	2010-10-15 10:07:04 UTC (rev 20838)
@@ -128,7 +128,11 @@
 
 	protected List<File> getCompilationUnits(String baseDir, String packageName) {
 		List<File> javaFiles = new ArrayList<File>();
-		String packageDirName = baseDir + PATH_SEPARATOR + packageName.replace( ".", PATH_SEPARATOR );
+		String packageDirName = baseDir;
+		if(packageName != null) {
+			packageDirName = packageDirName + PATH_SEPARATOR + packageName.replace( ".", PATH_SEPARATOR );	
+		}
+
 		File packageDir = new File( packageDirName );
 		FilenameFilter javaFileFilter = new FilenameFilter() {
 			@Override

Modified: jpamodelgen/trunk/src/test/suite/unit-tests.xml
===================================================================
--- jpamodelgen/trunk/src/test/suite/unit-tests.xml	2010-10-14 17:33:31 UTC (rev 20837)
+++ jpamodelgen/trunk/src/test/suite/unit-tests.xml	2010-10-15 10:07:04 UTC (rev 20838)
@@ -5,5 +5,8 @@
         <packages>
             <package name="org.hibernate.jpamodelgen.test.*"/>
         </packages>
+        <classes>
+            <class name="DefaultPackageTest"/>
+        </classes>
     </test>
 </suite>
\ No newline at end of file



More information about the hibernate-commits mailing list