Skip to content

Commit

Permalink
This replaces org.json with GSON. (#1073)
Browse files Browse the repository at this point in the history
Replace org.json with GSON 

Fixes #1016 and #1064.

Signed-off-by: Ronald DiFrango ronald.difrango@capitalone.com
  • Loading branch information
rdifrango authored and rhuss committed Sep 25, 2018
1 parent ab1593d commit d51ca2a
Show file tree
Hide file tree
Showing 36 changed files with 936 additions and 624 deletions.
1 change: 1 addition & 0 deletions doc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Fix property configuration based's build detection (#1078)
- Introduce container name patterns for naming containers (#931)
- Respect environment variables DOCKER_CONFIG, KUBECONFIG for looking up credentials (#1083)
- Change from org.json with Gson for less restrictive licensing (#1016) (#1064)z doc

* **0.26.1** (2018-07-20)
- Simple Dockerfile triggered also when only a single run section is given
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@
</dependency>

<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>

<dependency>
Expand Down
21 changes: 11 additions & 10 deletions src/main/java/io/fabric8/maven/docker/access/AuthConfig.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package io.fabric8.maven.docker.access;

import java.io.UnsupportedEncodingException;
import java.util.Map;
import com.google.gson.JsonObject;

import org.apache.commons.codec.binary.Base64;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;
import java.util.Map;

/**
* Configuration object holding auth information for
Expand All @@ -26,9 +27,9 @@ public class AuthConfig {

public AuthConfig(Map<String,String> params) {
this(params.get("username"),
params.get("password"),
params.get("email"),
params.get("auth"));
params.get("password"),
params.get("email"),
params.get("auth"));
}

public AuthConfig(String username, String password, String email, String auth) {
Expand Down Expand Up @@ -74,7 +75,7 @@ public String toHeaderValue() {
// ======================================================================================================

private String createAuthEncoded() {
JSONObject ret = new JSONObject();
JsonObject ret = new JsonObject();
putNonNull(ret, "username", username);
putNonNull(ret, "password", password);
putNonNull(ret, "email", email);
Expand All @@ -99,9 +100,9 @@ private String encodeBase64ChunkedURLSafeString(final byte[] binaryData) {
.replace('/', '_');
}

private void putNonNull(JSONObject ret, String key, String value) {
private void putNonNull(JsonObject ret, String key, String value) {
if (value != null) {
ret.put(key,value);
ret.addProperty(key,value);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.util.HashMap;
import java.util.Map;

import org.json.JSONObject;
import io.fabric8.maven.docker.util.JsonFactory;

/**
* @author roland
Expand Down Expand Up @@ -62,7 +62,7 @@ public BuildOptions noCache(boolean noCache) {

public BuildOptions buildArgs(Map<String, String> buildArgs) {
if (buildArgs != null && buildArgs.size() > 0) {
options.put("buildargs", new JSONObject(buildArgs).toString());
options.put("buildargs", JsonFactory.newJsonObject(buildArgs).toString());
}
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,49 @@
package io.fabric8.maven.docker.access;

import java.io.*;
import java.util.*;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;

import io.fabric8.maven.docker.util.EnvUtil;
import io.fabric8.maven.docker.config.Arguments;
import org.apache.commons.text.StrSubstitutor;
import org.json.JSONArray;
import org.json.JSONObject;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import io.fabric8.maven.docker.config.Arguments;
import io.fabric8.maven.docker.util.EnvUtil;
import io.fabric8.maven.docker.util.JsonFactory;

public class ContainerCreateConfig {

private final JSONObject createConfig = new JSONObject();
private final JsonObject createConfig = new JsonObject();
private final String imageName;

public ContainerCreateConfig(String imageName) {
this.imageName = imageName;
createConfig.put("Image", imageName);
createConfig.addProperty("Image", imageName);
}

public ContainerCreateConfig binds(List<String> volumes) {
if (volumes != null && !volumes.isEmpty()) {
JSONObject extractedVolumes = new JSONObject();
JsonObject extractedVolumes = new JsonObject();

for (String volume : volumes) {
extractedVolumes.put(extractContainerPath(volume),
new JSONObject());
extractedVolumes.add(extractContainerPath(volume),
new JsonObject());
}
createConfig.put("Volumes", extractedVolumes);
createConfig.add("Volumes", extractedVolumes);
}
return this;
}

public ContainerCreateConfig command(Arguments command) {
if (command != null) {
createConfig.put("Cmd", new JSONArray(command.asStrings()));
createConfig.add("Cmd", JsonFactory.newJsonArray(command.asStrings()));
}
return this;
}
Expand All @@ -44,7 +54,7 @@ public ContainerCreateConfig domainname(String domainname) {

public ContainerCreateConfig entrypoint(Arguments entrypoint) {
if (entrypoint != null) {
createConfig.put("Entrypoint", new JSONArray(entrypoint.asStrings()));
createConfig.add("Entrypoint", JsonFactory.newJsonArray(entrypoint.asStrings()));
}
return this;
}
Expand Down Expand Up @@ -80,18 +90,18 @@ public ContainerCreateConfig environment(String envPropsFile, Map<String, String

public ContainerCreateConfig labels(Map<String,String> labels) {
if (labels != null && labels.size() > 0) {
createConfig.put("Labels", new JSONObject(labels));
createConfig.add("Labels", JsonFactory.newJsonObject(labels));
}
return this;
}

public ContainerCreateConfig exposedPorts(Set<String> portSpecs) {
if (portSpecs != null && portSpecs.size() > 0) {
JSONObject exposedPorts = new JSONObject();
JsonObject exposedPorts = new JsonObject();
for (String portSpec : portSpecs) {
exposedPorts.put(portSpec, new JSONObject());
exposedPorts.add(portSpec, new JsonObject());
}
createConfig.put("ExposedPorts", exposedPorts);
createConfig.add("ExposedPorts", exposedPorts);
}
return this;
}
Expand Down Expand Up @@ -131,9 +141,16 @@ public String toJson() {

// =======================================================================

private ContainerCreateConfig add(String name, Object value) {
private ContainerCreateConfig add(String name, String value) {
if (value != null) {
createConfig.addProperty(name, value);
}
return this;
}

private ContainerCreateConfig add(String name, JsonObject value) {
if (value != null) {
createConfig.put(name, value);
createConfig.add(name, value);
}
return this;
}
Expand All @@ -150,17 +167,17 @@ private String extractContainerPath(String volume) {
}

private void addEnvironment(Properties envProps) {
JSONArray containerEnv = new JSONArray();
JsonArray containerEnv = new JsonArray();
Enumeration keys = envProps.keys();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
String value = envProps.getProperty(key);
if (value == null) {
value = "";
}
containerEnv.put(key + "=" + value);
containerEnv.add(key + "=" + value);
}
createConfig.put("Env", containerEnv);
createConfig.add("Env", containerEnv);
}

private void addPropertiesFromFile(String envPropsFile, Properties envProps) {
Expand Down
Loading

0 comments on commit d51ca2a

Please sign in to comment.