torquebox-vfs 1.0.0.CR1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/lib/gem_hook.rb +18 -0
  2. data/lib/jboss-common-core-2.2.17.GA.jar +0 -0
  3. data/lib/jboss-logging-3.0.0.Beta4.jar +0 -0
  4. data/lib/jboss-logging-spi-2.2.0.CR1.jar +0 -0
  5. data/lib/jboss-logmanager-1.2.0.CR9.jar +0 -0
  6. data/lib/jboss-logmanager-log4j-1.0.0.CR3.jar +0 -0
  7. data/lib/jboss-vfs-3.0.0.GA.jar +0 -0
  8. data/lib/log4j-1.2.14.jar +0 -0
  9. data/lib/org.torquebox.vfs.rb +20 -0
  10. data/lib/torquebox/vfs/debug_filter.rb +37 -0
  11. data/lib/torquebox/vfs/dir.rb +78 -0
  12. data/lib/torquebox/vfs/ext/dir.rb +188 -0
  13. data/lib/torquebox/vfs/ext/file.rb +278 -0
  14. data/lib/torquebox/vfs/ext/file_test.rb +48 -0
  15. data/lib/torquebox/vfs/ext/io.rb +158 -0
  16. data/lib/torquebox/vfs/ext/jdbc.rb +65 -0
  17. data/lib/torquebox/vfs/ext/kernel.rb +30 -0
  18. data/lib/torquebox/vfs/ext/pathname.rb +31 -0
  19. data/lib/torquebox/vfs/ext/tempfile.rb +31 -0
  20. data/lib/torquebox/vfs/ext/vfs.rb +24 -0
  21. data/lib/torquebox/vfs/ext/virtual_file.rb +72 -0
  22. data/lib/torquebox/vfs/file.rb +188 -0
  23. data/lib/torquebox/vfs/glob_filter.rb +46 -0
  24. data/lib/torquebox/vfs/glob_translator.rb +204 -0
  25. data/lib/torquebox/vfs.rb +100 -0
  26. data/lib/torquebox-vfs.jar +0 -0
  27. data/lib/torquebox-vfs.rb +20 -0
  28. data/lib/vfs.rb +20 -0
  29. data/licenses/lgpl-2.1.txt +504 -0
  30. data/spec/dir_spec.rb +259 -0
  31. data/spec/file_spec.rb +451 -0
  32. data/spec/file_test_spec.rb +34 -0
  33. data/spec/io_spec.rb +82 -0
  34. data/spec/jdbc_spec.rb +68 -0
  35. data/spec/pathname_spec.rb +20 -0
  36. data/spec/spec_helper.rb +171 -0
  37. data/spec/vfs_dir_spec.rb +23 -0
  38. data/spec/vfs_spec.rb +36 -0
  39. metadata +121 -0
