Esempio n. 1
0
def main(args):
    args = _parse_arguments(args)
    repo_root = common.get_repo_root(args.repo_root)
    cfg = config.load(repo_root, args.verbose)
    pom_content = pomcontentm.PomContent()
    if args.pom_description is not None:
        pom_content.description = args.pom_description
    if args.verbose:
        logger.debug("Global pom content: %s" % pom_content)

    mvn_install_info = maveninstallinfo.MavenInstallInfo(
        cfg.maven_install_paths)
    ws = workspace.Workspace(repo_root, cfg.excluded_dependency_paths,
                             cfg.all_src_exclusions, mvn_install_info,
                             pom_content)
    packages = argsupport.get_all_packages(repo_root, args.package)
    packages = ws.filter_artifact_producing_packages(packages)
    if len(packages) == 0:
        raise Exception(
            "Did not find any artifact producing BUILD.pom packages at [%s]" %
            args.package)
    spider = crawler.Crawler(ws, cfg.pom_template, args.verbose)
    result = spider.crawl(packages,
                          follow_monorepo_references=args.recursive,
                          force_release=args.force)

    if len(result.pomgens) == 0:
        logger.info(
            "No releases are required. pomgen will not generate any pom files. To force pom generation, use pomgen's --force option."
        )
    else:
        output_dir = _get_output_dir(args)

        for pomgen in result.pomgens:
            pom_dest_dir = os.path.join(output_dir, pomgen.bazel_package)
            if not os.path.exists(pom_dest_dir):
                os.makedirs(pom_dest_dir)

            # the goldfile pom is actually a pomgen metadata file, so we
            # write it using the mdfiles module, which ensures it goes
            # into the proper location within the specified bazel package
            if args.pom_goldfile:
                pom_content = pomgen.gen(pom.PomContentType.GOLDFILE)
                pom_goldfile_path = mdfiles.write_file(
                    pom_content, output_dir, pomgen.bazel_package,
                    mdfiles.POM_XML_RELEASED_FILE_NAME)
                logger.info("Wrote pom goldfile to [%s]" % pom_goldfile_path)
            else:
                pom_content = pomgen.gen(pom.PomContentType.RELEASE)
                pom_path = os.path.join(pom_dest_dir, "pom.xml")
                _write_file(pom_path, pom_content)
                logger.info("Wrote pom file to [%s]" % pom_path)
                for i, companion_pomgen in enumerate(
                        pomgen.get_companion_generators()):
                    pom_content = companion_pomgen.gen(
                        pom.PomContentType.RELEASE)
                    pom_path = os.path.join(pom_dest_dir,
                                            "pom_companion%s.xml" % i)
                    _write_file(pom_path, pom_content)
                    logger.info("Wrote companion pom file to [%s]" % pom_path)
Esempio n. 2
0
    def test_get_all_packages__single_package__label_syntax(self):
        packages = argsupport.get_all_packages(
            "root", "//projects/libs/servicelibs/...")

        self.assertIn("projects/libs/servicelibs/grail/grail-admin-api",
                      packages)
        self.assertIn("projects/libs/servicelibs/grail/grail-admin-impl",
                      packages)
        self.assertIn("projects/libs/servicelibs/zk-connect", packages)
Esempio n. 3
0
    def test_get_all_packages__multiple_packages(self):
        packages_str = "projects/libs/servicelibs/grail,projects/libs/servicelibs/zk-connect"

        packages = argsupport.get_all_packages("root", packages_str)

        self.assertIn("projects/libs/servicelibs/grail/grail-admin-api",
                      packages)
        self.assertIn("projects/libs/servicelibs/grail/grail-admin-impl",
                      packages)
        self.assertIn("projects/libs/servicelibs/zk-connect", packages)
