Ejemplo n.º 1
0
  def console_output(self, _targets):
    if not self.context.options.target_specs:
      raise TaskError("No targets specified.")

    # Heuristics to guess whether user tries to load a python project,
    # in which case intellij project sdk has to be set up manually.
    jvm_target_num = len([x for x in self.context.target_roots if isinstance(x, JvmTarget)])
    python_target_num = len([x for x in self.context.target_roots if isinstance(x, PythonTarget)])
    if python_target_num > jvm_target_num:
      logging.warn('This is likely a python project. Please make sure to '
                   'select the proper python interpreter as Project SDK in IntelliJ.')

    ide_file = self.generate_project()
    yield self.gen_project_workdir

    if ide_file and self.get_options().open:
      open_with = self.get_options().open_with
      if open_with:
        null = open(os.devnull, 'wb')
        subprocess.Popen([open_with, ide_file], stdout=null, stderr=null)
      else:
        try:
          desktop.ui_open(ide_file)
        except desktop.OpenError as e:
          raise TaskError(e)
Ejemplo n.º 2
0
 def do_report(exc=None):
   if coverage:
     coverage.report(all_targets, self.execute_java_for_coverage, tests_failed_exception=exc)
   if self._html_report:
     html_file_path = JUnitHtmlReport().report(output_dir, os.path.join(output_dir, 'reports'))
     if self._open:
       desktop.ui_open(html_file_path)
Ejemplo n.º 3
0
    def console_output(self, _targets):
        if not self.context.options.specs:
            raise TaskError("No targets specified.")

        # Heuristics to guess whether user tries to load a python project,
        # in which case intellij project sdk has to be set up manually.
        jvm_target_num = len(
            [x for x in self.context.target_roots if isinstance(x, JvmTarget)])
        python_target_num = len([
            x for x in self.context.target_roots
            if isinstance(x, PythonTarget)
        ])
        if python_target_num > jvm_target_num:
            logging.warn(
                'This is likely a python project. Please make sure to '
                'select the proper python interpreter as Project SDK in IntelliJ.'
            )

        ide_file = self.generate_project()
        yield self.gen_project_workdir

        if ide_file and self.get_options().open:
            open_with = self.get_options().open_with
            if open_with:
                null = open(os.devnull, 'wb')
                subprocess.Popen([open_with, ide_file],
                                 stdout=null,
                                 stderr=null)
            else:
                try:
                    desktop.ui_open(ide_file)
                except desktop.OpenError as e:
                    raise TaskError(e)
Ejemplo n.º 4
0
    def execute(self):
        # Heuristics to guess whether user tries to load a python project,
        # in which case intellij project sdk has to be set up manually.
        jvm_target_num = len(
            filter(lambda x: isinstance(x, JvmTarget),
                   self.context.target_roots))
        python_target_num = len(
            filter(lambda x: isinstance(x, PythonTarget),
                   self.context.target_roots))
        if python_target_num > jvm_target_num:
            logging.warn(
                'This is likely a python project. Please make sure to '
                'select the proper python interpreter as Project SDK in IntelliJ.'
            )

        ide_file = self.generate_project()
        if ide_file and self.get_options().open:
            open_with = self.get_options().open_with
            if open_with:
                null = open(os.devnull, 'w')
                subprocess.Popen([open_with, ide_file],
                                 stdout=null,
                                 stderr=null)
            else:
                try:
                    desktop.ui_open(ide_file)
                except desktop.OpenError as e:
                    raise TaskError(e)
Ejemplo n.º 5
0
    def execute(self):
        """Stages IDE project artifacts to a project directory and generates IDE configuration files."""
        # Grab the targets in-play before the context is replaced by `self._prepare_project()` below.
        targets = self.context.targets()

        self._prepare_project()

        if self.context.options.is_known_scope('lint.checkstyle'):
            checkstyle_classpath = self.tool_classpath('checkstyle',
                                                       scope='lint.checkstyle')
        else:  # Checkstyle not enabled.
            checkstyle_classpath = []

        if self.skip_scala:
            scalac_classpath = []
        else:
            scalac_classpath = ScalaPlatform.global_instance(
            ).compiler_classpath(self.context.products)

        self._project.set_tool_classpaths(checkstyle_classpath,
                                          scalac_classpath)
        self.map_internal_jars(targets)
        self.map_external_jars(targets)

        idefile = self.generate_project(self._project)
        if idefile:
            try:
                desktop.ui_open(idefile)
            except desktop.OpenError as e:
                raise TaskError(e)
