1 | # ------------------------------------------------------------------------------ |
---|
2 | # Copyright (C) 2006-2021 British Crown (Met Office) & Contributors. |
---|
3 | # |
---|
4 | # This file is part of FCM, tools for managing and building source code. |
---|
5 | # |
---|
6 | # FCM is free software: you can redistribute it and/or modify |
---|
7 | # it under the terms of the GNU General Public License as published by |
---|
8 | # the Free Software Foundation, either version 3 of the License, or |
---|
9 | # (at your option) any later version. |
---|
10 | # |
---|
11 | # FCM is distributed in the hope that it will be useful, |
---|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | # GNU General Public License for more details. |
---|
15 | # |
---|
16 | # You should have received a copy of the GNU General Public License |
---|
17 | # along with FCM. If not, see <http://www.gnu.org/licenses/>. |
---|
18 | # ------------------------------------------------------------------------------ |
---|
19 | use strict; |
---|
20 | use warnings; |
---|
21 | # ------------------------------------------------------------------------------ |
---|
22 | package FCM::System::Old; |
---|
23 | use base qw{FCM::Class::CODE}; |
---|
24 | |
---|
25 | use Cwd qw{cwd}; |
---|
26 | use FCM1::Build; |
---|
27 | use FCM1::Config; |
---|
28 | use FCM1::Extract; |
---|
29 | #use FCM1::ExtractConfigComparator; |
---|
30 | use FCM1::Keyword; |
---|
31 | |
---|
32 | my %CLASS_OF = (build => 'FCM1::Build', extract => 'FCM1::Extract'); |
---|
33 | |
---|
34 | my %KEY_OF = ( |
---|
35 | 'archive' => 'ARCHIVE', |
---|
36 | 'clean' => 'CLEAN', |
---|
37 | 'full' => 'FULL', |
---|
38 | 'ignore-lock' => 'IGNORE_LOCK', |
---|
39 | 'jobs' => 'JOBS', |
---|
40 | 'stage' => 'STAGE', |
---|
41 | 'targets' => 'TARGETS', |
---|
42 | ); |
---|
43 | |
---|
44 | __PACKAGE__->class( |
---|
45 | {util => '&'}, |
---|
46 | { init => \&_init, |
---|
47 | action_of => { |
---|
48 | build => sub {_run('build', @_)}, |
---|
49 | config_compare => \&_config_compare, |
---|
50 | extract => sub {_run('extract', @_)}, |
---|
51 | }, |
---|
52 | }, |
---|
53 | ); |
---|
54 | |
---|
55 | sub _init { |
---|
56 | my ($attrib_ref) = @_; |
---|
57 | if (!defined(FCM1::Keyword::get_util())) { |
---|
58 | FCM1::Keyword::set_util($attrib_ref->{util}); |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | sub _config_compare { |
---|
63 | my ($attrib_ref, $option_hash_ref, @args) = @_; |
---|
64 | $attrib_ref->{util}->class_load('FCM1::CmUrl'); |
---|
65 | $attrib_ref->{util}->class_load('FCM1::ExtractConfigComparator'); |
---|
66 | if (exists($option_hash_ref->{verbosity})) { |
---|
67 | FCM1::Config->instance()->verbose($option_hash_ref->{verbosity}); |
---|
68 | } |
---|
69 | my %option = %{$option_hash_ref}; |
---|
70 | if (exists($option{'wiki-format'})) { |
---|
71 | $option{'wiki'} = delete($option{'wiki-format'}); |
---|
72 | } |
---|
73 | my $system = FCM1::ExtractConfigComparator->new({files => \@args, %option}); |
---|
74 | $system->invoke(); |
---|
75 | } |
---|
76 | |
---|
77 | sub _run { |
---|
78 | my ($key, $attrib_ref, $option_hash_ref, @args) = @_; |
---|
79 | if (exists($option_hash_ref->{targets})) { |
---|
80 | @{$option_hash_ref->{targets}} |
---|
81 | = split(qr{:}msx, join(':', @{$option_hash_ref->{targets}})); |
---|
82 | } |
---|
83 | if (exists($option_hash_ref->{verbosity})) { |
---|
84 | FCM1::Config->instance()->verbose($option_hash_ref->{verbosity}); |
---|
85 | } |
---|
86 | my $system = $CLASS_OF{$key}->new(); |
---|
87 | my $path_to_cfg = @args ? $args[0] : cwd(); |
---|
88 | $system->cfg()->src($path_to_cfg); |
---|
89 | my %option_of; |
---|
90 | while (my ($key, $value) = each(%{$option_hash_ref})) { |
---|
91 | if (exists($KEY_OF{$key})) { |
---|
92 | $option_of{$KEY_OF{$key}} = $value; |
---|
93 | } |
---|
94 | } |
---|
95 | $system->invoke(%option_of); |
---|
96 | } |
---|
97 | |
---|
98 | # ------------------------------------------------------------------------------ |
---|
99 | 1; |
---|
100 | __END__ |
---|
101 | |
---|
102 | =head1 NAME |
---|
103 | |
---|
104 | FCM::System::Old |
---|
105 | |
---|
106 | =head1 SYNOPSIS |
---|
107 | |
---|
108 | use FCM::System::Old; |
---|
109 | my $system = FCM::System::Old->new(); |
---|
110 | $system->('extract', \%option, \@args); |
---|
111 | |
---|
112 | =head1 DESCRIPTION |
---|
113 | |
---|
114 | Provides a compatibility layer for obsolete FCM 1 functionalities. |
---|
115 | |
---|
116 | =head1 METHODS |
---|
117 | |
---|
118 | =over 4 |
---|
119 | |
---|
120 | =item $class->new() |
---|
121 | |
---|
122 | Creates and returns an instance of this class. |
---|
123 | |
---|
124 | =item $instance->build(\%option,@args) |
---|
125 | |
---|
126 | Invokes the FCM 1 build system. |
---|
127 | |
---|
128 | =item $instance->config_compare(\%option,@args) |
---|
129 | |
---|
130 | Invokes the FCM 1 cmp-ext-cfg application. |
---|
131 | |
---|
132 | =item $instance->extract(\%option,@args) |
---|
133 | |
---|
134 | Invokes the FCM 1 extract system. |
---|
135 | |
---|
136 | =back |
---|
137 | |
---|
138 | =head1 COPYRIGHT |
---|
139 | |
---|
140 | Copyright (C) 2006-2021 British Crown (Met Office) & Contributors. |
---|
141 | |
---|
142 | =cut |
---|