Exemplo n.º 1
0
    def _setup(self):
        '''
            Setup all the attributes of the class
        '''

        self._m2_home = self.build_cfg.tools()['maven'][self._maven_version]
        self._maven_cmd = self._find_maven_executable()
        self._user_home_dir = join(self.build_cfg.temp_dir(), 'user.home')
        self._dotm2_dir = join(self._user_home_dir, '.m2')
        self._maven_settings_xml_file = join(self._dotm2_dir, 'settings.xml')
        self._maven_jvm_options = ['-Djavax.net.ssl.trustStore='+join(inst.get_installation_dir(), 'xmake', 'template', 'maven', 'keystore'),
                                   '-Dmaven.wagon.http.ssl.insecure=true',  # Use keystore because these two VM options have no effect on maven...
                                   '-Dmaven.wagon.http.ssl.allowall=true']  # Also tried to use maven_jvm_opS but no effect as well
        self._maven_build_dependencies_file = join(self.build_cfg.temp_dir(), 'dependencies')
        self._maven_repository_dir = join(self.build_cfg.temp_dir(), 'repository')
        self._setup_settings_xml()
        self.java_exec_env.env['VERSION'] = self.build_cfg.base_version()
        self.java_exec_env.env['REPOSITORY'] = self._maven_repository_dir
        self.java_exec_env.env['MAVEN_OPTS'] = (self.java_exec_env.env['MAVEN_OPTS']+' ' if 'MAVEN_OPTS' in self.java_exec_env.env else '')+'-Duser.home='+self._user_home_dir+' -Dmaven.repo.local='+self._maven_repository_dir
        self.java_exec_env.env['HOME'] = self._user_home_dir

        if self._m2_home:
            self.java_exec_env.env['M2_HOME'] = self._m2_home

            m2_bin = os.path.join(self._m2_home, 'bin')
            path = self.java_exec_env.env['PATH']
            if path is None:
                self.java_exec_env.env['PATH'] = m2_bin
            elif path.find(m2_bin) < 0:
                self.java_exec_env.env['PATH'] = os.pathsep.join([m2_bin, path])
Exemplo n.º 2
0
    def _generate_ads_file(self):
        '''
            Create the artifact deployer script file
        '''

        # Retrieve artifacts from local deployment repo
        artifacts = Artifact.gather_artifacts(self._localDeploymentPath)

        group_section_list = []
        for key in artifacts:
            values = artifacts[key]
            gav = key.split(':')
            group = gav[0]
            aid = gav[1]
            version = gav[2]
            strippedVersion = version
            strippedVersion = re.sub(r'\-(?i)(SNAPSHOT|RELEASE|MILESTONE)$', '', version)
            # Rollback this change as it causes a regression concatenating version twice 1.42.2-1.42.2
            # project_version = self.build_cfg.version()
            # if project_version is not None:
            #     strippedVersion = strippedVersion + '-' + project_version
            group_section_list.append('artifact "%s", group:"%s", version:"%s" , { ' % (aid, group, strippedVersion))
            for artifactObj in values:
                log.info('artifact to deploy ' + artifactObj.path)
                fileLine = '\t\t file "%s"' % artifactObj.path.replace('\\', '/')
                if not artifactObj.classifier == '':
                    fileLine = fileLine + ', classifier:"%s"' % (artifactObj.classifier)
                if not artifactObj.extension == '':
                    fileLine = fileLine + ', extension:"%s"' % (artifactObj.extension)
                group_section_list.append(fileLine)

                # Removed this restriction according to the new wanted behaviour see BESTL-8564
                # # Check that all submodules POMs have the same version as the main (Reactor) POM
                # project_version = self.build_cfg.version()
                # strippedVersion = re.sub(r'\-(?i)(SNAPSHOT|RELEASE|MILESTONE)$', '', artifactObj.version)
                # if strippedVersion != project_version:
                #     errorMessage = 'the following sub module POM %s:%s:%s has different version from the main POM  %s' % (artifactObj.gid, artifactObj.aid,artifactObj.version,project_version)
                #     errorMessage= errorMessage + ' All sub modules POM must have the same version as the main POM '
                #     raise XmakeException( errorMessage)

            group_section_list.append('\n\t}')

        export_ads_template_file = join(inst.get_installation_dir(), 'xmake', 'template', 'maven', 'export.ads')
        with open(export_ads_template_file, 'r') as f:
            export_ads = f.read()
        export_ads = Template(export_ads).substitute(groupList='\n\t'.join(group_section_list))

        with open(self._ads, 'w') as f:
            f.write(export_ads)
