aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-scanner-engine')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/PluginFiles.java38
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/PluginFilesTest.java101
2 files changed, 4 insertions, 135 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/PluginFiles.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/PluginFiles.java
index 8e31b44d4ad..850d0e47a81 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/PluginFiles.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/PluginFiles.java
@@ -20,7 +20,6 @@
package org.sonar.scanner.bootstrap;
import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -28,10 +27,7 @@ import java.net.HttpURLConnection;
import java.nio.file.Files;
import java.util.Objects;
import java.util.Optional;
-import java.util.jar.JarOutputStream;
-import java.util.jar.Pack200;
import java.util.stream.Stream;
-import java.util.zip.GZIPInputStream;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.FileUtils;
import org.sonar.api.config.Configuration;
@@ -48,9 +44,6 @@ public class PluginFiles {
private static final Logger LOGGER = Loggers.get(PluginFiles.class);
private static final String MD5_HEADER = "Sonar-MD5";
- private static final String COMPRESSION_HEADER = "Sonar-Compression";
- private static final String PACK200 = "pack200";
- private static final String UNCOMPRESSED_MD5_HEADER = "Sonar-UncompressedMD5";
private final DefaultScannerWsClient wsClient;
private final File cacheDir;
@@ -94,13 +87,6 @@ public class PluginFiles {
.setParam("plugin", plugin.key)
.setTimeOutInMs(5 * 60_000);
- try {
- Class.forName("java.util.jar.Pack200");
- request.setParam("acceptCompressions", PACK200);
- } catch (ClassNotFoundException e) {
- // ignore and don't use any compression
- }
-
File downloadedFile = newTempFile();
LOGGER.debug("Download plugin '{}' to '{}'", plugin.key, downloadedFile);
@@ -123,15 +109,9 @@ public class PluginFiles {
// un-compress if needed
String cacheMd5;
File tempJar;
- Optional<String> compression = response.header(COMPRESSION_HEADER);
- if (compression.isPresent() && PACK200.equals(compression.get())) {
- tempJar = unpack200(plugin.key, downloadedFile);
- cacheMd5 = response.header(UNCOMPRESSED_MD5_HEADER).orElseThrow(() -> new IllegalStateException(format(
- "Fail to download plugin [%s]. Request to %s did not return header %s.", plugin.key, response.requestUrl(), UNCOMPRESSED_MD5_HEADER)));
- } else {
- tempJar = downloadedFile;
- cacheMd5 = expectedMd5.get();
- }
+
+ tempJar = downloadedFile;
+ cacheMd5 = expectedMd5.get();
// put in cache
File jarInCache = jarInCache(plugin.key, cacheMd5);
@@ -177,18 +157,6 @@ public class PluginFiles {
}
}
- private File unpack200(String pluginKey, File compressedFile) {
- LOGGER.debug("Unpacking plugin {}", pluginKey);
- File jar = newTempFile();
- try (InputStream input = new GZIPInputStream(new BufferedInputStream(FileUtils.openInputStream(compressedFile)));
- JarOutputStream output = new JarOutputStream(new BufferedOutputStream(FileUtils.openOutputStream(jar)))) {
- Pack200.newUnpacker().unpack(input, output);
- } catch (IOException e) {
- throw new IllegalStateException(format("Fail to download plugin [%s]. Pack200 error.", pluginKey), e);
- }
- return jar;
- }
-
private static String computeMd5(File file) {
try (InputStream fis = new BufferedInputStream(FileUtils.openInputStream(file))) {
return DigestUtils.md5Hex(fis);
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/PluginFilesTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/PluginFilesTest.java
index 233028242bd..f10f1659a66 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/PluginFilesTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/PluginFilesTest.java
@@ -19,26 +19,15 @@
*/
package org.sonar.scanner.bootstrap;
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.io.OutputStream;
-import java.nio.file.Files;
import java.util.Collections;
import java.util.Optional;
-import java.util.jar.JarInputStream;
-import java.util.jar.JarOutputStream;
-import java.util.jar.Pack200;
-import java.util.zip.GZIPInputStream;
-import java.util.zip.GZIPOutputStream;
import javax.annotation.Nullable;
import okhttp3.HttpUrl;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
-import okhttp3.mockwebserver.RecordedRequest;
import okio.Buffer;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.FileUtils;
@@ -107,7 +96,7 @@ public class PluginFilesTest {
verifySameContent(result, tempJar);
HttpUrl requestedUrl = server.takeRequest().getRequestUrl();
assertThat(requestedUrl.encodedPath()).isEqualTo("/api/plugins/download");
- assertThat(requestedUrl.encodedQuery()).isEqualTo("plugin=foo&acceptCompressions=pack200");
+ assertThat(requestedUrl.encodedQuery()).isEqualTo("plugin=foo");
// get from cache on second call
result = underTest.get(plugin).get();
@@ -116,24 +105,6 @@ public class PluginFilesTest {
}
@Test
- public void download_compressed_and_add_uncompressed_to_cache_if_missing() throws Exception {
- FileAndMd5 jar = new FileAndMd5();
- enqueueCompressedDownload(jar, true);
-
- InstalledPlugin plugin = newInstalledPlugin("foo", jar.md5);
- File result = underTest.get(plugin).get();
-
- verifySameContentAfterCompression(jar.file, result);
- RecordedRequest recordedRequest = server.takeRequest();
- assertThat(recordedRequest.getRequestUrl().queryParameter("acceptCompressions")).isEqualTo("pack200");
-
- // get from cache on second call
- result = underTest.get(plugin).get();
- verifySameContentAfterCompression(jar.file, result);
- assertThat(server.getRequestCount()).isOne();
- }
-
- @Test
public void return_empty_if_plugin_not_found_on_server() {
server.enqueue(new MockResponse().setResponseCode(404));
@@ -154,16 +125,6 @@ public class PluginFilesTest {
}
@Test
- public void fail_if_integrity_of_compressed_download_is_not_valid() throws Exception {
- FileAndMd5 jar = new FileAndMd5();
- enqueueCompressedDownload(jar, false);
-
- InstalledPlugin plugin = newInstalledPlugin("foo", jar.md5);
-
- expectISE("foo", "was expected to have checksum invalid_hash but had ", () -> underTest.get(plugin).get());
- }
-
- @Test
public void fail_if_md5_header_is_missing_from_response() throws IOException {
File tempJar = temp.newFile();
enqueueDownload(tempJar, null);
@@ -173,19 +134,6 @@ public class PluginFilesTest {
}
@Test
- public void fail_if_compressed_download_cannot_be_uncompressed() {
- MockResponse response = new MockResponse().setBody("not binary");
- response.setHeader("Sonar-MD5", DigestUtils.md5Hex("not binary"));
- response.setHeader("Sonar-UncompressedMD5", "abc");
- response.setHeader("Sonar-Compression", "pack200");
- server.enqueue(response);
-
- InstalledPlugin plugin = newInstalledPlugin("foo", "abc");
-
- expectISE("foo", "Pack200 error", () -> underTest.get(plugin).get());
- }
-
- @Test
public void fail_if_server_returns_error() {
server.enqueue(new MockResponse().setResponseCode(500));
InstalledPlugin plugin = newInstalledPlugin("foo", "abc");
@@ -260,26 +208,6 @@ public class PluginFilesTest {
server.enqueue(response);
}
- /**
- * Enqueue download of file with a MD5 that may not be returned (null) or not valid
- */
- private void enqueueCompressedDownload(FileAndMd5 jar, boolean validMd5) throws IOException {
- Buffer body = new Buffer();
-
- ByteArrayOutputStream bytes = new ByteArrayOutputStream();
- try (JarInputStream in = new JarInputStream(new BufferedInputStream(Files.newInputStream(jar.file.toPath())));
- OutputStream output = new GZIPOutputStream(new BufferedOutputStream(bytes))) {
- Pack200.newPacker().pack(in, output);
- }
- body.write(bytes.toByteArray());
-
- MockResponse response = new MockResponse().setBody(body);
- response.setHeader("Sonar-MD5", validMd5 ? DigestUtils.md5Hex(bytes.toByteArray()) : "invalid_hash");
- response.setHeader("Sonar-UncompressedMD5", jar.md5);
- response.setHeader("Sonar-Compression", "pack200");
- server.enqueue(response);
- }
-
private static InstalledPlugin newInstalledPlugin(String pluginKey, String fileChecksum) {
InstalledPlugin plugin = new InstalledPlugin();
plugin.key = pluginKey;
@@ -293,33 +221,6 @@ public class PluginFilesTest {
assertThat(file1).hasSameContentAs(file2.file);
}
- /**
- * Packing and unpacking a JAR generates a different file.
- */
- private void verifySameContentAfterCompression(File file1, File file2) throws IOException {
- assertThat(file1).isFile().exists();
- assertThat(file2).isFile().exists();
- assertThat(packAndUnpackJar(file1)).hasSameContentAs(packAndUnpackJar(file2));
- }
-
- private File packAndUnpackJar(File source) throws IOException {
- File packed = temp.newFile();
- try (JarInputStream in = new JarInputStream(new BufferedInputStream(Files.newInputStream(source.toPath())));
- OutputStream out = new GZIPOutputStream(new BufferedOutputStream(Files.newOutputStream(packed.toPath())))) {
- Pack200.newPacker().pack(in, out);
- }
-
- File to = temp.newFile();
- try (InputStream input = new GZIPInputStream(new BufferedInputStream(Files.newInputStream(packed.toPath())));
- JarOutputStream output = new JarOutputStream(new BufferedOutputStream(Files.newOutputStream(to.toPath())))) {
- Pack200.newUnpacker().unpack(input, output);
- } catch (IOException e) {
- throw new IllegalStateException(e);
- }
-
- return to;
- }
-
private void expectISE(String pluginKey, String message, ThrowingCallable shouldRaiseThrowable) {
assertThatThrownBy(shouldRaiseThrowable)
.isInstanceOf(IllegalStateException.class)