jlauncher 0.4.0 → 0.5.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: 2f5d6f1b0fc056dde808d74d238cdbf91ca0f335341d884b2cad35f0925747a6
4
- data.tar.gz: 5e221c1acf04898b192dbb5b94b92ee30e59913d1a273c5c95bdf702b66d6bde
3
+ metadata.gz: 3e2c517f35ed329bfd9c4914ce46c9cb73b9acf41997f20bba71a6ad38c1919b
4
+ data.tar.gz: 9a07409710858691cb51d53d4d3559f2682a7576bbf98000159dc0f9d8e6d3cc
5
5
  SHA512:
6
- metadata.gz: 160b96d74861c7cda6dbc325d0961157b413e51377659f529c7f677d7ec81f2873014f52f9d71d04f2925a95f62f880c86ae3a3872e2426009bb3a186dba92a5
7
- data.tar.gz: 43ecb79b1872658b6f0201de4132085ec7c244fe4aa8f44220b4d35784fd78b5ba789f861851de41baec6e2000488eadd65f8540f35906d55612800eaa284d0b
6
+ metadata.gz: fba8f573953cbe2f396408f4de14d92d477420d35a51e9ba88f6c024f3d2b4c4ad3c8cfe883b65660f04c6854f02261455a4e779219682352eb43c0f6f1e3d9f
7
+ data.tar.gz: 800674218c910be02e8410e6d3ac24169b23652b91762a1d32dc7541ed1413c789dadfb5f6ea034f528b3dfc4678f8cf70f2e337b66e36e1420e250aff78727d
@@ -10,40 +10,37 @@ require 'colorize'
10
10
  module JLauncher
11
11
 
12
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
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
18
  Starts a jar with a j-manifest.json description fetching (and caching) all dependencies.
19
19
 
20
20
  Usage:
21
21
  .. j [options] <run|install> <jarfile|manifestfile|mavencoordinates> args...
22
22
  where [options] are:
23
23
  EOS
24
- parser.opt :verbose, "Print debugging info to stderr"
24
+ parser.opt :verbose, "Print debugging info to stderr"
25
25
 
26
26
  begin
27
- opts = parser.parse(argv)
27
+ opts =parser.parse(argv)
28
28
  rescue Optimist::CommandlineError => e
29
- parser.die(e.message, nil, e.error_code)
29
+ parser.die(e.message, nil, e.error_code)
30
30
  rescue Optimist::HelpNeeded
31
- parser.educate
31
+ parser.educate
32
32
  exit
33
33
  rescue Optimist::VersionNeeded
34
- puts parser.version
34
+ putsparser.version
35
35
  exit
36
36
  end
37
37
 
38
38
  verbose = opts[:verbose]
39
39
 
40
- remaining_args = parser.leftovers
40
+ remaining_args =parser.leftovers
41
41
 
42
42
  subcommand = remaining_args.shift
43
43
 
44
- start_coordinates = remaining_args.shift
45
-
46
- program_args = remaining_args[0..-1]
47
44
 
48
45
  resolver = Resolver.new(
49
46
  MavenRepo.new(File.join(Dir.home, ".m2", "repository")),
@@ -52,64 +49,60 @@ where [options] are:
52
49
  verbose
53
50
  )
54
51
 
55
- full_config = if File.exist?(start_coordinates)
56
- if (start_coordinates.end_with?(".jar"))
57
- STDERR.puts("Starting local jar") if verbose
58
52
 
59
- start_coordinates = File.expand_path(start_coordinates)
60
53
 
61
- extra_class_path = "file:" + File.expand_path(start_coordinates)
54
+ if subcommand == "run"
55
+ start_coordinates = remaining_args.shift
62
56
 
57
+ full_config = resolve_full_config(resolver, start_coordinates, verbose)
63
58
 
64
- manifest = read_manifest(start_coordinates)
65
- FullConfig.new(manifest, extra_class_path)
66
- else
67
- STDERR.puts("Starting local manifest") if verbose
59
+ program_args = remaining_args[0..-1]
68
60
 
69
- manifest = Manifest.new(JSON.parse(File.read(start_coordinates)))
61
+ launch_config = full_config.launch_config(resolver)
70
62
 
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
63
+ launch_config.run(program_args)
64
+ else
65
+ if subcommand == "install"
66
+ subcommand_parser = Optimist::Parser.new
67
+ subcommand_parser.opt :executable_name, "Name of the executable script.", :type => :string
76
68
 
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
69
+ begin
70
+ opts = subcommand_parser.parse(remaining_args)
71
+ rescue Optimist::HelpNeeded
72
+ subcommand_parser.educate
73
+ exit
74
+ end
81
75
 
