[hibernate-commits] Hibernate SVN: r15705 - in validator/trunk: hibernate-validator and 13 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Thu Dec 18 11:21:24 EST 2008


Author: hardy.ferentschik
Date: 2008-12-18 11:21:24 -0500 (Thu, 18 Dec 2008)
New Revision: 15705

Added:
   validator/trunk/tck-utils/
   validator/trunk/tck-utils/pom.xml
   validator/trunk/tck-utils/src/
   validator/trunk/tck-utils/src/main/
   validator/trunk/tck-utils/src/main/java/
   validator/trunk/tck-utils/src/main/java/org/
   validator/trunk/tck-utils/src/main/java/org/hibernate/
   validator/trunk/tck-utils/src/main/java/org/hibernate/tck/
   validator/trunk/tck-utils/src/main/java/org/hibernate/tck/TCKAnnotationProcessor.java
   validator/trunk/tck-utils/src/main/java/org/hibernate/tck/TCKAnnotationProcessorFactory.java
   validator/trunk/tck-utils/src/main/java/org/hibernate/tck/annotations/
   validator/trunk/tck-utils/src/main/java/org/hibernate/tck/annotations/SpecAssertion.java
   validator/trunk/tck-utils/src/main/java/org/hibernate/tck/annotations/SpecVersion.java
   validator/trunk/tck-utils/src/main/resources/
   validator/trunk/tck-utils/src/main/resources/META-INF/
   validator/trunk/tck-utils/src/main/resources/META-INF/services/
   validator/trunk/tck-utils/src/main/resources/META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
   validator/trunk/tck-utils/src/test/
   validator/trunk/tck-utils/src/test/java/
Modified:
   validator/trunk/hibernate-validator/pom.xml
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java
   validator/trunk/pom.xml
Log:
added an apt based tool to process TCK related annotations.

Modified: validator/trunk/hibernate-validator/pom.xml
===================================================================
--- validator/trunk/hibernate-validator/pom.xml	2008-12-18 13:24:48 UTC (rev 15704)
+++ validator/trunk/hibernate-validator/pom.xml	2008-12-18 16:21:24 UTC (rev 15705)
@@ -38,6 +38,11 @@
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.hibernate</groupId>
+            <artifactId>tck-utils</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
     <build>
         <resources>
@@ -46,6 +51,22 @@
                 <filtering>true</filtering>
             </resource>
         </resources>
+        <plugins>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>apt-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>test-process</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <testOutputDirectory>${project.build.directory}/site</testOutputDirectory>
+                </configuration>
+            </plugin>
+        </plugins>
     </build>
     <reporting>
         <plugins>
@@ -80,9 +101,9 @@
                             <additionalparam>
                                 -d ${project.build.directory}/site
                             </additionalparam>
-                            <!-- Other dir than apidocs -->
+                            <!--Other dir than apidocs-->
                             <destDir>tck</destDir>
-                            <!-- For the project-reports page-->
+                            <!--For the project-reports page-->
                             <name>JSR Tests</name>
                             <description>Cross references unit tests to JSR 303 specification.</description>
                         </configuration>

Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java	2008-12-18 13:24:48 UTC (rev 15704)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java	2008-12-18 16:21:24 UTC (rev 15705)
@@ -47,6 +47,7 @@
 import org.hibernate.validation.eg.Last;
 import org.hibernate.validation.eg.DefaultAlias;
 import org.hibernate.validation.HibernateValidatorFactoryBuilder;
+import org.hibernate.tck.annotations.SpecAssertion;
 
 /**
  * Tests for the implementation of <code>Validator</code>.
@@ -73,6 +74,7 @@
 	 * JSR 303: Requirements on classes to be validates (3.1)
 	 * @jsr 3.1
 	 */
