def _convert_poms(self):
    modules = PomUtils.get_modules()
    logger.debug('Re-generating {count} modules'.format(count=len(modules)))
    # Convert pom files to BUILD files
    context = GenerationContext()
    for module_name in modules:
      if not module_name in _MODULES_TO_SKIP:
        pom_file_name = os.path.join(module_name, 'pom.xml')
        PomToBuild().convert_pom(pom_file_name, rootdir=self.baseroot, generation_context=context)
    context.os_to_java_homes = JavaHomesInfo.from_pom('parents/base/pom.xml',
                                                      self.baseroot).home_map
    # Write jvm platforms and distributions.
    with open(context.generated_ini_file, 'w+') as f:
      f.write('# Generated by regenerate_all.py. Do not hand-edit.\n\n')
      f.write('\n'.join(context.get_pants_ini_gen()))

    local_ini = 'pants-local.ini'
    if not os.path.exists(local_ini):
      with open(local_ini, 'w') as f:
        f.write('\n'.join([
          '# Local pants.ini file, not tracked by git.',
          '# Use this to make your own custom changes/overrides to pants settings.',
          '# Note: This is for local settings only.  Changes you make here will',
          '# not be used in CI (use pants.ini for that).',
          '',
          '# Uncomment to use local build cache ',
          '# (Saves time when switching between branches frequently.)',
          '#[cache]',
          '#read_from: ["~/.cache/pants/local-build-cache"]',
          '#read: True',
          '#write_to: ["~/.cache/pants/local-build-cache"]',
          '#write: True',
          '',
        ]))
Exemple #2
0
 def __init__(self, pom_file_path, root_directory=None, generation_context=None):
   if generation_context is None:
     generation_context = GenerationContext()
   generation_context.pom_file_cache[(pom_file_path, root_directory)] = self
   self.context = generation_context
   self.path = pom_file_path
   self.root_directory = root_directory
   # Get deps_from_pom, wire_info, etc.
   self._get_parsed_pom_data(generation_context)
   # These dependency lists are initially populated by the pom.xml's data, then updated by
   # build_components as they generated and inject their own dependencies.
   self.lib_deps = []
   self.test_deps = []
   self.lib_jar_deps = []
   self.test_jar_deps = []
   self.resources = []
   self.test_resources = []
   self._initialize_dependency_lists()
   # Names of targets generated for project-level BUILD file.
   self.project_target_names = set()
   # Update our properties dict with any 'special' properties (things that are conditional on
   # sys.platform, etc).
   self._properties = {}
   self._update_properties()
   self._java_options = None
   self._parents = None
   self._shading_rules = None
   self._config_tree = None
Exemple #3
0
  def convert_pom(self, pom_file_name, rootdir=None, generation_context=None):
    """returns the contents of a BUILD file that corresponds to a module pom.xml file.
       pom_file_name - path to the pom.xml to convert
    """
    if not os.path.exists(pom_file_name) or not os.path.isfile(pom_file_name):
      raise IOError("Couldn't find plain pom.xml file at {0}".format(pom_file_name))

    if generation_context is None:
      generation_context = GenerationContext()

    try:
      pom_file = PomFile(pom_file_name, rootdir, generation_context)
    except Exception as e:
      raise PomConversionError('Failed to initialize PomFile for {}:\n{}'.format(pom_file_name, e))

    contents = ''
    for component in BuildComponent.TYPE_LIST:
      bc = component(pom_file, generation_context=generation_context)
      if bc.exists:
        try:
          gen_code = bc.generate()
        except Exception as e:
          raise PomConversionError('Failed to generate component {} for pom file {}.\n{}'
                                   .format(component.__name__, pom_file_name, e))
        if gen_code:
          contents += gen_code

    try:
      generation_context.write_build_file(pom_file.directory, contents)
    except Exception as e:
      raise PomConversionError('Failed to write generated build data for {}:\n{}'
                               .format(pom_file_name, e))
 def __init__(self, pom_file, generation_context=None):
   """Creates a new BuildComponent for the given pom file.
   :param squarepants.pom_file.PomFile pom_file: the extracted information from a project's
     pom.xml.
   :return:
   """
   self.pom = pom_file
   self.gen_context = generation_context or GenerationContext()
 def _generate_module_list_file(self):
     modules = PomUtils.get_modules()
     context = GenerationContext()
     with open(context.module_list_file, 'w+') as f:
         f.write(
             "# List of modules for pants's reference. This are currently generated directly\n"
             "# from pom.xml, but in the future we can simply use\n"
             "# ./pants filter --target-type=jvm_binary ::\n\n")
         for module in modules:
             f.write('{}\n'.format(module.strip()))
    def convert_pom(self,
                    pom_file_name,
                    rootdir=None,
                    generation_context=None):
        """returns the contents of a BUILD file that corresponds to a module pom.xml file.
       pom_file_name - path to the pom.xml to convert
    """
        if not os.path.exists(pom_file_name) or not os.path.isfile(
                pom_file_name):
            raise IOError("Couldn't find plain pom.xml file at {0}".format(
                pom_file_name))

        if generation_context is None:
            generation_context = GenerationContext()

        try:
            pom_file = PomFile(pom_file_name, rootdir, generation_context)
        except Exception as e:
            raise PomConversionError(
                'Failed to initialize PomFile for {}:\n{}'.format(
                    pom_file_name, e))

        contents = ''
        for component in BuildComponent.TYPE_LIST:
            bc = component(pom_file, generation_context=generation_context)
            if bc.exists:
                try:
                    gen_code = bc.generate()
                except Exception as e:
                    raise PomConversionError(
                        'Failed to generate component {} for pom file {}.\n{}'.
                        format(component.__name__, pom_file_name, e))
                if gen_code:
                    contents += gen_code

        try:
            generation_context.write_build_file(pom_file.directory, contents)
        except Exception as e:
            raise PomConversionError(
                'Failed to write generated build data for {}:\n{}'.format(
                    pom_file_name, e))
    def _convert_poms(self):
        modules = PomUtils.get_modules()
        logger.debug(
            'Re-generating {count} modules'.format(count=len(modules)))
        # Convert pom files to BUILD files
        context = GenerationContext()
        for module_name in modules:
            if not module_name in _MODULES_TO_SKIP:
                pom_file_name = os.path.join(module_name, 'pom.xml')
                PomToBuild().convert_pom(pom_file_name,
                                         rootdir=self.baseroot,
                                         generation_context=context)
        context.os_to_java_homes = JavaHomesInfo.from_pom(
            'parents/base/pom.xml', self.baseroot).home_map
        # Write jvm platforms and distributions.
        with open(context.generated_ini_file, 'w+') as f:
            f.write('# Generated by regenerate_all.py. Do not hand-edit.\n\n')
            f.write('\n'.join(context.get_pants_ini_gen()))

        local_ini = 'pants-local.ini'
        if not os.path.exists(local_ini):
            with open(local_ini, 'w') as f:
                f.write('\n'.join([
                    '# Local pants.ini file, not tracked by git.',
                    '# Use this to make your own custom changes/overrides to pants settings.',
                    '# Note: This is for local settings only.  Changes you make here will',
                    '# not be used in CI (use pants.ini for that).',
                    '',
                    '# Uncomment to use local build cache ',
                    '# (Saves time when switching between branches frequently.)',
                    '#[cache]',
                    '#read_from: ["~/.cache/pants/local-build-cache"]',
                    '#read: True',
                    '#write_to: ["~/.cache/pants/local-build-cache"]',
                    '#write: True',
                    '',
                ]))