grump 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d87ae90a6f8938109360cb311c9d083c3a223ee6
4
+ data.tar.gz: 5ec504963512f48a41198670e8e35ce81cba753a
5
+ SHA512:
6
+ metadata.gz: 90a39344f6f150eed009c297d88aa38901aade23c343a7a267e3194ff499a4ad1752b355b52f22b19dc1338a600b5ac955c9a44b96192ef17e81d98c580bba6a
7
+ data.tar.gz: ab95c4fbf109a290c465efaeaff681e8c3f1cbdc45a85357cb49da52e4c3a7f9ee40fcec0a136c24e664d75d92a7f67c9c215e467e85bb72d2b14b8cd8d1ff8a
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## 0.0.1
2
+
3
+ * First released version
4
+ * Basic Maven compatible dependency handling
5
+ * Basic Java handling
data/Gemfile ADDED
@@ -0,0 +1 @@
1
+ source 'https://rubygems.org'
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Marek Jelen
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # Grump
2
+
3
+ Poor man's build system.
4
+
5
+ ## How does it work?
6
+
7
+ Create a `Grumpfile` and define your project. `Grumpfile`s are inherited from root (/) to current directory.
8
+
9
+ Run `grump (task name)` to invoke some logic. Tasks are defined in Grumpfiles. If no task name is specified "default" is used.
10
+
11
+ ## Grumpfile
12
+
13
+ ### plugin(name)
14
+
15
+ Loads plugin. Will require file "grump-#{name}" and will include it into current context. If "#{name}_plugin_setup"
16
+ method exists, invokes it.
17
+
18
+ ### task(name, &block)
19
+
20
+ If no block is given, execute task specified by name. If block is given, define new task identified by name.
21
+
22
+ ### var(name, value=nil)
23
+
24
+ If value is not nil, set value for name. When value is nil, return value for name.
25
+
26
+ ### directory(path)
27
+
28
+ Resolve directory relative to location of Grumpfile.
29
+
30
+ ## Example Grumpfile
31
+
32
+ ``ruby
33
+ plugin :maven
34
+
35
+ maven 'io.netty', 'netty-handler', '4.0.7.Final'
36
+ maven 'org.slf4j', 'slf4j-api', '1.7.5'
37
+ maven 'org.msgpack', 'msgpack', '0.6.7'
38
+
39
+ var(:pwd, directory('.'))
40
+
41
+ task('build') do
42
+ maven_download
43
+ java_build
44
+ end
45
+
46
+ task('package') do
47
+ task('build')
48
+ java_jar
49
+ java_package
50
+ end
51
+
52
+ task('default') do
53
+ task('build')
54
+ java_run
55
+ end
56
+
57
+ ``
58
+
59
+ ## Plugins
60
+
61
+ Plugin is a Module included into the context where Grumpfiles are resolved. Plugin defines methods, variables or anything
62
+ Grumpfile can define.
63
+
64
+ ## Why?
65
+
66
+ Because!
67
+
68
+ ## License
69
+
70
+ Check the LICENSE.md file.
71
+
data/ROADMAP.md ADDED
@@ -0,0 +1 @@
1
+ * whatever I will need
data/bin/grump ADDED
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+
4
+ $: << File.expand_path('../../lib', __FILE__)
5
+
6
+ require 'grump/plugin'
7
+
8
+ module Grump
9
+ class Application
10
+
11
+ def initialize
12
+ task('default') {}
13
+
14
+ segments = Dir.pwd.split('/')
15
+ path('')
16
+ segments.each do |dir|
17
+ path(File.join(path, dir))
18
+ file = File.join(path, 'Grumpfile')
19
+ if File.exist?(file)
20
+ eval(File.read(file))
21
+ end
22
+ end
23
+ end
24
+
25
+ def var(name, value=nil)
26
+ return (@vars ||= {})[name] unless value
27
+ (@vars ||= {})[name] = value
28
+ end
29
+
30
+ def path(path=nil)
31
+ return @path unless path
32
+ @path = path
33
+ end
34
+
35
+ def directory(path)
36
+ File.expand_path(path, @path)
37
+ end
38
+
39
+ def plugin(name)
40
+ require "grump-#{name}"
41
+ self.class.send(:include, Grump::Plugin.mod(name))
42
+ self.send("#{name}_plugin_setup".to_sym) if self.respond_to?("#{name}_plugin_setup")
43
+ end
44
+
45
+ def task(name, &block)
46
+ return (@tasks ||= {})[name.to_s].call unless block
47
+ (@tasks ||= {})[name.to_s] = block
48
+ end
49
+
50
+ def execute
51
+ task = (ARGV[0] || 'default')
52
+ instance_eval(&@tasks[task])
53
+ end
54
+
55
+ end
56
+ end
57
+
58
+ Grump::Application.new.execute
data/lib/grump-java.rb ADDED
@@ -0,0 +1,73 @@
1
+ module Grump
2
+ module Plugin
3
+ module Java
4
+
5
+ def java_plugin_setup
6
+ java_source('./src/main/java')
7
+ java_dist('./dist')
8
+ java_output('.grump/out')
9
+ java_libs('.grump/libs')
10
+ end
11
+
12
+ def java_source(path)
13
+ @java_source = File.expand_path(path, self.path)
14
+ end
15
+
16
+ def java_dist(path)
17
+ @java_dist = File.expand_path(path, self.path)
18
+ end
19
+
20
+ def java_output(path)
21
+ @java_output = File.expand_path(path, self.path)
22
+ end
23
+
24
+ def java_libs(path)
25
+ @java_libs = File.expand_path(path, self.path)
26
+ end
27
+
28
+ def java_main(clazz)
29
+ @java_main = clazz
30
+ end
31
+
32
+ def java_build
33
+ FileUtils.mkdir_p(@java_output)
34
+ cmd = "javac -d #{@java_output} -cp #{Dir.glob("#{@java_libs}/*.jar").join(':')} #{Dir.glob("#{@java_source}/**/*.java").join(' ')}"
35
+ `#{cmd}`
36
+ end
37
+
38
+ def java_run
39
+ libs = (Dir.glob("#{@java_libs}/*.jar") << @java_output).join(':')
40
+ Dir.chdir(var(:pwd))
41
+
42
+ cmd = "java -cp #{libs} #{@java_main}"
43
+
44
+ IO.popen (cmd) do |f|
45
+ begin
46
+ while (line = f.gets)
47
+ puts line
48
+ end
49
+ rescue => e
50
+ puts e.message
51
+ end
52
+ end
53
+ end
54
+
55
+ def java_jar
56
+ d = Dir.pwd
57
+ Dir.chdir(@java_output)
58
+ puts `jar cvf dist.jar #{Dir.glob('*').join(' ')}`
59
+ Dir.chdir(d)
60
+ end
61
+
62
+ def java_package
63
+ libs = File.join(@java_dist, 'libs')
64
+ FileUtils.mkdir_p(libs)
65
+ FileUtils.cp(Dir.glob(File.join(@java_libs, '*.jar')), libs)
66
+ FileUtils.mv(File.join(@java_output, 'dist.jar'), libs)
67
+ end
68
+
69
+ end
70
+ end
71
+
72
+ Plugin.register(:java, Plugin::Java)
73
+ end
@@ -0,0 +1,110 @@
1
+ require 'open-uri'
2
+ require "rexml/document"
3
+ require 'digest/md5'
4
+
5
+ module Grump
6
+ module Plugin
7
+ module Maven
8
+
9
+ def maven_plugin_setup
10
+ plugin(:java)
11
+ @temp = File.join(path, '.grump', 'temp')
12
+ end
13
+
14
+ def download(url)
15
+ FileUtils.mkdir_p(@temp)
16
+ d = Digest::MD5.hexdigest(url)
17
+ if File.exists?("#{@temp}/#{d}")
18
+ return File.read("#{@temp}/#{d}")
19
+ end
20
+ temp = nil
21
+ open(url) do |io|
22
+ temp = io.read
23
+ end
24
+ File.open("#{@temp}/#{d}", "w") do |file|
25
+ file.write(temp)
26
+ end
27
+ temp
28
+ end
29
+
30
+ def maven(*args)
31
+ (@maven ||= []) << args.join(':')
32
+ end
33
+
34
+ def maven_root
35
+ 'http://central.maven.org/maven2'
36
+ end
37
+
38
+ def maven_artifact(dependency)
39
+ group, artifact, version = dependency.split(':')
40
+ File.join(maven_root, group.gsub('.','/'), artifact, version, artifact + '-' + version)
41
+ end
42
+
43
+ def maven_pom(dependency)
44
+ maven_artifact(dependency) + '.pom'
45
+ end
46
+
47
+ def maven_jar(dependency)
48
+ maven_artifact(dependency) + '.jar'
49
+ end
50
+
51
+ def maven_latest(dependency)
52
+ group, artifact = dependency.split(':')
53
+ xml = download(File.join(maven_root, group.gsub('.','/'), artifact, 'maven-metadata.xml'))
54
+ xml = REXML::Document.new(xml)
55
+ (REXML::XPath.match(xml, '/metadata/versioning/latest').first || REXML::XPath.match(xml, '/metadata/version').first).text
56
+ end
57
+
58
+ def maven_subst(xml, str)
59
+ str.gsub(/\$\{([^\}]+)\}/) { |var| var = var.split('.').last; REXML::XPath.match(xml, "/project/parent/#{var}").first.text }
60
+ end
61
+
62
+ def maven_tree
63
+ @maven.each do |artifact|
64
+
65
+ xml = download(maven_pom(artifact))
66
+ xml = REXML::Document.new(xml)
67
+
68
+ REXML::XPath.match(xml, '/project/dependencies/dependency').each do |dependency|
69
+
70
+ next if dependency.elements['optional'] && dependency.elements['optional'].text == 'true'
71
+ next if dependency.elements['scope'] && dependency.elements['scope'].text == 'test'
72
+
73
+ group = dependency.elements['groupId'].text
74
+ group = maven_subst(xml, group)
75
+
76
+ artifact = dependency.elements['artifactId'].text
77
+ artifact = maven_subst(xml, artifact)
78
+
79
+ if dependency.elements['version']
80
+ version = dependency.elements['version'].text
81
+ version = maven_subst(xml, version)
82
+ else
83
+ version = maven_latest(group + ':' + artifact)
84
+ end
85
+
86
+ id = "#{group}:#{artifact}:#{version}"
87
+
88
+ unless @maven.include?(id)
89
+ maven(group, artifact, version)
90
+ end
91
+ end
92
+
93
+ end
94
+ @maven
95
+ end
96
+
97
+ def maven_download
98
+ FileUtils.mkdir_p(@java_libs)
99
+ maven_tree.each do |dependency|
100
+ jar = maven_jar(dependency)
101
+ file = File.join(@java_libs, File.basename(jar))
102
+ `curl -o #{file} #{jar}` unless File.exists?(file)
103
+ end
104
+ end
105
+
106
+ end
107
+ end
108
+ end
109
+
110
+ Grump::Plugin.register(:maven, Grump::Plugin::Maven)
@@ -0,0 +1,17 @@
1
+ module Grump
2
+ module Plugin
3
+
4
+ def self.register(name, mod)
5
+ mods[name.to_s] = mod
6
+ end
7
+
8
+ def self.mod(name)
9
+ mods[name.to_s]
10
+ end
11
+
12
+ def self.mods
13
+ @mods ||= {}
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module Grump
2
+ VERSION = '0.0.1' unless const_defined?(:VERSION)
3
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grump
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Marek Jelen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: '''cause I dislike XML, Gradle was pain in the *** and I had a grumpy
14
+ day'
15
+ email:
16
+ - marek@jelen.biz
17
+ executables:
18
+ - grump
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - bin/grump
23
+ - lib/grump/version.rb
24
+ - lib/grump/plugin.rb
25
+ - lib/grump-java.rb
26
+ - lib/grump-maven.rb
27
+ - LICENSE
28
+ - README.md
29
+ - ROADMAP.md
30
+ - CHANGELOG.md
31
+ - Gemfile
32
+ homepage: http://github.com/marekjelen/grump
33
+ licenses: []
34
+ metadata: {}
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubyforge_project:
51
+ rubygems_version: 2.0.3
52
+ signing_key:
53
+ specification_version: 4
54
+ summary: Poor mans build system
55
+ test_files: []