Exemplo 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)
Exemplo n.º 2
0
 def _mocked_mvn_install_info(self, maven_install_name):
     mii = maveninstallinfo.MavenInstallInfo(())
     mii.get_maven_install_names_and_paths = lambda r: [(
         maven_install_name,
         "some/repo/path",
     )]
     return mii
Exemplo n.º 3
0
    def test_json_file_not_found(self):
        m = maveninstallinfo.MavenInstallInfo(("a/b/c", "d/e/f"))
        
        with self.assertRaises(Exception) as ctx:
            m.get_maven_install_names_and_paths("/repo_root")

        self.assertIn("not found", str(ctx.exception))
        self.assertIn("/repo_root/a/b/c", str(ctx.exception))
Exemplo n.º 4
0
def main(args):
    args = _parse_arguments(args)
    repo_root = common.get_repo_root(args.repo_root)    
    cfg = config.load(repo_root)
    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)

    group_id = "all_ext_deps_group" if args.group_id is None else args.group_id
    artifact_id = "all_ext_deps_art" if args.artifact_id is None else args.artifact_id
    version = "0.0.1-SNAPSHOT" if args.version is None else args.version
    
    artifact_def = buildpom.MavenArtifactDef(group_id=group_id,
                                             artifact_id=artifact_id,
                                             version=version)

    if args.stdin:
        dep_labels = set() # we want to de-dupe labels
        dependencies = []
        for line in sys.stdin:
            line = line.strip()
            if len(line) == 0:
                continue
            if not line.startswith("@"):
                continue
            if _starts_with_ignored_prefix(line):
                continue
            dep_labels.add(line)
        dependencies = ws.parse_dep_labels(dep_labels)
    else:
        dependencies = list(ws.name_to_external_dependencies.values())

    # note that it is possible to end up with duplicate dependencies
    # because different labels may point to the same dependency (gav)
    # (for ex: @maven//:org_antlr_ST4 and @antlr//:org_antlr_ST4)
    # however those indentical gavs may have distinct exclusions
    dependencies.sort()

    if args.exclude_all_transitives:
        # ignore what was specified in the pinned dependencies files
        # and add an "exclude all" dependency for all dependencies that
        # will end up in the generated pom
        ws.dependency_metadata.clear()
        for dep in dependencies:
            ws.dependency_metadata.register_exclusions(
                dep, [dependency.EXCLUDE_ALL_PLACEHOLDER_DEP])

    pomgen = ThirdPartyDepsPomGen(ws, artifact_def, dependencies,
                                  cfg.pom_template)
    pomgen.process_dependencies()
    return pomgen.gen(pom.PomContentType.RELEASE)
Exemplo n.º 5
0
    def test_explicit_paths(self):
        repo_root = tempfile.mkdtemp("monorepo")
        self._touch_file_at_path(repo_root, "my_rules_install.json")
        self._touch_file_at_path(repo_root, "tools/maven_install.json")
        m = maveninstallinfo.MavenInstallInfo(("my_rules_install.json", "tools/maven_install.json"))

        files = m.get_maven_install_names_and_paths(repo_root)

        self.assertEquals(2, len(files))
        self.assertEquals("my_rules", files[0][0])
        self.assertEquals(os.path.join(repo_root, "my_rules_install.json"), files[0][1])
        self.assertEquals("maven", files[1][0])
        self.assertEquals(os.path.join(repo_root, "tools", "maven_install.json"), files[1][1])
Exemplo n.º 6
0
def main(args):
    args = _parse_arguments(args)
    repo_root = common.get_repo_root(args.repo_root)
    cfg = config.load(repo_root)
    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)
    group_id = "all_ext_deps_group" if args.group_id is None else args.group_id
    artifact_id = "all_ext_deps_art" if args.artifact_id is None else args.artifact_id
    version = "0.0.1-SNAPSHOT" if args.version is None else args.version

    artifact_def = buildpom.MavenArtifactDef(group_id=group_id,
                                             artifact_id=artifact_id,
                                             version=version)

    if args.stdin:
        dep_labels = []
        dependencies = []
        for line in sys.stdin:
            line = line.strip()
            if len(line) == 0:
                continue
            if not line.startswith("@"):
                continue
            if _starts_with_ignored_prefix(line):
                continue
            dep_labels.append(line)
        unique_dependencies = set(ws.parse_dep_labels(dep_labels))
        dependencies = list(unique_dependencies)
    else:
        dependencies = list(ws.name_to_external_dependencies.values())

    dependencies.sort()
    pomgen = ThirdPartyDepsPomGen(ws, artifact_def, dependencies,
                                  cfg.pom_template)
    pomgen.process_dependencies()
    return pomgen.gen(pom.PomContentType.RELEASE)
Exemplo n.º 7
0
        required=False,
        action="store_true",
        help="Simulates release information when --force option is used")

    return parser.parse_args(args)


def _to_json(thing):
    return json.dumps(thing, indent=2)


if __name__ == "__main__":
    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)