Ejemplo n.º 6
0
  def execute(self):
    """Stages IDE project artifacts to a project directory and generates IDE configuration files."""
    # Grab the targets in-play before the context is replaced by `self._prepare_project()` below.
    targets = self.context.targets()

    self._prepare_project()

    if self.context.options.is_known_scope('compile.checkstyle'):
      checkstyle_classpath = self.tool_classpath('checkstyle', scope='compile.checkstyle')
    else:  # Checkstyle not enabled.
      checkstyle_classpath = []

    if self.skip_scala:
      scalac_classpath = []
    else:
      scalac_classpath = ScalaPlatform.global_instance().compiler_classpath(self.context.products)

    self._project.set_tool_classpaths(checkstyle_classpath, scalac_classpath)
    self.map_internal_jars(targets)
    self.map_external_jars(targets)

    idefile = self.generate_project(self._project)
    if idefile:
      try:
        desktop.ui_open(idefile)
      except desktop.OpenError as e:
        raise TaskError(e)
Ejemplo n.º 7
0
 def maybe_open_report(self):
   if self._coverage_open:
     report_file_path = os.path.join(self._settings.coverage_dir, 'html', 'index.html')
     try:
       desktop.ui_open(report_file_path)
     except desktop.OpenError as e:
       raise TaskError(e)
Ejemplo n.º 8
0
 def do_report(exc=None):
   if coverage:
     coverage.report(all_targets, self.execute_java_for_coverage, tests_failed_exception=exc)
   if self._html_report:
     html_file_path = JUnitHtmlReport().report(output_dir, os.path.join(output_dir, 'reports'))
     if self._open:
       desktop.ui_open(html_file_path)
Ejemplo n.º 9
0
  def generate_doc(self, language_predicate, create_jvmdoc_command):
    """
    Generate an execute method given a language predicate and command to create documentation

    language_predicate: a function that accepts a target and returns True if the target is of that
                        language
    create_jvmdoc_command: (classpath, directory, *targets) -> command (string) that will generate
                           documentation documentation for targets
    """
    catalog = self.context.products.isrequired(self.jvmdoc().product_type)
    if catalog and self.combined:
      raise TaskError(
          'Cannot provide {} target mappings for combined output'.format(self.jvmdoc().product_type))

    def docable(target):
      if not language_predicate(target):
        self.context.log.debug('Skipping [{}] because it is does not pass the language predicate'.format(target.address.spec))
        return False
      if not self._include_codegen and target.is_synthetic:
        self.context.log.debug('Skipping [{}] because it is a synthetic target'.format(target.address.spec))
        return False
      for pattern in self._exclude_patterns:
        if pattern.search(target.address.spec):
          self.context.log.debug(
            "Skipping [{}] because it matches exclude pattern '{}'".format(target.address.spec, pattern.pattern))
          return False
      return True

    targets = self.get_targets(predicate=docable)
    if not targets:
      return

    with self.invalidated(targets, invalidate_dependents=self.combined) as invalidation_check:
      def find_invalid_targets():
        invalid_targets = set()
        for vt in invalidation_check.invalid_vts:
          invalid_targets.update(vt.targets)
        return invalid_targets

      invalid_targets = list(find_invalid_targets())
      if invalid_targets:
        if self.combined:
          self._generate_combined(targets, create_jvmdoc_command)
        else:
          self._generate_individual(invalid_targets, create_jvmdoc_command)

    if self.open and self.combined:
      try:
        desktop.ui_open(os.path.join(self.workdir, 'combined', 'index.html'))
      except desktop.OpenError as e:
        raise TaskError(e)

    if catalog:
      for target in targets:
        gendir = self._gendir(target)
        jvmdocs = []
        for root, dirs, files in safe_walk(gendir):
          jvmdocs.extend(os.path.relpath(os.path.join(root, f), gendir) for f in files)
        self.context.products.get(self.jvmdoc().product_type).add(target, gendir, jvmdocs)
Ejemplo n.º 10
0
 def maybe_open_report(self):
     if self._coverage_open:
         report_file_path = os.path.join(self._settings.coverage_dir,
                                         'html', 'index.html')
         try:
             desktop.ui_open(report_file_path)
         except desktop.OpenError as e:
             raise TaskError(e)
