mirah 0.1.1-java → 0.1.2-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,146 +0,0 @@
1
- # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2
- # All contributing project authors may be found in the NOTICE file.
3
- #
4
- # Licensed under the Apache License, Version 2.0 (the "License");
5
- # you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS,
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- # See the License for the specific language governing permissions and
14
- # limitations under the License.
15
-
16
- require 'mirah/jvm/compiler'
17
- require 'mirah/util/logging'
18
-
19
- module Mirah
20
- module Util
21
-
22
- class ArgumentProcessor
23
- def initialize(state, args)
24
- @state = state
25
- @args = args
26
- end
27
-
28
- attr_accessor :state, :args, :exit_status_code
29
-
30
- alias exit? exit_status_code
31
-
32
- def process
33
- state.args = args
34
- while args.length > 0 && args[0] =~ /^-/
35
- case args[0]
36
- when '--classpath', '-c'
37
- args.shift
38
- state.classpath = args.shift
39
- when '--bootclasspath'
40
- args.shift
41
- state.bootclasspath = args.shift
42
- when '--cd'
43
- args.shift
44
- Dir.chdir(args.shift)
45
- when '--dest', '-d'
46
- args.shift
47
- state.destination = File.join(File.expand_path(args.shift), '')
48
- when '-e'
49
- break
50
- when '--explicit-packages'
51
- args.shift
52
- Mirah::AST::Script.explicit_packages = true
53
- when '--help', '-h'
54
- args.shift
55
- print_help
56
-
57
- self.exit_status_code = 0
58
- break
59
- when '--jvm'
60
- args.shift
61
- state.set_jvm_version(args.shift)
62
- when '-I'
63
- args.shift
64
- $: << args.shift
65
- when '--plugin', '-p'
66
- args.shift
67
- plugin = args.shift
68
- require "mirah/plugin/#{plugin}"
69
- when '--verbose', '-V'
70
- Mirah::Logging::MirahLogger.level = Mirah::Logging::Level::FINE
71
- state.verbose = true
72
- args.shift
73
- when '--vmodule'
74
- args.shift
75
- spec = args.shift
76
- spec.split(',').each do |item|
77
- logger, level = item.split("=")
78
- logger = java.util.logging.Logger.getLogger(logger)
79
- (state.loggers ||= []) << logger
80
- level = java.util.logging.Level.parse(level)
81
- logger.setLevel(level)
82
- end
83
- when '--no-color'
84
- args.shift
85
- Mirah::Logging::MirahHandler.formatter = Mirah::Logging::LogFormatter.new(false)
86
- when '--version', '-v'
87
- args.shift
88
- print_version
89
-
90
- self.exit_status_code = 0 if args.empty?
91
- break
92
- when '--no-save-extensions'
93
- args.shift
94
- state.save_extensions = false
95
- when '--new-backend', '-N'
96
- args.shift
97
- state.compiler_class = Mirah::JVM::Compiler::Backend
98
- when '--new-types', '-T'
99
- args.shift
100
- java_import 'org.mirah.jvm.mirrors.MirrorTypeSystem'
101
- state.type_system = MirrorTypeSystem.new
102
- else
103
- $stderr.puts "unrecognized flag: " + args[0]
104
-
105
- self.exit_status_code = 1
106
- break
107
- end
108
- end
109
-
110
- return if exit?
111
-
112
- state.destination ||= File.join(File.expand_path('.'), '')
113
- state.compiler_class ||= Mirah::JVM::Compiler::JVMBytecode
114
- end
115
-
116
- def print_help
117
- puts help_message
118
- state.help_printed = true
119
- end
120
-
121
- def help_message
122
- "#{$0} [flags] <files or -e SCRIPT>
123
- -c, --classpath PATH\tAdd PATH to the Java classpath for compilation
124
- --bootclasspath PATH\tSet the Java bootclasspath to PATH for compilation
125
- --cd DIR\t\tSwitch to the specified DIR before compilation
126
- -d, --dest DIR\t\tUse DIR as the dir to place the resulting .class files
127
- -e CODE\t\tCompile or run the inline script following -e
128
- \t\t\t (the class will be named \"DashE\")
129
- --explicit-packages\tRequire explicit 'package' lines in source
130
- -h, --help\t\tPrint this help message
131
- -I DIR\t\tAdd DIR to the Ruby load path before running
132
- --jvm VERSION\t\tEmit JVM bytecode targeting specified JVM
133
- \t\t\t version (1.4, 1.5, 1.6, 1.7)
134
- -p, --plugin PLUGIN\trequire 'mirah/plugin/PLUGIN' before running
135
- -v, --version\t\tPrint the version of Mirah to the console
136
- -V, --verbose\t\tVerbose logging
137
- --vmodule logger.name=LEVEL[,...]\t\tSet the Level for the specified Java loggers"
138
- end
139
-
140
- def print_version
141
- puts "Mirah v#{Mirah::VERSION}"
142
- state.version_printed = true
143
- end
144
- end
145
- end
146
- end