]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - org.argeo.slc.factory/src/org/argeo/slc/factory/A2Factory.java
Make merge more robust
[gpl/argeo-slc.git] / org.argeo.slc.factory / src / org / argeo / slc / factory / A2Factory.java
index 5e1e85bcca01245d6de5c8eb5af82d58aafa093d..388ab7aba6f8cbbf62b4673141eed8fc24d33785 100644 (file)
@@ -1,17 +1,16 @@
 package org.argeo.slc.factory;
 
 import static java.lang.System.Logger.Level.DEBUG;
-import static org.argeo.slc.ManifestConstants.BUNDLE_LICENSE;
 import static org.argeo.slc.ManifestConstants.BUNDLE_SYMBOLICNAME;
 import static org.argeo.slc.ManifestConstants.BUNDLE_VERSION;
 import static org.argeo.slc.ManifestConstants.EXPORT_PACKAGE;
 import static org.argeo.slc.ManifestConstants.SLC_ORIGIN_M2;
+import static org.argeo.slc.ManifestConstants.SLC_ORIGIN_M2_REPO;
 
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.io.Writer;
 import java.lang.System.Logger;
 import java.lang.System.Logger.Level;
 import java.net.URL;
@@ -24,6 +23,7 @@ import java.nio.file.Path;
 import java.nio.file.PathMatcher;
 import java.nio.file.Paths;
 import java.nio.file.SimpleFileVisitor;
+import java.nio.file.StandardOpenOption;
 import java.nio.file.attribute.BasicFileAttributes;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -37,6 +37,7 @@ import java.util.jar.JarInputStream;
 import java.util.jar.JarOutputStream;
 import java.util.jar.Manifest;
 
+import org.argeo.slc.DefaultCategoryNameVersion;
 import org.argeo.slc.DefaultNameVersion;
 import org.argeo.slc.ManifestConstants;
 import org.argeo.slc.NameVersion;