Ejemplo n.º 11
0
 def _do_report(exception=None):
   if self._coverage:
     self._coverage.report(
       targets, tests_and_targets.keys(), self.execute_java_for_coverage, tests_failed_exception=exception)
   if self._html_report:
     html_file_path = JUnitHtmlReport().report(self.workdir, os.path.join(self.workdir, 'reports'))
     if self._open:
       desktop.ui_open(html_file_path)
Ejemplo n.º 12
0
def visualize_execution_graph(scheduler):
  with temporary_file_path(cleanup=False, suffix='.dot') as dot_file:
    scheduler.visualize_graph_to_file(dot_file)
    print('dot file saved to: {}'.format(dot_file))

  with temporary_file_path(cleanup=False, suffix='.svg') as image_file:
    subprocess.check_call('dot -Tsvg -o{} {}'.format(image_file, dot_file), shell=True)
    print('svg file saved to: {}'.format(image_file))
    desktop.ui_open(image_file)
Ejemplo n.º 13
0
def visualize_execution_graph(scheduler, request):
  with temporary_file_path(cleanup=False, suffix='.dot') as dot_file:
    scheduler.visualize_graph_to_file(request.roots, dot_file)
    print('dot file saved to: {}'.format(dot_file))

  with temporary_file_path(cleanup=False, suffix='.svg') as image_file:
    subprocess.check_call('dot -Tsvg -o{} {}'.format(image_file, dot_file), shell=True)
    print('svg file saved to: {}'.format(image_file))
    desktop.ui_open(image_file)
Ejemplo n.º 14
0
 def do_report(exc=None):
   if coverage:
     coverage.report(all_targets, self.execute_java_for_coverage, tests_failed_exception=exc)
   if self._html_report:
     self.context.log.debug('Generating JUnit HTML report...')
     html_file_path = JUnitHtmlReport().report(output_dir, os.path.join(output_dir, 'reports'))
     self.context.log.debug('JUnit HTML report generated to {}'.format(html_file_path))
     if self._open:
       desktop.ui_open(html_file_path)
Ejemplo n.º 15
0
    def report(self,
               targets,
               execute_java_for_targets,
               tests_failed_exception=None):
        if self._nothing_to_instrument:
            self._context.log.warn(
                'Nothing found to instrument, skipping report...')
            return
        if tests_failed_exception:
            self._context.log.warn(
                'Test failed: {0}'.format(tests_failed_exception))
            if self._coverage_force:
                self._context.log.warn(
                    'Generating report even though tests failed.')
            else:
                return
        cobertura_cp = self._settings.tool_classpath('cobertura-report')
        source_roots = {
            t.target_base
            for t in targets if self.is_coverage_target(t)
        }
        for report_format in ['xml', 'html']:
            report_dir = os.path.join(self._settings.coverage_dir,
                                      report_format)
            safe_mkdir(report_dir, clean=True)
            args = list(source_roots)
            args += [
                '--datafile',
                self._coverage_datafile,
                '--destination',
                report_dir,
                '--format',
                report_format,
            ]
            main = 'net.sourceforge.cobertura.reporting.ReportMain'
            result = execute_java_for_targets(
                targets,
                classpath=cobertura_cp,
                main=main,
                jvm_options=self._coverage_jvm_options,
                args=args,
                workunit_factory=self._context.new_workunit,
                workunit_name='cobertura-report-' + report_format)
            if result != 0:
                raise TaskError("java {0} ... exited non-zero ({1})"
                                " 'failed to report'".format(main, result))

        if self._coverage_open:
            coverage_html_file = os.path.join(self._settings.coverage_dir,
                                              'html', 'index.html')
            try:
                desktop.ui_open(coverage_html_file)
            except desktop.OpenError as e:
                raise TaskError(e)
Ejemplo n.º 16
0
 def _generate_combined(self, targets, create_jvmdoc_command):
   gendir = os.path.join(self.workdir, 'combined')
   if targets:
     classpath = self.classpath(targets)
     safe_mkdir(gendir, clean=True)
     command = create_jvmdoc_command(classpath, gendir, *targets)
     if command:
       self.context.log.debug("Running create_jvmdoc in {} with {}".format(gendir, " ".join(command)))
       result, gendir = create_jvmdoc(command, gendir)
       self._handle_create_jvmdoc_result(targets, result, command)
   if self.open:
     try:
       desktop.ui_open(os.path.join(gendir, 'index.html'))
     except desktop.OpenError as e:
       raise TaskError(e)
