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
.startsWith(":")) {
130 throw new IllegalStateException("Only the M2 version can be specified: " + m2Version
);
132 m2Version
= m2Version
.substring(1);
134 // String license = commonProps.getProperty(BUNDLE_LICENSE.toString());
136 DirectoryStream
<Path
> ds
= Files
.newDirectoryStream(duDir
,
137 (p
) -> p
.getFileName().toString().endsWith(".bnd")
138 && !p
.getFileName().toString().equals(COMMON_BND
));
140 Properties fileProps
= new Properties();
141 try (InputStream in
= Files
.newInputStream(p
)) {
144 String m2Coordinates
= fileProps
.getProperty(SLC_ORIGIN_M2
.toString());
145 DefaultArtifact artifact
= new DefaultArtifact(m2Coordinates
);
147 // temporary rewrite, for migration
148 String localLicense
= fileProps
.getProperty(BUNDLE_LICENSE
.toString());
149 if (localLicense
!= null || artifact
.getVersion() != null) {
150 fileProps
.remove(BUNDLE_LICENSE
.toString());
151 fileProps
.put(SLC_ORIGIN_M2
.toString(), artifact
.getGroupId() + ":" + artifact
.getArtifactId());
152 try (Writer writer
= Files
.newBufferedWriter(p
)) {
153 for (Object key
: fileProps
.keySet()) {
154 String value
= fileProps
.getProperty(key
.toString());
155 writer
.write(key
+ ": " + value
+ '\n');
157 logger
.log(DEBUG
, () -> "Migrated " + p
);
161 artifact
.setVersion(m2Version
);
162 URL url
= MavenConventionsUtils
.mavenCentralUrl(artifact
);
163 Path downloaded
= download(url
, originBase
, artifact
.toM2Coordinates() + ".jar");
165 // prepare manifest entries
166 Properties mergeProps
= new Properties();
167 mergeProps
.putAll(commonProps
);
169 // Map<String, String> entries = new HashMap<>();
170 // for (Object key : commonProps.keySet()) {
171 // entries.put(key.toString(), commonProps.getProperty(key.toString()));
173 fileEntries
: for (Object key
: fileProps
.keySet()) {
174 if (ManifestConstants
.SLC_ORIGIN_M2
.toString().equals(key
))
175 continue fileEntries
;
176 String value
= fileProps
.getProperty(key
.toString());
177 Object previousValue
= mergeProps
.put(key
.toString(), value
);
178 if (previousValue
!= null) {
179 logger
.log(Level
.WARNING
,
180 downloaded
+ ": " + key
+ " was " + previousValue
+ ", overridden with " + value
);
183 mergeProps
.put(ManifestConstants
.SLC_ORIGIN_M2
.toString(), artifact
.toM2Coordinates());
184 Path targetBundleDir
= processBndJar(downloaded
, targetCategoryBase
, mergeProps
, artifact
);
185 // logger.log(Level.DEBUG, () -> "Processed " + downloaded);
188 downloadAndProcessM2Sources(artifact
, targetBundleDir
);
190 createJar(targetBundleDir
);
192 } catch (IOException e
) {
193 throw new RuntimeException("Cannot process " + duDir
, e
);
198 protected void downloadAndProcessM2Sources(DefaultArtifact artifact
, Path targetBundleDir
) throws IOException
{
199 DefaultArtifact sourcesArtifact
= new DefaultArtifact(artifact
.toM2Coordinates(), "sources");
200 URL sourcesUrl
= MavenConventionsUtils
.mavenCentralUrl(sourcesArtifact
);
201 Path sourcesDownloaded
= download(sourcesUrl
, originBase
, artifact
.toM2Coordinates() + ".sources.jar");
202 processM2SourceJar(sourcesDownloaded
, targetBundleDir
);
203 logger
.log(Level
.DEBUG
, () -> "Processed source " + sourcesDownloaded
);
207 protected Path
processBndJar(Path downloaded
, Path targetCategoryBase
, Properties fileProps
,
208 DefaultArtifact artifact
) {
211 Map
<String
, String
> additionalEntries
= new TreeMap
<>();
212 boolean doNotModify
= Boolean
.parseBoolean(fileProps
213 .getOrDefault(ManifestConstants
.SLC_ORIGIN_MANIFEST_NOT_MODIFIED
.toString(), "false").toString());
215 // we always force the symbolic name
218 fileEntries
: for (Object key
: fileProps
.keySet()) {
219 if (ManifestConstants
.SLC_ORIGIN_M2
.toString().equals(key
))
220 continue fileEntries
;
221 String value
= fileProps
.getProperty(key
.toString());
222 additionalEntries
.put(key
.toString(), value
);
225 if (artifact
!= null) {
226 if (!fileProps
.containsKey(BUNDLE_SYMBOLICNAME
.toString())) {
227 fileProps
.put(BUNDLE_SYMBOLICNAME
.toString(), artifact
.getName());
229 if (!fileProps
.containsKey(BUNDLE_VERSION
.toString())) {
230 fileProps
.put(BUNDLE_VERSION
.toString(), artifact
.getVersion());
234 if (!fileProps
.containsKey(EXPORT_PACKAGE
.toString())) {
235 fileProps
.put(EXPORT_PACKAGE
.toString(),
236 "*;version=\"" + fileProps
.getProperty(BUNDLE_VERSION
.toString()) + "\"");
238 // if (!fileProps.contains(IMPORT_PACKAGE.toString())) {
239 // fileProps.put(IMPORT_PACKAGE.toString(), "*");
242 try (Analyzer bndAnalyzer
= new Analyzer()) {
243 bndAnalyzer
.setProperties(fileProps
);
244 Jar jar
= new Jar(downloaded
.toFile());
245 bndAnalyzer
.setJar(jar
);
246 Manifest manifest
= bndAnalyzer
.calcManifest();
248 keys
: for (Object key
: manifest
.getMainAttributes().keySet()) {
249 Object value
= manifest
.getMainAttributes().get(key
);
251 switch (key
.toString()) {
253 case "Bnd-LastModified":
257 if ("Require-Capability".equals(key
.toString())
258 && value
.toString().equals("osgi.ee;filter:=\"(&(osgi.ee=JavaSE)(version=1.1))\""))
259 continue keys
;// hack for very old classes
260 additionalEntries
.put(key
.toString(), value
.toString());
261 logger
.log(DEBUG
, () -> key
+ "=" + value
);
266 // try (Builder bndBuilder = new Builder()) {
267 // Jar jar = new Jar(downloaded.toFile());
268 // bndBuilder.addClasspath(jar);
269 // Path targetBundleDir = targetCategoryBase.resolve(artifact.getName() + "." + artifact.getBranch());
271 // Jar target = new Jar(targetBundleDir.toFile());
272 // bndBuilder.setJar(target);
273 // return targetBundleDir;
276 Path targetBundleDir
= processBundleJar(downloaded
, targetCategoryBase
, additionalEntries
);
277 logger
.log(Level
.DEBUG
, () -> "Processed " + downloaded
);
278 return targetBundleDir
;
279 } catch (Exception e
) {
280 throw new RuntimeException("Cannot BND process " + downloaded
, e
);
285 protected void processM2SourceJar(Path file
, Path targetBundleDir
) throws IOException
{
286 try (JarInputStream jarIn
= new JarInputStream(Files
.newInputStream(file
), false)) {
287 Path targetSourceDir
= targetBundleDir
.resolve("OSGI-OPT/src");
289 // TODO make it less dangerous?
290 if (Files
.exists(targetSourceDir
)) {
291 deleteDirectory(targetSourceDir
);
293 Files
.createDirectories(targetSourceDir
);
298 entries
: while ((entry
= jarIn
.getNextJarEntry()) != null) {
299 if (entry
.isDirectory())
301 if (entry
.getName().startsWith("META-INF"))// skip META-INF entries
303 Path target
= targetSourceDir
.resolve(entry
.getName());
304 Files
.createDirectories(target
.getParent());
305 Files
.copy(jarIn
, target
);
306 logger
.log(Level
.TRACE
, () -> "Copied source " + target
);
312 public void processEclipseArchive(Path duDir
) {
314 String category
= duDir
.getParent().getFileName().toString();
315 Path targetCategoryBase
= a2Base
.resolve(category
);
316 Files
.createDirectories(targetCategoryBase
);
317 Files
.createDirectories(originBase
);
319 Path commonBnd
= duDir
.resolve(COMMON_BND
);
320 Properties commonProps
= new Properties();
321 try (InputStream in
= Files
.newInputStream(commonBnd
)) {
322 commonProps
.load(in
);
324 Properties includes
= new Properties();
325 try (InputStream in
= Files
.newInputStream(duDir
.resolve("includes.properties"))) {
328 String url
= commonProps
.getProperty(ManifestConstants
.SLC_ORIGIN_URI
.toString());
329 Path downloaded
= tryDownload(url
, originBase
);
331 FileSystem zipFs
= FileSystems
.newFileSystem(downloaded
, (ClassLoader
) null);
333 List
<PathMatcher
> pathMatchers
= new ArrayList
<>();
334 for (Object pattern
: includes
.keySet()) {
335 PathMatcher pathMatcher
= zipFs
.getPathMatcher("glob:/" + pattern
);
336 pathMatchers
.add(pathMatcher
);
339 Files
.walkFileTree(zipFs
.getRootDirectories().iterator().next(), new SimpleFileVisitor
<Path
>() {
342 public FileVisitResult
visitFile(Path file
, BasicFileAttributes attrs
) throws IOException
{
343 pathMatchers
: for (PathMatcher pathMatcher
: pathMatchers
) {
344 if (pathMatcher
.matches(file
)) {
345 // Path target = targetBase.resolve(file.getFileName().toString());
346 // if (!Files.exists(target)) {
347 // Files.copy(file, target);
348 // logger.log(Level.DEBUG, () -> "Copied " + target + " from " + downloaded);
350 // logger.log(Level.DEBUG, () -> target + " already exists.");
353 if (file
.getFileName().toString().contains(".source_")) {
354 processEclipseSourceJar(file
, targetCategoryBase
);
355 logger
.log(Level
.DEBUG
, () -> "Processed source " + file
);
358 processBundleJar(file
, targetCategoryBase
, new HashMap
<>());
359 logger
.log(Level
.DEBUG
, () -> "Processed " + file
);
361 continue pathMatchers
;
364 return super.visitFile(file
, attrs
);
368 DirectoryStream
<Path
> dirs
= Files
.newDirectoryStream(targetCategoryBase
, (p
) -> Files
.isDirectory(p
));
369 for (Path dir
: dirs
) {
372 } catch (IOException e
) {
373 throw new RuntimeException("Cannot process " + duDir
, e
);
378 protected Path
processBundleJar(Path file
, Path targetBase
, Map
<String
, String
> entries
) throws IOException
{
379 DefaultNameVersion nameVersion
;
380 Path targetBundleDir
;
381 try (JarInputStream jarIn
= new JarInputStream(Files
.newInputStream(file
), false)) {
382 Manifest manifest
= new Manifest(jarIn
.getManifest());
384 // remove problematic entries in MANIFEST
385 manifest
.getEntries().clear();
386 // Set<String> entriesToDelete = new HashSet<>();
387 // for (String key : manifest.getEntries().keySet()) {
388 //// logger.log(DEBUG, "## " + key);
389 // Attributes attrs = manifest.getAttributes(key);
390 // for (Object attrName : attrs.keySet()) {
391 //// logger.log(DEBUG, attrName + "=" + attrs.get(attrName));
392 // if ("Specification-Version".equals(attrName.toString())
393 // || "Implementation-Version".equals(attrName.toString())) {
394 // entriesToDelete.add(key);
399 // for (String key : entriesToDelete) {
400 // manifest.getEntries().remove(key);
403 String symbolicNameFromEntries
= entries
.get(BUNDLE_SYMBOLICNAME
.toString());
404 String versionFromEntries
= entries
.get(BUNDLE_VERSION
.toString());
406 if (symbolicNameFromEntries
!= null && versionFromEntries
!= null) {
407 nameVersion
= new DefaultNameVersion(symbolicNameFromEntries
, versionFromEntries
);
409 nameVersion
= nameVersionFromManifest(manifest
);
410 if (versionFromEntries
!= null && !nameVersion
.getVersion().equals(versionFromEntries
)) {
411 logger
.log(Level
.WARNING
, "Original version is " + nameVersion
.getVersion()
412 + " while new version is " + versionFromEntries
);
414 if (symbolicNameFromEntries
!= null) {
415 // we always force our symbolic name
416 nameVersion
.setName(symbolicNameFromEntries
);
419 targetBundleDir
= targetBase
.resolve(nameVersion
.getName() + "." + nameVersion
.getBranch());
421 // TODO make it less dangerous?
422 if (Files
.exists(targetBundleDir
)) {
423 deleteDirectory(targetBundleDir
);
428 entries
: while ((entry
= jarIn
.getNextJarEntry()) != null) {
429 if (entry
.isDirectory())
431 if (entry
.getName().endsWith(".RSA") || entry
.getName().endsWith(".SF"))
433 Path target
= targetBundleDir
.resolve(entry
.getName());
434 Files
.createDirectories(target
.getParent());
435 Files
.copy(jarIn
, target
);
436 logger
.log(Level
.TRACE
, () -> "Copied " + target
);
440 Path manifestPath
= targetBundleDir
.resolve("META-INF/MANIFEST.MF");
441 Files
.createDirectories(manifestPath
.getParent());
442 for (String key
: entries
.keySet()) {
443 String value
= entries
.get(key
);
444 Object previousValue
= manifest
.getMainAttributes().putValue(key
, value
);
445 if (previousValue
!= null && !previousValue
.equals(value
)) {
446 if (ManifestConstants
.IMPORT_PACKAGE
.toString().equals(key
)
447 || ManifestConstants
.EXPORT_PACKAGE
.toString().equals(key
))
448 logger
.log(Level
.WARNING
, file
.getFileName() + ": " + key
+ " was modified");
451 logger
.log(Level
.WARNING
, file
.getFileName() + ": " + key
+ " was " + previousValue
452 + ", overridden with " + value
);
455 try (OutputStream out
= Files
.newOutputStream(manifestPath
)) {
459 return targetBundleDir
;
462 protected void processEclipseSourceJar(Path file
, Path targetBase
) throws IOException
{
463 // NameVersion nameVersion;
464 Path targetBundleDir
;
465 try (JarInputStream jarIn
= new JarInputStream(Files
.newInputStream(file
), false)) {
466 Manifest manifest
= jarIn
.getManifest();
467 // nameVersion = nameVersionFromManifest(manifest);
469 String
[] relatedBundle
= manifest
.getMainAttributes().getValue("Eclipse-SourceBundle").split(";");
470 String version
= relatedBundle
[1].substring("version=\"".length());
471 version
= version
.substring(0, version
.length() - 1);
472 NameVersion nameVersion
= new DefaultNameVersion(relatedBundle
[0], version
);
473 targetBundleDir
= targetBase
.resolve(nameVersion
.getName() + "." + nameVersion
.getBranch());
475 Path targetSourceDir
= targetBundleDir
.resolve("OSGI-OPT/src");
477 // TODO make it less dangerous?
478 if (Files
.exists(targetSourceDir
)) {
479 deleteDirectory(targetSourceDir
);
481 Files
.createDirectories(targetSourceDir
);
486 entries
: while ((entry
= jarIn
.getNextJarEntry()) != null) {
487 if (entry
.isDirectory())
489 if (entry
.getName().startsWith("META-INF"))// skip META-INF entries
491 Path target
= targetSourceDir
.resolve(entry
.getName());
492 Files
.createDirectories(target
.getParent());
493 Files
.copy(jarIn
, target
);
494 logger
.log(Level
.TRACE
, () -> "Copied source " + target
);
498 // Path manifestPath = targetBundleDir.resolve("META-INF/MANIFEST.MF");
499 // Files.createDirectories(manifestPath.getParent());
500 // try (OutputStream out = Files.newOutputStream(manifestPath)) {
501 // manifest.write(out);
507 static void deleteDirectory(Path path
) throws IOException
{
508 if (!Files
.exists(path
))
510 Files
.walkFileTree(path
, new SimpleFileVisitor
<Path
>() {
512 public FileVisitResult
postVisitDirectory(Path directory
, IOException e
) throws IOException
{
515 Files
.delete(directory
);
516 return FileVisitResult
.CONTINUE
;
520 public FileVisitResult
visitFile(Path file
, BasicFileAttributes attrs
) throws IOException
{
522 return FileVisitResult
.CONTINUE
;
527 protected DefaultNameVersion
nameVersionFromManifest(Manifest manifest
) {
528 Attributes attrs
= manifest
.getMainAttributes();
530 String symbolicName
= attrs
.getValue(ManifestConstants
.BUNDLE_SYMBOLICNAME
.toString());
531 if (symbolicName
== null)
533 // make sure there is no directive
534 symbolicName
= symbolicName
.split(";")[0];
536 String version
= attrs
.getValue(ManifestConstants
.BUNDLE_VERSION
.toString());
537 return new DefaultNameVersion(symbolicName
, version
);
540 protected Path
tryDownload(String uri
, Path dir
) throws IOException
{
542 List
<String
> urlBases
= null;
543 String uriPrefix
= null;
544 uriPrefixes
: for (String uriPref
: mirrors
.keySet()) {
545 if (uri
.startsWith(uriPref
)) {
546 if (mirrors
.get(uriPref
).size() > 0) {
547 urlBases
= mirrors
.get(uriPref
);
553 if (urlBases
== null)
555 return download(new URL(uri
), dir
, null);
556 } catch (FileNotFoundException e
) {
557 throw new FileNotFoundException("Cannot find " + uri
);
561 for (String urlBase
: urlBases
) {
562 String relativePath
= uri
.substring(uriPrefix
.length());
563 URL url
= new URL(urlBase
+ relativePath
);
565 return download(url
, dir
, null);
566 } catch (FileNotFoundException e
) {
567 logger
.log(Level
.WARNING
, "Cannot download " + url
+ ", trying another mirror");
570 throw new FileNotFoundException("Cannot find " + uri
);
573 // protected String simplifyName(URL u) {
574 // String name = u.getPath().substring(u.getPath().lastIndexOf('/') + 1);
578 protected Path
download(URL url
, Path dir
, String name
) throws IOException
{
582 name
= url
.getPath().substring(url
.getPath().lastIndexOf('/') + 1);
585 dest
= dir
.resolve(name
);
586 if (Files
.exists(dest
)) {
587 logger
.log(Level
.TRACE
, () -> "File " + dest
+ " already exists for " + url
+ ", not downloading again");
591 try (InputStream in
= url
.openStream()) {
592 Files
.copy(in
, dest
);
593 logger
.log(Level
.DEBUG
, () -> "Downloaded " + dest
+ " from " + url
);
598 protected Path
createJar(Path bundleDir
) throws IOException
{
599 Path jarPath
= bundleDir
.getParent().resolve(bundleDir
.getFileName() + ".jar");
600 Path manifestPath
= bundleDir
.resolve("META-INF/MANIFEST.MF");
602 try (InputStream in
= Files
.newInputStream(manifestPath
)) {
603 manifest
= new Manifest(in
);
605 try (JarOutputStream jarOut
= new JarOutputStream(Files
.newOutputStream(jarPath
), manifest
)) {
606 Files
.walkFileTree(bundleDir
, new SimpleFileVisitor
<Path
>() {
609 public FileVisitResult
visitFile(Path file
, BasicFileAttributes attrs
) throws IOException
{
610 if (file
.getFileName().toString().equals("MANIFEST.MF"))
611 return super.visitFile(file
, attrs
);
612 JarEntry entry
= new JarEntry(bundleDir
.relativize(file
).toString());
613 jarOut
.putNextEntry(entry
);
614 Files
.copy(file
, jarOut
);
615 return super.visitFile(file
, attrs
);
620 deleteDirectory(bundleDir
);
624 public static void main(String
[] args
) {
625 Path factoryBase
= Paths
.get("../output/a2").toAbsolutePath().normalize();
626 A2Factory factory
= new A2Factory(factoryBase
);
628 Path descriptorsBase
= Paths
.get("../tp").toAbsolutePath().normalize();
630 // factory.processSingleM2ArtifactDistributionUnit(descriptorsBase.resolve("org.argeo.tp.apache").resolve("org.apache.xml.resolver.bnd"));
631 // factory.processM2BasedDistributionUnit(descriptorsBase.resolve("org.argeo.tp.apache/apache-sshd"));
632 factory
.processM2BasedDistributionUnit(descriptorsBase
.resolve("org.argeo.tp.jetty/jetty"));
633 factory
.processM2BasedDistributionUnit(descriptorsBase
.resolve("org.argeo.tp.jetty/jetty-websocket"));
637 factory
.processEclipseArchive(
638 descriptorsBase
.resolve("org.argeo.tp.eclipse.equinox").resolve("eclipse-equinox"));
639 factory
.processEclipseArchive(descriptorsBase
.resolve("org.argeo.tp.eclipse.rap").resolve("eclipse-rap"));
640 factory
.processEclipseArchive(descriptorsBase
.resolve("org.argeo.tp.eclipse.rcp").resolve("eclipse-rcp"));
645 factory
.processCategory(descriptorsBase
.resolve("org.argeo.tp.sdk"));
646 factory
.processCategory(descriptorsBase
.resolve("org.argeo.tp"));
647 factory
.processCategory(descriptorsBase
.resolve("org.argeo.tp.apache"));
648 factory
.processCategory(descriptorsBase
.resolve("org.argeo.tp.jetty"));
649 factory
.processCategory(descriptorsBase
.resolve("org.argeo.tp.jcr"));