Subversion Repositories DevTools

Rev

Rev 263 | Rev 323 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 263 Rev 281
Line 1... Line 1...
1
########################################################################
1
########################################################################
2
# Copyright ( C ) 2008 ERG Limited, All rights reserved
2
# Copyright ( C ) 2008-2009 ERG Limited, All rights reserved
3
#
3
#
4
# Module name   : jats_rewrite.pl
4
# Module name   : jats_rewrite.pl
5
# Module type   : JATS Utility
5
# Module type   : JATS Utility
6
# Compiler(s)   : Perl
6
# Compiler(s)   : Perl
7
# Environment(s): jats
7
# Environment(s): jats
Line 26... Line 26...
26
 
26
 
27
################################################################################
27
################################################################################
28
#   Option variables
28
#   Option variables
29
#
29
#
30
 
30
 
31
my $VERSION = "1.3.0";                      # Update this
31
my $VERSION = "1.4.0";                      # Update this
32
my $opt_verbose = 0;
32
my $opt_verbose = 0;
33
my $opt_datafile = "";
33
my $opt_datafile = "";
34
my $opt_ofile  = "auto.pl";
34
my $opt_ofile  = "auto.pl";
35
my $opt_infile = "build.pl";
35
my $opt_infile = "build.pl";
36
my $opt_help = 0;
36
my $opt_help = 0;
37
my $opt_errors = 0;
37
my $opt_errors = 0;
38
my $opt_xml;
38
my $opt_xml;
39
my $opt_oldproject;
39
my $opt_oldproject;
40
my $opt_newproject;
40
my $opt_newproject;
41
my $opt_noconfig;
41
my $opt_noconfig;
-
 
42
my $opt_validate;
42
 
43
 
43
#
44
#
44
#   Globals
45
#   Globals
45
#
46
#
46
my %component =  ();
47
my %component =  ();
47
my %component_use =  ();
48
my %component_use =  ();
48
my $not_use_count = 0;
49
my $not_use_count = 0;
49
my $suffix_count = 0;
50
my $suffix_count = 0;
-
 
51
my @pkg_errors;
-
 
52
my @pkg_errors_val;
-
 
53
my $max_pkglen = 10;
50
 
54
 
51
#
55
#
52
#   Known extended fields
56
#   Known extended fields
53
#   Only these values may be configured with the value=tag syntax
57
#   Only these values may be configured with the value=tag syntax
54
#   These may not be used as package names
58
#   These may not be used as package names
Line 57... Line 61...
57
    'releasemanager.releasename' => undef,
61
    'releasemanager.releasename' => undef,
58
    'releasemanager.projectname' => undef,
62
    'releasemanager.projectname' => undef,
59
);
63
);
60
 
64
 
61
my $result = GetOptions (
65
my $result = GetOptions (
62
                "help:+"    => \$opt_help,          # flag, multiple use allowed
66
                "help:+"        => \$opt_help,          # flag, multiple use allowed
63
                "manual:3"  => \$opt_help,          # flag
67
                "manual:3"      => \$opt_help,          # flag
64
                "verbose:+"  => \$opt_verbose,      # flag
68
                "verbose:+"     => \$opt_verbose,       # flag
65
                "config=s"  => \$opt_datafile,      # string
69
                "config=s"      => \$opt_datafile,      # string
66
                "noconfig"  => \$opt_noconfig,      # flag
70
                "noconfig"      => \$opt_noconfig,      # flag
67
                "outfile=s" => \$opt_ofile,         # string
71
                "outfile=s"     => \$opt_ofile,         # string
68
                "infile=s"  => \$opt_infile,        # string
72
                "infile=s"      => \$opt_infile,        # string
69
                "errors"    => \$opt_errors,        # flag
73
                "errors"        => \$opt_errors,        # flag
70
                "xml!"       => \$opt_xml,          # flag
74
                "xml!"          => \$opt_xml,           # flag
71
                "oldproject=s"  => \$opt_oldproject,
75
                "oldproject=s"  => \$opt_oldproject,    # string
72
                "newproject=s"  => \$opt_newproject,
76
                "newproject=s"  => \$opt_newproject,    # string
-
 
77
                "validate"      => \$opt_validate,      # flag
73
                );
78
                );
74
 
79
 
75
#
80
#
76
#   Process help and manual options
81
#   Process help and manual options
77
#
82
#
Line 114... Line 119...
114
    if ( $ opt_newproject );
119
    if ( $ opt_newproject );
115
 
120
 
116
Warning("No project extensions changed")
121
Warning("No project extensions changed")
117
    if ( !$suffix_count && $opt_newproject);
122
    if ( !$suffix_count && $opt_newproject);
118
 
123
 
-
 
124
if ( @pkg_errors || @pkg_errors_val)
-
 
