source: LMDZ6/branches/Amaury_dev/tools/fcm/lib/FCM/System.pm

Last change on this file was 5129, checked in by abarral, 5 months ago

Re-add removed by mistake fcm

File size: 7.9 KB
Line 
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# ------------------------------------------------------------------------------
19use strict;
20use warnings;
21# ------------------------------------------------------------------------------
22
23package FCM::System;
24use base qw{FCM::Class::CODE};
25
26use FCM::Util;
27use Scalar::Util qw{reftype};
28
29# Alias
30our $S;
31
32# The (keys) named actions of this class and (values) their implementations.
33our %ACTION_OF = (
34    browse               => _func('misc', sub {$S->browse(@_)}),
35    build                => _func('old' , sub {$S->build(@_)}),
36    config_compare       => _func('old' , sub {$S->config_compare(@_)}),
37    config_parse         => _func('misc', sub {$S->config_parse(@_)}),
38    cm_branch_create     => _func('cm'  , sub {$S->cm_branch_create(@_)}),
39    cm_branch_delete     => _func('cm'  , sub {$S->cm_branch_delete(@_)}),
40    cm_branch_diff       => _func('cm'  , sub {$S->cm_branch_diff(@_)}),
41    cm_branch_info       => _func('cm'  , sub {$S->cm_branch_info(@_)}),
42    cm_branch_list       => _func('cm'  , sub {$S->cm_branch_list(@_)}),
43    cm_commit            => _func('cm'  , sub {$S->cm_commit(@_)}),
44    cm_checkout          => _func('cm'  , sub {$S->cm_checkout(@_)}),
45    cm_check_missing     => _func('cm'  , sub {$S->cm_check_missing(@_)}),
46    cm_check_unknown     => _func('cm'  , sub {$S->cm_check_unknown(@_)}),
47    cm_diff              => _func('cm'  , sub {$S->cm_diff(@_)}),
48    cm_loc_layout        => _func('cm'  , sub {$S->cm_loc_layout(@_)}),
49    cm_merge             => _func('cm'  , sub {$S->cm_merge(@_)}),
50    cm_mkpatch           => _func('cm'  , sub {$S->cm_mkpatch(@_)}),
51    cm_project_create    => _func('cm'  , sub {$S->cm_project_create(@_)}),
52    cm_resolve_conflicts => _func('cm'  , sub {$S->cm_resolve_conflicts(@_)}),
53    cm_switch            => _func('cm'  , sub {$S->cm_switch(@_)}),
54    cm_update            => _func('cm'  , sub {$S->cm_update(@_)}),
55    export_items         => _func('misc', sub {$S->export_items(@_)}),
56    extract              => _func('old' , sub {$S->extract(@_)}),
57    keyword_find         => _func('misc', sub {$S->keyword_find(@_)}),
58    make                 => _func('make', sub {$S->main(@_)}),
59    svn                  => _func('cm'  , sub {$S->svn(@_)}),
60    util                 => sub {$_[0]->{util}},
61);
62# The (keys) named system and their implementation classes.
63our %SYSTEM_CLASS_OF = (
64    cm   => 'FCM::System::CM',
65    old  => 'FCM::System::Old',
66    make => 'FCM::System::Make',
67    misc => 'FCM::System::Misc',
68);
69
70# Creates the class.
71__PACKAGE__->class(
72    {   gui             => '$',
73        system_class_of => {isa => '%', default => {%SYSTEM_CLASS_OF}},
74        system_of       => '%',
75        util            => '&',
76    },
77    {init => \&_init, action_of => {%ACTION_OF}},
78);
79
80# Initialises attributes.
81sub _init {
82    my $attrib_ref = shift();
83    $attrib_ref->{util} = FCM::Util->new();
84}
85
86# Generates main functions.
87sub _func  {
88    my ($name, $code_ref) = @_;
89    sub {
90        my ($attrib_ref, @args) = @_;
91        if (!defined($attrib_ref->{system_of}{$name})) {
92            my $class_name = $attrib_ref->{system_class_of}{$name};
93            $attrib_ref->{util}->class_load($class_name);
94            $attrib_ref->{system_of}{$name} = $class_name->new({
95                gui  => $attrib_ref->{gui},
96                util => $attrib_ref->{util},
97            });
98        }
99        local($S) = $attrib_ref->{system_of}{$name};
100        $code_ref->(@args);
101    };
102}
103
104# ------------------------------------------------------------------------------
1051;
106__END__
107
108=head1 NAME
109
110FCM::System
111
112=head1 SYNOPSIS
113
114    use FCM::System;
115    $fcm = FCM::System->new();
116    # ...
117    $fcm->make(\%option, @args);
118
119=head1 DESCRIPTION
120
121Provides a top level interface to access the functionalities of the FCM system.
122
123=head1 METHODS
124
125=over 4
126
127=item $class->new(\%attrib)
128
129Returns a new instance. It also initialises the utility and sub-system classes.
130The %attrib hash can be used configure the behaviour of the instance:
131
132=over 4
133
134=item event
135
136A CODE to handle event.
137
138=item gui
139
140The GUI geometry of "fcm gui-internal".
141
142=item system_class_of
143
144A HASH to map (keys) sub-system names to (values) their implementation classes.
145See %FCM::System::SYSTEM_CLASS_OF.
146
147=item system_of
148
149A HASH to map (keys) sub-system names to (values) their implementation instances.
150
151=item util
152
153An instance of L<FCM::Util|FCM::Util>.
154
155=back
156
157=item $fcm->browse(\%option,@args)
158
159Invokes a browser to browse the sources in @args.
160
161=item $fcm->build(\%option,@args)
162
163(Obsolete) Invokes the FCM 1 build system.
164
165=item $fcm->config_compare(\%option,@args)
166
167(Obsolete) Compares 2 FCM 1 extract configuration files.
168
169=item $fcm->config_parse(\%option,@args)
170
171Parses a configuration file.
172
173=item $fcm->cm_branch_create(\%option,@args)
174
175Creates of a branch in a project in a Subversion repository with a standard FCM
176layout.
177
178=item $fcm->cm_branch_delete(\%option,@args)
179
180Deletes of a branch in a project in a Subversion repository with a standard FCM
181layout.
182
183=item $fcm->cm_branch_diff(\%option,@args)
184
185Displays the changes between a branch and its parent in a project in a
186Subversion repository with a standard FCM layout.
187
188=item $fcm->cm_branch_info(\%option,@args)
189
190Displays information of a branch in a project in a Subversion repository with a
191standard FCM layout.
192
193=item $fcm->cm_branch_list(\%option,@args)
194
195Lists branches in a project in a Subversion repository with a standard FCM
196layout.
197
198=item $fcm->cm_commit(\%option,@args)
199
200Wraps C<svn commit>.
201
202=item $fcm->cm_checkout(\%option,@args)
203
204Wraps C<svn checkout>.
205
206=item $fcm->cm_check_missing(\%option,@args)
207
208Checks for missing status in a Subversion working copy.
209
210=item $fcm->cm_check_unknown(\%option,@args)
211
212Checks for unknown status in a Subversion working copy.
213
214=item $fcm->cm_diff(\%option,@args)
215
216Wraps C<svn diff>.
217
218=item $fcm->cm_loc_layout(\%option,@args)
219
220Parse and print layout information of each target in @args.
221
222=item $fcm->cm_merge(\%option,@args)
223
224Wraps C<svn merge>.
225
226=item $fcm->cm_mkpatch(\%option,@args)
227
228Creates FCM patches.
229
230=item $fcm->cm_project_create(\%option,@args)
231
232Create a new project in a Subversion repository.
233
234=item $fcm->cm_resolve_conflicts(\%option,@args)
235
236Invokes a graphic merge tool to resolve conflicts.
237
238=item $fcm->cm_switch(\%option,@args)
239
240Wraps C<svn switch>.
241
242=item $fcm->cm_update(\%option,@args)
243
244Wraps C<svn update>.
245
246=item $fcm->export_items(\%option,@args)
247
248Exports directories as versioned items in a branch of a project in a Subversion
249repository with the standard FCM layout.
250
251=item $fcm->extract(\%option,@args)
252
253(Obsolete) Invokes the FCM 1 extract system.
254
255=item $fcm->keyword_find(\%option,@args)
256
257If @args is empty, search for all known FCM location keyword entries. Otherwise,
258search for FCM location keyword entries matching the locations specified in
259@args.
260
261=item $fcm->make(\%option,@args)
262
263Invokes the FCM make system.
264
265=item $fcm->svn(\%option,@args)
266
267Invokes C<svn> with @args. %option is ignored.
268
269=item $fcm->util()
270
271Returns the L<FCM::Util|FCM::Util> object.
272
273=back
274
275=head1 DIAGNOSTICS
276
277=head2 FCM::System::Exception
278
279This exception is a sub-class of L<FCM::Exception|FCM::Exception> and is thrown
280by methods of this class on error.
281
282=head1 COPYRIGHT
283
284Copyright (C) 2006-2021 British Crown (Met Office) & Contributors.
285
286=cut
Note: See TracBrowser for help on using the repository browser.