jbundler 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +2 -2
- data/lib/commands/abstract_command.rb~ +113 -0
- data/lib/commands/install_with_jars.rb~ +22 -0
- data/lib/commands/nexus.rb~ +38 -0
- data/lib/commands/push.rb~ +38 -0
- data/lib/jars.rb~ +3 -0
- data/lib/jbundler/aether.rb +2 -2
- data/lib/jbundler.jar +0 -0
- data/lib/rubygems_plugin.rb~ +6 -0
- metadata +8 -22
- data/Test.md +0 -0
- data/lib/jbundler/aether.rb~ +0 -68
- data/lib/jbundler/classpath_file.rb~ +0 -207
- data/lib/jbundler/cli.rb~ +0 -5
- data/lib/jbundler/config.rb~ +0 -145
- data/lib/jbundler/gemfile_lock.rb~ +0 -17
- data/lib/jbundler/lazy.rb~ +0 -24
- data/lib/jbundler/maven.rb~ +0 -252
- data/lib/jbundler/maven_gemify3.rb~ +0 -337
- data/lib/jbundler/maven_util.rb~ +0 -46
- data/lib/jbundler/maven_version.rb~ +0 -4
- data/lib/jbundler/mavenfile.rb~ +0 -9
- data/lib/jbundler/pom.rb~ +0 -251
- data/lib/jbundler.rb~ +0 -2
- data/spec/aether_spec.rb~ +0 -101
- data/spec/classpath_file_spec.rb~ +0 -81
- data/spec/maven_util_spec.rb~ +0 -33
- data/spec/mavenfile_spec.rb~ +0 -40
- data/spec/pom_spec.rb~ +0 -40
- data/spec/setup.rb~ +0 -3
data/lib/jbundler/config.rb~
DELETED
@@ -1,145 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
|
-
module JBundler
|
4
|
-
|
5
|
-
# allow yaml config in $HOME/.jbundlerrc and $PWD/.jbundlerrc
|
6
|
-
class AetherConfig
|
7
|
-
|
8
|
-
attr_accessor :verbose, :local_repository, :jarfile, :gemfile, :skip
|
9
|
-
|
10
|
-
def initialize
|
11
|
-
file = '.jbundlerrc'
|
12
|
-
homefile = File.join(ENV['HOME'], file)
|
13
|
-
home_config = YAML.load_file(homefile) if File.exists?(homefile)
|
14
|
-
pwd_config = YAML.load_file(file) if File.exists?(file)
|
15
|
-
@config = (home_config || {}).merge(pwd_config || {})
|
16
|
-
end
|
17
|
-
|
18
|
-
if defined? JRUBY_VERSION
|
19
|
-
def jbundler_env(key)
|
20
|
-
ENV[key.upcase.gsub(/./, '_')] || java.lang.System.getProperty(key.downcase.gsub(/_/, '.')) || @config[key.downcase.sub(/^j?bundler/, '').sub(/./, '_')]
|
21
|
-
end
|
22
|
-
else
|
23
|
-
def jbundler_env(key)
|
24
|
-
ENV[key.upcase.gsub(/./, '_')] || @config[key.downcase.sub(/^j?bundler/, '').sub(/./, '_')]
|
25
|
-
end
|
26
|
-
end
|
27
|
-
private :jbundler_env
|
28
|
-
|
29
|
-
def skip
|
30
|
-
skip = jbundler_env('JBUNDLE_SKIP')
|
31
|
-
# defaults to false
|
32
|
-
@skip ||= skip && skip != 'false'
|
33
|
-
end
|
34
|
-
|
35
|
-
def verbose
|
36
|
-
verbose = jbundler_env('JBUNDLE_VERBOSE')
|
37
|
-
# defaults to false
|
38
|
-
@verbose ||= verbose && verbose != 'false'
|
39
|
-
end
|
40
|
-
|
41
|
-
def jarfile
|
42
|
-
if File.exists?('Mvnfile')
|
43
|
-
warn "'Mvnfile' name is deprecated, please use 'Jarfile' instead"
|
44
|
-
@jarfile = 'Mvnfile'
|
45
|
-
end
|
46
|
-
@jarfile ||= jbundler_env('JBUNDLE_JARFILE') || 'Jarfile'
|
47
|
-
end
|
48
|
-
|
49
|
-
def gemfile
|
50
|
-
@gemfile ||= jbundler_env('BUNDLE_GEMFILE') || 'Gemfile'
|
51
|
-
end
|
52
|
-
|
53
|
-
def classpath_file
|
54
|
-
'.jbundler/classpath.rb'
|
55
|
-
end
|
56
|
-
|
57
|
-
def local_repository
|
58
|
-
# use maven default local repo as default
|
59
|
-
@local_maven_repository ||= (jbundler_env('JBUNDLE_LOCAL_REPOSITORY') ||
|
60
|
-
File.join( ENV['HOME'], ".m2", "repository"))
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
class AetherRuby
|
65
|
-
|
66
|
-
def self.setup_classloader
|
67
|
-
require 'java'
|
68
|
-
|
69
|
-
maven_home = File.dirname(File.dirname(Gem.bin_path('ruby-maven',
|
70
|
-
'rmvn')))
|
71
|
-
# TODO reduce to the libs which are really needed
|
72
|
-
Dir.glob(File.join(maven_home, 'lib', "*jar")).each {|path| require path }
|
73
|
-
begin
|
74
|
-
require 'jbundler.jar'
|
75
|
-
rescue LoadError
|
76
|
-
# allow the classes already be added to the classloader
|
77
|
-
begin
|
78
|
-
java_import 'jbundler.Aether'
|
79
|
-
rescue NameError
|
80
|
-
# assume this happens only when working on the git clone
|
81
|
-
raise "jbundler.jar is missing - maybe you need to build it first ? try\n$ rmvn prepare-package -Dmaven.test.skip\n"
|
82
|
-
end
|
83
|
-
end
|
84
|
-
java_import 'jbundler.Aether'
|
85
|
-
end
|
86
|
-
|
87
|
-
def initialize(config = AetherConfig.new)
|
88
|
-
unless defined? Aether
|
89
|
-
self.class.setup_classloader
|
90
|
-
end
|
91
|
-
@aether = Aether.new(config.local_repository, config.verbose)
|
92
|
-
end
|
93
|
-
|
94
|
-
def add_artifact(coordinate, extension = nil)
|
95
|
-
if extension
|
96
|
-
coord = coordinate.split(/:/)
|
97
|
-
coord.insert(2, extension)
|
98
|
-
@aether.add_artifact(coord.join(":"))
|
99
|
-
else
|
100
|
-
@aether.add_artifact(coordinate)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
def add_repository(name, url)
|
105
|
-
@aether.add_repository(name, url)
|
106
|
-
end
|
107
|
-
|
108
|
-
def resolve
|
109
|
-
@aether.resolve unless artifacts.empty?
|
110
|
-
end
|
111
|
-
|
112
|
-
def classpath
|
113
|
-
if artifacts.empty?
|
114
|
-
''
|
115
|
-
else
|
116
|
-
@aether.classpath
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
def classpath_array
|
121
|
-
classpath.split(/#{File::PATH_SEPARATOR}/)
|
122
|
-
end
|
123
|
-
|
124
|
-
def repositories
|
125
|
-
@aether.repositories
|
126
|
-
end
|
127
|
-
|
128
|
-
def artifacts
|
129
|
-
@aether.artifacts
|
130
|
-
end
|
131
|
-
|
132
|
-
def resolved_coordinates
|
133
|
-
if artifacts.empty?
|
134
|
-
[]
|
135
|
-
else
|
136
|
-
@aether.resolved_coordinates
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
def install(coordinate, file)
|
141
|
-
@aether.install(coordinate, file)
|
142
|
-
end
|
143
|
-
|
144
|
-
end
|
145
|
-
end
|
data/lib/jbundler/lazy.rb~
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
module JBundler
|
2
|
-
module Lazy
|
3
|
-
|
4
|
-
def jar(name, version = '[0,)')
|
5
|
-
aether = aether_new
|
6
|
-
aether.add_artifact("#{name}:#{version}")
|
7
|
-
aether.resolve
|
8
|
-
aehter.classpath.each do |path|
|
9
|
-
puts "add #{path} to classloader"
|
10
|
-
require path
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def jb_config
|
17
|
-
@_jb_c =|| JBundler::AetherConfig.new
|
18
|
-
end
|
19
|
-
|
20
|
-
def aether_new
|
21
|
-
JBundler::AetherRuby.new(jb_config)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/lib/jbundler/maven.rb~
DELETED
@@ -1,252 +0,0 @@
|
|
1
|
-
require 'uri'
|
2
|
-
require 'tempfile'
|
3
|
-
require 'fileutils'
|
4
|
-
require 'set'
|
5
|
-
require 'java'
|
6
|
-
|
7
|
-
# A modified maven_gemify
|
8
|
-
module JBundler
|
9
|
-
|
10
|
-
class Maven3NotFound < StandardError; end
|
11
|
-
|
12
|
-
class Maven
|
13
|
-
attr_reader :repositories
|
14
|
-
|
15
|
-
#repositories should be an array of urls
|
16
|
-
def initialize(*repositories)
|
17
|
-
maven # ensure maven initialized
|
18
|
-
@repositories = Set.new
|
19
|
-
if repositories.length > 0
|
20
|
-
@repositories.merge([repositories].flatten)
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
def add_repository(repository_url)
|
26
|
-
@repositories << repository_url
|
27
|
-
end
|
28
|
-
|
29
|
-
@@verbose = false
|
30
|
-
def self.verbose?
|
31
|
-
@@verbose || $DEBUG
|
32
|
-
end
|
33
|
-
def verbose?
|
34
|
-
self.class.verbose?
|
35
|
-
end
|
36
|
-
def self.verbose=(v)
|
37
|
-
@@verbose = v
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
def self.maven_config
|
42
|
-
@maven_config ||= Gem.configuration["maven"] || {}
|
43
|
-
end
|
44
|
-
def maven_config; self.class.maven_config; end
|
45
|
-
|
46
|
-
def self.java_imports
|
47
|
-
%w(
|
48
|
-
org.codehaus.plexus.classworlds.ClassWorld
|
49
|
-
org.codehaus.plexus.DefaultContainerConfiguration
|
50
|
-
org.codehaus.plexus.DefaultPlexusContainer
|
51
|
-
org.apache.maven.Maven
|
52
|
-
org.apache.maven.repository.RepositorySystem
|
53
|
-
org.apache.maven.execution.DefaultMavenExecutionRequest
|
54
|
-
org.apache.maven.artifact.repository.MavenArtifactRepository
|
55
|
-
org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout
|
56
|
-
org.apache.maven.artifact.repository.ArtifactRepositoryPolicy
|
57
|
-
javax.xml.stream.XMLStreamWriter
|
58
|
-
javax.xml.stream.XMLOutputFactory
|
59
|
-
javax.xml.stream.XMLStreamException
|
60
|
-
).each {|i| java_import i }
|
61
|
-
end
|
62
|
-
|
63
|
-
def self.create_maven
|
64
|
-
require 'java' # done lazily, so we're not loading it all the time
|
65
|
-
bin = nil
|
66
|
-
if ENV['M2_HOME'] # use M2_HOME if set
|
67
|
-
bin = File.join(ENV['M2_HOME'], "bin")
|
68
|
-
else
|
69
|
-
ENV['PATH'].split(File::PATH_SEPARATOR).detect do |path|
|
70
|
-
mvn = File.join(path, "mvn")
|
71
|
-
if File.exists?(mvn)
|
72
|
-
if File.symlink?(mvn)
|
73
|
-
link = File.readlink(mvn)
|
74
|
-
if link =~ /^\// # is absolute path
|
75
|
-
bin = File.dirname(File.expand_path(link))
|
76
|
-
else # is relative path so join with dir of the maven command
|
77
|
-
bin = File.dirname(File.expand_path(File.join(File.dirname(mvn), link)))
|
78
|
-
end
|
79
|
-
else # is no link so just expand it
|
80
|
-
bin = File.expand_path(path)
|
81
|
-
end
|
82
|
-
else
|
83
|
-
nil
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
bin = "/usr/share/maven2/bin" if bin.nil? # OK let's try debian default
|
88
|
-
if File.exists?(bin)
|
89
|
-
@mvn = File.join(bin, "mvn")
|
90
|
-
if Dir.glob(File.join(bin, "..", "lib", "maven-core-3.*jar")).size == 0
|
91
|
-
begin
|
92
|
-
gem 'ruby-maven', ">=0"
|
93
|
-
bin = File.dirname(Gem.bin_path('ruby-maven', "rmvn"))
|
94
|
-
@mvn = File.join(bin, "rmvn")
|
95
|
-
rescue LoadError
|
96
|
-
bin = nil
|
97
|
-
end
|
98
|
-
end
|
99
|
-
else
|
100
|
-
bin = nil
|
101
|
-
end
|
102
|
-
raise Maven3NotFound.new("can not find maven3 installation. install ruby-maven with\n\n\tjruby -S gem install ruby-maven\n\n") if bin.nil?
|
103
|
-
|
104
|
-
warn "Using Maven install at #{bin}" if verbose?
|
105
|
-
|
106
|
-
boot = File.join(bin, "..", "boot")
|
107
|
-
lib = File.join(bin, "..", "lib")
|
108
|
-
ext = File.join(bin, "..", "ext")
|
109
|
-
(Dir.glob(lib + "/*jar") + Dir.glob(boot + "/*jar")).each {|path| require path }
|
110
|
-
|
111
|
-
java.lang.System.setProperty("classworlds.conf", File.join(bin, "m2.conf"))
|
112
|
-
java.lang.System.setProperty("maven.home", File.join(bin, ".."))
|
113
|
-
java_imports
|
114
|
-
|
115
|
-
class_world = ClassWorld.new("plexus.core", java.lang.Thread.currentThread().getContextClassLoader());
|
116
|
-
config = DefaultContainerConfiguration.new
|
117
|
-
config.set_class_world class_world
|
118
|
-
config.set_name "ruby-tools"
|
119
|
-
container = DefaultPlexusContainer.new(config);
|
120
|
-
@@execution_request_populator = container.lookup(org.apache.maven.execution.MavenExecutionRequestPopulator.java_class)
|
121
|
-
|
122
|
-
@@settings_builder = container.lookup(org.apache.maven.settings.building.SettingsBuilder.java_class )
|
123
|
-
container.lookup(Maven.java_class)
|
124
|
-
end
|
125
|
-
|
126
|
-
def self.maven
|
127
|
-
@maven ||= create_maven
|
128
|
-
end
|
129
|
-
def maven; self.class.maven; end
|
130
|
-
|
131
|
-
def self.temp_dir
|
132
|
-
@temp_dir ||=
|
133
|
-
begin
|
134
|
-
d=Dir.mktmpdir
|
135
|
-
at_exit {FileUtils.rm_rf(d.dup)}
|
136
|
-
d
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
def temp_dir
|
141
|
-
self.class.temp_dir
|
142
|
-
end
|
143
|
-
|
144
|
-
def execute(goals, pomFile, props = {})
|
145
|
-
request = DefaultMavenExecutionRequest.new
|
146
|
-
request.set_show_errors(true)
|
147
|
-
|
148
|
-
props.each do |k,v|
|
149
|
-
request.user_properties.put(k.to_s, v.to_s)
|
150
|
-
end
|
151
|
-
request.set_goals(goals)
|
152
|
-
request.set_logging_level 0
|
153
|
-
request.setPom(java.io.File.new(pomFile))
|
154
|
-
if verbose?
|
155
|
-
active_profiles = request.getActiveProfiles.collect{ |p| p.to_s }
|
156
|
-
puts "active profiles:\n\t[#{active_profiles.join(', ')}]"
|
157
|
-
puts "maven goals:"
|
158
|
-
request.goals.each { |g| puts "\t#{g}" }
|
159
|
-
puts "system properties:"
|
160
|
-
request.getUserProperties.map.each { |k,v| puts "\t#{k} => #{v}" }
|
161
|
-
puts
|
162
|
-
end
|
163
|
-
out = java.lang.System.out
|
164
|
-
string_io = java.io.ByteArrayOutputStream.new
|
165
|
-
java.lang.System.setOut(java.io.PrintStream.new(string_io))
|
166
|
-
result = maven.execute request
|
167
|
-
java.lang.System.out = out
|
168
|
-
has_exceptions = false
|
169
|
-
result.exceptions.each do |e|
|
170
|
-
has_exceptions = true
|
171
|
-
e.print_stack_trace
|
172
|
-
string_io.write(e.get_message.to_java_string.get_bytes)
|
173
|
-
end
|
174
|
-
raise string_io.to_s if has_exceptions
|
175
|
-
string_io.to_s
|
176
|
-
end
|
177
|
-
|
178
|
-
def writeElement(xmlWriter,element_name, text)
|
179
|
-
xmlWriter.writeStartElement(element_name.to_java)
|
180
|
-
xmlWriter.writeCharacters(text.to_java)
|
181
|
-
xmlWriter.writeEndElement
|
182
|
-
end
|
183
|
-
|
184
|
-
public
|
185
|
-
|
186
|
-
def generate_classpath(mavenfile = 'Mvnfile', classpathfile = '.jbundler/classpath.rb')
|
187
|
-
|
188
|
-
#to resolve deps and generate a classpath
|
189
|
-
pomfile=File.join(temp_dir,"pom.xml")
|
190
|
-
puts "pomfile=#{pomfile}"
|
191
|
-
out = java.io.BufferedOutputStream.new(java.io.FileOutputStream.new(pomfile.to_java))
|
192
|
-
outputFactory = XMLOutputFactory.newFactory()
|
193
|
-
xmlStreamWriter = outputFactory.createXMLStreamWriter(out)
|
194
|
-
xmlStreamWriter.writeStartDocument
|
195
|
-
xmlStreamWriter.writeStartElement("project".to_java)
|
196
|
-
|
197
|
-
writeElement(xmlStreamWriter,"groupId","org.hokiesuns.mavengemify")
|
198
|
-
writeElement(xmlStreamWriter,"artifactId","mavengemify")
|
199
|
-
writeElement(xmlStreamWriter,"modelVersion","4.0.0")
|
200
|
-
writeElement(xmlStreamWriter,"version","1.0-SNAPSHOT")
|
201
|
-
|
202
|
-
#Repositories
|
203
|
-
if @repositories.length > 0
|
204
|
-
xmlStreamWriter.writeStartElement("repositories".to_java)
|
205
|
-
@repositories.each_with_index {|repo,i|
|
206
|
-
xmlStreamWriter.writeStartElement("repository".to_java)
|
207
|
-
writeElement(xmlStreamWriter,"id","repository_#{i}")
|
208
|
-
writeElement(xmlStreamWriter,"url",repo)
|
209
|
-
xmlStreamWriter.writeEndElement #repository
|
210
|
-
}
|
211
|
-
xmlStreamWriter.writeEndElement #repositories
|
212
|
-
end
|
213
|
-
xmlStreamWriter.writeStartElement("dependencies".to_java)
|
214
|
-
|
215
|
-
|
216
|
-
File.read(mavenfile).each do |line|
|
217
|
-
group_id, artifact_id, version = line.sub(/jar\s+/, '').gsub(/[',]/,'').split(/[\s:]+/)
|
218
|
-
|
219
|
-
xmlStreamWriter.writeStartElement("dependency".to_java)
|
220
|
-
writeElement(xmlStreamWriter,"groupId",group_id)
|
221
|
-
writeElement(xmlStreamWriter,"artifactId",artifact_id)
|
222
|
-
writeElement(xmlStreamWriter,"version",version.to_s)
|
223
|
-
xmlStreamWriter.writeEndElement #dependency
|
224
|
-
|
225
|
-
end
|
226
|
-
|
227
|
-
xmlStreamWriter.writeEndElement #dependencies
|
228
|
-
|
229
|
-
xmlStreamWriter.writeEndElement #project
|
230
|
-
|
231
|
-
xmlStreamWriter.writeEndDocument
|
232
|
-
xmlStreamWriter.close
|
233
|
-
out.close
|
234
|
-
|
235
|
-
puts File.read pomfile
|
236
|
-
|
237
|
-
execute(["dependency:resolve","dependency:build-classpath"],pomfile,{"mdep.outputFile" => "cp.txt","mdep.fileSeparator"=>"/"})
|
238
|
-
|
239
|
-
FileUtils.mkdir_p(File.dirname(classpathfile))
|
240
|
-
File.open(classpathfile, 'w') do |f|
|
241
|
-
path_separator = java.lang.System.getProperty("path.separator").to_s
|
242
|
-
File.read(File.join(temp_dir,"cp.txt")).each do |line|
|
243
|
-
line.split(/#{path_separator}/).each do |path|
|
244
|
-
f.puts "require '#{path}'"
|
245
|
-
end
|
246
|
-
end
|
247
|
-
f.close
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
end
|
252
|
-
end
|