use of org.gradle.api.artifacts.component.ComponentIdentifier in project gradle by gradle.
the class LocalFileDependencyBackedArtifactSet method visit.
@Override
public void visit(Visitor listener) {
FileCollectionStructureVisitor.VisitType visitType = listener.prepareForVisit(this);
if (visitType == FileCollectionStructureVisitor.VisitType.NoContents) {
listener.visitArtifacts(new EndCollection(this));
return;
}
ComponentIdentifier componentIdentifier = dependencyMetadata.getComponentId();
if (componentIdentifier != null && !componentFilter.isSatisfiedBy(componentIdentifier)) {
listener.visitArtifacts(new EndCollection(this));
return;
}
FileCollectionInternal fileCollection = dependencyMetadata.getFiles();
Set<File> files;
try {
files = fileCollection.getFiles();
} catch (Exception throwable) {
listener.visitArtifacts(new BrokenArtifacts(throwable));
return;
}
ImmutableList.Builder<ResolvedArtifactSet> selectedArtifacts = ImmutableList.builderWithExpectedSize(files.size());
for (File file : files) {
ComponentArtifactIdentifier artifactIdentifier;
if (componentIdentifier == null) {
artifactIdentifier = new OpaqueComponentArtifactIdentifier(file);
if (!componentFilter.isSatisfiedBy(artifactIdentifier.getComponentIdentifier())) {
continue;
}
} else {
artifactIdentifier = new ComponentFileArtifactIdentifier(componentIdentifier, file.getName());
}
ImmutableAttributes variantAttributes = artifactTypeRegistry.mapAttributesFor(file);
SingletonFileResolvedVariant variant = new SingletonFileResolvedVariant(file, artifactIdentifier, LOCAL_FILE, variantAttributes, dependencyMetadata, calculatedValueContainerFactory);
selectedArtifacts.add(selector.select(variant, this));
}
CompositeResolvedArtifactSet.of(selectedArtifacts.build()).visit(listener);
if (visitType == FileCollectionStructureVisitor.VisitType.Spec) {
listener.visitArtifacts(new CollectionSpec(fileCollection));
}
}
use of org.gradle.api.artifacts.component.ComponentIdentifier in project gradle by gradle.
the class JsonProjectDependencyRenderer method collectModules.
private Set<ModuleIdentifier> collectModules(Configuration configuration) {
RenderableDependency root;
if (canBeResolved(configuration)) {
ResolutionResult result = configuration.getIncoming().getResolutionResult();
root = new RenderableModuleResult(result.getRoot());
} else {
root = new UnresolvableConfigurationResult(configuration);
}
Set<ModuleIdentifier> modules = Sets.newHashSet();
Set<ComponentIdentifier> visited = Sets.newHashSet();
populateModulesWithChildDependencies(root, visited, modules);
return modules;
}
use of org.gradle.api.artifacts.component.ComponentIdentifier in project gradle by gradle.
the class AbstractRenderableDependencyResult method getName.
@Override
public String getName() {
ComponentSelector requested = getRequested();
ComponentIdentifier selected = getActual();
if (exactMatch(requested, selected)) {
return getSimpleName();
}
if (requested instanceof ModuleComponentSelector && selected instanceof ModuleComponentIdentifier) {
ModuleComponentSelector requestedModuleComponentSelector = (ModuleComponentSelector) requested;
ModuleComponentIdentifier selectedModuleComponentedIdentifier = (ModuleComponentIdentifier) selected;
if (requestedModuleComponentSelector.getModuleIdentifier().equals(selectedModuleComponentedIdentifier.getModuleIdentifier())) {
return getSimpleName() + " -> " + selectedModuleComponentedIdentifier.getVersion();
}
}
return getSimpleName() + " -> " + selected.getDisplayName();
}
use of org.gradle.api.artifacts.component.ComponentIdentifier in project gradle by gradle.
the class DependencyInsightReporter method convertToRenderableItems.
public Collection<RenderableDependency> convertToRenderableItems(Collection<DependencyResult> dependencies, boolean singlePathToDependency) {
LinkedList<RenderableDependency> out = new LinkedList<>();
Collection<DependencyEdge> sortedEdges = toDependencyEdges(dependencies);
// remember if module id was annotated
Set<ComponentIdentifier> annotated = Sets.newHashSet();
Set<Throwable> alreadyReportedErrors = Sets.newHashSet();
RequestedVersion current = null;
for (DependencyEdge dependency : sortedEdges) {
// add description only to the first module
if (annotated.add(dependency.getActual())) {
DependencyReportHeader header = createHeaderForDependency(dependency, alreadyReportedErrors);
out.add(header);
current = newRequestedVersion(out, dependency);
} else if (!current.getRequested().equals(dependency.getRequested())) {
current = newRequestedVersion(out, dependency);
}
if (!singlePathToDependency || current.getChildren().isEmpty()) {
current.addChild(dependency);
}
}
return out;
}
use of org.gradle.api.artifacts.component.ComponentIdentifier in project SpongeCommon by SpongePowered.
the class OutputDependenciesToJson method configToDescriptor.
private List<DependencyDescriptor> configToDescriptor(final ArtifactCollection conf, final Set<ModuleComponentIdentifier> excludedDeps) {
return conf.getArtifacts().stream().filter(dep -> {
final ComponentIdentifier ident = dep.getId().getComponentIdentifier();
return ident instanceof ModuleComponentIdentifier && !excludedDeps.contains(ident);
}).distinct().map(dependency -> {
final ModuleComponentIdentifier id = (ModuleComponentIdentifier) dependency.getId().getComponentIdentifier();
// Get file input stream for reading the file content
final String md5hash;
try (final InputStream in = new FileInputStream(dependency.getFile())) {
final MessageDigest hasher = MessageDigest.getInstance("MD5");
final byte[] buf = new byte[4096];
int read;
while ((read = in.read(buf)) != -1) {
hasher.update(buf, 0, read);
}
md5hash = OutputDependenciesToJson.toHexString(hasher.digest());
} catch (final IOException | NoSuchAlgorithmException ex) {
throw new GradleException("Failed to create hash for " + dependency, ex);
}
// create descriptor
return new DependencyDescriptor(id.getGroup(), id.getModule(), id.getVersion(), md5hash);
}).sorted(// sort dependencies for stable output
Comparator.naturalOrder()).collect(Collectors.toList());
}
Aggregations