Esempio n. 4
0
    def test_get_all_packages__single_package__with_exlusion(self):
        packages_str = "projects/libs,-projects/libs/pastry"

        packages = argsupport.get_all_packages("root", packages_str)

        self.assertIn("projects/libs/servicelibs/grail/grail-admin-api",
                      packages)
        self.assertIn("projects/libs/servicelibs/grail/grail-admin-impl",
                      packages)
        self.assertIn("projects/libs/servicelibs/zk-connect", packages)
        self.assertNotIn("projects/libs/pastry/abstractions", packages)
        self.assertNotIn("projects/libs/pastry/pastry-metrics", packages)
Esempio n. 5
0
    def test_get_all_packages__multiple_packages__spaces_are_trimmed(self):
        packages_str = " projects/libs/servicelibs,  -projects/libs/servicelibs/zk-connect ,  projects/libs/pastry  "

        packages = argsupport.get_all_packages("root", packages_str)

        self.assertIn("projects/libs/pastry/abstractions", packages)
        self.assertIn("projects/libs/pastry/pastry-metrics", packages)
        self.assertIn("projects/libs/servicelibs/grail/grail-admin-api",
                      packages)
        self.assertIn("projects/libs/servicelibs/grail/grail-admin-impl",
                      packages)
        self.assertNotIn("projects/libs/servicelibs/zk-connect", packages)
Esempio n. 6
0
    def test_get_all_packages__multiple_packages__no_duplicates(self):
        packages_str = "projects/libs/pastry,projects/libs/servicelibs/zk-connect,projects/libs,projects/libs/servicelibs"

        packages = argsupport.get_all_packages("root", packages_str)

        self.assertIn("projects/libs/pastry/abstractions", packages)
        self.assertIn("projects/libs/pastry/pastry-metrics", packages)
        self.assertIn("projects/libs/servicelibs/grail/grail-admin-api",
                      packages)
        self.assertIn("projects/libs/servicelibs/zk-connect", packages)
        self.assertIn("projects/libs/pastry/abstractions", packages)
        # ensure no duplicates:
        num_packages = len(PASTRY_PACKAGES) + len(ZK_CONNECT_PACKAGES) + len(
            GRAIL_PACKAGES)
        self.assertEqual(
            num_packages, len(packages),
            "Expected %i packages but got %i: %s" %
            (num_packages, len(packages), packages))
Esempio n. 7
0
    args = _parse_arguments(sys.argv[1:])
    repo_root = common.get_repo_root(args.repo_root)
    cfg = config.load(repo_root, args.verbose)
    mvn_install_info = maveninstallinfo.MavenInstallInfo(
        cfg.maven_install_paths)
    ws = workspace.Workspace(repo_root, cfg.excluded_dependency_paths,
                             cfg.all_src_exclusions, mvn_install_info,
                             pomcontent.NOOP, args.verbose)

    determine_packages_to_process = (args.list_libraries or args.list_artifacts
                                     or args.library_release_plan_tree
                                     or args.library_release_plan_json
                                     or args.artifact_release_plan)

    if determine_packages_to_process:
        packages = argsupport.get_all_packages(repo_root, args.package)
        packages = ws.filter_artifact_producing_packages(packages)
        if len(packages) == 0:
            raise Exception("Did not find any BUILD.pom packages at [%s]" %
                            args.package)

    if args.list_libraries:
        all_libs = []
        for lib_path in bazel.query_all_libraries(repo_root, packages):
            attrs = OrderedDict()
            attrs["name"] = os.path.basename(lib_path)
            attrs["path"] = lib_path
            all_libs.append(attrs)
        print(_to_json(all_libs))

    if args.list_artifacts:
Esempio n. 8
0
    def test_get_all_packages__single_package(self):
        packages = argsupport.get_all_packages("root", "projects/libs/pastry")

        self.assertIn("projects/libs/pastry/abstractions", packages)
        self.assertIn("projects/libs/pastry/pastry-metrics", packages)
        self.assertNotIn("projects/libs/servicelibs/zk-connect", packages)