mkcollections.pl.in 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #!@PERL@
  2. #
  3. # mkcollections.pl - small perl script to convert GNU Classpath's
  4. # Collection classes into its own package for java 1.1
  5. #
  6. # USAGE: mkcollections.pl <Destination-Path>
  7. #
  8. # Copyright (C) 2000 Free Software Foundation, Inc.
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; either version 2, or (at your option)
  13. # any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU General Public License
  21. # along with this program; see the file COPYING. If not, write to
  22. # the Free Software Foundation, 51 Franklin St, Fifth Floor,
  23. # Boston, MA 02110-1301 USA
  24. my $destpath=@COLLECTIONS_PREFIX@;
  25. my $classpath=pop;
  26. my @javalangclasses=qw(UnsupportedOperationException
  27. Comparable
  28. Iterable);
  29. my @javautilclasses=qw(AbstractCollection
  30. AbstractList
  31. AbstractMap
  32. AbstractSequentialList
  33. AbstractSet
  34. ArrayList
  35. Arrays
  36. List
  37. Collection
  38. Collections
  39. Comparator
  40. ConcurrentModificationException
  41. HashMap
  42. HashSet
  43. Hashtable
  44. Iterator
  45. LinkedList
  46. ListIterator
  47. Map
  48. NoSuchElementException
  49. Random
  50. RandomAccess
  51. Set
  52. SortedMap
  53. SortedSet
  54. TreeMap
  55. TreeSet
  56. Vector);
  57. my @externalclasses=qw(AbstractQueue
  58. ArrayDeque
  59. Deque
  60. NavigableMap
  61. NavigableSet
  62. Queue);
  63. my $destPkg = $destpath;
  64. $destPkg =~ s!/!.!g;
  65. my %imports = ( "Collections" => [ "Enumeration" ],
  66. "Hashtable" => [ "Dictionary", "Enumeration" ],
  67. "Vector" => [ "Enumeration" ]);
  68. sub mymkdir ($)
  69. {
  70. my ($dir) = @_;
  71. if ($dir =~ /^(.*)\/\w+$/)
  72. {
  73. $parentdir = "$1";
  74. if (! (-d $parentdir))
  75. {
  76. mymkdir ($parentdir);
  77. }
  78. }
  79. print "$dir";
  80. mkdir ($dir, 0777);
  81. }
  82. sub convert($$$) {
  83. my ($file, $infile, $outfile) = @_;
  84. open (INPUT, "<$infile") || die "Could not open ", $infile, " for reading\n";
  85. my $dir = "$outfile";
  86. $dir =~ /^(.*)\/\S+\.java$/ and
  87. $dir = "$1";
  88. if (! (-d $dir)) {
  89. mymkdir ($dir);
  90. }
  91. open (OUTPUT, ">$outfile") || die "Could not open ", $outfile, " for writing\n";
  92. print OUTPUT <<'EOF';
  93. /* This file was converted from the GNU Classpath Project by a
  94. * perl script, written by Jochen Hoenicke <jochen\@gnu.org>.
  95. */
  96. EOF
  97. while (<INPUT>) {
  98. $_ = "package $destPkg;\n" if ($_ =~ /^package java.(lang|util);$/);
  99. next if $_ =~ /^import java.io.Object.*putStream.*Field;$/;
  100. next if $_ =~ /^import java.io.ObjectStreamField;$/;
  101. for $clazz (@javalangclasses) {
  102. $_ =~ s/java.lang.$clazz/$clazz/g;
  103. }
  104. for $clazz (@javautilclasses) {
  105. $_ =~ s/java.util.$clazz/$clazz/g;
  106. }
  107. for $clazz (@externalclasses) {
  108. $_ =~ s/java.util.$clazz/$clazz/g;
  109. }
  110. $_ =~ s/abstract (interface)/$1/g;
  111. print OUTPUT $_;
  112. if ($_ =~ /^package $destPkg;$/
  113. && exists $imports{$file}) {
  114. for $imp (@{$imports{$file}}) {
  115. print OUTPUT "import java.util.$imp;\n";
  116. }
  117. }
  118. }
  119. close (OUTPUT);
  120. close (INPUT);
  121. }
  122. my $file;
  123. for $file (@javalangclasses) {
  124. my $infile = "$classpath/java/lang/$file.java";
  125. my $outfile = "$destpath/$file.java";
  126. print "$outfile\n";
  127. convert ($file, $infile, $outfile);
  128. }
  129. for $file (@javautilclasses) {
  130. my $infile = "$classpath/java/util/$file.java";
  131. my $outfile = "$destpath/$file.java";
  132. print "$outfile\n";
  133. convert ($file, $infile, $outfile);
  134. }
  135. for $file (@externalclasses) {
  136. my $infile = "$classpath/external/jsr166/java/util/$file.java";
  137. my $outfile = "$destpath/$file.java";
  138. print "$outfile\n";
  139. convert ($file, $infile, $outfile);
  140. }