@@ -0,0 +1,204 @@
1
+ # Copyright 2008-2011 Red Hat, Inc, and individual contributors.
2
+ #
3
+ # This is free software; you can redistribute it and/or modify it
4
+ # under the terms of the GNU Lesser General Public License as
5
+ # published by the Free Software Foundation; either version 2.1 of
6
+ # the License, or (at your option) any later version.
7
+ #
8
+ # This software is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this software; if not, write to the Free
15
+ # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16
+ # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
17
+
18
+ module TorqueBox
19
+ module VFS
20
+ class GlobTranslator
21
+
22
+ ESCAPED_CHARS = [ '.', '?', '(', ')', '[', ']' ]
23
+
24
+ def initialize(input)
25
+ @input = input
26
+ @cur = 0
27
+ @alternation_depth = 0
28
+ end
29
+
30
+
31
+ def self.translate(glob_str)
32
+ translator = GlobTranslator.new( glob_str )
33
+ regexp_str = translator.glob()
34
+ #puts "#{glob_str} ==> #{regexp_str}"
35
+ regexp_str
36
+ end
37
+
38
+ def self.to_regexp(glob_str)
39
+ regexp_str = translate( glob_str )
40
+ ##puts "regexp_str: #{regexp_str}"
41
+ Regexp.new( regexp_str )
42
+ end
43
+
44
+ def glob()
45
+ result = ''
46
+ while ( ! complete? )
47
+ c = la()
48
+ case( c )
49
+ when '*'
50
+ result += splat()
51
+ when '?'
52
+ result += question()
53
+ when '{'
54
+ result += alternation()
55
+ when '['
56
+ result += char_class()
57
+ else
58
+ if ( la_is_char? )
59
+ result += char();
60
+ else
61
+ break
62
+ end
63
+ end
64
+ end
65
+ result
66
+ end
67
+
68
+ def splat()
69
+ #puts "enter splat()"
70
+ if ( la(1) == '*' )
71
+ result = double_splat()
72
+ else
73
+ if ( cur() == 0 || lb() == '/' )
74
+ result = '[^/.][^/]*'
75
+ else
76
+ result = '[^/]+'
77
+ end
78
+ consume('*')
79
+ end
80
+ #puts "exit splat()"
81
+ result
82
+ end
83
+
84
+ def double_splat()
85
+ #puts "enter double_splat()"
86
+ result = '(.*)'
87
+ consume('*')
88
+ consume('*')
89
+ consume('/') if ( la() == '/' )
90
+ #puts "exit double_splat()"
91
+ result
92
+ end
93
+
94
+ def question()
95
+ #puts "enter question()"
96
+ consume('?')
97
+ #puts "exit question()"
98
+ '[^/]'
99
+ end
100
+
101
+ def alternation()
102
+ #puts "enter alternation()"
103
+ @alternation_depth += 1
104
+
105
+ result = '('
106
+
107
+ match_empty = false
108
+
109
+ consume('{')
110
+ if ( la() == ',' )
111
+ consume(',')
112
+ match_empty = true
113
+ end
114
+
115
+ result += '(' + glob() +')'
116
+
117
+ while ( la() == ',' )
118
+ consume(',')
119
+ if ( la() == '}' )
120
+ match_empty = true
121
+ break
122
+ end
123
+ result += '|(' + glob() + ')'
124
+ end
125
+
126
+ if ( match_empty )
127
+ result += '|'
128
+ end
129
+ result += ')'
130
+ consume( '}' )
131
+ @alternation_depth -= 1
132
+ #puts "exit alternation()"
133
+ result
134
+ end
135
+
136
+ def char_class()
137
+ consume( '[' )
138
+ result = '['
139
+
140
+ while( la() != ']' )
141
+ result += consume();
142
+ end
143
+
144
+ consume( ']' )
145
+ result += ']'
146
+ result
147
+ end
148
+
149
+ def char()
150
+ #puts "enter char()"
151
+ c = consume()
152
+ if ( c == '\\' )
153
+ c = consume()
154
+ end
155
+ if ( ESCAPED_CHARS.include?( c ) )
156
+ c = '\\' + c
157
+ end
158
+ #puts "exit char() #{c}"
159
+ c
160
+ end
161
+
162
+ def la_is_char?()
163
+ ( return true ) if ( @alternation_depth == 0 )
164
+ case ( la() )
165
+ when '}'
166
+ return false
167
+ when ','
168
+ return false
169
+ else
170
+ return true
171
+ end
172
+ end
173
+
174
+ private
175
+
176
+ def la(a=0)
177
+ @input[@cur+a,1]
178
+ end
179
+
180
+ def lb()
181
+ @input[(@cur-1),1]
182
+ end
183
+
184
+ def cur()
185
+ @cur
186
+ end
187
+
188
+ def consume(expected=nil)
189
+ c = la()
190
+ #puts "attempt consume: #{c}"
191
+ raise "Unexpected character: '#{c}'" if ( ( ! expected.nil? ) && ( c != expected ) )
192
+ @cur += 1
193
+ c
194
+ end
195
+
196
+ def complete?
197
+ @cur >= @input.length
198
+ end
199
+
200
+ end
201
+
202
+ end
203
+ end
204
+
@@ -0,0 +1,100 @@
1
+ # Copyright 2008-2011 Red Hat, Inc, and individual contributors.
2
+ #
3
+ # This is free software; you can redistribute it and/or modify it
4
+ # under the terms of the GNU Lesser General Public License as
5
+ # published by the Free Software Foundation; either version 2.1 of
6
+ # the License, or (at your option) any later version.
7
+ #
8
+ # This software is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this software; if not, write to the Free
15
+ # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16
+ # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
17
+
18
+ require 'java'
19
+
20
+ module TorqueBox
21
+ module VFS
22
+ end
23
+ end
24
+
25
+ require 'torquebox/vfs/file'
26
+ require 'torquebox/vfs/dir'
27
+ require 'torquebox/vfs/glob_filter'
28
+ require 'torquebox/vfs/ext/vfs'
29
+ require 'torquebox/vfs/ext/io'
30
+ require 'torquebox/vfs/ext/file'
31
+ require 'torquebox/vfs/ext/file_test'
32
+ require 'torquebox/vfs/ext/dir'
33
+ require 'torquebox/vfs/ext/pathname'
34
+ require 'torquebox/vfs/ext/kernel'
35
+ require 'torquebox/vfs/ext/jdbc'
36
+
37
+
38
+ module TorqueBox
39
+ module VFS
40
+ def self.resolve_within_archive(path)
41
+ path = path.to_s
42
+ return path if ( path =~ %r(^vfs:) )
43
+ cur = path
44
+ while ( cur != '.' && cur != '/' )
45
+ if ( ::File.exist_without_vfs?( cur ) )
46
+
47
+ child_path = path[cur.length..-1]
48
+
49
+ if ( cur[-1,1] == '/' )
50
+ cur = cur[0..-2]
51
+ end
52
+ return TorqueBox::VFS.resolve_path_url( cur ), child_path
53
+ end
54
+ cur = ::File.dirname( cur )
55
+ cur << '/' unless cur[-1,1] == '/'
56
+ end
57
+ nil
58
+ end
59
+
60
+ def self.resolve_path_url(path)
61
+ prefix = case
62
+ when path =~ /^\// # unix absolute
63
+ "vfs:"
64
+ when path =~ /^[[:alpha:]]:/ # windows absolute
65
+ "vfs:/"
66
+ else
67
+ "#{resolve_path_url( ::Dir.pwd )}/"
68
+ end
69
+ "#{prefix}#{path}"
70
+ end
71
+
72
+ def self.virtual_file(filename)
73
+ vfs_url, child_path = TorqueBox::VFS.resolve_within_archive( filename )
74
+ return nil unless vfs_url
75
+
76
+ begin
77
+ virtual_file = Java::org.jboss.vfs.VFS.child( vfs_url )
78
+ virtual_file = virtual_file.get_child( child_path ) if child_path
79
+ virtual_file
80
+ rescue Java::JavaIo::IOException => e
81
+ nil
82
+ end
83
+ end
84
+
85
+ def self.writable_path_or_error(path, e)
86
+ virtual_file = TorqueBox::VFS.virtual_file( path )
87
+ raise e if virtual_file.nil?
88
+ mount = Java::org.jboss.vfs::VFS.get_mount(virtual_file)
89
+ # TODO: Replace with a better error stating the issue, which is
90
+ # the user is trying to write to a filesystem inside an archive
91
+ # that is mounted as readonly
92
+ #
93
+ # HACK: For some reason mount.file_system doesn't work inside TB
94
+ # but does in tests
95
+ # raise e if mount.file_system.read_only?
96
+ virtual_file.physical_file.path
97
+ end
98
+
99
+ end
100
+ end
Binary file
@@ -0,0 +1,20 @@
1
+ module TorqueboxVfs
2
+ VERSION = '1.0.0.CR1'
3
+ MAVEN_VERSION = '1.0.0.CR1'
4
+ end
5
+ begin
6
+ require 'java'
7
+ require File.dirname(__FILE__) + '/torquebox-vfs.jar'
8
+ require File.dirname(__FILE__) + '/jboss-vfs-3.0.0.GA.jar'
9
+ require File.dirname(__FILE__) + '/jboss-logging-spi-2.2.0.CR1.jar'
10
+ require File.dirname(__FILE__) + '/jboss-logging-3.0.0.Beta4.jar'
11
+ require File.dirname(__FILE__) + '/jboss-logmanager-1.2.0.CR9.jar'
12
+ require File.dirname(__FILE__) + '/jboss-logmanager-log4j-1.0.0.CR3.jar'
13
+ require File.dirname(__FILE__) + '/log4j-1.2.14.jar'
14
+ require File.dirname(__FILE__) + '/jboss-common-core-2.2.17.GA.jar'
15
+ rescue LoadError
16
+ puts 'JAR-based gems require JRuby to load. Please visit www.jruby.org.'
17
+ raise
18
+ end
19
+
20
+ load File.dirname(__FILE__) + '/gem_hook.rb' if File.exists?( File.dirname(__FILE__) + '/gem_hook.rb')
data/lib/vfs.rb ADDED
@@ -0,0 +1,20 @@
1
+ # Copyright 2008-2011 Red Hat, Inc, and individual contributors.
2
+ #
3
+ # This is free software; you can redistribute it and/or modify it
4
+ # under the terms of the GNU Lesser General Public License as
5
+ # published by the Free Software Foundation; either version 2.1 of
6
+ # the License, or (at your option) any later version.
7
+ #
8
+ # This software is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this software; if not, write to the Free
15
+ # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16
+ # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
17
+
18
+ # Backwards-compatibility
19
+ $stderr.puts "Usage of 'vfs' is deprecated. Please use 'torquebox-vfs'."
20
+ require 'torquebox-vfs'