Module: Gosu::Commands::Base

Defined in:
lib/gosu_android/commands/base.rb

Class Method Summary collapse

Class Method Details

.add_filesObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/gosu_android/commands/base.rb', line 29

def self.add_files 
  #root -> user directory
  root = Dir.pwd
  #gem root -> where the gem is located
  gem_root = File.expand_path(File.dirname(__FILE__))
  #Delete last occurence of /commands
  gem_root = gem_root.reverse.sub( "/commands".reverse, '' ).reverse

  #Add * to read all files in folder
  gem_root_s = gem_root + "/*"
  gem_root_ss = gem_root + "/*/*"
  
  #Get all the files needed for gosu android
  lib_files = FileList[ gem_root_s, gem_root_ss ].to_a
  #List of not usefull files
  not_copy_files = ["commands", "description", "version"]  
  
  #Do not copy the ones that are not needed
  not_copy_files.each do |not_copy|
    lib_files.delete_if do |element|
      element.include? not_copy 
    end
  end
  
  #Copy the files
  lib_files.each do |file|     
    src = String.new file     
    file.slice!(gem_root) 
    dst = root + '/src/gosu_android' + file 
    FileUtils.mkdir_p(File.dirname(dst))
    if file.include? ".rb"
      FileUtils.cp(src, dst)   
    end     
  end
  
  #Main file and jar dependencies go in different folders
  #than normal files
  #Delete last occurence of /gosu_android
  gem_root = gem_root.reverse.sub( "/gosu_android".reverse, '' ).reverse

  src = gem_root + "/gosu.rb"
  dst = root + "/src/gosu.rb"
  FileUtils.cp(src, dst)  
  src = gem_root + "/gosu.java.jar"
  dst = root + "/libs/gosu.java.jar"
  FileUtils.cp(src, dst)  
  
  #Resources files
  #Delete last occurence of /lib
  gem_root = gem_root.reverse.sub( "/lib".reverse, '' ).reverse
  gem_root_s = gem_root + "/res/*"
  gem_root_ss = gem_root + "/res/*/**"
  
  #Get all resources
  lib_files = FileList[ gem_root_s, gem_root_ss ].to_a   

  #Copy the resources
  lib_files.each do |file|     
    src = String.new file     
    file.slice!(gem_root) 
    dst = root + file
    FileUtils.mkdir_p(File.dirname(dst))
    if file.include? "."
      FileUtils.cp(src, dst)   
    end     
  end   
      
end

.delete_filesObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/gosu_android/commands/base.rb', line 98

def self.delete_files 
  root = Dir.pwd
  
  #Deleting whole gosu_android folder
  to_delete = root + "/src/gosu_android"   
  begin        
    FileUtils.rm_rf to_delete        
  rescue => e
    $stderr.puts e.message
  end  
  
  #Deleting gosu.rb file
  to_delete = root + "/src/gosu.rb"
  begin    
    File.delete to_delete        
  rescue => e
    $stderr.puts e.message
  end 
  
  #Deleting gosu.java.jar file
  to_delete = root + "/libs/gosu.java.jar"
  begin     
    File.delete to_delete        
  rescue => e
    $stderr.puts e.message
  end        
  
  #gem root -> where the gem is located
  gem_root = File.expand_path(File.dirname(__FILE__))
  gem_root = gem_root.reverse.sub( "/gosu_android/commands".reverse, '' ).reverse

  #Resources files
  #Delete last occurence of /lib
  gem_root = gem_root.reverse.sub( "/lib".reverse, '' ).reverse
  gem_root_s = gem_root + "/res/*"
  gem_root_ss = gem_root + "/res/*/**"
  
  #Get all resources
  lib_files = FileList[ gem_root_s, gem_root_ss ].to_a   

  #Delete only the previous copied resources
  lib_files.each do |file|      
    file.slice!(gem_root) 
    to_delete = root + file
    if file.include? "."
      begin     
        File.delete to_delete        
      rescue => e
        $stderr.puts e.message
      end   
    end     
  end          
  
end

.mainObject



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/gosu_android/commands/base.rb', line 153

def self.main
 add = false
 delete = false
 help = false
 version = false
  ARGV.each do|a|
    case a
    when "-a" 
      add = true
    when "--add"
      add = true
    when "-d"
      delete = true
    when "--delete" 
      delete = true
    when "-h" 
      help = true
    when "--help"
      help = true
    when "-v" 
      version = true
    when "--version"
      version = true            
    end    
  end
  
  if help or not add and not delete and not version
    show_help
    exit 0
  end
  
  if version
  	puts Gosu::VERSION
  	exit 0
  end
  
  if add and delete
    $stderr.puts "Add and delete can not be perform at the same time\n"
    exit 1
  end 
          
  if add 
    add_files
    exit 0
  end    
  
  if delete 
    delete_files
    exit 0
  end 
end

.show_helpObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gosu_android/commands/base.rb', line 12

def self.show_help
  puts "Usage: gosu_android OPTION"
  puts "Adds or deletes dependencies for Gosu in a Ruboto project."
  puts "If no argument is specified it displays this help."  
  puts ""
  puts " -a, --add adds the files to the project"
  puts " -d, --delete deletes the files from the project"
  puts " -v, --version shows current version"
  puts " -h, --help display this help and exit"
  puts ""
  puts "The options -a and -d can not be given together."
  puts ""
  puts "Exit status:"
  puts " 0 if everything went ok,"
  puts " 1 if there was some error."
end