![JAR search and dependency download from the Maven repository](/logo.png)
org.sonarsource.scanner.lib.internal.LegacyScannerEngineDownloader Maven / Gradle / Ivy
/*
* SonarScanner Java Library
* Copyright (C) 2011-2024 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarsource.scanner.lib.internal;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonarsource.scanner.lib.internal.BootstrapIndexDownloader.JarEntry;
import org.sonarsource.scanner.lib.internal.cache.CachedFile;
import org.sonarsource.scanner.lib.internal.cache.FileCache;
import org.sonarsource.scanner.lib.internal.http.ScannerHttpClient;
import static java.lang.String.format;
/**
* The scanner engine used to be downloaded from /batch/index and /batch/file, and was even made of multiple files to be put on the classpath.
*/
class LegacyScannerEngineDownloader {
private static final Logger LOG = LoggerFactory.getLogger(LegacyScannerEngineDownloader.class);
private final FileCache fileCache;
private final JarExtractor jarExtractor;
private final ScannerFileDownloader scannerFileDownloader;
private final BootstrapIndexDownloader bootstrapIndexDownloader;
LegacyScannerEngineDownloader(ScannerFileDownloader scannerFileDownloader, BootstrapIndexDownloader bootstrapIndexDownloader, FileCache fileCache,
JarExtractor jarExtractor) {
this.scannerFileDownloader = scannerFileDownloader;
this.bootstrapIndexDownloader = bootstrapIndexDownloader;
this.fileCache = fileCache;
this.jarExtractor = jarExtractor;
}
List getOrDownload() {
List files = new ArrayList<>();
LOG.debug("Extract sonar-scanner-java-library-batch in temp...");
files.add(new CachedFile(jarExtractor.extractToTemp("sonar-scanner-java-library-batch"), true));
files.addAll(getOrDownloadScannerEngineFiles());
return files;
}
private List getOrDownloadScannerEngineFiles() {
Collection index = bootstrapIndexDownloader.getIndex();
return index.stream()
.map(jar -> fileCache.getOrDownload(jar.getFilename(), jar.getHash(), "MD5", scannerFileDownloader))
.collect(Collectors.toList());
}
static class ScannerFileDownloader implements FileCache.Downloader {
private final ScannerHttpClient connection;
ScannerFileDownloader(ScannerHttpClient conn) {
this.connection = conn;
}
@Override
public void download(String filename, Path toFile) throws IOException {
connection.downloadFromWebApi(format("/batch/file?name=%s", filename), toFile);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy