use of org.sonarsource.sonarlint.core.plugin.cache.PluginCache.Copier in project sonarlint-core by SonarSource.
the class ConnectedIssueMediumTest method prepare.
@BeforeClass
public static void prepare() throws Exception {
Path slHome = temp.newFolder().toPath();
Path pluginCache = slHome.resolve("plugins");
/*
* This storage contains one server id "local" and two modules: "test-project" (with an empty QP) and "test-project-2" (with default QP)
*/
Path storage = Paths.get(ConnectedIssueMediumTest.class.getResource("/sample-storage").toURI());
Path tmpStorage = slHome.resolve("storage");
FileUtils.copyDirectory(storage.toFile(), tmpStorage.toFile());
Files.move(tmpStorage.resolve("local"), tmpStorage.resolve(StoragePaths.encodeForFs(SERVER_ID)));
PluginCache cache = PluginCache.create(pluginCache);
PluginReferences.Builder builder = PluginReferences.newBuilder();
builder.addReference(PluginReference.newBuilder().setFilename(PluginLocator.SONAR_JAVASCRIPT_PLUGIN_JAR).setHash(PluginLocator.SONAR_JAVASCRIPT_PLUGIN_JAR_HASH).setKey("javascript").build());
cache.get(PluginLocator.SONAR_JAVASCRIPT_PLUGIN_JAR, PluginLocator.SONAR_JAVASCRIPT_PLUGIN_JAR_HASH, new Copier() {
@Override
public void copy(String filename, Path toFile) throws IOException {
FileUtils.copyURLToFile(PluginLocator.getJavaScriptPluginUrl(), toFile.toFile());
}
});
builder.addReference(PluginReference.newBuilder().setFilename(PluginLocator.SONAR_JAVA_PLUGIN_JAR).setHash(PluginLocator.SONAR_JAVA_PLUGIN_JAR_HASH).setKey("java").build());
cache.get(PluginLocator.SONAR_JAVA_PLUGIN_JAR, PluginLocator.SONAR_JAVA_PLUGIN_JAR_HASH, new Copier() {
@Override
public void copy(String filename, Path toFile) throws IOException {
FileUtils.copyURLToFile(PluginLocator.getJavaPluginUrl(), toFile.toFile());
}
});
ProtobufUtil.writeToFile(builder.build(), tmpStorage.resolve(StoragePaths.encodeForFs(SERVER_ID)).resolve("global").resolve(StoragePaths.PLUGIN_REFERENCES_PB));
// update versions in test storage and create an empty stale module storage
writeModuleStatus(tmpStorage, "test-project", StoragePaths.STORAGE_VERSION);
writeModuleStatus(tmpStorage, JAVA_MODULE_KEY, StoragePaths.STORAGE_VERSION);
writeModuleStatus(tmpStorage, "stale_module", "0");
writeStatus(tmpStorage, VersionUtils.getLibraryVersion());
ConnectedGlobalConfiguration config = ConnectedGlobalConfiguration.builder().setServerId(SERVER_ID).setSonarLintUserHome(slHome).setStorageRoot(tmpStorage).setLogOutput(createNoOpLogOutput()).build();
sonarlint = new ConnectedSonarLintEngineImpl(config);
baseDir = temp.newFolder();
}
use of org.sonarsource.sonarlint.core.plugin.cache.PluginCache.Copier in project sonarlint-core by SonarSource.
the class BrokenStorageMissingPluginMediumTest method prepare.
@BeforeClass
public static void prepare() throws Exception {
Path slHome = temp.newFolder().toPath();
Path pluginCache = slHome.resolve("plugins");
/*
* This storage contains one server id "local" with references to java and javascript plugins but javascript is not in cache
*/
Path storage = Paths.get(BrokenStorageMissingPluginMediumTest.class.getResource("/sample-storage").toURI());
Path tmpStorage = slHome.resolve("storage");
FileUtils.copyDirectory(storage.toFile(), tmpStorage.toFile());
PluginCache cache = PluginCache.create(pluginCache);
PluginReferences.Builder builder = PluginReferences.newBuilder();
builder.addReference(PluginReference.newBuilder().setFilename(PluginLocator.SONAR_JAVASCRIPT_PLUGIN_JAR).setHash(PluginLocator.SONAR_JAVASCRIPT_PLUGIN_JAR_HASH).setKey("javascript").build());
builder.addReference(PluginReference.newBuilder().setFilename(PluginLocator.SONAR_JAVA_PLUGIN_JAR).setHash(PluginLocator.SONAR_JAVA_PLUGIN_JAR_HASH).setKey("java").build());
cache.get(PluginLocator.SONAR_JAVA_PLUGIN_JAR, PluginLocator.SONAR_JAVA_PLUGIN_JAR_HASH, new Copier() {
@Override
public void copy(String filename, Path toFile) throws IOException {
FileUtils.copyURLToFile(PluginLocator.getJavaPluginUrl(), toFile.toFile());
}
});
ProtobufUtil.writeToFile(builder.build(), tmpStorage.resolve("local").resolve("global").resolve(StoragePaths.PLUGIN_REFERENCES_PB));
ConnectedGlobalConfiguration config = ConnectedGlobalConfiguration.builder().setServerId("local").setSonarLintUserHome(slHome).setStorageRoot(tmpStorage).setLogOutput(createNoOpLogOutput()).build();
sonarlint = new ConnectedSonarLintEngineImpl(config);
baseDir = temp.newFolder();
}
use of org.sonarsource.sonarlint.core.plugin.cache.PluginCache.Copier in project sonarlint-core by SonarSource.
the class PluginReferencesDownloaderTest method update_all_plugins_before_6_0.
@Test
public void update_all_plugins_before_6_0() throws Exception {
pluginList.add(new DefaultSonarAnalyzer("scmsvn", "sonar-scm-svn-plugin-1.3-SNAPSHOT.jar", "d0a68d150314d96d3469e0f2246f3537", "1.3-SNAPSHOT", true));
pluginList.add(new DefaultSonarAnalyzer("javascript", "sonar-javascript-plugin-2.10.jar", "79dba9cab72d8d31767f47c03d169598", "2.10", true));
pluginList.add(new DefaultSonarAnalyzer("csharp", "sonar-csharp-plugin-4.4.jar", "e78bc8ac2e376c4a7a2a2cae914bdc52", "4.4", true));
pluginList.add(new DefaultSonarAnalyzer("groovy", "sonar-groovy-plugin-1.2.jar", "14908dd5f3a9b9d795dbc103f0af546f", "1.2", true));
pluginList.add(new DefaultSonarAnalyzer("java", "sonar-java-plugin-3.12-SNAPSHOT.jar", "de5308f43260d357acc97712ce4c5475", "3.12-SNAPSHOT", true));
pluginUpdate.fetchPluginsTo(dest, pluginList);
PluginReferences pluginReferences = ProtobufUtil.readFile(dest.resolve(StoragePaths.PLUGIN_REFERENCES_PB), PluginReferences.parser());
assertThat(pluginReferences.getReferenceList()).extracting("key", "hash", "filename").containsOnly(tuple("scmsvn", "d0a68d150314d96d3469e0f2246f3537", "sonar-scm-svn-plugin-1.3-SNAPSHOT.jar"), tuple("javascript", "79dba9cab72d8d31767f47c03d169598", "sonar-javascript-plugin-2.10.jar"), tuple("csharp", "e78bc8ac2e376c4a7a2a2cae914bdc52", "sonar-csharp-plugin-4.4.jar"), tuple("groovy", "14908dd5f3a9b9d795dbc103f0af546f", "sonar-groovy-plugin-1.2.jar"), tuple("java", "de5308f43260d357acc97712ce4c5475", "sonar-java-plugin-3.12-SNAPSHOT.jar"));
verify(pluginCache).get(eq("sonar-java-plugin-3.12-SNAPSHOT.jar"), eq("de5308f43260d357acc97712ce4c5475"), any(Copier.class));
ArgumentCaptor<Copier> downloaderCaptor = ArgumentCaptor.forClass(Copier.class);
verify(pluginCache).get(eq("sonar-java-plugin-3.12-SNAPSHOT.jar"), eq("de5308f43260d357acc97712ce4c5475"), downloaderCaptor.capture());
Copier downloader = downloaderCaptor.getValue();
WsClientTestUtils.addResponse(wsClient, "/deploy/plugins/java/test.jar", "content");
Path testFile = temp.newFile().toPath();
downloader.copy("test.jar", testFile);
assertThat(testFile).hasContent("content");
}
Aggregations