jlauncher 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e4bfab07d4162372333f02f6c63e7ff5eccb0d92
4
+ data.tar.gz: 70938c7ca84203978409c77a5834c68892dac040
5
+ SHA512:
6
+ metadata.gz: 35c084a53a1d21e59dba6746301fad4478e780de0133a9f850157bd1017bf7aef3c932a740f1b6c498ef98f91a45280018a527a3a28f4dc1bed0e0b354f1a32b
7
+ data.tar.gz: 11f377d89b730bd0acad41c59c01d1becfda021c17a210642d7816f4449730f3c3ff316c317e14ec09984f1cdb7124d66973bddc4e43b81837e3a00bb8670a84
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.3
5
+ before_install: gem install bundler -v 1.16.0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in j.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ jlauncher (0.1.0)
5
+ rubyzip
6
+ trollop
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ minitest (5.10.3)
12
+ rake (10.5.0)
13
+ rubyzip (1.2.1)
14
+ trollop (2.1.2)
15
+
16
+ PLATFORMS
17
+ ruby
18
+
19
+ DEPENDENCIES
20
+ bundler (~> 1.16)
21
+ jlauncher!
22
+ minitest (~> 5.0)
23
+ rake (~> 10.0)
24
+
25
+ BUNDLED WITH
26
+ 1.16.0
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Felix Leipold
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # J
2
+
3
+ ## Usage
4
+
5
+ Launch a jar that has a `j-manifest.json` from a local path:
6
+
7
+
8
+ ~~~ .bash
9
+ $ j path-to-my-jar
10
+ ~~~
11
+
12
+ Launching a jar via maven infrastructure:
13
+
14
+ ~~~ .bash
15
+ $ j org.my:myjar:1.0.0
16
+ ~~~
17
+
18
+ TODO: Deploy a test jar to maven central
19
+
20
+ ## Development
21
+
22
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
23
+
24
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
25
+
26
+ ## Contributing
27
+
28
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/j.
29
+
30
+ ## License
31
+
32
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "j"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/j ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require 'trollop'
3
+ require 'j'
4
+
5
+ JLauncher.do_it(ARGV)
data/jlauncher.gemspec ADDED
@@ -0,0 +1,32 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "j/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jlauncher"
8
+ spec.version = JLauncher::VERSION
9
+ spec.authors = ["Felix Leipold"]
10
+ spec.email = ["felix.leipold@gmail.com"]
11
+
12
+ spec.summary = %q{Starts jvm software from central repos}
13
+ spec.description = %q{Uses fully resolved dependencies to get and start software from central repos}
14
+ spec.homepage = "https://wuetender-junger-mann.de"
15
+ spec.license = "MIT"
16
+
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.16"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "minitest", "~> 5.0"
28
+
29
+ spec.add_dependency('trollop')
30
+ spec.add_dependency('rubyzip')
31
+ spec.add_dependency('httparty')
32
+ end
data/lib/j.rb ADDED
@@ -0,0 +1,117 @@
1
+ require "j/version"
2
+ require 'zip'
3
+ require 'json'
4
+ require 'j/repos'
5
+ require 'j/common.rb'
6
+ require 'trollop'
7
+
8
+ module JLauncher
9
+
10
+ def JLauncher.do_it(argv)
11
+ parser = Trollop::Parser.new
12
+ parser.stop_on_unknown
13
+ parser.version VERSION
14
+ parser.banner <<-EOS
15
+ Starts a jar with a j-manifest.json description fetching (and caching) all dependencies.
16
+
17
+ Usage:
18
+ .. j [options] <jarfile|mavencoordinates> args...
19
+ where [options] are:
20
+ EOS
21
+ parser.opt :verbose, "Print debugging info to stderr"
22
+
23
+ begin
24
+ opts = parser.parse(argv)
25
+ rescue Trollop::CommandlineError => e
26
+ parser.die(e.message, nil, e.error_code)
27
+ rescue Trollop::HelpNeeded
28
+ parser.educate
29
+ exit
30
+ rescue Trollop::VersionNeeded
31
+ puts parser.version
32
+ exit
33
+ end
34
+
35
+ verbose = opts[:verbose]
36
+ remaining_args = parser.leftovers
37
+ start_param = remaining_args[0]
38
+ program_args = remaining_args[1..-1]
39
+
40
+ resolver = Resolver.new(
41
+ MavenRepo.new(File.join(Dir.home, ".m2", "repository")),
42
+ IvyRepo.new(File.join(Dir.home, ".ivy2")),
43
+ MavenRemote.new("http://central.maven.org/maven2"),
44
+ verbose
45
+ )
46
+
47
+ start_info = if File.file?(start_param)
48
+ STDERR.puts("Starting local jar") if verbose
49
+
50
+ manifest = read_manifest(start_param)
51
+
52
+ StartInfo.new(manifest.dependencies.map {|c| resolver.get(c)} << start_param, manifest.main_class)
53
+ else
54
+ STDERR.puts("Starting from repo jar") if verbose
55
+
56
+ components = start_param.split(":")
57
+ if components.length != 3
58
+ raise "'#{start_param}' is not a valid coordinate use <groupId>:<artifactId>:<version>"
59
+ end
60
+
61
+ main_jar = resolver.get(Coordinates.new({
62
+ 'groupId' => components[0],
63
+ 'artifactId' => components[1],
64
+ 'version' => components[2]
65
+ }))
66
+
67
+ manifest = read_manifest(main_jar)
68
+
69
+ StartInfo.new(manifest.dependencies.map {|c| resolver.get(c)} << main_jar, manifest.main_class)
70
+ end
71
+
72
+ start_info.run(program_args)
73
+
74
+ classpath = classpath_elements.join(File::PATH_SEPARATOR)
75
+ exec("java", "-cp", "#{classpath}", "#{manifest.main_class}")
76
+ end
77
+
78
+ def self.read_manifest(jarfile)
79
+ Zip::File.open(jarfile) do |zip_file|
80
+ entry = zip_file.glob('j-manifest.json').first
81
+ Manifest.new(JSON.parse(entry.get_input_stream.read))
82
+ end
83
+ end
84
+
85
+
86
+ # All the info that is needed to launch
87
+ class StartInfo
88
+ def initialize(classpath_elements, main_class)
89
+
90
+ @main_class = main_class
91
+ @classpath_elements = classpath_elements
92
+ end
93
+
94
+ def run(args)
95
+ classpath = @classpath_elements.join(File::PATH_SEPARATOR)
96
+ exec("java", "-cp", "#{classpath}", "#{@main_class}", *args)
97
+ end
98
+
99
+ end
100
+
101
+
102
+ # A wrapper around the manifest file
103
+ class Manifest
104
+ def initialize(json_map)
105
+ @json_map = json_map
106
+ end
107
+
108
+ def dependencies
109
+ @json_map['dependencies'].map {|dep| Coordinates.new(dep)}
110
+ end
111
+
112
+ def main_class
113
+ @json_map['mainClass']
114
+ end
115
+ end
116
+
117
+ end
data/lib/j/common.rb ADDED
@@ -0,0 +1,39 @@
1
+ class Coordinates
2
+
3
+ def initialize(coords)
4
+ if coords.is_a? Hash
5
+ @group_id = coords['groupId']
6
+ @artifact_id = coords['artifactId']
7
+ @version = coords['version']
8
+ return
9
+ end
10
+ if coords.is_a? String
11
+ components = coords.split(":")
12
+ @group_id = components[0]
13
+ @artifact_id = components[1]
14
+ @version = components[2]
15
+ return
16
+ end
17
+
18
+ raise "Could not parse coordinates " + coords.to_s
19
+
20
+
21
+ end
22
+
23
+ def to_s
24
+ @group_id + ":" + @artifact_id + ":" + @version
25
+ end
26
+
27
+ def local_maven_path
28
+ File.join(@group_id.split("."), @artifact_id, @version, @artifact_id + "-" + @version + ".jar")
29
+ end
30
+
31
+ def local_ivy_path
32
+ File.join(@group_id, @artifact_id, "jars", @artifact_id + "-" + @version + ".jar")
33
+ end
34
+
35
+ def relative_url
36
+ @group_id.split(".").join("/") + "/" + @artifact_id + "/" + @version + "/" + @artifact_id + "-" + @version + ".jar"
37
+
38
+ end
39
+ end
data/lib/j/repos.rb ADDED
@@ -0,0 +1,93 @@
1
+ require 'httparty'
2
+
3
+ class Resolver
4
+ def initialize(local_maven_repo, local_ivy_repo, remote, verbose)
5
+
6
+ @local_maven_repo = local_maven_repo
7
+ @local_ivy_repo = local_ivy_repo
8
+ @remote = remote
9
+ @verbose = verbose
10
+ end
11
+
12
+ def get(coordinates)
13
+ path = @local_maven_repo.local_path(coordinates)
14
+
15
+ if File.exists?(path)
16
+ STDERR.puts("'#{coordinates}' found in local maven repo at #{path}") if @verbose
17
+ return path
18
+ end
19
+
20
+ path = @local_ivy_repo.local_path(coordinates)
21
+ if File.exists?(path)
22
+ STDERR.puts("'#{coordinates}' found in local ivy repo at #{path}") if @verbose
23
+ return path
24
+ end
25
+
26
+ path = @local_ivy_repo.cache_path(coordinates)
27
+ if File.exists?(path)
28
+ STDERR.puts("'#{coordinates}' found in ivy cache at #{path}") if @verbose
29
+ return path
30
+ end
31
+
32
+ STDERR.puts "'#{coordinates} not found in cache, trying to get them from remote..." if @verbose
33
+
34
+ FileUtils.makedirs(File.dirname(path))
35
+ content = @remote.get(coordinates)
36
+
37
+ open(path, "wb") do |file|
38
+ file.write(content)
39
+ end
40
+ path
41
+ end
42
+
43
+ end
44
+
45
+ class MavenRepo
46
+ def initialize(path)
47
+ @path = path
48
+ end
49
+
50
+ # for now we only support going for jars, thus no type or classifier or even platform here
51
+ # (to be honest mostly the latter may be interesting for us)
52
+ def local_path(coordinates)
53
+ File.join(@path, coordinates.local_maven_path)
54
+ end
55
+ end
56
+
57
+ class IvyRepo
58
+ def initialize(path)
59
+ @path = path
60
+ end
61
+
62
+ # for now we only support going for jars, thus no type or classifier or even platform here
63
+ # (to be honest mostly the latter may be interesting for us)
64
+ def local_path(coordinates)
65
+ File.join(@path,"local", coordinates.local_ivy_path)
66
+ end
67
+
68
+ # for now we only support going for jars, thus no type or classifier or even platform here
69
+ # (to be honest mostly the latter may be interesting for us)
70
+ def cache_path(coordinates)
71
+ File.join(@path, "cache", coordinates.local_ivy_path)
72
+ end
73
+
74
+ end
75
+
76
+
77
+ class MavenRemote
78
+ def initialize(url)
79
+ @url = url
80
+ end
81
+
82
+ def get(coordinates)
83
+ uri = URI(@url + "/" + coordinates.relative_url)
84
+
85
+ response = HTTParty.get(uri)
86
+
87
+ if response.code != 200
88
+ raise "Error getting #{uri} response code #{response.code}"
89
+ end
90
+
91
+ response.body
92
+ end
93
+ end
data/lib/j/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module JLauncher
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jlauncher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Felix Leipold
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: trollop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubyzip
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: httparty
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Uses fully resolved dependencies to get and start software from central
98
+ repos
99
+ email:
100
+ - felix.leipold@gmail.com
101
+ executables:
102
+ - j
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/setup
115
+ - exe/j
116
+ - jlauncher.gemspec
117
+ - lib/j.rb
118
+ - lib/j/common.rb
119
+ - lib/j/repos.rb
120
+ - lib/j/version.rb
121
+ homepage: https://wuetender-junger-mann.de
122
+ licenses:
123
+ - MIT
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.4.5.1
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: Starts jvm software from central repos
145
+ test_files: []