Roland et al

There is my first stab at version detection based on build-time
properties. Maven will happily filter resource files and replace
property placeholders with their corresponding build-time values. I am
not sure the same can be done for source files. So, the downside of this
approach is that the resource file containing the version needs to be
loaded through a class loader. Oh well. I am not sure this will pass the
scrutiny of the Holy API Inquisition but I'll try ;-)

Cheers

Oleg
Index: /home/oleg/src/apache.org/jakarta/httpcomponents/httpclient/module-client/pom.xml
===================================================================
--- /home/oleg/src/apache.org/jakarta/httpcomponents/httpclient/module-client/pom.xml	(revision 552157)
+++ /home/oleg/src/apache.org/jakarta/httpcomponents/httpclient/module-client/pom.xml	(working copy)
@@ -91,6 +91,15 @@
   </properties>
 
   <build>
+    <resources>
+      <resource>
+        <directory>src/main/resources</directory>
+        <filtering>true</filtering>
+        <includes>
+            <include>*.version</include>
+        </includes>
+      </resource>
+    </resources>
     <plugins>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
Index: /home/oleg/src/apache.org/jakarta/httpcomponents/httpclient/module-client/src/main/java/org/apache/http/client/Version.java
===================================================================
--- /home/oleg/src/apache.org/jakarta/httpcomponents/httpclient/module-client/src/main/java/org/apache/http/client/Version.java	(revision 0)
+++ /home/oleg/src/apache.org/jakarta/httpcomponents/httpclient/module-client/src/main/java/org/apache/http/client/Version.java	(revision 0)
@@ -0,0 +1,40 @@
+package org.apache.http.client;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.http.protocol.HTTP;
+import org.apache.http.util.ByteArrayBuffer;
+
+public class Version {
+
+    private static final String RESOURCE = "httpclient.version";
+    private static String VERSION;
+    
+    public static String getVersion() {
+        if (VERSION == null) {
+            try {
+                ClassLoader cl = Version.class.getClassLoader();
+                InputStream instream = cl.getResourceAsStream(RESOURCE);
+                try {
+                    ByteArrayBuffer buffer = new ByteArrayBuffer(32);
+                    byte[] tmp = new byte[1024];
+                    int l;
+                    while ((l = instream.read(tmp)) != -1) {
+                        buffer.append(tmp, 0, l);
+                    }
+                    VERSION = (new String(buffer.toByteArray(), HTTP.ASCII)).trim();
+                } finally {
+                    instream.close();
+                }
+            } catch (IOException ex) {
+                // shamelessly munch this exception
+            }
+            if (VERSION == null || VERSION.length() == 0 || VERSION.equals("${pom.version}")) {
+                VERSION = "UNKNOWN_SNAPSHOT";
+            }
+        }
+        return VERSION;
+    }
+    
+}

Property changes on: /home/oleg/src/apache.org/jakarta/httpcomponents/httpclient/module-client/src/main/java/org/apache/http/client/Version.java
___________________________________________________________________
Name: svn:eol-style
   + native
Name: svn:keywords
   + Date Author Id Revision HeadURL
Name: svn:mime-type
   + text/plain

Index: /home/oleg/src/apache.org/jakarta/httpcomponents/httpclient/module-client/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java
===================================================================
--- /home/oleg/src/apache.org/jakarta/httpcomponents/httpclient/module-client/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java	(revision 552268)
+++ /home/oleg/src/apache.org/jakarta/httpcomponents/httpclient/module-client/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java	(working copy)
@@ -42,6 +42,7 @@
 import org.apache.http.client.HttpState;
 import org.apache.http.client.RedirectHandler;
 import org.apache.http.client.RoutedRequest;
+import org.apache.http.client.Version;
 import org.apache.http.client.params.AuthPolicy;
 import org.apache.http.client.params.CookiePolicy;
 import org.apache.http.client.params.HttpClientParams;
@@ -121,10 +122,14 @@
     
     protected HttpParams createHttpParams() {
         HttpParams params = new BasicHttpParams();
-        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
-        HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET);
-        HttpProtocolParams.setUserAgent(params, "Apache-HttpClient/4.0");
-        HttpProtocolParams.setUseExpectContinue(params, true);
+        HttpProtocolParams.setVersion(params, 
+                HttpVersion.HTTP_1_1);
+        HttpProtocolParams.setContentCharset(params, 
+                HTTP.DEFAULT_CONTENT_CHARSET);
+        HttpProtocolParams.setUserAgent(params, 
+                "Apache-HttpClient/" + Version.getVersion() + " (java 1.4)");
+        HttpProtocolParams.setUseExpectContinue(params, 
+                true);
         return params;
     }
 
Index: /home/oleg/src/apache.org/jakarta/httpcomponents/httpclient/module-client/src/main/resources/httpclient.version
===================================================================
--- /home/oleg/src/apache.org/jakarta/httpcomponents/httpclient/module-client/src/main/resources/httpclient.version	(revision 0)
+++ /home/oleg/src/apache.org/jakarta/httpcomponents/httpclient/module-client/src/main/resources/httpclient.version	(revision 0)
@@ -0,0 +1 @@
+${pom.version}
\ No newline at end of file

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to