10000 [Issue 75] Solve commons-codec conflict on Android · robccan/google-http-java-client@f4e544d · GitHub
[go: up one dir, main page]

Skip to content

Commit f4e544d

Browse files
author
Yaniv Inbar
committed
[Issue 75] Solve commons-codec conflict on Android
http://codereview.appspot.com/5844050/
1 parent 75e9d4d commit f4e544d

19 files changed

+247
-921
lines changed

google-http-client/pom.xml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,35 @@
8080
</execution>
8181
</executions>
8282
</plugin>
83+
<!-- Use jarjar to include a private copy of Apache Commons Codec library
84+
to avoid a runtime dependency conflict with Android which includes
85+
an older version of that library -->
86+
<plugin>
87+
<groupId>org.sonatype.plugins</groupId>
88+
<artifactId>jarjar-maven-plugin</artifactId>
89+
<executions>
90+
<execution>
91+
<phase>package</phase>
92+
<goals>
93+
<goal>jarjar</goal>
94+
</goals>
95+
<configuration>
96+
<includes>
97+
<include>commons-codec:commons-codec</include>
98+
</includes>
99+
<rules>
100+
<rule>
101+
<pattern>org.apache.commons.codec.**</pattern>
102+
<result>com.google.api.client.repackaged.org.apache.commons.codec.@1</result>
103+
</rule>
104+
<keep>
105+
<pattern>com.google.api.client.**</pattern>
106+
</keep>
107+
</rules>
108+
</configuration>
109+
</execution>
110+
</executions>
111+
</plugin>
83112
</plugins>
84113
<pluginManagement>
85114
<plugins>
@@ -130,6 +159,7 @@
130159
<groupId>com.google.android</groupId>
131160
<artifactId>android</artifactId>
132161
<version>1.5_r4</version>
162+
<scope>provided</scope>
133163
</dependency>
134164
<dependency>
135165
<groupId>com.google.code.findbugs</groupId>
@@ -166,6 +196,7 @@
166196
<dependency>
167197
<groupId>commons-codec</groupId>
168198
<artifactId>commons-codec</artifactId>
199+
<scope>provided</scope>
169200
</dependency>
170201
</dependencies>
171202
</project>

google-http-client/src/main/java/com/google/api/client/http/ByteArrayContent.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414

1515
package com.google.api.client.http;
1616

17+
import com.google.api.client.util.StringUtils;
1718
import com.google.common.base.Preconditions;
1819

19-
import org.apache.commons.codec.binary.StringUtils;
20-
2120
import java.io.ByteArrayInputStream;
2221
import java.io.InputStream;
2322

@@ -85,8 +84,8 @@ public ByteArrayContent(String type, byte[] array, int offset, int length) {
8584
}
8685

