You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by th...@apache.org on 2014/07/05 21:04:47 UTC

git commit: TAP5-2192 : adds tags to ComponentLibraryInfo and adds @Description to tapestry5-annotations

Repository: tapestry-5
Updated Branches:
  refs/heads/master c4d8d6c30 -> aca075cb7


TAP5-2192 : adds tags to ComponentLibraryInfo and adds @Description to tapestry5-annotations


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/aca075cb
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/aca075cb
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/aca075cb

Branch: refs/heads/master
Commit: aca075cb714b5281457ae62146f8de5b6feebfae
Parents: c4d8d6c
Author: Thiago H. de Paula Figueiredo <th...@apache.org>
Authored: Sat Jul 5 16:04:32 2014 -0300
Committer: Thiago H. de Paula Figueiredo <th...@apache.org>
Committed: Sat Jul 5 16:04:32 2014 -0300

----------------------------------------------------------------------
 .../corelib/pages/ComponentLibraries.java       | 23 +++++++++-
 .../tapestry5/modules/TapestryModule.java       |  1 +
 .../services/ComponentLibraryInfo.java          | 20 ++++++++-
 .../corelib/pages/ComponentLibraries.tml        | 30 +++++++++++--
 .../ComponentLibrariesCatalogPageTests.groovy   | 12 ++++-
 .../locallib/alpha/pages/Logo.groovy            |  1 +
 .../locallib/alpha/pages/AlphaRoot.java         |  3 ++
 .../tapestry5/ioc/annotations/Description.java  | 46 ++++++++++++++++++++
 8 files changed, 129 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/aca075cb/tapestry-core/src/main/java/org/apache/tapestry5/corelib/pages/ComponentLibraries.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/pages/ComponentLibraries.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/pages/ComponentLibraries.java
index 362d5f7..675063c 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/pages/ComponentLibraries.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/pages/ComponentLibraries.java
@@ -23,12 +23,14 @@ import org.apache.tapestry5.annotations.OnEvent;
 import org.apache.tapestry5.annotations.Property;
 import org.apache.tapestry5.annotations.UnknownActivationContextCheck;
 import org.apache.tapestry5.annotations.WhitelistAccessOnly;
+import org.apache.tapestry5.ioc.annotations.Description;
 import org.apache.tapestry5.ioc.annotations.Inject;
 import org.apache.tapestry5.json.JSONArray;
 import org.apache.tapestry5.json.JSONObject;
 import org.apache.tapestry5.services.ComponentClassResolver;
 import org.apache.tapestry5.services.ComponentLibraryInfo;
 import org.apache.tapestry5.util.TextStreamResponse;
+import org.eclipse.jetty.io.NetworkTrafficListener.Empty;
 
 /**
  * Page used to describe the component libraries being used in the application.
@@ -39,7 +41,9 @@ import org.apache.tapestry5.util.TextStreamResponse;
 @WhitelistAccessOnly
 public class ComponentLibraries
 {
-    
+
+    final private static String[] EMTPY_STRING_ARRAY = {};
+
     private static enum Type { PAGE, COMPONENT, MIXIN }
 
     @Inject
@@ -158,6 +162,23 @@ public class ComponentLibraries
         return logicalName.replace("core/", "");
     }
     
+    @Cached(watch = "logicalName")
+    public String[] getTags() throws ClassNotFoundException {
+        Description description = getDescription();
+        return description != null ? description.tags() : EMTPY_STRING_ARRAY;
+    }
+
+    @Cached(watch = "logicalName")
+    public Description getDescription() throws ClassNotFoundException
+    {
+        return Class.forName(getClassName()).getAnnotation(Description.class);
+    }
+
+    public boolean isClassHasTags() throws ClassNotFoundException
+    {
+        return getTags().length > 0;
+    }
+    
     @OnEvent("json")
     Object generateJSONDescription(String libraryName)
     {

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/aca075cb/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java b/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java
index 8e3e070..318feec 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java
@@ -457,6 +457,7 @@ public final class TapestryModule
         info.setArtifactId("tapestry-core");
         info.setVersion("5.4.0");
         info.setSourceUrlResolver(new ComponentLibraryInfo.GitWebMavenSourceUrlResolver());
+        info.setTags(Arrays.asList("core", "out-of-the-box"));
         
         configuration.add(new LibraryMapping(InternalConstants.CORE_LIBRARY, "org.apache.tapestry5.corelib", info));
         configuration.add(new LibraryMapping("", appRootPackage));

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/aca075cb/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentLibraryInfo.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentLibraryInfo.java b/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentLibraryInfo.java
index 71c2743..92323af 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentLibraryInfo.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentLibraryInfo.java
@@ -14,6 +14,7 @@
 package org.apache.tapestry5.services;
 
 import java.io.Serializable;
+import java.util.List;
 
 /**
  * Class that encapsulates information about a component library, going beyond what a library mapping
@@ -34,6 +35,8 @@ public final class ComponentLibraryInfo implements Serializable
     private String name, description, homepageUrl, documentationUrl, sourceBrowseUrl, issueTrackerUrl, sourceRootUrl, 
                    javadocUrl, groupId, artifactId, version;
     
+    private List<String> tags;
+    
     /**
      * Returns the actual name of the component library (not the identifier). 
      * For example, "Tapestry 5 Core Library".
@@ -137,7 +140,16 @@ public final class ComponentLibraryInfo implements Serializable
     {
         return version;
     }
-    
+
+    /**
+     * Returns the tags associated which describe this component library.
+     * Use just lowercase letters, numbers and dashes.
+     */
+    public List<String> getTags()
+    {
+        return tags;
+    }
+
     /**
      * Returns an URL decribing the dependency management information for this component library.
      */
