Beispiel #1
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 %s: %s' %
                                (page, html_info))
            basedir, htmls = html_info.items()[0]
            if len(htmls) != 1:
                raise TaskError('Unexpected resources for %s: %s' %
                                (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 %s to %s' % (page, url))

        if self.open and urls:
            binary_util.ui_open(*urls)
Beispiel #2
0
  def execute(self):
    """Stages IDE project artifacts to a project directory and generates IDE configuration files."""
    self._prepare_project()

    def _checkstyle_enabled():
      for goal in Goal.all():
        if goal.has_task_of_type(Checkstyle):
          return True
      return False

    if _checkstyle_enabled():
      checkstyle_classpath = self.tool_classpath(self.checkstyle_bootstrap_key)
    else:
      checkstyle_classpath = []

    if self.scalac_bootstrap_key:
      scalac_classpath = self.tool_classpath(self.scalac_bootstrap_key)
    else:
      scalac_classpath = []

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

    idefile = self.generate_project(self._project)
    if idefile:
      binary_util.ui_open(idefile)
  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 %s: %s' % (page, html_info))
      basedir, htmls = html_info.items()[0]
      if len(htmls) != 1:
        raise TaskError('Unexpected resources for %s: %s' % (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 %s to %s' % (page, url))

    if self.open and urls:
      binary_util.ui_open(*urls)
Beispiel #4
0
    def execute(self):
        """Stages IDE project artifacts to a project directory and generates IDE configuration files."""
        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 = self.tool_classpath('scalac',
                                                   scope='compile.scala')

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

        idefile = self.generate_project(self._project)
        if idefile:
            binary_util.ui_open(idefile)
Beispiel #5
0
    def execute(self):
        """Stages IDE project artifacts to a project directory and generates IDE configuration files."""
        self._prepare_project()

        def _checkstyle_enabled():
            for goal in Goal.all():
                if goal.has_task_of_type(Checkstyle):
                    return True
            return False

        if _checkstyle_enabled():
            checkstyle_classpath = self.tool_classpath(
                self.checkstyle_bootstrap_key)
        else:
            checkstyle_classpath = []

        if self.scalac_bootstrap_key:
            scalac_classpath = self.tool_classpath(self.scalac_bootstrap_key)
        else:
            scalac_classpath = []

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

        idefile = self.generate_project(self._project)
        if idefile:
            binary_util.ui_open(idefile)
  def execute(self, targets):
    pages = []
    for target in targets:
      if isinstance(target, Page):
        wikiconfig = target.wiki_config(self.wiki())
        if wikiconfig:
          pages.append((target, wikiconfig))

    urls = list()

    genmap = self.context.products.get('wiki_html')
    for page, wikiconfig in pages:
      html_info = genmap.get((self.wiki(), page))
      if len(html_info) > 1:
        raise TaskError('Unexpected resources for %s: %s' % (page, html_info))
      basedir, htmls = html_info.items()[0]
      if len(htmls) != 1:
        raise TaskError('Unexpected resources for %s: %s' % (page, htmls))
      with safe_open(os.path.join(basedir, htmls[0])) as contents:
        url = self.publish_page(
          page.address,
          wikiconfig['space'],
          wikiconfig['title'],
          contents.read(),
          parent=wikiconfig.get('parent')
        )
        if url:
          urls.append(url)
          self.context.log.info('Published %s to %s' % (page, url))

    if self.open and urls:
      binary_util.ui_open(*urls)
Beispiel #7
0
    def execute(self, targets):
        pages = []
        for target in targets:
            if isinstance(target, Page):
                wikiconfig = target.wiki_config(self.wiki())
                if wikiconfig:
                    pages.append((target, wikiconfig))

        urls = list()

        genmap = self.context.products.get('wiki_html')
        for page, wikiconfig in pages:
            html_info = genmap.get((self.wiki(), page))
            if len(html_info) > 1:
                raise TaskError('Unexpected resources for %s: %s' %
                                (page, html_info))
            basedir, htmls = html_info.items()[0]
            if len(htmls) != 1:
                raise TaskError('Unexpected resources for %s: %s' %
                                (page, htmls))
            with safe_open(os.path.join(basedir, htmls[0])) as contents:
                url = self.publish_page(page.address,
                                        wikiconfig['space'],
                                        wikiconfig['title'],
                                        contents.read(),
                                        parent=wikiconfig.get('parent'))
                if url:
                    urls.append(url)
                    self.context.log.info('Published %s to %s' % (page, url))

        if self.open and urls:
            binary_util.ui_open(*urls)
Beispiel #8
0
    def report(self, targets, tests, tests_failed_exception=None):
        if tests_failed_exception:
            self._context.log.warn('Test failed: {0}'.format(
                str(tests_failed_exception)))
            if self._coverage_force:
                self._context.log.warn(
                    'Generating report even though tests failed')
            else:
                return
        args = [
            'report', '-in', self._coverage_metadata_file, '-in',
            self._coverage_file, '-exit'
        ]
        source_bases = set()

        def collect_source_base(target):
            if self.is_coverage_target(target):
                source_bases.add(target.target_base)

        for target in self._test_target_candidates(targets):
            target.walk(collect_source_base)
        for source_base in source_bases:
            args.extend(['-sp', source_base])

        sorting = ['-Dreport.sort', '+name,+class,+method,+block']
        if self._coverage_report_console:
            args.extend([
                '-r', 'txt', '-Dreport.txt.out.file={0}'.format(
                    self._coverage_console_file)
            ] + sorting)
        if self._coverage_report_xml:
            args.extend([
                '-r', 'xml',
                '-Dreport.xml.out.file={0}'.format(self._coverage_xml_file)
            ])
        if self._coverage_report_html:
            args.extend([
                '-r', 'html', '-Dreport.html.out.file={0}'.format(
                    self._coverage_html_file), '-Dreport.out.encoding=UTF-8'
            ] + sorting)

        main = 'emma'
        result = execute_java(classpath=self._emma_classpath,
                              main=main,
                              jvm_options=self._coverage_jvm_options,
                              args=args,
                              workunit_factory=self._context.new_workunit,
                              workunit_name='emma-report')
        if result != 0:
            raise TaskError(
                "java {0} ... exited non-zero ({1})"
                " 'failed to generate code coverage reports'".format(
                    main, result))

        if self._coverage_report_console:
            with safe_open(self._coverage_console_file) as console_report:
                sys.stdout.write(console_report.read())
        if self._coverage_report_html_open:
            binary_util.ui_open(self._coverage_html_file)
Beispiel #9
0
  def console_output(self, targets):
    DONE = '__done_reporting'

    port = ReportingServerManager.get_current_server_port()
    if port:
      return ['Server already running at http://localhost:%d' % port]

    def run_server(reporting_queue):
      def report_launch(actual_port):
        reporting_queue.put(
          'Launching server with pid %d at http://localhost:%d' % (os.getpid(), actual_port))

      def done_reporting():
        reporting_queue.put(DONE)

      try:
        # We mustn't block in the child, because the multiprocessing module enforces that the
        # parent either kills or joins to it. Instead we fork a grandchild that inherits the queue
        # but is allowed to block indefinitely on the server loop.
        if not os.fork():
          # Child process.
          info_dir = RunInfo.dir(self.context.config)
          # If these are specified explicitly in the config, use those. Otherwise
          # they will be None, and we'll use the ones baked into this package.
          template_dir = self.context.config.get('reporting', 'reports_template_dir')
          assets_dir = self.context.config.get('reporting', 'reports_assets_dir')
          settings = ReportingServer.Settings(info_dir=info_dir, template_dir=template_dir,
                                              assets_dir=assets_dir, root=get_buildroot(),
                                              allowed_clients=self.context.options.allowed_clients)
          server = ReportingServer(self.context.options.port, settings)
          actual_port = server.server_port()
          ReportingServerManager.save_current_server_port(actual_port)
          report_launch(actual_port)
          done_reporting()
          # Block forever here.
          server.start()
      except socket.error:
        done_reporting()
        raise

    # We do reporting on behalf of the child process (necessary, since reporting may be buffered in a
    # background thread). We use multiprocessing.Process() to spawn the child so we can use that
    # module's inter-process Queue implementation.
    reporting_queue = multiprocessing.Queue()
    proc = multiprocessing.Process(target=run_server, args=[reporting_queue])
    proc.daemon = True
    proc.start()
    s = reporting_queue.get()
    ret = []
    while s != DONE:
      ret.append(s)
      s = reporting_queue.get()
    # The child process is done reporting, and is now in the server loop, so we can proceed.
    server_port = ReportingServerManager.get_current_server_port()
    if server_port:
      binary_util.ui_open('http://localhost:%d/run/latest' % server_port)
    return ret
Beispiel #10
0
    def _generate_ivy_report(self, targets):
        def make_empty_report(report, organisation, module, conf):
            no_deps_xml_template = """
        <?xml version="1.0" encoding="UTF-8"?>
        <?xml-stylesheet type="text/xsl" href="ivy-report.xsl"?>
        <ivy-report version="1.0">
          <info
            organisation="%(organisation)s"
            module="%(module)s"
            revision="latest.integration"
            conf="%(conf)s"
            confs="%(conf)s"
            date="%(timestamp)s"/>
        </ivy-report>
      """
            no_deps_xml = no_deps_xml_template % dict(
                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, file=report_handle)

        classpath = self.tool_classpath(self._ivy_bootstrap_key,
                                        self.create_java_executor())

        reports = []
        org, name = self._ivy_utils.identify(targets)
        xsl = os.path.join(self._cachedir, '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._confs:
            params = dict(org=org, name=name, conf=conf)
            xml = self._ivy_utils.xml_report_path(targets, conf)
            if not os.path.exists(xml):
                make_empty_report(xml, org, name, conf)
            out = os.path.join(self._outdir,
                               '%(org)s-%(name)s-%(conf)s.html' % params)
            args = ['-IN', xml, '-XSL', xsl, '-OUT', out]
            if 0 != self.runjava(classpath=classpath,
                                 main='org.apache.xalan.xslt.Process',
                                 args=args,
                                 workunit_name='report'):
                raise TaskError
            reports.append(out)

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

        if self._open:
            binary_util.ui_open(*reports)
Beispiel #11
0
 def _generate_combined(self, classpath, targets, create_jvmdoc_command):
   gendir = os.path.join(self.workdir, 'combined')
   if targets:
     safe_mkdir(gendir, clean=True)
     command = create_jvmdoc_command(classpath, gendir, *targets)
     if command:
       create_jvmdoc(command, gendir)
   if self.open:
     binary_util.ui_open(os.path.join(gendir, 'index.html'))
Beispiel #12
0
 def _generate_combined(self, classpath, targets, create_jvmdoc_command):
   gendir = os.path.join(self.workdir, 'combined')
   if targets:
     safe_mkdir(gendir, clean=True)
     command = create_jvmdoc_command(classpath, gendir, *targets)
     if command:
       self.context.log.debug("Running create_jvmdoc in %s with %s" % (gendir, " ".join(command)))
       result, gendir = create_jvmdoc(command, gendir)
       self._handle_create_jvmdoc_result(targets, result, command)
   if self.open:
     binary_util.ui_open(os.path.join(gendir, 'index.html'))
Beispiel #13
0
  def _generate_ivy_report(self, targets):
    def make_empty_report(report, organisation, module, conf):
      no_deps_xml_template = """
        <?xml version="1.0" encoding="UTF-8"?>
        <?xml-stylesheet type="text/xsl" href="ivy-report.xsl"?>
        <ivy-report version="1.0">
          <info
            organisation="%(organisation)s"
            module="%(module)s"
            revision="latest.integration"
            conf="%(conf)s"
            confs="%(conf)s"
            date="%(timestamp)s"/>
        </ivy-report>
      """
      no_deps_xml = no_deps_xml_template % dict(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, file=report_handle)

    classpath = self._jvm_tool_bootstrapper.get_jvm_tool_classpath(self._ivy_bootstrap_key,
                                                                   self.create_java_executor())

    reports = []
    org, name = self._ivy_utils.identify(targets)
    xsl = os.path.join(self._cachedir, '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._confs:
      params = dict(org=org, name=name, conf=conf)
      xml = self._ivy_utils.xml_report_path(targets, conf)
      if not os.path.exists(xml):
        make_empty_report(xml, org, name, conf)
      out = os.path.join(self._outdir, '%(org)s-%(name)s-%(conf)s.html' % params)
      args = ['-IN', xml, '-XSL', xsl, '-OUT', out]
      if 0 != self.runjava(classpath=classpath, main='org.apache.xalan.xslt.Process',
                           args=args, workunit_name='report'):
        raise TaskError
      reports.append(out)

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

    if self._open:
      binary_util.ui_open(*reports)
Beispiel #14
0
    def report(self, targets, tests, junit_classpath):
        emma_classpath = self._task_exports.tool_classpath(
            self._emma_bootstrap_key)
        args = [
            'report', '-in', self._coverage_metadata_file, '-in',
            self._coverage_file, '-exit'
        ]
        source_bases = set()

        def collect_source_base(target):
            if self.is_coverage_target(target):
                source_bases.add(target.target_base)

        for target in self._test_target_candidates(targets):
            target.walk(collect_source_base)
        for source_base in source_bases:
            args.extend(['-sp', source_base])

        sorting = ['-Dreport.sort', '+name,+class,+method,+block']
        if self._coverage_report_console:
            args.extend([
                '-r', 'txt',
                '-Dreport.txt.out.file=%s' % self._coverage_console_file
            ] + sorting)
        if self._coverage_report_xml:
            args.extend([
                '-r', 'xml',
                '-Dreport.xml.out.file=%s' % self._coverage_xml_file
            ])
        if self._coverage_report_html:
            args.extend([
                '-r', 'html',
                '-Dreport.html.out.file=%s' %
                self._coverage_html_file, '-Dreport.out.encoding=UTF-8'
            ] + sorting)

        main = 'emma'
        result = execute_java(classpath=emma_classpath,
                              main=main,
                              args=args,
                              workunit_factory=self._context.new_workunit,
                              workunit_name='emma-report')
        if result != 0:
            raise TaskError("java %s ... exited non-zero (%i)"
                            " 'failed to generate code coverage reports'" %
                            (main, result))

        if self._coverage_report_console:
            with safe_open(self._coverage_console_file) as console_report:
                sys.stdout.write(console_report.read())
        if self._coverage_report_html_open:
            binary_util.ui_open(self._coverage_html_file)
Beispiel #15
0
  def report(self, targets, tests, tests_failed_exception=None):
    if tests_failed_exception:
      self._context.log.warn('Test failed: {0}'.format(str(tests_failed_exception)))
      if self._coverage_force:
        self._context.log.warn('Generating report even though tests failed')
      else:
        return
    args = [
      'report',
      '-in', self._coverage_metadata_file,
      '-in', self._coverage_file,
      '-exit'
      ]
    source_bases = set()

    def collect_source_base(target):
      if self.is_coverage_target(target):
        source_bases.add(target.target_base)
    for target in self._test_target_candidates(targets):
      target.walk(collect_source_base)
    for source_base in source_bases:
      args.extend(['-sp', source_base])

    sorting = ['-Dreport.sort', '+name,+class,+method,+block']
    if self._coverage_report_console:
      args.extend(['-r', 'txt',
                   '-Dreport.txt.out.file={0}'.format(self._coverage_console_file)] + sorting)
    if self._coverage_report_xml:
      args.extend(['-r', 'xml', '-Dreport.xml.out.file={0}'.format(self._coverage_xml_file)])
    if self._coverage_report_html:
      args.extend(['-r', 'html',
                   '-Dreport.html.out.file={0}'.format(self._coverage_html_file),
                   '-Dreport.out.encoding=UTF-8'] + sorting)

    main = 'emma'
    result = execute_java(classpath=self._emma_classpath,
                          main=main,
                          jvm_options=self._coverage_jvm_options,
                          args=args,
                          workunit_factory=self._context.new_workunit,
                          workunit_name='emma-report')
    if result != 0:
      raise TaskError("java {0} ... exited non-zero ({1})"
                      " 'failed to generate code coverage reports'".format(main, result))

    if self._coverage_report_console:
      with safe_open(self._coverage_console_file) as console_report:
        sys.stdout.write(console_report.read())
    if self._coverage_report_html_open:
      binary_util.ui_open(self._coverage_html_file)
Beispiel #16
0
  def report(self, targets, tests, junit_classpath):
    args = [
      'report',
      '-in', self._coverage_metadata_file,
      '-in', self._coverage_file,
      '-exit'
      ]
    source_bases = set()

    def collect_source_base(target):
      if self.is_coverage_target(target):
        source_bases.add(target.target_base)
    for target in self._test_target_candidates(targets):
      target.walk(collect_source_base)
    for source_base in source_bases:
      args.extend(['-sp', source_base])

    sorting = ['-Dreport.sort', '+name,+class,+method,+block']
    if self._coverage_report_console:
      args.extend(['-r', 'txt',
                   '-Dreport.txt.out.file=%s' % self._coverage_console_file] + sorting)
    if self._coverage_report_xml:
      args.extend(['-r', 'xml', '-Dreport.xml.out.file=%s' % self._coverage_xml_file])
    if self._coverage_report_html:
      args.extend(['-r', 'html',
                   '-Dreport.html.out.file=%s' % self._coverage_html_file,
                   '-Dreport.out.encoding=UTF-8'] + sorting)

    main = 'emma'
    result = execute_java(classpath=self._emma_classpath, main=main, args=args,
                          workunit_factory=self._context.new_workunit,
                          workunit_name='emma-report')
    if result != 0:
      raise TaskError("java %s ... exited non-zero (%i)"
                      " 'failed to generate code coverage reports'" % (main, result))

    if self._coverage_report_console:
      with safe_open(self._coverage_console_file) as console_report:
        sys.stdout.write(console_report.read())
    if self._coverage_report_html_open:
      binary_util.ui_open(self._coverage_html_file)
Beispiel #17
0
  def execute(self, targets):
    """Stages IDE project artifacts to a project directory and generates IDE configuration files."""
    checkstyle_enabled = len(Phase.goals_of_type(Checkstyle)) > 0
    if checkstyle_enabled:
      checkstyle_classpath = self.tool_classpath(self.checkstyle_bootstrap_key)
    else:
      checkstyle_classpath = []

    if self.scalac_bootstrap_key:
      scalac_classpath = self.tool_classpath(self.scalac_bootstrap_key)
    else:
      scalac_classpath = []

    self._project.set_tool_classpaths(checkstyle_classpath, scalac_classpath)

    self.map_internal_jars(targets)
    self.map_external_jars()

    idefile = self.generate_project(self._project)
    if idefile:
      binary_util.ui_open(idefile)
Beispiel #18
0
  def execute(self):
    """Stages IDE project artifacts to a project directory and generates IDE configuration files."""
    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 = self.tool_classpath('scalac', scope='compile.scala')

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

    idefile = self.generate_project(self._project)
    if idefile:
      binary_util.ui_open(idefile)
Beispiel #19
0
    def execute(self, targets):
        """Stages IDE project artifacts to a project directory and generates IDE configuration files."""
        checkstyle_enabled = len(Phase.goals_of_type(Checkstyle)) > 0
        if checkstyle_enabled:
            checkstyle_classpath = self.tool_classpath(
                self.checkstyle_bootstrap_key)
        else:
            checkstyle_classpath = []

        if self.scalac_bootstrap_key:
            scalac_classpath = self.tool_classpath(self.scalac_bootstrap_key)
        else:
            scalac_classpath = []

        self._project.set_tool_classpaths(checkstyle_classpath,
                                          scalac_classpath)

        self.map_internal_jars(targets)
        self.map_external_jars()

        idefile = self.generate_project(self._project)
        if idefile:
            binary_util.ui_open(idefile)
Beispiel #20
0
 def maybe_open(port):
     if self.get_options().open:
         binary_util.ui_open('http://localhost:%d' % port)
Beispiel #21
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 = 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=[WorkUnit.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, 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, 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 = page_to_html_path(linked_page)
          src_dir = os.path.dirname(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:
      binary_util.ui_open(*show)
Beispiel #22
0
 def maybe_open(port):
   if self.get_options().open:
     binary_util.ui_open('http://localhost:%d' % port)
Beispiel #23
0
    def _generate_ivy_report(self, targets):
        def make_empty_report(report, organisation, module, conf):
            no_deps_xml_template = """
        <?xml version="1.0" encoding="UTF-8"?>
        <?xml-stylesheet type="text/xsl" href="ivy-report.xsl"?>
        <ivy-report version="1.0">
          <info
            organisation="%(organisation)s"
            module="%(module)s"
            revision="latest.integration"
            conf="%(conf)s"
            confs="%(conf)s"
            date="%(timestamp)s"/>
        </ivy-report>
      """
            no_deps_xml = no_deps_xml_template % dict(
                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, file=report_handle)

        tool_classpath = self.tool_classpath('xalan')

        report = None
        org, name = IvyUtils.identify(targets)
        xsl = os.path.join(self._cachedir, '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.confs:
            params = dict(org=org, name=name, conf=conf)
            xml = IvyUtils.xml_report_path(targets, conf)
            if not os.path.exists(xml):
                make_empty_report(xml, org, name, conf)
            out = os.path.join(self._outdir,
                               '%(org)s-%(name)s-%(conf)s.html' % params)
            args = ['-IN', xml, '-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 IvyResolve.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._cachedir, 'ivy-report.css'),
                    self._outdir)

        if self._open and report:
            binary_util.ui_open(report)
 def maybe_open(port):
   if self.get_options().open:
     binary_util.ui_open('http://localhost:{port}'.format(port=port))
Beispiel #25
0
    def execute(self, targets):
        # TODO(John Sirois): consider adding change detection

        css_relpath = os.path.join('css', 'codehighlight.css')
        css = emit_codehighlight_css(os.path.join(self.workdir, css_relpath),
                                     self.code_style)
        if css:
            self.context.log.info('Emitted %s' % 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)

        plaingenmap = self.context.products.get('markdown_html')
        wikigenmap = self.context.products.get('wiki_html')
        show = []
        for page in filter(is_page, targets):
            _, ext = os.path.splitext(page.source)
            if ext in self.extensions:

                def process_page(key,
                                 outdir,
                                 url_builder,
                                 config,
                                 genmap,
                                 fragment=False):
                    html_path = self.process(outdir,
                                             page.target_base,
                                             page.source,
                                             self.fragment or fragment,
                                             url_builder,
                                             config,
                                             css=css)
                    self.context.log.info('Processed %s to %s' %
                                          (page.source, html_path))
                    relpath = os.path.relpath(html_path, outdir)
                    genmap.add(key, outdir, [relpath])
                    return html_path

                def url_builder(linked_page, config=None):
                    path, ext = os.path.splitext(linked_page.source)
                    return linked_page.name, os.path.relpath(
                        path + '.html', os.path.dirname(page.source))

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

                for wiki in page.wikis():

                    def get_config(page):
                        return page.wiki_config(wiki)

                    basedir = os.path.join(self.workdir, wiki.id)
                    process_page((wiki, page),
                                 basedir,
                                 wiki.url_builder,
                                 get_config,
                                 wikigenmap,
                                 fragment=True)

        if show:
            binary_util.ui_open(*show)
Beispiel #26
0
 def maybe_open(port):
     if self.context.options.server_open:
         binary_util.ui_open('http://localhost:%d' % port)
Beispiel #27
0
    def execute(self):
        # TODO(John Sirois): consider adding change detection

        outdir = os.path.join(self.context.config.getdefault('pants_distdir'),
                              'markdown')
        css_path = os.path.join(outdir, 'css', 'codehighlight.css')
        css = emit_codehighlight_css(css_path, self.code_style)
        if css:
            self.context.log.info('Emitted %s' % 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)

        plaingenmap = self.context.products.get('markdown_html')
        wikigenmap = self.context.products.get('wiki_html')
        show = []
        for page in self.context.targets(is_page):
            _, ext = os.path.splitext(page.source)
            if ext in self.extensions:

                def process_page(key,
                                 outdir,
                                 url_builder,
                                 config,
                                 genmap,
                                 fragment=False):
                    html_path = self.process(
                        os.path.join(outdir, page_to_html_path(page)),
                        os.path.join(page.payload.sources.rel_path,
                                     page.source),
                        self.fragment or fragment,
                        url_builder,
                        config,
                        css=css)
                    self.context.log.info('Processed %s to %s' %
                                          (page.source, html_path))
                    relpath = os.path.relpath(html_path, outdir)
                    genmap.add(key, outdir, [relpath])
                    return html_path

                def url_builder(linked_page, config=None):
                    dest = page_to_html_path(linked_page)
                    src_dir = os.path.dirname(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,
                                    lambda p: None, 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:

                        def get_config(page):
                            # Take the first provided WikiArtifact. If a page is published to multiple places, it's
                            # undefined what the "proper" one is to link to. So we just take whatever is "first".
                            for wiki_artifact in page.payload.provides:
                                return wiki_artifact.config

                        basedir = os.path.join(self.workdir, str(hash(wiki)))
                        process_page((wiki, page),
                                     basedir,
                                     wiki.wiki.url_builder,
                                     get_config,
                                     wikigenmap,
                                     fragment=True)

        if show:
            binary_util.ui_open(*show)
Beispiel #28
0
 def maybe_open(port):
   if self.context.options.server_open:
     binary_util.ui_open('http://localhost:%d' % port)
Beispiel #29
0
  def execute(self):
    # TODO(John Sirois): consider adding change detection

    css_relpath = os.path.join('css', 'codehighlight.css')
    css = emit_codehighlight_css(os.path.join(self.workdir, css_relpath), self.code_style)
    if css:
      self.context.log.info('Emitted %s' % 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)

    plaingenmap = self.context.products.get('markdown_html')
    wikigenmap = self.context.products.get('wiki_html')
    show = []
    for page in self.context.targets(is_page):
      _, ext = os.path.splitext(page.source)
      if ext in self.extensions:
        def process_page(key, outdir, url_builder, config, genmap, fragment=False):
          html_path = self.process(
            outdir,
            os.path.join(page.payload.sources_rel_path, page.source),
            self.fragment or fragment,
            url_builder,
            config,
            page.identifier,
            css=css
          )
          self.context.log.info('Processed %s to %s' % (page.source, html_path))
          relpath = os.path.relpath(html_path, outdir)
          genmap.add(key, outdir, [relpath])
          return html_path

        def url_builder(linked_page, config=None):
          dest = id_to_html_path(linked_page.identifier)
          src_dir = os.path.dirname(id_to_html_path(page.identifier))
          return linked_page.name, os.path.relpath(dest, src_dir)

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

        if page.provides:
          for wiki in page.provides:
            def get_config(page):
              # Take the first provided WikiArtifact. If a page is published to multiple places, it's
              # undefined what the "proper" one is to link to. So we just take whatever is "first".
              for wiki_artifact in page.payload.provides:
                return wiki_artifact.config
            basedir = os.path.join(self.workdir, str(hash(wiki)))
            process_page((wiki, page), basedir, wiki.wiki.url_builder, get_config,
                         wikigenmap, fragment=True)

    if show:
      binary_util.ui_open(*show)
Beispiel #30
0
  def execute(self):
    # TODO(John Sirois): consider adding change detection

    css_relpath = os.path.join('css', 'codehighlight.css')
    css = emit_codehighlight_css(os.path.join(self.workdir, css_relpath), self.code_style)
    if css:
      self.context.log.info('Emitted %s' % 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)

    plaingenmap = self.context.products.get('markdown_html')
    wikigenmap = self.context.products.get('wiki_html')
    show = []
    for page in self.context.targets(is_page):
      _, ext = os.path.splitext(page.source)
      if ext in self.extensions:
        def process_page(key, outdir, url_builder, config, genmap, fragment=False):
          html_path = self.process(
            outdir,
            page.target_base,
            page.source,
            self.fragment or fragment,
            url_builder,
            config,
            css=css
          )
          self.context.log.info('Processed %s to %s' % (page.source, html_path))
          relpath = os.path.relpath(html_path, outdir)
          genmap.add(key, outdir, [relpath])
          return html_path

        def url_builder(linked_page, config=None):
          path, ext = os.path.splitext(linked_page.source)
          return linked_page.name, os.path.relpath(path + '.html', os.path.dirname(page.source))

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

        for wiki in page.wikis():
          def get_config(page):
            return page.wiki_config(wiki)
          basedir = os.path.join(self.workdir, wiki.id)
          process_page((wiki, page), basedir, wiki.url_builder, get_config,
                       wikigenmap, fragment=True)

    if show:
      binary_util.ui_open(*show)
Beispiel #31
0
  def _generate_ivy_report(self, targets):
    def make_empty_report(report, organisation, module, conf):
      no_deps_xml_template = """
        <?xml version="1.0" encoding="UTF-8"?>
        <?xml-stylesheet type="text/xsl" href="ivy-report.xsl"?>
        <ivy-report version="1.0">
          <info
            organisation="%(organisation)s"
            module="%(module)s"
            revision="latest.integration"
            conf="%(conf)s"
            confs="%(conf)s"
            date="%(timestamp)s"/>
        </ivy-report>
      """
      no_deps_xml = no_deps_xml_template % dict(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, file=report_handle)

    tool_classpath = self.tool_classpath('xalan')

    report = None
    org, name = IvyUtils.identify(targets)
    xsl = os.path.join(self._cachedir, '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.confs:
      params = dict(org=org, name=name, conf=conf)
      xml = IvyUtils.xml_report_path(targets, conf)
      if not os.path.exists(xml):
        make_empty_report(xml, org, name, conf)
      out = os.path.join(self._outdir, '%(org)s-%(name)s-%(conf)s.html' % params)
      args = ['-IN', xml, '-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 IvyResolve.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._cachedir, 'ivy-report.css'), self._outdir)

    if self._open and report:
      binary_util.ui_open(report)
Beispiel #32
0
 def _maybe_open(self, port):
     if self.get_options().open:
         binary_util.ui_open('http://localhost:{port}'.format(port=port))