[
https://jira.jboss.org/jira/browse/GTNPORTAL-66?page=com.atlassian.jira.p...
]
Luca Stancapiano commented on GTNPORTAL-66:
-------------------------------------------
Here a first example of annotation processor:
/*
* Copyright (C) 2003-2007 eXo Platform SAS.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not,
see<http://www.gnu.org/licenses/>.
*/
package org.exoplatform.webui.config.annotation.processor;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import org.exoplatform.commons.utils.IOUtil;
import org.exoplatform.groovyscript.GroovyScriptBuilder;
import org.exoplatform.groovyscript.TemplateCompilationException;
import org.exoplatform.resolver.ClasspathResourceResolver;
/**
* An annotation processor to compile the Groovy templates
*
* @author <a href="mailto:jedim@vige.it">Luca Stancapiano</a>
* @version $Revision$
*/
@SupportedAnnotationTypes(value = {
"org.exoplatform.webui.config.annotation.ComponentConfig" })
@SupportedSourceVersion(SourceVersion.RELEASE_6)
public class GroovyAnnotationProcessor extends AbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
for (Element element : roundEnv.getRootElements()) {
for (AnnotationMirror element2 : element.getAnnotationMirrors()) {
Map<? extends ExecutableElement, ? extends AnnotationValue> elementsMap =
element2
.getElementValues();
for (Entry<? extends ExecutableElement, ? extends AnnotationValue> entry :
elementsMap
.entrySet()) {
if (entry.getKey().getSimpleName().toString().equals(
"template")) {
String url = (String) entry.getValue().getValue();
InputStream is = null;
byte[] bytes = null;
try {
is = new ClasspathResourceResolver()
.getInputStream(url);
bytes = IOUtil.getStreamContentAsBytes(is);
} catch (Exception ex) {
ex.printStackTrace();
return false;
} finally {
try {
if (is != null)
is.close();
} catch (IOException ioex) {
ioex.printStackTrace();
return false;
}
}
String text = new String(bytes);
GroovyScriptBuilder compiler = new GroovyScriptBuilder(
null, text);
try {
compiler.build();
} catch (TemplateCompilationException tcex) {
tcex.printStackTrace();
return false;
}
}
}
}
}
return true;
}
}
Processor for the annotations reading groovy templates
------------------------------------------------------
Key: GTNPORTAL-66
URL:
https://jira.jboss.org/jira/browse/GTNPORTAL-66
Project: GateIn Portal
Issue Type: Task
Components: Common integration
Affects Versions: 3.0.0-Beta01, 3.0.0-Beta02
Environment: jdk 1.6.0_07, jboss 5.1, mvn 2.2.1
Reporter: Luca Stancapiano
Priority: Minor
Fix For: 3.0.0-CR01
maybe useful a mechanism that validates the groovy templates passed in the
org.exoplatform.webui.config.annotation.ComponentConfig annotation declared in the
exo.portal.webui.core project.
This annotation is actually used in the exo.portal.component.dashboard project.
Using the Pluggable Annotation Processing API for java 6 (here some detail of the
technology:
http://www.javabeat.net/articles/14-java-60-features-part-2-pluggable-ann...)
we can validate the groovy templates so we are not forced to load them at runtime and we
avoid a boring testing navigations.
The idea is introduce the Pluggable Annotation Processing in the pom.xml so we validate
the templates through the 'mvn install' command
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira