lib/cicd/builder/manifest/mixlib/build.rb in manifest-builder-0.3.0 vs lib/cicd/builder/manifest/mixlib/build.rb in manifest-builder-0.4.0

- old
+ new

@@ -75,43 +75,106 @@ # # --------------------------------------------------------------------------------------------------------------- # def makeBuild() # super # end + VER_RGX = %r'^\d+\.\d+(\.?\d)*$' + MMP_RGX = %r'^(\d+\.?){2,3}$' + # --------------------------------------------------------------------------------------------------------------- + def getVersionBuildFromName(artifact) + version = artifact.dup + version.gsub!(%r'\.*(tar\.gz|tgz|bzip2|bz2|jar|war|[a-z]+)$', '') + # if artifact =~ %r'^#{comp[0]}' + # version.gsub!(%r'^#{comp[0]}\.*-*','') + # else + # version.gsub!(%r'^[a-zA-Z\-._]+','') + # end + version.gsub!(%r'^[a-zA-Z\-._]+', '') + + # build = if version.match(VER_RGX) + # if version.match(%r'^(\d+\.?){2,3}$') + # 0 + # elsif version.match(%r'\-') + # version,build = version.split(/-/) + # build + # else + # 0 + # end + # else + # 0 + # end + build = '' + if version.match(VER_RGX) + if version.match(%r'\-') + version,build = version.split(/-/) + end + # else + # match = version.match(%r'^(\d+)-(\d{4}-\d{2}-\d{2}[_]\d{2}-\d{2}-\d{2})\.(release|snapshot)$') + # if match + # build = match[1] + # # version.gsub!(/^#{build}-/, '') + # version = match[2] + # end + end + [version,build] + end + + # --------------------------------------------------------------------------------------------------------------- def getVersionBuild(path,artifact,comp) version,build = File.split(path) - if build.match(%r'^\d+$') and version.match(%r'/?\d+\.\d+\.?\d*$') + if build.match(%r'^\d+$') and version.match(%r'/?\d+\.\d+\.?\d*$') # Hole in one! version = File.basename(version) - build = build.to_i else - build = comp[1][:build] || 0 - version = comp[1][:build].nil? ? '' : ( comp[1][:build] > 0 ? build.to_s : '' ) - build = comp[1][:build] || 0 - unless version.match(%r'^[.0-9]+$') + if build.match(VER_RGX) + version = build + build = '' + else + version = comp[1][:build].nil? ? '' : ( comp[1][:build] > 0 ? build.to_s : '' ) + end + unless version.match(VER_RGX) version = comp[1][:version] || '' end + ver,bld = getVersionBuildFromName(artifact) if version.empty? - version = artifact.dup - version.gsub!(%r'\.*(tar\.gz|tgz|bzip2|bz2|jar|war|[a-z]+)$','') - if artifact =~ %r'^#{comp[0]}' - version.gsub!(%r'^#{comp[0]}\.*-*','') - else - version.gsub!(%r'^[a-zA-Z\-.]+','') - end + version,build = [ver,bld] if version.empty? version = @vars[:build_ver] else uri,ver = File.split(path) - if version =~ %r'^#{ver}' and version =~ %r'^(\d+\.){3}' + if version =~ %r'^#{ver}' + if version =~ VER_RGX + if version =~ %r'^#{build}' # prob the major part of version + build = '' + end + else + unless version.eql?(ver) + build = version.dup + version = ver + build = build.gsub(%r'^#{version}(\.|-)*','') + end + end + else build = version.dup version = ver build = build.gsub(%r'^#{version}(\.|-)*','') end end - if build == 0 or build.empty? - build = @vars[:build_num] - end else + if ver.match(VER_RGX) + if ver.match(MMP_RGX) + if version.length < ver.length + version = ver # Guessing it is the better version + end + else + build = ver.dup + # version.gsub!(/\.d+$/, '') + build.gsub!(/^#{version}\.?/, '') + end + end + end + unless build.match(%r'^[1-9]\d*$') + build = comp[1][:build] + build = @vars[:build_num] if (build.nil? or build.empty? or build.to_i == 0) end end [version,build] end