Sha256: e57681d50074ed63bcf7798df847d06a55733fd4038a743af2cd7f4ffc762398

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

require 'nokogiri'

def add_dependency( dep ) 
  pom = pom_xml
  dependencies = dependenciesFrom pom
  addNodes dependencies, dependency( pom , dep ) 
  pom
end

def parse( arg )
  array = arg.split ':'
  { :groupId => array[0], :artifactId => array[1], :version => array[2] }
end 

def pom_xml
  Nokogiri.XML File.open 'pom.xml'
end

def dependenciesFrom( pom )
  pom.css("dependencies")[0]
end

def simpleNode(pom, name, value=''  )
  node = Nokogiri::XML::Node.new name.to_s, pom
  node.content = value
  node  
end

def addNodes( parent, *children )
  children.each { |c| parent.children.last.add_next_sibling c }
end

def dependency(pom, contents)
  artifactId = simpleNode pom, :artifactId, contents[:artifactId]
  groupId = simpleNode pom, :groupId, contents[:groupId]
  version = simpleNode pom, :version, contents[:version]
  dep = simpleNode pom, :dependency
  addNodes dep, artifactId, groupId, version
  dep 
end

def savePom( pom )
  file = File.open 'pom.xml', 'w+'
  file.write pom.to_xml
  file.close
end

savePom add_dependency( parse ARGV[0] )


 

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pedit-0.1.0 lib/pedit.rb