Ejemplo n.º 17
0
  def execute(self):
    """Stages IDE project artifacts to a project directory and generates IDE configuration files."""
    # Grab the targets in-play before the context is replaced by `self._prepare_project()` below.
    self._prepare_project()
    ide_file = self.generate_project(self._project)

    if ide_file and self.get_options().open:
      open_with = self.get_options().open_with
      if open_with:
        null = open(os.devnull, 'w')
        subprocess.Popen([open_with, ide_file], stdout=null, stderr=null)
      else:
        try:
          desktop.ui_open(ide_file)
        except desktop.OpenError as e:
          raise TaskError(e)
Ejemplo n.º 18
0
  def execute(self):
    if not self.url:
      raise TaskError('Unable to proceed publishing to confluence. Please set the url option.')
    deprecated_conditional(
      lambda: True,
      '1.6.0.dev0',
      'pants.backend.docgen.tasks.confluence_publish.py',
      'Use contrib.confluence.tasks.confluence_publish.py instead'
    )
    pages = []
    targets = self.context.targets()
    for target in targets:
      if isinstance(target, Page):
        for wiki_artifact in target.payload.provides:
          pages.append((target, wiki_artifact))

    urls = list()

    genmap = self.context.products.get('wiki_html')
    for page, wiki_artifact in pages:
      html_info = genmap.get((wiki_artifact, page))
      if len(html_info) > 1:
        raise TaskError('Unexpected resources for {}: {}'.format(page, html_info))
      basedir, htmls = html_info.items()[0]
      if len(htmls) != 1:
        raise TaskError('Unexpected resources for {}: {}'.format(page, htmls))
      with safe_open(os.path.join(basedir, htmls[0])) as contents:
        url = self.publish_page(
          page.address,
          wiki_artifact.config['space'],
          wiki_artifact.config['title'],
          contents.read(),
          # Default to none if not present in the hash.
          parent=wiki_artifact.config.get('parent')
        )
        if url:
          urls.append(url)
          self.context.log.info('Published {} to {}'.format(page, url))

    if self.open and urls:
      try:
        desktop.ui_open(*urls)
      except desktop.OpenError as e:
        raise TaskError(e)
Ejemplo n.º 19
0
    def execute(self):
        if not self.url:
            raise TaskError(
                'Unable to proceed publishing to confluence. Please set the url option.'
            )

        pages = []
        targets = self.context.targets()
        for target in targets:
            if isinstance(target, Page):
                for wiki_artifact in target.payload.provides:
                    pages.append((target, wiki_artifact))

        urls = list()

        genmap = self.context.products.get(MarkdownToHtml.WIKI_HTML_PRODUCT)
        for page, wiki_artifact in pages:
            html_info = genmap.get((wiki_artifact, page))
            if len(html_info) > 1:
                raise TaskError('Unexpected resources for {}: {}'.format(
                    page, html_info))
            basedir, htmls = list(html_info.items())[0]
            if len(htmls) != 1:
                raise TaskError('Unexpected resources for {}: {}'.format(
                    page, htmls))
            with safe_open(os.path.join(basedir, htmls[0]), 'r') as contents:
                url = self.publish_page(
                    page.address,
                    wiki_artifact.config['space'],
                    wiki_artifact.config['title'],
                    contents.read(),
                    # Default to none if not present in the hash.
                    parent=wiki_artifact.config.get('parent'))
                if url:
                    urls.append(url)
                    self.context.log.info('Published {} to {}'.format(
                        page, url))

        if self.open and urls:
            try:
                desktop.ui_open(*urls)
            except desktop.OpenError as e:
                raise TaskError(e)
