diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-04-24 09:15:05 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-05-11 10:21:55 +0200 |
commit | 14a5c982e5f1b28354a853073bd3e225b3914abe (patch) | |
tree | e298a2948f49628880f8d5290451adc14a920613 /sonar-home | |
parent | cba928d505985972e13c8e895b490a52702af925 (diff) | |
download | sonarqube-14a5c982e5f1b28354a853073bd3e225b3914abe.tar.gz sonarqube-14a5c982e5f1b28354a853073bd3e225b3914abe.zip |
SONAR-6370 isolate plugin classloader from core
Diffstat (limited to 'sonar-home')
-rw-r--r-- | sonar-home/src/main/java/org/sonar/home/cache/FileCache.java | 44 | ||||
-rw-r--r-- | sonar-home/src/test/java/org/sonar/home/cache/FileCacheTest.java | 29 |
2 files changed, 1 insertions, 72 deletions
diff --git a/sonar-home/src/main/java/org/sonar/home/cache/FileCache.java b/sonar-home/src/main/java/org/sonar/home/cache/FileCache.java index 3588a908b4b..63a1168639d 100644 --- a/sonar-home/src/main/java/org/sonar/home/cache/FileCache.java +++ b/sonar-home/src/main/java/org/sonar/home/cache/FileCache.java @@ -20,15 +20,12 @@ package org.sonar.home.cache; import org.apache.commons.io.FileUtils; -import org.sonar.api.utils.ZipUtils; import org.sonar.home.log.Log; import javax.annotation.CheckForNull; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; -import java.util.zip.ZipEntry; /** * This class is responsible for managing Sonar batch file cache. You can put file into cache and @@ -138,7 +135,7 @@ public class FileCache { } } - private File createTempDir() { + public File createTempDir() { String baseName = System.currentTimeMillis() + "-"; for (int counter = 0; counter < TEMP_DIR_ATTEMPTS; counter++) { @@ -161,43 +158,4 @@ public class FileCache { } return dir; } - - /** - * Unzip a cached file. Unzip is done only the first time. - * @param cachedFile - * @return directory where cachedFile was unzipped - * @throws IOException - */ - public File unzip(File cachedFile) throws IOException { - String filename = cachedFile.getName(); - File destDir = new File(cachedFile.getParentFile(), filename + "_unzip"); - File lockFile = new File(cachedFile.getParentFile(), filename + "_unzip.lock"); - if (!destDir.exists()) { - FileOutputStream out = new FileOutputStream(lockFile); - try { - java.nio.channels.FileLock lock = out.getChannel().lock(); - try { - // Recheck in case of concurrent processes - if (!destDir.exists()) { - File tempDir = createTempDir(); - ZipUtils.unzip(cachedFile, tempDir, new LibFilter()); - FileUtils.moveDirectory(tempDir, destDir); - } - } finally { - lock.release(); - } - } finally { - out.close(); - FileUtils.deleteQuietly(lockFile); - } - } - return destDir; - } - - private static final class LibFilter implements ZipUtils.ZipEntryFilter { - @Override - public boolean accept(ZipEntry entry) { - return entry.getName().startsWith("META-INF/lib"); - } - } } diff --git a/sonar-home/src/test/java/org/sonar/home/cache/FileCacheTest.java b/sonar-home/src/test/java/org/sonar/home/cache/FileCacheTest.java index be82711e85e..2d90503598d 100644 --- a/sonar-home/src/test/java/org/sonar/home/cache/FileCacheTest.java +++ b/sonar-home/src/test/java/org/sonar/home/cache/FileCacheTest.java @@ -28,7 +28,6 @@ import org.sonar.home.log.Slf4jLog; import java.io.File; import java.io.IOException; -import java.net.URISyntaxException; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.any; @@ -120,32 +119,4 @@ public class FileCacheTest { assertThat(FileUtils.readFileToString(cachedFile)).contains("downloaded by"); } - @Test - public void unzip_from_cache() throws IOException, URISyntaxException { - final File samplePlugin = new File(this.getClass().getResource("/sonar-checkstyle-plugin-2.8.jar").toURI()); - FileHashes hashes = mock(FileHashes.class); - final FileCache cache = new FileCache(tempFolder.newFolder(), log, hashes); - when(hashes.of(any(File.class))).thenReturn("ABCDE"); - - FileCache.Downloader downloader = new FileCache.Downloader() { - public void download(String filename, File toFile) throws IOException { - FileUtils.copyFile(samplePlugin, toFile); - } - }; - final File cachedFile = cache.get("sonar-checkstyle-plugin-2.8.jar", "ABCDE", downloader); - assertThat(cachedFile).isNotNull().exists().isFile(); - assertThat(cachedFile.getName()).isEqualTo("sonar-checkstyle-plugin-2.8.jar"); - - File pluginDepsDir = cache.unzip(cachedFile); - - assertThat(pluginDepsDir.listFiles()).hasSize(1); - File metaDir = new File(pluginDepsDir, "META-INF"); - assertThat(metaDir.listFiles()).hasSize(1); - File libDir = new File(metaDir, "lib"); - assertThat(libDir.listFiles()).hasSize(3); - assertThat(libDir.listFiles()).containsOnly(new File(libDir, "antlr-2.7.6.jar"), new File(libDir, "checkstyle-5.1.jar"), new File(libDir, "commons-cli-1.0.jar")); - - // Unzip again should not do anything as it is already unzipped - cache.unzip(cachedFile); - } } |