+	@SpecAssertion( section = {"3.1"} )
 	@Test
 	public void testWrongMethodName() {
 		try {

Modified: validator/trunk/pom.xml
===================================================================
--- validator/trunk/pom.xml	2008-12-18 13:24:48 UTC (rev 15704)
+++ validator/trunk/pom.xml	2008-12-18 16:21:24 UTC (rev 15705)
@@ -49,6 +49,7 @@
         <module>validation-api</module>
         <module>hibernate-validator</module>
         <module>hibernate-validator-legacy</module>
+        <module>tck-utils</module>
     </modules>
 
     <dependencyManagement>
@@ -78,6 +79,11 @@
                 <artifactId>junit</artifactId>
                 <version>4.4</version>
             </dependency>
+            <dependency>
+                <groupId>org.hibernate</groupId>
+                <artifactId>tck-utils</artifactId>
+                <version>${version}</version>
+            </dependency>
         </dependencies>
     </dependencyManagement>
 


Property changes on: validator/trunk/tck-utils
___________________________________________________________________
Name: svn:ignore
   + target
*.iml


Added: validator/trunk/tck-utils/pom.xml
===================================================================
--- validator/trunk/tck-utils/pom.xml	                        (rev 0)
+++ validator/trunk/tck-utils/pom.xml	2008-12-18 16:21:24 UTC (rev 15705)
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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>
+
+    <parent>
+        <groupId>org.hibernate</groupId>
+        <artifactId>hibernate-validator-parent</artifactId>
+        <version>1.0.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <groupId>org.hibernate</groupId>
+    <artifactId>tck-utils</artifactId>
+    <packaging>jar</packaging>
+    <name>TCK Utils</name>
+
+    <distributionManagement>
+        <site>
+            <id>site</id>
+            <url>file:///Users/hardy/Sites/${artifactId}</url>
+        </site>
+    </distributionManagement>
+</project>

Added: validator/trunk/tck-utils/src/main/java/org/hibernate/tck/TCKAnnotationProcessor.java
===================================================================
--- validator/trunk/tck-utils/src/main/java/org/hibernate/tck/TCKAnnotationProcessor.java	                        (rev 0)
+++ validator/trunk/tck-utils/src/main/java/org/hibernate/tck/TCKAnnotationProcessor.java	2008-12-18 16:21:24 UTC (rev 15705)
@@ -0,0 +1,177 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, 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.
+*/
+package org.hibernate.tck;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import com.sun.mirror.apt.AnnotationProcessor;
+import com.sun.mirror.apt.AnnotationProcessorEnvironment;
+import com.sun.mirror.declaration.AnnotationTypeDeclaration;
+import com.sun.mirror.declaration.Declaration;
+import com.sun.mirror.declaration.MethodDeclaration;
+import static com.sun.mirror.util.DeclarationVisitors.NO_OP;
+import static com.sun.mirror.util.DeclarationVisitors.getDeclarationScanner;
+import com.sun.mirror.util.SimpleDeclarationVisitor;
+
+import org.hibernate.tck.annotations.SpecAssertion;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class TCKAnnotationProcessor implements AnnotationProcessor {
+
+	private static final String OUTDIR_OPTION_NAME = "-s";
+	private static final String REPORT_FILE_NAME = "tck.html";
+
+	private final AnnotationProcessorEnvironment env;
+	private final String[] tableHeaders = new String[] { "Section", "Class", "Method" };
+	private final StringBuffer out = new StringBuffer();
+	private final List<JSRReference> references = new ArrayList<JSRReference>();
+	private final File baseDir;
+
+	public TCKAnnotationProcessor(AnnotationProcessorEnvironment annotationProcessorEnvironment) {
+		this.env = annotationProcessorEnvironment;
+		String baseDirName = env.getOptions().get( OUTDIR_OPTION_NAME );
+		baseDir = new File( baseDirName );
+		baseDir.mkdirs();
+	}
+
+	public void process() {
+
+
+		AnnotationTypeDeclaration annType = ( AnnotationTypeDeclaration ) env.getTypeDeclaration(
+				SpecAssertion.class.getCanonicalName()
+		);
+		for ( Declaration d : env.getDeclarationsAnnotatedWith( annType ) ) {
+			d.accept(
+					getDeclarationScanner(
+							new DoNothingVisitor(),
+							NO_OP
+					)
+			);
+		}
+
+
+		writeHeader();
+		writeContents();
+		writeFooter();
+
+		writeReporttoFile();
+	}
+
+	private void writeReporttoFile() {
+		try {
+			File report = new File( baseDir, REPORT_FILE_NAME );
+			BufferedWriter writer = new BufferedWriter( new FileWriter( report ) );
+			writer.write( out.toString() );
+			writer.close();
+		}
+		catch ( IOException e ) {
+			System.err.println( "Error writing report." );
+		}
+	}
+
+	private void writeFooter() {
+		out.append( "</body></html>" );
+	}
+
+	private void writeHeader() {
+		out.append( "<html><head></head><body>" );
+	}
+
+	private void writeTableHeader() {
+		out.append( "<table border=\"1\"><tr>" );
+		for ( String s : tableHeaders ) {
+			out.append( "<th>" ).append( s ).append( "</th>" );
+		}
+		out.append( "</tr>" );
+	}
+
+	private void writeTableFooter() {
+		out.append( "</table>" );
+	}
+
+	private void writeContents() {
+		writeTableHeader();
+		for ( JSRReference reference : references ) {
+			out.append( "<tr>" );
+			out.append( "<td>" ).append( reference.jsrSectionReference ).append( "</td>" );
+			out.append( "<td><a href=\"" )
+					.append( reference.getSourceLink() )
+					.append( "\">" )
+					.append( reference.className )
+					.append( "</a></td>" );
+			out.append( "<td>" ).append( reference.methodName ).append( "</td>" );
+			out.append( "</tr>" );
+		}
+		writeTableFooter();
+	}
+
+	private class DoNothingVisitor extends SimpleDeclarationVisitor {
+		public void visitMethodDeclaration(MethodDeclaration d) {
+			SpecAssertion annotation = d.getAnnotation( SpecAssertion.class );
+			JSRReference ref = new JSRReference(
+					annotation.section()[0], d.getDeclaringType().getQualifiedName(), d.getSimpleName()
+			);
+			references.add( ref );
+		}
+	}
+
+	private static class JSRReference implements Comparable {
+		/**
+		 * The JSR  section this instance references.
+		 */
+		String jsrSectionReference;
+
+		/**
+		 * The name of the class which references the JSR.
+		 */
+		String className;
+
+		/**
+		 * The method which references the JSR.
+		 */
+		String methodName;
+
+		/**
+		 * @todo Add some validation
+		 */
+		JSRReference(String reference, String className, String methodName) {
+			this.jsrSectionReference = reference;
+			this.className = className;
+			this.methodName = methodName;
+		}
+
+		public String getSourceLink() {
+			StringBuilder builder = new StringBuilder();
+			builder.append( "xref-test/" );
+			builder.append( className.replace( '.', '/' ) );
+			builder.append( ".html" );
+			return builder.toString();
+		}
+
+		public int compareTo(Object o) {
+			return jsrSectionReference.compareTo( ( ( JSRReference ) o ).jsrSectionReference );
+		}
+	}
+}


Property changes on: validator/trunk/tck-utils/src/main/java/org/hibernate/tck/TCKAnnotationProcessor.java
___________________________________________________________________
Name: svn:keywords
   + Id

Added: validator/trunk/tck-utils/src/main/java/org/hibernate/tck/TCKAnnotationProcessorFactory.java
===================================================================
--- validator/trunk/tck-utils/src/main/java/org/hibernate/tck/TCKAnnotationProcessorFactory.java	                        (rev 0)
+++ validator/trunk/tck-utils/src/main/java/org/hibernate/tck/TCKAnnotationProcessorFactory.java	2008-12-18 16:21:24 UTC (rev 15705)
@@ -0,0 +1,65 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, 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.
+*/
+package org.hibernate.tck;
+
+import java.util.Arrays;
+import java.util.Collection;
+import static java.util.Collections.emptySet;
+import static java.util.Collections.unmodifiableCollection;
+import java.util.Set;
+
+import com.sun.mirror.apt.AnnotationProcessor;
+import com.sun.mirror.apt.AnnotationProcessorEnvironment;
+import com.sun.mirror.apt.AnnotationProcessorFactory;
+import com.sun.mirror.declaration.AnnotationTypeDeclaration;
+
+import org.hibernate.tck.annotations.SpecAssertion;
+import org.hibernate.tck.annotations.SpecVersion;
+
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class TCKAnnotationProcessorFactory implements AnnotationProcessorFactory {
+
+	// Process any set of annotations
+	private static final Collection<String> supportedAnnotations
+			= unmodifiableCollection(
+			Arrays.asList(
+					SpecAssertion.class.getCanonicalName(),
+					SpecVersion.class.getCanonicalName()
+			)
+	);
+
+	// No supported options
+	private static final Collection<String> supportedOptions = emptySet();
+
+
+	public Collection<String> supportedOptions() {
+		return supportedOptions;
+	}
+
+	public Collection<String> supportedAnnotationTypes() {
+		return supportedAnnotations;
+	}
+
+	public AnnotationProcessor getProcessorFor(Set<AnnotationTypeDeclaration> annotationTypeDeclarations, AnnotationProcessorEnvironment annotationProcessorEnvironment) {
+		return new TCKAnnotationProcessor( annotationProcessorEnvironment );
+
+	}
+}


Property changes on: validator/trunk/tck-utils/src/main/java/org/hibernate/tck/TCKAnnotationProcessorFactory.java
___________________________________________________________________
Name: svn:keywords
   + Id

Added: validator/trunk/tck-utils/src/main/java/org/hibernate/tck/annotations/SpecAssertion.java
===================================================================
--- validator/trunk/tck-utils/src/main/java/org/hibernate/tck/annotations/SpecAssertion.java	                        (rev 0)
+++ validator/trunk/tck-utils/src/main/java/org/hibernate/tck/annotations/SpecAssertion.java	2008-12-18 16:21:24 UTC (rev 15705)
@@ -0,0 +1,33 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, 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.
+*/
+package org.hibernate.tck.annotations;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+ at Target(ElementType.METHOD)
+ at Documented
+public @interface SpecAssertion {
+
+	public String[] section();
+
+	public String note() default "";
+
+}
+


Property changes on: validator/trunk/tck-utils/src/main/java/org/hibernate/tck/annotations/SpecAssertion.java
___________________________________________________________________
Name: svn:keywords
   + Id

Added: validator/trunk/tck-utils/src/main/java/org/hibernate/tck/annotations/SpecVersion.java
===================================================================
--- validator/trunk/tck-utils/src/main/java/org/hibernate/tck/annotations/SpecVersion.java	                        (rev 0)
+++ validator/trunk/tck-utils/src/main/java/org/hibernate/tck/annotations/SpecVersion.java	2008-12-18 16:21:24 UTC (rev 15705)
@@ -0,0 +1,30 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, 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.
+*/
+package org.hibernate.tck.annotations;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+ at Documented
+ at Target(ElementType.TYPE)
+public @interface SpecVersion {
+	
+	String value();
+}
+


Property changes on: validator/trunk/tck-utils/src/main/java/org/hibernate/tck/annotations/SpecVersion.java
___________________________________________________________________
Name: svn:keywords
   + Id

Added: validator/trunk/tck-utils/src/main/resources/META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
===================================================================
--- validator/trunk/tck-utils/src/main/resources/META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory	                        (rev 0)
+++ validator/trunk/tck-utils/src/main/resources/META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory	2008-12-18 16:21:24 UTC (rev 15705)
@@ -0,0 +1 @@
+org.hibernate.tck.TCKAnnotationProcessorFactory
\ No newline at end of file




More information about the hibernate-commits mailing list