Skip to content

Commit

Permalink
feat(cli): don't fetch dependencies on plugin resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
tchiotludo committed Sep 1, 2023
1 parent 0965126 commit c0b6132
Showing 1 changed file with 24 additions and 34 deletions.
58 changes: 24 additions & 34 deletions cli/src/main/java/io/kestra/cli/plugins/PluginDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import com.google.common.collect.ImmutableList;
import io.micronaut.context.annotation.Value;
import io.micronaut.core.annotation.Nullable;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
Expand All @@ -10,25 +13,17 @@
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.collection.CollectRequest;
import org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory;
import org.eclipse.aether.graph.Dependency;
import org.eclipse.aether.graph.DependencyFilter;
import org.eclipse.aether.impl.DefaultServiceLocator;
import org.eclipse.aether.repository.LocalRepository;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.resolution.ArtifactRequest;
import org.eclipse.aether.resolution.ArtifactResolutionException;
import org.eclipse.aether.resolution.ArtifactResult;
import org.eclipse.aether.resolution.DependencyRequest;
import org.eclipse.aether.resolution.DependencyResolutionException;
import org.eclipse.aether.spi.connector.RepositoryConnectorFactory;
import org.eclipse.aether.spi.connector.transport.TransporterFactory;
import org.eclipse.aether.transport.file.FileTransporterFactory;
import org.eclipse.aether.transport.http.HttpTransporterFactory;
import org.eclipse.aether.util.filter.DependencyFilterUtils;

import io.micronaut.core.annotation.Nullable;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import org.eclipse.aether.util.repository.AuthenticationBuilder;

import java.io.File;
Expand All @@ -42,7 +37,7 @@
@Singleton
@Slf4j
public class PluginDownloader {
private List<RepositoryConfig> repositoryConfigs;
private final List<RepositoryConfig> repositoryConfigs;
private final RepositorySystem system;
private final RepositorySystemSession session;

Expand All @@ -60,22 +55,14 @@ public void addRepository(RepositoryConfig repositoryConfig) {
this.repositoryConfigs.add(repositoryConfig);
}

public List<URL> resolve(List<String> dependencies) throws DependencyResolutionException, MalformedURLException {
public List<URL> resolve(List<String> dependencies) throws MalformedURLException, ArtifactResolutionException {
List<RemoteRepository> repositories = remoteRepositories();

ImmutableList.Builder<URL> urls = ImmutableList.builder();

for (String dependency : dependencies) {
log.debug("Resolving plugin {}", dependency);

List<ArtifactResult> artifactResults = resolveArtifacts(repositories, dependency);
List<URL> localUrls = resolveUrls(artifactResults);
log.debug("Resolved Plugin {} with {}", dependency, localUrls);
List<ArtifactResult> artifactResults = resolveArtifacts(repositories, dependencies);
List<URL> localUrls = resolveUrls(artifactResults);
log.debug("Resolved Plugin {} with {}", dependencies, localUrls);

urls.addAll(localUrls);
}

return urls.build();
return localUrls;
}

private List<RemoteRepository> remoteRepositories() {
Expand Down Expand Up @@ -139,18 +126,21 @@ private RepositorySystemSession repositorySystemSession(RepositorySystem system,
return session;
}

private List<ArtifactResult> resolveArtifacts(List<RemoteRepository> repositories, String dependency) throws DependencyResolutionException {
Artifact artifact = new DefaultArtifact(dependency);

DependencyFilter classpathFlter = DependencyFilterUtils.classpathFilter("jar");

CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(new Dependency(artifact, "jar"));
collectRequest.setRepositories(repositories);
private List<ArtifactResult> resolveArtifacts(List<RemoteRepository> repositories, List<String> dependencies) throws ArtifactResolutionException {
List<ArtifactRequest> requests = dependencies
.stream()
.map(s -> {
Artifact artifact = new DefaultArtifact(s);

DependencyRequest depRequest = new DependencyRequest(collectRequest, classpathFlter);
return new ArtifactRequest(
artifact,
repositories,
null
);
})
.collect(Collectors.toList());

return system.resolveDependencies(session, depRequest).getArtifactResults();
return system.resolveArtifacts(session, requests);
}

private List<URL> resolveUrls(List<ArtifactResult> artifactResults) throws MalformedURLException {
Expand Down

0 comments on commit c0b6132

Please sign in to comment.