@@ -51,6 +52,7 @@ public class A2Factory {
        private final static Logger logger = System.getLogger(A2Factory.class.getName());
 
        private final static String COMMON_BND = "common.bnd";
+       private final static String MERGE_BND = "merge.bnd";
 
        private Path originBase;
        private Path a2Base;
@@ -74,8 +76,8 @@ public class A2Factory {
        public void processCategory(Path targetCategoryBase) {
                try {
                        DirectoryStream<Path> bnds = Files.newDirectoryStream(targetCategoryBase,
-                                       (p) -> p.getFileName().toString().endsWith(".bnd")
-                                                       && !p.getFileName().toString().equals(COMMON_BND));
+                                       (p) -> p.getFileName().toString().endsWith(".bnd") && !p.getFileName().toString().equals(COMMON_BND)
+                                                       && !p.getFileName().toString().equals(MERGE_BND));
                        for (Path p : bnds) {
                                processSingleM2ArtifactDistributionUnit(p);
                        }
@@ -97,17 +99,28 @@ public class A2Factory {
                        try (InputStream in = Files.newInputStream(bndFile)) {
                                fileProps.load(in);
                        }
+                       String repoStr = fileProps.containsKey(SLC_ORIGIN_M2_REPO.toString())
+                                       ? fileProps.getProperty(SLC_ORIGIN_M2_REPO.toString())
+                                       : null;
+
+                       if (!fileProps.containsKey(BUNDLE_SYMBOLICNAME.toString())
+                                       && !fileProps.containsKey(ManifestConstants.SLC_ORIGIN_MANIFEST_NOT_MODIFIED.toString())) {
+                               // use file name as symbolic name
+                               String symbolicName = bndFile.getFileName().toString();
+                               symbolicName = symbolicName.substring(0, symbolicName.length() - ".bnd".length());
+                               fileProps.put(BUNDLE_SYMBOLICNAME.toString(), symbolicName);
+                       }
 
                        String m2Coordinates = fileProps.getProperty(SLC_ORIGIN_M2.toString());
                        if (m2Coordinates == null)
                                throw new IllegalArgumentException("No M2 coordinates available for " + bndFile);
                        DefaultArtifact artifact = new DefaultArtifact(m2Coordinates);
-                       URL url = MavenConventionsUtils.mavenCentralUrl(artifact);
+                       URL url = MavenConventionsUtils.mavenRepoUrl(repoStr, artifact);
                        Path downloaded = download(url, originBase, artifact.toM2Coordinates() + ".jar");
 
                        Path targetBundleDir = processBndJar(downloaded, targetCategoryBase, fileProps, artifact);
 
-                       downloadAndProcessM2Sources(artifact, targetBundleDir);
+                       downloadAndProcessM2Sources(repoStr, artifact, targetBundleDir);
 
                        createJar(targetBundleDir);
                } catch (Exception e) {
@@ -119,6 +132,14 @@ public class A2Factory {
                try {
                        String category = duDir.getParent().getFileName().toString();
                        Path targetCategoryBase = a2Base.resolve(category);
+
+                       // merge
+                       Path mergeBnd = duDir.resolve(MERGE_BND);
+                       if (Files.exists(mergeBnd)) {
+                               mergeM2Artifacts(mergeBnd);
+                               return;
+                       }
+
                        Path commonBnd = duDir.resolve(COMMON_BND);
                        Properties commonProps = new Properties();
                        try (InputStream in = Files.newInputStream(commonBnd)) {
@@ -126,13 +147,15 @@ public class A2Factory {
                        }
 
                        String m2Version = commonProps.getProperty(SLC_ORIGIN_M2.toString());
+                       if (m2Version == null) {
+                               logger.log(Level.WARNING, "Ignoring " + duDir + " as it is not an M2-based distribution unit");
+                               return;// ignore, this is probably an Eclipse archive
+                       }
                        if (!m2Version.startsWith(":")) {
                                throw new IllegalStateException("Only the M2 version can be specified: " + m2Version);
                        }
                        m2Version = m2Version.substring(1);
 
-                       // String license = commonProps.getProperty(BUNDLE_LICENSE.toString());
-
                        DirectoryStream<Path> ds = Files.newDirectoryStream(duDir,
                                        (p) -> p.getFileName().toString().endsWith(".bnd")
                                                        && !p.getFileName().toString().equals(COMMON_BND));
@@ -145,31 +168,25 @@ public class A2Factory {
                                DefaultArtifact artifact = new DefaultArtifact(m2Coordinates);
 
                                // temporary rewrite, for migration
-                               String localLicense = fileProps.getProperty(BUNDLE_LICENSE.toString());
-                               if (localLicense != null || artifact.getVersion() != null) {
-                                       fileProps.remove(BUNDLE_LICENSE.toString());
-                                       fileProps.put(SLC_ORIGIN_M2.toString(), artifact.getGroupId() + ":" + artifact.getArtifactId());
-                                       try (Writer writer = Files.newBufferedWriter(p)) {
-                                               for (Object key : fileProps.keySet()) {
-                                                       String value = fileProps.getProperty(key.toString());
-                                                       writer.write(key + ": " + value + '\n');
-                                               }
-                                               logger.log(DEBUG, () -> "Migrated  " + p);
-                                       }
-                               }
+//                             String localLicense = fileProps.getProperty(BUNDLE_LICENSE.toString());
+//                             if (localLicense != null || artifact.getVersion() != null) {
+//                                     fileProps.remove(BUNDLE_LICENSE.toString());
+//                                     fileProps.put(SLC_ORIGIN_M2.toString(), artifact.getGroupId() + ":" + artifact.getArtifactId());
+//                                     try (Writer writer = Files.newBufferedWriter(p)) {
+//                                             for (Object key : fileProps.keySet()) {
+//                                                     String value = fileProps.getProperty(key.toString());
+//                                                     writer.write(key + ": " + value + '\n');
+//                                             }
+//                                             logger.log(DEBUG, () -> "Migrated  " + p);
+//                                     }
+//                             }
 
                                artifact.setVersion(m2Version);
-                               URL url = MavenConventionsUtils.mavenCentralUrl(artifact);
-                               Path downloaded = download(url, originBase, artifact.toM2Coordinates() + ".jar");
 
                                // prepare manifest entries
                                Properties mergeProps = new Properties();
                                mergeProps.putAll(commonProps);
 
-                               // Map<String, String> entries = new HashMap<>();
-//                             for (Object key : commonProps.keySet()) {
-//                                     entries.put(key.toString(), commonProps.getProperty(key.toString()));
-//                             }
                                fileEntries: for (Object key : fileProps.keySet()) {
                                        if (ManifestConstants.SLC_ORIGIN_M2.toString().equals(key))
                                                continue fileEntries;
@@ -177,15 +194,31 @@ public class A2Factory {
                                        Object previousValue = mergeProps.put(key.toString(), value);
                                        if (previousValue != null) {
                                                logger.log(Level.WARNING,
-                                                               downloaded + ": " + key + " was " + previousValue + ", overridden with " + value);
+                                                               commonBnd + ": " + key + " was " + previousValue + ", overridden with " + value);
                                        }
                                }
                                mergeProps.put(ManifestConstants.SLC_ORIGIN_M2.toString(), artifact.toM2Coordinates());
+                               if (!mergeProps.containsKey(BUNDLE_SYMBOLICNAME.toString())
+                                               && !mergeProps.containsKey(ManifestConstants.SLC_ORIGIN_MANIFEST_NOT_MODIFIED.toString())) {
+                                       // use file name as symbolic name
+                                       String symbolicName = p.getFileName().toString();
+                                       symbolicName = symbolicName.substring(0, symbolicName.length() - ".bnd".length());
+                                       mergeProps.put(BUNDLE_SYMBOLICNAME.toString(), symbolicName);
+                               }
+
+                               String repoStr = mergeProps.containsKey(SLC_ORIGIN_M2_REPO.toString())
+                                               ? mergeProps.getProperty(SLC_ORIGIN_M2_REPO.toString())
+                                               : null;
+
+                               // download
+                               URL url = MavenConventionsUtils.mavenRepoUrl(repoStr, artifact);
+                               Path downloaded = download(url, originBase, artifact.toM2Coordinates() + ".jar");
+
                                Path targetBundleDir = processBndJar(downloaded, targetCategoryBase, mergeProps, artifact);
 //                             logger.log(Level.DEBUG, () -> "Processed " + downloaded);
 
                                // sources
-                               downloadAndProcessM2Sources(artifact, targetBundleDir);
+                               downloadAndProcessM2Sources(repoStr, artifact, targetBundleDir);
 
                                createJar(targetBundleDir);
                        }
@@ -195,9 +228,134 @@ public class A2Factory {
 
        }
 
-       protected void downloadAndProcessM2Sources(DefaultArtifact artifact, Path targetBundleDir) throws IOException {
+       protected void mergeM2Artifacts(Path mergeBnd) throws IOException {
+               Path duDir = mergeBnd.getParent();
+               String category = duDir.getParent().getFileName().toString();
+               Path targetCategoryBase = a2Base.resolve(category);
+
+               Properties mergeProps = new Properties();
+               try (InputStream in = Files.newInputStream(mergeBnd)) {
+                       mergeProps.load(in);
+               }
+               String m2Version = mergeProps.getProperty(SLC_ORIGIN_M2.toString());
+               if (m2Version == null) {
+                       logger.log(Level.WARNING, "Ignoring " + duDir + " as it is not an M2-based distribution unit");
+                       return;// ignore, this is probably an Eclipse archive
+               }
+               if (!m2Version.startsWith(":")) {
+                       throw new IllegalStateException("Only the M2 version can be specified: " + m2Version);
+               }
+               m2Version = m2Version.substring(1);
+
+               String artifactsStr = mergeProps.getProperty(ManifestConstants.SLC_ORIGIN_M2_MERGE.toString());
+               String repoStr = mergeProps.containsKey(SLC_ORIGIN_M2_REPO.toString())
+                               ? mergeProps.getProperty(SLC_ORIGIN_M2_REPO.toString())
+                               : null;
+
+               String bundleSymbolicName = mergeProps.getProperty(ManifestConstants.BUNDLE_SYMBOLICNAME.toString());
+               DefaultCategoryNameVersion nameVersion = new DefaultArtifact(
+                               category + ":" + bundleSymbolicName + ":" + m2Version);
+               Path targetBundleDir = targetCategoryBase.resolve(bundleSymbolicName + "." + nameVersion.getBranch());
+
+               String[] artifacts = artifactsStr.split(",");
+               artifacts: for (String str : artifacts) {
+                       String m2Coordinates = str.trim();
+                       if ("".equals(m2Coordinates))
+                               continue artifacts;
+                       DefaultArtifact artifact = new DefaultArtifact(m2Coordinates.trim());
+                       if (artifact.getVersion() == null)
+                               artifact.setVersion(m2Version);
+                       URL url = MavenConventionsUtils.mavenRepoUrl(repoStr, artifact);
+                       Path downloaded = download(url, originBase, artifact.toM2Coordinates() + ".jar");
+                       JarEntry entry;
+                       try (JarInputStream jarIn = new JarInputStream(Files.newInputStream(downloaded), false)) {
+                               entries: while ((entry = jarIn.getNextJarEntry()) != null) {
+                                       if (entry.isDirectory())
+                                               continue entries;
+                                       if (entry.getName().endsWith(".RSA") || entry.getName().endsWith(".SF"))
+                                               continue entries;
+                                       if (entry.getName().startsWith("META-INF/versions/"))
+                                               continue entries;
+                                       if (entry.getName().startsWith("META-INF/maven/"))
+                                               continue entries;
+                                       if (entry.getName().equals("module-info.class"))
+                                               continue entries;
+                                       if (entry.getName().equals("META-INF/NOTICE"))
+                                               continue entries;
+                                       if (entry.getName().equals("META-INF/LICENSE"))
+                                               continue entries;
+                                       Path target = targetBundleDir.resolve(entry.getName());
+                                       Files.createDirectories(target.getParent());
+                                       if (!Files.exists(target)) {
+                                               Files.copy(jarIn, target);
+                                       } else {
+                                               if (entry.getName().startsWith("META-INF/services/")) {
+                                                       try (OutputStream out = Files.newOutputStream(target, StandardOpenOption.APPEND)) {
+                                                               out.write("\n".getBytes());
+                                                               jarIn.transferTo(out);
+                                                               if (logger.isLoggable(DEBUG))
+                                                                       logger.log(DEBUG, "Appended " + entry.getName());
+                                                       }
+                                               } else if (entry.getName().startsWith("org/apache/batik/")) {
+                                                       logger.log(Level.WARNING, "Skip " + entry.getName());
+                                                       continue entries;
+                                               } else {
+                                                       throw new IllegalStateException("File " + target + " already exists");
+                                               }
+                                       }
+                                       logger.log(Level.TRACE, () -> "Copied " + target);
+                               }
+
+                       }
+                       downloadAndProcessM2Sources(repoStr, artifact, targetBundleDir);
+               }
+
+               Map<String, String> entries = new TreeMap<>();
+               try (Analyzer bndAnalyzer = new Analyzer()) {
+                       bndAnalyzer.setProperties(mergeProps);
+                       Jar jar = new Jar(targetBundleDir.toFile());
+                       bndAnalyzer.setJar(jar);
+                       Manifest manifest = bndAnalyzer.calcManifest();
+
+                       keys: for (Object key : manifest.getMainAttributes().keySet()) {
+                               Object value = manifest.getMainAttributes().get(key);
+
+                               switch (key.toString()) {
+                               case "Tool":
+                               case "Bnd-LastModified":
+                               case "Created-By":
+                                       continue keys;
+                               }
+                               if ("Require-Capability".equals(key.toString())
+                                               && value.toString().equals("osgi.ee;filter:=\"(&(osgi.ee=JavaSE)(version=1.1))\""))
+                                       continue keys;// hack for very old classes
+                               entries.put(key.toString(), value.toString());
+                               logger.log(DEBUG, () -> key + "=" + value);
+
+                       }
+               } catch (Exception e) {
+                       throw new RuntimeException("Cannot process " + mergeBnd, e);
+               }
+
+               Manifest manifest = new Manifest();
+               Path manifestPath = targetBundleDir.resolve("META-INF/MANIFEST.MF");
+               Files.createDirectories(manifestPath.getParent());
+               for (String key : entries.keySet()) {
+                       String value = entries.get(key);
+                       manifest.getMainAttributes().putValue(key, value);
+               }
+               try (OutputStream out = Files.newOutputStream(manifestPath)) {
+                       manifest.write(out);
+               }
+
+               createJar(targetBundleDir);
+
+       }
+
+       protected void downloadAndProcessM2Sources(String repoStr, DefaultArtifact artifact, Path targetBundleDir)
+                       throws IOException {
                DefaultArtifact sourcesArtifact = new DefaultArtifact(artifact.toM2Coordinates(), "sources");
-               URL sourcesUrl = MavenConventionsUtils.mavenCentralUrl(sourcesArtifact);
+               URL sourcesUrl = MavenConventionsUtils.mavenRepoUrl(repoStr, sourcesArtifact);
                Path sourcesDownloaded = download(sourcesUrl, originBase, artifact.toM2Coordinates() + ".sources.jar");
                processM2SourceJar(sourcesDownloaded, targetBundleDir);
                logger.log(Level.DEBUG, () -> "Processed source " + sourcesDownloaded);
@@ -288,7 +446,7 @@ public class A2Factory {
 
                        // TODO make it less dangerous?
                        if (Files.exists(targetSourceDir)) {
-                               deleteDirectory(targetSourceDir);
+//                             deleteDirectory(targetSourceDir);
                        } else {
                                Files.createDirectories(targetSourceDir);
                        }
@@ -300,10 +458,16 @@ public class A2Factory {
                                        continue entries;
                                if (entry.getName().startsWith("META-INF"))// skip META-INF entries
                                        continue entries;
+                               if (entry.getName().startsWith("module-info.java"))// skip META-INF entries
+                                       continue entries;
                                Path target = targetSourceDir.resolve(entry.getName());
                                Files.createDirectories(target.getParent());
-                               Files.copy(jarIn, target);
-                               logger.log(Level.TRACE, () -> "Copied source " + target);
+                               if (!Files.exists(target)) {
+                                       Files.copy(jarIn, target);
+                                       logger.log(Level.TRACE, () -> "Copied source " + target);
+                               } else {
+                                       logger.log(Level.WARNING, () -> target + " already exists, skipping...");
+                               }
                        }
                }
 
@@ -314,6 +478,11 @@ public class A2Factory {
                        String category = duDir.getParent().getFileName().toString();
                        Path targetCategoryBase = a2Base.resolve(category);
                        Files.createDirectories(targetCategoryBase);
+                       // first delete all directories from previous builds
+                       for (Path dir : Files.newDirectoryStream(targetCategoryBase, (p) -> Files.isDirectory(p))) {
+                               deleteDirectory(dir);
+                       }
+
                        Files.createDirectories(originBase);
 
                        Path commonBnd = duDir.resolve(COMMON_BND);
@@ -342,14 +511,6 @@ public class A2Factory {
                                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                                        pathMatchers: for (PathMatcher pathMatcher : pathMatchers) {
                                                if (pathMatcher.matches(file)) {
-//                                                     Path target = targetBase.resolve(file.getFileName().toString());
-//                                                     if (!Files.exists(target)) {
-//                                                             Files.copy(file, target);
-//                                                             logger.log(Level.DEBUG, () -> "Copied " + target + " from " + downloaded);
-//                                                     } else {
-//                                                             logger.log(Level.DEBUG, () -> target + " already exists.");
-//
-//                                                     }
                                                        if (file.getFileName().toString().contains(".source_")) {
                                                                processEclipseSourceJar(file, targetCategoryBase);
                                                                logger.log(Level.DEBUG, () -> "Processed source " + file);
@@ -358,10 +519,10 @@ public class A2Factory {
                                                                processBundleJar(file, targetCategoryBase, new HashMap<>());
                                                                logger.log(Level.DEBUG, () -> "Processed " + file);
                                                        }
-                                                       continue pathMatchers;
+                                                       break pathMatchers;
                                                }
                                        }
-                                       return super.visitFile(file, attrs);
+                                       return FileVisitResult.CONTINUE;
                                }
                        });
 
@@ -379,7 +540,8 @@ public class A2Factory {
                DefaultNameVersion nameVersion;
                Path targetBundleDir;
                try (JarInputStream jarIn = new JarInputStream(Files.newInputStream(file), false)) {
-                       Manifest manifest = new Manifest(jarIn.getManifest());
+                       Manifest sourceManifest = jarIn.getManifest();
+                       Manifest manifest = sourceManifest != null ? new Manifest(sourceManifest) : new Manifest();
 
                        // remove problematic entries in MANIFEST
                        manifest.getEntries().clear();
@@ -419,9 +581,9 @@ public class A2Factory {
                        targetBundleDir = targetBase.resolve(nameVersion.getName() + "." + nameVersion.getBranch());
 
                        // TODO make it less dangerous?
-                       if (Files.exists(targetBundleDir)) {
-                               deleteDirectory(targetBundleDir);
-                       }
+//                     if (Files.exists(targetBundleDir)) {
+//                             deleteDirectory(targetBundleDir);
+//                     }
 
                        // copy entries
                        JarEntry entry;
@@ -460,46 +622,48 @@ public class A2Factory {
        }
 
        protected void processEclipseSourceJar(Path file, Path targetBase) throws IOException {
-               // NameVersion nameVersion;
-               Path targetBundleDir;
-               try (JarInputStream jarIn = new JarInputStream(Files.newInputStream(file), false)) {
-                       Manifest manifest = jarIn.getManifest();
-                       // nameVersion = nameVersionFromManifest(manifest);
-
-                       String[] relatedBundle = manifest.getMainAttributes().getValue("Eclipse-SourceBundle").split(";");
-                       String version = relatedBundle[1].substring("version=\"".length());
-                       version = version.substring(0, version.length() - 1);
-                       NameVersion nameVersion = new DefaultNameVersion(relatedBundle[0], version);
-                       targetBundleDir = targetBase.resolve(nameVersion.getName() + "." + nameVersion.getBranch());
-
-                       Path targetSourceDir = targetBundleDir.resolve("OSGI-OPT/src");
-
-                       // TODO make it less dangerous?
-                       if (Files.exists(targetSourceDir)) {
-                               deleteDirectory(targetSourceDir);
-                       } else {
-                               Files.createDirectories(targetSourceDir);
-                       }
+               try {
+                       Path targetBundleDir;
+                       try (JarInputStream jarIn = new JarInputStream(Files.newInputStream(file), false)) {
+                               Manifest manifest = jarIn.getManifest();
+
+                               String[] relatedBundle = manifest.getMainAttributes().getValue("Eclipse-SourceBundle").split(";");
+                               String version = relatedBundle[1].substring("version=\"".length());
+                               version = version.substring(0, version.length() - 1);
+                               NameVersion nameVersion = new DefaultNameVersion(relatedBundle[0], version);
+                               targetBundleDir = targetBase.resolve(nameVersion.getName() + "." + nameVersion.getBranch());
+
+                               Path targetSourceDir = targetBundleDir.resolve("OSGI-OPT/src");
+
+                               // TODO make it less dangerous?
+                               if (Files.exists(targetSourceDir)) {
+//                             deleteDirectory(targetSourceDir);
+                               } else {
+                                       Files.createDirectories(targetSourceDir);
+                               }
 
-                       // copy entries
-                       JarEntry entry;
-                       entries: while ((entry = jarIn.getNextJarEntry()) != null) {
-                               if (entry.isDirectory())
-                                       continue entries;
-                               if (entry.getName().startsWith("META-INF"))// skip META-INF entries
-                                       continue entries;
-                               Path target = targetSourceDir.resolve(entry.getName());
-                               Files.createDirectories(target.getParent());
-                               Files.copy(jarIn, target);
-                               logger.log(Level.TRACE, () -> "Copied source " + target);
-                       }
+                               // copy entries
+                               JarEntry entry;
+                               entries: while ((entry = jarIn.getNextJarEntry()) != null) {
+                                       if (entry.isDirectory())
+                                               continue entries;
+                                       if (entry.getName().startsWith("META-INF"))// skip META-INF entries
+                                               continue entries;
+                                       Path target = targetSourceDir.resolve(entry.getName());
+                                       Files.createDirectories(target.getParent());
+                                       Files.copy(jarIn, target);
+                                       logger.log(Level.TRACE, () -> "Copied source " + target);
+                               }
 
-                       // copy MANIFEST
+                               // copy MANIFEST
 //                     Path manifestPath = targetBundleDir.resolve("META-INF/MANIFEST.MF");
 //                     Files.createDirectories(manifestPath.getParent());
 //                     try (OutputStream out = Files.newOutputStream(manifestPath)) {
 //                             manifest.write(out);
 //                     }
+                       }
+               } catch (IOException e) {
+                       throw new IllegalStateException("Cannot process " + file, e);
                }
 
        }
@@ -622,15 +786,20 @@ public class A2Factory {
        }
 
        public static void main(String[] args) {
-               Path factoryBase = Paths.get("../output/a2").toAbsolutePath().normalize();
+               Path factoryBase = Paths.get("../../output/a2").toAbsolutePath().normalize();
                A2Factory factory = new A2Factory(factoryBase);
 
                Path descriptorsBase = Paths.get("../tp").toAbsolutePath().normalize();
 
 //             factory.processSingleM2ArtifactDistributionUnit(descriptorsBase.resolve("org.argeo.tp.apache").resolve("org.apache.xml.resolver.bnd"));
 //             factory.processM2BasedDistributionUnit(descriptorsBase.resolve("org.argeo.tp.apache/apache-sshd"));
-               factory.processM2BasedDistributionUnit(descriptorsBase.resolve("org.argeo.tp.jetty/jetty"));
-               factory.processM2BasedDistributionUnit(descriptorsBase.resolve("org.argeo.tp.jetty/jetty-websocket"));
+//             factory.processM2BasedDistributionUnit(descriptorsBase.resolve("org.argeo.tp.jetty/jetty"));
+//             factory.processM2BasedDistributionUnit(descriptorsBase.resolve("org.argeo.tp.jetty/jetty-websocket"));
+//             factory.processCategory(descriptorsBase.resolve("org.argeo.tp.eclipse.rcp"));
+//             factory.processCategory(descriptorsBase.resolve("org.argeo.tp"));
+//             factory.processCategory(descriptorsBase.resolve("org.argeo.tp.apache"));
+//             factory.processCategory(descriptorsBase.resolve("org.argeo.tp.formats"));
+               factory.processCategory(descriptorsBase.resolve("org.argeo.tp.formats"));
                System.exit(0);
 
                // Eclipse