125
{
-
 
126
    ReportError ("Errors encountered in the following packages:");
-
 
127
    ReportError ( @pkg_errors );
-
 
128
    ReportError ( @pkg_errors_val );
-
 
129
    ReportError ( "Package Names and Versions in build files may not match Release Manager");
-
 
130
}
-
 
131
 
119
Error("Unused packages found: $not_use_count")
132
ReportError("Unused packages found: $not_use_count")
120
    if ( $opt_errors && $not_use_count && $opt_datafile);
133
    if ( $opt_errors && $not_use_count && $opt_datafile);
121
 
134
 
122
 
135
 
-
 
136
ErrorDoExit();
123
exit 0;
137
exit 0;
124
 
138
 
125
#-------------------------------------------------------------------------------
139
#-------------------------------------------------------------------------------
126
# Function        : read_config_file
140
# Function        : read_config_file
127
#
141
#
Line 222... Line 236...
222
    #   Display all if verbose
236
    #   Display all if verbose
223
    #
237
    #
224
    if ( $diff || $opt_verbose  )
238
    if ( $diff || $opt_verbose  )
225
    {
239
    {
226
        $title = 'Package' unless ( $title );
240
        $title = 'Package' unless ( $title );
227
        Message( sprintf("%-8s: %-35s, Version: %-15s %1.1s-> %-15s\n", $title, $name ,$version, $diff, $new_version));
241
        Message( sprintf("%-8s: %-${max_pkglen}s, Version: %-15s %1.1s-> %-15s\n", $title, $name ,$version, $diff, $new_version));
228
    }
242
    }
229
}
243
}
230
 
244
 
231
#-------------------------------------------------------------------------------
245
#-------------------------------------------------------------------------------
232
# Function        : process_build_file
246
# Function        : process_build_file
Line 299... Line 313...
299
        if ( m/^\s*BuildPreviousVersion/ )
313
        if ( m/^\s*BuildPreviousVersion/ )
300
        {
314
        {
301
            Error ("BuildPreviousVersion directive before BuildName") unless ( $build_info );
315
            Error ("BuildPreviousVersion directive before BuildName") unless ( $build_info );
302
            m/['"](.*?)['"]/;
316
            m/['"](.*?)['"]/;
303
            my $prev = $1;
317
            my $prev = $1;
-
 
318
            my $new_ver = $opt_validate ? $prev : $build_info->{BUILDVERSION};
304
 
319
 
305
            s/['"](.*?)['"]/'$build_info->{BUILDVERSION}'/;
320
            s/['"](.*?)['"]/'$build_info->{BUILDVERSION}'/;
306
            print_update( 'PrevVer', '', $prev, $build_info->{BUILDVERSION} );
321
            print_update( 'PrevVer', '', $prev, $new_ver );
307
        }
322
        }
308
 
323
 
309
        #
324
        #
310
        #   Process BuildPkgArchive and LinkPkgArchive
325
        #   Process BuildPkgArchive and LinkPkgArchive
311
        if ( m/^\s*LinkPkgArchive/ or m/^\s*BuildPkgArchive/ )
326
        if ( m/^\s*LinkPkgArchive/ or m/^\s*BuildPkgArchive/ )
Line 567... Line 582...
567
            $not_use_count++;
582
            $not_use_count++;
568
        }
583
        }
569
    }
584
    }
570
}
585
}
571
 
586
 
572
 
-
 
573
#-------------------------------------------------------------------------------
587
#-------------------------------------------------------------------------------
574
# Function        : save_package
588
# Function        : save_package
575
#
589
#
576
# Description     : Save the package name and version
590
# Description     : Save the package name and version
577
#
591
#
Line 583... Line 597...
583
sub save_package
597
sub save_package
584
{
598
{
585
    my ($package, $version) = @_;
599
    my ($package, $version) = @_;
586
 
600
 
587
    #
601
    #
-
 
602
    #   Determine longest package name
-
 
603
    #
-
 
604
    my $len = length $package;
-
 
605
    $max_pkglen = $len
-
 
606
        if ( $len > $max_pkglen );
-
 
607
 
-
 
608
    #
588
    #   Split the suffix off the version
609
    #   Split the suffix off the version
589
    #
610
    #
590
    my ($rel, $suf ) = extract_version( $package, $version);
611
    my ($rel, $suf ) = extract_version( $package, $version);
591
 
612
 
592
    Error ("Multiple definitions for $package $version" )
613
    Error ("Multiple definitions for $package $version" )
Line 603... Line 624...
603
}
624
}
604
 
625
 
605
#-------------------------------------------------------------------------------
626
#-------------------------------------------------------------------------------
606
# Function        : get_package
627
# Function        : get_package
607
#
628
#
608
# Description     : get the package version
629
# Description     : Get the package version
-
 
630
#                   Validates package-version if required
-
 
631
#
-
 
632
#                   Does not generate errors, but will generate error information
-
 
