From 529cd6742cae826916d777f48a45de40e83a9ae4 Mon Sep 17 00:00:00 2001 From: tenzap Date: Sun, 29 Jun 2025 19:48:33 +0200 Subject: [PATCH] Generate html files at build time --- build.xml | 16 ++++++++++- org/w3c/css/index/IndexGenerator.java | 28 +++++++++++++++++++ .../css/index/TranslationTableGenerator.java | 28 +++++++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/build.xml b/build.xml index 417780e63..c41da2bdd 100644 --- a/build.xml +++ b/build.xml @@ -149,7 +149,7 @@ - + @@ -175,6 +175,20 @@ + + + + + + + + + + + + + + diff --git a/org/w3c/css/index/IndexGenerator.java b/org/w3c/css/index/IndexGenerator.java index 924c56654..e9bb8ce35 100644 --- a/org/w3c/css/index/IndexGenerator.java +++ b/org/w3c/css/index/IndexGenerator.java @@ -22,6 +22,9 @@ import java.io.OutputStreamWriter; import java.net.URI; import java.net.URISyntaxException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.Files; import java.util.HashMap; import java.util.Iterator; @@ -42,6 +45,31 @@ public class IndexGenerator { * @param args */ public static void main(String[] args) { + // 1st argument: output path of the html files + if (args.length != 0 && !args[0].isEmpty()) + { + String currentPathToClass = IndexGenerator.class.getResource("").getPath(); + try { + Path path = Paths.get(currentPathToClass); + Path outputPath = Paths.get(new File(args[0]).getAbsolutePath().toString()); + Path relativeOutputPath = path.relativize(outputPath); + // Overwrite html_files_path so that it is relative to the path (ie. currentPathToClass) + html_files_path = relativeOutputPath.toString() + "/"; + if (!outputPath.toFile().exists()) { + System.err.println("Directory doesn't exist:" + outputPath); + System.exit(1); + } + if (!Files.isWritable(outputPath)) { + System.err.println("Directory is not writable: " + outputPath); + System.exit(1); + } + System.out.println("Writing files to " + path.toString() + "/" + html_files_path); + } catch (Exception e) + { + e.printStackTrace(); + System.exit(1); + } + } IndexGenerator.generatesIndex(false); } diff --git a/org/w3c/css/index/TranslationTableGenerator.java b/org/w3c/css/index/TranslationTableGenerator.java index 3153bdd8c..0eae3144c 100644 --- a/org/w3c/css/index/TranslationTableGenerator.java +++ b/org/w3c/css/index/TranslationTableGenerator.java @@ -22,6 +22,9 @@ import java.io.OutputStreamWriter; import java.net.URI; import java.net.URISyntaxException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -56,6 +59,31 @@ public class TranslationTableGenerator { * @param args */ public static void main(String[] args) { + // 1st argument: output path of the html files + if (args.length > 0 && !args[0].isEmpty()) + { + String currentPathToClass = IndexGenerator.class.getResource("").getPath(); + try { + Path path = Paths.get(currentPathToClass); + Path outputPath = Paths.get(new File(args[0]).getAbsolutePath().toString()); + Path relativeOutputPath = path.relativize(outputPath); + // Overwrite html_files_path so that it is relative to the path (ie. currentPathToClass) + html_files_path = relativeOutputPath.toString() + "/"; + if (!outputPath.toFile().exists()) { + System.err.println("Directory doesn't exist:" + outputPath); + System.exit(1); + } + if (!Files.isWritable(outputPath)) { + System.err.println("Directory is not writable: " + outputPath); + System.exit(1); + } + System.out.println("Writing files to " + path.toString() + "/" + html_files_path); + } catch (Exception e) + { + e.printStackTrace(); + System.exit(1); + } + } TranslationTableGenerator.generateTable(); }