class GitPivotalTrackerIntegration::VersionUpdate::Gradle

A version updater for dealing with typical Gradle projects. This updater assumes that the version of the current project is stored within a gradle.properties file in the root of the repository. This properties file should have an entry with a key of version and version number as the key.

Public Class Methods

new(root) click to toggle source

Creates an instance of this updater

@param [String] root The root of the repository

# File lib/git-pivotal-tracker-integration/version-update/gradle.rb, line 28
def initialize(root)
  @gradle_file = File.expand_path 'app/build.gradle', root
end

Public Instance Methods

update_dev_version(new_version) click to toggle source

Update the version of the project

@param [String] new_version the version to update the project to @return [void]

# File lib/git-pivotal-tracker-integration/version-update/gradle.rb, line 36
def update_dev_version(new_version)
  update_version_in_sec('DEV', new_version, 'SNAPSHOT')
end
update_prod_version(new_version) click to toggle source
# File lib/git-pivotal-tracker-integration/version-update/gradle.rb, line 48
def update_prod_version(new_version)
  update_version_in_sec('PROD', qa_version_code, new_version)
end
update_qa_version(new_version) click to toggle source
# File lib/git-pivotal-tracker-integration/version-update/gradle.rb, line 40
def update_qa_version(new_version)
  update_version_in_sec('QA', new_version, 'SNAPSHOT')
end
update_uat_version(new_version) click to toggle source
# File lib/git-pivotal-tracker-integration/version-update/gradle.rb, line 44
def update_uat_version(new_version)
  update_version_in_sec('UAT', qa_version_code, new_version)
end

Private Instance Methods

qa_version_code() click to toggle source
# File lib/git-pivotal-tracker-integration/version-update/gradle.rb, line 63
def qa_version_code
  content     = File.read(@gradle_file)
  match       = content.match(/productFlavors.*?QA.*?versionCode( )*=?( )*(.*?\s)/m)
  match[3].strip
end
update_version(file_content, section, type, new_value) click to toggle source
# File lib/git-pivotal-tracker-integration/version-update/gradle.rb, line 69
def update_version(file_content, section, type, new_value)
  file_content.gsub(/productFlavors.*?#{section}.*?version#{type}( )*=?( )*(.*?\s)/m) do |match|
    match.gsub($3.strip, new_value)
  end
end
update_version_in_sec(section, new_code, new_version) click to toggle source
# File lib/git-pivotal-tracker-integration/version-update/gradle.rb, line 54
def update_version_in_sec(section, new_code, new_version)
  content     = File.read(@gradle_file)

  new_content = update_version(content, section, 'Code', new_code)  #update versionCode
  new_content = update_version(new_content, section, 'Name', "\"#{new_version}\"") #update versionName

  File.open(@gradle_file, 'w') { |file| file.write(new_content) }
end