Reuse SmartGson.getReader() in JenkinsCiPluginsRepository JenkinsCiPluginsRepository was reading directly from a URI when fetching a remote stream rather than relying on the SmartGson.getReader(), which had exactly the same logic. Use a unique channel to fetch from a remote source so that mocking becomes easier and also replacing it with a different transport handler would not require changes to the JenkinsCiPluginsRepository implementation. Change-Id: Ib1f25e7085cafb1c133e1b7e48dc993328489254
diff --git a/src/main/java/com/googlesource/gerrit/plugins/manager/gson/SmartGson.java b/src/main/java/com/googlesource/gerrit/plugins/manager/gson/SmartGson.java index 21b1ddf..fa2860f 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/manager/gson/SmartGson.java +++ b/src/main/java/com/googlesource/gerrit/plugins/manager/gson/SmartGson.java
@@ -48,7 +48,7 @@ } } - private InputStreamReader getReader(String url) throws IOException { + public InputStreamReader getReader(String url) throws IOException { URL ciUrl; try { ciUrl = URI.create(url).toURL();
diff --git a/src/main/java/com/googlesource/gerrit/plugins/manager/repository/JenkinsCiPluginsRepository.java b/src/main/java/com/googlesource/gerrit/plugins/manager/repository/JenkinsCiPluginsRepository.java index 48dac31..4541e01 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/manager/repository/JenkinsCiPluginsRepository.java +++ b/src/main/java/com/googlesource/gerrit/plugins/manager/repository/JenkinsCiPluginsRepository.java
@@ -14,8 +14,6 @@ package com.googlesource.gerrit.plugins.manager.repository; -import static java.nio.charset.StandardCharsets.UTF_8; - import com.google.common.annotations.VisibleForTesting; import com.google.common.flogger.FluentLogger; import com.google.gson.JsonArray; @@ -31,8 +29,6 @@ import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.IOException; -import java.io.InputStreamReader; -import java.net.URI; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -225,8 +221,7 @@ "%s/artifact/%s", buildExecution.getString("url"), verArtifactJson.get().getString("relativePath")); try (BufferedReader reader = - new BufferedReader( - new InputStreamReader(URI.create(versionUrl).toURL().openStream(), UTF_8), 4096)) { + new BufferedReader(gsonProvider.get().getReader(versionUrl), 4096)) { String line; while ((line = reader.readLine()) != null) { if (artifactBody.length() > 0) {