blob: 2f7e184d451980cc8c019abc15cac271deb937e7 [file] [log] [blame]
Richard S. Hall85bafab2009-07-13 13:25:46 +00001#!/bin/sh
2
3# Licensed to the Apache Software Foundation (ASF) under one
4# or more contributor license agreements. See the NOTICE file
5# distributed with this work for additional information
6# regarding copyright ownership. The ASF licenses this file
7# to you under the Apache License, Version 2.0 (the
8# "License"); you may not use this file except in compliance
9# with the License. You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing,
14# software distributed under the License is distributed on an
15# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16# KIND, either express or implied. See the License for the
17# specific language governing permissions and limitations
18# under the License.
19
20# sigilgen build.xml ..
21
22function a2s() {
23 find ${1:?} -name '*.java' -o -name '*.spring' -o -name '*.sca' |
24 perl -e '
25 use strict;
26 use FileHandle;
27
28 my %imports;
29 my %exports;
30
31 while (<>) {
32 chomp($_);
33 my $path = $_;
34 my $fh = new FileHandle($path);
35
36 my $testFile = ($path =~ m!Test[^/]+$!);
37
38 while (my $line = <$fh>) {
39 chomp($line);
40
41 if ($line =~ /^\s*package\s+([\w.]+)\s*;\s*$/) {
42 my $exp = $1;
43 if (!($testFile && ($exp !~ /^test[.]/))) {
44 $exports{$exp} = 1;
45 }
46 }
47 elsif ($line =~ /^\s*import\s+([a-z_0-9.]+)([.][A-Z][^.]+)+;\s*$/) {
48 my $imp = $1;
49 $imports{$imp} = 1 unless ($imp =~ /^java[.]/);
50 }
51 elsif (($line !~ m!^\s*(//|\*|\@)!) &&
52 ($line =~ /(\W)((([a-z0-9]{2,})[.]){3,})[A-Z]/)) {
53 my $quot = $1;
54 my $imp = $2;
55 $imp =~ s/.$//;
56
57 if (($imp !~ /^java[.]/) &&
58 ($quot ne "\"" || ($path !~ /[.]java$/))) {
59 $imports{$imp} = 1;
60 }
61 }
62 }
63 $fh->close();
64 }
65
66 if (keys(%exports) == () && keys(%imports) == ()) {
67 exit(1);
68 }
69
70 print "-exports: \\\n";
71 foreach my $key (sort keys(%exports)) {
72 print "\t$key, \\\n";
73 }
74 print "\n";
75
76 print "-imports: \\\n";
77 foreach my $key (sort keys(%imports)) {
78 print "\t$key, \\\n";
79 }
80 print "\n";
81
82 exit(0);
83 '
84 return $?
85}
86
87for file in $*; do
88 echo "converting $file"
89 name=$(perl -ne 'print $1 if (/project name="([^"]*)"/);' $file)
90 dir=$(dirname $file)
91
92 if [ -f $dir/sigil.properties ]; then
93 rm -f $dir/sigil.properties.old
94 mv $dir/sigil.properties $dir/sigil.properties.old
95 fi
96
97 (
98 echo "# generated by sigilgen on $(date)"
99 echo
100 echo "-bundles: $name"
101 echo
102 a2s $dir && mv $dir/sigil.properties-part $dir/sigil.properties
103 ) > $dir/sigil.properties-part
104
105 rm -f $dir/sigil.properties-part
106
107done