Ejemplo n.º 20
0
  def report(self, targets, execute_java_for_targets, tests_failed_exception=None):
    if self._nothing_to_instrument:
      self._context.log.warn('Nothing found to instrument, skipping report...')
      return
    if tests_failed_exception:
      self._context.log.warn('Test failed: {0}'.format(tests_failed_exception))
      if self._coverage_force:
        self._context.log.warn('Generating report even though tests failed.')
      else:
        return
    cobertura_cp = self._settings.tool_classpath('cobertura-report')
    source_roots = { t.target_base for t in targets if self.is_coverage_target(t) }
    for report_format in ['xml', 'html']:
      report_dir = os.path.join(self._settings.coverage_dir, report_format)
      safe_mkdir(report_dir, clean=True)
      args = list(source_roots)
      args += [
        '--datafile',
        self._coverage_datafile,
        '--destination',
        report_dir,
        '--format',
        report_format,
      ]
      main = 'net.sourceforge.cobertura.reporting.ReportMain'
      result = execute_java_for_targets(targets,
                                        classpath=cobertura_cp,
                                        main=main,
                                        jvm_options=self._coverage_jvm_options,
                                        args=args,
                                        workunit_factory=self._context.new_workunit,
                                        workunit_name='cobertura-report-' + report_format)
      if result != 0:
        raise TaskError("java {0} ... exited non-zero ({1})"
                        " 'failed to report'".format(main, result))

    if self._coverage_open:
      coverage_html_file = os.path.join(self._settings.coverage_dir, 'html', 'index.html')
      try:
        desktop.ui_open(coverage_html_file)
      except desktop.OpenError as e:
        raise TaskError(e)
Ejemplo n.º 21
0
  def execute(self):
    # Heuristics to guess whether user tries to load a python project,
    # in which case intellij project sdk has to be set up manually.
    jvm_target_num = len(filter(lambda x: isinstance(x, JvmTarget), self.context.target_roots))
    python_target_num = len(filter(lambda x: isinstance(x, PythonTarget), self.context.target_roots))
    if python_target_num > jvm_target_num:
      logging.warn('This is likely a python project. Please make sure to '
                   'select the proper python interpreter as Project SDK in IntelliJ.')

    ide_file = self.generate_project()
    if ide_file and self.get_options().open:
      open_with = self.get_options().open_with
      if open_with:
        null = open(os.devnull, 'w')
        subprocess.Popen([open_with, ide_file], stdout=null, stderr=null)
      else:
        try:
          desktop.ui_open(ide_file)
        except desktop.OpenError as e:
          raise TaskError(e)
Ejemplo n.º 22
0
  def execute(self):
    if not self.url:
      raise TaskError('Unable to proceed publishing to confluence. Please set the url option.')

    pages = []
    targets = self.context.targets()
    for target in targets:
      if isinstance(target, Page):
        for wiki_artifact in target.payload.provides:
          pages.append((target, wiki_artifact))
    
    urls = list()
    
    genmap = self.context.products.get(MarkdownToHtml.WIKI_HTML_PRODUCT)
    for page, wiki_artifact in pages:
      html_info = genmap.get((wiki_artifact, page))
      if len(html_info) > 1:
        raise TaskError('Unexpected resources for {}: {}'.format(page, html_info))
      basedir, htmls = list(html_info.items())[0]
      if len(htmls) != 1:
        raise TaskError('Unexpected resources for {}: {}'.format(page, htmls))
      with safe_open(os.path.join(basedir, htmls[0]), 'r') as contents:
        url = self.publish_page(
          page.address,
          wiki_artifact.config['space'],
          wiki_artifact.config['title'],
          contents.read(),
          # Default to none if not present in the hash.
          parent=wiki_artifact.config.get('parent')
        )
        if url:
          urls.append(url)
          self.context.log.info('Published {} to {}'.format(page, url))
    
    if self.open and urls:
      try:
        desktop.ui_open(*urls)
      except desktop.OpenError as e:
        raise TaskError(e)
Ejemplo n.º 23
0
    def execute(self):
        pages = []
        targets = self.context.targets()
        for target in targets:
            if isinstance(target, Page):
                for wiki_artifact in target.payload.provides:
                    pages.append((target, wiki_artifact))

        urls = list()

        genmap = self.context.products.get("wiki_html")
        for page, wiki_artifact in pages:
            html_info = genmap.get((wiki_artifact, page))
            if len(html_info) > 1:
                raise TaskError("Unexpected resources for {}: {}".format(page, html_info))
            basedir, htmls = html_info.items()[0]
            if len(htmls) != 1:
                raise TaskError("Unexpected resources for {}: {}".format(page, htmls))
            with safe_open(os.path.join(basedir, htmls[0])) as contents:
                url = self.publish_page(
                    page.address,
                    wiki_artifact.config["space"],
                    wiki_artifact.config["title"],
                    contents.read(),
                    # Default to none if not present in the hash.
                    parent=wiki_artifact.config.get("parent"),
                )
                if url:
                    urls.append(url)
                    self.context.log.info("Published {} to {}".format(page, url))

        if self.open and urls:
            try:
                desktop.ui_open(*urls)
            except desktop.OpenError as e:
                raise TaskError(e)
