Beispiel #1
0
  def test_list_goals_graph(self):
    Phase.clear()

    Goal(name=self._LIST_GOALS_NAME, action=ListGoals)\
      .install().with_description(self._LIST_GOALS_DESC)
    Goal(name=self._LLAMA_NAME, action=ListGoalsTest.LlamaTask)\
      .install().with_description(self._LLAMA_DESC)
    Goal(name=self._ALPACA_NAME, action=ListGoalsTest.AlpacaTask, dependencies=[self._LLAMA_NAME])\
      .install()

    self.assert_console_output(
      'digraph G {\n  rankdir=LR;\n  graph [compound=true];',
      '  subgraph cluster_goals {\n    node [style=filled];\n    color = blue;\n    label = "goals";',
      '    goals_goals [label="goals"];',
      '  }',
      '  subgraph cluster_llama {\n    node [style=filled];\n    color = blue;\n    label = "llama";',
      '    llama_llama [label="llama"];',
      '  }',
      '  subgraph cluster_alpaca {\n    node [style=filled];\n    color = blue;\n    label = "alpaca";',
      '    alpaca_alpaca [label="alpaca"];',
      '  }',
      '  alpaca_alpaca -> llama_llama [ltail=cluster_alpaca lhead=cluster_llama];',
      '}',
      args=['--test-graph'],
    )
Beispiel #2
0
  def test_list_goals(self):
    Phase.clear()
    self.assert_console_output(self._INSTALLED_HEADER)

    Goal(name=self._LIST_GOALS_NAME, action=ListGoals)\
      .install().with_description(self._LIST_GOALS_DESC)
    self.assert_console_output(
      self._INSTALLED_HEADER,
      '  %s: %s' % (self._LIST_GOALS_NAME, self._LIST_GOALS_DESC),
    )

    Goal(name=self._LLAMA_NAME, action=ListGoalsTest.LlamaTask)\
      .install().with_description(self._LLAMA_DESC)
    self.assert_console_output(
      self._INSTALLED_HEADER,
      '  %s: %s' % (self._LIST_GOALS_NAME, self._LIST_GOALS_DESC),
      '  %s: %s' % (self._LLAMA_NAME, self._LLAMA_DESC),
    )

    Goal(name=self._ALPACA_NAME, action=ListGoalsTest.AlpacaTask, dependencies=[self._LLAMA_NAME])\
      .install()
    self.assert_console_output(
      self._INSTALLED_HEADER,
      '  %s: %s' % (self._LIST_GOALS_NAME, self._LIST_GOALS_DESC),
      '  %s: %s' % (self._LLAMA_NAME, self._LLAMA_DESC),
    )
Beispiel #3
0
 def install(self, phase=None, first=False, replace=False, before=None):
   """
     Installs this goal in the specified phase (or a new phase with the same name as this Goal),
     appending to any pre-existing goals unless first=True in which case it is installed as the
     first goal in the phase.  If replace=True then this goal replaces all others for the phase.
     The phase this goal is installed in is returned. If before is not None, installs this goal
     right before the goal marked by before.
   """
   phase = Phase(phase or self.name)
   phase.install(self, first, replace, before)
   return phase
Beispiel #4
0
  def install(self, phase=None, first=False, replace=False, before=None, after=None):
    """
      Installs this goal in the specified phase (or a new phase with the same name as this Goal).

      The placement of the goal in the execution list of the phase defaults to the end but can be
      influence by specifying exactly one of the following arguments:

      first: Places this goal 1st in the phase's execution list
      replace: Replaces any existing goals in the phase with this goal
      before: Places this goal before the named goal in the phase's execution list
      after: Places this goal after the named goal in the phase's execution list
    """
    phase = Phase(phase or self.name)
    phase.install(self, first, replace, before, after)
    return phase
