Skip to content

Commit

Permalink
METAGEN-10
Browse files Browse the repository at this point in the history
Switched to using Diagnostic.Kind.OTHER for debug messages. Only message in default mode is now "Hibernate JPA 2 Static-Metamodel Generator [version]"
  • Loading branch information
hferentschik authored and stliu committed Nov 11, 2013
1 parent 76d2d32 commit d5f15a1
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 16 deletions.
33 changes: 33 additions & 0 deletions tooling/metamodel-generator/pom.xml
Expand Up @@ -80,6 +80,32 @@
</resources>

<plugins>
<plugin>
<groupId>org.jboss.maven.plugins</groupId>
<artifactId>maven-injection-plugin</artifactId>
<version>1.0.2</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>bytecode</goal>
</goals>
</execution>
</executions>
<configuration>
<bytecodeInjections>
<bytecodeInjection>
<expression>${pom.version}</expression>
<targetMembers>
<methodBodyReturn>
<className>org.hibernate.jpamodelgen.Version</className>
<methodName>getVersionString</methodName>
</methodBodyReturn>
</targetMembers>
</bytecodeInjection>
</bytecodeInjections>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down Expand Up @@ -111,6 +137,7 @@
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.0.4</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -123,6 +150,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<systemProperties>
<property>
Expand All @@ -142,6 +170,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>generate-test-report</id>
Expand Down Expand Up @@ -174,7 +203,9 @@
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.0.4</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -185,7 +216,9 @@
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-2</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/dist.xml</descriptor>
Expand Down
Expand Up @@ -106,7 +106,7 @@ public Set<String> getElementsAlreadyProcessed() {
//does not work for Entity (risk of circularity)
public void processElement(TypeElement element, AccessType defaultAccessTypeForHierarchy) {
if ( elementsAlreadyProcessed.contains( element.getQualifiedName().toString() ) ) {
logMessage( Diagnostic.Kind.WARNING, "Element already processed (ignoring): " + element );
logMessage( Diagnostic.Kind.OTHER, "Element already processed (ignoring): " + element );
return;
}
ClassWriter.writeFile( new AnnotationMetaEntity( element, this, defaultAccessTypeForHierarchy ), this );
Expand All @@ -115,7 +115,7 @@ public void processElement(TypeElement element, AccessType defaultAccessTypeForH
}

public void logMessage(Diagnostic.Kind type, String message) {
if ( !logDebug && type.equals( Diagnostic.Kind.NOTE ) ) {
if ( !logDebug && type.equals( Diagnostic.Kind.OTHER ) ) {
return;
}
pe.getMessager().printMessage( type, message );
Expand Down
Expand Up @@ -85,17 +85,17 @@ public class JPAMetaModelEntityProcessor extends AbstractProcessor {
public void init(ProcessingEnvironment env) {
super.init( env );
context = new Context( env );
context.logMessage( Diagnostic.Kind.NOTE, "Init Processor " + this );
context.logMessage( Diagnostic.Kind.NOTE, "Hibernate JPA 2 Static-Metamodel Generator " + Version.getVersionString() );
}

@Override
public boolean process(final Set<? extends TypeElement> annotations,
final RoundEnvironment roundEnvironment) {

if ( roundEnvironment.processingOver() ) {
context.logMessage( Diagnostic.Kind.NOTE, "Last processing round." );
context.logMessage( Diagnostic.Kind.OTHER, "Last processing round." );
createMetaModelClasses();
context.logMessage( Diagnostic.Kind.NOTE, "Finished processing" );
context.logMessage( Diagnostic.Kind.OTHER, "Finished processing" );
return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
}

Expand All @@ -104,13 +104,13 @@ public boolean process(final Set<? extends TypeElement> annotations,
}

if ( !hostJPAAnnotations( annotations ) ) {
context.logMessage( Diagnostic.Kind.NOTE, "Current processing round does not contain entities" );
context.logMessage( Diagnostic.Kind.OTHER, "Current processing round does not contain entities" );
return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
}

Set<? extends Element> elements = roundEnvironment.getRootElements();
for ( Element element : elements ) {
context.logMessage( Diagnostic.Kind.NOTE, "Processing " + element.toString() );
context.logMessage( Diagnostic.Kind.OTHER, "Processing " + element.toString() );
handleRootElementAnnotationMirrors( element );
}

Expand All @@ -119,7 +119,7 @@ public boolean process(final Set<? extends TypeElement> annotations,

private void createMetaModelClasses() {
for ( MetaEntity entity : context.getMetaEntitiesToProcess().values() ) {
context.logMessage( Diagnostic.Kind.NOTE, "Writing meta model for " + entity );
context.logMessage( Diagnostic.Kind.OTHER, "Writing meta model for " + entity );
ClassWriter.writeFile( entity, context );
}

Expand All @@ -129,7 +129,7 @@ private void createMetaModelClasses() {
}

for ( MetaEntity entity : context.getMetaSuperclassAndEmbeddableToProcess().values() ) {
context.logMessage( Diagnostic.Kind.NOTE, "Writing meta model for " + entity );
context.logMessage( Diagnostic.Kind.OTHER, "Writing meta model for " + entity );
ClassWriter.writeFile( entity, context );
}
}
Expand Down Expand Up @@ -336,7 +336,7 @@ else if ( annotationType.equals( MAPPED_SUPERCLASS_ANN )
private InputStream getInputStreamForResource(String resource) {
String pkg = getPackage( resource );
String name = getRelativeName( resource );
context.logMessage( Diagnostic.Kind.NOTE, "Reading resource " + resource );
context.logMessage( Diagnostic.Kind.OTHER, "Reading resource " + resource );
InputStream ormStream;
try {
FileObject fileObject = processingEnv.getFiler().getResource( StandardLocation.CLASS_OUTPUT, pkg, name );
Expand Down Expand Up @@ -373,7 +373,7 @@ private <T> T parseXml(String resource, Class<T> clazz, String schemaName) {
InputStream stream = getInputStreamForResource( resource );

if ( stream == null ) {
context.logMessage( Diagnostic.Kind.NOTE, resource + " not found." );
context.logMessage( Diagnostic.Kind.OTHER, resource + " not found." );
return null;
}
try {
Expand Down
@@ -0,0 +1,31 @@
// $Id:$
/*
* JBoss, Home of Professional Open Source
* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.jpamodelgen;

/**
* Information about the Meta Model Generator version.
*
* @author Hardy Ferentschik
*/
public class Version {
public static String getVersionString() {
return "[WORKING]";
}
}


Expand Up @@ -206,14 +206,14 @@ private AccessType getAccessTypeForElement() {
}

private AccessType getAccessTypeForClass(TypeElement searchedElement) {
context.logMessage( Diagnostic.Kind.NOTE, "check class " + searchedElement );
context.logMessage( Diagnostic.Kind.OTHER, "check class " + searchedElement );
AccessType accessType = context.getAccessType( searchedElement );

if ( defaultAccessTypeForHierarchy == null ) {
this.defaultAccessTypeForHierarchy = context.getDefaultAccessTypeForHerarchy( searchedElement );
}
if ( accessType != null ) {
context.logMessage( Diagnostic.Kind.NOTE, "Found in cache" + searchedElement + ":" + accessType );
context.logMessage( Diagnostic.Kind.OTHER, "Found in cache" + searchedElement + ":" + accessType );
return accessType;
}

Expand All @@ -224,7 +224,7 @@ private AccessType getAccessTypeForClass(TypeElement searchedElement) {
final Access accessAnn = searchedElement.getAnnotation( Access.class );
AccessType forcedAccessType = accessAnn != null ? accessAnn.value() : null;
if ( forcedAccessType != null ) {
context.logMessage( Diagnostic.Kind.NOTE, "access type " + searchedElement + ":" + forcedAccessType );
context.logMessage( Diagnostic.Kind.OTHER, "access type " + searchedElement + ":" + forcedAccessType );
context.addAccessType( searchedElement, forcedAccessType );
}

Expand All @@ -244,7 +244,7 @@ private AccessType getAccessTypeForClass(TypeElement searchedElement) {
//FIXME consider XML
if ( annotationType.equals( Id.class.getName() )
|| annotationType.equals( EmbeddedId.class.getName() ) ) {
context.logMessage( Diagnostic.Kind.NOTE, "Found id on" + searchedElement );
context.logMessage( Diagnostic.Kind.OTHER, "Found id on" + searchedElement );
final ElementKind kind = subElement.getKind();
if ( kind == ElementKind.FIELD || kind == ElementKind.METHOD ) {
accessType = kind == ElementKind.FIELD ? AccessType.FIELD : AccessType.PROPERTY;
Expand All @@ -264,7 +264,7 @@ private AccessType getAccessTypeForClass(TypeElement searchedElement) {
if ( forcedAccessType == null ) {
context.addAccessType( searchedElement, accessType );
context.logMessage(
Diagnostic.Kind.NOTE, "access type " + searchedElement + ":" + accessType
Diagnostic.Kind.OTHER, "access type " + searchedElement + ":" + accessType
);
return accessType;
}
Expand Down

0 comments on commit d5f15a1

Please sign in to comment.