Ejemplo n.º 24
0
 def _maybe_open(self, port):
   if self.get_options().open:
     try:
       desktop.ui_open('http://localhost:{port}'.format(port=port))
     except desktop.OpenError as e:
       raise TaskError(e)
Ejemplo n.º 25
0
 def _maybe_open_report(self, report_file_path):
     if report_file_path:
         try:
             desktop.ui_open(report_file_path)
         except desktop.OpenError as e:
             raise TaskError(e)
Ejemplo n.º 26
0
  def _generate_ivy_report(self, result):
    def make_empty_report(report, organisation, module, conf):
      no_deps_xml_template = dedent("""<?xml version="1.0" encoding="UTF-8"?>
        <?xml-stylesheet type="text/xsl" href="ivy-report.xsl"?>
        <ivy-report version="1.0">
          <info
            organisation="{organisation}"
            module="{module}"
            revision="latest.integration"
            conf="{conf}"
            confs="{conf}"
            date="{timestamp}"/>
        </ivy-report>
        """).format(
        organisation=organisation,
        module=module,
        conf=conf,
        timestamp=time.strftime('%Y%m%d%H%M%S'),
        )
      with open(report, 'w') as report_handle:
        print(no_deps_xml_template, file=report_handle)

    tool_classpath = self.tool_classpath('xalan')

    report = None
    org = IvyUtils.INTERNAL_ORG_NAME
    name = result.resolve_hash_name
    xsl = os.path.join(self.ivy_cache_dir, 'ivy-report.xsl')

    # Xalan needs this dir to exist - ensure that, but do no more - we have no clue where this
    # points.
    safe_mkdir(self._outdir, clean=False)

    for conf in self.get_options().confs:
      xml_path = result.report_for_conf(conf)
      if not os.path.exists(xml_path):
        # Make it clear that this is not the original report from Ivy by changing its name.
        xml_path = xml_path[:-4] + "-empty.xml"
        make_empty_report(xml_path, org, name, conf)
      out = os.path.join(self._outdir,
                         '{org}-{name}-{conf}.html'.format(org=org, name=name, conf=conf))
      args = ['-IN', xml_path, '-XSL', xsl, '-OUT', out]

      # The ivy-report.xsl genrates tab links to files with extension 'xml' by default, we
      # override that to point to the html files we generate.
      args.extend(['-param', 'extension', 'html'])

      if 0 != self.runjava(classpath=tool_classpath, main='org.apache.xalan.xslt.Process',
                           args=args, workunit_name='report'):
        raise self.Error('Failed to create html report from xml ivy report.')

      # The ivy-report.xsl is already smart enough to generate an html page with tab links to all
      # confs for a given report coordinate (org, name).  We need only display 1 of the generated
      # htmls and the user can then navigate to the others via the tab links.
      if report is None:
        report = out

    css = os.path.join(self._outdir, 'ivy-report.css')
    if os.path.exists(css):
      os.unlink(css)
    shutil.copy(os.path.join(self.ivy_cache_dir, 'ivy-report.css'), self._outdir)

    if self._open and report:
      try:
        desktop.ui_open(report)
      except desktop.OpenError as e:
        raise TaskError(e)
