calabash-android 0.4.0.pre1 → 0.4.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/bin/calabash-android-build.rb +6 -0
  2. data/bin/calabash-android-setup.rb +2 -3
  3. data/lib/calabash-android/canned_steps.md +1 -1
  4. data/lib/calabash-android/helpers.rb +35 -2
  5. data/lib/calabash-android/lib/TestServer.apk +0 -0
  6. data/lib/calabash-android/operations.rb +13 -6
  7. data/lib/calabash-android/version.rb +1 -1
  8. data/test-server/instrumentation-backend/.classpath +2 -1
  9. data/test-server/instrumentation-backend/antlr.sh +2 -0
  10. data/test-server/instrumentation-backend/antlr/UIQuery.g +70 -0
  11. data/test-server/instrumentation-backend/antlr/UIQuery.tokens +12 -0
  12. data/test-server/instrumentation-backend/build-libs/antlr-3.4-complete.jar +0 -0
  13. data/test-server/instrumentation-backend/build-libs/junit.jar +0 -0
  14. data/test-server/instrumentation-backend/build.xml +56 -0
  15. data/test-server/instrumentation-backend/src/org/antlr/runtime/ANTLRFileStream.java +78 -0
  16. data/test-server/instrumentation-backend/src/org/antlr/runtime/ANTLRInputStream.java +70 -0
  17. data/test-server/instrumentation-backend/src/org/antlr/runtime/ANTLRReaderStream.java +95 -0
  18. data/test-server/instrumentation-backend/src/org/antlr/runtime/ANTLRStringStream.java +230 -0
  19. data/test-server/instrumentation-backend/src/org/antlr/runtime/BaseRecognizer.java +894 -0
  20. data/test-server/instrumentation-backend/src/org/antlr/runtime/BitSet.java +325 -0
  21. data/test-server/instrumentation-backend/src/org/antlr/runtime/BufferedTokenStream.java +272 -0
  22. data/test-server/instrumentation-backend/src/org/antlr/runtime/CharStream.java +57 -0
  23. data/test-server/instrumentation-backend/src/org/antlr/runtime/CharStreamState.java +45 -0
  24. data/test-server/instrumentation-backend/src/org/antlr/runtime/ClassicToken.java +141 -0
  25. data/test-server/instrumentation-backend/src/org/antlr/runtime/CommonToken.java +191 -0
  26. data/test-server/instrumentation-backend/src/org/antlr/runtime/CommonTokenStream.java +153 -0
  27. data/test-server/instrumentation-backend/src/org/antlr/runtime/DFA.java +250 -0
  28. data/test-server/instrumentation-backend/src/org/antlr/runtime/EarlyExitException.java +41 -0
  29. data/test-server/instrumentation-backend/src/org/antlr/runtime/FailedPredicateException.java +54 -0
  30. data/test-server/instrumentation-backend/src/org/antlr/runtime/IntStream.java +122 -0
  31. data/test-server/instrumentation-backend/src/org/antlr/runtime/LegacyCommonTokenStream.java +394 -0
  32. data/test-server/instrumentation-backend/src/org/antlr/runtime/Lexer.java +340 -0
  33. data/test-server/instrumentation-backend/src/org/antlr/runtime/MismatchedNotSetException.java +41 -0
  34. data/test-server/instrumentation-backend/src/org/antlr/runtime/MismatchedRangeException.java +45 -0
  35. data/test-server/instrumentation-backend/src/org/antlr/runtime/MismatchedSetException.java +44 -0
  36. data/test-server/instrumentation-backend/src/org/antlr/runtime/MismatchedTokenException.java +45 -0
  37. data/test-server/instrumentation-backend/src/org/antlr/runtime/MismatchedTreeNodeException.java +49 -0
  38. data/test-server/instrumentation-backend/src/org/antlr/runtime/MissingTokenException.java +56 -0
  39. data/test-server/instrumentation-backend/src/org/antlr/runtime/NoViableAltException.java +57 -0
  40. data/test-server/instrumentation-backend/src/org/antlr/runtime/Parser.java +98 -0
  41. data/test-server/instrumentation-backend/src/org/antlr/runtime/ParserRuleReturnScope.java +52 -0
  42. data/test-server/instrumentation-backend/src/org/antlr/runtime/RecognitionException.java +180 -0
  43. data/test-server/instrumentation-backend/src/org/antlr/runtime/RecognizerSharedState.java +144 -0
  44. data/test-server/instrumentation-backend/src/org/antlr/runtime/RuleReturnScope.java +42 -0
  45. data/test-server/instrumentation-backend/src/org/antlr/runtime/SerializedGrammar.java +204 -0
  46. data/test-server/instrumentation-backend/src/org/antlr/runtime/Token.java +92 -0
  47. data/test-server/instrumentation-backend/src/org/antlr/runtime/TokenRewriteStream.java +569 -0
  48. data/test-server/instrumentation-backend/src/org/antlr/runtime/TokenSource.java +54 -0
  49. data/test-server/instrumentation-backend/src/org/antlr/runtime/TokenStream.java +75 -0
  50. data/test-server/instrumentation-backend/src/org/antlr/runtime/UnbufferedTokenStream.java +82 -0
  51. data/test-server/instrumentation-backend/src/org/antlr/runtime/UnwantedTokenException.java +53 -0
  52. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/BlankDebugEventListener.java +77 -0
  53. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugEventHub.java +292 -0
  54. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugEventListener.java +323 -0
  55. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugEventRepeater.java +88 -0
  56. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugEventSocketProxy.java +358 -0
  57. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugParser.java +101 -0
  58. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugTokenStream.java +156 -0
  59. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugTreeAdaptor.java +250 -0
  60. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugTreeNodeStream.java +155 -0
  61. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugTreeParser.java +112 -0
  62. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/ParseTreeBuilder.java +109 -0
  63. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/Profiler.java +772 -0
  64. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/RemoteDebugEventSocketListener.java +541 -0
  65. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/TraceDebugEventListener.java +108 -0
  66. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/Tracer.java +69 -0
  67. data/test-server/instrumentation-backend/src/org/antlr/runtime/misc/DoubleKeyMap.java +62 -0
  68. data/test-server/instrumentation-backend/src/org/antlr/runtime/misc/FastQueue.java +100 -0
  69. data/test-server/instrumentation-backend/src/org/antlr/runtime/misc/IntArray.java +87 -0
  70. data/test-server/instrumentation-backend/src/org/antlr/runtime/misc/LookaheadStream.java +161 -0
  71. data/test-server/instrumentation-backend/src/org/antlr/runtime/misc/Stats.java +189 -0
  72. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/BaseTree.java +349 -0
  73. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/BaseTreeAdaptor.java +279 -0
  74. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/BufferedTreeNodeStream.java +489 -0
  75. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/CommonErrorNode.java +108 -0
  76. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/CommonTree.java +185 -0
  77. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/CommonTreeAdaptor.java +168 -0
  78. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/CommonTreeNodeStream.java +171 -0
  79. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/ParseTree.java +119 -0
  80. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteCardinalityException.java +47 -0
  81. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteEarlyExitException.java +39 -0
  82. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteEmptyStreamException.java +35 -0
  83. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteRuleElementStream.java +210 -0
  84. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteRuleNodeStream.java +70 -0
  85. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteRuleSubtreeStream.java +86 -0
  86. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteRuleTokenStream.java +76 -0
  87. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/Tree.java +127 -0
  88. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeAdaptor.java +263 -0
  89. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeFilter.java +135 -0
  90. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeIterator.java +132 -0
  91. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeNodeStream.java +106 -0
  92. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeParser.java +169 -0
  93. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreePatternLexer.java +135 -0
  94. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreePatternParser.java +154 -0
  95. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeRewriter.java +124 -0
  96. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeRuleReturnScope.java +41 -0
  97. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeVisitor.java +69 -0
  98. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeVisitorAction.java +47 -0
  99. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeWizard.java +531 -0
  100. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java +22 -7
  101. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/InstrumentationBackend.java +4 -4
  102. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/Result.java +0 -1
  103. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/HttpServer.java +161 -129
  104. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/activity/SetActivityOrientation.java +5 -7
  105. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/GetViewProperty.java +1 -7
  106. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/Query.java +70 -61
  107. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/UIQuery.tokens +12 -0
  108. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ViewMapper.java +63 -0
  109. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/antlr/UIQuery.tokens +10 -0
  110. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/antlr/UIQueryLexer.java +945 -0
  111. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/antlr/UIQueryParser.java +463 -0
  112. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/InvalidUIQueryException.java +10 -0
  113. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryAST.java +8 -0
  114. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryASTClassName.java +115 -0
  115. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryASTWith.java +157 -0
  116. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryDirection.java +5 -0
  117. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryEvaluator.java +205 -0
  118. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryUtils.java +135 -0
  119. data/test-server/instrumentation-backend/tests/sh/calaba/instrumentationbackend/query/tests/UIQueryTest.java +134 -0
  120. metadata +106 -3
  121. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/activity/SetOrientation.java +0 -39
