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 2010 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
*
* http://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.gradle.api.internal.plugins;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.util.concurrent.UncheckedExecutionException;
import org.gradle.api.internal.initialization.ClassLoaderScope;
import org.gradle.api.plugins.InvalidPluginException;
import org.gradle.internal.Cast;
import org.gradle.internal.UncheckedException;
import org.gradle.plugin.use.PluginId;
import org.gradle.util.internal.GUtil;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Comparator;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
public class DefaultPluginRegistry implements PluginRegistry {
private final PluginRegistry parent;
private final PluginInspector pluginInspector;
private final ClassLoaderScope classLoaderScope;
private final LoadingCache, PluginImplementation>> classMappings;
private final LoadingCache>> idMappings;
public DefaultPluginRegistry(PluginInspector pluginInspector, ClassLoaderScope classLoaderScope) {
this(null, pluginInspector, classLoaderScope);
}
private DefaultPluginRegistry(PluginRegistry parent, final PluginInspector pluginInspector, ClassLoaderScope classLoaderScope) {
this.parent = parent;
this.pluginInspector = pluginInspector;
this.classLoaderScope = classLoaderScope;
this.classMappings = CacheBuilder.newBuilder().build(new PotentialPluginCacheLoader(pluginInspector));
this.idMappings = CacheBuilder.newBuilder().build(new CacheLoader>>() {
@Override
public Optional> load(@Nonnull PluginIdLookupCacheKey key) {
PluginId pluginId = key.getId();
ClassLoader classLoader = key.getClassLoader();
PluginDescriptorLocator locator = new ClassloaderBackedPluginDescriptorLocator(classLoader);
PluginDescriptor pluginDescriptor = locator.findPluginDescriptor(pluginId.toString());
if (pluginDescriptor == null) {
return Optional.empty();
}
String implClassName = pluginDescriptor.getImplementationClassName();
if (!GUtil.isTrue(implClassName)) {
throw new InvalidPluginException(String.format("No implementation class specified for plugin '%s' in %s.", pluginId, pluginDescriptor));
}
final Class> implClass;
try {
implClass = classLoader.loadClass(implClassName);
} catch (ClassNotFoundException e) {
throw new InvalidPluginException(String.format(
"Could not find implementation class '%s' for plugin '%s' specified in %s.", implClassName, pluginId,
pluginDescriptor), e);
}
PotentialPlugin> potentialPlugin = pluginInspector.inspect(implClass);
PluginImplementation