jlauncher 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2053dc8be4fa27e96da72d166e91aadca5b844411379f6a02b405e8460c549f
4
- data.tar.gz: 875802232d73a9f8cd00e4e04dc9b84bf20b363cc72b3cf1283539ce019db958
3
+ metadata.gz: 2f5d6f1b0fc056dde808d74d238cdbf91ca0f335341d884b2cad35f0925747a6
4
+ data.tar.gz: 5e221c1acf04898b192dbb5b94b92ee30e59913d1a273c5c95bdf702b66d6bde
5
5
  SHA512:
6
- metadata.gz: 9fbe5c05c3d98f56cf965efed5bc4a539f9f6cf9e125f2df6dcb0cbc3fc0c7d0d5cab7089c88923550c7d1f710ea7779e3d8cdcf6a4c36060f977c0b3660c16d
7
- data.tar.gz: a5caa48508b6d1d4ec7f8a8602bcb841401de95f4acec288c52b68c8efdd6f2791148be268131652a2f365b9bb71bb8eb93c281ae09ceb49f7cbe0030860cd75
6
+ metadata.gz: 160b96d74861c7cda6dbc325d0961157b413e51377659f529c7f677d7ec81f2873014f52f9d71d04f2925a95f62f880c86ae3a3872e2426009bb3a186dba92a5
7
+ data.tar.gz: 43ecb79b1872658b6f0201de4132085ec7c244fe4aa8f44220b4d35784fd78b5ba789f861851de41baec6e2000488eadd65f8540f35906d55612800eaa284d0b
@@ -18,7 +18,7 @@ GEM
18
18
  minitest (5.10.3)
19
19
  multi_xml (0.6.0)
20
20
  optimist (3.0.1)
21
- rake (10.5.0)
21
+ rake (13.0.1)
22
22
  rubyzip (2.3.0)
23
23
 
24
24
  PLATFORMS
@@ -28,7 +28,7 @@ DEPENDENCIES
28
28
  bundler (~> 1.16)
29
29
  jlauncher!
30
30
  minitest (~> 5.0)
31
- rake (~> 10.0)
31
+ rake (~> 13.0)
32
32
 
33
33
  BUNDLED WITH
34
34
  1.16.1
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- require 'j'
2
+ require 'jlauncher'
3
3
 
4
4
  JLauncher.do_it(ARGV)
