public static ModuleDescriptorState forIvyModuleDescriptor(ModuleDescriptor ivyDescriptor) { ModuleRevisionId moduleRevisionId = ivyDescriptor.getModuleRevisionId(); ModuleComponentIdentifier componentIdentifier = DefaultModuleComponentIdentifier.newId(moduleRevisionId.getOrganisation(), moduleRevisionId.getName(), moduleRevisionId.getRevision()); MutableModuleDescriptorState state = new MutableModuleDescriptorState(componentIdentifier, ivyDescriptor.getStatus(), ivyDescriptor.isDefault()); state.setBranch(moduleRevisionId.getBranch()); state.setDescription(ivyDescriptor.getDescription()); state.setPublicationDate(ivyDescriptor.getPublicationDate()); Map<NamespaceId, String> extraInfo = Cast.uncheckedCast(ivyDescriptor.getExtraInfo()); state.getExtraInfo().putAll(extraInfo); for (ExcludeRule excludeRule : ivyDescriptor.getAllExcludeRules()) { addExcludeRule(state, excludeRule); } return state; }
/** * 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 CachedMetaData getCachedModuleDescriptor(ModuleComponentRepository repository, ModuleComponentIdentifier componentId) { ModuleComponentAtRepositoryKey key = createKey(repository, componentId); ModuleMetadataCacheEntry entry = getCache().get(key); if (entry == null) { return null; } if (entry.isMissing()) { return new DefaultCachedMetaData(entry, null, timeProvider); } MutableModuleComponentResolveMetadata metadata = moduleMetadataStore.getModuleDescriptor(key); if (metadata == null) { // Descriptor file has been deleted - ignore the entry getCache().remove(key); return null; } return new DefaultCachedMetaData(entry, entry.configure(metadata), timeProvider); }
protected final void resolveStaticDependency(ModuleComponentIdentifier moduleVersionIdentifier, ComponentOverrideMetadata prescribedMetaData, BuildableModuleComponentMetaDataResolveResult result, ExternalResourceArtifactResolver artifactResolver) { MutableModuleComponentResolveMetadata metaDataArtifactMetaData = parseMetaDataFromArtifact(moduleVersionIdentifier, artifactResolver, result); if (metaDataArtifactMetaData != null) { LOGGER.debug("Metadata file found for module '{}' in repository '{}'.", moduleVersionIdentifier, getName()); metaDataArtifactMetaData.setSource(artifactResolver.getSource()); result.resolved(metaDataArtifactMetaData.asImmutable()); return; } MutableModuleComponentResolveMetadata metaDataFromDefaultArtifact = createMetaDataFromDefaultArtifact(moduleVersionIdentifier, prescribedMetaData, artifactResolver, result); if (metaDataFromDefaultArtifact != null) { LOGGER.debug("Found artifact but no meta-data for module '{}' in repository '{}', using default meta-data.", moduleVersionIdentifier, getName()); metaDataFromDefaultArtifact.setSource(artifactResolver.getSource()); result.resolved(metaDataFromDefaultArtifact.asImmutable()); return; } LOGGER.debug("No meta-data file or artifact found for module '{}' in repository '{}'.", moduleVersionIdentifier, getName()); result.missing(); }
protected void checkMetadataConsistency(ModuleComponentIdentifier expectedId, MutableModuleComponentResolveMetadata metadata) throws MetaDataParseException { List<String> errors = new ArrayList<String>(); if (!expectedId.getGroup().equals(metadata.getId().getGroup())) { errors.add("bad group: expected='" + expectedId.getGroup() + "' found='" + metadata.getId().getGroup() + "'"); } if (!expectedId.getModule().equals(metadata.getId().getName())) { errors.add("bad module name: expected='" + expectedId.getModule() + "' found='" + metadata.getId().getName() + "'"); } if (!expectedId.getVersion().equals(metadata.getId().getVersion())) { errors.add("bad version: expected='" + expectedId.getVersion() + "' found='" + metadata.getId().getVersion() + "'"); } if (errors.size() > 0) { throw new MetaDataParseException(String.format("inconsistent module metadata found. Descriptor: %s Errors: %s", metadata.getId(), Joiner.on(SystemProperties.getInstance().getLineSeparator()).join(errors))); } }
@Override public String getName() { ComponentSelector requested = getRequested(); ComponentIdentifier selected = getActual(); if(requested.matchesStrictly(selected)) { return getSimpleName(); } if(requested instanceof ModuleComponentSelector && selected instanceof ModuleComponentIdentifier) { ModuleComponentSelector requestedModuleComponentSelector = (ModuleComponentSelector)requested; ModuleComponentIdentifier selectedModuleComponentedIdentifier = (ModuleComponentIdentifier)selected; if(isSameGroupAndModuleButDifferentVersion(requestedModuleComponentSelector, selectedModuleComponentedIdentifier)) { return getSimpleName() + " -> " + selectedModuleComponentedIdentifier.getVersion(); } } return getSimpleName() + " -> " + selected.getDisplayName(); }
private static void printInfoTag(ModuleDescriptorState descriptor, SimpleXmlWriter writer) throws IOException { ModuleComponentIdentifier id = descriptor.getComponentIdentifier(); writer.startElement("info"); writer.attribute("organisation", id.getGroup()); writer.attribute("module", id.getModule()); String branch = descriptor.getBranch(); if (branch != null) { writer.attribute("branch", branch); } writer.attribute("revision", id.getVersion()); writer.attribute("status", descriptor.getStatus()); if (descriptor.isGenerated()) { writer.attribute("default", "true"); } printUnusedContent(descriptor, writer); for (Map.Entry<NamespaceId, String> entry : descriptor.getExtraInfo().entrySet()) { if (entry.getValue() == null || entry.getValue().length() == 0) { continue; } NamespaceId namespaceId = entry.getKey(); writer.startElement("ns:" + namespaceId.getName()); writer.attribute("xmlns:ns", namespaceId.getNamespace()); writer.characters(entry.getValue()); writer.endElement(); } writer.endElement(); }
@Override public void resolveComponentMetaData(ModuleComponentIdentifier moduleComponentIdentifier, ComponentOverrideMetadata requestMetaData, BuildableModuleComponentMetaDataResolveResult result) { try { delegate.resolveComponentMetaData(moduleComponentIdentifier, requestMetaData, result); } catch (Throwable throwable) { result.failed(new ModuleVersionResolveException(moduleComponentIdentifier, throwable)); } }
@Override public void resolveComponentMetaData(ModuleComponentIdentifier moduleComponentIdentifier, ComponentOverrideMetadata requestMetaData, BuildableModuleComponentMetaDataResolveResult result) { super.resolveComponentMetaData(moduleComponentIdentifier, requestMetaData, result); if (result.getState() == BuildableModuleComponentMetaDataResolveResult.State.Resolved) { transformDependencies(result); } }
public void resolve(ComponentIdentifier identifier, ComponentOverrideMetadata componentOverrideMetadata, BuildableComponentResolveResult result) { if (!(identifier instanceof ModuleComponentIdentifier)) { throw new UnsupportedOperationException("Can resolve meta-data for module components only."); } resolveModule((ModuleComponentIdentifier) identifier, componentOverrideMetadata, result); }
private void resolveModule(ModuleComponentIdentifier identifier, ComponentOverrideMetadata componentOverrideMetadata, BuildableComponentResolveResult result) { LOGGER.debug("Attempting to resolve component for {} using repositories {}", identifier, repositoryNames); List<Throwable> errors = new ArrayList<Throwable>(); List<ComponentMetaDataResolveState> resolveStates = new ArrayList<ComponentMetaDataResolveState>(); for (ModuleComponentRepository repository : repositories) { resolveStates.add(new ComponentMetaDataResolveState(identifier, componentOverrideMetadata, repository, versionedComponentChooser)); } final RepositoryChainModuleResolution latestResolved = findBestMatch(resolveStates, errors); if (latestResolved != null) { LOGGER.debug("Using {} from {}", latestResolved.module.getId(), latestResolved.repository); for (Throwable error : errors) { LOGGER.debug("Discarding resolve failure.", error); } result.resolved(metaDataFactory.transform(latestResolved)); return; } if (!errors.isEmpty()) { result.failed(new ModuleVersionResolveException(identifier, errors)); } else { for (ComponentMetaDataResolveState resolveState : resolveStates) { resolveState.applyTo(result); } result.notFound(identifier); } }
private ModuleIdentifier getModuleIdentifier(RenderableDependency renderableDependency) { if (renderableDependency.getId() instanceof ModuleComponentIdentifier) { ModuleComponentIdentifier id = (ModuleComponentIdentifier) renderableDependency.getId(); return new DefaultModuleIdentifier(id.getGroup(), id.getModule()); } return null; }
@Override public void resolveComponentMetaData(ModuleComponentIdentifier moduleComponentIdentifier, ComponentOverrideMetadata requestMetaData, BuildableModuleComponentMetaDataResolveResult result) { if (!metaDataCache.supplyMetaData(moduleComponentIdentifier, result)) { super.resolveComponentMetaData(moduleComponentIdentifier, requestMetaData, result); metaDataCache.newDependencyResult(moduleComponentIdentifier, result); } }
boolean supplyMetaData(ModuleComponentIdentifier requested, BuildableModuleComponentMetaDataResolveResult result) { CachedModuleVersionResult fromCache = metaData.get(requested); if (fromCache == null) { return false; } fromCache.supply(result); return true; }
@Override public void resolveComponentMetaData(ModuleComponentIdentifier moduleComponentIdentifier, ComponentOverrideMetadata requestMetaData, BuildableModuleComponentMetaDataResolveResult result) { // First try to determine the artifacts in-memory (e.g using the metadata): don't use the cache in this case delegate.getLocalAccess().resolveComponentMetaData(moduleComponentIdentifier, requestMetaData, result); if (result.hasResult()) { return; } resolveComponentMetaDataFromCache(moduleComponentIdentifier, requestMetaData, result); }
private boolean matchesSelected(ResolvedDependencyResult candidate) { ComponentIdentifier selected = candidate.getSelected().getId(); if (moduleIdentifier != null && selected instanceof ModuleComponentIdentifier) { ModuleComponentIdentifier selectedModule = (ModuleComponentIdentifier) selected; return selectedModule.getGroup().equals(moduleIdentifier.getGroup()) && selectedModule.getModule().equals(moduleIdentifier.getName()); } return false; }
public void selectNewestMatchingComponent(Collection<? extends ModuleComponentResolveState> versions, BuildableComponentSelectionResult result, ModuleVersionSelector requested) { VersionSelector requestedVersion = versionSelectorScheme.parseSelector(requested.getVersion()); Collection<SpecRuleAction<? super ComponentSelection>> rules = componentSelectionRules.getRules(); for (ModuleComponentResolveState candidate : sortLatestFirst(versions)) { MetadataProvider metadataProvider = new MetadataProvider(candidate); boolean versionMatches = versionMatches(requestedVersion, candidate, metadataProvider); if (!metadataProvider.isUsable()) { applyTo(metadataProvider, result); return; } if (!versionMatches) { result.notMatched(candidate.getVersion()); continue; } ModuleComponentIdentifier candidateIdentifier = candidate.getId(); boolean accepted = !isRejectedByRules(candidateIdentifier, rules, metadataProvider); if (!metadataProvider.isUsable()) { applyTo(metadataProvider, result); return; } if (accepted) { result.matches(candidateIdentifier); return; } result.rejected(candidate.getVersion()); if (requestedVersion.matchesUniqueVersion()) { // Only consider one candidate break; } } result.noMatchFound(); }
@Override public void resolveComponentMetaData(ModuleComponentIdentifier moduleComponentIdentifier, ComponentOverrideMetadata requestMetaData, BuildableModuleComponentMetaDataResolveResult result) { delegate.getLocalAccess().resolveComponentMetaData(moduleComponentIdentifier, requestMetaData, result); if (!result.hasResult()) { delegate.getRemoteAccess().resolveComponentMetaData(moduleComponentIdentifier, requestMetaData, result); } if (result.getState() == BuildableModuleComponentMetaDataResolveResult.State.Resolved) { result.setMetadata(metadataProcessor.processMetadata(result.getMetaData())); } }
public ModuleDescriptorState(ModuleComponentIdentifier componentIdentifier, String status, boolean generated) { this.componentIdentifier = componentIdentifier; branch = null; description = null; publicationDate = new Date(); this.status = status; this.generated = generated; extraInfo = Maps.newHashMap(); excludes = Lists.newArrayList(); }
protected AbstractMutableModuleComponentResolveMetadata(ModuleComponentIdentifier componentIdentifier, ModuleDescriptorState moduleDescriptor, Map<String, Configuration> configurations, List<? extends DependencyMetadata> dependencies) { this.descriptor = moduleDescriptor; this.componentId = componentIdentifier; this.id = DefaultModuleVersionIdentifier.newId(componentIdentifier); this.status = moduleDescriptor.getStatus(); this.dependencies = dependencies; this.configurationDefinitions = configurations; }
private void writeInfoSection(ModuleComponentResolveMetadata metadata) throws IOException { writeId(metadata.getComponentId()); ModuleDescriptorState md = metadata.getDescriptor(); ModuleComponentIdentifier componentIdentifier = md.getComponentIdentifier(); writeId(componentIdentifier); writeString(md.getStatus()); writeBoolean(md.isGenerated()); writeNullableString(md.getDescription()); writeNullableDate(md.getPublicationDate()); writeNullableString(md.getBranch()); writeExtraInfo(md.getExtraInfo()); }
private void readInfoSection() throws IOException { id = readId(); ModuleComponentIdentifier componentIdentifier = readId(); String status = readString(); boolean generated = readBoolean(); md = new MutableModuleDescriptorState(componentIdentifier, status, generated); md.setDescription(readNullableString()); md.setPublicationDate(readNullableDate()); md.setBranch(readNullableString()); readExtraInfo(); }
public void write(Encoder encoder, ComponentIdentifier value) throws IOException { if (value == null) { throw new IllegalArgumentException("Provided component identifier may not be null"); } Implementation implementation = resolveImplementation(value); encoder.writeByte(implementation.getId()); if (implementation == Implementation.MODULE) { ModuleComponentIdentifier moduleComponentIdentifier = (ModuleComponentIdentifier) value; encoder.writeString(moduleComponentIdentifier.getGroup()); encoder.writeString(moduleComponentIdentifier.getModule()); encoder.writeString(moduleComponentIdentifier.getVersion()); } else if (implementation == Implementation.BUILD) { ProjectComponentIdentifier projectComponentIdentifier = (ProjectComponentIdentifier) value; BuildIdentifier build = projectComponentIdentifier.getBuild(); buildIdentifierSerializer.write(encoder, build); encoder.writeString(projectComponentIdentifier.getProjectPath()); } else if (implementation == Implementation.LIBRARY) { LibraryBinaryIdentifier libraryIdentifier = (LibraryBinaryIdentifier) value; encoder.writeString(libraryIdentifier.getProjectPath()); encoder.writeString(libraryIdentifier.getLibraryName()); encoder.writeString(libraryIdentifier.getVariant()); } else { throw new IllegalStateException("Unsupported implementation type: " + implementation); } }
private Implementation resolveImplementation(ComponentIdentifier value) { Implementation implementation; if (value instanceof ModuleComponentIdentifier) { implementation = Implementation.MODULE; } else if (value instanceof ProjectComponentIdentifier) { implementation = Implementation.BUILD; } else if (value instanceof LibraryBinaryIdentifier) { implementation = Implementation.LIBRARY; } else { throw new IllegalArgumentException("Unsupported component identifier class: " + value.getClass()); } return implementation; }
@Nullable protected S parseMetaDataFromArtifact(ModuleComponentIdentifier moduleComponentIdentifier, ExternalResourceArtifactResolver artifactResolver, ResourceAwareResolveResult result) { ModuleComponentArtifactMetadata artifact = getMetaDataArtifactFor(moduleComponentIdentifier); LocallyAvailableExternalResource metaDataResource = artifactResolver.resolveArtifact(artifact, result); if (metaDataResource == null) { return null; } ExternalResourceResolverDescriptorParseContext context = new ExternalResourceResolverDescriptorParseContext(componentResolvers); return parseMetaDataFromResource(moduleComponentIdentifier, metaDataResource, context); }
private S createMetaDataFromDefaultArtifact(ModuleComponentIdentifier moduleComponentIdentifier, ComponentOverrideMetadata overrideMetadata, ExternalResourceArtifactResolver artifactResolver, ResourceAwareResolveResult result) { Set<IvyArtifactName> artifacts = overrideMetadata.getArtifacts(); for (IvyArtifactName artifact : getDependencyArtifactNames(moduleComponentIdentifier.getModule(), artifacts)) { if (artifactResolver.artifactExists(new DefaultModuleComponentArtifactMetadata(moduleComponentIdentifier, artifact), result)) { return createDefaultComponentResolveMetaData(moduleComponentIdentifier, artifacts); } } return null; }
public ExternalResourceName toModuleVersionPath(ModuleComponentIdentifier componentIdentifier) { String pattern = getBase().getPath(); if (!pattern.endsWith(MavenPattern.M2_PATTERN)) { throw new UnsupportedOperationException("Cannot locate module version for non-maven layout."); } String metaDataPattern = pattern.substring(0, pattern.length() - MavenPattern.M2_PER_MODULE_VERSION_PATTERN.length() - 1); return getBase().getRoot().resolve(substituteTokens(metaDataPattern, toAttributes(componentIdentifier))); }
private File resolveMetaDataArtifactFile(ModuleComponentIdentifier moduleComponentIdentifier, ComponentMetaDataResolver componentResolver, ArtifactResolver artifactResolver, ArtifactType artifactType) { BuildableComponentResolveResult moduleVersionResolveResult = new DefaultBuildableComponentResolveResult(); componentResolver.resolve(moduleComponentIdentifier, new DefaultComponentOverrideMetadata(), moduleVersionResolveResult); BuildableArtifactSetResolveResult moduleArtifactsResolveResult = new DefaultBuildableArtifactSetResolveResult(); artifactResolver.resolveArtifactsWithType(moduleVersionResolveResult.getMetaData(), artifactType, moduleArtifactsResolveResult); BuildableArtifactResolveResult artifactResolveResult = new DefaultBuildableArtifactResolveResult(); ComponentArtifactMetadata artifactMetaData = moduleArtifactsResolveResult.getResult().iterator().next(); artifactResolver.resolveArtifact(artifactMetaData, moduleVersionResolveResult.getMetaData().getSource(), artifactResolveResult); return artifactResolveResult.getResult(); }
@Nullable private MavenUniqueSnapshotModuleSource composeUniqueSnapshotVersion(ModuleComponentIdentifier moduleComponentIdentifier) { Matcher matcher = UNIQUE_SNAPSHOT.matcher(moduleComponentIdentifier.getVersion()); if (!matcher.matches()) { return null; } return new MavenUniqueSnapshotModuleSource(matcher.group(1)); }
protected Map<String, String> toAttributes(ModuleComponentIdentifier componentIdentifier) { HashMap<String, String> attributes = new HashMap<String, String>(); attributes.put(IvyPatternHelper.ORGANISATION_KEY, componentIdentifier.getGroup()); attributes.put(IvyPatternHelper.MODULE_KEY, componentIdentifier.getModule()); attributes.put(IvyPatternHelper.REVISION_KEY, componentIdentifier.getVersion()); return attributes; }
public static MutableModuleDescriptorState createModuleDescriptor(ModuleComponentIdentifier componentIdentifier, Set<IvyArtifactName> componentArtifacts) { MutableModuleDescriptorState moduleDescriptorState = new MutableModuleDescriptorState(componentIdentifier); for (IvyArtifactName artifactName : componentArtifacts) { moduleDescriptorState.addArtifact(artifactName, Collections.singleton(org.gradle.api.artifacts.Dependency.DEFAULT_CONFIGURATION)); } if (componentArtifacts.isEmpty()) { IvyArtifactName defaultArtifact = new DefaultIvyArtifactName(componentIdentifier.getModule(), "jar", "jar"); moduleDescriptorState.addArtifact(defaultArtifact, Collections.singleton(org.gradle.api.artifacts.Dependency.DEFAULT_CONFIGURATION)); } return moduleDescriptorState; }
public ComponentArtifactMetadata read(Decoder decoder) throws Exception { ModuleComponentIdentifier componentIdentifier = (ModuleComponentIdentifier) componentIdentifierSerializer.read(decoder); String artifactName = decoder.readString(); String type = decoder.readString(); String extension = decoder.readNullableString(); String classifier = decoder.readNullableString(); return new DefaultModuleComponentArtifactMetadata(componentIdentifier, new DefaultIvyArtifactName(artifactName, type, extension, classifier)); }
private DefaultConfigurationMetadata(ModuleComponentIdentifier componentId, String name, boolean transitive, boolean visible, List<DefaultConfigurationMetadata> parents, List<Exclude> excludes) { this.componentId = componentId; this.name = name; this.parents = parents; this.transitive = transitive; this.visible = visible; this.hierarchy = calculateHierarchy(); this.exclusions = filterExcludes(excludes); }
boolean isExternalModuleArtifact(ResolvedArtifact element) { return element.getId().getComponentIdentifier() instanceof ModuleComponentIdentifier; }
public static ModuleRevisionId createModuleRevisionId(ModuleComponentIdentifier id) { return createModuleRevisionId(id.getGroup(), id.getModule(), id.getVersion()); }
public boolean mustRefreshMissingModule(ModuleComponentIdentifier component, long ageMillis) { return mustRefreshModule(component, null, ageMillis, false); }
public boolean mustRefreshModule(ModuleComponentIdentifier component, ResolvedModuleVersion resolvedModuleVersion, long ageMillis) { return mustRefreshModule(component, resolvedModuleVersion, ageMillis, false); }
public boolean mustRefreshChangingModule(ModuleComponentIdentifier component, ResolvedModuleVersion resolvedModuleVersion, long ageMillis) { return mustRefreshModule(component, resolvedModuleVersion, ageMillis, true); }
private boolean mustRefreshModule(ModuleComponentIdentifier component, ResolvedModuleVersion version, long ageMillis, boolean changingModule) { return mustRefreshModule(DefaultModuleVersionIdentifier.newId(component), version, ageMillis, changingModule); }
@Override public ModuleComponentIdentifier getFrom() { return (ModuleComponentIdentifier)dependency.getFrom().getId(); }