@@ -1,5 +1,11 @@
1
1
  def calabash_build(app)
2
2
  keystore = read_keystore_info()
3
+ if fingerprint_from_keystore != fingerprint_from_apk(app)
4
+ puts "#{app} is not signed with the configured keystore '#{keystore["keystore_location"]}' Aborting!"
5
+ exit 1
6
+ end
7
+
8
+
3
9
 
4
10
  test_server_file_name = test_server_path(app)
5
11
  FileUtils.mkdir_p File.dirname(test_server_file_name) unless File.exist? File.dirname(test_server_file_name)
@@ -8,12 +8,11 @@ def calabash_setup
8
8
  @settings = {}
9
9
 
10
10
  puts "Please enter keystore information to use a custom keystore instead of the default"
11
-
11
+
12
12
  ask_for_setting(:keystore_location, "Please enter keystore location")
13
13
  ask_for_setting(:keystore_password, "Please enter the password for the keystore")
14
14
  ask_for_setting(:keystore_alias, "Please enter the alias")
15
- ask_for_setting(:keystore_alias_password, "Please enter the password for the alias")
16
-
15
+
17
16
  open('.calabash_settings', 'w') do |f|
18
17
  f.puts @settings.to_json
19
18
  end
@@ -211,7 +211,7 @@ To take a screenshot of the phone while running the test use any of these steps.
211
211
 