@@ -1,7 +1,6 @@
1
-
2
1
  lib = File.expand_path("../lib", __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "j/version"
3
+ require "jlauncher/version"
5
4
 
6
5
  Gem::Specification.new do |spec|
7
6
  spec.name = "jlauncher"
@@ -11,7 +10,7 @@ Gem::Specification.new do |spec|
11
10
 
12
11
  spec.summary = %q{Launches jvm software from central repos}
13
12
  spec.description = %q{Uses fully resolved dependencies to get and start software from central repos}
14
- spec.homepage = "https://wuetender-junger-mann.de"
13
+ spec.homepage = "https://github.com/softwaretechnik-berlin/jlauncher"
15
14
  spec.license = "MIT"
16
15
 
17
16
 
@@ -23,10 +22,11 @@ Gem::Specification.new do |spec|
23
22
  spec.require_paths = ["lib"]
24
23
 
25
24
  spec.add_development_dependency "bundler", "~> 1.16"
26
- spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rake", "~> 13.0"
27
26
  spec.add_development_dependency "minitest", "~> 5.0"
28
27
 
29
28
  spec.add_dependency('optimist')
29
+ spec.add_dependency('colorize')
30
30
  spec.add_dependency('rubyzip')
31
31
  spec.add_dependency('httparty')
32
32
  end
@@ -0,0 +1,204 @@
1
+ require "jlauncher/version"
2
+ require 'zip'
3
+ require 'json'
4
+ require 'jlauncher/repos'
5
+ require 'jlauncher/common.rb'
6
+ require 'optimist'
7
+ require 'fileutils'
8
+ require 'colorize'
9
+
10
+ module JLauncher
11
+
12
+ def JLauncher.do_it(argv)
13
+ parser = Optimist::Parser.new
14
+ parser.stop_on_unknown
15
+ parser.stop_on %w(run install)
16
+ parser.version VERSION
17
+ parser.banner <<-EOS
18
+ Starts a jar with a j-manifest.json description fetching (and caching) all dependencies.
19
+
20
+ Usage:
21
+ .. j [options] <run|install> <jarfile|manifestfile|mavencoordinates> args...
22
+ where [options] are:
23
+ EOS
24
+ parser.opt :verbose, "Print debugging info to stderr"
25
+
26
+ begin
27
+ opts = parser.parse(argv)
28
+ rescue Optimist::CommandlineError => e
29
+ parser.die(e.message, nil, e.error_code)
30
+ rescue Optimist::HelpNeeded
31
+ parser.educate
32
+ exit
33
+ rescue Optimist::VersionNeeded
34
+ puts parser.version
35
+ exit
36
+ end
37
+
38
+ verbose = opts[:verbose]
39
+
40
+ remaining_args = parser.leftovers
41
+
42
+ subcommand = remaining_args.shift
43
+
44
+ start_coordinates = remaining_args.shift
45
+
46
+ program_args = remaining_args[0..-1]
47
+
48
+ resolver = Resolver.new(
49
+ MavenRepo.new(File.join(Dir.home, ".m2", "repository")),
50
+ IvyRepo.new(File.join(Dir.home, ".ivy2")),
51
+ MavenRemote.new("https://repo1.maven.org/maven2"),
52
+ verbose
53
+ )
54
+
55
+ full_config = if File.exist?(start_coordinates)
56
+ if (start_coordinates.end_with?(".jar"))
57
+ STDERR.puts("Starting local jar") if verbose
58
+
59
+ start_coordinates = File.expand_path(start_coordinates)
60
+
61
+ extra_class_path = "file:" + File.expand_path(start_coordinates)
62
+
63
+
64
+ manifest = read_manifest(start_coordinates)
65
+ FullConfig.new(manifest, extra_class_path)
66
+ else
67
+ STDERR.puts("Starting local manifest") if verbose
68
+
69
+ manifest = Manifest.new(JSON.parse(File.read(start_coordinates)))
70
+
71
+ extra_class_path = NIL
72
+ FullConfig.new(manifest, extra_class_path)
73
+ end
74
+ else
75
+ STDERR.puts("Starting from repo jar") if verbose
76
+
77
+ components = start_coordinates.split(":")
78
+ if components.length != 3
79
+ raise "'#{start_coordinates}' is not a valid coordinate use <groupId>:<artifactId>:<version>"
80
+ end
81
+
82
+ main_jar = resolver.get(Coordinates.new(start_coordinates))
83
+
84
+ manifest = read_manifest(main_jar)
85
+ extra_class_path = "maven:" + start_coordinates
86
+ FullConfig.new(manifest, extra_class_path)
87
+ end
88
+
89
+ if subcommand == "run"
90
+ launch_config = full_config.launch_config(resolver)
91
+
92
+ launch_config.run(program_args)
93
+ else
94
+ if subcommand == "install"
95
+ bin_dir = File.expand_path("~/.config/jlauncher/bin")
96
+ executable_path = bin_dir + "/" + (manifest.executable_name || "testme")
97
+ FileUtils.mkdir_p(bin_dir)
98
+ File.write(executable_path, <<~HEREDOC
99
+ #!/usr/bin/env bash
100
+
101
+ set -e
102
+ set -u
103
+ set -o pipefail
104
+
105
+ jlauncher run #{start_coordinates} "$@"
106
+ HEREDOC
107
+ )
108
+
109
+ File.chmod(0755, executable_path)
110
+ check_path(bin_dir)
111
+
112
+ STDERR.puts("'#{start_coordinates}' has been installed as #{manifest.executable_name.bold}.")
113
+ else
114
+ raise "'#{subcommand}' is not a valid subcommand."
115
+ end
116
+ end
117
+ end
118
+
119
+ def self.check_path(bin_dir)
120
+ path_entries = ENV['PATH'].split(":").map{|path| File.expand_path(path)}
121
+ if (!path_entries.include?(bin_dir))
122
+ STDERR.puts("Warning: The jlauncher binary path is not on the system path. You can add it to your .bashrc like so:".yellow)
123
+ STDERR.puts("export PATH=$PATH:#{bin_dir}\n\n")
124
+ end
125
+ end
126
+
127
+ def self.read_manifest(jarfile)
128
+ Zip::File.open(jarfile) do |zip_file|
129
+ entry = zip_file.glob('j-manifest.json').first
130
+ Manifest.new(JSON.parse(entry.get_input_stream.read))
131
+ end
132
+ end
133
+
134
+
135
+ # All the info that is needed to launch
136
+ class JvmLaunchConfig
137
+ def initialize(classpath_elements, main_class)
138
+
139
+ @main_class = main_class
140
+ @classpath_elements = classpath_elements
141
+ end
142
+
143
+ def run(args)
144
+ classpath = @classpath_elements.join(File::PATH_SEPARATOR)
145
+ exec("java", "-cp", "#{classpath}", "#{@main_class}", *args)
146
+ end
147
+ end
148
+
149
+
150
+ # The full configuration needed to start a program has a manifest
151
+ # plus an optional extra_class_path element, which contains either
152
+ # maven coordinates or a local file containing a jar
153
+ class FullConfig
154
+ def initialize(manifest, extra_class_path)
155
+ @manifest = manifest
156
+ @extra_class_path = extra_class_path
157
+
158
+ end
159
+
160
+ def launch_config(resolver)
161
+ class_path_from_manifest = @manifest.dependencies.map {
162
+ |c| resolver.get(c)
163
+ }
164
+
165
+ if @extra_class_path
166
+ split_index = @extra_class_path.index(":")
167
+ protocol = @extra_class_path[0..split_index - 1]
168
+ value = @extra_class_path[split_index + 1..-1]
169
+ extra_element = case protocol
170
+ when "file"
171
+ value
172
+ when "maven"
173
+ resolver.get(Coordinates.new(value))
174
+ end
175
+ class_path_from_manifest = class_path_from_manifest << extra_element
176
+ end
177
+
178
+ JvmLaunchConfig.new(
179
+ class_path_from_manifest,
180
+ @manifest.main_class
181
+ )
182
+ end
183
+ end
184
+
185
+
186
+ # A wrapper around the manifest file
187
+ class Manifest
188
+ def initialize(json_map)
189
+ @json_map = json_map
190
+ end
191
+
192
+ def dependencies
193
+ @json_map['dependencies'].map { |dep| Coordinates.new(dep) }
194
+ end
195
+
196
+ def main_class
197
+ @json_map['mainClass']
198
+ end
199
+
200
+ def executable_name
201
+ @json_map['executableName']
202
+ end
203
+ end
204
+ end
File without changes
File without changes
@@ -1,3 +1,3 @@
1
1
  module JLauncher
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jlauncher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix Leipold
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-19 00:00:00.000000000 Z
11
+ date: 2020-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '13.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: colorize
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'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rubyzip
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -99,7 +113,7 @@ description: Uses fully resolved dependencies to get and start software from cen
99
113
  email:
100
114
  - felix.leipold@gmail.com
101
115
  executables:
102
- - j
116
+ - jlauncher
103
117
  extensions: []
104
118
  extra_rdoc_files: []
105
119
  files:
@@ -109,14 +123,14 @@ files:
109
123
  - Rakefile
110
124
  - bin/console
111
125
  - bin/setup
112
- - exe/j
126
+ - exe/jlauncher
113
127
  - jlauncher.gemspec
114
- - lib/j.rb
115
- - lib/j/common.rb
116
- - lib/j/repos.rb
117
- - lib/j/version.rb
128
+ - lib/jlauncher.rb
129
+ - lib/jlauncher/common.rb
130
+ - lib/jlauncher/repos.rb
131
+ - lib/jlauncher/version.rb
118
132
  - test.rb
119
- homepage: https://wuetender-junger-mann.de
133
+ homepage: https://github.com/softwaretechnik-berlin/jlauncher
120
134
  licenses:
121
135
  - MIT
122
136
  metadata: {}
@@ -135,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
149
  - !ruby/object:Gem::Version
136
150
  version: '0'
137
151
  requirements: []
138
- rubygems_version: 3.1.2
152
+ rubygems_version: 3.1.4
139
153
  signing_key:
140
154
  specification_version: 4
141
155
  summary: Launches jvm software from central repos
data/lib/j.rb DELETED
@@ -1,125 +0,0 @@
1
- require "j/version"
2
- require 'zip'
3
- require 'json'
4
- require 'j/repos'
5
- require 'j/common.rb'
6
- require 'optimist'
7
-
8
- module JLauncher
9
-
10
- def JLauncher.do_it(argv)
11
- parser = Optimist::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|manifestfile|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 Optimist::CommandlineError => e
26
- parser.die(e.message, nil, e.error_code)
27
- rescue Optimist::HelpNeeded
28
- parser.educate
29
- exit
30
- rescue Optimist::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("https://repo1.maven.org/maven2"),
44
- verbose
45
- )
46
-
47
- start_info = if File.file?(start_param)
48
- if (start_param.end_with?(".jar"))
49
- STDERR.puts("Starting local jar") if verbose
50
-
51
- manifest = read_manifest(start_param)
52
-
53
- StartInfo.new(manifest.dependencies.map {|c| resolver.get(c)} << start_param, manifest.main_class)
54
- else
55
- STDERR.puts("Starting local manifest") if verbose
56
-
57
- manifest = Manifest.new(JSON.parse(File.read(start_param)))
58
-
59
- StartInfo.new(manifest.dependencies.map {|c| resolver.get(c)} << start_param, manifest.main_class)
60
- end
61
- else
62
- STDERR.puts("Starting from repo jar") if verbose
63
-
64
- components = start_param.split(":")
65
- if components.length != 3
66
- raise "'#{start_param}' is not a valid coordinate use <groupId>:<artifactId>:<version>"
67
- end
68
-
69
- main_jar = resolver.get(Coordinates.new({
70
- 'groupId' => components[0],
71
- 'artifactId' => components[1],
72
- 'version' => components[2]
73
- }))
74
-
75
- manifest = read_manifest(main_jar)
76
-
77
- StartInfo.new(manifest.dependencies.map {|c| resolver.get(c)} << main_jar, manifest.main_class)
78
- end
79
-
80
- start_info.run(program_args)
81
-
82
- classpath = classpath_elements.join(File::PATH_SEPARATOR)
83
- exec("java", "-cp", "#{classpath}", "#{manifest.main_class}")
84
- end
85
-
86
- def self.read_manifest(jarfile)
87
- Zip::File.open(jarfile) do |zip_file|
88
- entry = zip_file.glob('j-manifest.json').first
89
- Manifest.new(JSON.parse(entry.get_input_stream.read))
90
- end
91
- end
92
-
93
-
94
- # All the info that is needed to launch
95
- class StartInfo
96
- def initialize(classpath_elements, main_class)
97
-
98
- @main_class = main_class
99
- @classpath_elements = classpath_elements
100
- end
101
-
102
- def run(args)
103
- classpath = @classpath_elements.join(File::PATH_SEPARATOR)
104
- exec("java", "-cp", "#{classpath}", "#{@main_class}", *args)
105
- end
106
-
107
- end
108
-
109
-
110
- # A wrapper around the manifest file
111
- class Manifest
112
- def initialize(json_map)
113
- @json_map = json_map
114
- end
115
-
116
- def dependencies
117
- @json_map['dependencies'].map {|dep| Coordinates.new(dep)}
118
- end
119
-
120
- def main_class
121
- @json_map['mainClass']
122
- end
123
- end
124
-
125
- end