Ejemplo n.º 1
0
    def __init__(self, *args, **kwargs):
        super(Scalastyle, self).__init__(*args, **kwargs)
        self._scalastyle_config = self.context.config.get_required(
            self._CONFIG_SECTION, 'config')
        if not os.path.exists(self._scalastyle_config):
            raise Config.ConfigError(
                'Scalastyle config file does not exist: %s' %
                self._scalastyle_config)

        excludes_file = self.context.config.get(self._CONFIG_SECTION,
                                                'excludes')
        self._excludes = set()
        if excludes_file:
            if not os.path.exists(excludes_file):
                raise Config.ConfigError(
                    'Scalastyle excludes file does not exist: %s' %
                    excludes_file)
            self.context.log.debug('Using scalastyle excludes file %s' %
                                   excludes_file)
            with open(excludes_file) as fh:
                for pattern in fh.readlines():
                    self._excludes.add(re.compile(pattern.strip()))

        self._scalastyle_bootstrap_key = 'scalastyle'
        self.register_jvm_tool(self._scalastyle_bootstrap_key, [':scalastyle'])
Ejemplo n.º 2
0
    def _initialize_config(self):
        scalastyle_config = self.context.config.get(
            self._CONFIG_SECTION, self._CONFIG_SECTION_CONFIG_OPTION)

        # Scalastyle task by default isn't wired up in pants, but if it is installed
        # via plugin, then the config file setting is required.
        if not scalastyle_config:
            raise Config.ConfigError(
                'Scalastyle config is missing from section[{section}] option[{setting}] in '
                'pants.ini.'.format(
                    section=self._CONFIG_SECTION,
                    setting=self._CONFIG_SECTION_CONFIG_OPTION))

        # And the config setting value must be a valid file.
        if not os.path.exists(scalastyle_config):
            raise Config.ConfigError(
                'Scalastyle config file specified in section[{section}] option[{setting}] in pants.ini '
                'does not exist: {file}'.format(
                    section=self._CONFIG_SECTION,
                    setting=self._CONFIG_SECTION_CONFIG_OPTION,
                    file=scalastyle_config))

        excludes_file = self.context.config.get(
            self._CONFIG_SECTION, self._CONFIG_SECTION_EXCLUDES_OPTION)

        scalastyle_excludes = set()
        if excludes_file:
            # excludes setting is optional, but if specified, must be a valid file.
            if not os.path.exists(excludes_file):
                raise Config.ConfigError(
                    'Scalastyle excludes file specified in section[{section}] option[{setting}] in '
                    'pants.ini does not exist: {file}'.format(
                        section=self._CONFIG_SECTION,
                        setting=self._CONFIG_SECTION_EXCLUDES_OPTION,
                        file=excludes_file))
            with open(excludes_file) as fh:
                for pattern in fh.readlines():
                    scalastyle_excludes.add(re.compile(pattern.strip()))
                    self.context.log.debug(
                        'Scalastyle file exclude pattern: {pattern}'.format(
                            pattern=pattern))
        else:
            # excludes setting is optional.
            self.context.log.debug(
                'Unable to get section[{section}] option[{setting}] value in pants.ini. '
                'All scala sources will be checked.'.format(
                    section=self._CONFIG_SECTION,
                    setting=self._CONFIG_SECTION_EXCLUDES_OPTION))

        # Only transfer to local variables to the state at the end to minimize side effects.
        self._scalastyle_config = scalastyle_config or None
        self._scalastyle_excludes = scalastyle_excludes or None