Skip to content

Generate html files at build time #453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
</jar>
</target>

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

<path id="generate.class.path">
<path refid="build.class.path"/>
<pathelement location="build"/>
</path>

<target name="buildhtml" depends="build">
<java classpathref="generate.class.path" classname="org.w3c.css.index.IndexGenerator">
<arg value="."/>
</java>
<java classpathref="generate.class.path" classname="org.w3c.css.index.TranslationTableGenerator">
<arg value="."/>
</java>
</target>

<target name="javacc">
<ant antfile="build.xml" dir="javacc"/>
</target>

<target name="clean" description="Cleans up generated files">
<delete file="${jar.file}"/>
<delete file="${war.file}"/>
<delete>
<fileset dir="." includes="validator.html.*"/>
</delete>
<delete file="translations.html"/>
<delete dir="./build"/>
<delete dir="./javadoc"/>
<delete dir="./tmp"/>
Expand Down
28 changes: 28 additions & 0 deletions org/w3c/css/index/IndexGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}

Expand Down
28 changes: 28 additions & 0 deletions org/w3c/css/index/TranslationTableGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down
Loading