private ClassPath resolvePluginDependencies(final PluginUseMetaData metadata) { DependencyResolutionServices resolution = dependencyResolutionServicesFactory.create(); RepositoryHandler repositories = resolution.getResolveRepositoryHandler(); final String repoUrl = metadata.implementation.get("repo"); repositories.maven(new Action<MavenArtifactRepository>() { public void execute(MavenArtifactRepository mavenArtifactRepository) { mavenArtifactRepository.setUrl(repoUrl); } }); Dependency dependency = resolution.getDependencyHandler().create(metadata.implementation.get("gav")); ConfigurationContainerInternal configurations = (ConfigurationContainerInternal) resolution.getConfigurationContainer(); ConfigurationInternal configuration = configurations.detachedConfiguration(dependency); try { Set<File> files = configuration.getResolvedConfiguration().getFiles(Specs.satisfyAll()); return new DefaultClassPath(files); } catch (ResolveException e) { throw new DependencyResolutionException("Failed to resolve all plugin dependencies from " + repoUrl, e.getCause()); } }
/** * Creates a Provisioner for the given repositories. * * The first time a project is created, there are ~7 seconds of configuration * which will go away for all subsequent runs. * * Every call to resolve will take about 1 second, even when all artifacts are resolved. */ private static Supplier<Provisioner> createLazyWithRepositories(Consumer<RepositoryHandler> repoConfig) { // Running this takes ~3 seconds the first time it is called. Probably because of classloading. return Suppliers.memoize(() -> { Project project = ProjectBuilder.builder().build(); repoConfig.accept(project.getRepositories()); return mavenCoords -> { Dependency[] deps = mavenCoords.stream() .map(project.getDependencies()::create) .toArray(Dependency[]::new); Configuration config = project.getConfigurations().detachedConfiguration(deps); config.setDescription(mavenCoords.toString()); try { return config.resolve(); } catch (ResolveException e) { /* Provide Maven coordinates in exception message instead of static string 'detachedConfiguration' */ throw new ResolveException(config.getDescription(), e); } }; }); }
public void rethrowFailure() throws ResolveException { if (hasError()) { List<Throwable> failures = new ArrayList<Throwable>(); for (UnresolvedDependency unresolvedDependency : unresolvedDependencies) { failures.add(unresolvedDependency.getProblem()); } throw new ResolveException(configuration.toString(), failures); } }
@Override public void resolveGraph(ConfigurationInternal configuration, ResolverResults results) throws ResolveException { if (configuration.getAllDependencies().isEmpty()) { emptyGraph(configuration, results); } else { delegate.resolveGraph(configuration, results); } }
@Override public void resolveArtifacts(ConfigurationInternal configuration, ResolverResults results) throws ResolveException { if (configuration.getAllDependencies().isEmpty()) { results.artifactsResolved(new EmptyResolvedConfiguration(), new EmptyResults()); } else { delegate.resolveArtifacts(configuration, results); } }
@Override public void resolveGraph(ConfigurationInternal configuration, ResolverResults results) throws ResolveException { try { delegate.resolveGraph(configuration, results); } catch (Throwable e) { results.failed(wrapException(e, configuration)); BrokenResolvedConfiguration broken = new BrokenResolvedConfiguration(e, configuration); results.artifactsResolved(broken, broken); return; } ResolutionResult wrappedResult = new ErrorHandlingResolutionResult(results.getResolutionResult(), configuration); results.graphResolved(wrappedResult, results.getResolvedLocalComponents(), results.getVisitedArtifacts()); }
@Override public void resolveArtifacts(ConfigurationInternal configuration, ResolverResults results) throws ResolveException { try { delegate.resolveArtifacts(configuration, results); } catch (Throwable e) { BrokenResolvedConfiguration broken = new BrokenResolvedConfiguration(e, configuration); results.artifactsResolved(broken, broken); return; } ResolvedConfiguration wrappedConfiguration = new ErrorHandlingResolvedConfiguration(results.getResolvedConfiguration(), configuration); results.artifactsResolved(wrappedConfiguration, results.getVisitedArtifacts()); }
public void rethrowFailure() throws ResolveException { try { resolvedConfiguration.rethrowFailure(); } catch (Throwable e) { throw wrapException(e, configuration); } }
@Override public Set<File> getFiles() throws ResolveException { try { return resolvedConfiguration.getFiles(); } catch (ResolveException e) { throw wrapException(e, configuration); } }
public Set<File> getFiles(Spec<? super Dependency> dependencySpec) throws ResolveException { try { return resolvedConfiguration.getFiles(dependencySpec); } catch (Throwable e) { throw wrapException(e, configuration); } }
public Set<ResolvedDependency> getFirstLevelModuleDependencies() throws ResolveException { try { return resolvedConfiguration.getFirstLevelModuleDependencies(); } catch (Throwable e) { throw wrapException(e, configuration); } }
public Set<ResolvedDependency> getFirstLevelModuleDependencies(Spec<? super Dependency> dependencySpec) throws ResolveException { try { return resolvedConfiguration.getFirstLevelModuleDependencies(dependencySpec); } catch (Throwable e) { throw wrapException(e, configuration); } }
public Set<ResolvedArtifact> getResolvedArtifacts() throws ResolveException { try { return resolvedConfiguration.getResolvedArtifacts(); } catch (Throwable e) { throw wrapException(e, configuration); } }
@Override public ToolProvider select(ScalaPlatform targetPlatform) { try { Configuration scalaClasspath = resolveDependency("org.scala-lang:scala-compiler:" + targetPlatform.getScalaVersion()); Configuration zincClasspath = resolveDependency("com.typesafe.zinc:zinc:" + DefaultScalaToolProvider.DEFAULT_ZINC_VERSION); Set<File> resolvedScalaClasspath = scalaClasspath.resolve(); Set<File> resolvedZincClasspath = zincClasspath.resolve(); return new DefaultScalaToolProvider(gradleUserHomeDir, rootProjectDir, compilerDaemonManager, resolvedScalaClasspath, resolvedZincClasspath); } catch(ResolveException resolveException) { return new NotFoundScalaToolProvider(resolveException); } }
@Override public PlayToolProvider select(PlayPlatform targetPlatform) { try { Set<File> twirlClasspath = resolveToolClasspath(TwirlCompilerFactory.createAdapter(targetPlatform).getDependencyNotation()).resolve(); Set<File> routesClasspath = resolveToolClasspath(RoutesCompilerFactory.createAdapter(targetPlatform).getDependencyNotation()).resolve(); Set<File> javascriptClasspath = resolveToolClasspath(GoogleClosureCompiler.getDependencyNotation()).resolve(); return new DefaultPlayToolProvider(fileResolver, compilerDaemonManager, workerProcessBuilderFactory, targetPlatform, twirlClasspath, routesClasspath, javascriptClasspath); } catch (ResolveException e) { return new UnavailablePlayToolProvider(e); } }
public void resolve(final ConfigurationInternal configuration, final List<? extends ResolutionAwareRepository> repositories, final GlobalDependencyResolutionRules metadataHandler, final ResolverResults results) throws ResolveException { lockingManager.useCache(String.format("resolve %s", configuration), new Runnable() { public void run() { resolver.resolve(configuration, repositories, metadataHandler, results); } }); }
public void resolve(final ConfigurationInternal configuration, final List<? extends ResolutionAwareRepository> repositories, final ModuleMetadataProcessor metadataProcessor, final ResolverResults results) throws ResolveException { lockingManager.useCache(String.format("resolve %s", configuration), new Runnable() { public void run() { resolver.resolve(configuration, repositories, metadataProcessor, results); } }); }
@Override public <T extends Collection<? super File>> T collectFiles(T dest) throws ResolveException { return dest; }
@Override public <T extends Collection<? super ResolvedArtifactResult>> T collectArtifacts(T dest) throws ResolveException { return dest; }
@Override public void rethrowFailure() throws ResolveException { }
@Override public Set<File> getFiles() throws ResolveException { return Collections.emptySet(); }
@Override public Set<ResolvedDependency> getFirstLevelModuleDependencies(Spec<? super Dependency> dependencySpec) throws ResolveException { return Collections.emptySet(); }
private static ResolveException wrapException(Throwable e, ResolveContext resolveContext) { if (e instanceof ResolveException) { return (ResolveException) e; } return new ResolveException(resolveContext.getDisplayName(), e); }
@Override public void rethrowFailure() throws ResolveException { throw wrapException(e, configuration); }
@Override public Set<File> getFiles() throws ResolveException { throw wrapException(e, configuration); }
@Override public Set<File> getFiles(Spec<? super Dependency> dependencySpec) throws ResolveException { throw wrapException(e, configuration); }
@Override public Set<ResolvedDependency> getFirstLevelModuleDependencies() throws ResolveException { throw wrapException(e, configuration); }
@Override public Set<ResolvedDependency> getFirstLevelModuleDependencies(Spec<? super Dependency> dependencySpec) throws ResolveException { throw wrapException(e, configuration); }
@Override public Set<ResolvedArtifact> getResolvedArtifacts() throws ResolveException { throw wrapException(e, configuration); }
@Override public <T extends Collection<? super File>> T collectFiles(T dest) throws ResolveException { throw wrapException(e, configuration); }
@Override public <T extends Collection<? super ResolvedArtifactResult>> T collectArtifacts(T dest) throws ResolveException { throw wrapException(e, configuration); }
public void rethrowFailure() throws ResolveException { configuration.rethrowFailure(); }
@Override public Set<File> getFiles() throws ResolveException { return getFiles(Specs.<Dependency>satisfyAll()); }
public Set<File> getFiles(final Spec<? super Dependency> dependencySpec) throws ResolveException { rethrowFailure(); return configuration.select(dependencySpec, attributes).collectFiles(new LinkedHashSet<File>()); }
public Set<ResolvedDependency> getFirstLevelModuleDependencies() throws ResolveException { rethrowFailure(); return configuration.getFirstLevelModuleDependencies(); }
public Set<ResolvedDependency> getFirstLevelModuleDependencies(Spec<? super Dependency> dependencySpec) throws ResolveException { rethrowFailure(); return configuration.getFirstLevelModuleDependencies(dependencySpec); }
public Set<ResolvedArtifact> getResolvedArtifacts() throws ResolveException { rethrowFailure(); ArtifactCollectingVisitor visitor = new ArtifactCollectingVisitor(); configuration.select(Specs.<Dependency>satisfyAll(), attributes).visitArtifacts(visitor); return visitor.artifacts; }
@Override public <T extends Collection<? super ResolvedArtifactResult>> T collectArtifacts(T dest) throws ResolveException { throw new UnsupportedOperationException("Artifacts have not been resolved."); }
@Override public <T extends Collection<? super File>> T collectFiles(T dest) throws ResolveException { throw new UnsupportedOperationException("Artifacts have not been resolved."); }