1 package org
.argeo
.slc
.factory
;
3 import static java
.lang
.System
.Logger
.Level
.DEBUG
;
4 import static org
.argeo
.slc
.ManifestConstants
.BUNDLE_LICENSE
;
5 import static org
.argeo
.slc
.ManifestConstants
.BUNDLE_SYMBOLICNAME
;
6 import static org
.argeo
.slc
.ManifestConstants
.BUNDLE_VERSION
;
7 import static org
.argeo
.slc
.ManifestConstants
.EXPORT_PACKAGE
;
8 import static org
.argeo
.slc
.ManifestConstants
.SLC_ORIGIN_M2
;
10 import java
.io
.FileNotFoundException
;
11 import java
.io
.IOException
;
12 import java
.io
.InputStream
;
13 import java
.io
.OutputStream
;
14 import java
.io
.Writer
;
15 import java
.lang
.System
.Logger
;
16 import java
.lang
.System
.Logger
.Level
;
18 import java
.nio
.file
.DirectoryStream
;
19 import java
.nio
.file
.FileSystem
;
20 import java
.nio
.file
.FileSystems
;
21 import java
.nio
.file
.FileVisitResult
;
22 import java
.nio
.file
.Files
;
23 import java
.nio
.file
.Path
;
24 import java
.nio
.file
.PathMatcher
;
25 import java
.nio
.file
.Paths
;
26 import java
.nio
.file
.SimpleFileVisitor
;
27 import java
.nio
.file
.attribute
.BasicFileAttributes
;
28 import java
.util
.ArrayList
;
29 import java
.util
.HashMap
;
30 import java
.util
.List
;
32 import java
.util
.Properties
;
33 import java
.util
.TreeMap
;
34 import java
.util
.jar
.Attributes
;
35 import java
.util
.jar
.JarEntry
;
36 import java
.util
.jar
.JarInputStream
;
37 import java
.util
.jar
.JarOutputStream
;
38 import java
.util
.jar
.Manifest
;
40 import org
.argeo
.slc
.DefaultNameVersion
;
41 import org
.argeo
.slc
.ManifestConstants
;
42 import org
.argeo
.slc
.NameVersion
;
43 import org
.argeo
.slc
.factory
.m2
.DefaultArtifact
;
44 import org
.argeo
.slc
.factory
.m2
.MavenConventionsUtils
;
46 import aQute
.bnd
.osgi
.Analyzer
;
47 import aQute
.bnd
.osgi
.Jar
;
49 /** The central class for A2 packaging. */
50 public class A2Factory
{
51 private final static Logger logger
= System
.getLogger(A2Factory
.class.getName());
53 private final static String COMMON_BND
= "common.bnd";
55 private Path originBase
;
58 /** key is URI prefix, value list of base URLs */
59 private Map
<String
, List
<String
>> mirrors
= new HashMap
<String
, List
<String
>>();
61 public A2Factory(Path a2Base
) {
62 this.originBase
= Paths
.get(System
.getProperty("user.home"), ".cache", "argeo/slc/origin");
65 // TODO make it configurable
66 List
<String
> eclipseMirrors
= new ArrayList
<>();
67 eclipseMirrors
.add("https://archive.eclipse.org/");
68 eclipseMirrors
.add("http://ftp-stud.hs-esslingen.de/Mirrors/eclipse/");
69 eclipseMirrors
.add("http://ftp.fau.de/eclipse/");
71 mirrors
.put("http://www.eclipse.org/downloads", eclipseMirrors
);
74 public void processCategory(Path targetCategoryBase
) {
76 DirectoryStream
<Path
> bnds
= Files
.newDirectoryStream(targetCategoryBase
,
77 (p
) -> p
.getFileName().toString().endsWith(".bnd")
78 && !p
.getFileName().toString().equals(COMMON_BND
));
80 processSingleM2ArtifactDistributionUnit(p
);
83 DirectoryStream
<Path
> dus
= Files
.newDirectoryStream(targetCategoryBase
, (p
) -> Files
.isDirectory(p
));
84 for (Path duDir
: dus
) {
85 processM2BasedDistributionUnit(duDir
);
87 } catch (IOException e
) {
88 throw new RuntimeException("Cannot process category " + targetCategoryBase
, e
);
92 public void processSingleM2ArtifactDistributionUnit(Path bndFile
) {
94 String category
= bndFile
.getParent().getFileName().toString();
95 Path targetCategoryBase
= a2Base
.resolve(category
);
96 Properties fileProps
= new Properties();
97 try (InputStream in
= Files
.newInputStream(bndFile
)) {
101 String m2Coordinates
= fileProps
.getProperty(SLC_ORIGIN_M2
.toString());
102 if (m2Coordinates
== null)
103 throw new IllegalArgumentException("No M2 coordinates available for " + bndFile
);
104 DefaultArtifact artifact
= new DefaultArtifact(m2Coordinates
);
105 URL url
= MavenConventionsUtils
.mavenCentralUrl(artifact
);
106 Path downloaded
= download(url
, originBase
, artifact
.toM2Coordinates() + ".jar");
108 Path targetBundleDir
= processBndJar(downloaded
, targetCategoryBase
, fileProps
, artifact
);
110 downloadAndProcessM2Sources(artifact
, targetBundleDir
);
112 createJar(targetBundleDir
);
113 } catch (Exception e
) {
114 throw new RuntimeException("Cannot process " + bndFile
, e
);
118 public void processM2BasedDistributionUnit(Path duDir
) {
120 String category
= duDir
.getParent().getFileName().toString();
121 Path targetCategoryBase
= a2Base
.resolve(category
);
122 Path commonBnd
= duDir
.resolve(COMMON_BND
);
123 Properties commonProps
= new Properties();
124 try (InputStream in
= Files
.newInputStream(commonBnd
)) {
125 commonProps
.load(in
);
128 String m2Version
= commonProps
.getProperty(SLC_ORIGIN_M2
.toString());
129 if (m2Version
== null) {
130 logger
.log(Level
.WARNING
, "Ignoring " + duDir
+ " as it is not an M2-based distribution unit");
131 return;// ignore, this is probably an Eclipse archive
133 if (!m2Version
.startsWith(":")) {
134 throw new IllegalStateException("Only the M2 version can be specified: " + m2Version
);
136 m2Version
= m2Version
.substring(1);
138 // String license = commonProps.getProperty(BUNDLE_LICENSE.toString());
140 DirectoryStream
<Path
> ds
= Files
.newDirectoryStream(duDir
,
141 (p
) -> p
.getFileName().toString().endsWith(".bnd")
142 && !p
.getFileName().toString().equals(COMMON_BND
));
144 Properties fileProps
= new Properties();
145 try (InputStream in
= Files
.newInputStream(p
)) {
148 String m2Coordinates
= fileProps
.getProperty(SLC_ORIGIN_M2
.toString());
149 DefaultArtifact artifact
= new DefaultArtifact(m2Coordinates
);
151 // temporary rewrite, for migration
152 String localLicense
= fileProps
.getProperty(BUNDLE_LICENSE
.toString());
153 if (localLicense
!= null || artifact
.getVersion() != null) {
154 fileProps
.remove(BUNDLE_LICENSE
.toString());
155 fileProps
.put(SLC_ORIGIN_M2
.toString(), artifact
.getGroupId() + ":" + artifact
.getArtifactId());
156 try (Writer writer
= Files
.newBufferedWriter(p
)) {
157 for (Object key
: fileProps
.keySet()) {
158 String value
= fileProps
.getProperty(key
.toString());
159 writer
.write(key
+ ": " + value
+ '\n');
161 logger
.log(DEBUG
, () -> "Migrated " + p
);
165 artifact
.setVersion(m2Version
);
166 URL url
= MavenConventionsUtils
.mavenCentralUrl(artifact
);
167 Path downloaded
= download(url
, originBase
, artifact
.toM2Coordinates() + ".jar");
169 // prepare manifest entries
170 Properties mergeProps
= new Properties();
171 mergeProps
.putAll(commonProps
);
173 // Map<String, String> entries = new HashMap<>();
174 // for (Object key : commonProps.keySet()) {
175 // entries.put(key.toString(), commonProps.getProperty(key.toString()));
177 fileEntries
: for (Object key
: fileProps
.keySet()) {
178 if (ManifestConstants
.SLC_ORIGIN_M2
.toString().equals(key
))
179 continue fileEntries
;
180 String value
= fileProps
.getProperty(key
.toString());
181 Object previousValue
= mergeProps
.put(key
.toString(), value
);
182 if (previousValue
!= null) {
183 logger
.log(Level
.WARNING
,
184 downloaded
+ ": " + key
+ " was " + previousValue
+ ", overridden with " + value
);
187 mergeProps
.put(ManifestConstants
.SLC_ORIGIN_M2
.toString(), artifact
.toM2Coordinates());
188 Path targetBundleDir
= processBndJar(downloaded
, targetCategoryBase
, mergeProps
, artifact
);
189 // logger.log(Level.DEBUG, () -> "Processed " + downloaded);
192 downloadAndProcessM2Sources(artifact
, targetBundleDir
);
194 createJar(targetBundleDir
);
196 } catch (IOException e
) {
197 throw new RuntimeException("Cannot process " + duDir
, e
);
202 protected void downloadAndProcessM2Sources(DefaultArtifact artifact
, Path targetBundleDir
) throws IOException
{
203 DefaultArtifact sourcesArtifact
= new DefaultArtifact(artifact
.toM2Coordinates(), "sources");
204 URL sourcesUrl
= MavenConventionsUtils
.mavenCentralUrl(sourcesArtifact
);
205 Path sourcesDownloaded
= download(sourcesUrl
, originBase
, artifact
.toM2Coordinates() + ".sources.jar");
206 processM2SourceJar(sourcesDownloaded
, targetBundleDir
);
207 logger
.log(Level
.DEBUG
, () -> "Processed source " + sourcesDownloaded
);
211 protected Path
processBndJar(Path downloaded
, Path targetCategoryBase
, Properties fileProps
,
212 DefaultArtifact artifact
) {
215 Map
<String
, String
> additionalEntries
= new TreeMap
<>();
216 boolean doNotModify
= Boolean
.parseBoolean(fileProps
217 .getOrDefault(ManifestConstants
.SLC_ORIGIN_MANIFEST_NOT_MODIFIED
.toString(), "false").toString());
219 // we always force the symbolic name
222 fileEntries
: for (Object key
: fileProps
.keySet()) {
223 if (ManifestConstants
.SLC_ORIGIN_M2
.toString().equals(key
))
224 continue fileEntries
;
225 String value
= fileProps
.getProperty(key
.toString());
226 additionalEntries
.put(key
.toString(), value
);
229 if (artifact
!= null) {
230 if (!fileProps
.containsKey(BUNDLE_SYMBOLICNAME
.toString())) {
231 fileProps
.put(BUNDLE_SYMBOLICNAME
.toString(), artifact
.getName());
233 if (!fileProps
.containsKey(BUNDLE_VERSION
.toString())) {
234 fileProps
.put(BUNDLE_VERSION
.toString(), artifact
.getVersion());
238 if (!fileProps
.containsKey(EXPORT_PACKAGE
.toString())) {
239 fileProps
.put(EXPORT_PACKAGE
.toString(),
240 "*;version=\"" + fileProps
.getProperty(BUNDLE_VERSION
.toString()) + "\"");
242 // if (!fileProps.contains(IMPORT_PACKAGE.toString())) {
243 // fileProps.put(IMPORT_PACKAGE.toString(), "*");
246 try (Analyzer bndAnalyzer
= new Analyzer()) {
247 bndAnalyzer
.setProperties(fileProps
);
248 Jar jar
= new Jar(downloaded
.toFile());
249 bndAnalyzer
.setJar(jar
);
250 Manifest manifest
= bndAnalyzer
.calcManifest();
252 keys
: for (Object key
: manifest
.getMainAttributes().keySet()) {
253 Object value
= manifest
.getMainAttributes().get(key
);
255 switch (key
.toString()) {
257 case "Bnd-LastModified":
261 if ("Require-Capability".equals(key
.toString())
262 && value
.toString().equals("osgi.ee;filter:=\"(&(osgi.ee=JavaSE)(version=1.1))\""))
263 continue keys
;// hack for very old classes
264 additionalEntries
.put(key
.toString(), value
.toString());
265 logger
.log(DEBUG
, () -> key
+ "=" + value
);
270 // try (Builder bndBuilder = new Builder()) {
271 // Jar jar = new Jar(downloaded.toFile());
272 // bndBuilder.addClasspath(jar);
273 // Path targetBundleDir = targetCategoryBase.resolve(artifact.getName() + "." + artifact.getBranch());
275 // Jar target = new Jar(targetBundleDir.toFile());
276 // bndBuilder.setJar(target);
277 // return targetBundleDir;
280 Path targetBundleDir
= processBundleJar(downloaded
, targetCategoryBase
, additionalEntries
);
281 logger
.log(Level
.DEBUG
, () -> "Processed " + downloaded
);
282 return targetBundleDir
;
283 } catch (Exception e
) {
284 throw new RuntimeException("Cannot BND process " + downloaded
, e
);
289 protected void processM2SourceJar(Path file
, Path targetBundleDir
) throws IOException
{
290 try (JarInputStream jarIn
= new JarInputStream(Files
.newInputStream(file
), false)) {
291 Path targetSourceDir
= targetBundleDir
.resolve("OSGI-OPT/src");
293 // TODO make it less dangerous?
294 if (Files
.exists(targetSourceDir
)) {
295 deleteDirectory(targetSourceDir
);
297 Files
.createDirectories(targetSourceDir
);
302 entries
: while ((entry
= jarIn
.getNextJarEntry()) != null) {
303 if (entry
.isDirectory())
305 if (entry
.getName().startsWith("META-INF"))// skip META-INF entries
307 Path target
= targetSourceDir
.resolve(entry
.getName());
308 Files
.createDirectories(target
.getParent());
309 Files
.copy(jarIn
, target
);
310 logger
.log(Level
.TRACE
, () -> "Copied source " + target
);
316 public void processEclipseArchive(Path duDir
) {
318 String category
= duDir
.getParent().getFileName().toString();
319 Path targetCategoryBase
= a2Base
.resolve(category
);
320 Files
.createDirectories(targetCategoryBase
);
321 Files
.createDirectories(originBase
);
323 Path commonBnd
= duDir
.resolve(COMMON_BND
);
324 Properties commonProps
= new Properties();
325 try (InputStream in
= Files
.newInputStream(commonBnd
)) {
326 commonProps
.load(in
);
328 Properties includes
= new Properties();
329 try (InputStream in
= Files
.newInputStream(duDir
.resolve("includes.properties"))) {
332 String url
= commonProps
.getProperty(ManifestConstants
.SLC_ORIGIN_URI
.toString());
333 Path downloaded
= tryDownload(url
, originBase
);
335 FileSystem zipFs
= FileSystems
.newFileSystem(downloaded
, (ClassLoader
) null);
337 List
<PathMatcher
> pathMatchers
= new ArrayList
<>();
338 for (Object pattern
: includes
.keySet()) {
339 PathMatcher pathMatcher
= zipFs
.getPathMatcher("glob:/" + pattern
);
340 pathMatchers
.add(pathMatcher
);
343 Files
.walkFileTree(zipFs
.getRootDirectories().iterator().next(), new SimpleFileVisitor
<Path
>() {
346 public FileVisitResult
visitFile(Path file
, BasicFileAttributes attrs
) throws IOException
{
347 pathMatchers
: for (PathMatcher pathMatcher
: pathMatchers
) {
348 if (pathMatcher
.matches(file
)) {
349 // Path target = targetBase.resolve(file.getFileName().toString());
350 // if (!Files.exists(target)) {
351 // Files.copy(file, target);
352 // logger.log(Level.DEBUG, () -> "Copied " + target + " from " + downloaded);
354 // logger.log(Level.DEBUG, () -> target + " already exists.");
357 if (file
.getFileName().toString().contains(".source_")) {
358 processEclipseSourceJar(file
, targetCategoryBase
);
359 logger
.log(Level
.DEBUG
, () -> "Processed source " + file
);
362 processBundleJar(file
, targetCategoryBase
, new HashMap
<>());
363 logger
.log(Level
.DEBUG
, () -> "Processed " + file
);
365 continue pathMatchers
;
368 return super.visitFile(file
, attrs
);
372 DirectoryStream
<Path
> dirs
= Files
.newDirectoryStream(targetCategoryBase
, (p
) -> Files
.isDirectory(p
));
373 for (Path dir
: dirs
) {
376 } catch (IOException e
) {
377 throw new RuntimeException("Cannot process " + duDir
, e
);
382 protected Path
processBundleJar(Path file
, Path targetBase
, Map
<String
, String
> entries
) throws IOException
{
383 DefaultNameVersion nameVersion
;
384 Path targetBundleDir
;
385 try (JarInputStream jarIn
= new JarInputStream(Files
.newInputStream(file
), false)) {
386 Manifest manifest
= new Manifest(jarIn
.getManifest());
388 // remove problematic entries in MANIFEST
389 manifest
.getEntries().clear();
390 // Set<String> entriesToDelete = new HashSet<>();
391 // for (String key : manifest.getEntries().keySet()) {
392 //// logger.log(DEBUG, "## " + key);
393 // Attributes attrs = manifest.getAttributes(key);
394 // for (Object attrName : attrs.keySet()) {
395 //// logger.log(DEBUG, attrName + "=" + attrs.get(attrName));
396 // if ("Specification-Version".equals(attrName.toString())
397 // || "Implementation-Version".equals(attrName.toString())) {
398 // entriesToDelete.add(key);
403 // for (String key : entriesToDelete) {
404 // manifest.getEntries().remove(key);
407 String symbolicNameFromEntries
= entries
.get(BUNDLE_SYMBOLICNAME
.toString());
408 String versionFromEntries
= entries
.get(BUNDLE_VERSION
.toString());
410 if (symbolicNameFromEntries
!= null && versionFromEntries
!= null) {
411 nameVersion
= new DefaultNameVersion(symbolicNameFromEntries
, versionFromEntries
);
413 nameVersion
= nameVersionFromManifest(manifest
);
414 if (versionFromEntries
!= null && !nameVersion
.getVersion().equals(versionFromEntries
)) {
415 logger
.log(Level
.WARNING
, "Original version is " + nameVersion
.getVersion()
416 + " while new version is " + versionFromEntries
);
418 if (symbolicNameFromEntries
!= null) {
419 // we always force our symbolic name
420 nameVersion
.setName(symbolicNameFromEntries
);
423 targetBundleDir
= targetBase
.resolve(nameVersion
.getName() + "." + nameVersion
.getBranch());
425 // TODO make it less dangerous?
426 if (Files
.exists(targetBundleDir
)) {
427 deleteDirectory(targetBundleDir
);
432 entries
: while ((entry
= jarIn
.getNextJarEntry()) != null) {
433 if (entry
.isDirectory())
435 if (entry
.getName().endsWith(".RSA") || entry
.getName().endsWith(".SF"))
437 Path target
= targetBundleDir
.resolve(entry
.getName());
438 Files
.createDirectories(target
.getParent());
439 Files
.copy(jarIn
, target
);
440 logger
.log(Level
.TRACE
, () -> "Copied " + target
);
444 Path manifestPath
= targetBundleDir
.resolve("META-INF/MANIFEST.MF");
445 Files
.createDirectories(manifestPath
.getParent());
446 for (String key
: entries
.keySet()) {
447 String value
= entries
.get(key
);
448 Object previousValue
= manifest
.getMainAttributes().putValue(key
, value
);
449 if (previousValue
!= null && !previousValue
.equals(value
)) {
450 if (ManifestConstants
.IMPORT_PACKAGE
.toString().equals(key
)
451 || ManifestConstants
.EXPORT_PACKAGE
.toString().equals(key
))
452 logger
.log(Level
.WARNING
, file
.getFileName() + ": " + key
+ " was modified");
455 logger
.log(Level
.WARNING
, file
.getFileName() + ": " + key
+ " was " + previousValue
456 + ", overridden with " + value
);
459 try (OutputStream out
= Files
.newOutputStream(manifestPath
)) {
463 return targetBundleDir
;
466 protected void processEclipseSourceJar(Path file
, Path targetBase
) throws IOException
{
467 // NameVersion nameVersion;
468 Path targetBundleDir
;
469 try (JarInputStream jarIn
= new JarInputStream(Files
.newInputStream(file
), false)) {
470 Manifest manifest
= jarIn
.getManifest();
471 // nameVersion = nameVersionFromManifest(manifest);
473 String
[] relatedBundle
= manifest
.getMainAttributes().getValue("Eclipse-SourceBundle").split(";");
474 String version
= relatedBundle
[1].substring("version=\"".length());
475 version
= version
.substring(0, version
.length() - 1);
476 NameVersion nameVersion
= new DefaultNameVersion(relatedBundle
[0], version
);
477 targetBundleDir
= targetBase
.resolve(nameVersion
.getName() + "." + nameVersion
.getBranch());
479 Path targetSourceDir
= targetBundleDir
.resolve("OSGI-OPT/src");
481 // TODO make it less dangerous?
482 if (Files
.exists(targetSourceDir
)) {
483 deleteDirectory(targetSourceDir
);
485 Files
.createDirectories(targetSourceDir
);
490 entries
: while ((entry
= jarIn
.getNextJarEntry()) != null) {
491 if (entry
.isDirectory())
493 if (entry
.getName().startsWith("META-INF"))// skip META-INF entries
495 Path target
= targetSourceDir
.resolve(entry
.getName());
496 Files
.createDirectories(target
.getParent());
497 Files
.copy(jarIn
, target
);
498 logger
.log(Level
.TRACE
, () -> "Copied source " + target
);
502 // Path manifestPath = targetBundleDir.resolve("META-INF/MANIFEST.MF");
503 // Files.createDirectories(manifestPath.getParent());
504 // try (OutputStream out = Files.newOutputStream(manifestPath)) {
505 // manifest.write(out);
511 static void deleteDirectory(Path path
) throws IOException
{
512 if (!Files
.exists(path
))
514 Files
.walkFileTree(path
, new SimpleFileVisitor
<Path
>() {
516 public FileVisitResult
postVisitDirectory(Path directory
, IOException e
) throws IOException
{
519 Files
.delete(directory
);
520 return FileVisitResult
.CONTINUE
;
524 public FileVisitResult
visitFile(Path file
, BasicFileAttributes attrs
) throws IOException
{
526 return FileVisitResult
.CONTINUE
;
531 protected DefaultNameVersion
nameVersionFromManifest(Manifest manifest
) {
532 Attributes attrs
= manifest
.getMainAttributes();
534 String symbolicName
= attrs
.getValue(ManifestConstants
.BUNDLE_SYMBOLICNAME
.toString());
535 if (symbolicName
== null)
537 // make sure there is no directive
538 symbolicName
= symbolicName
.split(";")[0];
540 String version
= attrs
.getValue(ManifestConstants
.BUNDLE_VERSION
.toString());
541 return new DefaultNameVersion(symbolicName
, version
);
544 protected Path
tryDownload(String uri
, Path dir
) throws IOException
{
546 List
<String
> urlBases
= null;
547 String uriPrefix
= null;
548 uriPrefixes
: for (String uriPref
: mirrors
.keySet()) {
549 if (uri
.startsWith(uriPref
)) {
550 if (mirrors
.get(uriPref
).size() > 0) {
551 urlBases
= mirrors
.get(uriPref
);
557 if (urlBases
== null)
559 return download(new URL(uri
), dir
, null);
560 } catch (FileNotFoundException e
) {
561 throw new FileNotFoundException("Cannot find " + uri
);
565 for (String urlBase
: urlBases
) {
566 String relativePath
= uri
.substring(uriPrefix
.length());
567 URL url
= new URL(urlBase
+ relativePath
);
569 return download(url
, dir
, null);
570 } catch (FileNotFoundException e
) {
571 logger
.log(Level
.WARNING
, "Cannot download " + url
+ ", trying another mirror");
574 throw new FileNotFoundException("Cannot find " + uri
);
577 // protected String simplifyName(URL u) {
578 // String name = u.getPath().substring(u.getPath().lastIndexOf('/') + 1);
582 protected Path
download(URL url
, Path dir
, String name
) throws IOException
{
586 name
= url
.getPath().substring(url
.getPath().lastIndexOf('/') + 1);
589 dest
= dir
.resolve(name
);
590 if (Files
.exists(dest
)) {
591 logger
.log(Level
.TRACE
, () -> "File " + dest
+ " already exists for " + url
+ ", not downloading again");
595 try (InputStream in
= url
.openStream()) {
596 Files
.copy(in
, dest
);
597 logger
.log(Level
.DEBUG
, () -> "Downloaded " + dest
+ " from " + url
);
602 protected Path
createJar(Path bundleDir
) throws IOException
{
603 Path jarPath
= bundleDir
.getParent().resolve(bundleDir
.getFileName() + ".jar");
604 Path manifestPath
= bundleDir
.resolve("META-INF/MANIFEST.MF");
606 try (InputStream in
= Files
.newInputStream(manifestPath
)) {
607 manifest
= new Manifest(in
);
609 try (JarOutputStream jarOut
= new JarOutputStream(Files
.newOutputStream(jarPath
), manifest
)) {
610 Files
.walkFileTree(bundleDir
, new SimpleFileVisitor
<Path
>() {
613 public FileVisitResult
visitFile(Path file
, BasicFileAttributes attrs
) throws IOException
{
614 if (file
.getFileName().toString().equals("MANIFEST.MF"))
615 return super.visitFile(file
, attrs
);
616 JarEntry entry
= new JarEntry(bundleDir
.relativize(file
).toString());
617 jarOut
.putNextEntry(entry
);
618 Files
.copy(file
, jarOut
);
619 return super.visitFile(file
, attrs
);
624 deleteDirectory(bundleDir
);
628 public static void main(String
[] args
) {
629 Path factoryBase
= Paths
.get("../../output/a2").toAbsolutePath().normalize();
630 A2Factory factory
= new A2Factory(factoryBase
);
632 Path descriptorsBase
= Paths
.get("../tp").toAbsolutePath().normalize();
634 // factory.processSingleM2ArtifactDistributionUnit(descriptorsBase.resolve("org.argeo.tp.apache").resolve("org.apache.xml.resolver.bnd"));
635 // factory.processM2BasedDistributionUnit(descriptorsBase.resolve("org.argeo.tp.apache/apache-sshd"));
636 // factory.processM2BasedDistributionUnit(descriptorsBase.resolve("org.argeo.tp.jetty/jetty"));
637 // factory.processM2BasedDistributionUnit(descriptorsBase.resolve("org.argeo.tp.jetty/jetty-websocket"));
638 factory
.processCategory(descriptorsBase
.resolve("org.argeo.tp.eclipse.rcp"));
642 factory
.processEclipseArchive(
643 descriptorsBase
.resolve("org.argeo.tp.eclipse.equinox").resolve("eclipse-equinox"));
644 factory
.processEclipseArchive(descriptorsBase
.resolve("org.argeo.tp.eclipse.rap").resolve("eclipse-rap"));
645 factory
.processEclipseArchive(descriptorsBase
.resolve("org.argeo.tp.eclipse.rcp").resolve("eclipse-rcp"));
650 factory
.processCategory(descriptorsBase
.resolve("org.argeo.tp.sdk"));
651 factory
.processCategory(descriptorsBase
.resolve("org.argeo.tp"));
652 factory
.processCategory(descriptorsBase
.resolve("org.argeo.tp.apache"));
653 factory
.processCategory(descriptorsBase
.resolve("org.argeo.tp.jetty"));
654 factory
.processCategory(descriptorsBase
.resolve("org.argeo.tp.jcr"));