Skip to content
Newer
Older
100644 119 lines (96 sloc) 3.19 KB
2f72622 @adamjmurray started porting build.xml to rake
authored Nov 26, 2010
1 require 'rake/clean'
8149dff @adamjmurray cleaned up manifest stuff
authored Nov 29, 2010
2 require 'tempfile'
2f72622 @adamjmurray started porting build.xml to rake
authored Nov 27, 2010
3 include FileUtils
4
5 VERSION = '0.9.2'
3574003 @adamjmurray the distribution archive can now be constructed with rake (build.xml …
authored Nov 29, 2010
6 BUILD_DATE = Time.now.utc.strftime '%B %d, %Y (%H:%M GMT)'
8149dff @adamjmurray cleaned up manifest stuff
authored Nov 29, 2010
7 MANIFEST =
3574003 @adamjmurray the distribution archive can now be constructed with rake (build.xml …
authored Nov 29, 2010
8 "Library: ajm objects (MXJ) for MaxMSP
9 Version: #{VERSION}
8149dff @adamjmurray cleaned up manifest stuff
authored Nov 29, 2010
10 Built-Date: #{BUILD_DATE}
3574003 @adamjmurray the distribution archive can now be constructed with rake (build.xml …
authored Nov 29, 2010
11 Author: Adam Murray
12 URL: http://compusition.com
13 "
2f72622 @adamjmurray started porting build.xml to rake
authored Nov 27, 2010
14
3574003 @adamjmurray the distribution archive can now be constructed with rake (build.xml …
authored Nov 29, 2010
15 SRC = 'src'
16 LIB = 'lib'
17 PATCHES = 'ajm'
18 LICENSE = 'license'
19 BUILD = 'build'
20 DIST = 'dist'
f70228d @adamjmurray Rake now packages everything up in subdirectory under the dist/, to k…
authored Nov 30, 2010
21 PACKAGE = "#{DIST}/ajm-objects-#{VERSION}"
a975ffe @adamjmurray added jar task to rakefile
authored Nov 26, 2010
22
3574003 @adamjmurray the distribution archive can now be constructed with rake (build.xml …
authored Nov 29, 2010
23 SOURCES = FileList["#{SRC}/**/*.java"].exclude(/Test\.java$/)
24 CLASSPATH = FileList["#{LIB}/**/*.jar"].exclude(/^ajm.jar$/)
a975ffe @adamjmurray added jar task to rakefile
authored Nov 27, 2010
25 JAR = "#{LIB}/ajm.jar"
26
27
3574003 @adamjmurray the distribution archive can now be constructed with rake (build.xml …
authored Nov 29, 2010
28 ##############################################################################
29 # TASK DEFINITIONS
30
f70228d @adamjmurray Rake now packages everything up in subdirectory under the dist/, to k…
authored Dec 1, 2010
31 CLEAN.include BUILD, JAR
a975ffe @adamjmurray added jar task to rakefile
authored Nov 27, 2010
32 CLOBBER.include DIST
2f72622 @adamjmurray started porting build.xml to rake
authored Nov 27, 2010
33
34
35 desc 'compile the java source files'
36 task :compile do
3574003 @adamjmurray the distribution archive can now be constructed with rake (build.xml …
authored Nov 29, 2010
37 mkdir BUILD
38 puts "Compiling java sources to #{BUILD}/"
a975ffe @adamjmurray added jar task to rakefile
authored Nov 27, 2010
39 `javac -classpath #{CLASSPATH.join ':'} -d #{BUILD} -g -source 1.5 -target 1.5 #{SOURCES}`
40 end
41
42
3574003 @adamjmurray the distribution archive can now be constructed with rake (build.xml …
authored Nov 29, 2010
43 desc 'construct the jar archive of the compiled java sources'
44 task :jar => [:clean, :compile] do
8149dff @adamjmurray cleaned up manifest stuff
authored Nov 29, 2010
45 manifest = Tempfile.new('manifest')
46 File.open(manifest, 'w') {|io| io.write MANIFEST }
47 puts "Constructing #{JAR}"
48 `jar cvfm #{JAR} #{manifest.path} -C #{BUILD} .`
2f72622 @adamjmurray started porting build.xml to rake
authored Nov 27, 2010
49 end
3574003 @adamjmurray the distribution archive can now be constructed with rake (build.xml …
authored Nov 29, 2010
50
51
52 desc 'prepare the files for distribution'
ff1fc24 @adamjmurray put variable replacement logic in ints own rake task
authored Nov 29, 2010
53 task :package => [:jar] do
3574003 @adamjmurray the distribution archive can now be constructed with rake (build.xml …
authored Nov 29, 2010
54 puts "Preparing distribution package"
55 package_lib = "#{PACKAGE}/#{LIB}"
f70228d @adamjmurray Rake now packages everything up in subdirectory under the dist/, to k…
authored Dec 1, 2010
56 mkdir DIST
3574003 @adamjmurray the distribution archive can now be constructed with rake (build.xml …
authored Nov 29, 2010
57 mkdir PACKAGE
58 mkdir package_lib
59
60 # Collect the files
61 FileList['*.txt', '*.example'].each do |filename|
62 cp filename, PACKAGE
63 end
64 FileList["#{LIB}/*.jar"].exclude('max.jar', /^.*junit.*jar$/, 'bsf.jar').each do |filename|
65 cp filename, package_lib
66 end
67 cp_r PATCHES, PACKAGE
68 cp_r LICENSE, PACKAGE
ff1fc24 @adamjmurray put variable replacement logic in ints own rake task
authored Nov 29, 2010
69 end
70
3574003 @adamjmurray the distribution archive can now be constructed with rake (build.xml …
authored Nov 29, 2010
71
ff1fc24 @adamjmurray put variable replacement logic in ints own rake task
authored Nov 29, 2010
72 desc 'search and replace variable values in text files'
73 task :replace_vars => [:package] do
3574003 @adamjmurray the distribution archive can now be constructed with rake (build.xml …
authored Nov 29, 2010
74 puts "Performing search and replace for the VERSION and BUILD_DATE variables"
75 plaintext_filetypes = ['txt', 'maxpat', 'maxhelp']
76 files = FileList[ plaintext_filetypes.map{|type| "#{PACKAGE}/**/*.#{type}" } ]
77 files.replace_all '@@VERSION', VERSION
78 files.replace_all '@@BUILD_DATE', BUILD_DATE
79 end
80
81
82 desc 'construct the distribution archive'
ff1fc24 @adamjmurray put variable replacement logic in ints own rake task
authored Nov 29, 2010
83 task :dist => [:replace_vars] do
3574003 @adamjmurray the distribution archive can now be constructed with rake (build.xml …
authored Nov 29, 2010
84 mkdir DIST
85 archive = "#{DIST}/#{PACKAGE}.zip"
86 puts "Constructing distribution archive #{archive}"
ff22850 @adamjmurray fixed cross-platform text file newline issue in the rake build
authored Nov 29, 2010
87 `zip -l -r #{archive} #{PACKAGE}`
88 # The -l option converts newlines to crlf, which should display correctly on both OS X and Windows.
89 # Otherwise, since I write these txt files on OS X, newlines would disappear when viewed in Notepad on Windows.
3574003 @adamjmurray the distribution archive can now be constructed with rake (build.xml …
authored Nov 29, 2010
90 end
91
92
93 ##############################################################################
94 # SUPPORT CODE:
95
96 # I find it annoying that I always have to check if a directory exists
97 # before creating it, so I monkey patch mkdir() to handle it automatically:
98 alias original_mkdir mkdir
99 def mkdir(dir)
100 original_mkdir dir if not File.exist? dir
101 end
102
103
104 class FileList
105 # Replaces all occurrences of token with value
106 def replace_all(token, value)
107 self.each do |filename|
108 next if File.directory? filename
109 contents = IO.read filename
110 if contents.include? token
111 contents.gsub! token, value
112 File.open(filename, 'w') do |io|
113 io.write contents
114 end
115 end
116 end
117 end
118 end
Something went wrong with that request. Please try again.