212
212
  Location steps
213
213
  --------------
214
- If you app has the `ALLOW_MOCK_LOCATION` permission you can change the perceived location of the device by using any of these steps.
214
+ If you allow your phone to use mocked locations (configured on your device under development settings) and your app has the `ACCESS_MOCK_LOCATION` permission you can change the perceived location of the device by using any of these steps.
215
215
 
216
216
 
217
217
  You can change the location any address or named location. This is done using the [geocoder gem](http://www.rubygeocoder.com/).
@@ -83,11 +83,44 @@ def read_keystore_info
83
83
  "keystore_location" => "#{ENV["HOME"]}/.android/debug.keystore",
84
84
  "keystore_password" => "android",
85
85
  "keystore_alias" => "androiddebugkey",
86
- "keystore_alias_password" => "android"
87
86
  }
88
87
  end
89
88
  end
90
89
 
90
+ def fingerprint_from_keystore
91
+ keystore_info = read_keystore_info
92
+ fingerprints = `keytool -v -list -alias #{keystore_info["keystore_alias"]} -keystore #{keystore_info["keystore_location"]} -storepass #{keystore_info["keystore_password"]}`
93
+ md5_fingerprint = extract_md5_fingerprint(fingerprints)
94
+ log "MD5 fingerprint for keystore (#{keystore_info["keystore_location"]}): #{md5_fingerprint}"
95
+ md5_fingerprint
96
+ end
97
+
98
+ def fingerprint_from_apk(app_path)
99
+ Dir.mktmpdir do |tmp_dir|
100
+ Dir.chdir(tmp_dir) do
101
+ FileUtils.cp(app_path, "app.apk")
102
+ FileUtils.mkdir("META-INF")
103
+ Zip::ZipFile.foreach("app.apk") do |z|
104
+ z.extract if /^META-INF\/\w+.(RSA|rsa)/ =~ z.name
105
+ end
106
+ rsa_files = Dir["#{tmp_dir}/META-INF/*"]
107
+ raise "No RSA file found in META-INF. Cannot proceed." if rsa_files.empty?
108
+ raise "More than one RSA file found in META-INF. Cannot proceed." if rsa_files.length > 1
109
+
110
+ fingerprints = `keytool -v -printcert -file #{rsa_files.first}`
111
+ md5_fingerprint = extract_md5_fingerprint(fingerprints)
112
+ log "MD5 fingerprint for signing cert (#{app_path}): #{md5_fingerprint}"
113
+ md5_fingerprint
114
+ end
115
+ end
116
+ end
117
+
118
+ def extract_md5_fingerprint(fingerprints)
119
+ m = fingerprints.scan(/MD5:\s+((?:\h\h:){15}\h\h)/)
120
+ raise "No MD5 fingerprint found:\n #{fingerprints}" unless m
121
+ m.last.first
122
+ end
123
+
91
124
  def is_windows?
