Class: SiteAndEclipsePluginHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/mavenReactorService/SiteAndEclipsePluginHandler.rb

Constant Summary collapse

@@reactorHandler =
ReactorHandler.new
@@mvnReactorization =
MvnReactorization.new
@@dependencyHandler =
DependencyHandler.new

Instance Method Summary collapse

Instance Method Details

#findPluginfromOriginalPom(pluginName, pom_document) ⇒ Object



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
53
54
55
56
57
58
59
60
# File 'lib/mavenReactorService/SiteAndEclipsePluginHandler.rb', line 28

def findPluginfromOriginalPom(pluginName,pom_document)
  flag=false
  pom_document.css("project/build/plugins/plugin").each do |eachplugin|
    gid=nil
    if (!eachplugin.at("groupId").nil? and eachplugin.at("groupId").parent.name == "plugin")
      gid =  eachplugin.at("groupId").text
    else
      gid = "org.apache.maven.plugins"
    end
    artifactId =  eachplugin.at("artifactId").text
    pluginCordinate = "#{gid}:#{artifactId}"
    if (pluginName == pluginCordinate)
      if (eachplugin.at("version").nil? or eachplugin.at("version").parent.name != "plugin")
        version = searchVersionInPom(pluginName,pom_document,"project/build/pluginManagement/plugins/plugin")
        if version.nil?
          version = searchVersionInPom(pluginName,pom_document,"project/build/plugins/plugin")
        end
        if version.nil?
          effective_pom_document =  @@reactorHandler.parse_xml_from_file("effective_pom.xml")
          version = searchVersionInPom(pluginName,effective_pom_document,"project/build/pluginManagement/plugins/plugin")
          if version.nil?
             version = searchVersionInPom(pluginName,effective_pom_document,"project/build/plugins/plugin")
          end

        end
        insertVersioninPlugin(eachplugin,version)
      end
      writePluginInTemp(eachplugin)
      flag=true
    end
  end
  return flag
end

#findPluginfromParentPom(pluginName, pom_document) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/mavenReactorService/SiteAndEclipsePluginHandler.rb', line 62

def findPluginfromParentPom(pluginName,pom_document)
  parent = pom_document.at("project/parent")
  if !parent.nil?
    parent_pom_document =  @@dependencyHandler.getParentPomDomObjFromUrl(pom_document)
    findPluginfromOriginalPom(pluginName,parent_pom_document)
  end
end

#insertVersioninPlugin(pluginNode, version) ⇒ Object



70
71
72
73
74
75
# File 'lib/mavenReactorService/SiteAndEclipsePluginHandler.rb', line 70

def insertVersioninPlugin(pluginNode,version)
  nokObj = Nokogiri::XML::Node
  versionNode = nokObj.new("version",pluginNode)
  versionNode.content=version
  pluginNode.add_child(versionNode)
end

#managePlugins(project_directory, pluginName) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mavenReactorService/SiteAndEclipsePluginHandler.rb', line 5

def managePlugins(project_directory,pluginName)
  temp_document =  @@reactorHandler.parse_xml_from_file("temp.xml")
  pom_document =  @@reactorHandler.parse_xml_from_file("pom.xml")
  temp_document.css("project/build/plugins/plugin").each do |eachplugin|
    gid=nil
    if (!eachplugin.at("groupId").nil? and eachplugin.at("groupId").parent.name == "plugin")
      gid =  eachplugin.at("groupId").text
    else
      gid = "org.apache.maven.plugins"
    end
    artifactId =  eachplugin.at("artifactId").text
    pluginCordinate = "#{gid}:#{artifactId}"
    if (pluginName == pluginCordinate)
      eachplugin.remove
      @@mvnReactorization.write_nokogiri_to_xml("temp.xml", temp_document)
      isPluginFound =  findPluginfromOriginalPom(pluginName,pom_document)
      if !isPluginFound
        findPluginfromParentPom(pluginName,pom_document)
      end
    end
  end
end

#searchVersionInPom(pluginName, pom_document, tag) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/mavenReactorService/SiteAndEclipsePluginHandler.rb', line 77

def searchVersionInPom(pluginName,pom_document,tag)
  version = nil
  pom_document.css(tag).each do |eachplugin|
    gid=nil
    if (!eachplugin.at("groupId").nil? and eachplugin.at("groupId").parent.name == "plugin")
      gid =  eachplugin.at("groupId").text
    else
      gid = "org.apache.maven.plugins"
    end
    artifactId =  eachplugin.at("artifactId").text
    pluginCordinate = "#{gid}:#{artifactId}"
    if (pluginName == pluginCordinate)
      if (!eachplugin.at("version").nil? and eachplugin.at("version").parent.name == "plugin")
        version = eachplugin.at("version").text
      end
    end
  end
  return version
end

#writePluginInTemp(pluginNode) ⇒ Object



97
98
99
100
101
102
103
# File 'lib/mavenReactorService/SiteAndEclipsePluginHandler.rb', line 97

def writePluginInTemp(pluginNode)
  temp_document =  @@reactorHandler.parse_xml_from_file("temp.xml")
  @@dependencyHandler.add_node_element("project/build/plugins",pluginNode,temp_document)
  toalPom =  temp_document.to_s
  toalPom = toalPom.sub("<plugin xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns=\"http://maven.apache.org/POM/4.0.0\">","<plugin>")
  File.write("temp.xml", toalPom)
end