redcar-groovy 0.1-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.
- data/groovy-all-1.7.4.jar +0 -0
- data/lib/groovy.rb +38 -0
- data/lib/groovy/commands.rb +10 -0
- data/lib/groovy/repl_mirror.rb +85 -0
- data/lib/groovy/syntax_checker.rb +81 -0
- data/plugin.rb +8 -0
- metadata +63 -0
Binary file
|
data/lib/groovy.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
require 'groovy/commands'
|
3
|
+
require 'groovy/repl_mirror'
|
4
|
+
require 'groovy/syntax_checker'
|
5
|
+
|
6
|
+
module Redcar
|
7
|
+
class Groovy
|
8
|
+
|
9
|
+
def self.load_dependencies
|
10
|
+
unless @loaded
|
11
|
+
require File.expand_path("../../groovy-all-1.7.4", __FILE__)
|
12
|
+
@loaded = true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.menus
|
17
|
+
Redcar::Menu::Builder.build do
|
18
|
+
sub_menu "Plugins" do
|
19
|
+
sub_menu "REPL" do
|
20
|
+
item "Open Groovy REPL", OpenGroovyREPL
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.keymaps
|
27
|
+
osx = Keymap.build("main", :osx) do
|
28
|
+
link "Cmd+Alt+G", OpenGroovyREPL
|
29
|
+
end
|
30
|
+
|
31
|
+
linwin = Keymap.build("main", [:linux, :windows]) do
|
32
|
+
link "Ctrl+Alt+G", OpenGroovyREPL
|
33
|
+
end
|
34
|
+
|
35
|
+
[linwin, osx]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
|
2
|
+
require 'java'
|
3
|
+
|
4
|
+
module Redcar
|
5
|
+
class Groovy
|
6
|
+
class ReplMirror < Redcar::REPL::ReplMirror
|
7
|
+
def title
|
8
|
+
"Groovy REPL"
|
9
|
+
end
|
10
|
+
|
11
|
+
def grammar_name
|
12
|
+
"Groovy REPL"
|
13
|
+
end
|
14
|
+
|
15
|
+
def prompt
|
16
|
+
"groovy>"
|
17
|
+
end
|
18
|
+
|
19
|
+
def evaluator
|
20
|
+
@instance ||= ReplMirror::Evaluator.new
|
21
|
+
end
|
22
|
+
|
23
|
+
def format_error(e)
|
24
|
+
backtrace = e.backtrace
|
25
|
+
"ERROR #{e.class}:\n #{e.message}\n #{backtrace.join("\n ")}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def help
|
29
|
+
h = super
|
30
|
+
h << """
|
31
|
+
Note on Groovy Script Scoping:
|
32
|
+
Classes, undefined variables, and undefined closures are saved in the script
|
33
|
+
binding between statements.
|
34
|
+
Defined methods, closures, and variables are not added to the binding,
|
35
|
+
because they are considered local variables and thus are not available after
|
36
|
+
the defining statement.
|
37
|
+
|
38
|
+
Example:
|
39
|
+
|
40
|
+
def foo = 'hello! I am a local variable'
|
41
|
+
foo = 'hi! I am a binding variable'
|
42
|
+
|
43
|
+
See 'http://groovy.codehaus.org/Scoping+and+the+Semantics+of+%22def%22'
|
44
|
+
for more information.
|
45
|
+
"""
|
46
|
+
end
|
47
|
+
|
48
|
+
class Evaluator
|
49
|
+
def self.load_dependencies
|
50
|
+
unless @loaded
|
51
|
+
Groovy.load_dependencies
|
52
|
+
import 'groovy.lang.GroovyShell'
|
53
|
+
import 'java.io.PrintWriter'
|
54
|
+
import 'java.io.StringWriter'
|
55
|
+
@loaded = true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def initialize
|
60
|
+
Evaluator.load_dependencies
|
61
|
+
@out = StringWriter.new
|
62
|
+
@shell = GroovyShell.new
|
63
|
+
@shell.setProperty('out',@out)
|
64
|
+
end
|
65
|
+
|
66
|
+
def inspect
|
67
|
+
"groovyREPL main"
|
68
|
+
end
|
69
|
+
|
70
|
+
def execute(cmd)
|
71
|
+
output = @shell.evaluate(cmd,"GroovyREPL").to_s
|
72
|
+
output = "null" unless output and not output.empty?
|
73
|
+
if @out and not @out.toString().empty?
|
74
|
+
console = @out.toString() + "\n"
|
75
|
+
else
|
76
|
+
console = ""
|
77
|
+
end
|
78
|
+
buf = @out.getBuffer()
|
79
|
+
buf.delete(0,buf.length()) if buf.length() > 0
|
80
|
+
console + "===> #{output}"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
|
2
|
+
require 'java'
|
3
|
+
|
4
|
+
module Redcar
|
5
|
+
class Groovy
|
6
|
+
class SyntaxChecker < Redcar::SyntaxCheck::Checker
|
7
|
+
supported_grammars "Groovy", "Easyb"
|
8
|
+
|
9
|
+
def self.load_dependencies
|
10
|
+
unless @loaded
|
11
|
+
Groovy.load_dependencies
|
12
|
+
import 'groovy.lang.GroovyShell'
|
13
|
+
import 'org.codehaus.groovy.control.CompilationFailedException'
|
14
|
+
import 'org.codehaus.groovy.control.CompilerConfiguration'
|
15
|
+
@loaded = true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(document)
|
20
|
+
super
|
21
|
+
SyntaxChecker.load_dependencies
|
22
|
+
end
|
23
|
+
|
24
|
+
def check(*args)
|
25
|
+
path = manifest_path(doc)
|
26
|
+
name = File.basename(path)
|
27
|
+
shell = create_shell
|
28
|
+
text = doc.get_all_text
|
29
|
+
io = java.io.File.new(path)
|
30
|
+
begin
|
31
|
+
shell.parse(io)
|
32
|
+
rescue CompilationFailedException => e
|
33
|
+
create_syntax_error(doc, e.message, name).annotate
|
34
|
+
rescue Object => e
|
35
|
+
Redcar::SyntaxCheck.message(
|
36
|
+
"An error occurred while parsing #{name}: #{e.message}",:error)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def create_syntax_error(doc, message, name)
|
41
|
+
message =~ /#{Regexp.escape(name)}: (\d+):(.*)/
|
42
|
+
line = $1.to_i - 1
|
43
|
+
message = $2
|
44
|
+
Redcar::SyntaxCheck::Error.new(doc, line, message)
|
45
|
+
end
|
46
|
+
|
47
|
+
def classpath_files(project)
|
48
|
+
project.config_files("classpath.groovy")
|
49
|
+
end
|
50
|
+
|
51
|
+
def classpath(project)
|
52
|
+
parts = []
|
53
|
+
shell = GroovyShell.new
|
54
|
+
files = classpath_files(project)
|
55
|
+
return unless files.any?
|
56
|
+
files.each do |path|
|
57
|
+
begin
|
58
|
+
file = java.io.File.new(path)
|
59
|
+
part = shell.run(file, [])
|
60
|
+
parts += part if part
|
61
|
+
rescue Object => e
|
62
|
+
Redcar::SyntaxCheck.message(
|
63
|
+
"An error occurred while loading groovy classpath file #{path}: #{e.message}",:error)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
parts
|
67
|
+
end
|
68
|
+
|
69
|
+
def create_shell
|
70
|
+
config = CompilerConfiguration.new
|
71
|
+
if project = Redcar::Project::Manager.focussed_project
|
72
|
+
classpath = classpath(project)
|
73
|
+
config.setClasspathList(classpath) if classpath and classpath.any?
|
74
|
+
end
|
75
|
+
shell = GroovyShell.new(config)
|
76
|
+
shell.setProperty("out",nil)
|
77
|
+
shell
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/plugin.rb
ADDED
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: redcar-groovy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: "0.1"
|
6
|
+
platform: java
|
7
|
+
authors:
|
8
|
+
- Daniel Lucraft
|
9
|
+
- Delisa Mason
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
|
14
|
+
date: 2011-07-24 00:00:00 +01:00
|
15
|
+
default_executable:
|
16
|
+
dependencies: []
|
17
|
+
|
18
|
+
description: ""
|
19
|
+
email:
|
20
|
+
- dan@fluentradical.com
|
21
|
+
executables: []
|
22
|
+
|
23
|
+
extensions: []
|
24
|
+
|
25
|
+
extra_rdoc_files: []
|
26
|
+
|
27
|
+
files:
|
28
|
+
- lib/groovy.rb
|
29
|
+
- lib/groovy/commands.rb
|
30
|
+
- lib/groovy/repl_mirror.rb
|
31
|
+
- lib/groovy/syntax_checker.rb
|
32
|
+
- plugin.rb
|
33
|
+
- groovy-all-1.7.4.jar
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: http://github.com/danlucraft/redcar-groovy
|
36
|
+
licenses: []
|
37
|
+
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
requirements: []
|
56
|
+
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 1.5.1
|
59
|
+
signing_key:
|
60
|
+
specification_version: 3
|
61
|
+
summary: A Redcar plugin for Groovy development
|
62
|
+
test_files: []
|
63
|
+
|