@@ -219,6 +231,12 @@ public final class ComponentLibraryInfo implements Serializable
         this.issueTrackerUrl = issueTrackingUrl;
     }
 
+    public void setTags(List<String> tags)
+    {
+        if (this.tags != null) throwExceptionIfAlreadySet("tags", tags);
+        this.tags = tags;
+    }
+
     public void setLibraryMapping(LibraryMapping libraryMapping)
     {
         if (this.libraryMapping != null) throwExceptionIfAlreadySet("libraryMapping", libraryMapping);

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/aca075cb/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/pages/ComponentLibraries.tml
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/pages/ComponentLibraries.tml b/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/pages/ComponentLibraries.tml
index bfd5a39..acf3f31 100644
--- a/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/pages/ComponentLibraries.tml
+++ b/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/pages/ComponentLibraries.tml
@@ -11,6 +11,13 @@
     		<p t:type="If" t:test="info?.description">
     			${info.description}
     		</p>
+    		<p class="tags" t:type="If" t:test="!info?.tags.empty">
+    			Tags: 
+				<span t:type="Loop" t:source="info.tags" t:value="var:tag" class="badge" 
+					style="margin-right: 0.3em; font-size: 0.75em">
+					${var:tag}
+				</span>
+			</p>
     	</li>
     </ul>
 
@@ -106,6 +113,8 @@
 				<thead>
 					<tr>
 						<td>Name</td>
+						<td>Description</td>
+						<td>Tags</td>
 						<td>JavaDoc URL</td>
 						<td>Source URL</td>
 					</tr>
@@ -113,11 +122,24 @@
 				<tbody>
 					<tr t:type="Loop" t:source="logicalNames" t:value="logicalName">
 						<td><code>${simpleLogicalName}</code></td>
-						<td><t:if test="javadocUrl" else="message:not-informed" target="_blank">
-							<a href="${javadocUrl}">JavaDoc</a></t:if>
+						<td>${description?.text()}</td>
+						<td>
+							<ul t:type="If" t:test="classHasTags" style="padding: 0; margin: 0;">
+								<li t:type="Loop" t:source="tags" t:value="var:tag" 
+									style="display: inline; list-style-type: none; margin: 0; margin-right: 0.3em">
+										<span class="badge">${var:tag}</span>
+								</li>
+							</ul> 
 						</td>
-						<td><t:if test="sourceUrl" else="message:not-informed" target="_blank">
-							<a href="${sourceUrl}">Source</a></t:if>
+						<td>
+							<t:if test="javadocUrl" else="message:not-informed" target="_blank">
+								<a href="${javadocUrl}">JavaDoc</a>
+							</t:if>
+						</td>
+						<td>
+							<t:if test="sourceUrl" else="message:not-informed" target="_blank">
+								<a href="${sourceUrl}">Source</a>
+							</t:if>
 						</td>
 					</tr>
 				</tbody>

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/aca075cb/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/ComponentLibrariesCatalogPageTests.groovy
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/ComponentLibrariesCatalogPageTests.groovy b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/ComponentLibrariesCatalogPageTests.groovy
index ea68c7b..1a00cc7 100644
--- a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/ComponentLibrariesCatalogPageTests.groovy
+++ b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/ComponentLibrariesCatalogPageTests.groovy
@@ -21,6 +21,8 @@ class ComponentLibrariesCatalogPageTests extends TapestryCoreTestCase
         assertEquals getText("//ul[@id='libraryList']/li[1]/p"), "The set of components, pages and mixins provided by Tapestry out-of-the-box."
         assertEquals getText("//ul[@id='libraryList']/li[2]/a"), "lib/alpha"
         assertFalse isElementPresent("//ul[@id='libraryList']/li[2]/p")
+        assertEquals getText("//ul[@id='libraryList']/li[1]/p[@class='tags']"), "Tags: core out-of-the-box"
+        assertFalse isElementPresent("//ul[@id='libraryList']/li[2]/p[@class='tags']")
         
         // component library information
         
@@ -40,7 +42,15 @@ class ComponentLibrariesCatalogPageTests extends TapestryCoreTestCase
         
         // without ComponentLibraryInfo
         assertEquals "lib/alpha", getText("css=#lib-alpha h2")
-        assertEquals getText("css=#lib-alpha p.noInformation"), "No additional information provided for lib/alpha." 
+        assertEquals getText("css=#lib-alpha p.noInformation"), "No additional information provided for lib/alpha."
+        
+        // table row
+        assertEquals getText("//div[@id='lib-alpha']//table/tbody/tr[2]/td[1]"), "lib/alpha/Root"
+        assertEquals getText("//div[@id='lib-alpha']//table/tbody/tr[2]/td[2]"), "Alpha root page"
+        assertEquals getText("//div[@id='lib-alpha']//table/tbody/tr[2]/td[3]"), "alpha root page"
+        assertEquals getText("//div[@id='lib-alpha']//table/tbody/tr[2]/td[4]"), "Not informed"
+        assertEquals getText("//div[@id='lib-alpha']//table/tbody/tr[2]/td[5]"), "Not informed"
+        
 
     }
     

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/aca075cb/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/locallib/alpha/pages/Logo.groovy
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/locallib/alpha/pages/Logo.groovy b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/locallib/alpha/pages/Logo.groovy
index 9f4e9ba..c34a46d 100644
--- a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/locallib/alpha/pages/Logo.groovy
+++ b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/locallib/alpha/pages/Logo.groovy
@@ -3,6 +3,7 @@ package org.apache.tapestry5.integration.locallib.alpha.pages
 import org.apache.tapestry5.Asset
 import org.apache.tapestry5.annotations.Import
 import org.apache.tapestry5.annotations.Path
