public ResolvedComponentResult create() { synchronized (lock) { return cache.load(new Factory<ResolvedComponentResult>() { public ResolvedComponentResult create() { try { return data.read(new BinaryStore.ReadAction<ResolvedComponentResult>() { public ResolvedComponentResult read(Decoder decoder) throws IOException { return deserialize(decoder); } }); } finally { try { data.close(); } catch (IOException e) { throw throwAsUncheckedException(e); } } } }); } }
public StoreSet createStoreSet() { return new StoreSet() { int storeSetId = storeSetBaseId.getAndIncrement(); int binaryStoreId; public DefaultBinaryStore nextBinaryStore() { //one binary store per id+threadId String storeKey = Thread.currentThread().getId() + "-" + binaryStoreId++; return createBinaryStore(storeKey); } public Store<ResolvedComponentResult> newModelCache() { return getNewModelCache().createCachedStore(storeSetId); } public Store<TransientConfigurationResults> oldModelCache() { return getOldModelCache().createCachedStore(storeSetId); } }; }
/** * Gets IDE repository file dependencies. * * @param configuration Configuration * @return IDE repository file dependencies */ public List<IdeExtendedRepoFileDependency> getIdeRepoFileDependencies(Configuration configuration) { ResolutionResult result = getIncomingResolutionResult(configuration); final Set<ResolvedComponentResult> resolvedRepoFileComponents = CollectionUtils.filter(result.getAllComponents(), new Spec<ResolvedComponentResult>() { @Override public boolean isSatisfiedBy(ResolvedComponentResult element) { return element.getId() instanceof ModuleComponentIdentifier; } }); Set<ModuleVersionIdentifier> mappedResolvedDependencies = mapResolvedDependencies(resolvedRepoFileComponents); Set<ResolvedArtifact> artifacts = getExternalArtifacts(configuration); List<IdeExtendedRepoFileDependency> externalDependencies = new ArrayList<IdeExtendedRepoFileDependency>(); for (ResolvedArtifact artifact : artifacts) { if (mappedResolvedDependencies.contains(artifact.getModuleVersion().getId())) { IdeExtendedRepoFileDependency ideRepoFileDependency = new IdeExtendedRepoFileDependency(artifact.getFile()); ideRepoFileDependency.setId(artifact.getModuleVersion().getId()); externalDependencies.add(ideRepoFileDependency); } } return externalDependencies; }
public void resolveGraph(ConfigurationInternal configuration, ResolverResults results) { List<ResolutionAwareRepository> resolutionAwareRepositories = CollectionUtils.collect(repositories, Transformers.cast(ResolutionAwareRepository.class)); StoreSet stores = storeFactory.createStoreSet(); BinaryStore oldModelStore = stores.nextBinaryStore(); Store<TransientConfigurationResults> oldModelCache = stores.oldModelCache(); TransientConfigurationResultsBuilder oldTransientModelBuilder = new TransientConfigurationResultsBuilder(oldModelStore, oldModelCache); DefaultResolvedConfigurationBuilder oldModelBuilder = new DefaultResolvedConfigurationBuilder(oldTransientModelBuilder); ResolvedConfigurationDependencyGraphVisitor oldModelVisitor = new ResolvedConfigurationDependencyGraphVisitor(oldModelBuilder); BinaryStore newModelStore = stores.nextBinaryStore(); Store<ResolvedComponentResult> newModelCache = stores.newModelCache(); StreamingResolutionResultBuilder newModelBuilder = new StreamingResolutionResultBuilder(newModelStore, newModelCache); ResolvedLocalComponentsResultGraphVisitor localComponentsVisitor = new ResolvedLocalComponentsResultGraphVisitor(); DefaultResolvedArtifactsBuilder artifactsBuilder = new DefaultResolvedArtifactsBuilder(buildProjectDependencies); FileDependencyCollectingGraphVisitor fileDependencyVisitor = new FileDependencyCollectingGraphVisitor(); DependencyGraphVisitor graphVisitor = new CompositeDependencyGraphVisitor(oldModelVisitor, newModelBuilder, localComponentsVisitor, fileDependencyVisitor); DependencyArtifactsVisitor artifactsVisitor = new CompositeDependencyArtifactsVisitor(oldModelVisitor, artifactsBuilder); resolver.resolve(configuration, resolutionAwareRepositories, metadataHandler, Specs.<DependencyMetadata>satisfyAll(), graphVisitor, artifactsVisitor, attributesSchema); ArtifactTransformer transformer = new ArtifactTransformer(configuration.getResolutionStrategy(), attributesSchema); VisitedArtifactsResults artifactsResults = artifactsBuilder.complete(); results.graphResolved(newModelBuilder.complete(), localComponentsVisitor, new BuildDependenciesOnlyVisitedArtifactSet(artifactsResults, fileDependencyVisitor, transformer)); results.retainState(new ArtifactResolveState(oldModelBuilder.complete(), artifactsResults, fileDependencyVisitor, oldTransientModelBuilder)); }
public ResolvedComponentResult getRoot() { try { return resolutionResult.getRoot(); } catch (Throwable e) { throw wrapException(e, resolveContext); } }
public Set<ResolvedComponentResult> getAllComponents() { try { return resolutionResult.getAllComponents(); } catch (Throwable e) { throw wrapException(e, resolveContext); } }
private ResolvedComponentResult deserialize(Decoder decoder) { int valuesRead = 0; byte type = -1; Timer clock = Timers.startTimer(); try { DefaultResolutionResultBuilder builder = new DefaultResolutionResultBuilder(); while (true) { type = decoder.readByte(); valuesRead++; switch (type) { case ROOT: // Last entry, complete the result Long rootId = decoder.readSmallLong(); ResolvedComponentResult root = builder.complete(rootId).getRoot(); LOG.debug("Loaded resolution results ({}) from {}", clock.getElapsed(), data); return root; case COMPONENT: ComponentResult component = componentResultSerializer.read(decoder); builder.visitComponent(component); break; case DEPENDENCY: Long fromId = decoder.readSmallLong(); int size = decoder.readSmallInt(); List<DependencyResult> deps = new ArrayList<DependencyResult>(size); for (int i = 0; i < size; i++) { deps.add(dependencyResultSerializer.read(decoder, failures)); } builder.visitOutgoingEdges(fromId, deps); break; default: throw new IOException("Unknown value type read from stream: " + type); } } } catch (IOException e) { throw new RuntimeException("Problems loading the resolution results (" + clock.getElapsed() + "). " + "Read " + valuesRead + " values, last was: " + type, e); } }
public UnresolvedDependencyResult createUnresolvedDependency(ComponentSelector requested, ResolvedComponentResult from, ComponentSelectionReason reason, ModuleVersionResolveException failure) { List<Object> key = asList(requested, from); if (!unresolvedDependencies.containsKey(key)) { unresolvedDependencies.put(key, new DefaultUnresolvedDependencyResult(requested, reason, from, failure)); } return unresolvedDependencies.get(key); }
public ResolvedDependencyResult createResolvedDependency(ComponentSelector requested, ResolvedComponentResult from, DefaultResolvedComponentResult selected) { List<Object> key = asList(requested, from, selected); if (!resolvedDependencies.containsKey(key)) { resolvedDependencies.put(key, new DefaultResolvedDependencyResult(requested, selected, from)); } return resolvedDependencies.get(key); }
private synchronized CachedStoreFactory<ResolvedComponentResult> getNewModelCache() { if (newModelCache == null) { newModelCache = new CachedStoreFactory<ResolvedComponentResult>("Resolution result"); cleanUpLater.add(newModelCache); } return newModelCache; }
private void eachElement(ResolvedComponentResult node, Action<? super ResolvedComponentResult> moduleAction, Action<? super DependencyResult> dependencyAction, Set<ResolvedComponentResult> visited) { if (!visited.add(node)) { return; } moduleAction.execute(node); for (DependencyResult d : node.getDependencies()) { dependencyAction.execute(d); if (d instanceof ResolvedDependencyResult) { eachElement(((ResolvedDependencyResult) d).getSelected(), moduleAction, dependencyAction, visited); } } }
public AbstractDependencyResult(ComponentSelector requested, ResolvedComponentResult from) { assert requested != null; assert from != null; this.from = from; this.requested = requested; }
/** * Gets IDE project dependencies. * * @param configuration Configuration * @param project Project * @return IDE project dependencies */ public List<IdeProjectDependency> getIdeProjectDependencies(Configuration configuration, Project project) { ResolutionResult result = getIncomingResolutionResult(configuration); final Set<ResolvedComponentResult> projectComponents = CollectionUtils.filter(result.getAllComponents(), new Spec<ResolvedComponentResult>() { @Override public boolean isSatisfiedBy(ResolvedComponentResult element) { return element.getId() instanceof ProjectComponentIdentifier; } }); List<IdeProjectDependency> ideProjectDependencies = new ArrayList<IdeProjectDependency>(); ProjectComponentIdentifier thisProjectId = DefaultProjectComponentIdentifier.newProjectId(project); for (ResolvedComponentResult projectComponent : projectComponents) { ProjectComponentIdentifier projectId = (ProjectComponentIdentifier) projectComponent.getId(); if (thisProjectId.equals(projectId)) { continue; } if (!projectId.getBuild().isCurrentBuild()) { // Don't have access to the ProjectInstance: we can't use it to determine the name. ideProjectDependencies.add(new IdeProjectDependency(projectId)); } else { Project resolvedProject = project.project(projectId.getProjectPath()); ideProjectDependencies.add(new IdeProjectDependency(projectId, resolvedProject.getName())); } } return ideProjectDependencies; }
/** * Maps resolved dependencies by module version identifier. * * @param components Resolved dependencies * @return Mapped, resolved dependencies */ private Set<ModuleVersionIdentifier> mapResolvedDependencies(Set<ResolvedComponentResult> components) { Set<ModuleVersionIdentifier> mappedResolvedDependencies = new LinkedHashSet<ModuleVersionIdentifier>(); for (ResolvedComponentResult component : components) { mappedResolvedDependencies.add(component.getModuleVersion()); } return mappedResolvedDependencies; }
private boolean checkForExclusion(VariantDependencies configDependencies, ModuleVersionIdentifier moduleVersion, ResolvedComponentResult resolvedComponentResult) { if (configDependencies.getChecker().checkForExclusion(moduleVersion) || (apDependencies != null && apDependencies .hasSameResolvedDependency( moduleVersion) && !(resolvedComponentResult .getId() instanceof ProjectComponentIdentifier))) { return true; } return false; }
@Override protected boolean checkForExclusion(@NonNull VariantDependencies configDependencies, ModuleVersionIdentifier moduleVersion, ResolvedComponentResult resolvedComponentResult) { return super.checkForExclusion(configDependencies, moduleVersion, resolvedComponentResult) || ( apDependencies != null && apDependencies.hasSameResolvedDependency(moduleVersion) && !(resolvedComponentResult.getId() instanceof ProjectComponentIdentifier)); }
public ResolvedComponentResult getRoot() { try { return resolutionResult.getRoot(); } catch (Throwable e) { throw wrapException(e, configuration); } }
public Set<ResolvedComponentResult> getAllComponents() { try { return resolutionResult.getAllComponents(); } catch (Throwable e) { throw wrapException(e, configuration); } }
public StoreSet createStoreSet() { return new StoreSet() { int storeSetId = storeSetBaseId++; int binaryStoreId; public DefaultBinaryStore nextBinaryStore() { //one binary store per id+threadId String storeKey = Thread.currentThread().getId() + "-" + binaryStoreId++; return createBinaryStore(storeKey); } public Store<ResolvedComponentResult> oldModelStore() { if (oldModelCache == null) { oldModelCache = new CachedStoreFactory("Resolution result"); cleanUpLater.add(oldModelCache); } return oldModelCache.createCachedStore(storeSetId); } public Store<TransientConfigurationResults> newModelStore() { if (newModelCache == null) { newModelCache = new CachedStoreFactory("Resolved configuration"); cleanUpLater.add(newModelCache); } return newModelCache.createCachedStore(storeSetId); } }; }
public void allComponents(Action<? super ResolvedComponentResult> action) { resolutionResult.allComponents(action); }
public StreamingResolutionResultBuilder(BinaryStore store, Store<ResolvedComponentResult> cache) { this.store = store; this.cache = cache; }
public RootFactory(BinaryStore.BinaryData data, Map<ComponentSelector, ModuleVersionResolveException> failures, Store<ResolvedComponentResult> cache) { this.data = data; this.failures = failures; this.cache = cache; }
public ResolvedComponentResult create() { return rootModule; }
public DefaultResolutionResult(Factory<ResolvedComponentResult> rootSource) { assert rootSource != null; this.rootSource = rootSource; }
public ResolvedComponentResult getRoot() { return rootSource.create(); }
public void allDependencies(Action<? super DependencyResult> action) { eachElement(getRoot(), Actions.doNothing(), action, new HashSet<ResolvedComponentResult>()); }
public Set<ResolvedComponentResult> getAllComponents() { final Set<ResolvedComponentResult> out = new LinkedHashSet<ResolvedComponentResult>(); eachElement(getRoot(), Actions.doNothing(), Actions.doNothing(), out); return out; }