myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lof...@apache.org
Subject svn commit: r1747427 - in /myfaces/tobago/trunk: tobago-example/tobago-example-demo/src/main/webapp/ tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/processor/ tobago-tool/tobago-tool-apt/src/test/ tobago-tool/tobago-tool-apt/sr...
Date Wed, 08 Jun 2016 18:07:10 GMT
Author: lofwyr
Date: Wed Jun  8 18:07:10 2016
New Revision: 1747427

URL: http://svn.apache.org/viewvc?rev=1747427&view=rev
Log:
TOBAGO-1566: Enhance the check of the Facelet pages

Added:
    myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/test/
    myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/test/java/
    myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/test/java/org/
    myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/test/java/org/apache/
    myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/test/java/org/apache/myfaces/
    myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/test/java/org/apache/myfaces/tobago/
    myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/test/java/org/apache/myfaces/tobago/apt/
    myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/test/java/org/apache/myfaces/tobago/apt/processor/
    myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/test/java/org/apache/myfaces/tobago/apt/processor/CheckstyleConfigGeneratorUnitTest.java
Modified:
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/init.xhtml
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/menu.xhtml
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/plain.xhtml
    myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/processor/CheckstyleConfigGenerator.java

Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/init.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/init.xhtml?rev=1747427&r1=1747426&r2=1747427&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/init.xhtml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/init.xhtml Wed
Jun  8 18:07:10 2016
@@ -19,19 +19,24 @@
 
 <f:view locale="#{clientConfigController.locale}"
         xmlns:f="http://java.sun.com/jsf/core"
-        xmlns:tc="http://myfaces.apache.org/tobago/component"
-    >
+        xmlns:tc="http://myfaces.apache.org/tobago/component">
+
   <tc:loadBundle basename="overview" var="overviewBundle"/>
   <tc:page applicationIcon="icon/favicon.ico" label="#{overviewBundle.pageTitle}" id="page">
-    <f:facet name="layout">
-      <tc:gridLayout marginLeft="100px" marginTop="100px" rowSpacing="40px" rows="auto;auto"/>
-    </f:facet>
+
     <f:facet name="action">
       <tc:link action="#{navigationState.gotoFirst}"/>
     </f:facet>
 
-    <tc:image value="image/tobago_head.png" width="150px" height="83px"/>
-    <tc:out value="Initializing ..."/>
+    <!-- todo: justifyContent -->
+    <tc:flexLayout rows="auto;auto" alignItems="center" justifyContent="center">
+
+      <tc:image value="image/tobago_head.png">
+        <tc:style width="150px" height="83px"/>
+      </tc:image>
+
+      <tc:out value="Initializing ..."/>
+    </tc:flexLayout>
 
   </tc:page>
 </f:view>

Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/menu.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/menu.xhtml?rev=1747427&r1=1747426&r2=1747427&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/menu.xhtml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/menu.xhtml Wed
Jun  8 18:07:10 2016
@@ -31,7 +31,6 @@
 -->
 
     <tc:bar id="bar">
-    <!--<tc:bar image="image/feather-leaf.png" label="Tobago Demo" id="bar">-->
       <f:facet name="brand">
         <tc:link image="image/feather-leaf.png" label="Tobago Demo" id="brand" link="/"/>
       </f:facet>

Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/plain.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/plain.xhtml?rev=1747427&r1=1747426&r2=1747427&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/plain.xhtml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/plain.xhtml Wed
Jun  8 18:07:10 2016
@@ -23,7 +23,7 @@
 
   <f:view locale="#{clientConfigController.locale}">
     <tc:loadBundle basename="overview" var="overviewBundle"/>
-    <tc:page label="Test" id="page" width="1000px" height="750px">
+    <tc:page label="Test" id="page">
 
       <ui:insert/>
 

Modified: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/processor/CheckstyleConfigGenerator.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/processor/CheckstyleConfigGenerator.java?rev=1747427&r1=1747426&r2=1747427&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/processor/CheckstyleConfigGenerator.java
(original)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/main/java/org/apache/myfaces/tobago/apt/processor/CheckstyleConfigGenerator.java
Wed Jun  8 18:07:10 2016
@@ -168,6 +168,7 @@ public class CheckstyleConfigGenerator e
         addTag(taglib, parent, annotationTag.deprecatedName(), document);
         addAttributes(typeElement, taglib, parent, annotationTag.name(), document);
       }
+      addAttributesForTag(typeElement, taglib, parent, annotationTag.name(), document);
     }
   }
 
@@ -193,6 +194,48 @@ public class CheckstyleConfigGenerator e
     tagSet = new HashSet<String>();
   }
 