Exemplo n.º 3
0
def execute(build_cfg, module, args):
    l = inst.get_installation_dir()
    gen = os.path.join(build_cfg.module_genroot_dir(), module)
    cwd = os.path.join(build_cfg.src_dir(), module)

    cmd = [sys.executable, os.path.join(l, 'xmake', 'xmake.py'), '--gendir', gen, '-r', cwd, '--base-version', build_cfg.base_version()]
    log.info('------------------------------------------------------')
    log.info('- building module '+module+'...')
    log.info('------------------------------------------------------')

    cmd.extend(args)
    log.info('cmd is '+str(cmd))
    rc = log.log_execute(cmd, cwd=cwd)
    if rc != 0:
        raise XmakeException('module build failed for '+module+': RC='+str(rc))
Exemplo n.º 4
0
def bootstrap(argv=sys.argv):
    prepare_bootstrap()
    xmake_inst_dir = inst.get_installation_dir()
    v=inst.get_logical_xmake_version()
    if v != None:
        log.info( 'logical version is '+str(v))
    v=inst.get_technical_xmake_version()
    if v != None:
        log.info( 'technical version is '+v)
    log.info( 'python version is '+str(sys.version_info[0])+"."+str(sys.version_info[1])+"."+str(sys.version_info[2]))
    if not (sys.version_info[0]==2 and sys.version_info[1]>=7):
        log.error( "python version 2.7+ required to run xmake")
        sys.exit(2)
    handle_bootstrapper(xmake_inst_dir,argv)
    bootstrap2(argv)
Exemplo n.º 5
0
 def _writeConfig(self):
     if 'flavor' in self._options['parameters']:
         for flavor in [
                 f.strip()
                 for f in self._options['parameters']['flavor'].split(',')
         ]:
             templateFile = os.path.join(inst.get_installation_dir(),
                                         'xmake', 'template',
                                         '%s.cfg' % flavor)
             configFile = os.path.join(self.build_cfg.cfg_dir(),
                                       '%s.cfg' % flavor)
             if not os.path.isfile(configFile) and os.path.isfile(
                     templateFile):
                 shutil.copy(templateFile, configFile)
             if os.path.isfile(configFile):
                 self._options['configs'][flavor] = configFile
     elif 'config' in self._options['parameters']:
         self._options['configs']['user'] = self._expandVariables(
             self._options['parameters']['config'])
     else:
         for f in os.listdir(self.build_cfg.cfg_dir()):
             if f.endswith('.cfg'):
                 self._options['configs'][f[:-4]] = os.path.join(
                     self.build_cfg.cfg_dir(), f)
         if 'du' not in self._options['configs'] and os.path.isfile(
                 os.path.join(self.build_cfg.src_dir(), 'du.xs')):
             shutil.copy(
                 os.path.join(inst.get_installation_dir(), 'xmake',
                              'template', 'du.cfg'),
                 os.path.join(self.build_cfg.cfg_dir(), 'du.cfg'))
             self._options['configs']['du'] = os.path.join(
                 self.build_cfg.cfg_dir(), 'du.cfg')
     if not self._options['configs']:
         raise xmake_exceptions.XmakeException(
             'No flavor defined and no config file found. Add argument -- flavor=<your_flavor> where <your_flavor> has one of these values "node", "ant", "cmake", "du"'
         )
