Class: JBundler::Tree

Inherits:
Object
  • Object
show all
Includes:
Maven::Tools::DSL
Defined in:
lib/jbundler/tree.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Tree

Returns a new instance of Tree



11
12
13
# File 'lib/jbundler/tree.rb', line 11

def initialize( config )
  @config = config
end

Instance Method Details

#show_it(debug = false) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/jbundler/tree.rb', line 15

def show_it( debug = false )
  require 'jbundler'
  jfile = ::Maven::Tools::Jarfile.new( @config.jarfile )
  project = maven do
    basedir( File.dirname( @config.jarfile ) )

    gemfile( @config.gemfile ) if File.exists? @config.gemfile

    jarfile :skip_locked => true

    build.directory = @config.work_dir if @config.work_dir != 'target'
    
    properties( 'project.build.sourceEncoding' => 'utf-8' )
  end

  output = java.io.ByteArrayOutputStream.new
  out = java.io.PrintStream.new( output )
  old = java.lang.System.err
  java.lang.System.err = out

  m = Maven::Ruby::Maven.new( project, '.tree.pom.xml' )
  m.exec( 'org.apache.maven.plugins:maven-dependency-plugin:2.8:tree' )
  result = output.to_string( 'utf-8' ).split( "\n" )
  result = result.each do |line|
    line.gsub!( /\[[^ ]+\] /, '' )
  end
  unless debug
    result = result.select do |line|
      line =~ /^[INFO].*/
    end
  end
  result = result.each do |line|
    line.gsub!( /^.* - /, '' )
  end
  $stdout.puts result.join( "\n" )#.gsub( /^.* - /, '' )#.gsub( /\n\n\n/, "\n" )
ensure
  java.lang.System.err = old
end