]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - tests/makemakebuild.pl
Allow bold, italics or underlined for numbers
[SourceForge/phpwiki.git] / tests / makemakebuild.pl
1 #!/usr/bin/perl
2 #  Write out a Makefile and a build.xml file based on the *.inputs files
3 #  in the current directory. Steve Wainstead, April 2001.
4
5 # read in all the input files, loop over each one and build up 
6 # text blocks that we will subsitute into the skeletons for Makefile
7 # and build.xml.
8
9 # reqirements: 
10 #  sun's java sdk, http://java.sun.com/j2se/
11 #  httpunit,       http://httpunit.sf.net
12 #  ant,            http://jakarta.apache.org/builds/jakarta-ant/release/
13
14 # usage:
15 #  copy the httpunit jars to this path or add them to your CLASSPATH
16 #  fix the url below for your server
17 #  run makemakebuild.pl, this creates Makefile (gnu make) and build.xml (ant)
18 #  run make, this compiles the classes and runs ant. 
19 #  if your classpath is wrong run ant separately to test.
20 #  run ant for each test. both ant and make can run independently.
21
22 #my $my_wikiurl = 'http://reini/phpwiki/';  # this will replace steve's url below if defined
23 #-----------------------------------------
24
25 my $ori_wikiurl = 'http://127.0.0.1:8080/~swain/phpwiki/';
26 my @files = <*.inputs>;
27 chomp(@files); # prolly unnecessary, but oh well.
28
29 print "Found ", scalar(@files), " input files.\n";
30
31 foreach $inputfile (@files) {
32   $inputfile =~ m/\.inputs$/;
33   $javafile = "$`.java";
34   $classname = $`;
35   if ($my_wikiurl and ($my_wikiurl ne $ori_wikiurl)) {
36     local $/;
37     open IN, "< $inputfile";
38     $contents = <IN>;
39     `perl -i.orig -pe 's|$ori_wikiurl|$my_wikiurl|' $inputfile` if $contents =~ m|$ori_wikiurl|;
40   }
41
42   $test_make_target_names .= "$javafile ";
43   $test_make_targets .=<<"EOLN";
44 $javafile: $inputfile
45 \tmaketest.pl $inputfile
46
47 EOLN
48
49   $test_ant_targets .= <<"EOLN";
50   <target name="$classname">
51     <echo message="Testing with $classname..."/>
52     <java classname="$classname"></java>
53   </target>
54
55 EOLN
56
57   push @test_dependency_names, $classname;
58
59 }
60
61 $test_dependency_names = join(',', @test_dependency_names);
62
63 #  print <<"SHOW_RESULTS";
64 #    make's targets: $test_make_target_names
65
66 #    make's acutual targets:
67 #  $test_make_targets
68
69 #    ant's target names: $test_dependency_names
70
71 #    ant's targets:
72 #  $test_ant_targets
73
74 #  SHOW_RESULTS
75
76
77 # these are the skeleton files for the Makefile and the build.xml file
78
79 $makefile = <<MAKEFILE_SKEL;
80 # Generate new test classes if their input files have changed.
81 # This makefile is called from an Ant build.xml though you can run
82 # it by hand.
83
84 .SUFFIXES: .inputs .java .class .zip 
85 .PHONY: all clean buildtests dotest
86
87 tests = $test_make_target_names
88
89 # ANT_HOME=P:\\ant # path style os dependent!
90 CLASSPATH="httpunit.jar:Tidy.jar:classes.zip"
91
92 testsrc = \$(wildcard *.inputs)
93 javas   = \$(testsrc:.inputs=.java)
94 classes = \$(javas:.java=.class)
95 tests   = \$(javas:.java=)
96
97 all: buildtests classes.zip dotest
98
99 dotest: \$(classes)
100 \texport CLASSPATH=\$(CLASSPATH)
101 \tant 
102 #\tjava -classpath "\$(CLASSPATH):\${ANT_HOME}\\lib\\ant.jar" -Dant.home="\${ANT_HOME}" org.apache.tools.ant.Main \$(<:.class=)
103
104 buildtests: \$(javas) classes.zip
105
106 classes.zip: \$(classes)
107 \tzip \$@ \$?
108
109 clean:
110 \t-rm -f \$(javas) \$(classes) classes.zip
111
112 %.java : %.inputs
113 \tmaketest.pl \$<
114
115 %.class : %.java
116 \tjavac -classpath httpunit.jar \$<
117
118 MAKEFILE_SKEL
119
120
121 $buildxml = <<"BUILDXML_SKEL";
122 <project name="test" default="all">
123         
124    <target 
125       name="all"
126       depends="init,generate,compile,test">
127    </target>
128
129
130    <target name="init">
131       <tstamp/>
132    </target>
133
134    <target name="generate" depends="init">
135       <exec executable="make">
136          <arg line="buildtests"/>
137       </exec>
138    </target>
139
140
141
142    <target name="compile" depends="generate">
143       <javac srcdir="." destdir="." />
144    </target>
145
146
147    <target name="test" depends="compile,$test_dependency_names">
148    </target>
149
150
151    <target name="clean">
152
153       <exec executable="make">
154          <arg line="clean"/>
155       </exec>
156
157       <delete>
158          <fileset dir="." includes="*.class"/>
159       </delete>
160
161    </target>
162
163
164    <!-- individual test files are compiled here -->
165
166 $test_ant_targets
167
168 </project>
169 BUILDXML_SKEL
170
171
172 print "Writing Makefile...\n";
173 open MAKEFILE, ">./Makefile" or die $!;
174 print MAKEFILE $makefile;
175
176 print "Writing build.xml...\n";
177 open BUILDXML, ">./build.xml" or die $!;
178 print BUILDXML $buildxml;
179
180 print "Done.\n";