Author: hardy.ferentschik
Date: 2010-10-04 10:03:09 -0400 (Mon, 04 Oct 2010)
New Revision: 20771
Modified:
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util/CompilationTest.java
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util/TestUtil.java
Log:
METAGEN-36 added the ability to check for compliation errors after running the tests
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-04
13:45:28 UTC (rev 20770)
+++
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util/CompilationTest.java 2010-10-04
14:03:09 UTC (rev 20771)
@@ -43,17 +43,22 @@
import static org.testng.FileAssert.fail;
/**
+ * Base class for annotation processor tests.
+ *
* @author Hardy Ferentschik
*/
public abstract class CompilationTest {
private static final Logger log = LoggerFactory.getLogger( CompilationTest.class );
private static final String PATH_SEPARATOR = System.getProperty(
"file.separator" );
private static final String ANNOTATION_PROCESSOR_OPTION_PREFIX = "-A";
+ private static final String PROC_NONE = "-proc:none";
private static final String SOURCE_BASE_DIR_PROPERTY = "sourceBaseDir";
private static final String OUT_BASE_DIR_PROPERTY = "outBaseDir";
private static final String sourceBaseDir;
private static final String outBaseDir;
+ private List<Diagnostic> compilationDiagnostics;
+
static {
String tmp = System.getProperty( SOURCE_BASE_DIR_PROPERTY );
if ( tmp == null ) {
@@ -69,8 +74,13 @@
}
public CompilationTest() {
+ compilationDiagnostics = new ArrayList<Diagnostic>();
}
+ public final List<Diagnostic> getCompilationDiagnostics() {
+ return compilationDiagnostics;
+ }
+
@BeforeClass
protected void compile() throws Exception {
TestUtil.deleteGeneratedSourceFiles( new File( outBaseDir ) );
@@ -91,8 +101,9 @@
compilationUnits = fileManager.getJavaFileObjectsFromFiles(
getCompilationUnits( outBaseDir )
);
- options.add( "-proc:none" ); // for the second compile skip the processor
+ options.add( PROC_NONE ); // for the second compile skip the processor
compileSources( options, compiler, diagnostics, fileManager, compilationUnits );
+ compilationDiagnostics.addAll( diagnostics.getDiagnostics() );
fileManager.close();
}
Property changes on:
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util/CompilationTest.java
___________________________________________________________________
Name: svn:keyword
+ Id
Modified:
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util/TestUtil.java
===================================================================
---
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util/TestUtil.java 2010-10-04
13:45:28 UTC (rev 20770)
+++
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util/TestUtil.java 2010-10-04
14:03:09 UTC (rev 20771)
@@ -28,6 +28,8 @@
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
+import java.util.List;
+import javax.tools.Diagnostic;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -209,10 +211,6 @@
}
}
- private static boolean hasFieldInMetamodelFor(Class<?> clazz, String fieldName) {
- return getFieldFromMetamodelFor( clazz, fieldName ) != null;
- }
-
public static Field getFieldFromMetamodelFor(Class<?> entityClass, String
fieldName) {
Class<?> metaModelClass = getMetamodelClassFor( entityClass );
Field field;
@@ -229,6 +227,18 @@
return fcn.replace( PACKAGE_SEPARATOR, PATH_SEPARATOR );
}
+ public static void assertNoCompilationError(List<Diagnostic> diagnostics) {
+ for ( Diagnostic diagnostic : diagnostics ) {
+ if ( diagnostic.getKind().equals( Diagnostic.Kind.ERROR ) ) {
+ fail( "There was a compilation error. " + diagnostic.getMessage( null ) );
+ }
+ }
+ }
+
+ private static boolean hasFieldInMetamodelFor(Class<?> clazz, String fieldName) {
+ return getFieldFromMetamodelFor( clazz, fieldName ) != null;
+ }
+
private static class MetaModelFilenameFilter implements FileFilter {
@Override
public boolean accept(File pathName) {
Property changes on:
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util/TestUtil.java
___________________________________________________________________
Name: svn:keyword
+ Id
Show replies by date