changeset 10:6e6b00d95d0b 1

Automatic versioning.
author Mikhail Kryshen <mikhail@kryshen.net>
date Tue, 17 Jul 2012 07:16:29 +0400
parents 2efb0973ab83
children 27996848b621
files Rakefile src/net/kryshen/charamega/field.mirah src/net/kryshen/charamega/game.mirah src/net/kryshen/charamega/ui.mirah
diffstat 4 files changed, 22 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/Rakefile	Tue Jul 17 05:08:17 2012 +0400
+++ b/Rakefile	Tue Jul 17 07:16:29 2012 +0400
@@ -5,12 +5,18 @@
 SRC = FileList['src/**/*.mirah']
 
 CLEAN.include 'build/**/*.class'
+CLEAN.include 'build/**/version.properties'
 CLEAN.include 'dist/*.jar'
 
 task :default => [:compile]
 
 task :compile => SRC do
   Mirah::compile '--jvm', '1.6', '-d', 'build', *SRC
+
+  version = `hg log -r tip --template "{latesttag}.{latesttagdistance}"`
+  File.open('build/net/kryshen/charamega/version.properties', 'w') do |f|
+    f.write "version = #{version}\n"
+  end
 end
 
 task :run => [:compile] do
@@ -26,4 +32,3 @@
     end
   end
 end
-
--- a/src/net/kryshen/charamega/field.mirah	Tue Jul 17 05:08:17 2012 +0400
+++ b/src/net/kryshen/charamega/field.mirah	Tue Jul 17 07:16:29 2012 +0400
@@ -42,7 +42,7 @@
     setPreferredSize Dimension.new(790, 500)
 
     begin
-      source = getClass.getResource("DejaVuSans.ttf").openStream
+      source = getClass.getResourceAsStream("DejaVuSans.ttf")
       font = Font.createFont(Font.TRUETYPE_FONT, source)
     ensure
       source.close  unless source.nil?
--- a/src/net/kryshen/charamega/game.mirah	Tue Jul 17 05:08:17 2012 +0400
+++ b/src/net/kryshen/charamega/game.mirah	Tue Jul 17 07:16:29 2012 +0400
@@ -23,6 +23,7 @@
 import java.util.List
 import java.util.ArrayList
 import java.util.Collections
+import java.util.Properties
 
 class Game
 
@@ -305,6 +306,19 @@
     Card(row.get j)
   end
 
+  def version
+    return @version  unless @version.nil?
+    
+    begin
+      source = getClass.getResourceAsStream("version.properties")
+      properties = Properties.new.load(source)
+    ensure
+      source.close  unless source.nil?
+    end
+    
+    @version = properties.getProperty("version")
+  end
+
   private
 
   def compute_limits
--- a/src/net/kryshen/charamega/ui.mirah	Tue Jul 17 05:08:17 2012 +0400
+++ b/src/net/kryshen/charamega/ui.mirah	Tue Jul 17 07:16:29 2012 +0400
@@ -28,7 +28,6 @@
 
   def self.initialize:void
     @@title = 'Charamega'
-    @@version = '0.9'
     @@home = 'http://kryshen.net/games/'
   end
 
@@ -162,7 +161,7 @@
     title = JLabel.new(@@title)
       .setFont(Font.new('serif', Font.BOLD, 26))
 
-    version = JLabel.new("version #{@@version}")
+    version = JLabel.new("version #{@game.version}")
     link = HyperlinkLabel.new(@@home)
 
     players_label = JLabel.new('Players: ')