1 package org.unicode.cldr.tool; 2 3 import java.io.File; 4 import java.io.FileNotFoundException; 5 import java.io.IOException; 6 import java.nio.file.Path; 7 8 import org.unicode.cldr.util.CLDRPaths; 9 import org.unicode.cldr.util.CLDRTool; 10 11 @CLDRTool(alias = "checkout-archive", description = "Checkout CLDR archive to $ARCHIVE (usually ../cldr-archive)") 12 public class CheckoutArchive { main(String args[])13 public static void main(String args[]) throws IOException, InterruptedException { 14 Path archiveDir = new File(CLDRPaths.ARCHIVE_DIRECTORY).toPath(); 15 if (!archiveDir.toFile().isDirectory()) { 16 throw new FileNotFoundException( 17 "Archive directory " + archiveDir.toString() + 18 " does not exist, please create it or change the value of -DARCHIVE="); 19 } 20 System.out.println("Setting up in $ARCHIVE " + archiveDir.toString() + " …"); 21 int skip = 0; 22 int created = 0; 23 int err = 0; 24 for (final String ver : ToolConstants.CLDR_VERSIONS) { 25 final Path dirName = archiveDir.resolve("cldr-" + ver); 26 if (dirName.toFile().isDirectory()) { 27 skip++; 28 System.out.println("# Skipping existing \t" + dirName.toString()); 29 } else { 30 final String tag = "release-" + ver.replaceAll("\\.", "-").replaceAll("-0$", ""); 31 final String cmd[] = { 32 "git", 33 "worktree", 34 "add", 35 dirName.toString(), 36 tag 37 }; 38 System.out.println("# " + String.join(" ", cmd)); 39 int ev = new ProcessBuilder(cmd) 40 .directory(new File(CLDRPaths.BASE_DIRECTORY)) 41 .inheritIO() 42 .start() 43 .waitFor(); 44 if (ev != 0) { 45 err++; 46 System.err.println("Error: exit value " + ev); 47 } 48 } 49 } 50 System.out.println(String.format("Created %d and skipped %d version(s)", created, skip)); 51 if (err != 0) { 52 throw new RuntimeException("Total errors: " + err); 53 } 54 } 55 } 56