warbler 2.1.1 → 2.1.3
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 +4 -4
- data/CHANGELOG.md +11 -0
- data/Gemfile +6 -1
- data/README.rdoc +37 -38
- data/Rakefile +16 -20
- data/ext/pom.xml +59 -0
- data/ext/{JarMain.java → src/main/java/warbler/JarMain.java} +15 -42
- data/ext/{WarMain.java → src/main/java/warbler/WarMain.java} +23 -20
- data/ext/{WarblerJar.java → src/main/java/warbler/WarblerJar.java} +23 -45
- data/lib/warbler/config.rb +4 -2
- data/lib/warbler/jar.rb +11 -2
- data/lib/warbler/templates/bundler.erb +0 -3
- data/lib/warbler/templates/jar.erb +4 -2
- data/lib/warbler/templates/war.erb +3 -1
- data/lib/warbler/traits/bundler.rb +75 -42
- data/lib/warbler/traits/jar.rb +4 -7
- data/lib/warbler/traits/war.rb +5 -7
- data/lib/warbler/version.rb +1 -1
- data/lib/warbler/web_server.rb +3 -1
- data/lib/warbler/zip_support.rb +3 -0
- data/lib/warbler_jar.jar +0 -0
- data/mvnw +295 -0
- data/mvnw.cmd +189 -0
- data/pom.xml +139 -0
- data/warble.rb +5 -5
- data/warbler.gemspec +1 -9
- metadata +12 -86
- data/Mavenfile +0 -49
- data/ext/WarblerJarService.java +0 -18
|
@@ -4,10 +4,12 @@ ENV['GEM_HOME'] <%= config.override_gem_home ? '=' : '||=' %> File.expand_path(F
|
|
|
4
4
|
ENV['GEM_HOME'] <%= config.override_gem_home ? '=' : '||=' %> File.expand_path(File.join('..', '..', '<%= config.relative_gem_path %>'), __FILE__)
|
|
5
5
|
<% end -%>
|
|
6
6
|
<% if config.override_gem_home -%>
|
|
7
|
-
|
|
7
|
+
<%# GEM_HOME (the packed gems) is always on Gem.path; adding only the runtime's own default %>
|
|
8
|
+
<%# gem dir (Ruby's "bundled gems") excludes host gem paths (e.g. Gem.user_dir aka ~/.gem) %>
|
|
9
|
+
ENV['GEM_PATH'] = Gem.default_dir
|
|
8
10
|
<% end -%>
|
|
9
11
|
<% if config.bundler && config.bundler[:gemfile_path] -%>
|
|
10
12
|
ENV['BUNDLE_GEMFILE'] = File.expand_path(File.join('..', '..', '<%= config.bundler[:gemfile_path] %>'), __FILE__)
|
|
11
13
|
<% end -%>
|
|
12
14
|
<%# Ensure any cached paths are cleared; otherwise behaviour can be indeterminate if the paths have already been read %>
|
|
13
|
-
|
|
15
|
+
Gem.clear_paths
|
|
@@ -6,7 +6,9 @@ if $servlet_context.nil?
|
|
|
6
6
|
else
|
|
7
7
|
ENV['GEM_HOME'] <%= config.override_gem_home ? '=' : '||=' %> $servlet_context.getRealPath('<%= config.gem_path %>')
|
|
8
8
|
<% if config.override_gem_home -%>
|
|
9
|
-
|
|
9
|
+
<%# GEM_HOME (the packed gems) is always on Gem.path; adding only the runtime's own default %>
|
|
10
|
+
<%# gem dir (Ruby's "bundled gems") excludes host gem paths (e.g. Gem.user_dir aka ~/.gem) %>
|
|
11
|
+
ENV['GEM_PATH'] = Gem.default_dir
|
|
10
12
|
<% end -%>
|
|
11
13
|
<% if config.bundler && config.bundler[:gemfile_path] -%>
|
|
12
14
|
ENV['BUNDLE_GEMFILE'] ||= $servlet_context.getRealPath('/<%= config.bundler[:gemfile_path] %>')
|
|
@@ -14,6 +14,23 @@ module Warbler
|
|
|
14
14
|
include PathmapHelper
|
|
15
15
|
include BundlerHelper
|
|
16
16
|
|
|
17
|
+
# Bundler settings enforced in the packed application via a generated
|
|
18
|
+
# *.bundle/config*, the highest-precedence documented configuration level:
|
|
19
|
+
BUNDLE_CONFIG_DEFAULTS = {
|
|
20
|
+
# BUNDLE_VERSION: disable bundler's "auto-switch" to Gemfile.lock's BUNDLED WITH bundler version
|
|
21
|
+
# (bundler restarts the process to do so, which cannot work inside a servlet container or self-contained executable jar)
|
|
22
|
+
'BUNDLE_VERSION' => 'system',
|
|
23
|
+
# BUNDLE_FROZEN: fail fast with a descriptive error on Gemfile vs Gemfile.lock drift instead of attempting
|
|
24
|
+
# a runtime re-resolution
|
|
25
|
+
'BUNDLE_FROZEN' => 'true',
|
|
26
|
+
# BUNDLE_PATH__SYSTEM (path.system): pin bundler to the "system" gems - which are the packed gems, via
|
|
27
|
+
# GEM_HOME/GEM_PATH from *init.rb* - immune to a BUNDLE_PATH/BUNDLE_DEPLOYMENT leaking in from the host's
|
|
28
|
+
# environment or ~/.bundle/config
|
|
29
|
+
'BUNDLE_PATH__SYSTEM' => 'true',
|
|
30
|
+
# BUNDLE_AUTO_INSTALL: never install gems at boot time, even if the host's environment or global config enables it
|
|
31
|
+
'BUNDLE_AUTO_INSTALL' => 'false'
|
|
32
|
+
}.freeze
|
|
33
|
+
|
|
17
34
|
def self.detect?
|
|
18
35
|
File.exist?(ENV['BUNDLE_GEMFILE'] || 'Gemfile')
|
|
19
36
|
end
|
|
@@ -36,6 +53,8 @@ module Warbler
|
|
|
36
53
|
config.gem_dependencies = false # Bundler takes care of these
|
|
37
54
|
config.bundler = {} if config.bundler == true
|
|
38
55
|
|
|
56
|
+
warn_on_bundler_version_mismatch
|
|
57
|
+
|
|
39
58
|
bundler_specs.each do |spec|
|
|
40
59
|
spec = to_spec(spec)
|
|
41
60
|
|
|
@@ -45,11 +64,12 @@ module Warbler
|
|
|
45
64
|
config.bundler[:git_specs] << spec
|
|
46
65
|
when ::Bundler::Source::Path
|
|
47
66
|
unless bundler_source_is_warbled_gem_itself?(spec.source)
|
|
48
|
-
if spec.source.path
|
|
49
|
-
#
|
|
50
|
-
#
|
|
67
|
+
if spec.source.path&.relative?
|
|
68
|
+
# pack the gem at its relative *[APP_ROOT]/gem/path* location - at runtime bundler resolves the path
|
|
69
|
+
# source relative to the packed Gemfile.
|
|
70
|
+
# Deliberately NOT also added to config.gems: bundler never materializes path gems from the gem
|
|
71
|
+
# repository; doing so would cause duplication.
|
|
51
72
|
config.includes += FileList[File.join(spec.source.path, '**/*')]
|
|
52
|
-
config.gems << spec # probably not really needed
|
|
53
73
|
else
|
|
54
74
|
warn("Bundler `path' components are not fully supported.\n" +
|
|
55
75
|
"The `#{spec.full_name}' component was not bundled.\n" +
|
|
@@ -57,13 +77,12 @@ module Warbler
|
|
|
57
77
|
end
|
|
58
78
|
end
|
|
59
79
|
else
|
|
60
|
-
config.gems << spec
|
|
80
|
+
config.gems << spec unless spec.respond_to?(:default_gem?) && spec.default_gem?
|
|
61
81
|
end
|
|
62
82
|
end
|
|
63
83
|
config.bundler[:gemfile] = ::Bundler.default_gemfile
|
|
64
84
|
config.bundler[:gemfile_path] = apply_pathmaps(config, relative_from_pwd(::Bundler.default_gemfile), :application)
|
|
65
85
|
config.bundler[:lockfile] = ::Bundler.default_lockfile
|
|
66
|
-
config.bundler[:frozen] = ::Bundler.settings[:frozen]
|
|
67
86
|
path = ::Bundler.settings[:path]
|
|
68
87
|
config.excludes += [path, "#{path}/**/*"] if path
|
|
69
88
|
config.init_contents << "#{config.warbler_templates}/bundler.erb"
|
|
@@ -73,42 +92,41 @@ module Warbler
|
|
|
73
92
|
add_bundler_files(jar) if config.bundler
|
|
74
93
|
end
|
|
75
94
|
|
|
76
|
-
# Add Bundler Gemfiles and git repositories to the archive.
|
|
95
|
+
# Add Bundler Gemfiles, .bundle/config and git repositories to the archive.
|
|
77
96
|
def add_bundler_files(jar)
|
|
78
97
|
gemfile = relative_from_pwd(config.bundler[:gemfile])
|
|
79
98
|
lockfile = relative_from_pwd(config.bundler[:lockfile])
|
|
99
|
+
bundle_config = File.join('.bundle', 'config')
|
|
100
|
+
|
|
80
101
|
jar.files[apply_pathmaps(config, gemfile, :application)] = config.bundler[:gemfile].to_s
|
|
81
|
-
if File.exist?(lockfile)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if config.bundler[:git_specs]
|
|
85
|
-
pathmap = "#{config.relative_gem_path}/bundler/gems/%p"
|
|
86
|
-
pathmap.sub!(%r{^/+}, '')
|
|
87
|
-
config.pathmaps.git = [pathmap]
|
|
88
|
-
config.bundler[:git_specs].each do |spec|
|
|
89
|
-
full_gem_path = Pathname.new(spec.full_gem_path)
|
|
90
|
-
|
|
91
|
-
gem_relative_path = full_gem_path.relative_path_from(::Bundler.install_path)
|
|
92
|
-
filenames = []
|
|
93
|
-
gem_relative_path.each_filename { |f| filenames << f }
|
|
94
|
-
|
|
95
|
-
exclude_gems = true
|
|
96
|
-
unless filenames.empty?
|
|
97
|
-
full_gem_path = Pathname.new(::Bundler.install_path) + filenames.first
|
|
98
|
-
exclude_gems = false
|
|
99
|
-
end
|
|
102
|
+
jar.files[apply_pathmaps(config, lockfile, :application)] = config.bundler[:lockfile].to_s if File.exist?(lockfile)
|
|
103
|
+
# NOTE: in-memory content must be an IO - jar creation treats plain Strings as source file paths
|
|
104
|
+
jar.files[apply_pathmaps(config, bundle_config, :application)] = StringIO.new(bundle_config_contents)
|
|
100
105
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
else
|
|
104
|
-
pattern = "#{full_gem_path.to_s}/**/*"
|
|
105
|
-
end
|
|
106
|
+
add_bundler_git_specs(config.bundler[:git_specs], jar) if config.bundler[:git_specs]
|
|
107
|
+
end
|
|
106
108
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
109
|
+
private
|
|
110
|
+
|
|
111
|
+
def add_bundler_git_specs(git_specs, jar)
|
|
112
|
+
config.pathmaps.git = ["#{config.relative_gem_path}/bundler/gems/%p".sub(%r{^/+}, '')]
|
|
113
|
+
|
|
114
|
+
# a git source checkout may contain multiple gems (spec.full_gem_path being a sub-directory) - bundler expects
|
|
115
|
+
# the complete repository checkout under bundler/gems/<repo>-<ref>, so pack from its root (once per repository,
|
|
116
|
+
# even when several specs share the checkout)
|
|
117
|
+
checkout_paths = git_specs.map do |spec|
|
|
118
|
+
full_gem_path = Pathname.new(spec.full_gem_path)
|
|
119
|
+
filenames = full_gem_path.relative_path_from(::Bundler.install_path).each_filename.to_a
|
|
120
|
+
filenames.empty? ? full_gem_path : Pathname.new(::Bundler.install_path) + filenames.first
|
|
121
|
+
end.uniq
|
|
122
|
+
|
|
123
|
+
checkout_paths.each do |checkout_path|
|
|
124
|
+
FileList["#{checkout_path.to_s}/**/*"].each do |src|
|
|
125
|
+
f = Pathname.new(src).relative_path_from(checkout_path).to_s
|
|
126
|
+
# NOTE: for git sources the excludes match relative to the packed repository checkout root (the gem root,
|
|
127
|
+
# except multi-gem repos)
|
|
128
|
+
next if config.gem_excludes && config.gem_excludes.any? { |rx| f =~ rx }
|
|
129
|
+
jar.files[apply_pathmaps(config, File.join(checkout_path.basename, f), :git)] = src
|
|
112
130
|
end
|
|
113
131
|
end
|
|
114
132
|
end
|
|
@@ -121,17 +139,32 @@ module Warbler
|
|
|
121
139
|
end
|
|
122
140
|
end
|
|
123
141
|
|
|
124
|
-
|
|
142
|
+
def warn_on_bundler_version_mismatch
|
|
143
|
+
lockfile = ::Bundler.default_lockfile
|
|
144
|
+
return unless lockfile && File.exist?(lockfile)
|
|
145
|
+
locked = ::Bundler::LockfileParser.new(File.read(lockfile)).bundler_version rescue nil
|
|
146
|
+
if locked && locked.to_s != ::Bundler::VERSION
|
|
147
|
+
warn("Gemfile.lock BUNDLED WITH (#{locked}) does not match the bundler running warbler (#{::Bundler::VERSION}).\n" +
|
|
148
|
+
"The packed application will boot with the default bundler of the packed JRuby (jruby-jars),\n" +
|
|
149
|
+
"consider re-generating Gemfile.lock with a matching bundler version.")
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
# Contents for the packed *.bundle/config*: only warbler's deployment settings, deliberately independent of the
|
|
154
|
+
# application's build-time bundler configuration.
|
|
155
|
+
def bundle_config_contents
|
|
156
|
+
require 'yaml'
|
|
157
|
+
settings = BUNDLE_CONFIG_DEFAULTS.dup
|
|
158
|
+
# frozen mode errors without a lockfile - do not force it upon applications packed without a Gemfile.lock
|
|
159
|
+
settings.delete('BUNDLE_FROZEN') if config.bundler[:frozen] == false || !File.exist?(config.bundler[:lockfile].to_s)
|
|
160
|
+
settings.to_yaml
|
|
161
|
+
end
|
|
125
162
|
|
|
126
163
|
def bundler_specs
|
|
127
164
|
bundle_without = config.bundle_without.map { |s| s.to_sym }
|
|
128
165
|
definition = ::Bundler.definition
|
|
129
|
-
all = definition.specs.to_a
|
|
130
166
|
requested_groups = definition.groups - bundle_without
|
|
131
|
-
|
|
132
|
-
excluded_git_specs = (all - requested).select { |spec| ::Bundler::Source::Git === spec.source }
|
|
133
|
-
excluded_git_specs.each { |spec| spec.groups << :warbler_excluded }
|
|
134
|
-
requested + excluded_git_specs
|
|
167
|
+
requested_groups.empty? ? [] : definition.specs_for(requested_groups).to_a
|
|
135
168
|
end
|
|
136
169
|
|
|
137
170
|
def bundler_source_is_warbled_gem_itself?(source)
|
data/lib/warbler/traits/jar.rb
CHANGED
|
@@ -16,6 +16,8 @@ module Warbler
|
|
|
16
16
|
class Jar
|
|
17
17
|
include Trait
|
|
18
18
|
|
|
19
|
+
MAIN_PATH_TO_CLASS = 'warbler/JarMain.class'.freeze
|
|
20
|
+
|
|
19
21
|
def self.detect?
|
|
20
22
|
!detect_any_conflicts?
|
|
21
23
|
end
|
|
@@ -32,16 +34,11 @@ module Warbler
|
|
|
32
34
|
config.init_contents << "#{config.warbler_templates}/jar.erb"
|
|
33
35
|
end
|
|
34
36
|
|
|
35
|
-
def after_configure
|
|
36
|
-
config.init_contents << StringIO.new("require 'rubygems' unless defined?(Gem)\n")
|
|
37
|
-
end
|
|
38
|
-
|
|
39
37
|
def update_archive(jar)
|
|
40
38
|
unless config.manifest_file
|
|
41
|
-
|
|
42
|
-
jar.files['META-INF/MANIFEST.MF'] = StringIO.new(manifest)
|
|
39
|
+
jar.files[Warbler::Jar::MANIFEST_PATH] = StringIO.new(Warbler::Jar.manifest_with_main(MAIN_PATH_TO_CLASS))
|
|
43
40
|
end
|
|
44
|
-
jar.files[
|
|
41
|
+
jar.files[MAIN_PATH_TO_CLASS] = jar.entry_in_jar(WARBLER_JAR, MAIN_PATH_TO_CLASS)
|
|
45
42
|
end
|
|
46
43
|
|
|
47
44
|
def default_pathmaps
|
data/lib/warbler/traits/war.rb
CHANGED
|
@@ -104,21 +104,19 @@ module Warbler
|
|
|
104
104
|
end
|
|
105
105
|
end
|
|
106
106
|
|
|
107
|
-
def add_runnables(jar,
|
|
108
|
-
main_class = main_class.sub('.class', '') # handles WarMain.class
|
|
107
|
+
def add_runnables(jar, main_path_to_class = WebServer::Artifact::MAIN_PATH_TO_CLASS)
|
|
109
108
|
unless config.manifest_file
|
|
110
|
-
|
|
111
|
-
jar.files['META-INF/MANIFEST.MF'] = StringIO.new(manifest)
|
|
109
|
+
jar.files[Warbler::Jar::MANIFEST_PATH] = StringIO.new(Warbler::Jar.manifest_with_main(main_path_to_class))
|
|
112
110
|
end
|
|
113
|
-
[
|
|
114
|
-
jar.files["#{
|
|
111
|
+
[ Warbler::Traits::Jar::MAIN_PATH_TO_CLASS, WebServer::Artifact::MAIN_PATH_TO_CLASS, main_path_to_class ].uniq.each do |path_to_class|
|
|
112
|
+
jar.files["#{path_to_class}"] = jar.entry_in_jar(WARBLER_JAR, "#{path_to_class}")
|
|
115
113
|
end
|
|
116
114
|
end
|
|
117
115
|
|
|
118
116
|
def add_executables(jar)
|
|
119
117
|
webserver = WEB_SERVERS[config.webserver.to_s]
|
|
120
118
|
webserver.add(jar)
|
|
121
|
-
add_runnables jar, webserver.main_class ||
|
|
119
|
+
add_runnables jar, webserver.main_class || WebServer::Artifact::MAIN_PATH_TO_CLASS
|
|
122
120
|
end
|
|
123
121
|
|
|
124
122
|
def add_gemjar(jar)
|
data/lib/warbler/version.rb
CHANGED
data/lib/warbler/web_server.rb
CHANGED
|
@@ -2,6 +2,8 @@ module Warbler
|
|
|
2
2
|
class WebServer
|
|
3
3
|
class Artifact < Struct.new(:repo, :group_id, :artifact_id, :version)
|
|
4
4
|
|
|
5
|
+
MAIN_PATH_TO_CLASS = 'warbler/WarMain.class'.freeze
|
|
6
|
+
|
|
5
7
|
def path_fragment
|
|
6
8
|
@path_fragment ||= "#{group_id.gsub('.', '/')}/#{artifact_id}/#{version}/#{artifact_id}-#{version}.jar"
|
|
7
9
|
end
|
|
@@ -82,7 +84,7 @@ module Warbler
|
|
|
82
84
|
end
|
|
83
85
|
|
|
84
86
|
def main_class
|
|
85
|
-
|
|
87
|
+
Artifact::MAIN_PATH_TO_CLASS
|
|
86
88
|
end
|
|
87
89
|
end
|
|
88
90
|
|
data/lib/warbler/zip_support.rb
CHANGED
data/lib/warbler_jar.jar
CHANGED
|
Binary file
|
data/mvnw
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# ----------------------------------------------------------------------------
|
|
3
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
|
4
|
+
# or more contributor license agreements. See the NOTICE file
|
|
5
|
+
# distributed with this work for additional information
|
|
6
|
+
# regarding copyright ownership. The ASF licenses this file
|
|
7
|
+
# to you under the Apache License, Version 2.0 (the
|
|
8
|
+
# "License"); you may not use this file except in compliance
|
|
9
|
+
# with the License. You may obtain a copy of the License at
|
|
10
|
+
#
|
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
#
|
|
13
|
+
# Unless required by applicable law or agreed to in writing,
|
|
14
|
+
# software distributed under the License is distributed on an
|
|
15
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
16
|
+
# KIND, either express or implied. See the License for the
|
|
17
|
+
# specific language governing permissions and limitations
|
|
18
|
+
# under the License.
|
|
19
|
+
# ----------------------------------------------------------------------------
|
|
20
|
+
|
|
21
|
+
# ----------------------------------------------------------------------------
|
|
22
|
+
# Apache Maven Wrapper startup batch script, version 3.3.4
|
|
23
|
+
#
|
|
24
|
+
# Optional ENV vars
|
|
25
|
+
# -----------------
|
|
26
|
+
# JAVA_HOME - location of a JDK home dir, required when download maven via java source
|
|
27
|
+
# MVNW_REPOURL - repo url base for downloading maven distribution
|
|
28
|
+
# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
|
|
29
|
+
# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output
|
|
30
|
+
# ----------------------------------------------------------------------------
|
|
31
|
+
|
|
32
|
+
set -euf
|
|
33
|
+
[ "${MVNW_VERBOSE-}" != debug ] || set -x
|
|
34
|
+
|
|
35
|
+
# OS specific support.
|
|
36
|
+
native_path() { printf %s\\n "$1"; }
|
|
37
|
+
case "$(uname)" in
|
|
38
|
+
CYGWIN* | MINGW*)
|
|
39
|
+
[ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")"
|
|
40
|
+
native_path() { cygpath --path --windows "$1"; }
|
|
41
|
+
;;
|
|
42
|
+
esac
|
|
43
|
+
|
|
44
|
+
# set JAVACMD and JAVACCMD
|
|
45
|
+
set_java_home() {
|
|
46
|
+
# For Cygwin and MinGW, ensure paths are in Unix format before anything is touched
|
|
47
|
+
if [ -n "${JAVA_HOME-}" ]; then
|
|
48
|
+
if [ -x "$JAVA_HOME/jre/sh/java" ]; then
|
|
49
|
+
# IBM's JDK on AIX uses strange locations for the executables
|
|
50
|
+
JAVACMD="$JAVA_HOME/jre/sh/java"
|
|
51
|
+
JAVACCMD="$JAVA_HOME/jre/sh/javac"
|
|
52
|
+
else
|
|
53
|
+
JAVACMD="$JAVA_HOME/bin/java"
|
|
54
|
+
JAVACCMD="$JAVA_HOME/bin/javac"
|
|
55
|
+
|
|
56
|
+
if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then
|
|
57
|
+
echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2
|
|
58
|
+
echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2
|
|
59
|
+
return 1
|
|
60
|
+
fi
|
|
61
|
+
fi
|
|
62
|
+
else
|
|
63
|
+
JAVACMD="$(
|
|
64
|
+
'set' +e
|
|
65
|
+
'unset' -f command 2>/dev/null
|
|
66
|
+
'command' -v java
|
|
67
|
+
)" || :
|
|
68
|
+
JAVACCMD="$(
|
|
69
|
+
'set' +e
|
|
70
|
+
'unset' -f command 2>/dev/null
|
|
71
|
+
'command' -v javac
|
|
72
|
+
)" || :
|
|
73
|
+
|
|
74
|
+
if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then
|
|
75
|
+
echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2
|
|
76
|
+
return 1
|
|
77
|
+
fi
|
|
78
|
+
fi
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
# hash string like Java String::hashCode
|
|
82
|
+
hash_string() {
|
|
83
|
+
str="${1:-}" h=0
|
|
84
|
+
while [ -n "$str" ]; do
|
|
85
|
+
char="${str%"${str#?}"}"
|
|
86
|
+
h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296))
|
|
87
|
+
str="${str#?}"
|
|
88
|
+
done
|
|
89
|
+
printf %x\\n $h
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
verbose() { :; }
|
|
93
|
+
[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; }
|
|
94
|
+
|
|
95
|
+
die() {
|
|
96
|
+
printf %s\\n "$1" >&2
|
|
97
|
+
exit 1
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
trim() {
|
|
101
|
+
# MWRAPPER-139:
|
|
102
|
+
# Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds.
|
|
103
|
+
# Needed for removing poorly interpreted newline sequences when running in more
|
|
104
|
+
# exotic environments such as mingw bash on Windows.
|
|
105
|
+
printf "%s" "${1}" | tr -d '[:space:]'
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
scriptDir="$(dirname "$0")"
|
|
109
|
+
scriptName="$(basename "$0")"
|
|
110
|
+
|
|
111
|
+
# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties
|
|
112
|
+
while IFS="=" read -r key value; do
|
|
113
|
+
case "${key-}" in
|
|
114
|
+
distributionUrl) distributionUrl=$(trim "${value-}") ;;
|
|
115
|
+
distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;;
|
|
116
|
+
esac
|
|
117
|
+
done <"$scriptDir/.mvn/wrapper/maven-wrapper.properties"
|
|
118
|
+
[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties"
|
|
119
|
+
|
|
120
|
+
case "${distributionUrl##*/}" in
|
|
121
|
+
maven-mvnd-*bin.*)
|
|
122
|
+
MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/
|
|
123
|
+
case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in
|
|
124
|
+
*AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;;
|
|
125
|
+
:Darwin*x86_64) distributionPlatform=darwin-amd64 ;;
|
|
126
|
+
:Darwin*arm64) distributionPlatform=darwin-aarch64 ;;
|
|
127
|
+
:Linux*x86_64*) distributionPlatform=linux-amd64 ;;
|
|
128
|
+
*)
|
|
129
|
+
echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2
|
|
130
|
+
distributionPlatform=linux-amd64
|
|
131
|
+
;;
|
|
132
|
+
esac
|
|
133
|
+
distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip"
|
|
134
|
+
;;
|
|
135
|
+
maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;;
|
|
136
|
+
*) MVN_CMD="mvn${scriptName#mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;;
|
|
137
|
+
esac
|
|
138
|
+
|
|
139
|
+
# apply MVNW_REPOURL and calculate MAVEN_HOME
|
|
140
|
+
# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-<version>,maven-mvnd-<version>-<platform>}/<hash>
|
|
141
|
+
[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}"
|
|
142
|
+
distributionUrlName="${distributionUrl##*/}"
|
|
143
|
+
distributionUrlNameMain="${distributionUrlName%.*}"
|
|
144
|
+
distributionUrlNameMain="${distributionUrlNameMain%-bin}"
|
|
145
|
+
MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}"
|
|
146
|
+
MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")"
|
|
147
|
+
|
|
148
|
+
exec_maven() {
|
|
149
|
+
unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || :
|
|
150
|
+
exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD"
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if [ -d "$MAVEN_HOME" ]; then
|
|
154
|
+
verbose "found existing MAVEN_HOME at $MAVEN_HOME"
|
|
155
|
+
exec_maven "$@"
|
|
156
|
+
fi
|
|
157
|
+
|
|
158
|
+
case "${distributionUrl-}" in
|
|
159
|
+
*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;;
|
|
160
|
+
*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;;
|
|
161
|
+
esac
|
|
162
|
+
|
|
163
|
+
# prepare tmp dir
|
|
164
|
+
if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then
|
|
165
|
+
clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; }
|
|
166
|
+
trap clean HUP INT TERM EXIT
|
|
167
|
+
else
|
|
168
|
+
die "cannot create temp dir"
|
|
169
|
+
fi
|
|
170
|
+
|
|
171
|
+
mkdir -p -- "${MAVEN_HOME%/*}"
|
|
172
|
+
|
|
173
|
+
# Download and Install Apache Maven
|
|
174
|
+
verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
|
|
175
|
+
verbose "Downloading from: $distributionUrl"
|
|
176
|
+
verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
|
|
177
|
+
|
|
178
|
+
# select .zip or .tar.gz
|
|
179
|
+
if ! command -v unzip >/dev/null; then
|
|
180
|
+
distributionUrl="${distributionUrl%.zip}.tar.gz"
|
|
181
|
+
distributionUrlName="${distributionUrl##*/}"
|
|
182
|
+
fi
|
|
183
|
+
|
|
184
|
+
# verbose opt
|
|
185
|
+
__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR=''
|
|
186
|
+
[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v
|
|
187
|
+
|
|
188
|
+
# normalize http auth
|
|
189
|
+
case "${MVNW_PASSWORD:+has-password}" in
|
|
190
|
+
'') MVNW_USERNAME='' MVNW_PASSWORD='' ;;
|
|
191
|
+
has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;;
|
|
192
|
+
esac
|
|
193
|
+
|
|
194
|
+
if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then
|
|
195
|
+
verbose "Found wget ... using wget"
|
|
196
|
+
wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl"
|
|
197
|
+
elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then
|
|
198
|
+
verbose "Found curl ... using curl"
|
|
199
|
+
curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl"
|
|
200
|
+
elif set_java_home; then
|
|
201
|
+
verbose "Falling back to use Java to download"
|
|
202
|
+
javaSource="$TMP_DOWNLOAD_DIR/Downloader.java"
|
|
203
|
+
targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName"
|
|
204
|
+
cat >"$javaSource" <<-END
|
|
205
|
+
public class Downloader extends java.net.Authenticator
|
|
206
|
+
{
|
|
207
|
+
protected java.net.PasswordAuthentication getPasswordAuthentication()
|
|
208
|
+
{
|
|
209
|
+
return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() );
|
|
210
|
+
}
|
|
211
|
+
public static void main( String[] args ) throws Exception
|
|
212
|
+
{
|
|
213
|
+
setDefault( new Downloader() );
|
|
214
|
+
java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() );
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
END
|
|
218
|
+
# For Cygwin/MinGW, switch paths to Windows format before running javac and java
|
|
219
|
+
verbose " - Compiling Downloader.java ..."
|
|
220
|
+
"$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java"
|
|
221
|
+
verbose " - Running Downloader.java ..."
|
|
222
|
+
"$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")"
|
|
223
|
+
fi
|
|
224
|
+
|
|
225
|
+
# If specified, validate the SHA-256 sum of the Maven distribution zip file
|
|
226
|
+
if [ -n "${distributionSha256Sum-}" ]; then
|
|
227
|
+
distributionSha256Result=false
|
|
228
|
+
if [ "$MVN_CMD" = mvnd.sh ]; then
|
|
229
|
+
echo "Checksum validation is not supported for maven-mvnd." >&2
|
|
230
|
+
echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
|
|
231
|
+
exit 1
|
|
232
|
+
elif command -v sha256sum >/dev/null; then
|
|
233
|
+
if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c - >/dev/null 2>&1; then
|
|
234
|
+
distributionSha256Result=true
|
|
235
|
+
fi
|
|
236
|
+
elif command -v shasum >/dev/null; then
|
|
237
|
+
if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then
|
|
238
|
+
distributionSha256Result=true
|
|
239
|
+
fi
|
|
240
|
+
else
|
|
241
|
+
echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2
|
|
242
|
+
echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
|
|
243
|
+
exit 1
|
|
244
|
+
fi
|
|
245
|
+
if [ $distributionSha256Result = false ]; then
|
|
246
|
+
echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2
|
|
247
|
+
echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2
|
|
248
|
+
exit 1
|
|
249
|
+
fi
|
|
250
|
+
fi
|
|
251
|
+
|
|
252
|
+
# unzip and move
|
|
253
|
+
if command -v unzip >/dev/null; then
|
|
254
|
+
unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip"
|
|
255
|
+
else
|
|
256
|
+
tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar"
|
|
257
|
+
fi
|
|
258
|
+
|
|
259
|
+
# Find the actual extracted directory name (handles snapshots where filename != directory name)
|
|
260
|
+
actualDistributionDir=""
|
|
261
|
+
|
|
262
|
+
# First try the expected directory name (for regular distributions)
|
|
263
|
+
if [ -d "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" ]; then
|
|
264
|
+
if [ -f "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/bin/$MVN_CMD" ]; then
|
|
265
|
+
actualDistributionDir="$distributionUrlNameMain"
|
|
266
|
+
fi
|
|
267
|
+
fi
|
|
268
|
+
|
|
269
|
+
# If not found, search for any directory with the Maven executable (for snapshots)
|
|
270
|
+
if [ -z "$actualDistributionDir" ]; then
|
|
271
|
+
# enable globbing to iterate over items
|
|
272
|
+
set +f
|
|
273
|
+
for dir in "$TMP_DOWNLOAD_DIR"/*; do
|
|
274
|
+
if [ -d "$dir" ]; then
|
|
275
|
+
if [ -f "$dir/bin/$MVN_CMD" ]; then
|
|
276
|
+
actualDistributionDir="$(basename "$dir")"
|
|
277
|
+
break
|
|
278
|
+
fi
|
|
279
|
+
fi
|
|
280
|
+
done
|
|
281
|
+
set -f
|
|
282
|
+
fi
|
|
283
|
+
|
|
284
|
+
if [ -z "$actualDistributionDir" ]; then
|
|
285
|
+
verbose "Contents of $TMP_DOWNLOAD_DIR:"
|
|
286
|
+
verbose "$(ls -la "$TMP_DOWNLOAD_DIR")"
|
|
287
|
+
die "Could not find Maven distribution directory in extracted archive"
|
|
288
|
+
fi
|
|
289
|
+
|
|
290
|
+
verbose "Found extracted Maven distribution directory: $actualDistributionDir"
|
|
291
|
+
printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$actualDistributionDir/mvnw.url"
|
|
292
|
+
mv -- "$TMP_DOWNLOAD_DIR/$actualDistributionDir" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME"
|
|
293
|
+
|
|
294
|
+
clean || :
|
|
295
|
+
exec_maven "$@"
|