You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2007/10/13 23:39:01 UTC

svn commit: r584456 - in /tapestry/tapestry5/trunk: support/ tapestry-core/src/main/java/org/apache/tapestry/internal/services/ tapestry-core/src/main/resources/org/apache/tapestry/internal/services/ tapestry-core/src/test/app1/ tapestry-core/src/test/...

Author: hlship
Date: Sat Oct 13 14:39:00 2007
New Revision: 584456

URL: http://svn.apache.org/viewvc?rev=584456&view=rev
Log:
TAPESTRY-1345: Exception generated when a page does not have a template is confusing: "No root element has been defined."

Added:
    tapestry/tapestry5/trunk/support/prepsvn   (with props)
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/MissingTemplate.java
Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/PageMarkupRendererImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ServicesMessages.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties
    tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java

Added: tapestry/tapestry5/trunk/support/prepsvn
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/support/prepsvn?rev=584456&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/support/prepsvn (added)
+++ tapestry/tapestry5/trunk/support/prepsvn Sat Oct 13 14:39:00 2007
@@ -0,0 +1,172 @@
+#!/usr/bin/ruby
+
+# Used to prepare a directory for commit to Subversion. This is necessary for certain file types on Mac OS X because what appear to be files in the Finder
+# are actually directories (Mac uses the term "bundle" for this concept). It is useless to put the .svn folder inside such a directory, because it will
+# tend to be deleted whenever the "file" is saved.  
+#
+# Instead, we want to compress the directory to a single archive file; the bundle will be marked as svn:ignore.
+#
+# We use tar with Bzip2 compression, which is resource intensive to create, but compresses much better than GZip or PKZip.
+#
+# The trick is that we only want to create the archive version when necessary; when the archive does not exist, or when any file
+# in the bundle is newer than the archive.
+
+require 'optparse'
+
+# Set via command line options
+
+$extensions = %w{pages key oo3 graffle}
+$recursive = true
+$dry_run = false
+
+# Queue of folders to search (for bundles)
+
+$queue = []
+
+def matching_extension(name)
+  dotx = name.rindex('.')
+  
+  return false unless dotx
+  
+  ext = name[dotx + 1 .. -1]
+  
+  return $extensions.include?(ext)
+end
+
+
+# Iterate over the directory, identify bundles that may need to be compressed and (if recursive) subdirectories
+# to search.
+#
+# path: string path for a directory
+def search_directory(dirpath)
+  
+  Dir.foreach(dirpath) do |name|
+    
+    # Skip hidden files and directories
+    next if name[0..0] == "."
+    
+    path = File.join(dirpath, name)
+        
+    next unless File.directory?(path)
+                  
+    if matching_extension(name)
+      update_archive path
+      next
+    end
+    
+    if $recursive
+      $queue << path
+    end
+    
+  end
+  
+end
+
+
+def needs_update(bundle_path, archive_path)
+  
+  return true unless File.exists?(archive_path)
+  
+  archive_mtime = File.mtime(archive_path)
+  
+  # The archive exists ... can we find a file inside the bundle thats newer?
+  # This won't catch deletions, but that's ok.  Bundles tend to get completly
+  # overwritten when any tiny thing changes.
+  
+  dirqueue = [bundle_path]
+
+  until dirqueue.empty?
+    
+    dirpath = dirqueue.pop
+    
+    Dir.foreach(dirpath) do |name|
+      
+      path = File.join(dirpath, name)
+      
+      if File.directory?(path)
+        dirqueue << path unless [".", ".."].include?(name)
+        next
+      end
+      
+      # Is this file newer?
+      
+      if File.mtime(path) > archive_mtime
+        return true
+      end
+      
+    end
+    
+  end
+  
+  return false
+end
+
+def update_archive(path)
+  archive = path + ".tar.bz2"
+  
+  return unless needs_update(path, archive)
+
+  if $dry_run
+    puts "Would create #{archive}"
+    return
+  end
+
+  puts "Creating #{archive}"
+    
+  dir = File.dirname(path)
+  bundle = File.basename(path)
+    
+  # Could probably fork and do it in a subshell
+  system "tar --create --file=#{archive} --bzip2 --directory=#{dir} #{bundle}"
+
+end
+
+$opts = OptionParser.new do |opts|
+  
+  opts.banner = "Usage: prepsvn [options]"
+
+  opts.on("-d", "--dir DIR", "Add directory to search (if no directory specify, current directory is searched)") do |value|
+    $queue << value
+  end
+
+  opts.on("-e", "--extension EXTENSION", "Add another extension to match when searching for bundles to archive") do |value|
+    $extensions << value
+  end
+  
+  opts.on("-N", "--non-recursive", "Do not search non-bundle sub directories for files to archive") do
+    $recursive = false
+  end
+  
+  opts.on("-D", "--dry-run", "Identify what archives would be created") do
+    $dry_run = true
+  end
+  
+  opts.on("-h", "--help", "Help for this command") do
+    puts opts
+    exit
+  end
+end
+
+def fail(message)
+    puts "Error: #{message}"
+    puts $opts
+end
+
+begin
+    $opts.parse!
+rescue OptionParser::InvalidOption
+    fail $!
+end
+
+# If no --dir specified, use the current directory.
+
+if $queue.empty?
+  $queue << Dir.getwd
+end
+
+until $queue.empty? 
+  search_directory $queue.pop
+end
+
+
+

