HTTPCLIENT-664: First take at version detection based on build-time properties

git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@552347 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2007-07-01 17:55:46 +00:00
parent 2dbe8c3557
commit 545f1c40eb
4 changed files with 93 additions and 4 deletions

View File

@ -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>

View File

@ -0,0 +1,74 @@
package org.apache.http.client;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class VersionInfo {
private static final String RESOURCE = "org/apache/http/client/version.properties";
private static final String REV = "$Revision$";
private static Properties RELEASE_PROPERTIES;
private static String RELEASE_VERSION;
private static Long REV_VERSION;
private static Properties getReleaseProperties() {
if (RELEASE_PROPERTIES == null) {
try {
ClassLoader cl = VersionInfo.class.getClassLoader();
InputStream instream = cl.getResourceAsStream(RESOURCE);
try {
Properties props = new Properties();
props.load(instream);
RELEASE_PROPERTIES = props;
} finally {
instream.close();
}
} catch (IOException ex) {
// shamelessly munch this exception
}
if (RELEASE_PROPERTIES == null) {
// Create dummy properties instance
RELEASE_PROPERTIES = new Properties();
}
}
return RELEASE_PROPERTIES;
}
public static String getReleaseVersion() {
if (RELEASE_VERSION == null) {
Properties props = getReleaseProperties();
RELEASE_VERSION = (String) props.get("httpclient.release");
if (RELEASE_VERSION == null
|| RELEASE_VERSION.length() == 0
|| RELEASE_VERSION.equals("${pom.version}")) {
RELEASE_VERSION = "UNKNOWN_SNAPSHOT";
}
}
return RELEASE_VERSION;
}
public static long getRevision() {
if (REV_VERSION == null) {
Pattern p = Pattern.compile("\\$Revision: (\\d*) \\$");
Matcher m = p.matcher(REV);
if (m.matches()) {
String s = m.group(1);
try {
REV_VERSION = new Long(Long.parseLong(s));
} catch (NumberFormatException ex) {
// shamelessly munch this exception
}
}
if (REV_VERSION == null) {
REV_VERSION = new Long(-1);
}
}
return REV_VERSION.intValue();
}
}

View File

@ -42,6 +42,7 @@ import org.apache.http.client.HttpRequestRetryHandler;
import org.apache.http.client.HttpState;
import org.apache.http.client.RedirectHandler;
import org.apache.http.client.RoutedRequest;
import org.apache.http.client.VersionInfo;
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 @@ public class DefaultHttpClient extends AbstractHttpClient {
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/" + VersionInfo.getReleaseVersion() + " (java 1.4)");
HttpProtocolParams.setUseExpectContinue(params,
true);
return params;
}

View File

@ -0,0 +1 @@
httpclient.release=${pom.version}