82
- main_jar = resolver.get(Coordinates.new(start_coordinates))
76
+ start_coordinates = subcommand_parser.leftovers.first
83
77
 
84
- manifest = read_manifest(main_jar)
85
- extra_class_path = "maven:" + start_coordinates
86
- FullConfig.new(manifest, extra_class_path)
87
- end
78
+ full_config = resolve_full_config(resolver, start_coordinates, verbose)
88
79
 
89
- if subcommand == "run"
90
- launch_config = full_config.launch_config(resolver)
80
+ executable_name = full_config.manifest.executable_name || opts[:executable_name]
81
+
82
+ if ! executable_name
83
+ raise "Manifest does not contain executable name, please specify one on the commandline like so:\n" +
84
+ "jlauncher install --executable-name myexecutablename #{full_config.start_coordinates}"
85
+ end
91
86
 
92
- launch_config.run(program_args)
93
- else
94
- if subcommand == "install"
95
87
  bin_dir = File.expand_path("~/.config/jlauncher/bin")
96
- executable_path = bin_dir + "/" + (manifest.executable_name || "testme")
88
+
89
+ executable_path = bin_dir + "/" + (executable_name)
97
90
  FileUtils.mkdir_p(bin_dir)
98
91
  File.write(executable_path, <<~HEREDOC
99
- #!/usr/bin/env bash
100
-
101
- set -e
102
- set -u
103
- set -o pipefail
92
+ #!/usr/bin/env bash
93
+
94
+ set -e
95
+ set -u
96
+ set -o pipefail
104
97
 
105
- jlauncher run #{start_coordinates} "$@"
98
+ jlauncher run #{full_config.start_coordinates} "$@"
106
99
  HEREDOC
107
100
  )
108
101
 
109
102
  File.chmod(0755, executable_path)
110
103
  check_path(bin_dir)
111
104
 
112
- STDERR.puts("'#{start_coordinates}' has been installed as #{manifest.executable_name.bold}.")
105
+ STDERR.puts("'#{full_config.start_coordinates}' has been installed as #{executable_name.bold}.")
113
106
  else
114
107
  raise "'#{subcommand}' is not a valid subcommand."
115
108
  end
@@ -151,12 +144,16 @@ where [options] are:
151
144
  # plus an optional extra_class_path element, which contains either
152
145
  # maven coordinates or a local file containing a jar
153
146
  class FullConfig
154
- def initialize(manifest, extra_class_path)
147
+ attr_reader :manifest, :start_coordinates
148
+
149
+ def initialize(manifest, extra_class_path, start_coordinates)
155
150
  @manifest = manifest
156
151
  @extra_class_path = extra_class_path
152
+ @start_coordinates = start_coordinates
157
153
 
158
154
  end
159
155
 
156
+
160
157
  def launch_config(resolver)
161
158
  class_path_from_manifest = @manifest.dependencies.map {
162
159
  |c| resolver.get(c)
@@ -201,4 +198,43 @@ where [options] are:
201
198
  @json_map['executableName']
202
199
  end
203
200
  end
201
+
202
+ private
203
+
204
+ def self.resolve_full_config(resolver, start_coordinates, verbose)
205
+ full_config = if File.exist?(start_coordinates)
206
+ if (start_coordinates.end_with?(".jar"))
207
+ STDERR.puts("Starting local jar") if verbose
208
+
209
+ start_coordinates = File.expand_path(start_coordinates)
210
+
211
+ extra_class_path = "file:" + File.expand_path(start_coordinates)
212
+
213
+
214
+ manifest = read_manifest(start_coordinates)
215
+ FullConfig.new(manifest, extra_class_path, start_coordinates)
216
+ else
217
+ STDERR.puts("Starting local manifest") if verbose
218
+
219
+ manifest = Manifest.new(JSON.parse(File.read(start_coordinates)))
220
+
221
+ extra_class_path = nil
222
+ FullConfig.new(manifest, extra_class_path, start_coordinates)
223
+ end
224
+ else
225
+ STDERR.puts("Starting from repo jar") if verbose
226
+
227
+ components = start_coordinates.split(":")
228
+ if components.length != 3
229
+ raise "'#{start_coordinates}' is not a valid coordinate use <groupId>:<artifactId>:<version>"
230
+ end
231
+
232
+ main_jar = resolver.get(Coordinates.new(start_coordinates))
233
+
234
+ manifest = read_manifest(main_jar)
235
+ extra_class_path = "maven:" + start_coordinates
236
+ FullConfig.new(manifest, extra_class_path, start_coordinates)
237
+ end
238
+ full_config
239
+ end
204
240
  end
@@ -1,3 +1,3 @@
1
1
  module JLauncher
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.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.4.0
4
+ version: 0.5.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-09-25 00:00:00.000000000 Z
11
+ date: 2020-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler