Beispiel #1
0
def process_target_exclusions(args, xml=XmlUtils()):
    def process_exclusions_closure(logger):
        project_file = 'jira-project.iml'
        paths_to_exclude = get_targets_for(
            ['jira-ondemand-project', 'jira-distribution'])
        paths_to_exclude += [
            'jirahome', 'jirahome-od', 'svn', 'jirahome-shared',
            'jirahome-clustered'
        ]

        try:
            tree = xml.parse(project_file)
        except IOError:
            logger.error('Could not open ' + project_file)
            return Callable.success - 1

        content_nodes = tree.getroot().findall('./component/content')
        save_needed = False
        for content in content_nodes:
            for file in paths_to_exclude:
                save_needed |= add_single_exclusion(content, file)

        if save_needed:
            logger.debug('Added new exclusions to %s.' % project_file)
            pretty_xml = minidom.parseString(xml.tostring(
                tree.getroot())).toprettyxml()
            file = open(project_file, 'wt', encoding='utf-8')
            file.write(pretty_xml)
            file.close()

        return Callable.success

    return process_exclusions_closure
Beispiel #2
0
 def __init__(self, fs: FileUtils = FileUtils(),
              xml: XmlUtils = XmlUtils()):
     super().__init__()
     self.roots = []
     self.fs = fs
     self.xml = xml
     self.report_header_logged = False
Beispiel #3
0
 def __init__(self, pom_path, xml=XmlUtils()):
     path_abspath = os.path.abspath(pom_path)
     if not os.path.lexists(pom_path):
         raise IOError('Pom file not found %s' % path_abspath)
     try:
         self.pom_xml = xml.parse(path_abspath)
     except ParseError as e:
         raise ParseError('Error parsing %s: %s' % (path_abspath, e.msg))
     self.root_element = self.pom_xml.getroot()
Beispiel #4
0
def process_run_configs(args, xml=XmlUtils()):
    def run_configs_closure(logger):
        logger.info('Checking for run configurations in workspace...')
        workspace_file = '.idea%sworkspace.xml' % os.sep
        idea_runners_file = os.sep.join([
            'jira-ide-support', 'src', 'main', 'resources', 'ideaTemplates',
            'runConfigurations.xml'
        ])

        try:
            workspace_tree = xml.parse(workspace_file)
        except IOError:
            logger.error('Could not open ' + workspace_file)
            return Callable.success - 1

        try:
            run_config_tree = xml.parse(idea_runners_file)
        except IOError:
            logger.error('Could not open ' + idea_runners_file)
            return Callable.success - 1

        component_element = run_config_tree.getroot()[0]
        workspace_component = xml.produce(
            workspace_tree.getroot(),
            (component_element.tag, component_element.attrib))

        num_configurations_written = 0

        for run_config_element in component_element:
            workspace_config = workspace_component.find(
                './%s[@name="%s"]' %
                (run_config_element.tag, run_config_element.attrib['name']))
            if workspace_config is None:
                logger.debug('copying run configuration ' +
                             run_config_element.attrib['name'])
                xml.copy_tree(workspace_component, run_config_element)
                num_configurations_written += 1
            elif args.force:
                workspace_component.remove(workspace_config)
                logger.debug('overwriting run configuration ' +
                             run_config_element.attrib['name'])
                xml.copy_tree(workspace_component, run_config_element)
                num_configurations_written += 1

        if num_configurations_written > 0:
            try:
                #os.rename(workspace_file, workspace_file + '.jmake_backup')
                workspace_tree.write(workspace_file)
                logger.info('Added %d new run configurations.' %
                            num_configurations_written)
            except IOError:
                logger.error('Could not save ' + workspace_file)
                return Callable.success - 2

        return Callable.success

    return run_configs_closure
Beispiel #5
0
 def __init__(self,
              logger: Logger,
              build_name: str,
              build_number: str,
              urlutils=UrlUtils(),
              xml=XmlUtils(),
              auth=None):
     self.buildname = build_name
     self.buildnumber = build_number
     self.auth = auth
     self.logger = logger
     self.urlutils = urlutils
     self.xml = xml