Exemplo n.º 6
0
def _setup_global_settings_xml(build_cfg):
    '''
        Build a custom settings.xml file from a template located in [install_dir]/xmake/template/maven/global_settings.xml
        Override the the default mirroring for global maven settings (use case: run maven outside xmake )
        This new file is saved into M2_HOME/conf/settings.xml
    '''

    # Add xml namespaces
    ET.register_namespace('', 'http://maven.apache.org/SETTINGS/1.0.0')
    ET.register_namespace('xsi', "http://www.w3.org/2001/XMLSchema-instance")
    ET.register_namespace(
        'xsi:schemaLocation',
        'http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd'
    )

    # Parse template/settings.xml
    templateSettingsXmlFile = join(inst.get_installation_dir(), 'xmake',
                                   'template', 'maven', 'global_settings.xml')
    xmlSettingsContent = ''
    with open(templateSettingsXmlFile, 'r') as f:
        xmlSettingsContent = f.read()

    tree = ET.fromstring(xmlSettingsContent)
    if tree is None:
        raise XmakeException('cannot generate specific settings.xml for maven')

    #Search fileds to update
    namespace = "{http://maven.apache.org/SETTINGS/1.0.0}"
    mirrorsUrl = tree.find('./{0}mirrors'.format(namespace))
    repos = tree.find(
        './{0}profiles/{0}profile[{0}id="customized.repo"]/{0}repositories'.
        format(namespace))
    pluginrepositoryListUrl = tree.find(
        './{0}profiles/{0}profile[{0}id="customized.repo"]/{0}pluginRepositories'
        .format(namespace))

    if mirrorsUrl is None or repos is None or pluginrepositoryListUrl is None:
        raise XmakeException('cannot generate specific settings.xml for maven')

    # Add specific fields
    if build_cfg.is_release() is None:
        i = 1
        for repo in build_cfg.import_repos():
            pluginrepository = ET.SubElement(pluginrepositoryListUrl,
                                             'pluginRepository')
            ET.SubElement(pluginrepository, 'id').text = 'repo%d' % i \
                if i < len(build_cfg.import_repos()) else "central"
            ET.SubElement(pluginrepository, 'url').text = repo
            snapshots = ET.SubElement(pluginrepository, 'snapshots')
            ET.SubElement(snapshots, 'enabled').text = 'true'
            i += 1

    i = 1
    for import_repo in build_cfg.import_repos():
        additional_mirror = ET.SubElement(mirrorsUrl, 'mirror')
        ET.SubElement(additional_mirror, 'id').text = 'mirror%d' % i
        ET.SubElement(additional_mirror, 'url').text = import_repo
        ET.SubElement(additional_mirror, 'mirrorOf').text = 'repo%d' % i \
            if i < len(build_cfg.import_repos()) else "central"
        i += 1

    i = 1
    for repo in build_cfg.import_repos():
        additional_repo = ET.SubElement(repos, 'repository')
        ET.SubElement(additional_repo, 'id').text = 'repo%d' % i \
            if i < len(build_cfg.import_repos()) else "central"
        ET.SubElement(additional_repo, 'url').text = repo
        i += 1

    for tid in build_cfg.tools_to_be_installed():
        for gav_str in build_cfg.tools_to_be_installed()[tid]:
            gav = build_cfg.tools().mapToolGAVStr(gav_str)
            if 'org.apache.maven' == gav[0] and 'apache-maven' == gav[
                    1] and build_cfg.tools()[tid] and build_cfg.tools()[tid][
                        gav[-1]]:
                _maven_global_settings_xml_file = join(
                    build_cfg.tools()[tid][gav[-1]], 'conf', 'settings.xml')
                log.info(
                    'write maven global settings in {} for "{}" {}'.format(
                        _maven_global_settings_xml_file, tid, gav_str))
                with open(_maven_global_settings_xml_file, 'w') as f:
                    f.write(ET.tostring(tree))
