1:
2    eval 'exec perl -S $0 ${1+"$@"}'
3        if 0;
4#*************************************************************************
5#
6# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7#
8# Copyright 2000, 2010 Oracle and/or its affiliates.
9#
10# OpenOffice.org - a multi-platform office productivity suite
11#
12# This file is part of OpenOffice.org.
13#
14# OpenOffice.org is free software: you can redistribute it and/or modify
15# it under the terms of the GNU Lesser General Public License version 3
16# only, as published by the Free Software Foundation.
17#
18# OpenOffice.org is distributed in the hope that it will be useful,
19# but WITHOUT ANY WARRANTY; without even the implied warranty of
20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21# GNU Lesser General Public License version 3 for more details
22# (a copy is included in the LICENSE file that accompanied this code).
23#
24# You should have received a copy of the GNU Lesser General Public License
25# version 3 along with OpenOffice.org.  If not, see
26# <http://www.openoffice.org/license.html>
27# for a copy of the LGPLv3 License.
28#
29#*************************************************************************
30
31use Cwd;
32use File::Temp qw/ tempfile tempdir /;
33
34my $verbosity = 1;  # will be adjusted to the value of $Env{VERBOSE} below
35
36# platforms which are not supported anymore, and thus can be filtered from the svn:ignore list
37my %obsolete_platforms = (
38    );
39    # (none so far)
40
41# platforms whose output trees should appear in all modules' svn:ignore list
42my @platforms = (
43        "common",
44        "unxlngi6",
45        "unxlngx6",
46        "unxsols4",
47        "unxsolu4",
48        "unxsoli4",
49        "wntmsci12",
50        "unxmacxi",
51        "unxubit8",
52        "unxaixp",
53        "unxbsda",
54        "unxbsdi2",
55        "unxbsdi",
56        "unxbsds",
57        "unxfbsdi",
58        "unxfbsd",
59        "unxfbsdx",
60        "unxhpgr",
61        "unxhpxr",
62        "unxirgm",
63        "unxirxm3",
64        "unxirxm",
65        "unxlnga",
66        "unxlngm68k",
67        "unxlngmips",
68        "unxlngp",
69        "unxlngppc4",
70        "unxlngppc64",
71        "unxlngppc",
72        "unxlngr",
73        "unxlngs3904",
74        "unxlngs390x",
75        "unxlngs",
76        "unxlnxi",
77        "unxmacxp",
78        "unxsogi",
79        "unxsogs"
80    );
81
82
83# .........................................................................
84# retrieves the repository URL of the SVN working copy in the current directory
85sub retrieve_repo_url
86{
87    open( SVN, "svn info 2>&1 |" );
88    my @result = <SVN>;
89    close( SVN );
90
91    foreach (@result)
92    {
93        chomp;
94        next if ( ! /^URL: / );
95        s/^URL: //;
96        return $_;
97    }
98    return undef;
99}
100
101# .........................................................................
102# gets the "modules" below the given SVN repository URL, by calling "svn list"
103sub get_modules
104{
105    my @modules = ();
106
107    open( SVN, "svn list $_ 2>&1 |" );
108    my @result = <SVN>;
109    close( SVN );
110
111    foreach (@result)
112    {
113        chomp;
114        s/\/$//;
115        push @modules, $_;
116    }
117
118    return @modules;
119}
120
121# .........................................................................
122sub set_ignore_property
123{
124    my ($repo_url, @modules) = @_;
125
126    # max length of a module name
127    my $max_len = 0;
128    foreach ( @modules ) { $max_len = length( $_ ) if ( length( $_ ) > $max_len ); }
129
130    my $updated = 0;
131
132    my $current = 0;
133    my $count = $#modules + 1;
134    foreach $module ( @modules )
135    {
136        ++$current;
137
138        # print progress
139        if ( $verbosity > 1 )
140        {
141            my $progress = "$module ";
142            $progress .= "(" . $current . "/" . $count . ")";
143
144            my $dots = 3 + ( $max_len - length($module) );
145            $dots += int( digits( $count ) ) - int( digits( $current ) );
146
147            $progress .= ( "." x $dots );
148            $progress .= " ";
149
150            print STDOUT $progress;
151        }
152        elsif ( $verbosity > 0 )
153        {
154            print STDOUT ".";
155        }
156
157        # retrieve the current ignore list
158        open( SVN, "svn propget svn:ignore $module 2>&1 |" );
159        my @ignore_list = <SVN>;
160        close( SVN );
161
162        # the last item in the list is an empty string, usually. Don't let it confuse the below
163        # code
164        my $supposed_empty = pop @ignore_list;
165        chomp( $supposed_empty );
166        push( @ignore_list, $supposed_empty ) if ( !( $supposed_empty =~ /^$/ ) );
167
168        # filter out obsolte entries
169        my @stripped_ignore_list = ();
170        foreach $ignore_entry (@ignore_list)
171        {
172            chomp( $ignore_entry );
173            next if ( $ignore_entry =~ /^$/ );
174
175            if  (   ( exists $obsolete_platforms{$ignore_entry} )
176                ||  ( exists $obsolete_platforms{"$ignore_entry.pro"} )
177                )
178            {
179                next;
180            }
181            push @stripped_ignore_list, $ignore_entry;
182        }
183        my $removed = $#ignore_list - $#stripped_ignore_list;
184        @ignore_list = @stripped_ignore_list;
185
186        # append the platforms which should appear in the ignore list
187        my %ignore_list = ();
188        foreach (@ignore_list) { $ignore_list{$_} = 1; }
189        foreach $platform_entry ( @platforms )
190        {
191            $ignore_list{$platform_entry} = 1;
192            $ignore_list{"$platform_entry.pro"} = 1;
193        }
194        my @extended_ignore_list = keys %ignore_list;
195        my $added = $#extended_ignore_list - $#ignore_list;
196        @ignore_list = @extended_ignore_list;
197
198        if ( $removed || $added )
199        {
200            # create a temporary file taking the new content of the svn_ignore property
201            my $temp_dir = tempdir( CLEANUP => 1 );
202            my ($fh, $filename) = tempfile( DIR => $dir );
203            open( IGNORE, ">$filename" );
204            print IGNORE join "\n", @ignore_list;
205            close( IGNORE );
206
207            # actually set the property
208            open( SVN, "svn propset -F $filename svn:ignore $module 2>&1 |" );
209
210            ++$updated;
211        }
212
213        # statistics
214        print STDOUT "done (removed/added: $removed/$added)\n" if $verbosity > 1;
215    }
216
217    print STDOUT "\n" if $verbosity eq 1;
218    print STDOUT "$updated module(s) updated\n" if $verbosity > 0;
219}
220
221# .........................................................................
222sub digits
223{
224    my ($number, $base) = @_;
225    $base = 10 if !defined $base;
226    return log($number)/log($base);
227}
228
229# .........................................................................
230# 'main'
231
232# initialize verbosity
233my $verbose = $ENV{VERBOSE};
234if ( defined $verbose )
235{
236    $verbose = uc( $verbose );
237    $verbosity = 2 if ( $verbose eq "TRUE" );
238    $verbosity = 0 if ( $verbose eq "FALSE" );
239}
240
241# work on the current directory
242my $working_copy_root = cwd();
243die "current directory does not contain an SVN working copy" if !-d $working_copy_root . "/\.svn";
244
245# retrieve repository URL
246my $repo_url = retrieve_repo_url();
247die "unable to retrieve repository URL" if !defined $repo_url;
248print STDOUT "repository URL: $repo_url\n" if $verbosity > 1;
249
250# list modules
251my @modules = get_modules( $repo_url );
252print STDOUT "processing " . ( $#modules + 1 ) . " modules\n" if $verbosity > 0;
253
254# process modules, by setting the svn:ignore property
255set_ignore_property( $repo_url, @modules );
256