Beispiel #6
0
def process_compiler_settings(args, xml=XmlUtils()):
    def process_compiler_settings_closure(logger):
        logger.info('Checking for compiler configuration...')
        compiler_file = '.idea%scompiler.xml' % os.sep
        try:
            tree = xml.parse(compiler_file)
        except IOError:
            logger.error('Could not open ' + compiler_file)
            return Callable.success - 1

        javac_element = xml.produce(tree.getroot(), ('component', {
            'name': 'JavacSettings'
        }), ('option', {
            'name': 'MAXIMUM_HEAP_SIZE'
        }))

        needs_save = False

        if int(javac_element.get('value', '-1')) < 512 or args.force:
            javac_element.set('value', '512')
            needs_save = True
            logger.debug('Updated javac memory to 512M')

        resource_list = xml.produce(tree.getroot(),
                                    ('component', {
                                        'name': 'CompilerConfiguration'
                                    }), ('wildcardResourcePatterns', {}))

        resources_to_add = ['vm', 'soy']

        for resource in resources_to_add:
            name = 'entry'
            attr = {'name': ('?*.' + resource)}
            if not xml.child_exists(resource_list, name, attr):
                logger.debug(
                    'Added "%s" files as resources in compiler settings.' %
                    resource)
                xml.produce(resource_list, (name, attr))
                needs_save = True

        if needs_save:
            try:
                tree.write(compiler_file)
            except IOError:
                logger.error('Could not save ' + compiler_file)
                return Callable.success - 2

        return Callable.success

    return process_compiler_settings_closure
Beispiel #7
0
 def __init__(self,
              urlutils=UrlUtils(),
              xml=XmlUtils(),
              fileutils=FileUtils()):
     JmakeModule.__init__(self)
     self.command = 'investigate'
     self.description = 'Investigates JBAC failures and prepares to reproduce them locally. This command will ' \
                        'produce a file, that will contain information what tests failed and what should be done ' \
                        'to replay what happened locally. By default, the failed tests will be accompanied with ' \
                        '5 tests that preceded it on the particular run in an attempt to repliacate the way the ' \
                        'instance might have been corrupted by previous tests (which is random on regular rerun ' \
                        'due to how hallelujah works).'
     self.urlutils = urlutils
     self.xml = xml
     self.fileutils = fileutils
     self.replays_dir = self.fileutils.existing_dir(
         os.sep.join(['target', 'replays']))
Beispiel #8
0
def process_jmake_module(args, fileutils=FileUtils(), xml=XmlUtils()):
    def process_jmake_module_closure(logger):
        logger.info('Installing jmake dev module...')
        jmake_module_file = os.sep.join(['.', 'jmake_src', 'jmake_src.iml'])
        if not fileutils.file_exists(jmake_module_file) or args.force:
            # module file does not exist: create it and add it to the module list.
            jmake_module_template = os.sep.join([
                'jira-ide-support', 'src', 'main', 'resources',
                'ideaTemplates', 'jmake', 'jmake_src.iml.template'
            ])
            logger.debug('Copying %s to %s' %
                         (jmake_module_template, jmake_module_file))
            fileutils.copy_file(jmake_module_template, jmake_module_file)

            workspace_modules_file = os.sep.join(['.', '.idea', 'modules.xml'])

            try:
                workspace_tree = xml.parse(workspace_modules_file)
            except IOError:
                logger.error('Could not open ' + workspace_modules_file)
                return Callable.success - 1

            module = xml.produce(
                workspace_tree.getroot(), ('component', {}), ('modules', {}),
                ('module', {
                    'filepath':
                    os.sep.join(
                        ['$PROJECT_DIR$', 'jmake_src', 'jmake_src.iml'])
                }))

            if not 'fileurl' in module.attrib:
                logger.debug('Adding module entry to %s' %
                             workspace_modules_file)
                module.attrib[
                    'fileurl'] = 'file://$PROJECT_DIR$/jmake_src/jmake_src.iml'
                try:
                    #os.rename(workspace_file, workspace_file + '.jmake_backup')
                    workspace_tree.write(workspace_modules_file)
                    logger.debug('Saved successfully.')
                except IOError:
                    logger.error('Could not save ' + workspace_modules_file)
                    return Callable.success - 2

        return Callable.success

    return process_jmake_module_closure
Beispiel #9
0
def process_dev_profiles(xml=XmlUtils()):
    def process_dev_profiles_closure(logger):
        logger.info('Enabling dev profiles...')

        workspace_file = os.sep.join(['.', '.idea', 'workspace.xml'])
        try:
            workspace_tree = xml.parse(workspace_file)
        except IOError:
            logger.error('Could not open ' + workspace_file)
            return Callable.success - 1

        profiles = ['func-mode-plugins', 'pseudo-loc', 'dev-mode-plugins']

        profile_list = xml.produce(workspace_tree.getroot(),
                                   ('component', {
                                       'name': 'MavenImportPreferences'
                                   }), ('option', {
                                       'name': 'enabledProfiles'
                                   }), ('list', {}))

        existing_profiles = [child.attrib['value'] for child in profile_list]
        item_added = False

        for profile in (e for e in profiles if e not in existing_profiles):
            logger.debug('Adding profile: ' + profile)
            item_added = True
            xml.produce(profile_list, ('option', {'value': profile}))

        if item_added:
            try:
                #os.rename(workspace_file, workspace_file + '.jmake_backup')
                workspace_tree.write(workspace_file)
                logger.debug('Saved successfully.')
            except IOError:
                logger.error('Could not save ' + workspace_file)
                return Callable.success - 2
        return Callable.success

    return process_dev_profiles_closure
Beispiel #10
0
    def get_build_name(self,
                       logger,
                       args,
                       branchDiscovery,
                       urlutils=UrlUtils(),
                       xml=XmlUtils()):
        if branchDiscovery.branch == 'master':
            return self.__fulljobname(args.type)
        else:
            # translate the branch into bamboo branch name:
            bamboo_branch_name = branchDiscovery.branch.replace('/', '-')
            logger.info('Trying to find bamboo branch "%s"...' %
                        bamboo_branch_name)

            auth = JbacAuthentication.get()
            url = '%s/rest/api/latest/plan/%s?expand=branches&max-results=10000' % (
                Jbac.url, CIInvestigate.planname[args.type])
            logger.info('Querying JBAC: ' + url)
            text = self.urlutils.read(url, auth.login, auth.password)

            try:
                root = self.xml.parse_string(text)
                for branchElement in root.findall('.//branches/branch'):
                    branch_key = branchElement.attrib['key']
                    branch_name = branchElement.attrib['shortName']
                    if branch_name == bamboo_branch_name:
                        logger.debug('Bamboo branch plan key is: "%s".' %
                                     branch_key)
                        return '-'.join(
                            [branch_key, CIInvestigate.jobname[args.type]])
            except ParseError:
                logger.debug('\n' + text)
                logger.error('Could not parse JBAC reply.')

            logger.warn(
                'Could not find the Bamboo branch for branch: "%s". Will inspect master instead.'
                % bamboo_branch_name)
            return self.__fulljobname(args.type)
Beispiel #11
0
def process_project_local_settings(args, fileutils=FileUtils(),
                                   xml=XmlUtils()):
    def process_project_local_settings_closure(logger):
        code_style_name = 'codeStyleSettings.xml'
        code_style_src = os.sep.join([
            'jira-ide-support', 'src', 'main', 'resources', 'ideaTemplates',
            code_style_name
        ])
        code_style_dst = os.sep.join(['.idea', code_style_name])

        uses_per_project_settings = False

        try:
            tree = xml.parse(code_style_dst)

            element = xml.produce(tree.getroot(), ('component', {}),
                                  ('option', {
                                      'name': 'USE_PER_PROJECT_SETTINGS'
                                  }))

            uses_per_project_settings = element.attrib[
                'value'] == 'true' if 'value' in element.attrib else False
        except IOError:
            pass

        if args.force or not uses_per_project_settings:
            logger.info('Installing project code style...')
            fileutils.copy_file(code_style_src, code_style_dst)
            #make sure to wake up idea:
            fileutils.touch(os.sep.join(['.idea', 'workspace.xml']))
        elif uses_per_project_settings:
            logger.debug(
                'Not installing project code style, because already set to per-project configuration. Use --force to override.'
            )

        return Callable.success

    return process_project_local_settings_closure
Beispiel #12
0
def ensure_reloadable_resources(logger, xml=XmlUtils()):
    artifact_file = os.sep.join(
        ['.idea', 'artifacts', 'atlassian_jira_webapp_war_exploded.xml'])
    try:
        tree = xml.parse(artifact_file)
    except IOError:
        return Callable.success

    webinf_element = xml.produce(tree.getroot(), ('artifact', {}),
                                 ('root', {}), ('element', {
                                     'id': 'directory',
                                     'name': 'WEB-INF'
                                 }), ('element', {
                                     'id': 'directory',
                                     'name': 'classes'
                                 }))

    modules = ['jira-api', 'jira-core']
    needs_save = False

    for module in modules:
        if not xml.child_exists(webinf_element, 'element', {'name': module}):
            xml.produce(webinf_element, ('element', {
                'id': 'module-output',
                'name': module
            }))
            needs_save = True

    if needs_save:
        logger.debug('Updating JIRA artifact to enable resources reload...')
        try:
            tree.write(artifact_file)
        except IOError:
            logger.error('Could not save ' + artifact_file)
            return Callable.success - 2

    return Callable.success
Beispiel #13
0
class XmlUtilsTest(TestCase):
    def setUp(self):
        self.xml = XmlUtils()

    def test_produce_method(self):
        parent = XML.Element('parent', {'id': '1'})

        child1 = self.xml.produce(parent, ('child', {'id': '2'}))

        self.assertEqual(len(parent), 1)
        self.assertDictEqual(child1.attrib, {'id': '2'})
        self.assertIn(child1, parent)
        child1.attrib['name'] = 'child1'

        self.xml.produce(parent, ('child', {'name': 'child1'}))
        self.assertEqual(len(parent), 1)

        child2 = self.xml.produce(parent, ('child', {'name': 'child2'}))
        self.assertEqual(len(parent), 2)

        self.xml.produce(child2, ('sub', {'id': '3'}))
        self.assertEqual(len(child2), 1)
Beispiel #14
0
class XmlUtilsTest(TestCase):

    def setUp(self):
        self.xml = XmlUtils()

    def test_produce_method(self):
        parent = XML.Element('parent', {'id': '1'})

        child1 = self.xml.produce(parent, ('child', {'id': '2'}))

        self.assertEqual(len(parent), 1)
        self.assertDictEqual(child1.attrib, {'id': '2'})
        self.assertIn(child1, parent)
        child1.attrib['name'] = 'child1'

        self.xml.produce(parent, ('child', {'name': 'child1'}))
        self.assertEqual(len(parent), 1)

        child2 = self.xml.produce(parent, ('child', {'name': 'child2'}))
        self.assertEqual(len(parent), 2)

        self.xml.produce(child2, ('sub', {'id': '3'}))
        self.assertEqual(len(child2), 1)
Beispiel #15
0
 def setUp(self):
     self.xml = XmlUtils()
Beispiel #16
0
 def setUp(self):
     self.xml = XmlUtils()
Beispiel #17
0
def add_single_exclusion(content, file, xml=XmlUtils()):
    file_uri = 'file://$MODULE_DIR$/%s' % file
    if len(content.findall('./excludeFolder[@url="%s"]' % file_uri)) == 0:
        xml.produce(content, ('excludeFolder', {'url': file_uri}))
        return True
    return False