Skip to content

Commit d451336

Browse files
committed
Merge pull request #134 from aslakknutsen/remove_guava
Remove Google Guava as dependency
2 parents 0a3a28e + ad7881a commit d451336

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1108
-245
lines changed

pom.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
<slf4j-api.version>1.7.5</slf4j-api.version>
6363
<jsr305.version>1.3.9</jsr305.version>
6464
<jnr.unixsocket.version>0.3</jnr.unixsocket.version>
65-
<guava.version>18.0</guava.version>
6665
<bouncycastle.version>1.51</bouncycastle.version>
6766
<unix-socket-factory.version>2014-11-16T14-41-27</unix-socket-factory.version>
6867

@@ -150,12 +149,6 @@
150149
<version>${slf4j-api.version}</version>
151150
</dependency>
152151

153-
<dependency>
154-
<groupId>com.google.guava</groupId>
155-
<artifactId>guava</artifactId>
156-
<version>${guava.version}</version>
157-
</dependency>
158-
159152
<dependency>
160153
<groupId>org.bouncycastle</groupId>
161154
<artifactId>bcpkix-jdk15on</artifactId>
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/* Copyright (C) 2008 The Guava Authors
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
package com.github.dockerjava;
16+
17+
18+
public final class Preconditions {
19+
private Preconditions() {}
20+
21+
/**
22+
* Ensures the truth of an expression involving one or more parameters to the calling method.
23+
*
24+
* @param expression a boolean expression
25+
* @param errorMessageTemplate a template for the exception message should the check fail. The
26+
* message is formed by replacing each {@code %s} placeholder in the template with an
27+
* argument. These are matched by position - the first {@code %s} gets {@code
28+
* errorMessageArgs[0]}, etc. Unmatched arguments will be appended to the formatted message
29+
* in square braces. Unmatched placeholders will be left as-is.
30+
* @param errorMessageArgs the arguments to be substituted into the message template. Arguments
31+
* are converted to strings using {@link String#valueOf(Object)}.
32+
* @throws IllegalArgumentException if {@code expression} is false
33+
* @throws NullPointerException if the check fails and either {@code errorMessageTemplate} or
34+
* {@code errorMessageArgs} is null (don't let this happen)
35+
*/
36+
public static void checkArgument(boolean expression,
37+
String errorMessageTemplate,
38+
Object... errorMessageArgs) {
39+
if (!expression) {
40+
throw new IllegalArgumentException(Preconditions.format(errorMessageTemplate, errorMessageArgs));
41+
}
42+
}
43+
44+
/**
45+
* Ensures that an object reference passed as a parameter to the calling method is not null.
46+
*
47+
* @param reference an object reference
48+
* @param errorMessage the exception message to use if the check fails; will be converted to a
49+
* string using {@link String#valueOf(Object)}
50+
* @return the non-null reference that was validated
51+
* @throws NullPointerException if {@code reference} is null
52+
*/
53+
public static <T> T checkNotNull(T reference, Object errorMessage) {
54+
if (reference == null) {
55+
throw new NullPointerException(String.valueOf(errorMessage));
56+
}
57+
return reference;
58+
}
59+
60+
/**
61+
* Ensures the truth of an expression involving one or more parameters to the calling method.
62+
*
63+
* @param expression a boolean expression
64+
* @param errorMessage the exception message to use if the check fails; will be converted to a
65+
* string using {@link String#valueOf(Object)}
66+
* @throws IllegalArgumentException if {@code expression} is false
67+
*/
68+
public static void checkArgument(boolean expression, Object errorMessage) {
69+
if (!expression) {
70+
throw new IllegalArgumentException(String.valueOf(errorMessage));
71+
}
72+
}
73+
74+
/**
75+
* Ensures that an object reference passed as a parameter to the calling method is not null.
76+
*
77+
* @param reference an object reference
78+
* @return the non-null reference that was validated
79+
* @throws NullPointerException if {@code reference} is null
80+
*/
81+
public static <T> T checkNotNull(T reference) {
82+
if (reference == null) {
83+
throw new NullPointerException();
84+
}
85+
return reference;
86+
}
87+
88+
/**
89+
* Ensures the truth of an expression involving the state of the calling instance, but not
90+
* involving any parameters to the calling method.
91+
*
92+
* @param expression a boolean expression
93+
* @param errorMessage the exception message to use if the check fails; will be converted to a
94+
* string using {@link String#valueOf(Object)}
95+
* @throws IllegalStateException if {@code expression} is false
96+
*/
97+
public static void checkState(boolean expression, Object errorMessage) {
98+
if (!expression) {
99+
throw new IllegalStateException(String.valueOf(errorMessage));
100+
}
101+
}
102+
103+
/**
104+
* Substitutes each {@code %s} in {@code template} with an argument. These are matched by
105+
* position: the first {@code %s} gets {@code args[0]}, etc. If there are more arguments than
106+
* placeholders, the unmatched arguments will be appended to the end of the formatted message in
107+
* square braces.
108+
*
109+
* @param template a non-null string containing 0 or more {@code %s} placeholders.
110+
* @param args the arguments to be substituted into the message template. Arguments are converted
111+
* to strings using {@link String#valueOf(Object)}. Arguments can be null.
112+
*/
113+
// Note that this is somewhat-improperly used from Verify.java as well.
114+
public static String format(String template, Object... args) {
115+
template = String.valueOf(template); // null -> "null"
116+
117+
// start substituting the arguments into the '%s' placeholders
118+
StringBuilder builder = new StringBuilder(template.length() + 16 * args.length);
119+
int templateStart = 0;
120+
int i = 0;
121+
while (i < args.length) {
122+
int placeholderStart = template.indexOf("%s", templateStart);
123+
if (placeholderStart == -1) {
124+
break;
125+
}
126+
builder.append(template.substring(templateStart, placeholderStart));
127+
builder.append(args[i++]);
128+
templateStart = placeholderStart + 2;
129+
}
130+
builder.append(template.substring(templateStart));
131+
132+
// if we run out of placeholders, append the extra args in square braces
133+
if (i < args.length) {
134+
builder.append(" [");
135+
builder.append(args[i++]);
136+
while (i < args.length) {
137+
builder.append(", ");
138+
builder.append(args[i++]);
139+
}
140+
builder.append(']');
141+
}
142+
143+
return builder.toString();
144+
}
145+
}

