mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 00:45:44 +01:00
Check plugin dependencies after download
This commit is contained in:
@@ -19,11 +19,13 @@ class PluginInstaller {
|
||||
|
||||
private final SCMContextProvider context;
|
||||
private final AdvancedHttpClient client;
|
||||
private final SmpDDescriptorExtractor smpDDescriptorExtractor;
|
||||
|
||||
@Inject
|
||||
public PluginInstaller(SCMContextProvider context, AdvancedHttpClient client) {
|
||||
public PluginInstaller(SCMContextProvider context, AdvancedHttpClient client, SmpDDescriptorExtractor smpDDescriptorExtractor) {
|
||||
this.context = context;
|
||||
this.client = client;
|
||||
this.smpDDescriptorExtractor = smpDDescriptorExtractor;
|
||||
}
|
||||
|
||||
@SuppressWarnings("squid:S4790") // hashing should be safe
|
||||
@@ -34,6 +36,17 @@ class PluginInstaller {
|
||||
Files.copy(input, file);
|
||||
|
||||
verifyChecksum(plugin, input.hash(), file);
|
||||
InstalledPluginDescriptor pluginDescriptor = smpDDescriptorExtractor.extractPluginDescriptor(file);
|
||||
if (!pluginDescriptor.getCondition().isSupported()) {
|
||||
cleanup(file);
|
||||
throw new PluginConditionFailedException(
|
||||
pluginDescriptor.getCondition(),
|
||||
String.format(
|
||||
"could not load plugin %s, the plugin condition does not match",
|
||||
pluginDescriptor.getInformation().getId()
|
||||
)
|
||||
);
|
||||
}
|
||||
return new PendingPluginInstallation(plugin.install(), file);
|
||||
} catch (IOException ex) {
|
||||
cleanup(file);
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package sonia.scm.plugin;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
class SmpDDescriptorExtractor {
|
||||
|
||||
InstalledPluginDescriptor extractPluginDescriptor(Path file) throws IOException {
|
||||
try (ZipInputStream zipInputStream = new ZipInputStream(Files.newInputStream(file), StandardCharsets.UTF_8)) {
|
||||
ZipEntry nextEntry;
|
||||
while ((nextEntry = zipInputStream.getNextEntry()) != null) {
|
||||
if ("META-INF/scm/plugin.xml".equals(nextEntry.getName())) {
|
||||
JAXBContext context = JAXBContext.newInstance(ScmModule.class, InstalledPluginDescriptor.class);
|
||||
return (InstalledPluginDescriptor) context.createUnmarshaller().unmarshal(zipInputStream);
|
||||
}
|
||||
}
|
||||
} catch (JAXBException e) {
|
||||
throw new IOException("failed to read descriptor file META-INF/scm/plugin.xml from plugin", e);
|
||||
}
|
||||
throw new IOException("Missing plugin descriptor META-INF/scm/plugin.xml in download package");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user