Skip to content

Commit afe9be6

Browse files
author
Dave Syer
committed
Factor out some Guava usage in util jar
Signed-off-by: Dave Syer <dsyer@vmware.com>
1 parent ffb7dee commit afe9be6

25 files changed

+286
-195
lines changed

util/pom.xml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@
4646
<groupId>org.apache.commons</groupId>
4747
<artifactId>commons-lang3</artifactId>
4848
</dependency>
49-
<dependency>
50-
<groupId>com.google.guava</groupId>
51-
<artifactId>guava</artifactId>
52-
</dependency>
5349
<dependency>
5450
<groupId>org.slf4j</groupId>
5551
<artifactId>slf4j-api</artifactId>
@@ -81,9 +77,9 @@
8177
<artifactId>commons-collections4</artifactId>
8278
</dependency>
8379
<dependency>
84-
<groupId>org.bitbucket.b_c</groupId>
85-
<artifactId>jose4j</artifactId>
86-
</dependency>
80+
<groupId>org.bitbucket.b_c</groupId>
81+
<artifactId>jose4j</artifactId>
82+
</dependency>
8783
<!-- test dependencies -->
8884
<dependency>
8985
<groupId>junit</groupId>

util/src/main/java/io/kubernetes/client/Copy.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
*/
1313
package io.kubernetes.client;
1414

