You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2011/11/09 05:10:50 UTC
svn commit: r1199608 - in /myfaces/tobago/trunk:
tobago-extension/tobago-taglib-extension/
tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/
Author: lofwyr
Date: Wed Nov 9 04:10:50 2011
New Revision: 1199608
URL: http://svn.apache.org/viewvc?rev=1199608&view=rev
Log:
TOBAGO-1047: Checkstyle configuration file to find deprecated attriubutes or tags.
Added:
myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CheckstyleConfigAnnotationProcessor.java (contents, props changed)
- copied, changed from r1195915, myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FacesConfigAnnotationProcessor.java
myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CheckstyleConfigAnnotationProcessorFactory.java (contents, props changed)
- copied, changed from r1195915, myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FacesConfigAnnotationProcessorFactory.java
myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CheckstyleConfigAnnotationVisitor.java (contents, props changed)
- copied, changed from r1195915, myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FacesConfigAnnotationVisitor.java
Modified:
myfaces/tobago/trunk/tobago-extension/tobago-taglib-extension/pom.xml
Modified: myfaces/tobago/trunk/tobago-extension/tobago-taglib-extension/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-extension/tobago-taglib-extension/pom.xml?rev=1199608&r1=1199607&r2=1199608&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-extension/tobago-taglib-extension/pom.xml (original)
+++ myfaces/tobago/trunk/tobago-extension/tobago-taglib-extension/pom.xml Wed Nov 9 04:10:50 2011
@@ -97,6 +97,23 @@
</options>
</configuration>
</execution>
+ <execution>
+ <id>tobago-checkstyle</id>
+ <goals><goal>process</goal></goals>
+ <phase>process-classes</phase>
+ <configuration>
+ <outputFiles>
+ <outputFile>checkstyle-tobago.xml</outputFile>
+ </outputFiles>
+ <resourceTargetPath>META-INF</resourceTargetPath>
+ <outputDirectory>${project.build.directory}/generated-checkstyle-config</outputDirectory>
+ <factory>org.apache.myfaces.tobago.apt.CheckstyleConfigAnnotationProcessorFactory</factory>
+ <additionalSourceRoots>
+ <additionalSourceRoot>${project.build.directory}/tobago-core-sources</additionalSourceRoot>
+ </additionalSourceRoots>
+ <encoding>${maven.compile.encoding}</encoding>
+ </configuration>
+ </execution>
</executions>
</plugin>
Copied: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CheckstyleConfigAnnotationProcessor.java (from r1195915, myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FacesConfigAnnotationProcessor.java)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CheckstyleConfigAnnotationProcessor.java?p2=myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CheckstyleConfigAnnotationProcessor.java&p1=myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FacesConfigAnnotationProcessor.java&r1=1195915&r2=1199608&rev=1199608&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FacesConfigAnnotationProcessor.java (original)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CheckstyleConfigAnnotationProcessor.java Wed Nov 9 04:10:50 2011
@@ -23,21 +23,16 @@ import com.sun.mirror.declaration.Annota
import com.sun.mirror.declaration.Declaration;
import com.sun.mirror.util.DeclarationVisitors;
-import javax.xml.parsers.ParserConfigurationException;
-import java.io.IOException;
import java.util.Collection;
import java.util.Set;
-/*
- * Date: Sep 25, 2006
- * Time: 9:26:19 PM
- */
-public class FacesConfigAnnotationProcessor implements AnnotationProcessor {
+public class CheckstyleConfigAnnotationProcessor implements AnnotationProcessor {
private final AnnotationProcessorEnvironment env;
private final Set<AnnotationTypeDeclaration> atds;
- public FacesConfigAnnotationProcessor(Set<AnnotationTypeDeclaration> atds,
+ public CheckstyleConfigAnnotationProcessor(
+ Set<AnnotationTypeDeclaration> atds,
AnnotationProcessorEnvironment env) {
this.atds = atds;
this.env = env;
@@ -45,22 +40,18 @@ public class FacesConfigAnnotationProces
}
public void process() {
- FacesConfigAnnotationVisitor visitor = new FacesConfigAnnotationVisitor(env);
+ CheckstyleConfigAnnotationVisitor visitor = new CheckstyleConfigAnnotationVisitor(env);
for (AnnotationTypeDeclaration atd : atds) {
env.getMessager().printNotice("Collecting annotation "+atd);
- Collection<Declaration> decls = env.getDeclarationsAnnotatedWith(atd);
- for (Declaration decl : decls) {
- decl.accept(DeclarationVisitors.getDeclarationScanner(visitor, DeclarationVisitors.NO_OP));
+ Collection<Declaration> declarations = env.getDeclarationsAnnotatedWith(atd);
+ for (Declaration declaration : declarations) {
+ declaration.accept(DeclarationVisitors.getDeclarationScanner(visitor, DeclarationVisitors.NO_OP));
}
}
-
try {
visitor.process();
- } catch (ParserConfigurationException e) {
- // TODO
- e.printStackTrace();
- } catch (IOException e) {
+ } catch (Exception e) {
e.printStackTrace();
}
}
Propchange: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CheckstyleConfigAnnotationProcessor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CheckstyleConfigAnnotationProcessor.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Copied: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CheckstyleConfigAnnotationProcessorFactory.java (from r1195915, myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FacesConfigAnnotationProcessorFactory.java)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CheckstyleConfigAnnotationProcessorFactory.java?p2=myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CheckstyleConfigAnnotationProcessorFactory.java&p1=myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FacesConfigAnnotationProcessorFactory.java&r1=1195915&r2=1199608&rev=1199608&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FacesConfigAnnotationProcessorFactory.java (original)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CheckstyleConfigAnnotationProcessorFactory.java Wed Nov 9 04:10:50 2011
@@ -27,30 +27,17 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Set;
-/*
- * Date: Sep 25, 2006
- * Time: 9:29:33 PM
- */
-public class FacesConfigAnnotationProcessorFactory implements AnnotationProcessorFactory {
+public class CheckstyleConfigAnnotationProcessorFactory implements AnnotationProcessorFactory {
private static final Collection<String> SUPPORTED_ANNOTATIONS
= Collections.unmodifiableCollection(Arrays.asList(
"org.apache.myfaces.tobago.apt.annotation.Tag",
"org.apache.myfaces.tobago.apt.annotation.TagAttribute",
- "org.apache.myfaces.tobago.apt.annotation.Taglib",
- "org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute",
- "org.apache.myfaces.tobago.apt.annotation.UIComponentTag",
- "org.apache.myfaces.tobago.apt.annotation.Facet",
- "org.apache.myfaces.tobago.apt.annotation.Preliminary",
- "org.apache.myfaces.tobago.apt.annotation.Converter",
- "org.apache.myfaces.tobago.apt.annotation.Validator"
- ));
-
- private static final Collection<String> SUPPORTED_OPTIONS =
- Collections.unmodifiableCollection(Arrays.asList(FacesConfigAnnotationVisitor.SOURCE_FACES_CONFIG_KEY,
- FacesConfigAnnotationVisitor.TARGET_FACES_CONFIG_KEY));
+ "org.apache.myfaces.tobago.apt.annotation.Taglib"));
- private FacesConfigAnnotationProcessor annotationProcessor = null;
+ private static final Collection<String> SUPPORTED_OPTIONS = Collections.emptySet();
+
+ private CheckstyleConfigAnnotationProcessor annotationProcessor = null;
public Collection<String> supportedAnnotationTypes() {
return SUPPORTED_ANNOTATIONS;
@@ -60,10 +47,10 @@ public class FacesConfigAnnotationProces
return SUPPORTED_OPTIONS;
}
- public AnnotationProcessor getProcessorFor(Set<AnnotationTypeDeclaration> atds,
+ public AnnotationProcessor getProcessorFor(Set<AnnotationTypeDeclaration> declarations,
AnnotationProcessorEnvironment env) {
if (annotationProcessor == null) {
- annotationProcessor = new FacesConfigAnnotationProcessor(atds, env);
+ annotationProcessor = new CheckstyleConfigAnnotationProcessor(declarations, env);
}
return annotationProcessor;
}
Propchange: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CheckstyleConfigAnnotationProcessorFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CheckstyleConfigAnnotationProcessorFactory.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Copied: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CheckstyleConfigAnnotationVisitor.java (from r1195915, myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FacesConfigAnnotationVisitor.java)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CheckstyleConfigAnnotationVisitor.java?p2=myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CheckstyleConfigAnnotationVisitor.java&p1=myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FacesConfigAnnotationVisitor.java&r1=1195915&r2=1199608&rev=1199608&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/FacesConfigAnnotationVisitor.java (original)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CheckstyleConfigAnnotationVisitor.java Wed Nov 9 04:10:50 2011
@@ -22,721 +22,254 @@ import com.sun.mirror.apt.Filer;
import com.sun.mirror.declaration.ClassDeclaration;
import com.sun.mirror.declaration.InterfaceDeclaration;
import com.sun.mirror.declaration.MethodDeclaration;
-import com.sun.mirror.declaration.TypeDeclaration;
+import com.sun.mirror.declaration.PackageDeclaration;
import com.sun.mirror.type.InterfaceType;
import org.apache.commons.io.IOUtils;
-import org.apache.myfaces.tobago.apt.annotation.Converter;
-import org.apache.myfaces.tobago.apt.annotation.Facet;
+import org.apache.commons.lang.StringUtils;
+import org.apache.myfaces.tobago.apt.annotation.Tag;
import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
+import org.apache.myfaces.tobago.apt.annotation.Taglib;
import org.apache.myfaces.tobago.apt.annotation.UIComponentTag;
-import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;
-import org.apache.myfaces.tobago.apt.annotation.Validator;
-import org.codehaus.plexus.util.FileUtils;
-import org.jdom.Attribute;
-import org.jdom.Comment;
-import org.jdom.DocType;
-import org.jdom.Document;
-import org.jdom.Element;
-import org.jdom.JDOMException;
-import org.jdom.Namespace;
-import org.jdom.filter.ContentFilter;
-import org.jdom.input.SAXBuilder;
-import org.jdom.output.Format;
-import org.jdom.output.XMLOutputter;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringReader;
-import java.io.StringWriter;
import java.io.Writer;
-import java.lang.reflect.Field;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
+import java.util.HashSet;
import java.util.Locale;
-import java.util.Map;
+import java.util.Set;
-/*
- * Date: Sep 25, 2006
- * Time: 9:31:09 PM
- */
-public class FacesConfigAnnotationVisitor extends AbstractAnnotationVisitor {
- public static final String SOURCE_FACES_CONFIG_KEY = "sourceFacesConfig";
- public static final String TARGET_FACES_CONFIG_KEY = "targetFacesConfig";
-
- private String jsfVersion = "1.1";
-
- private static final String SEPARATOR = System.getProperty("line.separator");
- private static final String COMPONENT = "component";
- private static final String COMPONENT_TYPE = "component-type";
- private static final String COMPONENT_CLASS = "component-class";
- private static final String COMPONENT_EXTENSION = "component-extension";
- private static final String ALLOWED_CHILD_COMPONENTS = "allowed-child-components";
- private static final String CATEGORY = "category";
- private static final String DEPRECATED = "deprecated";
- private static final String HIDDEN = "hidden";
- private static final String FACET = "facet";
- private static final String DISPLAY_NAME = "display-name";
- private static final String DESCRIPTION = "description";
- private static final String FACET_NAME = "facet-name";
- private static final String FACET_EXTENSION = "facet-extension";
- private static final String PROPERTY = "property";
- private static final String PROPERTY_NAME = "property-name";
- private static final String PROPERTY_CLASS = "property-class";
- private static final String PROPERTY_EXTENSION = "property-extension";
- private static final String VALUE_EXPRESSION = "value-expression"; //UIComponentTagAttribute.valueExpression()
- private static final String PROPERTY_VALUES = "property-values"; //UIComponentTagAttribute.allowedValues()
- private static final String READONLY = "read-only";
- private static final String REQUIRED = "required"; //UITagAttribute.required()
- private static final String DEFAULT_VALUE = "default-value";
- private static final String ATTRIBUTE = "attribute";
- private static final String ATTRIBUTE_NAME = "attribute-name";
- private static final String ATTRIBUTE_CLASS = "attribute-class";
- private static final String ATTRIBUTE_EXTENSION = "attribute-extension";
- private static final String APPLICATION = "application";
- private static final String FACTORY = "factory";
- private static final String CONVERTER = "converter";
- private static final String CONVERTER_ID = "converter-id";
- private static final String CONVERTER_FOR_CLASS = "converter-for-class";
- private static final String CONVERTER_CLASS = "converter-class";
- private static final String VALIDATOR = "validator";
- private static final String VALIDATOR_ID = "validator-id";
- private static final String VALIDATOR_FOR_CLASS = "validator-for-class";
- private static final String VALIDATOR_CLASS = "validator-class";
- private static final String RENDERER = "renderer";
- private static final String COMPONENT_FAMILY = "component-family";
- private static final String RENDER_KIT = "render-kit";
- private static final String RENDER_KIT_ID = "render-kit-id";
- private static final String RENDER_KIT_CLASS = "render-kit-class";
- private static final String RENDERER_TYPE = "renderer-type";
- private static final String RENDERER_CLASS = "renderer-class";
+public class CheckstyleConfigAnnotationVisitor extends AbstractAnnotationVisitor {
- public FacesConfigAnnotationVisitor(AnnotationProcessorEnvironment env) {
+ private Set<String> tagSet = new HashSet<String>();
+
+ public CheckstyleConfigAnnotationVisitor(AnnotationProcessorEnvironment env) {
super(env);
}
- public void process() throws ParserConfigurationException, IOException {
- String sourceFacesConfigFile = null;
- String targetFacesConfigFile = null;
- for (Map.Entry<String, String> entry : getEnv().getOptions().entrySet()) {
- if (entry.getKey().startsWith("-A" + SOURCE_FACES_CONFIG_KEY + "=")) {
- sourceFacesConfigFile = entry.getKey().substring(SOURCE_FACES_CONFIG_KEY.length() + 3);
- }
- if (entry.getKey().startsWith("-A" + TARGET_FACES_CONFIG_KEY + "=")) {
- targetFacesConfigFile = entry.getKey().substring(TARGET_FACES_CONFIG_KEY.length() + 3);
- }
- if (entry.getKey().startsWith("-Ajsf-version=")) {
- String version = entry.getKey().substring("-Ajsf-version=".length());
- if ("1.2".equals(version)) {
- jsfVersion = "1.2";
- }
- if ("2.0".equals(version)) {
- jsfVersion = "2.0";
- }
- }
+ public void process() throws Exception {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setValidating(false);
+ DocumentBuilder parser = dbf.newDocumentBuilder();
+ Document document = parser.newDocument();
+ Element module = document.createElement("module");
+ module.setAttribute("name", "Checker");
+
+ for (PackageDeclaration packageDeclaration : getCollectedPackageDeclarations()) {
+ Taglib taglibAnnotation = packageDeclaration.getAnnotation(Taglib.class);
+ createCheckstyleConfig(taglibAnnotation, packageDeclaration, module, document);
}
- Document document;
- Writer writer = null;
- try {
- String content = FileUtils.fileRead(sourceFacesConfigFile);
- SAXBuilder builder = new SAXBuilder();
- builder.setEntityResolver(new EntityResolver() {
- public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
- if ("-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN".equals(publicId)) {
- InputStream stream = FacesConfigAnnotationVisitor.class.getResourceAsStream(
- "/org/apache/myfaces/tobago/dtd/web-facesconfig_1_1.dtd");
- return new InputSource(stream);
- }
- return null;
- }
- });
- document = builder.build(new StringReader(content));
- // Normalise line endings. For some reason, JDOM replaces \r\n inside a comment with \n.
- normaliseLineEndings(document);
+ document.appendChild(module);
- // rewrite DOM as a string to find differences, since text outside the root element is not tracked
+ writeCheckstyleConfig(document);
+ }
- Element rootElement = document.getRootElement();
- if (is12()) {
- rootElement.setNamespace(Namespace.getNamespace("http://java.sun.com/xml/ns/javaee"));
- Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
- rootElement.addNamespaceDeclaration(Namespace.getNamespace("xi", "http://www.w3.org/2001/XInclude"));
- rootElement.setAttribute(new Attribute("schemaLocation",
- "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd", xsi));
- rootElement.setAttribute("version", "1.2");
- } else if (is20()) {
- rootElement.setNamespace(Namespace.getNamespace("http://java.sun.com/xml/ns/javaee"));
- Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
- rootElement.addNamespaceDeclaration(Namespace.getNamespace("xi", "http://www.w3.org/2001/XInclude"));
- rootElement.setAttribute(new Attribute("schemaLocation",
- "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd", xsi));
- rootElement.setAttribute("version", "2.0");
- }
- Namespace namespace = rootElement.getNamespace();
- if (is12()||is20()) {
- applyNamespace(rootElement, namespace);
- }
- List<Element> components = rootElement.getChildren(COMPONENT, namespace);
+ private Document createCheckstyleConfig(
+ Taglib taglibAnnotation, PackageDeclaration packageDeclaration, Element module, Document document)
+ throws ParserConfigurationException {
+ resetDuplicateList();
- List<Element> newComponents = new ArrayList<Element>();
- List<Element> newRenderer = new ArrayList<Element>();
- List<Element> newConverters = new ArrayList<Element>();
- List<Element> newValidators = new ArrayList<Element>();
-
- for (ClassDeclaration decl : getCollectedClassDeclarations()) {
- if (decl.getAnnotation(UIComponentTag.class) != null) {
- addElement(decl, newComponents, newRenderer, namespace);
- } else if (decl.getAnnotation(Converter.class) != null) {
- addConverter(decl, newConverters, namespace);
- } else if (decl.getAnnotation(Validator.class) != null) {
- addValidator(decl, newValidators, namespace);
- }
- }
- for (InterfaceDeclaration decl : getCollectedInterfaceDeclarations()) {
- if (decl.getAnnotation(UIComponentTag.class) != null) {
- addElement(decl, newComponents, newRenderer, namespace);
- }
- }
- List<Element> elementsToAdd = new ArrayList<Element>();
- // sort out duplicates
- for (Element newElement : newComponents) {
- boolean found = containsElement(components, newElement);
- if (!found) {
- elementsToAdd.add(newElement);
- }
- }
- if (!elementsToAdd.isEmpty()) {
- // if facesconfig contains no component section add the components after factory or application
- int lastIndex = getIndexAfter(rootElement, COMPONENT, FACTORY, APPLICATION);
- rootElement.addContent(lastIndex, elementsToAdd);
- }
- if (!newRenderer.isEmpty()) {
- Element renderKit = new Element(RENDER_KIT, namespace);
- Element renderKitId = new Element(RENDER_KIT_ID, namespace);
- renderKitId.setText("tobago");
- renderKit.addContent(renderKitId);
- Element renderKitClass = new Element(RENDER_KIT_CLASS, namespace);
- renderKitClass.setText("org.apache.myfaces.tobago.renderkit.TobagoRenderKit");
- renderKit.addContent(renderKitClass);
- renderKit.addContent(newRenderer);
- int lastIndex = getIndexAfter(rootElement, CONVERTER, COMPONENT, FACTORY, APPLICATION);
- rootElement.addContent(lastIndex, renderKit);
- }
- if (!newConverters.isEmpty()) {
- int lastIndex = getIndexAfter(rootElement, RENDER_KIT, CONVERTER, COMPONENT, FACTORY, APPLICATION);
- rootElement.addContent(lastIndex, newConverters);
- }
- if (!newValidators.isEmpty()) {
- rootElement.addContent(newValidators);
+ addLib(taglibAnnotation, module, document);
+
+ for (ClassDeclaration declaration : getCollectedClassDeclarations()) {
+ if (declaration.getPackage().equals(packageDeclaration)) {
+ appendTag(declaration, taglibAnnotation.shortName(), module, document);
}
- if (is11()) {
- document.setDocType(new DocType("faces-config",
- "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN",
- "http://java.sun.com/dtd/web-facesconfig_1_1.dtd"));
+ }
+ for (InterfaceDeclaration declaration : getCollectedInterfaceDeclarations()) {
+ if (declaration.getPackage().equals(packageDeclaration)) {
+ appendTag(declaration, taglibAnnotation.shortName(), module, document);
}
- writer =
- getEnv().getFiler().createTextFile(Filer.Location.SOURCE_TREE, "", new File(targetFacesConfigFile), null);
+ }
- StringWriter facesConfig = new StringWriter(1024);
- Format format = Format.getPrettyFormat();
- format.setLineSeparator(SEPARATOR);
- XMLOutputter out = new XMLOutputter(format);
- out.output(document, facesConfig);
- if (is11()) {
- // TODO: is this replace really necessary?
- String facesConfigStr =
- facesConfig.toString().replaceFirst(" xmlns=\"http://java.sun.com/JSF/Configuration\"", "");
- // TODO: Find a better way
- facesConfigStr = facesConfigStr.replaceFirst("\"http://java.sun.com/dtd/web-facesconfig_1_1.dtd\"",
- "\"http://java.sun.com/dtd/web-facesconfig_1_1.dtd\"[\n"
- + "<!ELEMENT allowed-child-components (#PCDATA)>\n"
- + "<!ELEMENT category (#PCDATA)>\n"
- + "<!ELEMENT deprecated (#PCDATA)>\n"
- + "<!ELEMENT hidden (#PCDATA)>\n"
- + "<!ELEMENT preferred (#PCDATA)>\n"
- + "<!ELEMENT read-only (#PCDATA)>\n"
- + "<!ELEMENT value-expression (#PCDATA)>\n"
- + "<!ELEMENT property-values (#PCDATA)>\n"
- + "<!ELEMENT required (#PCDATA)>\n"
- + "]");
- writer.append(facesConfigStr);
- } else {
- writer.append(facesConfig.toString());
- }
+ return document;
+ }
- } catch (JDOMException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
+ protected void writeCheckstyleConfig(Document document) throws
+ IOException, TransformerException {
+ Writer writer = null;
+ try {
+ getEnv().getMessager().printNotice("Create DOM");
+ final String path = "checkstyle-tobago.xml";
+ writer = getEnv().getFiler().createTextFile(
+ Filer.Location.SOURCE_TREE,
+ "",
+ new File(path),
+ null);
+ TransformerFactory transFactory = TransformerFactory.newInstance();
+ transFactory.setAttribute("indent-number", 2);
+ Transformer transformer = transFactory.newTransformer();
+
+ transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, "-//Puppy Crawl//DTD Check Configuration 1.2//EN");
+ transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "http://www.puppycrawl.com/dtds/configuration_1_2.dtd");
+
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ transformer.transform(new DOMSource(document), new StreamResult(writer));
+ getEnv().getMessager().printNotice("Write to file '" + path + "'");
} finally {
IOUtils.closeQuietly(writer);
}
}
- private void applyNamespace(Element parent, Namespace namespace) {
- for (Element element : (List<Element>) parent.getChildren()) {
- element.setNamespace(namespace);
- applyNamespace(element, namespace);
+ protected void appendTag(ClassDeclaration declaration, String taglib, Element parent, Document document) {
+ Tag annotationTag = declaration.getAnnotation(Tag.class);
+ checkDuplicates(annotationTag.name());
+ if (declaration.getAnnotation(Deprecated.class) != null) {
+ addTag(taglib, parent, annotationTag.name(), document);
}
- }
-
- private void addConverter(ClassDeclaration decl, List<Element> newConverters, Namespace namespace) {
- Converter converterAnn = decl.getAnnotation(Converter.class);
- Element converter = new Element(CONVERTER, namespace);
- if (converterAnn.id().length() > 0) {
- Element converterId = new Element(CONVERTER_ID, namespace);
- converterId.setText(converterAnn.id());
- converter.addContent(converterId);
- } else if (converterAnn.forClass().length() > 0) {
- Element converterForClass = new Element(CONVERTER_FOR_CLASS, namespace);
- converterForClass.setText(converterAnn.forClass());
- converter.addContent(converterForClass);
- }
-
- Element converterClass = new Element(CONVERTER_CLASS, namespace);
- converterClass.setText(decl.getQualifiedName());
- converter.addContent(converterClass);
- newConverters.add(converter);
- }
-
- private void addValidator(ClassDeclaration decl, List<Element> newValidators, Namespace namespace) {
- Validator validatorAnn = decl.getAnnotation(Validator.class);
- Element validator = new Element(VALIDATOR, namespace);
- if (validatorAnn.id().length() > 0) {
- Element validatorId = new Element(VALIDATOR_ID, namespace);
- validatorId.setText(validatorAnn.id());
- validator.addContent(validatorId);
- } else if (validatorAnn.forClass().length() > 0) {
- Element validatorForClass = new Element(VALIDATOR_FOR_CLASS, namespace);
- validatorForClass.setText(validatorAnn.forClass());
- validator.addContent(validatorForClass);
- }
-
- Element validatorClass = new Element(VALIDATOR_CLASS, namespace);
- validatorClass.setText(decl.getQualifiedName());
- validator.addContent(validatorClass);
- newValidators.add(validator);
- }
-
- private boolean containsElement(List<Element> components, Element newElement) {
- return getEqualElement(components, newElement) != null;
- }
-
- private Element getEqualElement(List<Element> components, Element newElement) {
- for (Element element : components) {
- if (equals(element, newElement)) {
- return element;
- }
- }
- return null;
- }
-
- private int getIndexAfter(Element rootElement, String... tagNames) {
- for (String tagName : tagNames) {
- int index = getIndexAfter(rootElement, tagName);
- if (index != 0) {
- return index;
- }
+ addAttributes(declaration, taglib, parent, annotationTag.name(), document);
+ if (StringUtils.isNotEmpty(annotationTag.deprecatedName())) {
+ addTag(taglib, parent, annotationTag.deprecatedName(), document);
+ addAttributes(declaration, taglib, parent, annotationTag.deprecatedName(), document);
}
- return 0;
}
- private int getIndexAfter(Element rootElement, String tagName) {
- List<Element> components = rootElement.getChildren(tagName, rootElement.getNamespace());
- if (!components.isEmpty()) {
- return rootElement.indexOf(components.get(components.size() - 1)) + 1;
- }
- return 0;
- }
+ protected void appendTag(InterfaceDeclaration declaration, String taglib, Element parent, Document document) {
+ Tag annotationTag = declaration.getAnnotation(Tag.class);
+ if (annotationTag != null) {
+ checkDuplicates(annotationTag.name());
+ // TODO configure replacement
- public boolean equals(Element element1, Element element2) {
- Namespace namespace = element1.getNamespace();
- if (element1.getName().equals(element2.getName()) && element1.getNamespace().equals(element2.getNamespace())) {
- if (element1.getChildText(COMPONENT_CLASS, namespace).equals(element2.getChildText(COMPONENT_CLASS, namespace))) {
- if (element1.getChildText(COMPONENT_TYPE, namespace).equals(element2.getChildText(COMPONENT_TYPE, namespace))) {
- return true;
- }
+ String className =
+ declaration.getQualifiedName().substring(0, declaration.getQualifiedName().length() - "Declaration".length());
+ if (declaration.getAnnotation(UIComponentTag.class) != null) {
+ className = "org.apache.myfaces.tobago.internal.taglib." + StringUtils.capitalize(annotationTag.name()) + "Tag";
}
- }
- return false;
- }
-
- protected Element createComponentElement(TypeDeclaration decl, UIComponentTag componentTag,
- Class uiComponentClass, Namespace namespace) throws IOException, NoSuchFieldException, IllegalAccessException {
- Field componentField = uiComponentClass.getField("COMPONENT_TYPE");
- String componentType = (String) componentField.get(null);
- Element element = new Element(COMPONENT, namespace);
- String displayName = componentTag.displayName();
- if (displayName.equals("")) {
- displayName = uiComponentClass.getName().substring(uiComponentClass.getName().lastIndexOf(".") + 1);
- }
- Element elementDisplayName = new Element(DISPLAY_NAME, namespace);
- elementDisplayName.setText(displayName);
- element.addContent(elementDisplayName);
- Element elementType = new Element(COMPONENT_TYPE, namespace);
- elementType.setText(componentType);
- element.addContent(elementType);
- Element elementClass = new Element(COMPONENT_CLASS, namespace);
- elementClass.setText(componentTag.uiComponent());
- element.addContent(elementClass);
-
- return element;
- }
-
- protected void addRendererElement(TypeDeclaration decl, UIComponentTag componentTag,
- Class uiComponentClass, List<Element> renderer, Namespace namespace)
- throws IOException, NoSuchFieldException, IllegalAccessException {
- String rendererType = componentTag.rendererType();
- if (rendererType != null && rendererType.length() > 0) {
- Field componentField = uiComponentClass.getField("COMPONENT_FAMILY");
- String componentFamily = (String) componentField.get(null);
- Element element = new Element(RENDERER, namespace);
- String displayName = componentTag.displayName();
- if (displayName.equals("")) {
- displayName = uiComponentClass.getName().substring(uiComponentClass.getName().lastIndexOf(".") + 1);
+ String msg = "Replacing: " + declaration.getQualifiedName() + " -> " + className;
+ getEnv().getMessager().printNotice(msg);
+ if (declaration.getAnnotation(Deprecated.class) != null) {
+ addTag(taglib, parent, annotationTag.name(), document);
+ }
+ addAttributes(declaration, taglib, parent, annotationTag.name(), document);
+ if (StringUtils.isNotEmpty(annotationTag.deprecatedName())) {
+ addTag(taglib, parent, annotationTag.deprecatedName(), document);
+ addAttributes(declaration, taglib, parent, annotationTag.name(), document);
}
- Element elementDisplayName = new Element(DISPLAY_NAME, namespace);
- elementDisplayName.setText(displayName);
- element.addContent(elementDisplayName);
- Element elementComponentFamily = new Element(COMPONENT_FAMILY, namespace);
- elementComponentFamily.addContent(componentFamily);
- element.addContent(elementComponentFamily);
- Element elementType = new Element(RENDERER_TYPE, namespace);
- elementType.setText(rendererType);
- element.addContent(elementType);
- Element elementClass = new Element(RENDERER_CLASS, namespace);
- String className = "org.apache.myfaces.tobago.renderkit." + rendererType + "Renderer";
- elementClass.setText(className);
- element.addContent(elementClass);
- renderer.add(element);
}
}
+ protected void addTag(String taglib, Element parent, String tagName, Document document) {
- private Element createElementExtension(TypeDeclaration decl, UIComponentTag uiComponentTag,
- Namespace namespace) {
- Element elementExtension = new Element(COMPONENT_EXTENSION, namespace);
- Element elementAllowedChildComponents = new Element(ALLOWED_CHILD_COMPONENTS, namespace);
- String[] allowedChildComponents = uiComponentTag.allowedChildComponenents();
- String allowedComponentTypes = "";
- for (String componentType : allowedChildComponents) {
- allowedComponentTypes += componentType + " ";
- }
- elementAllowedChildComponents.setText(allowedComponentTypes);
- elementExtension.addContent(elementAllowedChildComponents);
- Element elementCategory = new Element(CATEGORY, namespace);
- elementCategory.setText(uiComponentTag.category().toString());
- elementExtension.addContent(elementCategory);
- Deprecated deprecated = decl.getAnnotation(Deprecated.class);
- if (deprecated != null) {
- Element elementDeprecated = new Element(DEPRECATED, namespace);
- elementDeprecated.setText("Warning: This component is deprecated!");
- elementExtension.addContent(elementDeprecated);
- }
- Element elementHidden = new Element(HIDDEN, namespace);
- elementHidden.setText(Boolean.toString(uiComponentTag.isHidden()));
- elementExtension.addContent(elementHidden);
-
- return elementExtension;
- }
-
- protected void addAttribute(MethodDeclaration d, Class uiComponentClass, List properties, List attributes,
- Namespace namespace) {
- UIComponentTagAttribute componentAttribute = d.getAnnotation(UIComponentTagAttribute.class);
- if (componentAttribute != null) {
- String simpleName = d.getSimpleName();
- if (simpleName.startsWith("set")) {
- String attributeStr = simpleName.substring(3, 4).toLowerCase(Locale.ENGLISH) + simpleName.substring(4);
- String methodStr;
- if (componentAttribute.type().length == 1
- && (componentAttribute.type()[0].equals(Boolean.class.getName())
- || componentAttribute.type()[0].equals("boolean"))) {
- methodStr = "is" + simpleName.substring(3);
- } else {
- methodStr = "get" + simpleName.substring(3);
- }
- try {
- uiComponentClass.getMethod(methodStr, new Class[0]);
- Element property = new Element(PROPERTY, namespace);
- Element propertyName = new Element(PROPERTY_NAME, namespace);
- Element propertyClass = new Element(PROPERTY_CLASS, namespace);
-
- propertyName.setText(attributeStr);
- addClass(componentAttribute, propertyClass);
-
- addDescription(d, property, namespace);
-
- property.addContent(propertyName);
- property.addContent(propertyClass);
- if (componentAttribute.defaultValue().length() > 0) {
- Element defaultValue = new Element(DEFAULT_VALUE, namespace);
- defaultValue.setText(componentAttribute.defaultValue());
- property.addContent(defaultValue);
- }
-
- property.addContent(createPropertyOrAttributeExtension(PROPERTY_EXTENSION, d, componentAttribute, namespace));
- properties.add(property);
- } catch (NoSuchMethodException e) {
- // if property not found should be attribute
- Element attribute = new Element(ATTRIBUTE, namespace);
- Element attributeName = new Element(ATTRIBUTE_NAME, namespace);
- Element attributeClass = new Element(ATTRIBUTE_CLASS, namespace);
-
- attributeName.setText(attributeStr);
- addClass(componentAttribute, attributeClass);
-
- addDescription(d, attribute, namespace);
-
- attribute.addContent(attributeName);
- attribute.addContent(attributeClass);
- if (componentAttribute.defaultValue().length() > 0) {
- Element defaultValue = new Element(DEFAULT_VALUE, namespace);
- defaultValue.setText(componentAttribute.defaultValue());
- attribute.addContent(defaultValue);
- }
+ final String format = "<" + taglib + ":" + tagName + "\\b";
+ final String message = "The tag '" + tagName + "' is deprecated.";
- attribute.addContent(createPropertyOrAttributeExtension(ATTRIBUTE_EXTENSION, d,
- componentAttribute, namespace));
+ Element module = createRegexpModule(format, message, document);
- attributes.add(attribute);
- }
- } else {
- throw new IllegalArgumentException("Only setter allowed found: " + simpleName);
- }
- }
+ parent.appendChild(module);
}
- private void addClass(UIComponentTagAttribute componentAttribute, Element attributeClass) {
- if (componentAttribute.type().length > 1) {
- attributeClass.setText(Object.class.getName());
- } else if (componentAttribute.type().length == 1) {
- String className = componentAttribute.type()[0];
- if (componentAttribute.expression().isMethodExpression() && isUnifiedEL()) {
- className = "javax.el.MethodExpression";
- }
- attributeClass.setText((className.equals(Boolean.class.getName()) && !isUnifiedEL()) ? "boolean" : className);
+ private void checkDuplicates(String tagName) {
+ if (tagSet.contains(tagName)) {
+ throw new IllegalArgumentException("tag with name " + tagName + " already defined!");
} else {
- if (componentAttribute.expression().isMethodExpression()) {
- String className = "";
- if (isUnifiedEL()) {
- className = "javax.el.MethodExpression";
- } else {
- className = "javax.faces.el.MethodBinding";
- }
- attributeClass.setText(className);
- }
+ tagSet.add(tagName);
}
}
- private void addDescription(MethodDeclaration d, Element attribute, Namespace namespace) {
- String comment = d.getDocComment();
- if (comment != null) {
- int index = comment.indexOf('@');
- if (index != -1) {
- comment = comment.substring(0, index);
- }
- comment = comment.trim();
- if (comment.length() > 0) {
- Element description = new Element(DESCRIPTION, namespace);
- description.setText(comment);
- attribute.addContent(description);
- }
+ protected void addAttributes(
+ Collection<InterfaceType> interfaces, String taglib, Element parent, String tagName, Document document) {
+ for (InterfaceType type : interfaces) {
+ addAttributes(type.getDeclaration(), taglib, parent, tagName, document);
}
}
- private Element createPropertyOrAttributeExtension(String extensionType, MethodDeclaration methodDeclaration,
- UIComponentTagAttribute uiComponentTagAttribute, Namespace namespace) throws IllegalArgumentException {
- Element extensionElement = new Element(extensionType, namespace);
- Element valueExpression = new Element(VALUE_EXPRESSION, namespace);
- valueExpression.setText(uiComponentTagAttribute.expression().toMetaDataString());
- extensionElement.addContent(valueExpression);
- String[] allowedValues = uiComponentTagAttribute.allowedValues();
- if (allowedValues.length > 0) {
- Element propertyValues = new Element(PROPERTY_VALUES, namespace);
- String values = "";
- for (String value : allowedValues) {
- values += value + " ";
- }
- propertyValues.setText(values);
- extensionElement.addContent(propertyValues);
- }
- Deprecated deprecated = methodDeclaration.getAnnotation(Deprecated.class);
- if (deprecated != null) {
- Element elementDeprecated = new Element(DEPRECATED, namespace);
- elementDeprecated.setText("Warning: This property is deprecated!");
- extensionElement.addContent(elementDeprecated);
- }
- Element hidden = new Element(HIDDEN, namespace);
- hidden.setText(Boolean.toString(uiComponentTagAttribute.isHidden()));
- extensionElement.addContent(hidden);
- Element readOnly = new Element(READONLY, namespace);
- readOnly.setText(Boolean.toString(uiComponentTagAttribute.isReadOnly()));
- extensionElement.addContent(readOnly);
- TagAttribute tagAttribute = methodDeclaration.getAnnotation(TagAttribute.class);
- if (tagAttribute != null) {
- Element required = new Element(REQUIRED, namespace);
- required.setText(Boolean.toString(tagAttribute.required()));
- extensionElement.addContent(required);
- }
-
- return extensionElement;
- }
-
- protected void addAttributes(InterfaceDeclaration type, Class uiComponentClass, List properties, List attributes,
- Namespace namespace) {
- addAttributes(type.getSuperinterfaces(), uiComponentClass, properties, attributes, namespace);
- for (MethodDeclaration decl : getCollectedMethodDeclarations()) {
- if (decl.getDeclaringType().equals(type)) {
- addAttribute(decl, uiComponentClass, properties, attributes, namespace);
+ protected void addAttributes(
+ InterfaceDeclaration type, String taglib, Element parent, String tagName, Document document) {
+ addAttributes(type.getSuperinterfaces(), taglib, parent, tagName, document);
+ for (MethodDeclaration declaration : getCollectedMethodDeclarations()) {
+ if (declaration.getDeclaringType().equals(type)) {
+ addAttribute(declaration, taglib, parent, tagName, document);
}
}
}
- protected void addAttributes(Collection<InterfaceType> interfaces, Class uiComponentClass, List properties,
- List attributes, Namespace namespace) {
- for (InterfaceType type : interfaces) {
- addAttributes(type.getDeclaration(), uiComponentClass, properties, attributes, namespace);
- }
- }
+ protected void addAttributes(
+ ClassDeclaration d, String taglib, Element parent, String tagName, Document document) {
- protected void addAttributes(ClassDeclaration d, Class uiComponentClass, List properties, List attributes,
- Namespace namespace) {
- for (MethodDeclaration decl : getCollectedMethodDeclarations()) {
+ for (MethodDeclaration declaration : getCollectedMethodDeclarations()) {
if (d.getQualifiedName().
- equals(decl.getDeclaringType().getQualifiedName())) {
- addAttribute(decl, uiComponentClass, properties, attributes, namespace);
+ equals(declaration.getDeclaringType().getQualifiedName())) {
+ addAttribute(declaration, taglib, parent, tagName, document);
}
}
- addAttributes(d.getSuperinterfaces(), uiComponentClass, properties, attributes, namespace);
+ addAttributes(d.getSuperinterfaces(), taglib, parent, tagName, document);
if (d.getSuperclass() != null) {
- addAttributes(d.getSuperclass().getDeclaration(), uiComponentClass, properties, attributes, namespace);
+ addAttributes(d.getSuperclass().getDeclaration(), taglib, parent, tagName, document);
}
}
-
- private void addFacets(UIComponentTag componentTag, Namespace namespace, Element element) {
- Facet[] facets = componentTag.facets();
- for (Facet facet : facets) {
- Element facetElement = new Element(FACET, namespace);
- String description = facet.description();
- if (description != null && description.length() > 0) {
- Element facetDescription = new Element(DESCRIPTION, namespace);
- facetDescription.setText(description);
- facetElement.addContent(facetDescription);
- }
- Element facetName = new Element(FACET_NAME, namespace);
- facetName.setText(facet.name());
- facetElement.addContent(facetName);
- Element facetExtension = new Element(FACET_EXTENSION, namespace);
- Element elementAllowedChildComponents = new Element(ALLOWED_CHILD_COMPONENTS, namespace);
- String[] allowedChildComponents = facet.allowedChildComponenents();
- String allowedComponentTypes = "";
- for (String componentType : allowedChildComponents) {
- allowedComponentTypes += componentType + " ";
- }
- elementAllowedChildComponents.setText(allowedComponentTypes);
- facetExtension.addContent(elementAllowedChildComponents);
- facetElement.addContent(facetExtension);
- element.addContent(facetElement);
- }
+ private void resetDuplicateList() {
+ tagSet = new HashSet<String>();
}
- protected void addElement(ClassDeclaration decl, List<Element> components, List<Element> renderer,
- Namespace namespace) throws IOException {
- UIComponentTag componentTag = decl.getAnnotation(UIComponentTag.class);
- if (componentTag != null) {
- try {
- Class<?> uiComponentClass = Class.forName(componentTag.uiComponent());
- if (!componentTag.isComponentAlreadyDefined()) {
- Element element = createComponentElement(decl, componentTag, uiComponentClass, namespace);
- if (element != null) {
- if (!containsElement(components, element)) {
- addFacets(componentTag, namespace, element);
- List attributes = new ArrayList();
- List properties = new ArrayList();
- addAttributes(decl, uiComponentClass, attributes, properties, namespace);
- if (!attributes.isEmpty()) {
- element.addContent(attributes);
- }
- if (!properties.isEmpty()) {
- element.addContent(properties);
- }
- element.addContent(createElementExtension(decl, componentTag, namespace));
- components.add(element);
- } else {
- // TODO add facet and attributes
- }
- }
- }
- addRendererElement(decl, componentTag, uiComponentClass, renderer, namespace);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
+ protected void addAttribute(
+ MethodDeclaration declaration, String taglib, Element parent, String tagName, Document document) {
+ TagAttribute tagAttribute = declaration.getAnnotation(TagAttribute.class);
+ Deprecated deprecatedAnnotation = declaration.getAnnotation(Deprecated.class);
+ if (tagAttribute != null && deprecatedAnnotation != null) {
+ String simpleName = declaration.getSimpleName();
+ if (simpleName.startsWith("set") || simpleName.startsWith("get")) {
- protected void addElement(InterfaceDeclaration decl, List<Element> components, List<Element> renderer,
- Namespace namespace) throws IOException {
- UIComponentTag componentTag = decl.getAnnotation(UIComponentTag.class);
- if (componentTag != null) {
- try {
- Class<?> uiComponentClass = Class.forName(componentTag.uiComponent());
- if (!componentTag.isComponentAlreadyDefined()) {
- Element element = createComponentElement(decl, componentTag, uiComponentClass, namespace);
- if (element != null) {
- if (!containsElement(components, element)) {
- addFacets(componentTag, namespace, element);
- List attributes = new ArrayList();
- List properties = new ArrayList();
- addAttributes(decl, uiComponentClass, properties, attributes, namespace);
- if (!attributes.isEmpty()) {
- element.addContent(attributes);
- }
- if (!properties.isEmpty()) {
- element.addContent(properties);
- }
- element.addContent(createElementExtension(decl, componentTag, namespace));
- components.add(element);
- } else {
- // TODO add facet and attributes
- }
- }
+ String attributeStr = simpleName.substring(3, 4).toLowerCase(Locale.ENGLISH) + simpleName.substring(4);
+ if (tagAttribute.name().length() > 0) {
+ attributeStr = tagAttribute.name();
}
- addRendererElement(decl, componentTag, uiComponentClass, renderer, namespace);
- } catch (Exception e) {
- e.printStackTrace();
+
+ final String format = "<" + taglib + ":" + tagName + "\\b[^<]*\\b" + attributeStr + "=";
+ final String message = "The attribute '" + attributeStr + "' is deprecated for tag '" + tagName + "'";
+
+ Element module = createRegexpModule(format, message, document);
+
+ parent.appendChild(module);
+ } else {
+ throw new IllegalArgumentException("Only setter allowed found: " + simpleName);
}
}
}
- private void normaliseLineEndings(Document document) {
- for (Iterator i = document.getDescendants(new ContentFilter(ContentFilter.COMMENT)); i.hasNext();) {
- Comment c = (Comment) i.next();
- c.setText(c.getText().replaceAll("\n", SEPARATOR));
+ private void addLib(Taglib taglibAnnotation, Element parent, Document document) {
+
+ final String shortName = taglibAnnotation.shortName();
+ if (shortName.length() != 2) {
+
}
- }
+ final String uri = taglibAnnotation.uri();
- private boolean is12() {
- return "1.2".equals(jsfVersion);
- }
+ final String format = "(?<!" + shortName + ")=(\"|')" + uri + "(\"|')";
+ final String message = "The taglib declaration is not like 'xmlns:" + shortName + "=\"" + uri + "\"'";
- private boolean is11() {
- return "1.1".equals(jsfVersion);
- }
+ final Element module = createRegexpModule(format, message, document);
- private boolean is20() {
- return "2.0".equals(jsfVersion);
+ parent.appendChild(module);
}
- private boolean isUnifiedEL() {
- return !"1.1".equals(jsfVersion);
+ protected Element createRegexpModule(String formatValue, String messageValue, Document document) {
+ Element module = document.createElement("module");
+ module.setAttribute("name", "RegexpMultiline");
+
+ Element format = document.createElement("property");
+ format.setAttribute("name", "format");
+ format.setAttribute("value", formatValue);
+ module.appendChild(format);
+
+ Element message = document.createElement("property");
+ message.setAttribute("name", "message");
+ message.setAttribute("value", messageValue);
+ module.appendChild(message);
+
+ return module;
}
}
Propchange: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CheckstyleConfigAnnotationVisitor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/CheckstyleConfigAnnotationVisitor.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL