Пример #1
0
class TestManifestoUtils(TestCase):
    def setUp(self):
        self.fs = MockFileUtils()
        self.url = Mock()
        self.manifesto = ManifestoUtils(url_utils=self.url, fs=self.fs)

        self.url.expect_read('https://manifesto.uc-inf.net/api/env/jirastudio-dev', None, None,
                             toReturn='{ "hash": "123456" }')

    def test_resolve_aliases(self):
        h = self.manifesto.determine_hash('dev')
        self.assertEqual(h, '123456')

    def test_get_plugins(self):
        self.url.expect_read('https://manifesto.uc-inf.net/static/12345/psd', None, None,
                             toReturn='{ "plugins": { "jira" : {"myplugin" : { "groupId" : "g", "artifactId" : "a", "version": "v"}}}}')

        plugins = self.manifesto.get_plugins_maven_artifacts('12345')
        self.assertDictEqual({"myplugin": {"groupId": "g", "artifactId": "a", "version": "v"}}, plugins)

    def test_requests_are_cached(self):
        self.url.expect_read('https://manifesto.uc-inf.net/api/env/jirastudio-dev', None, None,
                             toReturn='{ "hash": "123456" }')

        h = self.manifesto.determine_hash('jirastudio-dev')
        self.assertEqual(h, '123456')

        h = self.manifesto.determine_hash('jirastudio-dev')
        self.assertEqual(h, '123456')

        self.assertEqual(1, self.url.callcount_read())
Пример #2
0
    def setUp(self):
        self.fs = MockFileUtils()
        self.url = Mock()
        self.manifesto = ManifestoUtils(url_utils=self.url, fs=self.fs)

        self.url.expect_read(
            'https://manifesto.uc-inf.net/api/env/jirastudio-dev',
            None,
            None,
            toReturn='{ "hash": "123456" }')
Пример #3
0
    def setUp(self):
        self.fs = MockFileUtils()
        self.url = Mock()
        self.manifesto = ManifestoUtils(url_utils=self.url, fs=self.fs)

        self.url.expect_read('https://manifesto.uc-inf.net/api/env/jirastudio-dev', None, None,
                             toReturn='{ "hash": "123456" }')
Пример #4
0
 def __init__(self):
     super().__init__()
     self.description = 'Runs JIRA-only OD instance using your code. This will download a tomcat for you, configure ' \
                        'it and start JIRA and Horde on your local machine. This will also download plugins from ' \
                        'manifesto from given zone/hash (manifesto required you to be in the ofice or connect via ' \
                        'VPN). This will not enable you to hotswap, JRebel or debug your running instance.'
     self.manifesto = ManifestoUtils()
Пример #5
0
class TestManifestoUtils(TestCase):
    def setUp(self):
        self.fs = MockFileUtils()
        self.url = Mock()
        self.manifesto = ManifestoUtils(url_utils=self.url, fs=self.fs)

        self.url.expect_read(
            'https://manifesto.uc-inf.net/api/env/jirastudio-dev',
            None,
            None,
            toReturn='{ "hash": "123456" }')

    def test_resolve_aliases(self):
        h = self.manifesto.determine_hash('dev')
        self.assertEqual(h, '123456')

    def test_get_plugins(self):
        self.url.expect_read(
            'https://manifesto.uc-inf.net/static/12345/psd',
            None,
            None,
            toReturn=
            '{ "plugins": { "jira" : {"myplugin" : { "groupId" : "g", "artifactId" : "a", "version": "v"}}}}'
        )

        plugins = self.manifesto.get_plugins_maven_artifacts('12345')
        self.assertDictEqual(
            {"myplugin": {
                "groupId": "g",
                "artifactId": "a",
                "version": "v"
            }}, plugins)

    def test_requests_are_cached(self):
        self.url.expect_read(
            'https://manifesto.uc-inf.net/api/env/jirastudio-dev',
            None,
            None,
            toReturn='{ "hash": "123456" }')

        h = self.manifesto.determine_hash('jirastudio-dev')
        self.assertEqual(h, '123456')

        h = self.manifesto.determine_hash('jirastudio-dev')
        self.assertEqual(h, '123456')

        self.assertEqual(1, self.url.callcount_read())
Пример #6
0
class OnDemandRun(Run):

    template_file = os.sep.join(['.', 'jmake_src', 'data', 'download_poms_pom_template.xml'])

    def __init__(self):
        super().__init__()
        self.description = 'Runs JIRA-only OD instance using your code. This will download a tomcat for you, configure ' \
                           'it and start JIRA and Horde on your local machine. This will also download plugins from ' \
                           'manifesto from given zone/hash (manifesto required you to be in the ofice or connect via ' \
                           'VPN). This will not enable you to hotswap, JRebel or debug your running instance.'
        self.manifesto = ManifestoUtils()

    def __call__(self, args, executor):
        if args.setup_home:
            executor.append(lambda log: log.warn('Setup home option is not available for ondemand.') or 0)
        if args.bundled_plugins:
            executor.append(lambda log: log.warn('Bundled plugins option is implicitly on with ondemand.') or 0)

        super().__call__(args, executor)

    def define_parser(self, parser):
        super().define_parser(parser)
        parser.add_argument('--manifesto-hash', '-mh', action='store', default='default', dest='manifesto_hash',
                            help='Get plugins using a manifesto hash, zone or alias. Should handle most conventions: '
                                 '"dev", "dog", "prod", "jirastudio-dev", etc., or explicit hash. Case insensitive. '
                                 'Defaults to latest dev.')

        parser.add_argument('--manifesto-jira', action='store_true', dest='manifesto_jira',
                            help='Will not build JIRA but will take it from the given manifesto hash using '
                                 '--manifesto-hash parameter. Too bad JIRA repo must be cloned for this...')

        parser.add_argument('--ignore-manifesto-errors', action='store_true', dest='ignore_manifesto_errors',
                            help='Will not stop the build if manifesto calls are unsuccessful. Will start without'
                                 'manifesto driven PSD instead.')

        self.sample_usage(parser, 'To run an instance that uses your code for JIRA, but uses plugins from manifesto hash 123456abcdef:',
                          ['./jmake ondemand run --manifesto-hash 123456abcdef'])

        self.sample_usage(parser, 'To run an instance that uses JIRA and plugins from current DOG configuration:',
                          ['./jmake ondemand run --manifesto-hash DOG --manifesto-jira'])
        #we should consider using sparse checkouts see
        #http://stackoverflow.com/questions/600079/is-there-any-way-to-clone-a-git-repositorys-sub-directory-only

        parser.autocomplete_contributor = lambda : self.manifesto.generate_all_zones_and_aliases()


    #Override
    def get_tasks_to_build_jira(self, args, workspace_utils=WorkspaceUtils()):

        if not args.manifesto_jira:
            #for workspace build maven must be executed from parent directory
            maven = MavenCallable(args)
            maven.phase('package')

            maven.profile('ondemand').project(OD_WEBAPP_PROJECT_DIR).option('-am')
            maven.property('jira.home', args.layout.jira_home())

            maven.projects.extend(workspace_utils.get_workspace_projects_without_jira(args))
            self.add_devmode_plugins(args, maven)

            if not args.attach_sources:
                maven.property('skipSources')
            maven.skip_tests()
            if args.third_party_licensing:
                maven.profiles.extend(['third-party-licensing'])

            # return builder and manifesto plugins job:
            return [maven]
        else:

            mavenClean = MavenCallable(args, path=OD_WEBAPP_PROJECT_DIR)
            mavenClean.phase('clean')

            return [mavenClean,
                    self.manifesto_jira(args, manifesto=self.manifesto),
                    self.__create_target_dir_for_exploded_webapp(),
                    SystemCallable(args, command='unzip *.war -d war/exploded', cwd=os.sep.join([OD_WEBAPP_PROJECT_DIR, 'target']))]

    #Override
    def get_tasks_before_build_jira(self, args, executor):
        if args.with_workspace:
            #TODO: untested.
            executor.append(WorkspaceValidator())

        self.check_ports(args, executor)

        executor.append(LegacyOdSvnSetup(args))
        executor.append(HordeRunner(args))

    #Override
    def get_tasks_post_build_jira(self, args, executor):
        executor.append(self.manifesto_plugins(args, manifesto=self.manifesto))
        executor.append(HordeStatusEnforcer(args))

    #Override
    def build_layouts(self, args):
        """ This is called by superclass to build the directory layouts for the needed webapps. """
        args.layout = WorkspaceBuilder.buildLayout(args.tomcat_dir, args.tomcat_version, args.jira_home,
                                                   args.instance_name, True)
        args.horde_layout = HordeLayout(args.layout.jira_home())

    def handle_manifesto_exception(self, args, message, e, logger):
        logger.error(message)
        if args.ignore_manifesto_errors:
            args.manifesto_psd = None
            logger.debug(str(e))
            return Callable.success
        else:
            logger.error(str(e))
            return Callable.failure

    def manifesto_jira(self, args, manifesto: ManifestoUtils=ManifestoUtils(), fs: FileUtils=FileUtils()):

        def manifesto_jira_closure(logger):

            webapp_target_dir = fs.existing_dir(os.sep.join([OD_WEBAPP_PROJECT_DIR, 'target']))

            logger.info('Determining the manifesto hash...')
            try:
                manifesto_hash = manifesto.determine_hash(args.manifesto_hash)
            except Exception as e:
                return self.handle_manifesto_exception('Unable to resolve zone to hash.', args, e, logger)
            logger.info('Will setup the OD instance with the following hash: ' + manifesto_hash)

            logger.info('Determining manifest JIRA version...')
            try:
                manifesto_jira = manifesto.get_od_jira(manifesto_hash)
            except Exception as e:
                return self.handle_manifesto_exception('Unable to determine jira version from manifesto.', args, e,
                                                       logger)
            logger.info('Will use JIRA webapp version: %s.' % manifesto_jira['version'])

            logger.info('Downloading JIRA...')
            try:
                fs.filter_file(OnDemandRun.template_file,
                               os.sep.join([webapp_target_dir, 'pom.xml']),
                               {'${ARTIFACT_ITEMS}': self.__artifact_description_for_pom_template(manifesto_jira)})

                rc = MavenCallable(path=webapp_target_dir).phase('verify').option('-B')(logger)
            except Exception as e:
                return self.handle_manifesto_exception('Unable to download required plugins.', args, e, logger)
            return rc

        return manifesto_jira_closure

    def manifesto_plugins(self, args, manifesto: ManifestoUtils=ManifestoUtils(), fs: FileUtils=FileUtils()):

        def download_pom_location(manifesto_hash):
            return fs.abs_path(os.sep.join(['.', 'target', 'manifesto', 'psd-' + manifesto_hash]))

        def manifesto_plugins_closure(logger):
            logger.info('Determining the manifesto hash...')
            try:
                manifesto_hash = manifesto.determine_hash(args.manifesto_hash)
            except Exception as e:
                return self.handle_manifesto_exception('Unable to resolve zone to hash.', args, e, logger)
            logger.info('Will setup the OD instance with the following hash: ' + manifesto_hash)

            logger.info('Determining plugin list...')
            try:
                manifesto_plugins = manifesto.get_plugins_maven_artifacts(manifesto_hash)
            except Exception as e:
                return self.handle_manifesto_exception('Unable to determine required plugins from manifesto.', args, e,
                                                       logger)
            logger.info('Found %d plugins to install.' % len(manifesto_plugins))

            logger.info('Downloading plugins...')
            try:
                fs.filter_file(OnDemandRun.template_file,
                               os.sep.join([fs.existing_dir(download_pom_location(manifesto_hash)), 'pom.xml']),
                               {'${ARTIFACT_ITEMS}': ''.join(
                                   self.__artifact_description_for_pom_template(v) for k, v in manifesto_plugins.items())})

                rc = MavenCallable(path=download_pom_location(manifesto_hash)).phase('verify').option('-B')(logger)
            except Exception as e:
                return self.handle_manifesto_exception('Unable to download required plugins.', args, e, logger)
            args.manifesto_psd = download_pom_location(os.sep.join([manifesto_hash, 'target']))

            return rc

        return manifesto_plugins_closure

    def __create_target_dir_for_exploded_webapp(self, fs: FileUtils=FileUtils()):
        def create_target_dir_for_exploded_webapp_closure(_):
            fs.existing_dir(os.sep.join([OD_WEBAPP_PROJECT_DIR, 'target', 'war', 'exploded']))
            return 0
        return create_target_dir_for_exploded_webapp_closure

    def __artifact_description_for_pom_template(self, artifact):

        def in_tag(tagname, text):
            return '<{0}>{1}</{0}>'.format(tagname, text)

        return in_tag('artifactItem', ''.join([
            in_tag('groupId', artifact['groupId']),
            in_tag('artifactId', artifact['artifactId']),
            in_tag('version', artifact['version']),
            in_tag('outputDirectory', './target'),
            in_tag('type', artifact['packaging'])
        ]))