Beispiel #5
0
 def configure_profiles(self, scala_compiler_profile):
   checkstyle_enabled = len(Phase.goals_of_type(Checkstyle)) > 0
   self.checkstyle_classpath = (binary_util.profile_classpath('checkstyle') if checkstyle_enabled
                                else [])
   self.scala_compiler_classpath = []
   if self.has_scala:
     self.scala_compiler_classpath.extend(binary_util.profile_classpath(scala_compiler_profile))
Beispiel #6
0
    def _gen_goals_reference(self):
        """Generate the goals reference rst doc."""
        phase_dict = {}
        phase_names = []
        for phase, raw_goals in Phase.all():
            goals = []
            for g in raw_goals:
                # TODO(lahosken) generalize indent_docstring, use here
                doc = (g.task_type.__doc__ or "").replace("\n", " ").strip()
                goals.append(TemplateData(name=g.task_type.__name__, doc=doc))
            phase_dict[phase.name] = TemplateData(phase=phase, goals=goals)
            phase_names.append(phase.name)

        phases = [
            phase_dict[name] for name in sorted(phase_names, key=str.lower)
        ]

        template = resource_string(
            __name__,
            os.path.join(self._templates_dir, 'goals_reference.mustache'))
        filename = os.path.join(self._outdir, 'goals_reference.rst')
        self.context.log.info('Generating %s' % filename)
        with safe_open(filename, 'w') as outfile:
            generator = Generator(template, phases=phases)
            generator.write(outfile)
Beispiel #7
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
    checkstyle_classpath = \
      self._bootstrap_utils.get_jvm_build_tools_classpath(self.checkstyle_bootstrap_key) \
      if checkstyle_enabled else []
    scalac_classpath = \
      self._bootstrap_utils.get_jvm_build_tools_classpath(self.scalac_bootstrap_key) \
      if self.scalac_bootstrap_key else []

    targets, self._project = self.configure_project(
      targets,
      self.checkstyle_suppression_files,
      self.debug_port)

    self._project.set_tool_classpaths(checkstyle_classpath, scalac_classpath)

    self.configure_compile_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 #8
0
 def configure_profiles(self, scala_compiler_profile):
     checkstyle_enabled = len(Phase.goals_of_type(Checkstyle)) > 0
     self.checkstyle_classpath = profile_classpath(
         'checkstyle') if checkstyle_enabled else []
     self.scala_compiler_classpath = []
     if self.has_scala:
         self.scala_compiler_classpath.extend(
             profile_classpath(scala_compiler_profile))
Beispiel #9
0
    def install(self,
                phase=None,
                first=False,
                replace=False,
                before=None,
                after=None):
        """
      Installs this goal in the specified phase (or a new phase with the same name as this Goal).

      The placement of the goal in the execution list of the phase defaults to the end but can be
      influence by specifying exactly one of the following arguments:

      first: Places this goal 1st in the phase's execution list
      replace: Replaces any existing goals in the phase with this goal
      before: Places this goal before the named goal in the phase's execution list
      after: Places this goal after the named goal in the phase's execution list
    """
        phase = Phase(phase or self.name)
        phase.install(self, first, replace, before, after)
        return phase
Beispiel #10
0
 def configure_profiles(self, scala_compiler_profile):
     checkstyle_enabled = len(Phase.goals_of_type(Checkstyle)) > 0
     self.checkstyle_classpath = \
       (binary_util.profile_classpath('checkstyle', workunit_factory=self.workunit_factory)
        if checkstyle_enabled else [])
     self.scala_compiler_classpath = []
     if self.has_scala:
         self.scala_compiler_classpath.extend(
             binary_util.profile_classpath(
                 scala_compiler_profile,
                 workunit_factory=self.workunit_factory))
