|
35 | 35 | public class LuacageDatabaseGenerator { |
36 | 36 |
|
37 | 37 | public static final String BUILD_PATH = System.getenv("luainminecraftbukkit_luacage_build"); |
| 38 | + private static final String NAME_PATTERN = "[a-zA-Z][a-zA-Z0-9_-]+"; |
38 | 39 |
|
39 | 40 | public static void run() { |
40 | 41 | if (BUILD_PATH == null) return; |
@@ -127,6 +128,9 @@ public static void generateMetaList(String repoPath, String outPath) { |
127 | 128 | } |
128 | 129 |
|
129 | 130 | public static void updateMetaList(String repoPath, String outPath, String name) throws Exception { |
| 131 | + if (!name.matches(NAME_PATTERN)) { |
| 132 | + throw new Exception("Invalid name " + name + ", name not matches pattern " + NAME_PATTERN); |
| 133 | + } |
130 | 134 | File repo = new File(repoPath); |
131 | 135 | File pkgDir = new File(repoPath, PACKAGE_DIR_NAME); |
132 | 136 | List<LuacageJsonMeta> database = getDatabase(repo); |
@@ -221,12 +225,13 @@ private static List<LuacageJsonMeta> getDatabase(File repo) throws FileNotFoundE |
221 | 225 | private static void writeJson(List<LuacageJsonMeta> list, String outPath) throws IOException, NoSuchAlgorithmException { |
222 | 226 | list.sort(Comparator.comparing(LuacageCommonMeta::getName)); |
223 | 227 | String json = new Gson().toJson(list); |
224 | | - Files.write(Paths.get(outPath), json.getBytes(StandardCharsets.UTF_8), |
| 228 | + Path path = Paths.get(outPath); |
| 229 | + Files.write(path, json.getBytes(StandardCharsets.UTF_8), |
225 | 230 | StandardOpenOption.WRITE, |
226 | 231 | StandardOpenOption.TRUNCATE_EXISTING, |
227 | 232 | StandardOpenOption.CREATE |
228 | 233 | ); |
229 | | - String hash = HashUtil.sha256(Paths.get(outPath).toFile()); |
| 234 | + String hash = HashUtil.sha256(path.toFile()); |
230 | 235 | Files.write(Paths.get(outPath + ".hash"), hash.getBytes(StandardCharsets.UTF_8), |
231 | 236 | StandardOpenOption.WRITE, |
232 | 237 | StandardOpenOption.TRUNCATE_EXISTING, |
|
0 commit comments