Пример #1
0
    def test_add_dependency(self):
        dep = _make_dep()
        context = DependencyContext([], Language({}, 'lang'),
                                    Configuration({}, [], None))
        context._resolve = MagicMock()

        assert dep.transient is False
        assert len(context._dependencies) == 0

        context.add_dependency(dep)

        assert dep.transient is True
Пример #2
0
def read_pom_for_dependencies(pom_path: Path, context: DependencyContext, parent_dependency: Dependency):
    """
    A function that reads a POM file for transient dependencies and includes them into
    the specified context.

    :param pom_path: the path to the POM file to read.
    :param context: the dependency context to add dependencies to.
    :param parent_dependency: the dependency to which the POM file belongs.
    :return: the list of dependencies found in the POM file, if any.
    """
    pom_file = POMFile(pom_path, context)

    for dependency in pom_file.dependencies():
        group, name, version = pom_file.get_dependency_info(dependency)
        version = pom_file.resolve_version(group, name, version)

        # If the version could not be resolved, it's not a dependency we care about.
        if version:
            context.add_dependency(parent_dependency.derive_from(group, name, version))
Пример #3
0
def _use_module_resolution(context: DependencyContext, dependency: Dependency, module_path: Path) \
        -> Optional[DependencyPathSet]:
    """
    A function that resolves Java dependencies using module files (the new way).

    :param context: the current dependency context in play.
    :param dependency: the dependency we are to resolve.
    :param module_path: the local path to our module file.
    :return: the appropriate dependency path set or ``None``.
    """
    module_data = ModuleData.from_path(module_path)
    variant = module_data.get_variant(API_ELEMENTS)

    # If there's not an API variant, then we really can't do anything.
    if not variant:
        return None

    jar_variant_file = variant.files[0]
    jar_file = context.to_local_path(dependency, jar_variant_file.name, jar_variant_file.signatures)

    # If we couldn't get the jar file, report same.
    if not jar_file:
        return None

    # Ok, let's process any dependencies that may be involved.
    if not dependency.ignore_transients:
        for transient_dependency in variant.dependencies:
            context.add_dependency(transient_dependency.as_dependency(dependency))

    # Now, let's create and load up our result:
    result = DependencyPathSet(dependency, jar_file)

    _try_for_variant(context, dependency, module_data, SOURCE_ELEMENTS, result)
    _try_for_variant(context, dependency, module_data, JAVADOC_ELEMENTS, result)

    return result