1 package org.unicode.cldr.tool; 2 3 import java.io.File; 4 import java.io.IOException; 5 import java.nio.file.Files; 6 import java.nio.file.Path; 7 import java.nio.file.StandardCopyOption; 8 import org.unicode.cldr.util.CLDRPaths; 9 10 public class GenerateKeyboardCharts { 11 12 static final String SUBDIR = "keyboards"; 13 main(String args[])14 public static void main(String args[]) throws IOException { 15 final File mainDir = new File(CLDRPaths.CHART_DIRECTORY); 16 if (mainDir.mkdirs()) { 17 System.err.println("Created: " + mainDir); 18 } 19 if (!mainDir.isDirectory()) { 20 throw new IOException("Main dir doesn't exist: " + mainDir); 21 } 22 final File kbdDir = new File(CLDRPaths.BASE_DIRECTORY, "docs/charts/" + SUBDIR); 23 if (!kbdDir.exists()) { 24 throw new IOException("Keyboards root dir doesn't exist: " + kbdDir); 25 } 26 final File kbdStatic = new File(kbdDir, "static"); 27 final File kbdStaticData = new File(kbdDir, "static/data"); 28 if (!kbdStaticData.exists()) { 29 System.err.println( 30 "ERROR: " + kbdStaticData + " does not exist. Keyboard charts weren't run."); 31 System.err.println("See " + new File(kbdDir, "README.md") + " for help."); 32 return; 33 } 34 final File staticTarg = new File(mainDir, SUBDIR + "/static"); 35 final File staticDataTarg = new File(mainDir, SUBDIR + "/static/data"); 36 if (staticDataTarg.mkdirs()) { 37 System.err.println("Created: " + staticDataTarg); 38 } 39 System.out.println("Copying: " + kbdStatic + " to " + staticTarg); 40 41 Files.copy( 42 new File(kbdDir, "index.html").toPath(), 43 new File(mainDir, SUBDIR + "/index.html").toPath(), 44 StandardCopyOption.REPLACE_EXISTING); 45 final String kbdStaticPrefix = kbdStatic.getAbsolutePath(); 46 Files.walk(kbdStatic.toPath()) 47 .forEach( 48 path -> { 49 if (!path.toFile().isFile()) return; 50 path.getParent().toFile().mkdirs(); 51 52 System.out.println(path.toFile().getAbsolutePath()); 53 /** path from static prefix */ 54 final String rel = 55 path.toFile() 56 .getAbsolutePath() 57 .substring(kbdStaticPrefix.length()); 58 try { 59 final Path out = new File(staticTarg, rel).toPath(); 60 System.out.println(" -> " + out); 61 Files.copy(path, out, StandardCopyOption.REPLACE_EXISTING); 62 } catch (IOException e) { 63 e.printStackTrace(); 64 System.err.println("Error copying " + path); 65 System.exit(1); 66 } 67 }); 68 } 69 } 70