Fixed unstable order of dependencies in json file
@@ -19,10 +19,10 @@ public class CreateDependencyInfoFile {
private static final String DESCRIPTION = "This file was generated by Shipkit Gradle plugin. See http://shipkit.org\n\n";
public void createDependencyInfoFile(CreateDependencyInfoFileTask task) {
- JsonObject result = new JsonObject(new LinkedHashMap<String, Object>()); // linkedHashMap to keep the order
+ JsonObject result = createJsonObject();
result.put("description", DESCRIPTION);
- JsonArray dependencies = new JsonArray(new ArrayList<Object>()); //arrayList to keep the order
+ JsonArray dependencies = createJsonArray();
for (Dependency dependency : task.getConfiguration().getAllDependencies()) {
if (dependency instanceof SelfResolvingDependency) {
@@ -40,7 +40,7 @@ public class CreateDependencyInfoFile {
}
private void addResolvedDependency(CreateDependencyInfoFileTask task, JsonArray dependencies, ResolvedArtifact artifact) {
- JsonObject dependency = new JsonObject(new LinkedHashMap<String, Object>()); // linkedHashMap to keep the order
+ JsonObject dependency = createJsonObject();
ModuleVersionIdentifier moduleVersionId = moduleVersionId(artifact);
@@ -65,8 +65,8 @@ public class CreateDependencyInfoFile {
}
private void addSelfResolvingDependency(JsonArray dependencies, SelfResolvingDependency selfResolvingDependency) {
- JsonObject selfDependency = new JsonObject(new LinkedHashMap<String, Object>()); // linkedHashMap to keep the order
- JsonArray files = new JsonArray();
+ JsonObject selfDependency = createJsonObject();
+ JsonArray files = createJsonArray();
Set<File> resolvedFiles = selfResolvingDependency.resolve();
if (!resolvedFiles.isEmpty()) {
for (File file : resolvedFiles) {
@@ -78,5 +78,13 @@ public class CreateDependencyInfoFile {
}
}
+ private JsonObject createJsonObject() {
+ return new JsonObject(new LinkedHashMap<String, Object>()); // linkedHashMap to keep the order
+ }
+
+ private JsonArray createJsonArray() {
+ return new JsonArray(new ArrayList<Object>()); //arrayList to keep the order
+ }
+
}