633
#                   to be reported later.
609
#
634
#
610
# Inputs          : $package
635
# Inputs          : $package
611
#                   $version ( suffix is used only )
636
#                   $version ( suffix is used only )
612
#
637
#
613
# Returns         : Replacement version
638
# Returns         : Replacement version
Line 642... Line 667...
642
    #
667
    #
643
    #   If a datafile was provided, then the packages MUST be present
668
    #   If a datafile was provided, then the packages MUST be present
644
    #
669
    #
645
    if ( $opt_datafile )
670
    if ( $opt_datafile )
646
    {
671
    {
-
 
672
        unless ( exists $component{$package} )
-
 
673
        {
647
        Error ("No definitions for the package '$package'" )
674
            push @pkg_errors, "No definitions for package '$package'";
648
            unless ( exists $component{$package} );
675
            return $version;
-
 
676
        }
649
 
677
 
650
    #    print Data::Dumper->Dump ( [\%component], ["Component" ]);
678
    #    print Data::Dumper->Dump ( [\%component], ["Component" ]);
651
 
679
 
-
 
680
        unless ( exists $component{$package}{$suf} )
-
 
681
        {
652
        Error ("No definitions for '$package' '$version' '$suf'" )
682
            push @pkg_errors, "No definitions for '$package' '$version' '$suf'";
653
            unless ( exists $component{$package}{$suf} );
683
            return $version;
-
 
684
        }
654
    }
685
    }
655
 
686
 
656
    #
687
    #
657
    #   remove used packages from the "use" hash
688
    #   remove used packages from the "use" hash
658
    #
689
    #
Line 660... Line 691...
660
    delete $component_use{$package} unless ( keys %{$component_use{$package}} );
691
    delete $component_use{$package} unless ( keys %{$component_use{$package}} );
661
 
692
 
662
    #
693
    #
663
    #   Was the suffix real
694
    #   Was the suffix real
664
    #
695
    #
665
    return get_version( $package, $suf, $rel );
696
    my $new_version = get_version( $package, $suf, $rel );
-
 
697
    if ( $opt_validate )
-
 
698
    {
-
 
699
        if ( $new_version ne $version )
-
 
700
        {
-
 
701
            push @pkg_errors_val, sprintf("Validation mismatch: %-${max_pkglen}s, %-15s != %-15s", $package ,$version,  $new_version);
-
 
702
            return $version;
-
 
703
        }
-
 
704
    }
-
 
705
    return $new_version;
666
}
706
}
667
 
707
 
668
#-------------------------------------------------------------------------------
708
#-------------------------------------------------------------------------------
669
# Function        : extract_version
709
# Function        : extract_version
670
#
710
#
Line 815... Line 855...
815
    -newproject         - New project extension (optional)
855
    -newproject         - New project extension (optional)
816
    -infile xxx         - Input file (build.pl)
856
    -infile xxx         - Input file (build.pl)
817
    -outfile xxx        - Output file (auto.pl)
857
    -outfile xxx        - Output file (auto.pl)
818
    -errors             - Generate errors for unused config items
858
    -errors             - Generate errors for unused config items
819
    -xml                - Process a build.xml file
859
    -xml                - Process a build.xml file
-
 
860
    -validate           - Validate dependencies only
820
 
861
 
821
=head1 OPTIONS
862
=head1 OPTIONS
822
 
863
 
823
=over 8
864
=over 8
824
 
865
 
Line 846... Line 887...
846
 
887
 
847
The option is not required if -newproject and -oldproject are specified
888
The option is not required if -newproject and -oldproject are specified
848
 
889
 
849
=item B<-noconfig>
890
=item B<-noconfig>
850
 
891
 
851
This option indiocates that no config file is present and that the output file
892
This option indicates that no config file is present and that the output file
852
is to be created without reference to the configuration.
893
is to be created without reference to the configuration.
853
 
894
 
854
=item B<-oldproject=xxx>
895
=item B<-oldproject=xxx>
855
 
896
 
856
This option, in conjunction with B<-oldproject=xxx> allows the project
897
This option, in conjunction with B<-oldproject=xxx> allows the project
Line 882... Line 923...
882
=item B<-xml>
923
=item B<-xml>
883
 
924
 
884
Process a build.xml file instead of a build.pl file.
925
Process a build.xml file instead of a build.pl file.
885
This option will be set internally if the infile extension is '.xml'
926
This option will be set internally if the infile extension is '.xml'
886
 
927
 
-
 
928
=item B<-validate>
-
 
929
 
-
 
930
This option will validate the build files against the configuration file. This
-
 
931
option is used by build tools to validate dependency information.
-
 
932
 
887
=back
933
=back
888
 
934
 
889
=head1 DESCRIPTION
935
=head1 DESCRIPTION
890
 
936
 
891
This utility is used within the automated build system to rewrite build files
937
This utility is used within the automated build system to rewrite build files