92
125
  require 'rbconfig'
93
126
  (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
@@ -95,4 +128,4 @@ end
95
128
 
96
129
  def log(message, error = false)
97
130
  $stdout.puts "#{Time.now.strftime("%Y-%m-%d %H:%M:%S")} - #{message}" if (error or ARGV.include? "-v" or ARGV.include? "--verbose")
98
- end
131
+ end
@@ -83,16 +83,17 @@ module Operations
83
83
  end
84
84
 
85
85
  def wait_for(timeout, &block)
86
+ value = nil
86
87
  begin
87
88
  Timeout::timeout(timeout) do
88
- until block.call
89
+ until value = block.call
89
90
  sleep 0.3
90
91
  end
91
92
  end
92
93
  rescue Exception => e
93
- take_screenshot
94
94
  raise e
95
95
  end
96
+ value
96
97
  end
97
98
 
98
99
  def query(uiquery, *args)
@@ -105,7 +106,10 @@ module Operations
105
106
  raise "Invalid query #{uiquery}"
106
107
  end
107
108
  else
108
- JSON.parse(http("/query", {"query" => uiquery}))
109
+ arguments = [*args]
110
+ operation = {"method_name"=>"query", "arguments" => arguments}
111
+ data = {"query" => uiquery, "operation" => operation}
112
+ JSON.parse(http("/map",data))
109
113
  end
110
114
  end
111
115
 
@@ -381,16 +385,19 @@ module Operations
381
385
  raise(msg)
382
386
  end
383
387
 
384
- def touch(uiquery,options={})
388
+ def touch(uiquery,*args)
385
389
  if uiquery.instance_of? String
386
- elements = query(uiquery, options)
390
+ elements = query(uiquery, *args)
387
391
  raise "No elements found" if elements.empty?
388
392
  element = elements.first
389
393
  else
390
394
  element = uiquery
391
395
  end
392
396
 
393
- performAction("touch_coordinate", element["frame"]["x"], element["frame"]["y"])
397
+
398
+ center_x = element["frame"]["x"] + element["frame"]["width"] / 2
399
+ center_y = element["frame"]["y"] + element["frame"]["height"] / 2
400
+ performAction("touch_coordinate", center_x, center_y)
394
401
  end
395
402
 
396
403
  def http(options, data=nil)
@@ -1,5 +1,5 @@
1
1
  module Calabash
2
2
  module Android
3
- VERSION = "0.4.0.pre1"
3
+ VERSION = "0.4.0.pre2"
4
4
  end
5
5
  end
@@ -3,8 +3,9 @@
3
3
  <classpathentry kind="src" path="src"/>
4
4
  <classpathentry kind="src" path="gen"/>
5
5
  <classpathentry kind="src" path="assets"/>
6
+ <classpathentry kind="src" path="tests"/>
6
7
  <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
7
8
  <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
8
- <classpathentry kind="lib" path="libs/robotium-solo-3.3.jar"/>
9
+ <classpathentry kind="lib" path="libs/robotium-solo-3.6.jar"/>
9
10
  <classpathentry kind="output" path="bin/classes"/>
10
11
  </classpath>
@@ -0,0 +1,2 @@
1
+ #!/bin/bash
2
+ java -cp build-libs/antlr-3.4-complete.jar org.antlr.Tool antlr/UIQuery.g -o src/sh/calaba/instrumentationbackend/query
@@ -0,0 +1,70 @@
1
+ grammar UIQuery;
2
+ options {
3
+ output=AST;
4
+ ASTLabelType=CommonTree;
5
+ }
6
+
7
+
8
+ @header {
9
+ package sh.calaba.instrumentationbackend.query.antlr;
10
+ }
11
+ @lexer::header {
12
+ package sh.calaba.instrumentationbackend.query.antlr;
13
+ }
14
+
15
+
16
+ query : expr (WHITE! expr)*
17
+ ;
18
+
19
+
20
+ expr : (className | filter)
21
+ ;
22
+
23
+ className : (NAME^ | QUALIFIED_NAME^);
24
+
25
+ QUALIFIED_NAME : NAME ('.' NAME)+;
26
+
27
+ filter : NAME FILTER_COLON^ (INT | STRING | BOOL | NIL);
28
+
29
+ FILTER_COLON : ':'
30
+ ;
31
+
32
+
33
+ INT : '0'..'9'+
34
+ ;
35
+
36
+ BOOL : 'true' | 'false'
37
+ ;
38
+
39
+ NIL : 'nil' | 'null'
40
+ ;
41
+
42
+ NAME : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
43
+ ;
44
+
45
+ STRING
46
+ : '\'' ( ESC_SEQ | ~('\\'|'"') )* '\''
47
+ ;
48
+
49
+ WHITE : ' '* ;
50
+ fragment
51
+ HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ;
52
+
53
+ fragment
54
+ ESC_SEQ
55
+ : '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
56
+ | UNICODE_ESC
57
+ | OCTAL_ESC
58
+ ;
59
+
60
+ fragment
61
+ OCTAL_ESC
62
+ : '\\' ('0'..'3') ('0'..'7') ('0'..'7')
63
+ | '\\' ('0'..'7') ('0'..'7')
64
+ | '\\' ('0'..'7')
65
+ ;
66
+
67
+ fragment
68
+ UNICODE_ESC
69
+ : '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
70
+ ;
@@ -0,0 +1,12 @@
1
+ T__12=12
2
+ T__13=13
3
+ ESC_SEQ=4
4
+ HEX_DIGIT=5
5
+ ID=6
6
+ INT=7
7
+ OCTAL_ESC=8
8
+ STRING=9
9
+ UNICODE_ESC=10
10
+ WHITE=11
11
+ '.'=12
12
+ ':'=13
@@ -0,0 +1,56 @@
1
+ <project name="instrumentationbackend" basedir="." default="test">
2
+
3
+ <property name="src.dir" value="src"/>
4
+ <property name="test.dir" value="tests"/>
5
+
6
+ <property name="build.dir" value="build"/>
7
+ <property name="classes.dir" value="${build.dir}/classes"/>
8
+ <property name="jar.dir" value="${build.dir}/jar"/>
9
+
10
+
11
+ <property name="lib.dir" value="build-libs"/>
12
+
13
+ <path id="classpath">
14
+ <fileset dir="${lib.dir}" includes="**/*.jar"/>
15
+ </path>
16
+
17
+ <target name="clean">
18
+ <delete dir="${build.dir}"/>
19
+ </target>
20
+
21
+ <target name="compile">
22
+ <mkdir dir="${classes.dir}"/>
23
+ <javac
24
+ sourcepath=""
25
+ srcdir="${src.dir}"
26
+ classpathref="classpath"
27
+ includeantruntime="false"
28
+ destdir="${build.dir}" >
29
+ <include name="sh/calaba/instrumentationbackend/query/**/*.java"/>
30
+ <exclude name="sh/calaba/instrumentationbackend/query/*.java"/>
31
+ </javac>
32
+ </target>
33
+
34
+
35
+ <target name="test" depends="compile">
36
+ <javac
37
+ sourcepath=""
38
+ srcdir="${test.dir}"
39
+ classpathref="classpath"
40
+ includeantruntime="false"
41
+ destdir="${build.dir}" >
42
+ <include name="sh/calaba/instrumentationbackend/query/**/*.java"/>
43
+
44
+ </javac>
45
+ <junit showoutput="true" >
46
+ <classpath>
47
+ <path refid="classpath"/>
48
+ <pathelement location="${build.dir}"/>
49
+ </classpath>
50
+ <formatter type="plain" usefile="false" />
51
+ <batchtest fork="yes">
52
+ <fileset dir="${test.dir}" includes="**/*Test.java"/>
53
+ </batchtest>
54
+ </junit>
55
+ </target>
56
+ </project>
@@ -0,0 +1,78 @@
1
+ /*
2
+ [The "BSD license"]
3
+ Copyright (c) 2005-2009 Terence Parr
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions
8
+ are met:
9
+ 1. Redistributions of source code must retain the above copyright
10
+ notice, this list of conditions and the following disclaimer.
11
+ 2. Redistributions in binary form must reproduce the above copyright
12
+ notice, this list of conditions and the following disclaimer in the
13
+ documentation and/or other materials provided with the distribution.
14
+ 3. The name of the author may not be used to endorse or promote products
15
+ derived from this software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
+ IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ */
28
+ package org.antlr.runtime;
29
+
30
+ import java.io.*;
31
+
32
+ /** This is a char buffer stream that is loaded from a file
33
+ * all at once when you construct the object. This looks very
34
+ * much like an ANTLReader or ANTLRInputStream, but it's a special case
35
+ * since we know the exact size of the object to load. We can avoid lots
36
+ * of data copying.
37
+ */
38
+ public class ANTLRFileStream extends ANTLRStringStream {
39
+ protected String fileName;
40
+
41
+ public ANTLRFileStream(String fileName) throws IOException {
42
+ this(fileName, null);
43
+ }
44
+
45
+ public ANTLRFileStream(String fileName, String encoding) throws IOException {
46
+ this.fileName = fileName;
47
+ load(fileName, encoding);
48
+ }
49
+
50
+ public void load(String fileName, String encoding)
51
+ throws IOException
52
+ {
53
+ if ( fileName==null ) {
54
+ return;
55
+ }
56
+ File f = new File(fileName);
57
+ int size = (int)f.length();
58
+ InputStreamReader isr;
59
+ FileInputStream fis = new FileInputStream(fileName);
60
+ if ( encoding!=null ) {
61
+ isr = new InputStreamReader(fis, encoding);
62
+ }
63
+ else {
64
+ isr = new InputStreamReader(fis);
65
+ }
66
+ try {
67
+ data = new char[size];
68
+ super.n = isr.read(data);
69
+ }
70
+ finally {
71
+ isr.close();
72
+ }
73
+ }
74
+
75
+ public String getSourceName() {
76
+ return fileName;
77
+ }
78
+ }
@@ -0,0 +1,70 @@
1
+ /*
2
+ [The "BSD license"]
3
+ Copyright (c) 2005-2009 Terence Parr
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions
8
+ are met:
9
+ 1. Redistributions of source code must retain the above copyright
10
+ notice, this list of conditions and the following disclaimer.
11
+ 2. Redistributions in binary form must reproduce the above copyright
12
+ notice, this list of conditions and the following disclaimer in the
13
+ documentation and/or other materials provided with the distribution.
14
+ 3. The name of the author may not be used to endorse or promote products
15
+ derived from this software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
+ IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ */
28
+ package org.antlr.runtime;
29
+
30
+ import java.io.*;
31
+
32
+ /** A kind of ReaderStream that pulls from an InputStream.
33
+ * Useful for reading from stdin and specifying file encodings etc...
34
+ */
35
+ public class ANTLRInputStream extends ANTLRReaderStream {
36
+ public ANTLRInputStream() {
37
+ }
38
+
39
+ public ANTLRInputStream(InputStream input) throws IOException {
40
+ this(input, null);
41
+ }
42
+
43
+ public ANTLRInputStream(InputStream input, int size) throws IOException {
44
+ this(input, size, null);
45
+ }
46
+
47
+ public ANTLRInputStream(InputStream input, String encoding) throws IOException {
48
+ this(input, INITIAL_BUFFER_SIZE, encoding);
49
+ }
50
+
51
+ public ANTLRInputStream(InputStream input, int size, String encoding) throws IOException {
52
+ this(input, size, READ_BUFFER_SIZE, encoding);
53
+ }
54
+
55
+ public ANTLRInputStream(InputStream input,
56
+ int size,
57
+ int readBufferSize,
58
+ String encoding)
59
+ throws IOException
60
+ {
61
+ InputStreamReader isr;
62
+ if ( encoding!=null ) {
63
+ isr = new InputStreamReader(input, encoding);
64
+ }
65
+ else {
66
+ isr = new InputStreamReader(input);
67
+ }
68
+ load(isr, size, readBufferSize);
69
+ }
70
+ }