src/main/java/com/github/dockerjava/api/command/TopContainerResponse.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package com.github.dockerjava.api.command;
22

3+
import static com.github.dockerjava.jaxrs.util.guava.Guava.join;
4+
35
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
46
import com.fasterxml.jackson.annotation.JsonProperty;
5-
import com.google.common.base.Joiner;
67

78
/**
89
*
@@ -28,17 +29,15 @@ public String[][] getProcesses() {
2829

2930
@Override
3031
public String toString() {
31-
Joiner joiner = Joiner.on("; ").skipNulls();
32-
3332
StringBuffer buffer = new StringBuffer();
3433
buffer.append("[");
3534
for(String[] fields: processes) {
36-
buffer.append("[" + joiner.join(fields) + "]");
35+
buffer.append("[" + join(fields, "; ", true) + "]");
3736
}
3837
buffer.append("]");
3938

4039
return "TopContainerResponse{" +
41-
"titles=" + joiner.join(titles) +
40+
"titles=" + join(titles, "; ", true) +
4241
", processes=" + buffer.toString() +
4342
'}';
4443
}

src/main/java/com/github/dockerjava/api/model/Device.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package com.github.dockerjava.api.model;
22

3+
import static com.github.dockerjava.Preconditions.checkNotNull;
4+
35
import org.apache.commons.lang.builder.EqualsBuilder;
46
import org.apache.commons.lang.builder.HashCodeBuilder;
57

68
import com.fasterxml.jackson.annotation.JsonProperty;
7-
import com.google.common.base.Preconditions;
89

910
public class Device {
1011

@@ -22,10 +23,10 @@ public Device() {
2223

2324
public Device(String cGroupPermissions, String pathInContainer,
2425
String pathOnHost) {
25-
Preconditions.checkNotNull(cGroupPermissions,
26+
checkNotNull(cGroupPermissions,
2627
"cGroupPermissions is null");
27-
Preconditions.checkNotNull(pathInContainer, "pathInContainer is null");
28-
Preconditions.checkNotNull(pathOnHost, "pathOnHost is null");
28+
checkNotNull(pathInContainer, "pathInContainer is null");
29+
checkNotNull(pathOnHost, "pathOnHost is null");
2930
this.cGroupPermissions = cGroupPermissions;
3031
this.pathInContainer = pathInContainer;
3132
this.pathOnHost = pathOnHost;

src/main/java/com/github/dockerjava/api/model/RestartPolicy.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package com.github.dockerjava.api.model;
22

3+
import static com.github.dockerjava.Preconditions.checkNotNull;
4+
35
import org.apache.commons.lang.builder.EqualsBuilder;
46
import org.apache.commons.lang.builder.HashCodeBuilder;
57

68
import com.fasterxml.jackson.annotation.JsonProperty;
7-
import com.google.common.base.Preconditions;
89

910
/**
1011
* Container restart policy
@@ -36,7 +37,7 @@ public RestartPolicy() {
3637
}
3738

3839
private RestartPolicy(int maximumRetryCount, String name) {
39-
Preconditions.checkNotNull(name, "name is null");
40+
checkNotNull(name, "name is null");
4041
this.maximumRetryCount = maximumRetryCount;
4142
this.name = name;
4243
}

src/main/java/com/github/dockerjava/core/DockerClientConfig.java

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
package com.github.dockerjava.core;
22

3-
import com.github.dockerjava.api.DockerClientException;
4-
import com.github.dockerjava.api.model.AuthConfig;
5-
import com.github.dockerjava.core.NameParser.HostnameReposName;
6-
import com.github.dockerjava.core.NameParser.ReposTag;
7-
import com.google.common.base.Preconditions;
8-
import com.google.common.collect.ImmutableMap;
3+
import static com.github.dockerjava.Preconditions.checkNotNull;
94

105
import java.io.File;
116
import java.io.FileInputStream;
127
import java.io.IOException;
138
import java.io.Serializable;
149
import java.net.URI;
10+
import java.util.Collections;
11+
import java.util.HashMap;
1512
import java.util.Map;
1613
import java.util.Properties;
1714

15+
import com.github.dockerjava.api.DockerClientException;
16+
import com.github.dockerjava.api.model.AuthConfig;
17+
import com.github.dockerjava.core.NameParser.HostnameReposName;
18+
import com.github.dockerjava.core.NameParser.ReposTag;
19+
1820
public class DockerClientConfig implements Serializable {
1921

2022
private static final long serialVersionUID = -4307357472441531489L;
@@ -39,18 +41,23 @@ public class DockerClientConfig implements Serializable {
3941
/**
4042
* A map from the environment name to the interval name.
4143
*/
42-
private static final Map<String, String> ENV_NAME_TO_IO_NAME = ImmutableMap.<String, String>builder()
43-
.put("DOCKER_URL", DOCKER_IO_URL_PROPERTY)
44-
.put("DOCKER_VERSION", DOCKER_IO_VERSION_PROPERTY)
45-
.put("DOCKER_USERNAME", DOCKER_IO_USERNAME_PROPERTY)
46-
.put("DOCKER_PASSWORD", DOCKER_IO_PASSWORD_PROPERTY)
47-
.put("DOCKER_EMAIL", DOCKER_IO_EMAIL_PROPERTY)
48-
.put("DOCKER_SERVER_ADDRESS", DOCKER_IO_SERVER_ADDRESS_PROPERTY)
49-
.put("DOCKER_READ_TIMEOUT", DOCKER_IO_READ_TIMEOUT_PROPERTY)
50-
.put("DOCKER_LOGGING_FILTER_ENABLED", DOCKER_IO_ENABLE_LOGGING_FILTER_PROPERTY)
51-
.put(DOCKER_CERT_PATH_PROPERTY, DOCKER_IO_DOCKER_CERT_PATH_PROPERTY)
52-
.put("DOCKER_CFG_PATH", DOCKER_IO_DOCKER_CFG_PATH_PROPERTY)
53-
.build();
44+
// Immutable ish
45+
private static final Map<String, String> ENV_NAME_TO_IO_NAME;
46+
static {
47+
Map<String, String> m = new HashMap<String, String>();
48+
m.put("DOCKER_URL", DOCKER_IO_URL_PROPERTY);
49+
m.put("DOCKER_VERSION", DOCKER_IO_VERSION_PROPERTY);
50+
m.put("DOCKER_USERNAME", DOCKER_IO_USERNAME_PROPERTY);
51+
m.put("DOCKER_PASSWORD", DOCKER_IO_PASSWORD_PROPERTY);
52+
m.put("DOCKER_EMAIL", DOCKER_IO_EMAIL_PROPERTY);
53+
m.put("DOCKER_SERVER_ADDRESS", DOCKER_IO_SERVER_ADDRESS_PROPERTY);
54+
m.put("DOCKER_READ_TIMEOUT", DOCKER_IO_READ_TIMEOUT_PROPERTY);
55+
m.put("DOCKER_LOGGING_FILTER_ENABLED", DOCKER_IO_ENABLE_LOGGING_FILTER_PROPERTY);
56+
m.put(DOCKER_CERT_PATH_PROPERTY, DOCKER_IO_DOCKER_CERT_PATH_PROPERTY);
57+
m.put("DOCKER_CFG_PATH", DOCKER_IO_DOCKER_CFG_PATH_PROPERTY);
58+
ENV_NAME_TO_IO_NAME = Collections.unmodifiableMap(m);
59+
}
60+
5461
private static final String DOCKER_IO_PROPERTIES_PROPERTY = "docker.io.properties";
5562
private URI uri;
5663
private final String version, username, password, email, serverAddress, dockerCfgPath;
@@ -370,7 +377,7 @@ public DockerClientConfigBuilder withProperties(Properties p) {
370377
}
371378

372379
public final DockerClientConfigBuilder withUri(String uri) {
373-
Preconditions.checkNotNull(uri, "uri was not specified");
380+
checkNotNull(uri, "uri was not specified");
374381
this.uri = URI.create(uri);
375382
return this;
376383
}

0 commit comments

Comments
 (0)