Fix workaround
[cc0/argeo-build.git] / src / org / argeo / build / Repackage.java
index b594f3a19b44e4aff5ee3d62a772e845a8928225..ca5242e415d49bb2e767100efdaddf2594f5d679 100644 (file)
@@ -119,6 +119,8 @@ public class Repackage {
        /** Deletes remaining sub directories. */
        void cleanPreviousFailedBuild(Path categoryPath) {
                Path outputCategoryPath = a2Base.resolve(categoryPath);
+               if (!Files.exists(outputCategoryPath))
+                       return;
                // clean previous failed build
                try {
                        for (Path subDir : Files.newDirectoryStream(outputCategoryPath, (d) -> Files.isDirectory(d))) {
@@ -932,6 +934,10 @@ public class Repackage {
                                                                        map.put(key.toString(), commonProps.getProperty(key.toString()));
                                                                A2Origin origin = new A2Origin();
                                                                Path bundleDir = processBundleJar(file, targetCategoryBase, map, origin);
+                                                               if (bundleDir == null) {
+                                                                       logger.log(WARNING, "No bundle dir created for " + file + ", skipping...");
+                                                                       return FileVisitResult.CONTINUE;
+                                                               }
                                                                origins.put(bundleDir, origin);
                                                                logger.log(DEBUG, () -> "Processed " + file);
                                                        }
@@ -1015,6 +1021,8 @@ public class Repackage {
                Manifest sourceManifest;
                try (JarInputStream jarIn = new JarInputStream(Files.newInputStream(file), false)) {
                        sourceManifest = jarIn.getManifest();
+                       if (sourceManifest == null)
+                               logger.log(WARNING, file + " has no manifest");
                        manifest = sourceManifest != null ? new Manifest(sourceManifest) : new Manifest();
 
                        String rawSourceSymbolicName = manifest.getMainAttributes().getValue(BUNDLE_SYMBOLICNAME.toString());
@@ -1037,6 +1045,13 @@ public class Repackage {
                                nameVersion = new NameVersion(ourSymbolicName, ourVersion);
                        } else {
                                nameVersion = nameVersionFromManifest(manifest);
+                               if (nameVersion == null) {
+                                       logger.log(WARNING, file + " has no symbolic name, trying name/version based on its name");
+                                       // hack for weird issue with JNA jar in Eclipse
+                                       String[] arr_ = file.getFileName().toString().split("_");
+                                       String v = arr_[1].substring(0, arr_[1].length() - 4);// remove .jar
+                                       nameVersion = new NameVersion(arr_[0], v);
+                               }
                                if (ourVersion != null && !nameVersion.getVersion().equals(ourVersion)) {
                                        logger.log(WARNING,
                                                        "Original version is " + nameVersion.getVersion() + " while new version is " + ourVersion);