Propchange: tapestry/tapestry5/trunk/support/prepsvn
------------------------------------------------------------------------------
    svn:executable = *

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/PageMarkupRendererImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/PageMarkupRendererImpl.java?rev=584456&r1=584455&r2=584456&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/PageMarkupRendererImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/PageMarkupRendererImpl.java Sat Oct 13 14:39:00 2007
@@ -40,6 +40,9 @@
         queue.run(writer);
 
         _pageRenderInitializer.cleanup(writer);
+
+        if (writer.getDocument().getRootElement() == null)
+            throw new RuntimeException(ServicesMessages.noMarkupFromPageRender(page));
     }
 
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ServicesMessages.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ServicesMessages.java?rev=584456&r1=584455&r2=584456&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ServicesMessages.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ServicesMessages.java Sat Oct 13 14:39:00 2007
@@ -413,4 +413,9 @@
     {
         return MESSAGES.format("resource-access-forbidden", URI);
     }
+
+    static String noMarkupFromPageRender(org.apache.tapestry.internal.structure.Page page)
+    {
+        return MESSAGES.format("no-markup-from-page-render", page.getLogicalName());
+    }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties?rev=584456&r1=584455&r2=584456&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties Sat Oct 13 14:39:00 2007
@@ -83,4 +83,6 @@
 missing-validator-constraint=Validator '%s' requires a validation constraint (of type %s) but none was provided.
 startup-failure=An exception occurred during startup: %s
 resource-access-forbidden=URI %s may not be accessed remotely.
+no-markup-from-page-render=Page %s did not generate any markup when rendered. This could be because its template file could not be located, or because a \
+  render phase method in the page prevented rendering.
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml?rev=584456&r1=584455&r2=584456&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml Sat Oct 13 14:39:00 2007
@@ -109,6 +109,9 @@
             </a>
             -- Loops and Submit inside Form, volatile mode
           </li>
+          <li>
+<t:pagelink page="MissingTemplate">Missing Template Demo</t:pagelink> -- Demo for what happens when a template is not found for a page.
+</li>
         </ul>
       </td>
       <td>

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java?rev=584456&r1=584455&r2=584456&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java Sat Oct 13 14:39:00 2007
@@ -1112,4 +1112,12 @@
         assertFieldValueSeries("title_%d", 0, "Cure Cancer", "Pay Phone Bill");
         assertFieldValueSeries("urgency_%d", 0, "HIGH", "LOW");
     }
+
+    @Test
+    public void missing_template_for_page()
+    {
+        start("Missing Template Demo");
+
+        assertTextPresent("Page MissingTemplate did not generate any markup when rendered. This could be because its template file could not be located, or because a render phase method in the page prevented rendering.");
+    }
 }

Added: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/MissingTemplate.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/MissingTemplate.java?rev=584456&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/MissingTemplate.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/MissingTemplate.java Sat Oct 13 14:39:00 2007
@@ -0,0 +1,21 @@
+// Copyright 2007 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.tapestry.integration.app1.pages;
+
+/** A page that simple doesn't have a template. */
+public class MissingTemplate
+{
+
+}