コード例 #1
0
  def generate(self):
    config_data = self._dedent_xml(self.pom.jooq_config)
    config_data = '<configuration>{tail}'.format(tail=config_data[config_data.find('\n'):])
    config_data = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n{body}'.format(
      body=config_data,
    )

    try:
      symbols = dict(self.pom.properties)
      # NB(gmalmquist): We switched to using build_symbols for dynamic properties,
      # however that only works in BUILD files, and this is raw xml. So we have to
      # explicitly define the dynamic properites.
      basedir = os.path.abspath(self.pom.directory)
      symbols.update({
        'basedir': basedir,
        'project.basedir': basedir,
        'project.baseUri': 'file://{}'.format(os.path.realpath(basedir)),
        'project.build.directory': os.path.join(basedir, 'target'),
        'user.name': getpass.getuser(),
      })
      config_data = GenerationUtils.symbol_substitution(symbols, config_data,
                                                        symbols_name=self.pom.path,
                                                        fail_on_missing=True)
    except GenerationUtils.MissingSymbolError as e:
      logger.debug('{} Skipping jooq target generation.'.format(e))
      return ''

    config_path = os.path.join(self.pom.directory, self.gen_context.jooq_config_file)
    with open(config_path, 'w+') as f:
      f.write(config_data.strip())

    setup_target = None
    if not self.pom.jooq_info.skip_setup:
      try:
        setup_target = self._generate_setup_target()
      except self.JdbcConfig.MissingConfigError as e:
        logger.debug('Skipping jooq target generation for {} due to missing jdbc config.\n{}'
                     .format(self.pom.path, e))
        return ''

    jooq_target_deps = list(self._jooq_target_deps)
    if setup_target:
      sql_name = self.gen_context.infer_target_name(self.pom.directory, 'jooq-sql-setup')
      jooq_target_deps.append(':{}'.format(sql_name))

    targets = [
      self.create_project_target(
        Target.jvm_prep_command,
        name='jooq',
        goal='jooq',
        mainclass='org.jooq.util.GenerationTool',
        args=[
          config_path,
        ],
        dependencies=format_dependency_list(jooq_target_deps),
      )
    ]
    if setup_target:
      targets.append(setup_target)
    return '\n'.join(targets)
コード例 #2
0
  def format_jar_library(cls, target_name, jar_deps, pom_file=None):
    """Given a list of jar dependencies, format a jar_library target.

    Exposed for testing.
    :param target_name: the target name for the jar_library.
    :param jar_deps: - <jar> dependency names to add to the jar_library.
    :returns: A jar_library declaration.
    :rtype: string
    """
    if not jar_deps:
      return ''

    # There is a bug in Target.jar_library.format(). See test_target_template.py
    #return Target.jar_library.format(
    #  name=target_name,
    #  jars=sorted(set(jar_deps)),
    #  symbols=pom_file.properties if pom_file else None,
    #  file_name=pom_file.path if pom_file else None,
    #)
    jar_library = dedent('''
        jar_library(name='{name}',
          jars=[{jars}
          ],
        )
      ''').format(name=target_name,
                  jars=','.join('\n{}{}'.format(' '*4, jar) for jar in sorted(set(jar_deps))))
    if pom_file:
      jar_library = GenerationUtils.symbol_substitution(pom_file.properties, jar_library)
    return GenerationUtils.autoindent(jar_library)
コード例 #3
0
  def get_jvm_platform_name(self):
    # if self.is_test:
    #   return self.get_jvm_platform_test_name()
    options = self.pom.java_options
    if not any([options.target_level, options.source_level, options.compile_args]):
      return None

    args = [GenerationUtils.symbol_substitution(self.pom.properties, arg, symbols_name=self.pom.path)
            for arg in options.compile_args]

    return self.gen_context.jvm_platform(options.target_level,
                                         options.source_level,
                                         args,)
コード例 #4
0
  def _parse(self, source_file_name, rootdir):
    pomHandler = _DFPomContentHandler()
    if rootdir:
      full_source_path = os.path.join(rootdir, source_file_name)
    else:
      full_source_path = source_file_name

    if os.path.basename(full_source_path) != 'pom.xml':
      full_source_path = os.path.join(full_source_path, 'pom.xml')

    try:
      with open(full_source_path) as source:
        xml.sax.parse(source, pomHandler)
    except IOError:
      # assume this file has been removed for a good reason and just continue normally
      return
    except xml.sax.SAXParseException as e:
      raise MalformattedPOMException(source_file_name, e)

    self._artifactId = pomHandler.artifactId
    self._groupId = pomHandler.groupId
    self._parent = pomHandler.parent

    # Since dependencies are just dicts, we keep track of keys separately.  Maybe in the future
    # it would be good to create a Dependency data structure and return a set or ordered dictionary
    # of those instances instead.
    dep_keys = set()
    for dep in pomHandler.dependencies:
      if 'groupId' in dep and 'artifactId' in dep:
        dep_keys.add('{0} {1}'.format(dep['groupId'], dep['artifactId']))
        self._dependencies.append(dep)

    parent_df = self.parent
    if parent_df:
      for dep in parent_df.dependencies:
        key = '{0} {1}'.format(dep['groupId'], dep['artifactId'])
        # dependencies declared in parent poms can be overridden
        if key not in dep_keys:
          self._dependencies.append(dep)
      self._properties.update(parent_df.properties)

    self._properties.update(pomHandler.properties)
    for key, value in self._properties.items():
      self._properties[key] = GenerationUtils.symbol_substitution(self._properties, value)
    self._dependencies = GenerationUtils.symbol_substitution_on_dicts(self._properties,
                                                                      self._dependencies)
コード例 #5
0
 def substitute(value):
   return GenerationUtils.symbol_substitution(symbols, value, symbols_name=file_name)
コード例 #6
0
 def _substitute_symbols(cls, s):
     return GenerationUtils.symbol_substitution(PomFile("parents/base/pom.xml").properties, s)
コード例 #7
0
 def _substitute_symbols(cls, s):
     return GenerationUtils.symbol_substitution(
         PomFile('parents/base/pom.xml').properties, s)