15-
import com.google.common.io.ByteStreams;
1615
import io.kubernetes.client.openapi.ApiClient;
1716
import io.kubernetes.client.openapi.ApiException;
1817
import io.kubernetes.client.openapi.Configuration;
1918
import io.kubernetes.client.openapi.models.V1Pod;
19+
import io.kubernetes.client.util.Streams;
2020
import io.kubernetes.client.util.exception.CopyNotSupportedException;
2121
import java.io.BufferedInputStream;
2222
import java.io.BufferedReader;
@@ -95,7 +95,7 @@ public void copyFileFromPod(
9595
throws ApiException, IOException {
9696
try (InputStream is = copyFileFromPod(namespace, name, container, srcPath);
9797
FileOutputStream fos = new FileOutputStream(destination.toFile())) {
98-
ByteStreams.copy(is, fos);
98+
Streams.copy(is, fos);
9999
fos.flush();
100100
}
101101
}
@@ -199,7 +199,7 @@ public Future<Integer> copyDirectoryFromPodAsync(
199199
throw new IOException("create directory failed: " + parent);
200200
}
201201
try (OutputStream fs = new FileOutputStream(f)) {
202-
ByteStreams.copy(archive, fs);
202+
Streams.copy(archive, fs);
203203
fs.flush();
204204
}
205205
}
@@ -245,7 +245,7 @@ private void createFiles(
245245
String modifiedSrcPath = genericPathBuilder(srcPath, childNode.name);
246246
try (InputStream is = copyFileFromPod(namespace, pod, modifiedSrcPath);
247247
OutputStream fs = new FileOutputStream(f)) {
248-
ByteStreams.copy(is, fs);
248+
Streams.copy(is, fs);
249249
fs.flush();
250250
}
251251
} else {
@@ -332,7 +332,7 @@ public static void copyFileFromPod(String namespace, String pod, String srcPath,
332332
Copy c = new Copy();
333333
try (InputStream is = c.copyFileFromPod(namespace, pod, null, srcPath);
334334
FileOutputStream os = new FileOutputStream(dest.toFile())) {
335-
ByteStreams.copy(is, os);
335+
Streams.copy(is, os);
336336
os.flush();
337337
}
338338
}
@@ -366,7 +366,7 @@ public Future<Integer> copyFileToPodAsync(
366366
ArchiveEntry tarEntry = new TarArchiveEntry(srcFile, destPath.getFileName().toString());
367367

368368
archiveOutputStream.putArchiveEntry(tarEntry);
369-
ByteStreams.copy(input, archiveOutputStream);
369+
Streams.copy(input, archiveOutputStream);
370370
archiveOutputStream.closeArchiveEntry();
371371

372372
return new ProcessFuture(proc);
@@ -399,7 +399,7 @@ public Future<Integer> copyFileToPodAsync(
399399
((TarArchiveEntry) tarEntry).setSize(src.length);
400400

401401
archiveOutputStream.putArchiveEntry(tarEntry);
402-
ByteStreams.copy(new ByteArrayInputStream(src), archiveOutputStream);
402+
Streams.copy(new ByteArrayInputStream(src), archiveOutputStream);
403403
archiveOutputStream.closeArchiveEntry();
404404

405405
return new ProcessFuture(proc);

util/src/main/java/io/kubernetes/client/Discovery.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,26 @@
1212
*/
1313
package io.kubernetes.client;
1414

15-
import com.google.common.base.Objects;
16-
import io.kubernetes.client.openapi.ApiClient;
17-
import io.kubernetes.client.openapi.ApiException;
18-
import io.kubernetes.client.openapi.ApiResponse;
19-
import io.kubernetes.client.openapi.Configuration;
20-
import io.kubernetes.client.openapi.models.V1APIGroup;
21-
import io.kubernetes.client.openapi.models.V1APIGroupList;
22-
import io.kubernetes.client.openapi.models.V1APIResourceList;
23-
import io.kubernetes.client.openapi.models.V1APIVersions;
2415
import java.util.ArrayList;
2516
import java.util.Arrays;
2617
import java.util.Collections;
2718
import java.util.HashMap;
2819
import java.util.HashSet;
2920
import java.util.List;
3021
import java.util.Map;
22+
import java.util.Objects;
3123
import java.util.Optional;
3224
import java.util.Set;
3325
import java.util.stream.Collectors;
26+
27+
import io.kubernetes.client.openapi.ApiClient;
28+
import io.kubernetes.client.openapi.ApiException;
29+
import io.kubernetes.client.openapi.ApiResponse;
30+
import io.kubernetes.client.openapi.Configuration;
31+
import io.kubernetes.client.openapi.models.V1APIGroup;
32+
import io.kubernetes.client.openapi.models.V1APIGroupList;
33+
import io.kubernetes.client.openapi.models.V1APIResourceList;
34+
import io.kubernetes.client.openapi.models.V1APIVersions;
3435
import okhttp3.Call;
3536

3637
public class Discovery {
@@ -237,19 +238,19 @@ public boolean equals(Object o) {
237238
if (this == o) return true;
238239
if (o == null || getClass() != o.getClass()) return false;
239240
APIResource that = (APIResource) o;
240-
return Objects.equal(group, that.group)
241-
&& Objects.equal(kind, that.kind)
242-
&& Objects.equal(versions, that.versions)
243-
&& Objects.equal(preferredVersion, that.preferredVersion)
244-
&& Objects.equal(isNamespaced, that.isNamespaced)
245-
&& Objects.equal(resourcePlural, that.resourcePlural)
246-
&& Objects.equal(resourceSingular, that.resourceSingular)
247-
&& Objects.equal(subResources, that.subResources);
241+
return Objects.equals(group, that.group)
242+
&& Objects.equals(kind, that.kind)
243+
&& Objects.equals(versions, that.versions)
244+
&& Objects.equals(preferredVersion, that.preferredVersion)
245+
&& Objects.equals(isNamespaced, that.isNamespaced)
246+
&& Objects.equals(resourcePlural, that.resourcePlural)
247+
&& Objects.equals(resourceSingular, that.resourceSingular)
248+
&& Objects.equals(subResources, that.subResources);
248249
}
249250

250251
@Override
251252
public int hashCode() {
252-
return Objects.hashCode(
253+
return Objects.hash(
253254
group,
254255
kind,
255256
versions,

util/src/main/java/io/kubernetes/client/Exec.java

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

1515
import static io.kubernetes.client.KubernetesConstants.*;
1616

17-
import com.google.common.io.CharStreams;
1817
import com.google.gson.reflect.TypeToken;
1918
import io.kubernetes.client.custom.IOTrio;
2019
import io.kubernetes.client.openapi.ApiClient;
@@ -25,6 +24,7 @@
2524
import io.kubernetes.client.openapi.models.V1Status;
2625
import io.kubernetes.client.openapi.models.V1StatusCause;
2726
import io.kubernetes.client.openapi.models.V1StatusDetails;
27+
import io.kubernetes.client.util.Streams;
2828
import io.kubernetes.client.util.WebSocketStreamHandler;
2929
import io.kubernetes.client.util.WebSockets;
3030
import java.io.IOException;
@@ -446,7 +446,7 @@ static int parseExitCode(ApiClient client, InputStream inputStream) {
446446
Type returnType = new TypeToken<V1Status>() {}.getType();
447447
String body;
448448
try (final Reader reader = new InputStreamReader(inputStream)) {
449-
body = CharStreams.toString(reader);
449+
body = Streams.toString(reader);
450450
}
451451

452452
V1Status status = client.getJSON().deserialize(body, returnType);

util/src/main/java/io/kubernetes/client/ProtoClient.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
*/
1313
package io.kubernetes.client;
1414

15-
import com.google.common.io.ByteStreams;
16-
import com.google.common.primitives.Bytes;
1715
import com.google.protobuf.Message;
1816
import com.google.protobuf.Message.Builder;
1917
import io.kubernetes.client.openapi.ApiClient;
@@ -24,6 +22,8 @@
2422
import io.kubernetes.client.proto.Meta.Status;
2523
import io.kubernetes.client.proto.Runtime.TypeMeta;
2624
import io.kubernetes.client.proto.Runtime.Unknown;
25+
import io.kubernetes.client.util.Streams;
26+
2727
import java.io.IOException;
2828
import java.io.InputStream;
2929
import java.util.ArrayList;
@@ -309,12 +309,19 @@ private byte[] encode(Message msg, String apiVersion, String kind) {
309309
.setTypeMeta(TypeMeta.newBuilder().setApiVersion(apiVersion).setKind(kind))
310310
.setRaw(msg.toByteString())
311311
.build();
312-
return Bytes.concat(MAGIC, u.toByteArray());
312+
return concat(MAGIC, u.toByteArray());
313+
}
314+
315+
private static byte[] concat(byte[] one, byte[] two) {
316+
byte[] result = new byte[one.length + two.length];
317+
System.arraycopy(one, 0, result, 0, one.length);
318+
System.arraycopy(two, 0, result, one.length, two.length);
319+
return result;
313320
}
314321

315322
private Unknown parse(InputStream stream) throws ApiException, IOException {
316323
byte[] magic = new byte[4];
317-
ByteStreams.readFully(stream, magic);
324+
Streams.readFully(stream, magic);
318325
if (!Arrays.equals(magic, MAGIC)) {
319326
throw new ApiException("Unexpected magic number: " + Hex.encodeHexString(magic));
320327
}

util/src/main/java/io/kubernetes/client/apimachinery/GroupVersion.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
*/
1313
package io.kubernetes.client.apimachinery;
1414

15-
import com.google.common.base.Objects;
16-
import com.google.common.base.Strings;
15+
import java.util.Objects;
16+
1717
import io.kubernetes.client.common.KubernetesObject;
18+
import io.kubernetes.client.util.Strings;
1819

1920
public class GroupVersion {
2021

@@ -28,7 +29,8 @@ public static GroupVersion parse(String apiVersion) {
2829
}
2930
String[] parts = apiVersion.split("/");
3031
if (parts.length != 2) {
31-
throw new IllegalArgumentException("Invalid apiVersion found on object: " + apiVersion);
32+
throw new IllegalArgumentException(
33+
"Invalid apiVersion found on object: " + apiVersion);
3234
}
3335
return new GroupVersion(parts[0], parts[1]);
3436
}
@@ -49,6 +51,7 @@ public GroupVersion(String group, String version) {
4951
}
5052

5153
private final String group;
54+
5255
private final String version;
5356

5457
public String getGroup() {
@@ -61,14 +64,17 @@ public String getVersion() {
6164

6265
@Override
6366
public boolean equals(Object o) {
64-
if (this == o) return true;
65-
if (o == null || getClass() != o.getClass()) return false;
67+
if (this == o)
68+
return true;
69+
if (o == null || getClass() != o.getClass())
70+
return false;
6671
GroupVersion that = (GroupVersion) o;
67-
return Objects.equal(group, that.group) && Objects.equal(version, that.version);
72+
return Objects.equals(group, that.group) && Objects.equals(version, that.version);
6873
}
6974

7075
@Override
7176
public int hashCode() {
72-
return Objects.hashCode(group, version);
77+
return Objects.hash(group, version);
7378
}
79+
7480
}

util/src/main/java/io/kubernetes/client/apimachinery/GroupVersionKind.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
package io.kubernetes.client.apimachinery;
1414

15-
import com.google.common.base.Objects;
15+
import java.util.Objects;
1616

1717
public class GroupVersionKind extends GroupVersion {
1818

@@ -32,15 +32,19 @@ public String getKind() {
3232

3333
@Override
3434
public boolean equals(Object o) {
35-
if (this == o) return true;
36-
if (o == null || getClass() != o.getClass()) return false;
37-
if (!super.equals(o)) return false;
35+
if (this == o)
36+
return true;
37+
if (o == null || getClass() != o.getClass())
38+
return false;
39+
if (!super.equals(o))
40+
return false;
3841
GroupVersionKind that = (GroupVersionKind) o;
39-
return Objects.equal(kind, that.kind);
42+
return Objects.equals(kind, that.kind);
4043
}
4144

4245
@Override
4346
public int hashCode() {
44-
return Objects.hashCode(super.hashCode(), kind);
47+
return Objects.hash(super.hashCode(), kind);
4548
}
49+
4650
}

util/src/main/java/io/kubernetes/client/apimachinery/GroupVersionResource.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
package io.kubernetes.client.apimachinery;
1414

15-
import com.google.common.base.Objects;
15+
import java.util.Objects;
1616

1717
public class GroupVersionResource extends GroupVersion {
1818

@@ -28,19 +28,23 @@ public GroupVersionResource(String group, String version, String resource) {
2828

2929
@Override
3030
public boolean equals(Object o) {
31-
if (this == o) return true;
32-
if (o == null || getClass() != o.getClass()) return false;
33-
if (!super.equals(o)) return false;
31+
if (this == o)
32+
return true;
33+
if (o == null || getClass() != o.getClass())
34+
return false;
35+
if (!super.equals(o))
36+
return false;
3437
GroupVersionResource that = (GroupVersionResource) o;
35-
return Objects.equal(resource, that.resource);
38+
return Objects.equals(resource, that.resource);
3639
}
3740

3841
@Override
3942
public int hashCode() {
40-
return Objects.hashCode(super.hashCode(), resource);
43+
return Objects.hash(super.hashCode(), resource);
4144
}
4245

4346
public String getResource() {
4447
return resource;
4548
}
49+
4650
}

0 commit comments

Comments
 (0)