+  protected void addAttributesForTag(
+      final TypeElement type, final String taglib, final Element parent, final String tagName,
+      final Document document)
+      throws ClassNotFoundException {
+
+    List<String> attributes = new ArrayList<String>();
+    for (final javax.lang.model.element.Element element : getAllMembers(type)) {
+      if (element instanceof ExecutableElement) {
+        final ExecutableElement executableElement = (ExecutableElement) element;
+        if (executableElement.getAnnotation(TagAttribute.class) == null
+            && executableElement.getAnnotation(UIComponentTagAttribute.class) ==
null) {
+          continue;
+        }
+        final TagAttribute tagAttribute = executableElement.getAnnotation(TagAttribute.class);
+        if (tagAttribute != null) {
+          final String simpleName = executableElement.getSimpleName().toString();
+          if (simpleName.startsWith("set") || simpleName.startsWith("get")) {
+
+            String attributeStr = simpleName.substring(3, 4).toLowerCase(Locale.ENGLISH)
+ simpleName.substring(4);
+            if (tagAttribute.name().length() > 0) {
+              attributeStr = tagAttribute.name();
+            }
+            attributes.add(attributeStr);
+          }
+        }
+      }
+    }
+    final String regexp = getRegExpForUndefinedAttributes(taglib, tagName, attributes);
+
+    final String message = "Found an unknown attribute in tag '" + tagName + "'.";
+
+    Element module = createRegexpModule(regexp, message, document);
+    parent.appendChild(module);
+
+    if (taglib.equals("tx")) {
+      final String m2 = "The taglib tx is deprecated, please use tc with labelLayout. Found
tag 'tx:" + tagName + "'.";
+      module = createRegexpModule("<" + taglib + ":" + tagName + "\\b", m2, document);
+      parent.appendChild(module);
+    }
+
+  }
+
   protected void addAttributes(
       final TypeElement type, final String taglib, final Element tagElement, final String
tagName,
       final Document document)
@@ -286,4 +329,25 @@ public class CheckstyleConfigGenerator e
     return module;
   }
 
+  protected static String getRegExpForUndefinedAttributes(
+      String taglib, String tagName, List<String> attributes) {
+    final StringBuilder builder = new StringBuilder();
+    builder.append("<");
+    builder.append(taglib);
+    builder.append(":");
+    builder.append(tagName);
+    builder.append("(\\s+(");
+    for (String attribute : attributes) {
+      builder.append(attribute);
+      builder.append('|');
+    }
+    builder.append("xmlns:\\w*)=\\\"([^\"=<>]*)\\\")*\\s+(?!(");
+    for (String attribute : attributes) {
+      builder.append(attribute);
+      builder.append('|');
+    }
+    builder.append("xmlns:\\w*|\\W))");
+    return builder.toString();
+  }
+
 }

Added: myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/test/java/org/apache/myfaces/tobago/apt/processor/CheckstyleConfigGeneratorUnitTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/test/java/org/apache/myfaces/tobago/apt/processor/CheckstyleConfigGeneratorUnitTest.java?rev=1747427&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/test/java/org/apache/myfaces/tobago/apt/processor/CheckstyleConfigGeneratorUnitTest.java
(added)
+++ myfaces/tobago/trunk/tobago-tool/tobago-tool-apt/src/test/java/org/apache/myfaces/tobago/apt/processor/CheckstyleConfigGeneratorUnitTest.java
Wed Jun  8 18:07:10 2016
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.myfaces.tobago.apt.processor;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Arrays;
+
+public class CheckstyleConfigGeneratorUnitTest {
+
+  @Test
+  public void testGetRegExpForUndefinedAttributes() {
+
+    String regexp = CheckstyleConfigGenerator.getRegExpForUndefinedAttributes(
+        "tc", "textarea", Arrays.asList("attr1", "attr2"));
+
+    Assert.assertEquals(
+        "<tc:textarea(\\s+(attr1|attr2|xmlns:\\w*)=\\\"([^\"=<>]*)\\\")*\\s+(?!(attr1|attr2|xmlns:\\w*|\\W))",
regexp);
+
+    regexp = ".*" + regexp + ".*";
+
+    Assert.assertFalse("<tc:textarea attr1=\"bla bla\"/>".matches(regexp));
+    Assert.assertFalse("<tc:textarea attr2=\"bla bla\"/>".matches(regexp));
+    Assert.assertFalse("<tc:textarea attr2=\"bla bla\" attr1=\".....\"/>".matches(regexp));
+    Assert.assertTrue("<tc:textarea hallo=\"bla bla\"/>".matches(regexp));
+
+    Assert.assertFalse("<tc:textarea xmlns:f=\"http://java.sun.com/jsf/core\" attr1=\"bla
bla\"/>".matches(regexp));
+    Assert.assertTrue("<tc:textarea xmlns:f=\"http://java.sun.com/jsf/core\" hallo=\"bla
bla\"/>".matches(regexp));
+
+    Assert.assertFalse("<any> <tc:textarea      attr1=\"bla bla\"     /> <any>".matches(regexp));
+    Assert.assertFalse("<any> <tc:textarea         attr2=\"bla bla\"  /><any>".matches(regexp));
+    Assert.assertFalse("<any> <tc:textarea            attr2=\"bla bla\"    attr1=\".....\"/><any>
".matches(regexp));
+    Assert.assertTrue("<any> <tc:textarea        hallo=\"bla bla\"         />
<any> ".matches(regexp));
+  }
+}



Mime
View raw message