Class: Maven::Jetty::PomMagic

Inherits:
Ruby::PomMagic
  • Object
show all
Defined in:
lib/maven/jetty/pom_magic.rb

Instance Method Summary collapse

Instance Method Details

#config_dir(dir) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/maven/jetty/pom_magic.rb', line 63

def config_dir( dir )
  if File.exists?( File.join( dir, 'config' ) )
    File.join( dir, 'config' )
  else
    dir
  end
end

#ensure_keystore(dir) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/maven/jetty/pom_magic.rb', line 79

def ensure_keystore( dir )
  target = File.join( target_dir( dir ), 'server.keystore' )
  if !File.exists?( target ) && !File.exists?( File.join( dir, 'src', 'test', 'resources', 'server.keystore' ) )
    store =   File.join( File.dirname( __FILE__ ), "server.keystore" )
    FileUtils.cp( store, target )
  end
end

#ensure_overlays(dir) ⇒ Object



42
43
44
45
46
47
# File 'lib/maven/jetty/pom_magic.rb', line 42

def ensure_overlays( dir )
  target = target_dir( dir )
  Dir[ File.join( File.dirname( __FILE__ ), "override-*-web.xml" ) ].each do |f|
    FileUtils.cp( f, target )
  end
end

#ensure_web_xml(dir, proj, source = File.dirname( __FILE__ ), target = nil) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/maven/jetty/pom_magic.rb', line 49

def ensure_web_xml( dir, proj, source = File.dirname( __FILE__ ), target = nil )
  target ||= File.join( config_dir( dir ), 'web.xml' )
  if !File.exists?( target ) && !File.exists?( File.join( dir, 'src', 'main', 'webapp', 'WEB-INF', 'web.xml' ) )
    flavour = rails?( dir ) ? "rails" : "rack"
    web_xml = File.join( source, "#{flavour}-web.xml" )
    FileUtils.cp( web_xml, target )
    warn "created #{target.sub( /#{dir}\/?/, './' )}"
  end
end

#generate_pom(dir = '.', *args) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/maven/jetty/pom_magic.rb', line 29

def generate_pom( dir = '.', *args )
  proj = JettyProject.new( dir )

  ensure_web_xml( dir, proj )
  ensure_mavenfile( dir, File.dirname( __FILE__ ) )
  ensure_keystore( dir )
  ensure_overlays( dir )

  load_standard_files( dir, proj )

  pom_xml( dir, proj, args )
end

#rails?(dir) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/maven/jetty/pom_magic.rb', line 59

def rails?( dir )
  File.exists? File.join( dir, 'config', 'application.rb' )
end

#target_dir(dir) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/maven/jetty/pom_magic.rb', line 71

def target_dir( dir )
  target = File.join( dir, 'target', 'jetty' )
  unless File.exists?( target )
    FileUtils.mkdir_p target
  end
  target
end