Search in sources :

Example 1 with FileAndMd5

use of org.sonar.server.plugins.PluginFilesAndMd5.FileAndMd5 in project sonarqube by SonarSource.

the class GeneratePluginIndexTest method newInstalledPlugin.

private ServerPlugin newInstalledPlugin(String key, boolean supportSonarLint) throws IOException {
    FileAndMd5 jar = new FileAndMd5(temp.newFile());
    PluginInfo pluginInfo = new PluginInfo(key).setJarFile(jar.getFile()).setSonarLintSupported(supportSonarLint);
    return new ServerPlugin(pluginInfo, BUNDLED, null, jar, null, null);
}
Also used : FileAndMd5(org.sonar.server.plugins.PluginFilesAndMd5.FileAndMd5) PluginInfo(org.sonar.core.platform.PluginInfo) ServerPlugin(org.sonar.server.plugins.ServerPlugin)

Example 2 with FileAndMd5

use of org.sonar.server.plugins.PluginFilesAndMd5.FileAndMd5 in project sonarqube by SonarSource.

the class DetectPluginChangeTest method addPluginToFs.

private void addPluginToFs(String key, String hash, PluginType type) {
    PluginInfo pluginInfo = new PluginInfo(key);
    Plugin plugin = mock(Plugin.class);
    FileAndMd5 fileAndMd5 = mock(FileAndMd5.class);
    when(fileAndMd5.getMd5()).thenReturn(hash);
    ServerPlugin serverPlugin = new ServerPlugin(pluginInfo, type, plugin, fileAndMd5, null);
    pluginRepository.addPlugin(serverPlugin);
}
Also used : FileAndMd5(org.sonar.server.plugins.PluginFilesAndMd5.FileAndMd5) PluginInfo(org.sonar.core.platform.PluginInfo) Plugin(org.sonar.api.Plugin)

Example 3 with FileAndMd5

use of org.sonar.server.plugins.PluginFilesAndMd5.FileAndMd5 in project sonarqube by SonarSource.

the class ServerPluginManagerTest method newPluginFilesAndMd5.

private static PluginFilesAndMd5 newPluginFilesAndMd5(String name) {
    FileAndMd5 jar = mock(FileAndMd5.class);
    when(jar.getFile()).thenReturn(new File(name));
    when(jar.getMd5()).thenReturn(name + "-md5");
    FileAndMd5 compressed = mock(FileAndMd5.class);
    when(compressed.getFile()).thenReturn(new File(name + "-compressed"));
    when(compressed.getMd5()).thenReturn(name + "-compressed-md5");
    return new PluginFilesAndMd5(jar, compressed);
}
Also used : FileAndMd5(org.sonar.server.plugins.PluginFilesAndMd5.FileAndMd5) File(java.io.File)

Example 4 with FileAndMd5

use of org.sonar.server.plugins.PluginFilesAndMd5.FileAndMd5 in project sonarqube by SonarSource.

the class DownloadAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    String pluginKey = request.mandatoryParam(PLUGIN_PARAM);
    Optional<ServerPlugin> file = pluginRepository.findPlugin(pluginKey);
    if (!file.isPresent()) {
        throw new NotFoundException("Plugin " + pluginKey + " not found");
    }
    FileAndMd5 downloadedFile;
    FileAndMd5 compressedJar = file.get().getCompressed();
    if (compressedJar != null && PACK200.equals(request.param(ACCEPT_COMPRESSIONS_PARAM))) {
        response.stream().setMediaType("application/octet-stream");
        response.setHeader("Sonar-Compression", PACK200);
        response.setHeader("Sonar-UncompressedMD5", file.get().getJar().getMd5());
        downloadedFile = compressedJar;
    } else {
        response.stream().setMediaType("application/java-archive");
        downloadedFile = file.get().getJar();
    }
    response.setHeader("Sonar-MD5", downloadedFile.getMd5());
    try (InputStream input = FileUtils.openInputStream(downloadedFile.getFile())) {
        IOUtils.copyLarge(input, response.stream().output());
    }
}
Also used : FileAndMd5(org.sonar.server.plugins.PluginFilesAndMd5.FileAndMd5) InputStream(java.io.InputStream) NotFoundException(org.sonar.server.exceptions.NotFoundException) ServerPlugin(org.sonar.server.plugins.ServerPlugin)

Example 5 with FileAndMd5

use of org.sonar.server.plugins.PluginFilesAndMd5.FileAndMd5 in project sonarqube by SonarSource.

the class InstalledActionTest method plugin.

private ServerPlugin plugin(String key, String name) throws IOException {
    File file = temp.newFile();
    PluginInfo info = new PluginInfo(key).setName(name).setVersion(Version.create("1.0"));
    info.setJarFile(file);
    return new ServerPlugin(info, PluginType.BUNDLED, null, new FileAndMd5(file), null, null);
}
Also used : FileAndMd5(org.sonar.server.plugins.PluginFilesAndMd5.FileAndMd5) PluginInfo(org.sonar.core.platform.PluginInfo) ServerPlugin(org.sonar.server.plugins.ServerPlugin) File(java.io.File)

Aggregations

FileAndMd5 (org.sonar.server.plugins.PluginFilesAndMd5.FileAndMd5)8 ServerPlugin (org.sonar.server.plugins.ServerPlugin)7 PluginInfo (org.sonar.core.platform.PluginInfo)6 File (java.io.File)4 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1 InputStream (java.io.InputStream)1 Random (java.util.Random)1 Test (org.junit.Test)1 Plugin (org.sonar.api.Plugin)1 NotFoundException (org.sonar.server.exceptions.NotFoundException)1 PluginFilesAndMd5 (org.sonar.server.plugins.PluginFilesAndMd5)1 UpdateCenter (org.sonar.updatecenter.common.UpdateCenter)1