~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to nbbuild/misc/bundlecheck.pl

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env perl
 
2
# -*- perl -*-
 
3
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
4
#
 
5
# Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
6
#
 
7
# The contents of this file are subject to the terms of either the GNU
 
8
# General Public License Version 2 only ("GPL") or the Common
 
9
# Development and Distribution License("CDDL") (collectively, the
 
10
# "License"). You may not use this file except in compliance with the
 
11
# License. You can obtain a copy of the License at
 
12
# http://www.netbeans.org/cddl-gplv2.html
 
13
# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
 
14
# specific language governing permissions and limitations under the
 
15
# License.  When distributing the software, include this License Header
 
16
# Notice in each file and include the License file at
 
17
# nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
 
18
# particular file as subject to the "Classpath" exception as provided
 
19
# by Sun in the GPL Version 2 section of the License file that
 
20
# accompanied this code. If applicable, add the following below the
 
21
# License Header, with the fields enclosed by brackets [] replaced by
 
22
# your own identifying information:
 
23
# "Portions Copyrighted [year] [name of copyright owner]"
 
24
#
 
25
# Contributor(s):
 
26
#
 
27
# The Original Software is NetBeans. The Initial Developer of the Original
 
28
# Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
 
29
# Microsystems, Inc. All Rights Reserved.
 
30
#
 
31
# If you wish your version of this file to be governed by only the CDDL
 
32
# or only the GPL Version 2, indicate your decision by adding
 
33
# "[Contributor] elects to include this software in this distribution
 
34
# under the [CDDL or GPL Version 2] license." If you do not indicate a
 
35
# single choice of license, a recipient has the option to distribute
 
36
# your version of this file under either the CDDL, the GPL Version 2 or
 
37
# to extend the choice of license to its licensees as provided above.
 
38
# However, if you add GPL Version 2 code and therefore, elected the GPL
 
39
# Version 2 license, then the option applies only if the new code is
 
40
# made subject to such option by the copyright holder.
 
41
 
 
42
require 5.005;
 
43
use File::Find;
 
44
 
 
45
my @files = ();
 
46
my $quiet = 0;
 
47
 
 
48
if ($#ARGV < 0) {
 
49
    die "usage: $0 [-q] file | directory ...\n";
 
50
}
 
51
 
 
52
if ($ARGV[0] eq "-q") {
 
53
    $quiet = 1;
 
54
    shift @ARGV;
 
55
}
 
56
 
 
57
foreach my $name (@ARGV) {
 
58
    if (-f $name) {
 
59
        push @files, $name;
 
60
    } elsif (-d $name) {
 
61
        find(sub {
 
62
                 if (-f && m,\.java$, || -f && m,\bBundle.properties$,) {
 
63
                     push @files, $File::Find::name;
 
64
                 }
 
65
             },
 
66
             $name);
 
67
    }
 
68
}
 
69
 
 
70
#
 
71
# read Bundle.properties
 
72
#
 
73
 
 
74
@props = ();
 
75
 
 
76
foreach $f (@files) {
 
77
    next if $f !~ m,\bBundle.properties$,i;
 
78
 
 
79
    print STDERR "*** $f\n" unless $quiet;
 
80
    
 
81
    open FH, "< $f" or die;
 
82
    {
 
83
        local $/ = undef;
 
84
        $all = <FH>;
 
85
    }
 
86
    close FH;
 
87
 
 
88
    @lines = split /\r\n|\n|\r/, $all;
 
89
    for ($lineno = 0; $lineno <= $#lines; $lineno++) {
 
90
        $_ = $lines[$lineno];
 
91
        
 
92
        next if /^\s*#/;
 
93
        next if /^\s*$/;
 
94
 
 
95
        if (m,^([^=]+)=(.*)$,) {
 
96
            $k = $1;
 
97
            $k =~ s,\\ , ,g;
 
98
            push @props, { key => $k,
 
99
                           file => $f,
 
100
                           lineno => $lineno + 1,
 
101
                           line => $_,
 
102
                           used => 0
 
103
                         };
 
104
        }
 
105
 
 
106
        while (m,\\$, && $lineno <= $#lines) {
 
107
            $lineno++;
 
108
            $_ = $lines[$lineno];
 
109
        }
 
110
    }
 
111
}
 
112
 
 
113
#
 
114
# go through *.java
 
115
#
 
116
  
 
117
  
 
118
foreach $f (@files) {
 
119
    next if $f =~ m,\bBundle.properties$,i;
 
120
 
 
121
    print STDERR "*** $f\n" unless $quiet;
 
122
    
 
123
    open FH, "< $f" or die;
 
124
    {
 
125
        local $/ = undef;
 
126
        $all = <FH>;
 
127
    }
 
128
    close FH;
 
129
 
 
130
    foreach $p (@props) {
 
131
        next if $p->{used} > 0;
 
132
        $pat = $p->{key};
 
133
        $pat = quotemeta $pat;
 
134
        $p->{used}++ if $all =~ m,\"$pat\",;
 
135
    }
 
136
}
 
137
 
 
138
foreach $p (@props) {
 
139
    next if $p->{line} =~ m!/!; # probably a filename localization, not in Java code
 
140
    next if $p->{line} =~ m!^OpenIDE-Module-!; # manifest localization, not in Java code
 
141
    print "$p->{file}:$p->{lineno}: $p->{line}\n" if $p->{used} == 0;
 
142
}