/** * Empty String for either group or module name is not allowed. */ protected ComponentSelector parseType(String notation) { assert notation != null; String[] split = notation.split(":"); if (split.length < 2 || split.length > 3) { throw new UnsupportedNotationException(notation); } String group = validate(split[0].trim(), notation); String name = validate(split[1].trim(), notation); if (split.length == 2) { return new UnversionedModuleComponentSelector(group, name); } String version = split[2].trim(); if (!GUtil.isTrue(version)) { throw new UnsupportedNotationException(notation); } return DefaultModuleComponentSelector.newSelector(group, name, version); }
public void resolve(DependencyMetadata dependency, BuildableComponentIdResolveResult result) { ComponentSelector selector = dependency.getSelector(); DependencySubstitutionInternal details = new DefaultDependencySubstitution(selector, dependency.getRequested()); try { rule.execute(details); } catch (Throwable e) { result.failed(new ModuleVersionResolveException(selector, e)); return; } if (details.isUpdated()) { resolver.resolve(dependency.withTarget(details.getTarget()), result); result.setSelectionReason(details.getSelectionReason()); return; } resolver.resolve(dependency, result); }
public DslOriginDependencyMetadata createDependencyDescriptor(String clientConfiguration, AttributeContainer clientAttributes, ModuleDependency dependency) { ProjectDependencyInternal projectDependency = (ProjectDependencyInternal) dependency; projectDependency.beforeResolved(); Module module = getProjectModule(dependency); ModuleVersionSelector requested = new DefaultModuleVersionSelector(module.getGroup(), module.getName(), module.getVersion()); ComponentSelector selector = DefaultProjectComponentSelector.newSelector(projectDependency.getDependencyProject()); LocalComponentDependencyMetadata dependencyMetaData = new LocalComponentDependencyMetadata( selector, requested, clientConfiguration, clientAttributes, projectDependency.getTargetConfiguration(), convertArtifacts(dependency.getArtifacts()), convertExcludeRules(clientConfiguration, dependency.getExcludeRules()), false, false, dependency.isTransitive()); return new DslOriginDependencyMetadataWrapper(dependencyMetaData, dependency); }
public void convert(String notation, NotationConvertResult<? super ComponentSelector> result) throws TypeConversionException { ParsedModuleStringNotation parsed; try { parsed = new ParsedModuleStringNotation(notation, null); } catch (IllegalDependencyNotation e) { throw new InvalidUserDataException( "Invalid format: '" + notation + "'. The correct notation is a 3-part group:name:version notation, " + "e.g: 'org.gradle:gradle-core:1.0'"); } if (parsed.getGroup() == null || parsed.getName() == null || parsed.getVersion() == null) { throw new InvalidUserDataException( "Invalid format: '" + notation + "'. Group, name and version cannot be empty. Correct example: " + "'org.gradle:gradle-core:1.0'"); } result.converted(newSelector(parsed.getGroup(), parsed.getName(), parsed.getVersion())); }
@Override public DependencyMetadata withTarget(ComponentSelector target) { if (target instanceof ModuleComponentSelector) { ModuleComponentSelector moduleTarget = (ModuleComponentSelector) target; ModuleVersionSelector requestedVersion = DefaultModuleVersionSelector.newSelector(moduleTarget.getGroup(), moduleTarget.getModule(), moduleTarget.getVersion()); if (requestedVersion.equals(requested)) { return this; } return withRequested(requestedVersion); } else if (target instanceof ProjectComponentSelector) { ProjectComponentSelector projectTarget = (ProjectComponentSelector) target; return new DefaultProjectDependencyMetadata(projectTarget, this); } else { throw new IllegalArgumentException("Unexpected selector provided: " + target); } }
public LocalComponentDependencyMetadata(ComponentSelector selector, ModuleVersionSelector requested, String moduleConfiguration, AttributeContainer moduleAttributes, String dependencyConfiguration, Set<IvyArtifactName> artifactNames, List<Exclude> excludes, boolean force, boolean changing, boolean transitive) { this.selector = selector; this.requested = requested; this.moduleConfiguration = moduleConfiguration; this.moduleAttributes = moduleAttributes; this.dependencyConfiguration = dependencyConfiguration; this.artifactNames = artifactNames; this.excludes = excludes; this.exclusions = ModuleExclusions.excludeAny(excludes); this.force = force; this.changing = changing; this.transitive = transitive; }
@Override public LocalOriginDependencyMetadata withTarget(ComponentSelector target) { if (target instanceof ModuleComponentSelector) { ModuleComponentSelector moduleTarget = (ModuleComponentSelector) target; ModuleVersionSelector requestedVersion = DefaultModuleVersionSelector.newSelector(moduleTarget.getGroup(), moduleTarget.getModule(), moduleTarget.getVersion()); if (selector.equals(target) && requested.equals(requestedVersion)) { return this; } return copyWithTarget(moduleTarget, requestedVersion); } else if (target instanceof ProjectComponentSelector) { if (target.equals(selector)) { return this; } return copyWithTarget(target, requested); } else { throw new AssertionError("Invalid component selector type for substitution: " + target); } }
@Override public String getName() { ComponentSelector requested = dependency.getRequested(); ComponentSelector attempted = dependency.getAttempted(); if(requested.equals(attempted)) { return requested.getDisplayName(); } if(requested instanceof ModuleComponentSelector && attempted instanceof ModuleComponentSelector) { ModuleComponentSelector requestedSelector = (ModuleComponentSelector)requested; ModuleComponentSelector attemptedSelector = (ModuleComponentSelector)attempted; if(requestedSelector.getGroup().equals(attemptedSelector.getGroup()) && requestedSelector.getModule().equals(attemptedSelector.getModule()) && !requestedSelector.getVersion().equals(attemptedSelector.getVersion())) { return requested.getDisplayName() + " -> " + ((ModuleComponentSelector) attempted).getVersion(); } } return requested.getDisplayName() + " -> " + attempted.getDisplayName(); }
@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(); }
/** * Gets unresolved IDE repository file dependencies. * * @param configuration Configuration * @return Unresolved IDE repositoru file dependencies */ public List<UnresolvedIdeRepoFileDependency> getUnresolvedIdeRepoFileDependencies(Configuration configuration) { ResolutionResult result = getIncomingResolutionResult(configuration); List<UnresolvedDependencyResult> unresolvedDependencies = findAllUnresolvedDependencyResults(result.getRoot().getDependencies()); List<UnresolvedIdeRepoFileDependency> unresolvedIdeRepoFileDependencies = new ArrayList<UnresolvedIdeRepoFileDependency>(); for (UnresolvedDependencyResult unresolvedDependencyResult : unresolvedDependencies) { Throwable failure = unresolvedDependencyResult.getFailure(); ComponentSelector componentSelector = unresolvedDependencyResult.getAttempted(); String displayName = componentSelector.getDisplayName(); File file = new File(unresolvedFileName(componentSelector)); unresolvedIdeRepoFileDependencies.add(new UnresolvedIdeRepoFileDependency(file, failure, displayName)); } return unresolvedIdeRepoFileDependencies; }
public void write(Encoder encoder, ComponentSelector value) throws IOException { if(value == null) { throw new IllegalArgumentException("Provided component selector may not be null"); } if(value instanceof DefaultModuleComponentSelector) { ModuleComponentSelector moduleComponentSelector = (ModuleComponentSelector)value; encoder.writeByte(Implementation.MODULE.getId()); encoder.writeString(moduleComponentSelector.getGroup()); encoder.writeString(moduleComponentSelector.getModule()); encoder.writeString(moduleComponentSelector.getVersion()); } else if(value instanceof DefaultProjectComponentSelector) { ProjectComponentSelector projectComponentSelector = (ProjectComponentSelector)value; encoder.writeByte(Implementation.BUILD.getId()); encoder.writeString(projectComponentSelector.getProjectPath()); } else { throw new IllegalArgumentException("Unsupported component selector class: " + value.getClass()); } }
public String getName() { ComponentSelector requested = dependency.getRequested(); ComponentSelector attempted = dependency.getAttempted(); if(requested.equals(attempted)) { return requested.getDisplayName(); } if(requested instanceof ModuleComponentSelector && attempted instanceof ModuleComponentSelector) { ModuleComponentSelector requestedSelector = (ModuleComponentSelector)requested; ModuleComponentSelector attemptedSelector = (ModuleComponentSelector)attempted; if(requestedSelector.getGroup().equals(attemptedSelector.getGroup()) && requestedSelector.getModule().equals(attemptedSelector.getModule()) && !requestedSelector.getVersion().equals(attemptedSelector.getVersion())) { return requested.getDisplayName() + " -> " + ((ModuleComponentSelector) attempted).getVersion(); } } return requested.getDisplayName() + " -> " + attempted.getDisplayName(); }
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 LocalOriginDependencyMetadata projectDependencyMetadata(ProjectDependencySpec projectDependency, String defaultProject, String usageConfigurationName) { String projectPath = projectDependency.getProjectPath(); if (isNullOrEmpty(projectPath)) { projectPath = defaultProject; } String libraryName = projectDependency.getLibraryName(); ComponentSelector selector = new DefaultLibraryComponentSelector(projectPath, libraryName); DefaultModuleVersionSelector requested = new DefaultModuleVersionSelector(nullToEmpty(projectPath), nullToEmpty(libraryName), getId().getVersion()); return dependencyMetadataFor(selector, requested, usageConfigurationName, usageConfigurationName); }
private LocalOriginDependencyMetadata binaryDependencyMetadata(LibraryBinaryDependencySpec binarySpec, String usageConfigurationName) { String projectPath = binarySpec.getProjectPath(); String libraryName = binarySpec.getLibraryName(); ComponentSelector selector = new DefaultLibraryComponentSelector(projectPath, libraryName, binarySpec.getVariant()); DefaultModuleVersionSelector requested = new DefaultModuleVersionSelector(projectPath, libraryName, getId().getVersion()); return dependencyMetadataFor(selector, requested, usageConfigurationName, usageConfigurationName); }
/** * This generates local dependency metadata for a dependency, but with a specific trick: normally, "usage" represents * the kind of dependency which is requested. For example, a library may require the API of a component, or the runtime of a component. * However, for external dependencies, there's no configuration called 'API' or 'runtime': we're mapping them to 'compile', which is * assumed to exist. Therefore, this method takes 2 arguments: one is the requested usage ("API") and the other is the mapped usage * ("compile"). For local libraries, both should be equal, but for external dependencies, they will be different. */ private LocalOriginDependencyMetadata dependencyMetadataFor(ComponentSelector selector, ModuleVersionSelector requested, String usageConfigurationName, String mappedUsageConfiguration) { return new LocalComponentDependencyMetadata( selector, requested, usageConfigurationName, null, mappedUsageConfiguration, Collections.<IvyArtifactName>emptySet(), EXCLUDE_RULES, false, false, true); }
public static DefaultDependencySubstitutions forResolutionStrategy(ComponentIdentifierFactory componentIdentifierFactory) { NotationParser<Object, ComponentSelector> projectSelectorNotationParser = NotationParserBuilder .toType(ComponentSelector.class) .fromCharSequence(new ProjectPathConverter(componentIdentifierFactory)) .toComposite(); return new DefaultDependencySubstitutions(VersionSelectionReasons.SELECTED_BY_RULE, projectSelectorNotationParser); }
public static DefaultDependencySubstitutions forIncludedBuild(IncludedBuild build) { NotationParser<Object, ComponentSelector> projectSelectorNotationParser = NotationParserBuilder .toType(ComponentSelector.class) .fromCharSequence(new CompositeProjectPathConverter(build)) .toComposite(); return new DefaultDependencySubstitutions(VersionSelectionReasons.COMPOSITE_BUILD, projectSelectorNotationParser); }
private DefaultDependencySubstitutions(ComponentSelectionReason reason, Set<Action<? super DependencySubstitution>> substitutionRules, NotationParser<Object, ComponentSelector> moduleSelectorNotationParser, NotationParser<Object, ComponentSelector> projectSelectorNotationParser) { this.reason = reason; this.substitutionRules = substitutionRules; this.moduleSelectorNotationParser = moduleSelectorNotationParser; this.projectSelectorNotationParser = projectSelectorNotationParser; }
public DependencyResult read(Decoder decoder, Map<ComponentSelector, ModuleVersionResolveException> failures) throws IOException { ComponentSelector requested = componentSelectorSerializer.read(decoder); byte resultByte = decoder.readByte(); if (resultByte == SUCCESSFUL) { Long selectedId = decoder.readSmallLong(); return new DefaultDependencyResult(requested, selectedId, null, null); } else if (resultByte == FAILED) { ComponentSelectionReason reason = componentSelectionReasonSerializer.read(decoder); ModuleVersionResolveException failure = failures.get(requested); return new DefaultDependencyResult(requested, null, reason, failure); } else { throw new IllegalArgumentException("Unknown result byte: " + resultByte); } }
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); }
public ComponentSelector read(Decoder decoder) throws IOException { byte id = decoder.readByte(); if (Implementation.BUILD.getId() == id) { return new DefaultProjectComponentSelector(decoder.readString(), decoder.readString()); } else if (Implementation.MODULE.getId() == id) { return new DefaultModuleComponentSelector(decoder.readString(), decoder.readString(), decoder.readString()); } else if (Implementation.LIBRARY.getId() == id) { return new DefaultLibraryComponentSelector(decoder.readString(), decoder.readNullableString(), decoder.readNullableString()); } throw new IllegalArgumentException("Unable to find component selector with id: " + id); }
public void write(Encoder encoder, ComponentSelector value) throws IOException { if (value == null) { throw new IllegalArgumentException("Provided component selector may not be null"); } Implementation implementation = resolveImplementation(value); encoder.writeByte(implementation.getId()); if (implementation == Implementation.MODULE) { ModuleComponentSelector moduleComponentSelector = (ModuleComponentSelector) value; encoder.writeString(moduleComponentSelector.getGroup()); encoder.writeString(moduleComponentSelector.getModule()); encoder.writeString(moduleComponentSelector.getVersion()); } else if (implementation == Implementation.BUILD) { ProjectComponentSelector projectComponentSelector = (ProjectComponentSelector) value; encoder.writeString(projectComponentSelector.getBuildName()); encoder.writeString(projectComponentSelector.getProjectPath()); } else if (implementation == Implementation.LIBRARY) { LibraryComponentSelector libraryComponentSelector = (LibraryComponentSelector) value; encoder.writeString(libraryComponentSelector.getProjectPath()); encoder.writeNullableString(libraryComponentSelector.getLibraryName()); encoder.writeNullableString(libraryComponentSelector.getVariant()); } else { throw new IllegalStateException("Unsupported implementation type: " + implementation); } }
private ComponentSelectorSerializer.Implementation resolveImplementation(ComponentSelector value) { Implementation implementation; if (value instanceof ModuleComponentSelector) { implementation = Implementation.MODULE; } else if (value instanceof ProjectComponentSelector) { implementation = Implementation.BUILD; } else if (value instanceof LibraryComponentSelector) { implementation = Implementation.LIBRARY; } else { throw new IllegalArgumentException("Unsupported component selector class: " + value.getClass()); } return implementation; }
public DefaultDependencyResult(ComponentSelector requested, Long selected, ComponentSelectionReason reason, ModuleVersionResolveException failure) { assert requested != null; assert failure != null || selected != null; this.requested = requested; this.reason = reason; this.selected = selected; this.failure = failure; }
public AbstractDependencyResult(ComponentSelector requested, ResolvedComponentResult from) { assert requested != null; assert from != null; this.from = from; this.requested = requested; }
protected ModuleVersionResolveException createCopy() { try { return getClass().getConstructor(ComponentSelector.class, String.class).newInstance(selector, getMessage()); } catch (Exception e) { throw UncheckedException.throwAsUncheckedException(e); } }
@Override public DependencyMetadata withTarget(ComponentSelector target) { if (target.equals(selector)) { return this; } return delegate.withTarget(target); }
@Override public void execute(DependencySubstitution sub) { DependencySubstitutionInternal dependencySubstitution = (DependencySubstitutionInternal) sub; // Use the result of previous rules as the input for dependency substitution ComponentSelector requested = dependencySubstitution.getTarget(); if (requested instanceof ModuleComponentSelector) { ModuleComponentSelector selector = (ModuleComponentSelector) requested; ProjectComponentIdentifier replacement = getReplacementFor(selector); if (replacement != null) { dependencySubstitution.useTarget( DefaultProjectComponentSelector.newSelector(replacement), VersionSelectionReasons.COMPOSITE_BUILD); } } }
private boolean matchesRequested(DependencyResult candidate) { ComponentSelector requested = candidate.getRequested(); if (moduleIdentifier != null && requested instanceof ModuleComponentSelector) { ModuleComponentSelector requestedSelector = (ModuleComponentSelector) requested; return requestedSelector.getGroup().equals(moduleIdentifier.getGroup()) && requestedSelector.getModule().equals(moduleIdentifier.getName()); } return false; }
private boolean matchesRequested(DependencyResult candidate) { ComponentSelector requested = candidate.getRequested(); if(requested instanceof ModuleComponentSelector) { ModuleComponentSelector requestedModule = (ModuleComponentSelector)requested; String requestedCandidate = requestedModule.getGroup() + ":" + requestedModule.getModule() + ":" + requestedModule.getVersion(); return requestedCandidate.contains(stringNotation); } return false; }
public DefaultInternalDependencyResult(ComponentSelector requested, ModuleVersionIdentifier selected, ComponentSelectionReason reason, ModuleVersionResolveException failure) { assert requested != null; assert failure != null || selected != null; this.requested = requested; this.reason = reason; this.selected = selected; this.failure = failure; }
public InternalDependencyResult read(Decoder decoder, Map<ComponentSelector, ModuleVersionResolveException> failures) throws IOException { ComponentSelector requested = componentSelectorSerializer.read(decoder); byte resultByte = decoder.readByte(); if (resultByte == SUCCESSFUL) { ModuleVersionIdentifier selected = moduleVersionIdentifierSerializer.read(decoder); return new DefaultInternalDependencyResult(requested, selected, null, null); } else if (resultByte == FAILED) { ComponentSelectionReason reason = componentSelectionReasonSerializer.read(decoder); ModuleVersionResolveException failure = failures.get(requested); return new DefaultInternalDependencyResult(requested, null, reason, failure); } else { throw new IllegalArgumentException("Unknown result byte: " + resultByte); } }
public ComponentSelector read(Decoder decoder) throws IOException { byte id = decoder.readByte(); if(Implementation.BUILD.getId() == id) { return new DefaultProjectComponentSelector(decoder.readString()); } else if(Implementation.MODULE.getId() == id) { return new DefaultModuleComponentSelector(decoder.readString(), decoder.readString(), decoder.readString()); } throw new IllegalArgumentException("Unable to find component selector with id: " + id); }