METAGEN-40 Taking care of entities in default package
This commit is contained in:
parent
3e0ecf66c0
commit
5f9e26746f
|
@ -1,6 +1,4 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
@ -62,8 +62,10 @@ public final class ClassWriter {
|
|||
OutputStream os = fo.openOutputStream();
|
||||
PrintWriter pw = new PrintWriter( os );
|
||||
|
||||
if ( !metaModelPackage.isEmpty() ) {
|
||||
pw.println( "package " + metaModelPackage + ";" );
|
||||
pw.println();
|
||||
}
|
||||
pw.println( entity.generateImports() );
|
||||
pw.println( body );
|
||||
|
||||
|
@ -166,7 +168,12 @@ public final class ClassWriter {
|
|||
}
|
||||
|
||||
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) {
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
@Entity
|
||||
public class DefaultPackageEntity {
|
||||
@Id
|
||||
private long id;
|
||||
}
|
||||
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -128,7 +128,11 @@ public abstract class CompilationTest {
|
|||
|
||||
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
|
||||
|
|
|
@ -5,5 +5,8 @@
|
|||
<packages>
|
||||
<package name="org.hibernate.jpamodelgen.test.*"/>
|
||||
</packages>
|
||||
<classes>
|
||||
<class name="DefaultPackageTest"/>
|
||||
</classes>
|
||||
</test>
|
||||
</suite>
|
Loading…
Reference in New Issue