redcar-groovy 0.2
Sign up to get free protection for your applications and to get access to all the features.
- 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 +54 -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,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: redcar-groovy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.2'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Daniel Lucraft
|
9
|
+
- Delisa Mason
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2011-09-10 00:00:00.000000000 +01:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
description: ''
|
17
|
+
email:
|
18
|
+
- dan@fluentradical.com
|
19
|
+
executables: []
|
20
|
+
extensions: []
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- lib/groovy/commands.rb
|
24
|
+
- lib/groovy/repl_mirror.rb
|
25
|
+
- lib/groovy/syntax_checker.rb
|
26
|
+
- lib/groovy.rb
|
27
|
+
- plugin.rb
|
28
|
+
- groovy-all-1.7.4.jar
|
29
|
+
has_rdoc: true
|
30
|
+
homepage: http://github.com/danlucraft/redcar-groovy
|
31
|
+
licenses: []
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 1.6.2
|
51
|
+
signing_key:
|
52
|
+
specification_version: 3
|
53
|
+
summary: A Redcar plugin for Groovy development
|
54
|
+
test_files: []
|