Exemplo n.º 7
0
    def _setup_settings_xml(self):
        '''
            Build a custom settings.xml file from a template located in [install_dir]/xmake/template/maven/settings.xml
            Mainly two fields are customized:
             - localRepository
             - mirrors: adding <mirror> one per import repository
            This new file is saved into [component_dir]/gen/tmp/settings.xml
        '''

        # Add xml namespaces
        ET.register_namespace('', 'http://maven.apache.org/SETTINGS/1.0.0')
        ET.register_namespace('xsi', 'http://www.w3.org/2001/XMLSchema-instance')
        ET.register_namespace('xsi:schemaLocation', 'http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd')

        # Parse template/settings.xml
        templateSettingsXmlFile = join(inst.get_installation_dir(), 'xmake', 'template', 'maven', 'settings.xml')
        xmlSettingsContent = ''
        with open(templateSettingsXmlFile, 'r') as f:
            xmlSettingsContent = f.read()

        xmlSettingsContent = Template(xmlSettingsContent).substitute(
            proxyactivated='false' if self._maven_settings_noproxy else 'true', 
            mavensettingsxml=self._maven_settings_xml_file)

        tree = ET.fromstring(xmlSettingsContent)
        if tree is None:
            raise XmakeException('cannot generate specific settings.xml for maven')

        # Search fileds to update
        namespace = '{http://maven.apache.org/SETTINGS/1.0.0}'
        localRepository = tree.find('./{}localRepository'.format(namespace))
        mirrorsUrl = tree.find('./{0}mirrors'.format(namespace))
        sonarproperties = tree.find('./{0}profiles/{0}profile[{0}id="sonar"]/{0}properties'.format(namespace))
        sonarjdbcurl = sonarproperties.find('{0}sonar.jdbc.url'.format(namespace))
        sonarjdbcdriver = sonarproperties.find('{0}sonar.jdbc.driver'.format(namespace))
        sonarjdbcusername = sonarproperties.find('{0}sonar.jdbc.username'.format(namespace))
        sonarjdbcpassword = sonarproperties.find('{0}sonar.jdbc.password'.format(namespace))
        sonarhosturl = sonarproperties.find('{0}sonar.host.url'.format(namespace))
        repos = tree.find('./{0}profiles/{0}profile[{0}id="customized.repo"]/{0}repositories'.format(namespace))
        pluginrepositoryListUrl = tree.find('./{0}profiles/{0}profile[{0}id="customized.repo"]/{0}pluginRepositories'.format(namespace))

        if localRepository is None and mirrorsUrl is None:
            raise XmakeException('cannot generate specific settings.xml for maven')

        # Add specific fields
        localRepository.text = self._maven_repository_dir

        if self.build_cfg.is_release() is None:
            i = 1
            for repo in self.build_cfg.import_repos():
                pluginrepository = ET.SubElement(pluginrepositoryListUrl, 'pluginRepository')
                ET.SubElement(pluginrepository, 'id').text = 'repo%d' % i \
                    if i < len(self.build_cfg.import_repos()) else "central"
                ET.SubElement(pluginrepository, 'url').text = repo
                snapshots = ET.SubElement(pluginrepository, 'snapshots')
                ET.SubElement(snapshots, 'enabled').text = 'true'
                i += 1

        i = 1
        for import_repo in self.build_cfg.import_repos():
            additional_mirror = ET.SubElement(mirrorsUrl, 'mirror')
            ET.SubElement(additional_mirror, 'id').text = 'mirror%d' % i
            ET.SubElement(additional_mirror, 'url').text = import_repo
            ET.SubElement(additional_mirror, 'mirrorOf').text = 'repo%d' % i \
                if i < len(self.build_cfg.import_repos()) else "central"
            i += 1

        i = 1
        for repo in self.build_cfg.import_repos():
            additional_repo = ET.SubElement(repos, 'repository')
            ET.SubElement(additional_repo, 'id').text = 'repo%d' % i \
                if i < len(self.build_cfg.import_repos()) else "central"
            ET.SubElement(additional_repo, 'url').text = repo
            i += 1

        # sonar properties
        jdbcurl = os.getenv('SONAR_JDBC_URL')  # jdbc:mysql://ldisonarci.wdf.sap.corp:3306/sonar?useUnicode=true&characterEncoding=utf8
        jdbcdriver = os.getenv('SONAR_JDBC_DRIVER')  # com.mysql.jdbc.Driver
        jdbcusername = os.getenv('SONAR_JDBC_USERNAME')  # sonar
        jdbcpassword = os.getenv('SONAR_JDBC_PASSWORD')  # sonar
        hosturl = os.getenv('SONAR_HOST_URL')  # http://ldisonarci.wdf.sap.corp:8080/sonar

        logWarnings = []

        # Check server utl is set
        if jdbcurl is None:
            logWarnings.append('jdbc url is not set for sonar. Please set env SONAR_JDBC_URL')
        if jdbcdriver is None:
            logWarnings.append('jdbc driver is not set for sonar. Please set env SONAR_JDBC_DRIVER')
        if jdbcusername is None:
            logWarnings.append('jdbc username is not set for sonar. Please set env SONAR_JDBC_USERNAME')
        if jdbcpassword is None:
            logWarnings.append('jdbc password is not set for sona. Please set env SONAR_JDBC_PASSWORD')
        if hosturl is None:
            logWarnings.append('sonar host url is not set. Please set env SONAR_HOST_URL')

        if len(logWarnings) > 0:
            for logWarning in logWarnings:
                log.warning(logWarning, log.INFRA)
        else:
            sonarjdbcurl.text = jdbcurl
            sonarjdbcdriver.text = jdbcdriver
            sonarjdbcusername.text = jdbcusername
            sonarjdbcpassword.text = jdbcpassword
            sonarhosturl.text = hosturl

        # Write settings.xml in component/tmp directory
        log.info('write maven settings in ' + self._maven_settings_xml_file)
        if not os.path.isdir(self._dotm2_dir):
            os.makedirs(self._dotm2_dir)
        with open(self._maven_settings_xml_file, 'w') as f:
            f.write(ET.tostring(tree))
