Class: PivotalIntegration::VersionUpdate::Gradle

Inherits:
Object
  • Object
show all
Defined in:
lib/pivotal-integration/version-update/gradle.rb

Overview

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.

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ Gradle

Creates an instance of this updater

Parameters:

  • root (String)

    The root of the repository



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/pivotal-integration/version-update/gradle.rb', line 27

def initialize(root)
  @gradle_properties = File.expand_path 'gradle.properties', root

  if File.exist? @gradle_properties
    groups = nil
    File.open(@gradle_properties, 'r') do |file|
      groups = file.read().scan(/version[=:](.*)/)
    end
    @version = groups[0] ? groups[0][0]: nil
  end
end

Instance Method Details

#current_versionString

The current version of the project

Returns:

  • (String)

    the current version of the project



50
51
52
# File 'lib/pivotal-integration/version-update/gradle.rb', line 50

def current_version
  @version
end

#supports?Boolean

Whether this updater supports updating this project

Returns:

  • (Boolean)

    true if a valid version number was found on initialization, false otherwise



43
44
45
# File 'lib/pivotal-integration/version-update/gradle.rb', line 43

def supports?
  !@version.nil?
end

#update_version(new_version) ⇒ void

This method returns an undefined value.

Update the version of the project

Parameters:

  • new_version (String)

    the version to update the project to



58
59
60
61
62
# File 'lib/pivotal-integration/version-update/gradle.rb', line 58

def update_version(new_version)
  contents = File.read(@gradle_properties)
  contents = contents.gsub(/(version[=:])#{@version}/, "\\1#{new_version}")
  File.open(@gradle_properties, 'w') { |file| file.write(contents) }
end