equal
deleted
inserted
replaced
112 public List<String> requirements() { return get_list("requirements"); } |
112 public List<String> requirements() { return get_list("requirements"); } |
113 public List<String> sources() { return get_list("sources"); } |
113 public List<String> sources() { return get_list("sources"); } |
114 public List<String> resources() { return get_list("resources"); } |
114 public List<String> resources() { return get_list("resources"); } |
115 public List<String> services() { return get_list("services"); } |
115 public List<String> services() { return get_list("services"); } |
116 |
116 |
|
117 public boolean is_vacuous() |
|
118 { |
|
119 return sources().isEmpty() && resources().isEmpty() && services().isEmpty(); |
|
120 } |
|
121 |
117 public Path path(String file) |
122 public Path path(String file) |
118 throws IOException, InterruptedException |
123 throws IOException, InterruptedException |
119 { |
124 { |
120 return _dir.resolve(Environment.expand_platform_path(file)); |
125 return _dir.resolve(Environment.expand_platform_path(file)); |
121 } |
126 } |
241 } |
246 } |
242 |
247 |
243 |
248 |
244 /** shasum for jar content **/ |
249 /** shasum for jar content **/ |
245 |
250 |
246 private static String SHASUM = "META-INF/shasum"; |
251 private static String SHASUM = "META-INF/isabelle/shasum"; |
247 |
252 |
248 public static String get_shasum(Path jar_path) |
253 public static String get_shasum(Path jar_path) |
249 throws IOException |
254 throws IOException |
250 { |
255 { |
251 if (Files.exists(jar_path)) { |
256 if (Files.exists(jar_path)) { |
266 throws IOException |
271 throws IOException |
267 { |
272 { |
268 Path path = dir.resolve(SHASUM); |
273 Path path = dir.resolve(SHASUM); |
269 Files.createDirectories(path.getParent()); |
274 Files.createDirectories(path.getParent()); |
270 Files.writeString(path, shasum); |
275 Files.writeString(path, shasum); |
|
276 } |
|
277 |
|
278 |
|
279 /** services **/ |
|
280 |
|
281 private static String SERVICES = "META-INF/isabelle/services"; |
|
282 |
|
283 public static List<String> get_services(Path jar_path) |
|
284 throws IOException |
|
285 { |
|
286 if (Files.exists(jar_path)) { |
|
287 try (JarFile jar_file = new JarFile(jar_path.toFile())) |
|
288 { |
|
289 JarEntry entry = jar_file.getJarEntry(SERVICES); |
|
290 if (entry != null) { |
|
291 byte[] bytes = jar_file.getInputStream(entry).readAllBytes(); |
|
292 return Library.split_lines(new String(bytes, StandardCharsets.UTF_8)); |
|
293 } |
|
294 else { return List.of(); } |
|
295 } |
|
296 } |
|
297 else { return List.of(); } |
|
298 } |
|
299 |
|
300 public static void create_services(Path dir, List<String> services) |
|
301 throws IOException |
|
302 { |
|
303 if (!services.isEmpty()) { |
|
304 Path path = dir.resolve(SERVICES); |
|
305 Files.createDirectories(path.getParent()); |
|
306 Files.writeString(path, Library.cat_lines(services)); |
|
307 } |
271 } |
308 } |
272 |
309 |
273 |
310 |
274 /** create jar **/ |
311 /** create jar **/ |
275 |
312 |
344 List<String> resources = context.resources(); |
381 List<String> resources = context.resources(); |
345 List<String> sources = context.sources(); |
382 List<String> sources = context.sources(); |
346 |
383 |
347 Files.deleteIfExists(context.shasum_path()); |
384 Files.deleteIfExists(context.shasum_path()); |
348 |
385 |
349 if (sources.isEmpty() && resources.isEmpty()) { |
386 if (context.is_vacuous()) { Files.deleteIfExists(jar_path); } |
350 Files.deleteIfExists(jar_path); |
|
351 } |
|
352 else { |
387 else { |
353 String shasum_old = get_shasum(jar_path); |
388 String shasum_old = get_shasum(jar_path); |
354 String shasum; |
389 String shasum; |
355 List<Path> compiler_deps = new LinkedList<Path>(); |
390 List<Path> compiler_deps = new LinkedList<Path>(); |
356 { |
391 { |
432 |
467 |
433 |
468 |
434 /* packaging */ |
469 /* packaging */ |
435 |
470 |
436 create_shasum(build_dir, shasum); |
471 create_shasum(build_dir, shasum); |
|
472 create_services(build_dir, context.services()); |
437 create_jar(build_dir, context.main(), jar_path); |
473 create_jar(build_dir, context.main(), jar_path); |
438 } |
474 } |
439 finally { |
475 finally { |
440 try (Stream<Path> walk = Files.walk(build_dir)) { |
476 try (Stream<Path> walk = Files.walk(build_dir)) { |
441 walk.sorted(Comparator.reverseOrder()) |
477 walk.sorted(Comparator.reverseOrder()) |