Ejemplo n.º 27
0
    def execute(self):
        # TODO(John Sirois): consider adding change detection

        outdir = os.path.join(self.get_options().pants_distdir, 'markdown')
        css_path = os.path.join(outdir, 'css', 'codehighlight.css')
        css = util().emit_codehighlight_css(css_path, self.code_style)
        if css:
            self.context.log.info('Emitted {}'.format(css))

        def is_page(target):
            return isinstance(target, Page)

        roots = set()
        interior_nodes = set()
        if self.open:
            dependencies_by_page = self.context.dependents(
                on_predicate=is_page, from_predicate=is_page)
            roots.update(dependencies_by_page.keys())
            for dependencies in dependencies_by_page.values():
                interior_nodes.update(dependencies)
                roots.difference_update(dependencies)
            for page in self.context.targets(is_page):
                # There are no in or out edges so we need to show show this isolated page.
                if not page.dependencies and page not in interior_nodes:
                    roots.add(page)

        with self.context.new_workunit(name='render',
                                       labels=[WorkUnitLabel.MULTITOOL]):
            plaingenmap = self.context.products.get(self.MARKDOWN_HTML_PRODUCT)
            wikigenmap = self.context.products.get(self.WIKI_HTML_PRODUCT)
            show = []
            for page in self.context.targets(is_page):

                def process_page(key,
                                 outdir,
                                 url_builder,
                                 genmap,
                                 fragment=False):
                    if page.format == 'rst':
                        with self.context.new_workunit(name='rst') as workunit:
                            html_path = self.process_rst(
                                workunit,
                                page,
                                os.path.join(outdir,
                                             util().page_to_html_path(page)),
                                os.path.join(page.payload.sources.rel_path,
                                             page.source),
                                self.fragment or fragment,
                            )
                    else:
                        with self.context.new_workunit(name='md'):
                            html_path = self.process_md(
                                os.path.join(outdir,
                                             util().page_to_html_path(page)),
                                os.path.join(page.payload.sources.rel_path,
                                             page.source),
                                self.fragment or fragment,
                                url_builder,
                                css=css,
                            )
                    self.context.log.info('Processed {} to {}'.format(
                        page.source, html_path))
                    relpath = os.path.relpath(html_path, outdir)
                    genmap.add(key, outdir, [relpath])
                    return html_path

                def url_builder(linked_page):
                    dest = util().page_to_html_path(linked_page)
                    src_dir = os.path.dirname(util().page_to_html_path(page))
                    return linked_page.name, os.path.relpath(dest, src_dir)

                page_path = os.path.join(outdir, 'html')
                html = process_page(page, page_path, url_builder, plaingenmap)
                if css and not self.fragment:
                    plaingenmap.add(page, self.workdir, list(css_path))
                if self.open and page in roots:
                    show.append(html)

                if page.provides:
                    for wiki in page.provides:
                        basedir = os.path.join(self.workdir, str(hash(wiki)))
                        process_page((wiki, page),
                                     basedir,
                                     wiki.wiki.url_builder,
                                     wikigenmap,
                                     fragment=True)

        if show:
            try:
                desktop.ui_open(*show)
            except desktop.OpenError as e:
                raise TaskError(e)
Ejemplo n.º 28
0
 def _maybe_open_report(self, report_file_path):
   if report_file_path:
     try:
       desktop.ui_open(report_file_path)
     except desktop.OpenError as e:
       raise TaskError(e)
Ejemplo n.º 29
0
  def execute(self):
    # TODO(John Sirois): consider adding change detection

    outdir = os.path.join(self.get_options().pants_distdir, 'markdown')
    css_path = os.path.join(outdir, 'css', 'codehighlight.css')
    css = util().emit_codehighlight_css(css_path, self.code_style)
    if css:
      self.context.log.info('Emitted {}'.format(css))

    def is_page(target):
      return isinstance(target, Page)

    roots = set()
    interior_nodes = set()
    if self.open:
      dependencies_by_page = self.context.dependents(on_predicate=is_page, from_predicate=is_page)
      roots.update(dependencies_by_page.keys())
      for dependencies in dependencies_by_page.values():
        interior_nodes.update(dependencies)
        roots.difference_update(dependencies)
      for page in self.context.targets(is_page):
        # There are no in or out edges so we need to show show this isolated page.
        if not page.dependencies and page not in interior_nodes:
          roots.add(page)

    with self.context.new_workunit(name='render', labels=[WorkUnitLabel.MULTITOOL]):
      plaingenmap = self.context.products.get('markdown_html')
      wikigenmap = self.context.products.get('wiki_html')
      show = []
      for page in self.context.targets(is_page):
        def process_page(key, outdir, url_builder, genmap, fragment=False):
          if page.format == 'rst':
            with self.context.new_workunit(name='rst') as workunit:
              html_path = self.process_rst(
                workunit,
                page,
                os.path.join(outdir, util().page_to_html_path(page)),
                os.path.join(page.payload.sources.rel_path, page.source),
                self.fragment or fragment,
              )
          else:
            with self.context.new_workunit(name='md'):
              html_path = self.process_md(
                os.path.join(outdir, util().page_to_html_path(page)),
                os.path.join(page.payload.sources.rel_path, page.source),
                self.fragment or fragment,
                url_builder,
                css=css,
              )
          self.context.log.info('Processed {} to {}'.format(page.source, html_path))
          relpath = os.path.relpath(html_path, outdir)
          genmap.add(key, outdir, [relpath])
          return html_path

        def url_builder(linked_page):
          dest = util().page_to_html_path(linked_page)
          src_dir = os.path.dirname(util().page_to_html_path(page))
          return linked_page.name, os.path.relpath(dest, src_dir)

        page_path = os.path.join(outdir, 'html')
        html = process_page(page, page_path, url_builder, plaingenmap)
        if css and not self.fragment:
          plaingenmap.add(page, self.workdir, list(css_path))
        if self.open and page in roots:
          show.append(html)

        if page.provides:
          for wiki in page.provides:
            basedir = os.path.join(self.workdir, str(hash(wiki)))
            process_page((wiki, page), basedir, wiki.wiki.url_builder, wikigenmap, fragment=True)

    if show:
      try:
        desktop.ui_open(*show)
      except desktop.OpenError as e:
        raise TaskError(e)
