jar-dependencies 0.5.7 → 0.6.0.pre2
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/Mavenfile +16 -27
- data/Rakefile +51 -2
- data/Readme.md +6 -11
- data/jar-dependencies.gemspec +4 -13
- data/lib/jar_dependencies.rb +56 -49
- data/lib/jars/gemspec_artifacts.rb +10 -10
- data/lib/jars/installer.rb +11 -13
- data/lib/jars/lock.rb +1 -1
- data/lib/jars/lock_down.rb +90 -59
- data/lib/jars/maven_exec.rb +23 -25
- data/lib/jars/maven_settings.rb +2 -70
- data/lib/jars/mima/context-2.4.42.jar +0 -0
- data/lib/jars/mima/jcl-over-slf4j-2.0.17.jar +0 -0
- data/lib/jars/mima/slf4j-api-2.0.17.jar +0 -0
- data/lib/jars/mima/slf4j-simple-2.0.17.jar +0 -0
- data/lib/jars/mima/standalone-static-uber-2.4.42.jar +0 -0
- data/lib/jars/mima/version.rb +42 -0
- data/lib/jars/mima.rb +262 -0
- data/lib/jars/post_install_hook.rb +0 -1
- data/lib/jars/version.rb +1 -3
- metadata +16 -36
- data/lib/jars/attach_jars_pom.rb +0 -28
- data/lib/jars/gemspec_pom.rb +0 -11
- data/lib/jars/lock_down_pom.rb +0 -35
- data/lib/jars/maven_factory.rb +0 -132
- data/lib/jars/output_jars_pom.rb +0 -16
- data/lib/jars/settings.xml +0 -20
data/lib/jars/mima.rb
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'jars/mima/version'
|
|
4
|
+
require 'jars/gemspec_artifacts'
|
|
5
|
+
|
|
6
|
+
module Jars
|
|
7
|
+
# Resolver backed by the Mima Java library (MIni MAven).
|
|
8
|
+
# Replaces the previous ruby-maven based resolution pipeline.
|
|
9
|
+
#
|
|
10
|
+
# Mima wraps the Maven Resolver (Aether) API as a standalone library (no Maven process is spawned).
|
|
11
|
+
module Mima
|
|
12
|
+
class << self
|
|
13
|
+
@@jars_loaded = nil # rubocop:disable Style/ClassVars
|
|
14
|
+
|
|
15
|
+
# Loads the bundled Mima jars onto the classpath.
|
|
16
|
+
# Safe to call multiple times; only loads once.
|
|
17
|
+
def ensure_jars_loaded
|
|
18
|
+
return if @@jars_loaded
|
|
19
|
+
|
|
20
|
+
mima_dir = File.expand_path('mima', File.dirname(__FILE__))
|
|
21
|
+
|
|
22
|
+
load File.join(mima_dir, "slf4j-api-#{SLF4J_VERSION}.jar")
|
|
23
|
+
load File.join(mima_dir, "slf4j-simple-#{SLF4J_VERSION}.jar")
|
|
24
|
+
load File.join(mima_dir, "jcl-over-slf4j-#{SLF4J_VERSION}.jar")
|
|
25
|
+
load File.join(mima_dir, "context-#{MIMA_VERSION}.jar")
|
|
26
|
+
load File.join(mima_dir, "standalone-static-uber-#{MIMA_VERSION}.jar")
|
|
27
|
+
|
|
28
|
+
@@jars_loaded = true # rubocop:disable Style/ClassVars
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Builds a +ContextOverrides+ from jar-dependencies configuration
|
|
32
|
+
# (local repo, user/global settings.xml).
|
|
33
|
+
#
|
|
34
|
+
# @return [Java::eu.maveniverse.maven.mima.context.ContextOverrides]
|
|
35
|
+
def context_overrides
|
|
36
|
+
ensure_jars_loaded
|
|
37
|
+
|
|
38
|
+
builder = Java::eu.maveniverse.maven.mima.context.ContextOverrides.create
|
|
39
|
+
builder.withUserSettings(true)
|
|
40
|
+
|
|
41
|
+
# Local repository override
|
|
42
|
+
local_repo = ::Jars.local_maven_repo
|
|
43
|
+
builder.withLocalRepositoryOverride(java.nio.file.Paths.get(local_repo)) if local_repo
|
|
44
|
+
|
|
45
|
+
# User settings.xml override
|
|
46
|
+
settings = ::Jars::MavenSettings.settings
|
|
47
|
+
builder.withUserSettingsXmlOverride(java.nio.file.Paths.get(settings)) if settings
|
|
48
|
+
|
|
49
|
+
# Global settings.xml override
|
|
50
|
+
global = ::Jars::MavenSettings.global_settings
|
|
51
|
+
builder.withGlobalSettingsXmlOverride(java.nio.file.Paths.get(global)) if global
|
|
52
|
+
|
|
53
|
+
builder.build
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Creates a Mima Context. Caller is responsible for closing it.
|
|
57
|
+
#
|
|
58
|
+
# @param overrides [Java::eu.maveniverse.maven.mima.context.ContextOverrides, nil]
|
|
59
|
+
# optional overrides; when +nil+, {#context_overrides} is used
|
|
60
|
+
# @return [Java::eu.maveniverse.maven.mima.context.Context]
|
|
61
|
+
def create_context(overrides = nil)
|
|
62
|
+
ensure_jars_loaded
|
|
63
|
+
|
|
64
|
+
overrides ||= context_overrides
|
|
65
|
+
runtime = Java::eu.maveniverse.maven.mima.context.Runtimes::INSTANCE.getRuntime
|
|
66
|
+
runtime.create(overrides)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Resolves transitive dependencies for the given artifacts.
|
|
70
|
+
# Creates (and closes) its own Mima context.
|
|
71
|
+
#
|
|
72
|
+
# @param artifacts [Array<Jars::GemspecArtifacts::Artifact>] jar dependency declarations
|
|
73
|
+
# @param all_dependencies [Boolean] when +true+, include provided/test scoped artifacts
|
|
74
|
+
# @return [Array<ResolvedDependency>] resolved artifacts with local file paths
|
|
75
|
+
def resolve_artifacts(artifacts, all_dependencies: false)
|
|
76
|
+
context = create_context
|
|
77
|
+
begin
|
|
78
|
+
resolve_with_context(context, artifacts, all_dependencies: all_dependencies)
|
|
79
|
+
ensure
|
|
80
|
+
context.close
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Resolves transitive dependencies using an existing Mima context.
|
|
85
|
+
#
|
|
86
|
+
# @param context [Java::eu.maveniverse.maven.mima.context.Context] an open Mima context
|
|
87
|
+
# @param artifacts [Array<Jars::GemspecArtifacts::Artifact>] jar dependency declarations
|
|
88
|
+
# @param all_dependencies [Boolean] when +true+, include provided/test scoped artifacts
|
|
89
|
+
# @return [Array<ResolvedDependency>] resolved artifacts with local file paths
|
|
90
|
+
def resolve_with_context(context, artifacts, all_dependencies: false)
|
|
91
|
+
deps = artifacts_to_dependencies(artifacts, all_dependencies: all_dependencies)
|
|
92
|
+
return [] if deps.empty?
|
|
93
|
+
|
|
94
|
+
collect_request = org.eclipse.aether.collection.CollectRequest.new
|
|
95
|
+
deps.each { |d| collect_request.addDependency(d) }
|
|
96
|
+
collect_request.setRepositories(context.remoteRepositories)
|
|
97
|
+
|
|
98
|
+
dependency_request = org.eclipse.aether.resolution.DependencyRequest.new
|
|
99
|
+
dependency_request.setCollectRequest(collect_request)
|
|
100
|
+
|
|
101
|
+
result = context.repositorySystem.resolveDependencies(
|
|
102
|
+
context.repositorySystemSession, dependency_request
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
root = result.getRoot
|
|
106
|
+
collect_resolved(root)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
private
|
|
110
|
+
|
|
111
|
+
# Converts {GemspecArtifacts::Artifact} objects to Aether +Dependency+ list,
|
|
112
|
+
# filtering by scope unless +all_dependencies+ is set.
|
|
113
|
+
#
|
|
114
|
+
# @param artifacts [Array<Jars::GemspecArtifacts::Artifact>]
|
|
115
|
+
# @param all_dependencies [Boolean]
|
|
116
|
+
# @return [Array<org.eclipse.aether.graph.Dependency>]
|
|
117
|
+
def artifacts_to_dependencies(artifacts, all_dependencies: false)
|
|
118
|
+
filtered = artifacts.select do |a|
|
|
119
|
+
all_dependencies || (a.scope != 'provided' && a.scope != 'test')
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
filtered.map do |a|
|
|
123
|
+
aether_artifact = build_aether_artifact(a)
|
|
124
|
+
scope = a.scope || 'compile'
|
|
125
|
+
dep = org.eclipse.aether.graph.Dependency.new(aether_artifact, scope)
|
|
126
|
+
|
|
127
|
+
if a.exclusions && !a.exclusions.empty?
|
|
128
|
+
exclusions = a.exclusions.map do |ex|
|
|
129
|
+
org.eclipse.aether.graph.Exclusion.new(ex.group_id, ex.artifact_id, '*', '*')
|
|
130
|
+
end
|
|
131
|
+
dep = dep.setExclusions(exclusions)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
dep
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# Converts a single {GemspecArtifacts::Artifact} to an Aether +DefaultArtifact+.
|
|
139
|
+
#
|
|
140
|
+
# @param artifact [Jars::GemspecArtifacts::Artifact]
|
|
141
|
+
# @return [org.eclipse.aether.artifact.DefaultArtifact]
|
|
142
|
+
def build_aether_artifact(artifact)
|
|
143
|
+
version = Jars::MavenVersion.new(artifact.version) || artifact.version
|
|
144
|
+
if artifact.classifier
|
|
145
|
+
org.eclipse.aether.artifact.DefaultArtifact.new(
|
|
146
|
+
artifact.group_id, artifact.artifact_id, artifact.classifier,
|
|
147
|
+
artifact.type || 'jar', version
|
|
148
|
+
)
|
|
149
|
+
else
|
|
150
|
+
org.eclipse.aether.artifact.DefaultArtifact.new(
|
|
151
|
+
artifact.group_id, artifact.artifact_id,
|
|
152
|
+
artifact.type || 'jar', version
|
|
153
|
+
)
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
# Walks the resolved dependency tree and collects {ResolvedDependency} objects.
|
|
158
|
+
#
|
|
159
|
+
# @param node [org.eclipse.aether.graph.DependencyNode] root of the resolved tree
|
|
160
|
+
# @param result [Array<ResolvedDependency>] accumulator
|
|
161
|
+
# @return [Array<ResolvedDependency>]
|
|
162
|
+
def collect_resolved(node, result = [])
|
|
163
|
+
node.getChildren.each do |child|
|
|
164
|
+
dep = child.getDependency
|
|
165
|
+
next unless dep
|
|
166
|
+
|
|
167
|
+
artifact = dep.getArtifact
|
|
168
|
+
next unless artifact.getFile # skip unresolved
|
|
169
|
+
|
|
170
|
+
result << ResolvedDependency.new(
|
|
171
|
+
artifact.getGroupId,
|
|
172
|
+
artifact.getArtifactId,
|
|
173
|
+
artifact.getVersion,
|
|
174
|
+
artifact.getClassifier.to_s.empty? ? nil : artifact.getClassifier,
|
|
175
|
+
artifact.getExtension,
|
|
176
|
+
dep.getScope,
|
|
177
|
+
artifact.getFile.getAbsolutePath
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
collect_resolved(child, result)
|
|
181
|
+
end
|
|
182
|
+
result
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
# Structured result from dependency resolution.
|
|
187
|
+
#
|
|
188
|
+
# @!attribute [r] group_id
|
|
189
|
+
# @return [String] Maven group ID
|
|
190
|
+
# @!attribute [r] artifact_id
|
|
191
|
+
# @return [String] Maven artifact ID
|
|
192
|
+
# @!attribute [r] version
|
|
193
|
+
# @return [String] resolved version
|
|
194
|
+
# @!attribute [r] classifier
|
|
195
|
+
# @return [String, nil] Maven classifier (e.g. +"sources"+, +"no_aop"+)
|
|
196
|
+
# @!attribute [r] type
|
|
197
|
+
# @return [String] artifact type/extension (e.g. +"jar"+, +"pom"+)
|
|
198
|
+
# @!attribute [r] scope
|
|
199
|
+
# @return [String] Maven scope (+"compile"+, +"runtime"+, +"test"+, +"provided"+, +"system"+)
|
|
200
|
+
# @!attribute [r] file
|
|
201
|
+
# @return [String] absolute path to the resolved artifact in the local repository
|
|
202
|
+
ResolvedDependency = Struct.new(:group_id, :artifact_id, :version, :classifier, :type, :scope, :file) do
|
|
203
|
+
# @return [Boolean] true if scope is neither +test+ nor +provided+
|
|
204
|
+
def runtime?
|
|
205
|
+
scope != 'test' && scope != 'provided'
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
# @return [Boolean] true if scope is +system+
|
|
209
|
+
def system?
|
|
210
|
+
scope == 'system'
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
# Maven repository layout path relative to repo root.
|
|
214
|
+
#
|
|
215
|
+
# @return [String] e.g. +"org/slf4j/slf4j-api/1.7.36/slf4j-api-1.7.36.jar"+
|
|
216
|
+
def path
|
|
217
|
+
parts = group_id.split('.')
|
|
218
|
+
parts << artifact_id
|
|
219
|
+
parts << version
|
|
220
|
+
filename = +"#{artifact_id}-#{version}"
|
|
221
|
+
filename << "-#{classifier}" if classifier
|
|
222
|
+
filename << ".#{type || 'jar'}"
|
|
223
|
+
parts << filename
|
|
224
|
+
File.join(parts)
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
# Formats a line suitable for the +Jars.lock+ file.
|
|
228
|
+
#
|
|
229
|
+
# @return [String] e.g. +"org.slf4j:slf4j-api:1.7.36:compile:"+
|
|
230
|
+
def to_lock_entry
|
|
231
|
+
entry = +"#{group_id}:#{artifact_id}:"
|
|
232
|
+
entry << "#{classifier}:" if classifier
|
|
233
|
+
entry << "#{version}:#{scope}:"
|
|
234
|
+
entry
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
# Colon-separated GAV string suitable for +require_jar+ calls.
|
|
238
|
+
#
|
|
239
|
+
# @return [String] e.g. +"org.slf4j:slf4j-api:1.7.36"+
|
|
240
|
+
def gav
|
|
241
|
+
parts = [group_id, artifact_id]
|
|
242
|
+
parts << classifier if classifier
|
|
243
|
+
parts << version
|
|
244
|
+
parts.join(':')
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
# Relative jar path for vendoring / +require_jar+.
|
|
248
|
+
#
|
|
249
|
+
# @return [String] e.g. +"org/slf4j/slf4j-api/1.7.36/slf4j-api-1.7.36.jar"+
|
|
250
|
+
def jar_path
|
|
251
|
+
parts = group_id.split('.')
|
|
252
|
+
parts << artifact_id
|
|
253
|
+
parts << version
|
|
254
|
+
filename = +"#{artifact_id}-#{version}"
|
|
255
|
+
filename << "-#{classifier}" if classifier
|
|
256
|
+
filename << '.jar'
|
|
257
|
+
parts << filename
|
|
258
|
+
File.join(parts)
|
|
259
|
+
end
|
|
260
|
+
end
|
|
261
|
+
end
|
|
262
|
+
end
|
|
@@ -26,7 +26,6 @@ if defined?(JRUBY_VERSION) && Gem.post_install_hooks.empty?
|
|
|
26
26
|
if ENV['JARS_SKIP'] != 'true' && ENV_JAVA['jars.skip'] != 'true'
|
|
27
27
|
require 'jars/installer'
|
|
28
28
|
jars = Jars::Installer.new(gem_installer.spec)
|
|
29
|
-
jars.ruby_maven_install_options = gem_installer.options || {}
|
|
30
29
|
jars.vendor_jars
|
|
31
30
|
end
|
|
32
31
|
end
|
data/lib/jars/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jar-dependencies
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0.pre2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- christian meier
|
|
8
|
+
autorequire:
|
|
8
9
|
bindir: exe
|
|
9
10
|
cert_chain: []
|
|
10
|
-
date:
|
|
11
|
+
date: 2026-06-30 00:00:00.000000000 Z
|
|
11
12
|
dependencies:
|
|
12
13
|
- !ruby/object:Gem::Dependency
|
|
13
|
-
name: minitest
|
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
|
15
15
|
requirements:
|
|
16
16
|
- - "~>"
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
18
|
version: '5.10'
|
|
19
|
+
name: minitest
|
|
19
20
|
type: :development
|
|
20
21
|
prerelease: false
|
|
21
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -23,20 +24,6 @@ dependencies:
|
|
|
23
24
|
- - "~>"
|
|
24
25
|
- !ruby/object:Gem::Version
|
|
25
26
|
version: '5.10'
|
|
26
|
-
- !ruby/object:Gem::Dependency
|
|
27
|
-
name: ruby-maven
|
|
28
|
-
requirement: !ruby/object:Gem::Requirement
|
|
29
|
-
requirements:
|
|
30
|
-
- - "~>"
|
|
31
|
-
- !ruby/object:Gem::Version
|
|
32
|
-
version: '3.9'
|
|
33
|
-
type: :development
|
|
34
|
-
prerelease: false
|
|
35
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
-
requirements:
|
|
37
|
-
- - "~>"
|
|
38
|
-
- !ruby/object:Gem::Version
|
|
39
|
-
version: '3.9'
|
|
40
27
|
description: |
|
|
41
28
|
manage jar dependencies for gems and keep track which jar was already
|
|
42
29
|
loaded using maven artifact coordinates. it warns on version conflicts and
|
|
@@ -59,20 +46,21 @@ files:
|
|
|
59
46
|
- lib/jar-dependencies.rb
|
|
60
47
|
- lib/jar_dependencies.rb
|
|
61
48
|
- lib/jar_install_post_install_hook.rb
|
|
62
|
-
- lib/jars/attach_jars_pom.rb
|
|
63
49
|
- lib/jars/classpath.rb
|
|
64
50
|
- lib/jars/gemspec_artifacts.rb
|
|
65
|
-
- lib/jars/gemspec_pom.rb
|
|
66
51
|
- lib/jars/installer.rb
|
|
67
52
|
- lib/jars/lock.rb
|
|
68
53
|
- lib/jars/lock_down.rb
|
|
69
|
-
- lib/jars/lock_down_pom.rb
|
|
70
54
|
- lib/jars/maven_exec.rb
|
|
71
|
-
- lib/jars/maven_factory.rb
|
|
72
55
|
- lib/jars/maven_settings.rb
|
|
73
|
-
- lib/jars/
|
|
56
|
+
- lib/jars/mima.rb
|
|
57
|
+
- lib/jars/mima/context-2.4.42.jar
|
|
58
|
+
- lib/jars/mima/jcl-over-slf4j-2.0.17.jar
|
|
59
|
+
- lib/jars/mima/slf4j-api-2.0.17.jar
|
|
60
|
+
- lib/jars/mima/slf4j-simple-2.0.17.jar
|
|
61
|
+
- lib/jars/mima/standalone-static-uber-2.4.42.jar
|
|
62
|
+
- lib/jars/mima/version.rb
|
|
74
63
|
- lib/jars/post_install_hook.rb
|
|
75
|
-
- lib/jars/settings.xml
|
|
76
64
|
- lib/jars/setup.rb
|
|
77
65
|
- lib/jars/version.rb
|
|
78
66
|
- lib/rubygems_plugin.rb
|
|
@@ -81,16 +69,7 @@ licenses:
|
|
|
81
69
|
- MIT
|
|
82
70
|
metadata:
|
|
83
71
|
rubygems_mfa_required: 'true'
|
|
84
|
-
post_install_message:
|
|
85
|
-
|
|
86
|
-
if you want to use the executable lock_jars then install ruby-maven gem before using lock_jars
|
|
87
|
-
|
|
88
|
-
$ gem install ruby-maven -v '~> 3.9'
|
|
89
|
-
|
|
90
|
-
or add it as a development dependency to your Gemfile
|
|
91
|
-
|
|
92
|
-
gem 'ruby-maven', '~> 3.9'
|
|
93
|
-
|
|
72
|
+
post_install_message:
|
|
94
73
|
rdoc_options: []
|
|
95
74
|
require_paths:
|
|
96
75
|
- lib
|
|
@@ -101,11 +80,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
101
80
|
version: '2.6'
|
|
102
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
82
|
requirements:
|
|
104
|
-
- - "
|
|
83
|
+
- - ">"
|
|
105
84
|
- !ruby/object:Gem::Version
|
|
106
|
-
version:
|
|
85
|
+
version: 1.3.1
|
|
107
86
|
requirements: []
|
|
108
|
-
rubygems_version:
|
|
87
|
+
rubygems_version: 3.3.26
|
|
88
|
+
signing_key:
|
|
109
89
|
specification_version: 4
|
|
110
90
|
summary: manage jar dependencies for gems
|
|
111
91
|
test_files: []
|
data/lib/jars/attach_jars_pom.rb
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# this file is maven DSL
|
|
4
|
-
|
|
5
|
-
10_000.times do |i|
|
|
6
|
-
coord = ENV_JAVA["jars.#{i}"]
|
|
7
|
-
break unless coord
|
|
8
|
-
|
|
9
|
-
artifact = Maven::Tools::Artifact.from_coordinate(coord)
|
|
10
|
-
exclusions = []
|
|
11
|
-
10_000.times do |j|
|
|
12
|
-
exclusion = ENV_JAVA["jars.#{i}.exclusions.#{j}"]
|
|
13
|
-
break unless exclusion
|
|
14
|
-
|
|
15
|
-
exclusions << exclusion
|
|
16
|
-
end
|
|
17
|
-
scope = ENV_JAVA["jars.#{i}.scope"]
|
|
18
|
-
artifact.scope = scope if scope
|
|
19
|
-
classifier = ENV_JAVA["jars.#{i}.classifier"]
|
|
20
|
-
artifact.classifier = classifier if classifier
|
|
21
|
-
|
|
22
|
-
# declare the artifact inside the POM
|
|
23
|
-
dependency_artifact(artifact) do
|
|
24
|
-
exclusions.each do |ex|
|
|
25
|
-
exclusion ex
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
data/lib/jars/gemspec_pom.rb
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# this file is maven DSL and used by maven via jars/maven_exec.rb
|
|
4
|
-
|
|
5
|
-
def eval_file(file)
|
|
6
|
-
file = File.join(__dir__, file)
|
|
7
|
-
eval(File.read(file), nil, file) # rubocop:disable Security/Eval
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
eval_file('attach_jars_pom.rb')
|
|
11
|
-
eval_file('output_jars_pom.rb')
|
data/lib/jars/lock_down_pom.rb
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# this file is maven DSL and used by maven via jars/lock_down.rb
|
|
4
|
-
|
|
5
|
-
basedir(ENV_JAVA['jars.basedir'])
|
|
6
|
-
|
|
7
|
-
def eval_file(file)
|
|
8
|
-
file = File.join(__dir__, file)
|
|
9
|
-
eval(File.read(file), nil, file) # rubocop:disable Security/Eval
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
eval_file('attach_jars_pom.rb')
|
|
13
|
-
|
|
14
|
-
jfile = ENV_JAVA['jars.jarfile']
|
|
15
|
-
jarfile(jfile) if jfile
|
|
16
|
-
|
|
17
|
-
# need to fix the version of this plugin for gem:jars_lock goal
|
|
18
|
-
jruby_plugin :gem, ENV_JAVA['jruby.plugins.version']
|
|
19
|
-
|
|
20
|
-
# if you use bundler we collect all root jar dependencies
|
|
21
|
-
# from each gemspec file. otherwise we need to resolve
|
|
22
|
-
# the gemspec artifact in the maven way
|
|
23
|
-
unless ENV_JAVA['jars.bundler']
|
|
24
|
-
begin
|
|
25
|
-
gemspec
|
|
26
|
-
rescue
|
|
27
|
-
nil
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
properties('project.build.sourceEncoding' => 'utf-8')
|
|
32
|
-
|
|
33
|
-
plugin :dependency, ENV_JAVA['dependency.plugin.version']
|
|
34
|
-
|
|
35
|
-
eval_file('output_jars_pom.rb')
|
data/lib/jars/maven_factory.rb
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'jar_dependencies'
|
|
4
|
-
require 'jars/gemspec_artifacts'
|
|
5
|
-
|
|
6
|
-
module Jars
|
|
7
|
-
class MavenFactory
|
|
8
|
-
module AttachJars
|
|
9
|
-
def attach_jars(spec, all_dependencies: false)
|
|
10
|
-
@index ||= 0
|
|
11
|
-
@done ||= []
|
|
12
|
-
|
|
13
|
-
deps = GemspecArtifacts.new(spec)
|
|
14
|
-
deps.artifacts.each do |a|
|
|
15
|
-
# for this gemspec we want to include all artifacts but
|
|
16
|
-
# for all others we want to exclude provided and test artifacts
|
|
17
|
-
next unless !@done.include?(a.key) && (all_dependencies || ((a.scope != 'provided') && (a.scope != 'test')))
|
|
18
|
-
|
|
19
|
-
# ruby dsl is not working reliably for classifier
|
|
20
|
-
self["jars.#{@index}"] = a.to_coord_no_classifier
|
|
21
|
-
if a.exclusions
|
|
22
|
-
jndex = 0
|
|
23
|
-
a.exclusions.each do |ex|
|
|
24
|
-
self["jars.#{@index}.exclusions.#{jndex}"] = ex.to_s
|
|
25
|
-
jndex += 1
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
self["jars.#{@index}.scope"] = a.scope if a.scope
|
|
29
|
-
self["jars.#{@index}.classifier"] = a.classifier if a.classifier
|
|
30
|
-
@index += 1
|
|
31
|
-
@done << a.key
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
attr_reader :debug, :verbose
|
|
37
|
-
|
|
38
|
-
def initialize(options = nil, debug = Jars.debug?, verbose = Jars.verbose?)
|
|
39
|
-
@options = (options || {}).dup
|
|
40
|
-
@options.delete(:ignore_dependencies)
|
|
41
|
-
@debug = debug
|
|
42
|
-
@verbose = verbose
|
|
43
|
-
@installed_maven = false
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def maven_new(pom)
|
|
47
|
-
lazy_load_maven
|
|
48
|
-
maven = setup(Maven::Ruby::Maven.new)
|
|
49
|
-
|
|
50
|
-
maven.extend AttachJars
|
|
51
|
-
# TODO: copy pom to tmp dir in case it is not a real file
|
|
52
|
-
maven.options['-f'] = pom
|
|
53
|
-
maven
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
private
|
|
57
|
-
|
|
58
|
-
def setup(maven)
|
|
59
|
-
maven.verbose = @verbose
|
|
60
|
-
maven.options['-X'] = nil if @debug
|
|
61
|
-
if @verbose
|
|
62
|
-
maven.options['-e'] = nil
|
|
63
|
-
elsif !@debug
|
|
64
|
-
maven.options['--quiet'] = nil
|
|
65
|
-
end
|
|
66
|
-
maven['verbose'] = (@debug || @verbose) == true
|
|
67
|
-
|
|
68
|
-
maven.options['-s'] = Jars::MavenSettings.effective_settings if Jars.maven_settings
|
|
69
|
-
|
|
70
|
-
maven['maven.repo.local'] = java.io.File.new(Jars.local_maven_repo).absolute_path.to_s
|
|
71
|
-
|
|
72
|
-
maven
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def lazy_load_maven
|
|
76
|
-
add_gem_to_load_path('ruby-maven')
|
|
77
|
-
add_gem_to_load_path('ruby-maven-libs')
|
|
78
|
-
if @installed_maven
|
|
79
|
-
puts
|
|
80
|
-
puts 'using maven for the first time results in maven'
|
|
81
|
-
puts 'downloading all its default plugin and can take time.'
|
|
82
|
-
puts 'as those plugins get cached on disk and further execution'
|
|
83
|
-
puts 'of maven is much faster then the first time.'
|
|
84
|
-
puts
|
|
85
|
-
end
|
|
86
|
-
require 'maven/ruby/maven'
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
def find_spec_via_rubygems(name, req)
|
|
90
|
-
require 'rubygems/dependency'
|
|
91
|
-
dep = Gem::Dependency.new(name, req)
|
|
92
|
-
dep.matching_specs(true).last
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
def add_gem_to_load_path(name)
|
|
96
|
-
# if the gem is already activated => good
|
|
97
|
-
return if Gem.loaded_specs[name]
|
|
98
|
-
|
|
99
|
-
# just install gem if needed and add it to the load_path
|
|
100
|
-
# and leave activated gems as they are
|
|
101
|
-
req = requirement(name)
|
|
102
|
-
unless (spec = find_spec_via_rubygems(name, req))
|
|
103
|
-
spec = install_gem(name, req)
|
|
104
|
-
end
|
|
105
|
-
raise "failed to resolve gem '#{name}' if you're using Bundler add it as a dependency" unless spec
|
|
106
|
-
|
|
107
|
-
path = File.join(spec.full_gem_path, spec.require_path)
|
|
108
|
-
$LOAD_PATH << path unless $LOAD_PATH.include?(path)
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
def requirement(name)
|
|
112
|
-
jars = Gem.loaded_specs['jar-dependencies']
|
|
113
|
-
dep = jars&.dependencies&.detect { |d| d.name == name }
|
|
114
|
-
dep.nil? ? Gem::Requirement.create('>0') : dep.requirement
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
def install_gem(name, req)
|
|
118
|
-
@installed_maven = true
|
|
119
|
-
puts "Installing gem '#{name}' . . ."
|
|
120
|
-
require 'rubygems/dependency_installer'
|
|
121
|
-
inst = Gem::DependencyInstaller.new(@options ||= {})
|
|
122
|
-
inst.install(name, req).first
|
|
123
|
-
rescue => e
|
|
124
|
-
if Jars.verbose?
|
|
125
|
-
warn e.inspect
|
|
126
|
-
warn e.backtrace.join("\n")
|
|
127
|
-
end
|
|
128
|
-
raise "there was an error installing '#{name} (#{req})' " \
|
|
129
|
-
"#{@options[:domain]}. please install it manually: #{e.inspect}"
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
|
-
end
|
data/lib/jars/output_jars_pom.rb
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# this file is maven DSL
|
|
4
|
-
|
|
5
|
-
if ENV_JAVA['jars.quiet'] != 'true'
|
|
6
|
-
model.dependencies.each do |d|
|
|
7
|
-
puts " #{d.group_id}:#{d.artifact_id}" \
|
|
8
|
-
"#{d.classifier ? ":#{d.classifier}" : ''}" \
|
|
9
|
-
":#{d.version}:#{d.scope || 'compile'}"
|
|
10
|
-
next if d.exclusions.empty?
|
|
11
|
-
|
|
12
|
-
puts " exclusions: #{d.exclusions.collect do |e|
|
|
13
|
-
"#{e.group_id}:#{e.artifact_id}"
|
|
14
|
-
end.join}"
|
|
15
|
-
end
|
|
16
|
-
end
|
data/lib/jars/settings.xml
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
<proxies>
|
|
2
|
-
<proxy>
|
|
3
|
-
<active>__HTTP_ACTIVE__</active>
|
|
4
|
-
<protocol>http</protocol>
|
|
5
|
-
<host>__HTTP_SERVER__</host>
|
|
6
|
-
<port>__HTTP_PORT__</port>
|
|
7
|
-
<!--nonProxyHosts>
|
|
8
|
-
www.oracle.com|localhost|127.0.0.1
|
|
9
|
-
</nonProxyHosts-->
|
|
10
|
-
</proxy>
|
|
11
|
-
<proxy>
|
|
12
|
-
<active>__HTTPS_ACTIVE__</active>
|
|
13
|
-
<protocol>https</protocol>
|
|
14
|
-
<host>__HTTPS_SERVER__</host>
|
|
15
|
-
<port>__HTTPS_PORT__</port>
|
|
16
|
-
<!--nonProxyHosts>
|
|
17
|
-
www.oracle.com|localhost|127.0.0.1
|
|
18
|
-
</nonProxyHosts-->
|
|
19
|
-
</proxy>
|
|
20
|
-
</proxies>
|