Example #1
0
    def test_add_variant_with_dependencies(self, tmpdir):
        path = Path(str(tmpdir)) / 'fake.jar'
        project = Project.from_dir(Path('/path/to/project'), version='1.3.4')

        path.write_text("Testing\n", encoding='utf-8')

        with Options(project=project):
            module_data = _create_module_data()

        dependency = Dependency('dep', {
            'location': 'remote',
            'version': '1.2.3',
            'scope': 'scope'
        })

        transient = dependency.derive_from('group', 'name', '1.2.4')
        transient.transient = True
        path_sets = [
            DependencyPathSet(dependency, path),
            DependencyPathSet(transient, path)
        ]

        _add_variant(module_data, API_ELEMENTS, path, {}, 'library', 'api',
                     None, path_sets)

        self._compare_to_file(module_data, 'variant_2')
Example #2
0
    def test_as_dependency(self):
        component = Component('group', 'module', '7.2.1')
        parent = Dependency('parent', {
            'location': 'remote',
            'version': '7.2.1',
            'scope': 'scope'
        })
        dep = Dependency(
            'module', {
                'location': 'remote',
                'group': 'group',
                'version': '7.2.1',
                'scope': 'scope'
            })

        assert component.as_dependency(parent) == dep
Example #3
0
    def test_dependencies(self):
        dependency = Dependency('dep', {
            'location': 'local',
            'version': '3.2.7',
            'scope': 'scope'
        })
        variant = Variant(API_ELEMENTS)

        assert len(variant.dependencies) == 0

        variant.add_dependency(dependency)

        assert len(variant.dependencies) == 1
        assert variant.to_dict() == {
            'name':
            API_ELEMENTS,
            'dependencies': [{
                'group': 'dep',
                'module': 'dep',
                'version': '3.2.7',
                'attributes': {
                    'org.gradle.status': 'release'
                }
            }]
        }
Example #4
0
    def as_dependency(self, parent: Dependency) -> Dependency:
        """
        A function that creates a builder dependency object out of the information
        we carry.

        :param parent: the parent dependency to use.
        :return: the representative framework dependency object.
        """
        return parent.derive_from(self._group, self._module, self._version)
Example #5
0
def _make_dep(location: Optional[str] = 'remote',
              name: Optional[str] = 'name',
              version: Optional[str] = '1.2.3',
              scope: Optional[List[str]] = None) -> Dependency:
    content = {'location': location, 'name': name, 'version': version}

    if scope:
        content['scope'] = scope

    return Dependency('dep', content)
Example #6
0
    def test_build_names(self):
        dependency = Dependency('dep', {
            'location': 'remote',
            'version': '4.5.6',
            'scope': 'scope'
        })

        resolver, classified, base_name = build_names(dependency)

        assert resolver._directory_url == 'https://repo1.maven.org/maven2/dep/dep/4.5.6'
        assert resolver._directory_path == Path('dep')
        assert classified == 'dep-4.5.6'
        assert base_name == 'dep-4.5.6'
Example #7
0
    def test_from_dependency(self):
        dep = Dependency('key', {
            'location': 'remote',
            'version': '7.2.1',
            'scope': 'scope'
        })
        component = Component.from_dependency(dep)

        assert component.to_dict() == {
            'group': 'key',
            'module': 'key',
            'version': '7.2.1',
            'attributes': {
                'org.gradle.status': 'release'
            }
        }
Example #8
0
    def test_add_class_path(self):
        dep = Dependency('dep', {
            'location': 'local',
            'version': '4.5.6',
            'scope': 'scope'
        })
        dps_list = [
            DependencyPathSet(dep, Path('a.jar')),
            DependencyPathSet(dep, Path('b.jar')),
            DependencyPathSet(dep, Path('c.jar'))
        ]
        expected_class_path = os.pathsep.join(['a.jar', 'b.jar', 'c.jar'])
        options = []

        add_class_path(options, dps_list)

        assert options == ['--class-path', expected_class_path]
Example #9
0
    def test_build_options_with_class_path(self):
        """Make sure we build options correctly with no extra class path."""
        classes_dir = Path('classes')
        dep = Dependency('dep', {
            'location': 'local',
            'version': '1.2.3',
            'scope': 'scope'
        })
        dps_list = [
            DependencyPathSet(dep, Path('a.jar')),
            DependencyPathSet(dep, Path('b.jar')),
            DependencyPathSet(dep, Path('c.jar'))
        ]
        expected_class_path = os.pathsep.join(['a.jar', 'b.jar', 'c.jar'])
        options = _build_compiler_options(classes_dir, dps_list)

        assert options == ['-d', 'classes', '--class-path', expected_class_path]
Example #10
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))
Example #11
0
    def test_format_args_dependencies_not_accepted(self):
        project = Project.from_dir(Path('/path/to/project'))
        dependency = Dependency('name', {
            'location': 'remote',
            'version': '1.2.3',
            'scope': 'myTask'
        })
        project.get_dependencies()._dependencies = {'name': dependency}
        engine = Engine(project)
        module = Language(None, 'java')
        task = Task('myTask', func_no_args)

        with patch('builder.engine.end') as mock_end:
            # noinspection PyProtectedMember
            _, _ = engine._format_args(module, task)

        assert mock_end.mock_calls == [
            call(
                'Dependencies were specified for task myTask but it does not accept dependencies.'
            )
        ]
Example #12
0
    def _verify_dependency(cls, content: Dict[str, str], location: str,
                           group: str, name: str, version: str,
                           transient: bool, scope: List[str]):
        dep = Dependency('dep', content)

        _assert_dep(dep, location, group, name, version, transient, scope)
Example #13
0
 def _parent_dependency():
     return Dependency('name', {
         'location': 'remote',
         'version': '1.0.1',
         'scope': 'compile'
     })