+import org.apache.tapestry5.ioc.annotations.Description;
 import org.apache.tapestry5.ioc.annotations.Inject
 
 @Import(library="show-logo.js")

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/aca075cb/tapestry-core/src/test/java/org/apache/tapestry5/integration/locallib/alpha/pages/AlphaRoot.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/locallib/alpha/pages/AlphaRoot.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/locallib/alpha/pages/AlphaRoot.java
index dd378da..ea64aea 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/locallib/alpha/pages/AlphaRoot.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/locallib/alpha/pages/AlphaRoot.java
@@ -1,8 +1,11 @@
 package org.apache.tapestry5.integration.locallib.alpha.pages;
 
+import org.apache.tapestry5.ioc.annotations.Description;
+
 /**
  *
  */
+@Description(text="Alpha root page", tags = {"alpha", "root", "page"})
 public class AlphaRoot
 {
 }

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/aca075cb/tapestry5-annotations/src/main/java/org/apache/tapestry5/ioc/annotations/Description.java
----------------------------------------------------------------------
diff --git a/tapestry5-annotations/src/main/java/org/apache/tapestry5/ioc/annotations/Description.java b/tapestry5-annotations/src/main/java/org/apache/tapestry5/ioc/annotations/Description.java
new file mode 100644
index 0000000..b951eda
--- /dev/null
+++ b/tapestry5-annotations/src/main/java/org/apache/tapestry5/ioc/annotations/Description.java
@@ -0,0 +1,46 @@
+// Copyright 2014 The Apache Software Foundation
+//
+// 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.apache.tapestry5.ioc.annotations;
+
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.ElementType.PACKAGE;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+
+import static org.apache.tapestry5.ioc.annotations.AnnotationUseContext.*;
+
+/**
+ * Annotation used by Tapestry to describe the annotated class or package in runtime, 
+ * specially in the T5Dashboard page.
+ */
+@Target({TYPE, PACKAGE})
+@Retention(RUNTIME)
+@Documented
+@UseWith({COMPONENT,MIXIN,PAGE,SERVICE})
+public @interface Description
+{
+    /**
+     * A textual description of this class.
+     */
+    String text();
+    
+    /**
+     * Tags used to describe this class. Use just lowercase letters, numbers and dashes.
+     */
+    String[] tags() default {};
+    
+}