org.gradle.nativeplatform.internal.NativeDependentBinariesResolutionStrategy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-api Show documentation
Show all versions of gradle-api Show documentation
Gradle 6.9.1 API redistribution.
/*
* Copyright 2016 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.nativeplatform.internal;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Ordering;
import com.google.common.collect.Sets;
import org.gradle.api.CircularReferenceException;
import org.gradle.api.Nullable;
import org.gradle.api.internal.project.ProjectInternal;
import org.gradle.api.internal.project.ProjectRegistry;
import org.gradle.api.internal.resolve.ProjectModelResolver;
import org.gradle.api.reporting.dependents.internal.DependentComponentsUtils;
import org.gradle.internal.graph.DirectedGraph;
import org.gradle.internal.graph.DirectedGraphRenderer;
import org.gradle.internal.graph.GraphNodeRenderer;
import org.gradle.internal.logging.text.StyledTextOutput;
import org.gradle.language.base.plugins.ComponentModelBasePlugin;
import org.gradle.model.ModelMap;
import org.gradle.model.internal.registry.ModelRegistry;
import org.gradle.model.internal.type.ModelTypes;
import org.gradle.nativeplatform.NativeComponentSpec;
import org.gradle.nativeplatform.NativeLibraryBinary;
import org.gradle.platform.base.VariantComponentSpec;
import org.gradle.platform.base.internal.BinarySpecInternal;
import org.gradle.platform.base.internal.dependents.AbstractDependentBinariesResolutionStrategy;
import org.gradle.platform.base.internal.dependents.DefaultDependentBinariesResolvedResult;
import org.gradle.platform.base.internal.dependents.DependentBinariesResolvedResult;
import java.io.StringWriter;
import java.util.ArrayDeque;
import java.util.Collection;
import java.util.Deque;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import static com.google.common.base.Preconditions.checkNotNull;
public class NativeDependentBinariesResolutionStrategy extends AbstractDependentBinariesResolutionStrategy {
public interface TestSupport {
boolean isTestSuite(BinarySpecInternal target);
List getTestDependencies(NativeBinarySpecInternal nativeBinary);
}
private static class State {
private final Map> dependencies = Maps.newLinkedHashMap();
private final Map> dependents = Maps.newHashMap();
void registerBinary(NativeBinarySpecInternal binary) {
if (dependencies.get(binary) == null) {
dependencies.put(binary, Sets.newLinkedHashSet());
}
}
List getDependents(NativeBinarySpecInternal target) {
List result = dependents.get(target);
if (result == null) {
result = Lists.newArrayList();
for (NativeBinarySpecInternal dependentBinary : dependencies.keySet()) {
if (dependencies.get(dependentBinary).contains(target)) {
result.add(dependentBinary);
}
}
dependents.put(target, result);
}
return result;
}
}
public static final String NAME = "native";
private final ProjectRegistry projectRegistry;
private final ProjectModelResolver projectModelResolver;
private final Cache stateCache = CacheBuilder.newBuilder()
.maximumSize(1)
.expireAfterAccess(10, TimeUnit.SECONDS)
.build();
private final Cache> resultsCache = CacheBuilder.>newBuilder()
.maximumSize(3000)
.expireAfterAccess(10, TimeUnit.SECONDS)
.build();
private TestSupport testSupport;
public NativeDependentBinariesResolutionStrategy(ProjectRegistry projectRegistry, ProjectModelResolver projectModelResolver) {
super();
checkNotNull(projectRegistry, "ProjectRegistry must not be null");
checkNotNull(projectModelResolver, "ProjectModelResolver must not be null");
this.projectRegistry = projectRegistry;
this.projectModelResolver = projectModelResolver;
}
@Override
public String getName() {
return NAME;
}
public void setTestSupport(TestSupport testSupport) {
this.testSupport = testSupport;
}
@Nullable
@Override
protected List resolveDependents(BinarySpecInternal target) {
if (!(target instanceof NativeBinarySpecInternal)) {
return null;
}
return resolveDependentBinaries((NativeBinarySpecInternal) target);
}
private List resolveDependentBinaries(NativeBinarySpecInternal target) {
State state = getState();
return buildResolvedResult(target, state);
}
private State getState() {
try {
return stateCache.get("state", new Callable() {
@Override
public State call() {
return buildState();
}
});
} catch (ExecutionException ex) {
throw new RuntimeException("Unable to build native dependent binaries resolution cache", ex);
}
}
private State buildState() {
State state = new State();
List orderedProjects = Ordering.usingToString().sortedCopy(projectRegistry.getAllProjects());
for (ProjectInternal project : orderedProjects) {
if (project.getPlugins().hasPlugin(ComponentModelBasePlugin.class)) {
ModelRegistry modelRegistry = projectModelResolver.resolveProjectModel(project.getPath());
ModelMap components = modelRegistry.realize("components", ModelTypes.modelMap(NativeComponentSpec.class));
for (NativeBinarySpecInternal binary : allBinariesOf(components.withType(VariantComponentSpec.class))) {
state.registerBinary(binary);
}
ModelMap
© 2015 - 2025 Weber Informatics LLC | Privacy Policy