Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.grails.cli.compiler.grape;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import groovy.grape.GrapeEngine;
import groovy.lang.GroovyClassLoader;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.collection.CollectRequest;
import org.eclipse.aether.graph.Dependency;
import org.eclipse.aether.graph.Exclusion;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.resolution.ArtifactResult;
import org.eclipse.aether.resolution.DependencyRequest;
import org.eclipse.aether.resolution.DependencyResult;
import org.eclipse.aether.util.artifact.JavaScopes;
import org.eclipse.aether.util.filter.DependencyFilterUtils;
/**
* A {@link GrapeEngine} implementation that uses
* Maven Resolver, the
* dependency resolution system used by Maven.
*
* @author Andy Wilkinson
* @author Phillip Webb
* @since 2022.1.0
*/
@SuppressWarnings("rawtypes")
public class MavenResolverGrapeEngine implements GrapeEngine {
private static final Collection WILDCARD_EXCLUSION;
static {
List exclusions = new ArrayList<>();
exclusions.add(new Exclusion("*", "*", "*", "*"));
WILDCARD_EXCLUSION = Collections.unmodifiableList(exclusions);
}
private final DependencyResolutionContext resolutionContext;
private final ProgressReporter progressReporter;
private final GroovyClassLoader classLoader;
private final DefaultRepositorySystemSession session;
private final RepositorySystem repositorySystem;
private final List repositories;
public MavenResolverGrapeEngine(GroovyClassLoader classLoader, RepositorySystem repositorySystem,
DefaultRepositorySystemSession repositorySystemSession, List remoteRepositories,
DependencyResolutionContext resolutionContext, boolean quiet) {
this.classLoader = classLoader;
this.repositorySystem = repositorySystem;
this.session = repositorySystemSession;
this.resolutionContext = resolutionContext;
this.repositories = new ArrayList<>();
List remotes = new ArrayList<>(remoteRepositories);
Collections.reverse(remotes); // priority is reversed in addRepository
for (RemoteRepository repository : remotes) {
addRepository(repository);
}
this.progressReporter = getProgressReporter(this.session, quiet);
}
private ProgressReporter getProgressReporter(DefaultRepositorySystemSession session, boolean quiet) {
String progressReporter = (quiet ? "none"
: System.getProperty("org.grails.cli.compiler.grape.ProgressReporter"));
if ("detail".equals(progressReporter) || Boolean.getBoolean("groovy.grape.report.downloads")) {
return new DetailedProgressReporter(session, System.out);
}
if ("none".equals(progressReporter)) {
return () -> {
};
}
return new SummaryProgressReporter(session, System.out);
}
@Override
public Object grab(Map args) {
return grab(args, args);
}
@Override
public Object grab(Map args, Map... dependencyMaps) {
List exclusions = createExclusions(args);
List dependencies = createDependencies(dependencyMaps, exclusions);
try {
List files = resolve(dependencies);
GroovyClassLoader classLoader = getClassLoader(args);
for (File file : files) {
classLoader.addURL(file.toURI().toURL());
}
}
catch (MalformedURLException ex) {
throw new DependencyResolutionFailedException(ex);
}
return null;
}
@SuppressWarnings("unchecked")
private List createExclusions(Map, ?> args) {
List exclusions = new ArrayList<>();
if (args != null) {
List