From b594e3380c4bedfadfcbe798c0257412f6ebd71e Mon Sep 17 00:00:00 2001 From: Lukasz Wawrzyk Date: Fri, 13 Nov 2020 15:04:49 +0100 Subject: [PATCH] Allow multiple plugin resolvers --- .../ideprobe/dependencies/DependencyProvider.scala | 13 +++++++++++-- .../ideprobe/ide/intellij/IntelliJFactory.scala | 10 +++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/driver/sources/src/main/scala/org/virtuslab/ideprobe/dependencies/DependencyProvider.scala b/driver/sources/src/main/scala/org/virtuslab/ideprobe/dependencies/DependencyProvider.scala index 0af2ce3a..1f879f09 100644 --- a/driver/sources/src/main/scala/org/virtuslab/ideprobe/dependencies/DependencyProvider.scala +++ b/driver/sources/src/main/scala/org/virtuslab/ideprobe/dependencies/DependencyProvider.scala @@ -33,11 +33,20 @@ final class IntelliJDependencyProvider( } final class PluginDependencyProvider( - pluginResolver: DependencyResolver[Plugin], + pluginResolvers: Seq[DependencyResolver[Plugin]], resources: ResourceProvider ) { def fetch(plugin: Plugin): Path = { - pluginResolver.resolve(plugin) match { + val noResolversError = Try[Path](error("Dependency resolver list is empty")) + pluginResolvers + .foldLeft(noResolversError) { (result, resolver) => + result.orElse(Try(resolve(plugin, resolver))) + } + .get + } + + private def resolve(plugin: Plugin, resolver: DependencyResolver[Plugin]): Path = { + resolver.resolve(plugin) match { case Artifact(uri) => resources.get(uri) case Sources(id, config) => diff --git a/driver/sources/src/main/scala/org/virtuslab/ideprobe/ide/intellij/IntelliJFactory.scala b/driver/sources/src/main/scala/org/virtuslab/ideprobe/ide/intellij/IntelliJFactory.scala index c52f72f9..acb2b528 100644 --- a/driver/sources/src/main/scala/org/virtuslab/ideprobe/ide/intellij/IntelliJFactory.scala +++ b/driver/sources/src/main/scala/org/virtuslab/ideprobe/ide/intellij/IntelliJFactory.scala @@ -85,18 +85,22 @@ object IntelliJFactory { new IntelliJFactory( new DependencyProvider( new IntelliJDependencyProvider(Seq(IntelliJZipResolver.Community), ResourceProvider.Default), - new PluginDependencyProvider(PluginResolver.Official, ResourceProvider.Default) + new PluginDependencyProvider(Seq(PluginResolver.Official), ResourceProvider.Default) ), IdeProbePaths.Default, DriverConfig() ) - def from(resolversConfig: DependenciesConfig.Resolvers, paths: IdeProbePaths, driverConfig: DriverConfig): IntelliJFactory = { + def from( + resolversConfig: DependenciesConfig.Resolvers, + paths: IdeProbePaths, + driverConfig: DriverConfig + ): IntelliJFactory = { val intelliJResolver = IntelliJZipResolver.from(resolversConfig.intellij) val pluginResolver = PluginResolver.from(resolversConfig.plugins) val resourceProvider = ResourceProvider.from(paths) val intelliJDependencyProvider = new IntelliJDependencyProvider(Seq(intelliJResolver), resourceProvider) - val pluginDependencyProvider = new PluginDependencyProvider(pluginResolver, resourceProvider) + val pluginDependencyProvider = new PluginDependencyProvider(Seq(pluginResolver), resourceProvider) val dependencyProvider = new DependencyProvider(intelliJDependencyProvider, pluginDependencyProvider) new IntelliJFactory(dependencyProvider, paths, driverConfig) }