Skip to content

Commit 52477ad

Browse files
committed
Generate html files at build time
1 parent cbd3400 commit 52477ad

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

build.xml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
</jar>
150150
</target>
151151

152-
<target name="war" depends="build" description="Creates the webapp module">
152+
<target name="war" depends="build, buildhtml" description="Creates the webapp module">
153153
<delete file="${war.file}"/>
154154
<war warfile="${war.file}" webxml="web.xml" basedir="." includes="*html*,favicon.ico,images/**,style/**,scripts/**" excludes="html,css-validator.*">
155155
<classes dir="build"/>
@@ -175,13 +175,31 @@
175175
</java>
176176
</target>
177177

178+
<path id="generate.class.path">
179+
<path refid="build.class.path"/>
180+
<pathelement location="build"/>
181+
</path>
182+
183+
<target name="buildhtml" depends="build">
184+
<java classpathref="generate.class.path" classname="org.w3c.css.index.IndexGenerator">
185+
<arg value="."/>
186+
</java>
187+
<java classpathref="generate.class.path" classname="org.w3c.css.index.TranslationTableGenerator">
188+
<arg value="."/>
189+
</java>
190+
</target>
191+
178192
<target name="javacc">
179193
<ant antfile="build.xml" dir="javacc"/>
180194
</target>
181195

182196
<target name="clean" description="Cleans up generated files">
183197
<delete file="${jar.file}"/>
184198
<delete file="${war.file}"/>
199+
<delete>
200+
<fileset dir="." includes="validator.html.*"/>
201+
</delete>
202+
<delete file="translations.html"/>
185203
<delete dir="./build"/>
186204
<delete dir="./javadoc"/>
187205
<delete dir="./tmp"/>

org/w3c/css/index/IndexGenerator.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
import java.io.OutputStreamWriter;
2323
import java.net.URI;
2424
import java.net.URISyntaxException;
25+
import java.nio.file.Path;
26+
import java.nio.file.Paths;
27+
import java.nio.file.Files;
2528
import java.util.HashMap;
2629
import java.util.Iterator;
2730

@@ -42,6 +45,31 @@ public class IndexGenerator {
4245
* @param args
4346
*/
4447
public static void main(String[] args) {
48+
// 1st argument: output path of the html files
49+
if (args.length != 0 && !args[0].isEmpty())
50+
{
51+
String currentPathToClass = IndexGenerator.class.getResource("").getPath();
52+
try {
53+
Path path = Paths.get(currentPathToClass);
54+
Path outputPath = Paths.get(new File(args[0]).getAbsolutePath().toString());
55+
Path relativeOutputPath = path.relativize(outputPath);
56+
// Overwrite html_files_path so that it is relative to the path (ie. currentPathToClass)
57+
html_files_path = relativeOutputPath.toString() + "/";
58+
if (!outputPath.toFile().exists()) {
59+
System.err.println("Directory doesn't exist:" + outputPath);
60+
System.exit(1);
61+
}
62+
if (!Files.isWritable(outputPath)) {
63+
System.err.println("Directory is not writable: " + outputPath);
64+
System.exit(1);
65+
}
66+
System.out.println("Writing files to " + path.toString() + "/" + html_files_path);
67+
} catch (Exception e)
68+
{
69+
e.printStackTrace();
70+
System.exit(1);
71+
}
72+
}
4573
IndexGenerator.generatesIndex(false);
4674
}
4775

org/w3c/css/index/TranslationTableGenerator.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
import java.io.OutputStreamWriter;
2323
import java.net.URI;
2424
import java.net.URISyntaxException;
25+
import java.nio.file.Path;
26+
import java.nio.file.Paths;
27+
import java.nio.file.Files;
2528
import java.util.ArrayList;
2629
import java.util.Collections;
2730
import java.util.Comparator;
@@ -56,6 +59,31 @@ public class TranslationTableGenerator {
5659
* @param args
5760
*/
5861
public static void main(String[] args) {
62+
// 1st argument: output path of the html files
63+
if (args.length > 0 && !args[0].isEmpty())
64+
{
65+
String currentPathToClass = IndexGenerator.class.getResource("").getPath();
66+
try {
67+
Path path = Paths.get(currentPathToClass);
68+
Path outputPath = Paths.get(new File(args[0]).getAbsolutePath().toString());
69+
Path relativeOutputPath = path.relativize(outputPath);
70+
// Overwrite html_files_path so that it is relative to the path (ie. currentPathToClass)
71+
html_files_path = relativeOutputPath.toString() + "/";
72+
if (!outputPath.toFile().exists()) {
73+
System.err.println("Directory doesn't exist:" + outputPath);
74+
System.exit(1);
75+
}
76+
if (!Files.isWritable(outputPath)) {
77+
System.err.println("Directory is not writable: " + outputPath);
78+
System.exit(1);
79+
}
80+
System.out.println("Writing files to " + path.toString() + "/" + html_files_path);
81+
} catch (Exception e)
82+
{
83+
e.printStackTrace();
84+
System.exit(1);
85+
}
86+
}
5987
TranslationTableGenerator.generateTable();
6088
}
6189

0 commit comments

Comments
 (0)