Author: vsiveton Date: Sat May 16 13:54:32 2009 New Revision: 775465 URL: http://svn.apache.org/viewvc?rev=775465&view=rev Log: o improved properties filtering o update test case o added doc
Added: maven/plugins/trunk/maven-pdf-plugin/src/site/apt/examples/ maven/plugins/trunk/maven-pdf-plugin/src/site/apt/examples/filtering.apt (with props) Modified: maven/plugins/trunk/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java maven/plugins/trunk/maven-pdf-plugin/src/site/apt/index.apt maven/plugins/trunk/maven-pdf-plugin/src/site/site.xml maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/PdfMojoTest.java maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/DefaultMavenProjectStub.java maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/pom_filtering.xml maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/src/site/pdf_filtering.xml Modified: maven/plugins/trunk/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java?rev=775465&r1=775464&r2=775465&view=diff ============================================================================== --- maven/plugins/trunk/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java (original) +++ maven/plugins/trunk/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java Sat May 16 13:54:32 2009 @@ -53,9 +53,14 @@ import org.apache.maven.plugin.logging.Log; import org.apache.maven.project.MavenProject; import org.apache.maven.wagon.PathUtils; +import org.codehaus.plexus.interpolation.EnvarBasedValueSource; +import org.codehaus.plexus.interpolation.InterpolationException; +import org.codehaus.plexus.interpolation.Interpolator; +import org.codehaus.plexus.interpolation.MapBasedValueSource; +import org.codehaus.plexus.interpolation.ObjectBasedValueSource; +import org.codehaus.plexus.interpolation.RegexBasedInterpolator; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; -import org.codehaus.plexus.util.InterpolationFilterReader; import org.codehaus.plexus.util.ReaderFactory; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.WriterFactory; @@ -404,7 +409,7 @@ siteDescriptorContent = getSiteTool().getInterpolatedSiteDescriptorContent( props, project, siteDescriptorContent, - reader.getEncoding(), "UTF-8" ); + reader.getEncoding(), reader.getEncoding() ); decoration = new DecorationXpp3Reader().read( new StringReader( siteDescriptorContent ) ); } @@ -442,68 +447,66 @@ * @throws DocumentRendererException if any * @throws IOException if any */ - private static DocumentModel readAndFilterDocumentDescriptor( MavenProject project, File docDescriptor, Log log ) + private DocumentModel readAndFilterDocumentDescriptor( final MavenProject project, File docDescriptor, Log log ) throws DocumentRendererException, IOException { Reader reader = null; try { // System properties - Properties filterProperties = new Properties( System.getProperties() ); + Properties filterProperties = System.getProperties(); // Project properties if ( project != null && project.getProperties() != null ) { filterProperties.putAll( project.getProperties() ); } - reader = - new InterpolationFilterReader( ReaderFactory.newXmlReader( docDescriptor ), filterProperties, - "${", "}" ); - reader = new InterpolationFilterReader( reader, new ReflectionProperties( project, log ), "${", "}" ); + Interpolator interpolator = new RegexBasedInterpolator(); + interpolator.addValueSource( new MapBasedValueSource( filterProperties ) ); + interpolator.addValueSource( new EnvarBasedValueSource() ); + interpolator.addValueSource( new ObjectBasedValueSource( project ) + { + /** {...@inheritdoc} */ + public Object getValue( String expression ) + { + try + { + return ReflectionValueExtractor.evaluate( expression, project ); + } + catch ( Exception e ) + { + addFeedback( "Failed to extract \'" + expression + "\' from: " + project, e ); + } + + return null; + } + } ); - return new DocumentXpp3Reader().read( reader ); + reader = ReaderFactory.newXmlReader( docDescriptor ); + + String interpolatedDoc = interpolator.interpolate( IOUtil.toString( reader ) ); + + if ( getLog().isDebugEnabled() ) + { + getLog().debug( + "Interpolated document descriptor (" + docDescriptor.getAbsolutePath() + ")\n" + + interpolatedDoc ); + } + + // No Strict + return new DocumentXpp3Reader().read( new StringReader( interpolatedDoc ), false ); } catch ( XmlPullParserException e ) { throw new DocumentRendererException( "Error parsing document descriptor", e ); } - finally + catch ( InterpolationException e ) { - IOUtil.close( reader ); + throw new DocumentRendererException( "Error interpolating document descriptor", e ); } - } - - static class ReflectionProperties - extends Properties - { - private static final long serialVersionUID = 4283750804305363781L; - - private MavenProject project; - - private Log log; - - public ReflectionProperties( MavenProject aProject, Log aLog ) - { - super(); - - this.project = aProject; - this.log = aLog; - } - - /** {...@inheritdoc} */ - public Object get( Object key ) + finally { - Object value = null; - try - { - value = ReflectionValueExtractor.evaluate( key.toString(), project ); - } - catch ( Exception e ) - { - log.error( e.getMessage(), e ); - } - - return value; + IOUtil.close( reader ); } } } Added: maven/plugins/trunk/maven-pdf-plugin/src/site/apt/examples/filtering.apt URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/src/site/apt/examples/filtering.apt?rev=775465&view=auto ============================================================================== --- maven/plugins/trunk/maven-pdf-plugin/src/site/apt/examples/filtering.apt (added) +++ maven/plugins/trunk/maven-pdf-plugin/src/site/apt/examples/filtering.apt Sat May 16 13:54:32 2009 @@ -0,0 +1,72 @@ + ------ + Filtering Document Descriptor + ------ + Vincent Siveton + ------ + 2009-05-16 + ------ + +~~ 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. + +~~ NOTE: For help with the syntax of this file, see: +~~ http://maven.apache.org/doxia/references/apt-format.html + +Filtering Document Descriptor + + The document descriptor (aka src/site/pdf.xml) could be filtered by System properties or POM properties. + + For instance, if you have defined the following pom.xml and pdf.xml: + ++-----+ +<project> + <modelVersion>4.0.0</modelVersion> + + <version>1.0-SNAPSHOT</version> + <name>Your project</name> + + ... + + <developers> + <developer> + <email>y...@email.com</email> + ... + </developer> + </developers> + + ... +</project> ++-----+ + ++-----+ +<document xmlns="http://maven.apache.org/DOCUMENT/1.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/DOCUMENT/1.0.0 http://maven.apache.org/xsd/document-1.0.0.xsd" + outputName="maven-pdf-plugin-doc-${project.version}"> + + <meta> + <title>User guide of ${project.name} version ${project.version}</title> + <author>${project.developers[0].email}</author> + </meta> + + <toc name="Table of Contents"> + ... + </toc> +</document> ++-----+ + + The title will be <<<User guide of Your project version 1.0-SNAPSHOT>>> and the author will be <<<y...@email.com>>>. Propchange: maven/plugins/trunk/maven-pdf-plugin/src/site/apt/examples/filtering.apt ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-pdf-plugin/src/site/apt/examples/filtering.apt ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Modified: maven/plugins/trunk/maven-pdf-plugin/src/site/apt/index.apt URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/src/site/apt/index.apt?rev=775465&r1=775464&r2=775465&view=diff ============================================================================== --- maven/plugins/trunk/maven-pdf-plugin/src/site/apt/index.apt (original) +++ maven/plugins/trunk/maven-pdf-plugin/src/site/apt/index.apt Sat May 16 13:54:32 2009 @@ -45,4 +45,10 @@ * Example - Have a look at the {{{./maven-pdf-plugin.pdf}pdf}} version of this web site. \ No newline at end of file + Have a look at the {{{./maven-pdf-plugin.pdf}pdf}} version of this web site. + + The following examples show how to use the PDF Plugin in more advanced usecases: + + * {{{examples/filtering.html}Filtering Document Descriptor}} + + [] Modified: maven/plugins/trunk/maven-pdf-plugin/src/site/site.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/src/site/site.xml?rev=775465&r1=775464&r2=775465&view=diff ============================================================================== --- maven/plugins/trunk/maven-pdf-plugin/src/site/site.xml (original) +++ maven/plugins/trunk/maven-pdf-plugin/src/site/site.xml Sat May 16 13:54:32 2009 @@ -21,7 +21,10 @@ */ --> -<project name="Maven PDF plugin"> +<project xmlns="http://maven.apache.org/DECORATION/1.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/DECORATION/1.0.0 http://maven.apache.org/xsd/decoration-1.0.0.xsd" + name="Maven PDF plugin"> <body> @@ -33,5 +36,8 @@ <item name="FAQ" href="faq.html"/> </menu> + <menu name="Examples"> + <item name="Filtering Document Descriptor" href="/examples/filtering.html"/> + </menu> </body> </project> Modified: maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/PdfMojoTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/PdfMojoTest.java?rev=775465&r1=775464&r2=775465&view=diff ============================================================================== --- maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/PdfMojoTest.java (original) +++ maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/PdfMojoTest.java Sat May 16 13:54:32 2009 @@ -22,6 +22,8 @@ import org.apache.maven.plugin.testing.AbstractMojoTestCase; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.ReaderFactory; +import org.codehaus.plexus.util.StringUtils; +import org.codehaus.plexus.util.cli.CommandLineUtils; import java.io.File; import java.io.Reader; @@ -127,7 +129,17 @@ { IOUtil.close( reader ); } - assertTrue( foContent.indexOf( ">Test filtering<" ) > 0 ); + // ${pom.name} + assertTrue( foContent.indexOf( "Test filtering" ) > 0 ); + assertTrue( foContent.indexOf( "1.0-SNAPSHOT" ) > 0 ); + // env ${M2_HOME} + String m2Home = CommandLineUtils.getSystemEnvVars().getProperty( "M2_HOME" ); + if ( StringUtils.isNotEmpty( m2Home ) ) + { + assertTrue( foContent.indexOf( m2Home ) > 0 ); + } + // ${project.developers[0].email} + assertTrue( foContent.indexOf( "vsive...@apache.org ltheu...@apache.org" ) > 0 ); } } \ No newline at end of file Modified: maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/DefaultMavenProjectStub.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/DefaultMavenProjectStub.java?rev=775465&r1=775464&r2=775465&view=diff ============================================================================== --- maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/DefaultMavenProjectStub.java (original) +++ maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/DefaultMavenProjectStub.java Sat May 16 13:54:32 2009 @@ -21,6 +21,8 @@ import java.io.File; import java.io.FileReader; +import java.util.List; +import java.util.Properties; import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; @@ -64,4 +66,16 @@ { return new File( super.getBasedir() + "/target/test-classes/unit/pdf/" ); } + + /** {...@inheritdoc} */ + public List getDevelopers() + { + return getModel().getDevelopers(); + } + + /** {...@inheritdoc} */ + public Properties getProperties() + { + return getModel().getProperties(); + } } Modified: maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/pom_filtering.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/pom_filtering.xml?rev=775465&r1=775464&r2=775465&view=diff ============================================================================== --- maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/pom_filtering.xml (original) +++ maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/pom_filtering.xml Sat May 16 13:54:32 2009 @@ -25,6 +25,29 @@ <version>1.0-SNAPSHOT</version> <name>Test filtering</name> + <developers> + <developer> + <id>vsiveton</id> + <name>Vincent Siveton</name> + <email>vsive...@apache.org</email> + <organization>Apache Software Foundation</organization> + <roles> + <role>Java Developer</role> + </roles> + <timezone>-5</timezone> + </developer> + <developer> + <id>ltheussl</id> + <name>Lukas Theussl</name> + <email>ltheu...@apache.org</email> + <organization>Apache Software Foundation</organization> + <roles> + <role>Java Developer</role> + </roles> + <timezone>+1</timezone> + </developer> + </developers> + <build> <plugins> <plugin> @@ -39,4 +62,8 @@ </plugin> </plugins> </build> + + <properties> + <pdf.language>en</pdf.language> + </properties> </project> Modified: maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/src/site/pdf_filtering.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/src/site/pdf_filtering.xml?rev=775465&r1=775464&r2=775465&view=diff ============================================================================== --- maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/src/site/pdf_filtering.xml (original) +++ maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/src/site/pdf_filtering.xml Sat May 16 13:54:32 2009 @@ -21,11 +21,14 @@ */ --> -<document outputName="maven-pdf-plugin-doc-${project.version}"> +<document xmlns="http://maven.apache.org/DOCUMENT/1.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/DOCUMENT/1.0.0 http://maven.apache.org/xsd/document-1.0.0.xsd" + outputName="maven-pdf-plugin-doc-${project.version}"> <meta> - <title>${project.name}</title> - <author>The Apache Maven Project</author> + <title>User guide in ${pdf.language} of ${pom.name} version ${pom.version} for ${M2_HOME}</title> + <author>${project.developers[0].email} ${project.developers[1].email}</author> </meta> <toc name="Table of Contents"> @@ -35,5 +38,4 @@ <item name="Links" ref="ref/links.apt"/> <item name="FAQ" ref="faq.fml"/> </toc> - </document>