コード例 #1
0
 def __enter__(self):
     """
     This allows a project to be used with the ``with`` statement to temporarily become
     the current project in the set of global options.  Note that this cannot be nested.
     """
     self._hold_project = global_options.project()
     global_options.set_project(self)
コード例 #2
0
ファイル: java.py プロジェクト: jskress/builder-tool
    def __init__(self):
        self.type = 'library'
        self.source = 'src'
        self.build = 'build'
        self.code_source = 'code'
        self.code_resources = 'resources'
        self.code_target = 'code/classes'
        self.code_doc = 'code/javadoc'
        self.tests_source = 'tests'
        self.test_resources = 'test_resources'
        self.tests_target = 'tests/classes'
        self.dist = 'dist'
        self.app_target = 'app'
        self.lib_target = 'lib'

        self._project = global_options.project()
        self._code_dir = None
        self._resources_dir = None
        self._tests_dir = None
        self._test_resources_dir = None
        self._build_dir = None
        self._classes_dir = None
        self._test_target_dir = None
        self._doc_dir = None
        self._dist_dir = None
        self._lib_dir = None
        self._app_dir = None
コード例 #3
0
def check_dependency_versions():
    """
    A function that provides the implementation of the ``check-versions`` task for the
    Java language.  It will attempt to verify the version of all dependencies noted in
    the current project and report when a dependency is not using the current one or
    it's version cannot be found.
    """
    context = global_options.project().get_full_dependency_context('java')
    local_paths = global_options.project().configuration.local_paths

    for dependency in context.dependencies:
        resolver, _, _ = build_names(dependency, version_in_url=False)
        version_info = None

        context.set_remote_resolver(resolver)

        if dependency.is_remote:
            version_info = _get_remote_version_info(context, dependency)
        elif dependency.is_project:
            publishing_directory = context.get_publishing_directory(
                dependency.key)

            if publishing_directory:
                version_info = _get_local_version_info([publishing_directory],
                                                       dependency.name)

        else:  # dependency.is_local
            version_info = _get_local_version_info(local_paths,
                                                   dependency.name)

        if version_info:
            dependency_version = Version(dependency.version)
            latest, available = version_info

            if latest == dependency_version:
                out(f'  - {dependency.name}: {dependency_version} (current).')
            elif dependency_version not in available:
                out(f'  - Version {dependency.version} of {dependency.name} is not available.'
                    )
            else:
                out(f'  - {dependency.name}: {dependency_version} (not latest; latest is {latest}).'
                    )
        else:
            out(f'  - Could not obtain version information for the {dependency.name} dependency.'
                )
コード例 #4
0
ファイル: resolver.py プロジェクト: jskress/builder-tool
def project_to_dist_dir(configuration: JavaConfiguration) -> Optional[Path]:
    """
    A function that returns the primary library distribution directory for the given
    configuration.  This is used when resolving project dependencies.

    :param configuration: the configuration to get dependency directory for.
    :return: the configuration's library distribution directory.
    """
    return configuration.library_dist_dir() / global_options.project().name
コード例 #5
0
ファイル: init.py プロジェクト: jskress/builder-tool
def init_java_project(language_config: JavaConfiguration):
    project = global_options.project()
    ij_project = IJProject(project.directory)

    _create_project_yaml(project)
    create_ij_project_file(language_config, ij_project)
    _create_directory_tree(language_config)
    _create_misc_xml(ij_project)
    _create_modules_xml(ij_project, project.name)

    ij_project.save()
コード例 #6
0
def sync_dependencies_to_ij(language_config: JavaConfiguration):
    project = global_options.project()
    full_context: DependencyContext = project.get_full_dependency_context(
        'java')
    ij_project = IJProject(project.directory)

    # This will make sure we have the primary IntelliJ project file.  Note that it
    # will not actually create it if it already exists.
    create_ij_project_file(language_config, ij_project)

    ij_project.iml_file().clear_libraries()

    for context in full_context.split():
        ij_project.add_library(context.resolve())

    # Now save everything.
    ij_project.save()
コード例 #7
0
ファイル: intellij.py プロジェクト: jskress/builder-tool
    def _create_default_document(**inputs) -> Xml.Element:
        """
        A function that creates an initial IntelliJ ``modules.xml`` file.
        """
        path_sets: List[DependencyPathSet] = inputs['path_sets']
        project = global_options.project()
        main_dependency = path_sets[0].dependency
        root = Xml.Element('component', OrderedDict(name='libraryTable'))

        library = Xml.SubElement(
            root, 'library',
            OrderedDict(name=repr(main_dependency), type='repository'))

        Xml.SubElement(library, 'properties',
                       {'maven-id': repr(main_dependency)})

        classes = Xml.SubElement(library, 'CLASSES')
        javadoc = Xml.SubElement(library, 'JAVADOC')
        sources = Xml.SubElement(library, 'SOURCES')

        for path_set in path_sets:
            Xml.SubElement(
                classes, 'root', {
                    'url':
                    _to_relative_path_url(path_set.primary_path,
                                          project.directory)
                })

            if path_set.has_secondary_path(SOURCE_ELEMENTS):
                Xml.SubElement(
                    sources, 'root', {
                        'url':
                        _to_relative_path_url(path_set.sourcesElements,
                                              project.directory)
                    })

            if path_set.has_secondary_path(JAVADOC_ELEMENTS):
                Xml.SubElement(
                    javadoc, 'root', {
                        'url':
                        _to_relative_path_url(path_set.javadocElements,
                                              project.directory)
                    })

        return root
コード例 #8
0
def _build_jacoco_agent_options(
        language_config: JavaConfiguration, task_config: TestingConfiguration,
        dependencies: List[DependencyPathSet]) -> List[str]:
    """
    A function that knows how to build the command line options for configuring the JaCoCo runtime
    as an agent.

    :param language_config: the current Java language configuration information.
    :param task_config: the configuration for this task.
    :param dependencies: any configured dependencies that were given..
    :return: the list of options for the JaCoCo agent.
    """
    project_name = global_options.project().name
    coverage_report_dir = task_config.coverage_reports_dir(language_config)
    data_file = coverage_report_dir / f'{project_name}.exec'
    agent_jar = _find_primary_jar(task_config.coverage_agent, dependencies)

    # noinspection SpellCheckingInspection
    return [f'-javaagent:{str(agent_jar)}=destfile={str(data_file)}']
コード例 #9
0
def _build_jacoco_cli_options(
        language_config: JavaConfiguration, task_config: TestingConfiguration,
        dependencies: List[DependencyPathSet]) -> List[str]:
    """
    A function that knows how to build the command line options for the JaCoCo CLI for report
    formatter..

    :param language_config: the current Java language configuration information.
    :param task_config: the configuration for this task.
    :param dependencies: any configured dependencies that were given..
    :return: the list of options for the JaCoCo CLI.
    """
    executor = _find_primary_jar(task_config.coverage_reporter, dependencies)
    project_name = global_options.project().name
    coverage_report_dir = task_config.coverage_reports_dir(language_config)
    data_file = coverage_report_dir / f'{project_name}.exec'

    # noinspection SpellCheckingInspection
    options = [
        '-jar',
        str(executor),
        'report',
        str(data_file),
        '--classfiles',
        str(language_config.classes_dir(required=True)),
        '--html',
        str(task_config.coverage_reports_dir(language_config, ensure=True)),
        '--name',
        project_name,
    ]

    if global_options.verbose() == 0:
        options.append('--quiet')

    # noinspection SpellCheckingInspection
    options.extend(['--sourcefiles', str(language_config.code_dir())])

    return options