Beispiel #11
0
    def __init__(self,
                 name,
                 action,
                 group=None,
                 dependencies=None,
                 serialize=True):
        """Parameters:
       name: the name of the goal.
       action: the goal action object to invoke this goal.
       dependencies: the names of other goals which must be achieved
          before invoking this goal.
       serialize: a flag indicating whether or not the action to achieve
          this goal requires the global lock. If true, the action will
          block until it can acquire the lock.
    """
        self.serialize = serialize
        self.name = name
        self.group = group
        self.dependencies = [Phase(d)
                             for d in dependencies] if dependencies else []

        if type(action) == type and issubclass(action, Task):
            self._task = action
        else:
            args, varargs, keywords, defaults = inspect.getargspec(action)
            if varargs or keywords or defaults:
                raise GoalError(
                    'Invalid action supplied, cannot accept varargs, keywords or defaults'
                )
            if len(args) > 2:
                raise GoalError(
                    'Invalid action supplied, must accept 0, 1, or 2 args')

            class FuncTask(Task):
                def __init__(self, context):
                    Task.__init__(self, context)

                    if not args:
                        self.action = lambda targets: action()
                    elif len(args) == 1:
                        self.action = lambda targets: action(self.context)
                    elif len(args) == 2:
                        self.action = lambda targets: action(
                            self.context, targets)
                    else:
                        raise AssertionError('Unexpected fallthrough')

                def execute(self, targets):
                    self.action(targets)

            self._task = FuncTask
    def _gen_goals_reference(self):
        """Generate the goals reference rst doc."""
        phase_dict = {}
        phase_names = []
        for phase, raw_goals in Phase.all():
            goals = []
            for g in raw_goals:
                # TODO(lahosken) generalize indent_docstring, use here
                doc = (g.task_type.__doc__ or "").replace("\n", " ").strip()
                goals.append(TemplateData(name=g.task_type.__name__, doc=doc))
            phase_dict[phase.name] = TemplateData(phase=phase, goals=goals)
            phase_names.append(phase.name)

        phases = [phase_dict[name] for name in sorted(phase_names, key=str.lower)]

        template = resource_string(__name__, os.path.join(self._templates_dir, "goals_reference.mustache"))
        filename = os.path.join(self._outdir, "goals_reference.rst")
        self.context.log.info("Generating %s" % filename)
        with safe_open(filename, "w") as outfile:
            generator = Generator(template, phases=phases)
            generator.write(outfile)
Beispiel #13
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._jvm_tool_bootstrapper.get_jvm_tool_classpath(
          self.checkstyle_bootstrap_key)
    else:
      checkstyle_classpath = []

    if self.scalac_bootstrap_key:
      scalac_classpath = self._jvm_tool_bootstrapper.get_jvm_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 #14
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._jvm_tool_bootstrapper.get_jvm_tool_classpath(
                self.checkstyle_bootstrap_key)
        else:
            checkstyle_classpath = []

        if self.scalac_bootstrap_key:
            scalac_classpath = self._jvm_tool_bootstrapper.get_jvm_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 #15
0
    def __init__(self, name, action, group=None, dependencies=None):
        self.name = name
        self.group = group
        self.dependencies = [Phase(d)
                             for d in dependencies] if dependencies else []

        if type(action) == type and issubclass(action, Task):
            self._task = action
        else:
            args, varargs, keywords, defaults = inspect.getargspec(action)
            if varargs or keywords or defaults:
                raise GoalError(
                    'Invalid action supplied, cannot accept varargs, keywords or defaults'
                )
            if len(args) > 2:
                raise GoalError(
                    'Invalid action supplied, must accept 0, 1, or 2 args')

            class FuncTask(Task):
                def __init__(self, context):
                    Task.__init__(self, context)

                    if not args:
                        self.action = lambda targets: action()
                    elif len(args) == 1:
                        self.action = lambda targets: action(self.context)
                    elif len(args) == 2:
                        self.action = lambda targets: action(
                            self.context, targets)
                    else:
                        raise AssertionError('Unexpected fallthrough')

                def execute(self, targets):
                    self.action(targets)

            self._task = FuncTask