Clean previous failed build
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 14 Sep 2023 04:46:02 +0000 (06:46 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 14 Sep 2023 04:46:02 +0000 (06:46 +0200)
src/org/argeo/build/Repackage.java

index c3fbcaf8850278db4fb2e67e1b2e100cf76770c5..310c6ca186bc974eecf72ba1c9ace6adc5269f86 100644 (file)
@@ -98,13 +98,14 @@ public class Repackage {
 
                List<CompletableFuture<Void>> toDos = new ArrayList<>();
                for (int i = 1; i < args.length; i++) {
-                       Path p = Paths.get(args[i]);
-                       if (sequential)
-                               factory.processCategory(p);
+                       Path categoryPath = Paths.get(args[i]);
+                       cleanPreviousFailedBuild(categoryPath);
+                       if (sequential) // sequential processing happens here
+                               factory.processCategory(categoryPath);
                        else
-                               toDos.add(CompletableFuture.runAsync(() -> factory.processCategory(p)));
+                               toDos.add(CompletableFuture.runAsync(() -> factory.processCategory(categoryPath)));
                }
-               if (!sequential)
+               if (!sequential)// parallel processing
                        CompletableFuture.allOf(toDos.toArray(new CompletableFuture[toDos.size()])).join();
 
                // Summary
@@ -115,6 +116,22 @@ public class Repackage {
                logger.log(INFO, "# License summary:\n" + sb);
        }
 
+       /** Deletes remaining sub directories. */
+       static void cleanPreviousFailedBuild(Path categoryPath) {
+               // clean previous failed build
+               try {
+                       for (Path subDir : Files.newDirectoryStream(categoryPath, (d) -> Files.isDirectory(d))) {
+                               if (Files.exists(subDir)) {
+                                       logger.log(WARNING, "Bundle dir " + subDir
+                                                       + " already exists, probably from a previous failed build, deleting it...");
+                                       deleteDirectory(subDir);
+                               }
+                       }
+               } catch (IOException e) {
+                       logger.log(ERROR, "Cannot clean previous build", e);
+               }
+       }
+
        /** MANIFEST headers. */
        enum ManifestHeader {
                // OSGi
@@ -1029,13 +1046,7 @@ public class Repackage {
                                }
                        }
 
-                       // create bundle dir
                        bundleDir = targetBase.resolve(nameVersion.getName() + "." + nameVersion.getBranch());
-                       if (Files.exists(bundleDir)) {
-                               logger.log(WARNING, "Bundle dir " + bundleDir
-                                               + " already exists, probably from a previous failed build, deleting it...");
-                               deleteDirectory(bundleDir);
-                       }
 
                        // copy original MANIFEST
                        if (sourceManifest != null) {