Awesome stuff Jorge!

On Nov 26, 8:07 pm, "Jorge Ortiz" <[EMAIL PROTECTED]> wrote:
> Oops, it just test *.htm and *.xhtml files as well. Updated code below.
>
> --j
>
>   /**
>    * Tests to make sure the project's XML files are well-formed.
>    *
>    * Finds every *.html and *.xml file in src/main/webapp (and its
>    * subdirectories) and tests to make sure they are well-formed.
>    */
>   def testXml() = {
>     var failed: List[java.io.File] = Nil
>
>     def handled(file: String) =
>       file.endsWith(".html") || file.endsWith(".xml") ||
>       file.endsWith(".htm")  || file.endsWith(".xhtml")
>
>     def wellFormed(file: java.io.File) {
>       if (file.isDirectory)
>         for (f <- file.listFiles) wellFormed(f)
>
>       if (file.isFile && handled(file.getName)) {
>         try {
>           scala.xml.XML.loadFile(file)
>         } catch {
>           case e: org.xml.sax.SAXParseException => failed = file :: failed
>         }
>       }
>     }
>
>     wellFormed(new java.io.File("src/main/webapp"))
>
>     val numFails = failed.size
>     if (numFails > 0) {
>       val fileStr = if (numFails == 1) "file" else "files"
>       val msg = "Malformed XML in " + numFails + " " + fileStr + ": " +
> failed.mkString(", ")
>       println(msg)
>       fail(msg)
>     }
>   }
>
> On Wed, Nov 26, 2008 at 4:58 PM, Jorge Ortiz <[EMAIL PROTECTED]> wrote:
> > Folks,
>
> > One of the concerns raised at the Lift Workshop on Saturday was that
> > ill-formed XML files in your templates will fail at run time instead of
> > compile time, often with cryptic errors.
>
> > To correct for this, I've added a simple test to lift-archetype-basic and
> > lift-archetype-blank that will test all *.html and *.xml files in your
> > src/main/webapp directory (and its subdirectories) to make sure they can all
> > be loaded by Scala's XML parser. If they can't be loaded the test will fail
> > and notify you which files couldn't be loaded and why.
>
> > These tests run during Maven's 'test' phase. This phase is required before
> > the 'package', 'install', or 'deploy' phases can run. Unfortunately, the
> > 'jetty:run' phase only requires 'test-compile', not 'test'. If you want the
> > test to run before starting Jetty, you'll have to specify it manually: 'mvn
> > test jetty:run' (or 'mvn install jetty:run', etc).
>
> > The test is available on any new projects created with Lift's archetypes.
> > To add the test to your own project, the code is included below. It's a
> > simple JUnit test. If you used a previous version of the archetypes to start
> > your project, you can throw it into AppTest.scala
>
> > Enjoy,
>
> > --j
>
> >   /**
> >    * Tests to make sure the project's XML files are well-formed.
> >    *
> >    * Finds every *.html and *.xml file in src/main/webapp (and its
> >    * subdirectories) and tests to make sure they are well-formed.
> >    */
> >   def testXml() = {
> >     var failed: List[java.io.File] = Nil
>
> >     def wellFormed(file: java.io.File) {
> >       if (file.isDirectory)
> >         for (f <- file.listFiles) wellFormed(f)
>
> >       if (file.isFile && (file.getName.endsWith(".html") ||
> > file.getName.endsWith(".xml"))) {
> >         try {
> >           scala.xml.XML.loadFile(file)
> >         } catch {
> >           case e: org.xml.sax.SAXParseException => failed = file :: failed
> >         }
> >       }
> >     }
>
> >     wellFormed(new java.io.File("src/main/webapp"))
>
> >     val numFails = failed.size
> >     if (numFails > 0) {
> >       val fileStr = if (numFails == 1) "file" else "files"
> >       val msg = "Malformed XML in " + numFails + " " + fileStr + ": " +
> > failed.mkString(", ")
> >       println(msg)
> >       fail(msg)
> >     }
> >   }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to