8786
/**
88-
* Returns a new instance with the UTF-8 encoding (using {@code Strings.toBytesUtf8()}) of the
89-
* given content string.
87+
* Returns a new instance with the UTF-8 encoding (using {@link StringUtils#getBytesUtf8(String)})
88+
* of the given content string.
9089
* <p>
9190
* Sample use:
9291
* </p>

google-http-client/src/main/java/com/google/api/client/http/HttpHeaders.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@
1414

1515
package com.google.api.client.http;
1616

17+
import com.google.api.client.util.Base64;
1718
import com.google.api.client.util.ClassInfo;
1819
import com.google.api.client.util.GenericData;
1920
import com.google.api.client.util.Key;
21+
import com.google.api.client.util.StringUtils;
2022
import com.google.common.base.Preconditions;
2123

22-
import org.apache.commons.codec.binary.Base64;
23-
import org.apache.commons.codec.binary.StringUtils;
24-
2524
import java.util.HashMap;
2625

2726
/**

google-http-client/src/main/java/com/google/api/client/http/HttpRequest.java

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import com.google.api.client.util.Data;
1818
import com.google.api.client.util.FieldInfo;
19-
import com.google.api.client.util.Strings;
19+
import com.google.api.client.util.StringUtils;
2020
import com.google.api.client.util.Types;
2121
import com.google.common.base.Preconditions;
2222

@@ -39,6 +39,14 @@
3939
*/
4040
public final class HttpRequest {
4141

42+
/**
43+
* Current version of the Google API Client Library for Java.
44+
*
45+
* @since 1.8
46+
*/
47+
@SuppressWarnings("deprecation")
48+
public static final String VERSION = com.google.api.client.util.Strings.VERSION;
49+
4250
/**
4351
* User agent suffix for all requests.
4452
*
@@ -49,8 +57,7 @@ public final class HttpRequest {
4957
*
5058
* @since 1.4
5159
*/
52-
public static final String USER_AGENT_SUFFIX = "Google-HTTP-Java-Client/" + Strings.VERSION
53-
+ " (gzip)";
60+
public static final String USER_AGENT_SUFFIX = "Google-HTTP-Java-Client/" + VERSION + " (gzip)";
5461

5562
/**
5663
* HTTP request execute interceptor to intercept the start of {@link #execute()} (before executing
@@ -369,8 +376,8 @@ public HttpRequest setDisableContentLogging(boolean disableContentLogging) {
369376
* @since 1.7
370377
*/
371378
public HttpRequest setContentLoggingLimit(int contentLoggingLimit) {
372-
Preconditions.checkArgument(contentLoggingLimit >= 0,
373-
"The content logging limit must be non-negative.");
379+
Preconditions.checkArgument(
380+
contentLoggingLimit >= 0, "The content logging limit must be non-negative.");
374381
this.contentLoggingLimit = contentLoggingLimit;
375382
return this;
376383
}
@@ -704,13 +711,13 @@ public HttpResponse execute() throws IOException {
704711
lowLevelHttpRequest = transport.buildGetRequest(urlString);
705712
break;
706713
case HEAD:
707-
Preconditions.checkArgument(transport.supportsHead(),
708-
"HTTP transport doesn't support HEAD");
714+
Preconditions.checkArgument(
715+
transport.supportsHead(), "HTTP transport doesn't support HEAD");
709716
lowLevelHttpRequest = transport.buildHeadRequest(urlString);
710717
break;
711718
case PATCH:
712-
Preconditions.checkArgument(transport.supportsPatch(),
713-
"HTTP transport doesn't support PATCH");
719+
Preconditions.checkArgument(
720+
transport.supportsPatch(), "HTTP transport doesn't support PATCH");
714721
lowLevelHttpRequest = transport.buildPatchRequest(urlString);
715722
break;
716723
case POST:
@@ -726,8 +733,8 @@ public HttpResponse execute() throws IOException {
726733
// log method and URL
727734
if (loggable) {
728735
logbuf = new StringBuilder();
729-
logbuf.append("-------------- REQUEST --------------").append(Strings.LINE_SEPARATOR);
730-
logbuf.append(method).append(' ').append(urlString).append(Strings.LINE_SEPARATOR);
736+
logbuf.append("-------------- REQUEST --------------").append(StringUtils.LINE_SEPARATOR);
737+
logbuf.append(method).append(' ').append(urlString).append(StringUtils.LINE_SEPARATOR);
731738
}
732739
// add to user agent
733740
if (headers.getUserAgent() == null) {
@@ -772,9 +779,8 @@ public HttpResponse execute() throws IOException {
772779
&& LogContent.isTextBasedContentType(contentType)
773780
&& (loggable && !disableContentLogging || logger.isLoggable(Level.ALL))) {
774781
if (contentLength <= contentLoggingLimit && contentLoggingLimit != 0) {
775-
content =
776-
new LogContent(content, contentType, contentEncoding, contentLength,
777-
contentLoggingLimit);
782+
content = new LogContent(
783+
content, contentType, contentEncoding, contentLength, contentLoggingLimit);
778784
}
779785
}
780786
// gzip
@@ -786,13 +792,14 @@ public HttpResponse execute() throws IOException {
786792
// append content headers to log buffer
787793
if (loggable) {
788794
if (contentType != null) {
789-
logbuf.append("Content-Type: " + contentType).append(Strings.LINE_SEPARATOR);
795+
logbuf.append("Content-Type: " + contentType).append(StringUtils.LINE_SEPARATOR);
790796
}
791797
if (contentEncoding != null) {
792-
logbuf.append("Content-Encoding: " + contentEncoding).append(Strings.LINE_SEPARATOR);
798+
logbuf.append("Content-Encoding: " + contentEncoding)
799+
.append(StringUtils.LINE_SEPARATOR);
793800
}
794801
if (contentLength >= 0) {
795-
logbuf.append("Content-Length: " + contentLength).append(Strings.LINE_SEPARATOR);
802+
logbuf.append("Content-Length: " + contentLength).append(StringUtils.LINE_SEPARATOR);
796803
}
797804
}
798805
lowLevelHttpRequest.setContent(content);
@@ -919,7 +926,7 @@ private static void addHeader(Logger logger, StringBuilder logbuf,
919926
} else {
920927
logbuf.append(stringValue);
921928
}
922-
logbuf.append(Strings.LINE_SEPARATOR);
929+
logbuf.append(StringUtils.LINE_SEPARATOR);
923930
}
924931
// add header
925932
lowLevelHttpRequest.addHeader(name, stringValue);

google-http-client/src/main/java/com/google/api/client/http/HttpResponse.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@
1818
import com.google.api.client.util.ClassInfo;
1919
import com.google.api.client.util.Data;
2020
import com.google.api.client.util.FieldInfo;
21-
import com.google.api.client.util.Strings;
21+
import com.google.api.client.util.StringUtils;
2222
import com.google.api.client.util.Types;
2323
import com.google.common.base.Preconditions;
2424

25-
import org.apache.commons.codec.binary.StringUtils;
26-
2725
import java.io.ByteArrayInputStream;
2826
import java.io.ByteArrayOutputStream;
2927
import java.io.IOException;
@@ -130,7 +128,7 @@ public final class HttpResponse {
130128
StringBuilder logbuf = null;
131129
if (loggable) {
132130
logbuf = new StringBuilder();
133-
logbuf.append("-------------- RESPONSE --------------").append(Strings.LINE_SEPARATOR);
131+
logbuf.append("-------------- RESPONSE --------------").append(StringUtils.LINE_SEPARATOR);
134132
String statusLine = response.getStatusLine();
135133
if (statusLine != null) {
136134
logbuf.append(statusLine);
@@ -140,7 +138,7 @@ public final class HttpResponse {
140138
logbuf.append(' ').append(message);
141139
}
142140
}
143-
logbuf.append(Strings.LINE_SEPARATOR);
141+
logbuf.append(StringUtils.LINE_SEPARATOR);
144142
}
145143
// headers
146144
int size = response.getHeaderCount();
@@ -153,7 +151,7 @@ public final class HttpResponse {
153151
String headerName = response.getHeaderName(i);
154152
String headerValue = response.getHeaderValue(i);
155153
if (loggable) {
156-
logbuf.append(headerName + ": " + headerValue).append(Strings.LINE_SEPARATOR);
154+
logbuf.append(headerName + ": " + headerValue).append(StringUtils.LINE_SEPARATOR);
157155
}
158156
String fieldName = fieldNameMap.get(headerName);
159157
if (fieldName == null) {

google-http-client/src/main/java/com/google/api/client/http/HttpResponseException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
package com.google.api.client.http;
1616

17-
import com.google.api.client.util.Strings;
17+
import com.google.api.client.util.StringUtils;
1818

1919
import java.io.IOException;
2020

@@ -123,7 +123,7 @@ private static String computeMessageWithContent(HttpResponse response) {
123123
exception.printStackTrace();
124124
}
125125
if (content.length() != 0) {
126-
builder.append(Strings.LINE_SEPARATOR).append(content);
126+
builder.append(StringUtils.LINE_SEPARATOR).append(content);
127127
}
128128
return builder.toString();
129129
}

google-http-client/src/main/java/com/google/api/client/http/LogContent.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414

1515
package com.google.api.client.http;
1616

17+
import com.google.api.client.util.StringUtils;
1718
import com.google.common.base.Preconditions;
1819

19-
import org.apache.commons.codec.binary.StringUtils;
20-
2120
import java.io.ByteArrayOutputStream;
2221
import java.io.IOException;
2322
import java.io.OutputStream;

google-http-client/src/main/java/com/google/api/client/testing/http/MockLowLevelHttpResponse.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
package com.google.api.client.testing.http;
1616

1717
import com.google.api.client.http.LowLevelHttpResponse;
18+
import com.google.api.client.util.StringUtils;
1819
import com.google.common.base.Preconditions;
1920

20-
import org.apache.commons.codec.binary.StringUtils;
21-
2221
import java.io.ByteArrayInputStream;
2322
import java.io.IOException;
2423
import java.io.InputStream;

google-http-client/src/main/java/com/google/api/client/testing/json/AbstractJsonFactoryTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
import com.google.api.client.util.Data;
2626
import com.google.api.client.util.Key;
2727
import com.google.api.client.util.NullValue;
28+
import com.google.api.client.util.StringUtils;
2829
import com.google.api.client.util.Value;
2930
import com.google.common.collect.ImmutableList;
3031
import com.google.common.collect.ImmutableMap;
3132

3233
import junit.framework.TestCase;
33-
import org.apache.commons.codec.binary.StringUtils;
3434

3535
import java.io.ByteArrayOutputStream;
3636
import java.io.IOException;

0 commit comments

Comments
 (0)
0