Class: FilterPlugin

Inherits:
Object
  • Object
show all
Extended by:
Plugin, PluginType
Defined in:
lib/mvn2/plugin/filter.plugin.rb

Constant Summary collapse

INFO_LINE_FULL =
'[INFO] ------------------------------------------------------------------------'
BUILD_REGEX =
/(\[(?:\e\S+)?INFO(?:\e\S+)?\] (?:\e\S+)?)Building (?!(jar|war|zip)).*(?:\e\S+)?$/

Class Method Summary collapse

Class Method Details

.def_filter1Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/mvn2/plugin/filter.plugin.rb', line 35

def self.def_filter1
  register(:line_filter, priority: 10) { |_, line|
    info_line_last = Plugins.get_var :info_line_last
    info_line = Plugins.get_var :info_line
    if line.start_with_any?('[INFO] BUILD SUCCESS', '[INFO] Reactor Summary:', '[INFO] BUILD FAILURE')
      str = ''
      str << "#{info_line}\n" unless info_line_last
      str << line << "\n"
      Plugins.set_vars found: true, info_line_last: false
      str
    else
      nil
    end
  }
end

.def_filter2Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/mvn2/plugin/filter.plugin.rb', line 51

def self.def_filter2
  register(:line_filter, priority: 20) { |_, line|
    if line.start_with_any?('[ERROR] COMPILATION ERROR :', 'Results :')
      str = line << "\n"
      Plugins.set_vars found: true, info_line_last: false
      str
    else
      nil
    end
  }
end

.def_filter3Object



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/mvn2/plugin/filter.plugin.rb', line 63

def self.def_filter3
  register(:line_filter, priority: 30) { |_, line|
    found = Plugins.get_var :found
    if found
      str = line << "\n"
      Plugins.set_vars found: true, info_line_last: line.start_with_any?(INFO_LINE_FULL)
      str
    else
      nil
    end
  }
end

.def_filter4Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/mvn2/plugin/filter.plugin.rb', line 76

def self.def_filter4
  register(:line_filter, priority: 40) { |options, line|
    found = Plugins.get_var :found
    if options[:hide_between] && found && line.start_with_any?('Tests run:')
      str = line << "\n\n"
      Plugins.set_vars found: false, info_line_last: false
      if line =~ /^.*Failures:\s+(\d+),.*$/
        Plugins.set_var :failures, $1.to_i
      else
        Plugins.set_var :failures, nil
      end
      str
    else
      nil
    end
  }
end

.def_filter5Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/mvn2/plugin/filter.plugin.rb', line 94

def self.def_filter5
  register(:line_filter, priority: 50) { |options, line|
    info_line_last = Plugins.get_var :info_line_last
    info_line = Plugins.get_var :info_line
    if line.gsub(/\e\[.*?m/, '').chomp == INFO_LINE_FULL
      Plugins.set_var :info_line, line.chomp
      nil
    elsif options[:show_projects] && line =~ BUILD_REGEX
      str = ''
      str << "#{info_line}\n" unless info_line_last
      str << line << "\n"
      str << "#{info_line}\n"
      Plugins.set_var :info_line_last, true
      str
    else
      nil
    end
  }
end

.def_filtersObject



27
28
29
30
31
32
33
# File 'lib/mvn2/plugin/filter.plugin.rb', line 27

def self.def_filters
  def_filter1
  def_filter2
  def_filter3
  def_filter4
  def_filter5
end

.def_optionsObject



20
21
22
23
# File 'lib/mvn2/plugin/filter.plugin.rb', line 20

def self.def_options
  register :option, sym: :hide_between, names: %w(-h --hide-between), desc: 'hide the output between the end of test results (the line starting with "Tests run:") and the next trigger line'
  register :option, sym: :show_projects, names: %w(-j --show-projects), desc: 'show the "Building <project>" lines when outputting'
end

.def_varsObject



11
12
13
14
15
16
# File 'lib/mvn2/plugin/filter.plugin.rb', line 11

def self.def_vars
  register_variable :info_line_last, false
  register_variable :found, false
  register_variable :failures, 0
  register_variable :info_line, ''
end