Exemple #1
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)
Exemple #2
0
    def _store_build_dependencies(self):
        '''
            Store build dependencies in this format [group:artifact:version:type::classifier]
            ie: log4j-1.2.12-debug.jar --> log4j:log4j:1.2.12:jar::debug
            The file will be saved in [component_dir]/gen/tmp/dependencies
        '''
        artifacts = Artifact.gather_artifacts(self._maven_repository_dir)
        lines = []
        for key in artifacts:
            values = artifacts[key]
            for artifact in values:

                str_key = ':'.join([key, artifact.extension])
                if artifact.classifier:
                    str_key = '::'.join([str_key, artifact.classifier])
                lines.append(str_key)

        with open(self._maven_build_dependencies_file, 'w') as f:
            f.writelines(['%s\n' % line for line in lines])

        self.build_cfg.add_metadata_file(self._maven_build_dependencies_file)
        log.info('found ' + str(len(lines)) + ' dependencies')
Exemple #3
0
def execute_deployment(build_cfg):
    '''performs the xmake DEPLOY phase (deploys contents exported in the EXPORT phase to the specified maven repository)'''
    if not build_cfg.do_deploy():
        log.info(
            "skipping deployment, because the according option '-d' was not set"
        )
        return
    if build_cfg.do_custom_deploy():
        log.info("skipping nexus deployment, because of custom deployment")
        return
    if not os.path.exists(build_cfg.export_file()):
        log.warning("no export file found at: " + build_cfg.export_file())
        return  # TODO: consider breaking w/ err code

    isDiskDeployment = build_cfg.export_repo().startswith("file://")
    isStaging = build_cfg.is_release()

    # Deploy to nexus
    if not isDiskDeployment and not isStaging:
        _nexus_deployment(build_cfg, build_cfg.export_repo())
        return

    # Deploy to disk
    diskDeploymentPath = join(build_cfg.temp_dir(), 'stagingDeployment')
    local_repo_url = urlparse.urljoin('file:',
                                      urllib.pathname2url(diskDeploymentPath))

    log.info('deploying on disk {}'.format(diskDeploymentPath))
    _disk_deployment(build_cfg, local_repo_url)
    # Find artifacts in deployment folder
    artifacts = Artifact.gather_artifacts(diskDeploymentPath)

    if isStaging:
        (jsonUserAgent, nexusApi,
         repoDescription) = _nexus_staging_init(build_cfg)
        repoId = _nexus_staging_create(build_cfg, jsonUserAgent, nexusApi,
                                       repoDescription)
        status = _nexus_staging_push(build_cfg, jsonUserAgent, nexusApi,
                                     repoId, diskDeploymentPath)

        # If staging repo id set on commmand line, do not close it, except if promoting is requested in the same life cycle
        if not build_cfg.get_staging_repoid_parameter(
        ) or build_cfg.do_promote():
            status = _nexus_staging_close(build_cfg, nexusApi, repoId)

            # Create deployment descriptor file
            log.info("creating deploy.json file")
            if status and 'repositoryURI' in status:
                _create_deployment_file_descriptor(build_cfg, artifacts,
                                                   local_repo_url,
                                                   status['repositoryURI'])
            else:
                log.error(
                    'cannot create deployment file. Staging repository status returned by nexus does not contain the repository URI'
                )
    else:
        log.info("deployment in a file share. Creating deploy.json file")
        # Create deployment descriptor file
        _create_deployment_file_descriptor(build_cfg, artifacts,
                                           local_repo_url,
                                           build_cfg.export_repo())
        # Deploy really to the definive disk place
        _disk_deployment(build_cfg, build_cfg.export_repo())