Author: ltheussl Date: Tue Apr 19 09:30:13 2011 New Revision: 1094965 URL: http://svn.apache.org/viewvc?rev=1094965&view=rev Log: [DOXIA-418] Inject the Doxia version from the POM into AbstractXmlParser
Added: maven/doxia/doxia/trunk/doxia-core/src/main/resources/ maven/doxia/doxia/trunk/doxia-core/src/main/resources/build-info.properties Modified: maven/doxia/doxia/trunk/doxia-core/pom.xml maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractParser.java maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractXmlParser.java maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/parser/XhtmlBaseParserTest.java Modified: maven/doxia/doxia/trunk/doxia-core/pom.xml URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/pom.xml?rev=1094965&r1=1094964&r2=1094965&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-core/pom.xml (original) +++ maven/doxia/doxia/trunk/doxia-core/pom.xml Tue Apr 19 09:30:13 2011 @@ -71,6 +71,13 @@ under the License. </dependencies> <build> + <resources> + <resource> + <directory>${basedir}/src/main/resources/</directory> + <filtering>true</filtering> + </resource> + </resources> + <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> Modified: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractParser.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractParser.java?rev=1094965&r1=1094964&r2=1094965&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractParser.java (original) +++ maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractParser.java Tue Apr 19 09:30:13 2011 @@ -20,8 +20,12 @@ package org.apache.maven.doxia.parser; */ import java.io.File; +import java.io.IOException; +import java.io.InputStream; import java.io.StringReader; +import java.util.Properties; + import org.apache.maven.doxia.logging.Log; import org.apache.maven.doxia.logging.SystemStreamLog; import org.apache.maven.doxia.macro.Macro; @@ -52,6 +56,43 @@ public abstract class AbstractParser /** Log instance. */ private Log logger; + private static final String DOXIA_VERSION; + + static + { + final Properties props = new Properties(); + final InputStream is = AbstractParser.class.getResourceAsStream( "/build-info.properties" ); + + if ( is == null ) + { + props.setProperty( "version", "unknown" ); // should not happen + } + else + { + try + { + props.load( is ); + } + catch ( IOException ex ) + { + props.setProperty( "version", "unknown" ); // should not happen + } + finally + { + try + { + is.close(); + } + catch ( IOException ex ) + { + // oh well... + } + } + } + + DOXIA_VERSION = props.getProperty( "version" ); + } + /** {@inheritDoc} */ public int getType() { @@ -181,4 +222,16 @@ public abstract class AbstractParser { // nop } + + /** + * The current Doxia version. + * + * @return the current Doxia version as a String. + * + * @since 1.2 + */ + protected static String doxiaVersion() + { + return DOXIA_VERSION; + } } Modified: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractXmlParser.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractXmlParser.java?rev=1094965&r1=1094964&r2=1094965&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractXmlParser.java (original) +++ maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractXmlParser.java Tue Apr 19 09:30:13 2011 @@ -797,7 +797,7 @@ public abstract class AbstractXmlParser HttpGet method = new HttpGet( url.toString() ); // Set a user-agent that doesn't contain the word "java", otherwise it will be blocked by the W3C // The default user-agent is "Apache-HttpClient/4.0.2 (java 1.5)" - method.setHeader( "user-agent", "Apache-Doxia/1.1.4" ); + method.setHeader( "user-agent", "Apache-Doxia/" + doxiaVersion() ); HttpRequestRetryHandler retryHandler = new DefaultHttpRequestRetryHandler( 3, false ); client.setHttpRequestRetryHandler( retryHandler ); Added: maven/doxia/doxia/trunk/doxia-core/src/main/resources/build-info.properties URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/resources/build-info.properties?rev=1094965&view=auto ============================================================================== --- maven/doxia/doxia/trunk/doxia-core/src/main/resources/build-info.properties (added) +++ maven/doxia/doxia/trunk/doxia-core/src/main/resources/build-info.properties Tue Apr 19 09:30:13 2011 @@ -0,0 +1 @@ +version=@version@ Modified: maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/parser/XhtmlBaseParserTest.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/parser/XhtmlBaseParserTest.java?rev=1094965&r1=1094964&r2=1094965&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/parser/XhtmlBaseParserTest.java (original) +++ maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/parser/XhtmlBaseParserTest.java Tue Apr 19 09:30:13 2011 @@ -51,6 +51,12 @@ public class XhtmlBaseParserTest sink.reset(); } + public void testDoxiaVersion() + { + assertNotNull( XhtmlBaseParser.doxiaVersion() ); + assertFalse( "unknown".equals( XhtmlBaseParser.doxiaVersion() ) ); + } + /** @throws Exception */ public void testHeadingEventsList() throws Exception