Exemplo n.º 8
0
def bootstrap2(argv):
    global xmake_status, build_cfg
    prepare_bootstrap()
    xmake_inst_dir = inst.get_installation_dir()
    if len(argv)>1 and argv[1]=='--bootstrap':
        xmake_status='bootstrap'
        sys.argv=argv=argv[0:1]+argv[2:]
    else:
        if isfile(join(xmake_inst_dir,'.loaded')):
            log.warning( 'directly using loaded sub level version of xmake')
            xmake_status='loaded'

    if xmake_status=='loaded':
        run(argv)
    else:
        log.info( 'bootstrapping xmake...')
        build_cfg = BuildConfig()
        (args,_,_) = setup_config(build_cfg, True)
        log.info("component root is "+build_cfg.component_dir())
        log.info( 'build runtime is ' + build_cfg.runtime())
        create_gendir(build_cfg)
        log.start_logfile(join(build_cfg.genroot_dir(),"boot.log"))
        determine_version_suffix(build_cfg, args.version) # required by xmake version check below

        if args.use_current_xmake_version:
            log.warning( 'using actually installed version as requested by option --use-current-xmake-version')
            run(argv)
        else:
            v=determine_xmake_version(build_cfg)
            if v==None:
                log.warning( 'no xmake version specified (please maintain file '+XMAKE_VERSION+" or xmake.cfg in project's cfg folder")
                log.info("default version is "+str(args.default_xmake_version))
                if args.default_xmake_version==None:
                    if build_cfg.is_release() or build_cfg.is_milestone():
                        raise XmakeException('no version specified for xmake for a productive build')
                    else:
                        log.warning( 'using actually installed version')
                        run(argv)
                else:
                    v=args.default_xmake_version
                    log.warning( 'using explicit default version '+v)
            if v==None:
                log.error("do not know any xmake version to use -> exit")
                sys.exit(2)
            else:
                v=find_latest(v)
                log.info( 'required xmake version is '+v)
                if v.endswith("-SNAPSHOT"):
                    if build_cfg.is_release() or build_cfg.is_milestone():
                        log.info("version suffix is "+str(build_cfg.version_suffix()))
                        log.error( 'this is a snapshot version, it cannot be used for release or milestone builds')
                        raise XmakeException('snapshot version specified for xmake for a realease or milestone build')
                    else:
                        log.warning( 'this is a snapshot version, it cannot be used for release builds')
                l=get_xmake_version(v, build_cfg)
                if is_existing_file(xmake_loaded): os.remove(xmake_loaded)
                log.info( 'required xmake version found at '+l)
                if test_mode:
                    cmd=[sys.executable, join(l,'xmake','bootstrap.py'), '--use-current-xmake-version']
                else:
                    cmd=[sys.executable, join(l,'xmake','xmake.py')]
                log.info( 'starting xmake...')
                cmd.extend(prepare_args(build_cfg, l,argv[1:]))
                if build_cfg.component_dir()!=None: os.chdir(build_cfg.component_dir())
                flush()
                log.stop_logfile()
                rc=subprocess.call(cmd)
                sys.exit(rc)