Ejemplo n.º 30
0
 def maybe_open_report(self):
   desktop.ui_open(self._report_file_path)
Ejemplo n.º 31
0
 def _maybe_open(self, port):
     if self.get_options().open:
         try:
             desktop.ui_open('http://localhost:{port}'.format(port=port))
         except desktop.OpenError as e:
             raise TaskError(e)
Ejemplo n.º 32
0
    def _generate_ivy_report(self, result):
        def make_empty_report(report, organisation, module, conf):
            no_deps_xml_template = dedent("""
                <?xml version="1.0" encoding="UTF-8"?>
                <?xml-stylesheet type="text/xsl" href="ivy-report.xsl"?>
                <ivy-report version="1.0">
                  <info
                    organisation="{organisation}"
                    module="{module}"
                    revision="latest.integration"
                    conf="{conf}"
                    confs="{conf}"
                    date="{timestamp}"/>
                </ivy-report>
                """).format(
                organisation=organisation,
                module=module,
                conf=conf,
                timestamp=time.strftime("%Y%m%d%H%M%S"),
            )
            with open(report, "w") as report_handle:
                print(no_deps_xml_template, file=report_handle)

        tool_classpath = self.tool_classpath("xalan")

        report = None
        org = IvyUtils.INTERNAL_ORG_NAME
        name = result.resolve_hash_name
        xsl = os.path.join(self.ivy_resolution_cache_dir, "ivy-report.xsl")

        # Xalan needs this dir to exist - ensure that, but do no more - we have no clue where this
        # points.
        safe_mkdir(self._outdir, clean=False)

        for conf in self.get_options().confs:
            xml_path = result.report_for_conf(conf)
            if not os.path.exists(xml_path):
                # Make it clear that this is not the original report from Ivy by changing its name.
                xml_path = xml_path[:-4] + "-empty.xml"
                make_empty_report(xml_path, org, name, conf)
            out = os.path.join(self._outdir, f"{org}-{name}-{conf}.html")
            args = ["-IN", xml_path, "-XSL", xsl, "-OUT", out]

            # The ivy-report.xsl generates tab links to files with extension 'xml' by default, we
            # override that to point to the html files we generate.
            args.extend(["-param", "extension", "html"])

            if 0 != self.runjava(
                    classpath=tool_classpath,
                    main="org.apache.xalan.xslt.Process",
                    args=args,
                    workunit_name="report",
            ):
                raise self.Error(
                    "Failed to create html report from xml ivy report.")

            # The ivy-report.xsl is already smart enough to generate an html page with tab links to all
            # confs for a given report coordinate (org, name).  We need only display 1 of the generated
            # htmls and the user can then navigate to the others via the tab links.
            if report is None:
                report = out

        css = os.path.join(self._outdir, "ivy-report.css")
        if os.path.exists(css):
            os.unlink(css)
        shutil.copy(
            os.path.join(self.ivy_resolution_cache_dir, "ivy-report.css"),
            self._outdir)

        if self._open and report:
            try:
                desktop.ui_open(report)
            except desktop.OpenError as e:
                raise TaskError(e)