1 package org
.argeo
.build
;
3 import static java
.lang
.System
.Logger
.Level
.DEBUG
;
4 import static java
.lang
.System
.Logger
.Level
.WARNING
;
5 import static org
.argeo
.build
.Repackage
.ManifestConstants
.BUNDLE_SYMBOLICNAME
;
6 import static org
.argeo
.build
.Repackage
.ManifestConstants
.BUNDLE_VERSION
;
7 import static org
.argeo
.build
.Repackage
.ManifestConstants
.EXPORT_PACKAGE
;
8 import static org
.argeo
.build
.Repackage
.ManifestConstants
.SLC_ORIGIN_M2
;
9 import static org
.argeo
.build
.Repackage
.ManifestConstants
.SLC_ORIGIN_M2_REPO
;
12 import java
.io
.FileNotFoundException
;
13 import java
.io
.IOException
;
14 import java
.io
.InputStream
;
15 import java
.io
.OutputStream
;
16 import java
.lang
.System
.Logger
;
17 import java
.lang
.System
.Logger
.Level
;
18 import java
.net
.MalformedURLException
;
20 import java
.nio
.charset
.StandardCharsets
;
21 import java
.nio
.file
.DirectoryStream
;
22 import java
.nio
.file
.FileSystem
;
23 import java
.nio
.file
.FileSystems
;
24 import java
.nio
.file
.FileVisitResult
;
25 import java
.nio
.file
.Files
;
26 import java
.nio
.file
.Path
;
27 import java
.nio
.file
.PathMatcher
;
28 import java
.nio
.file
.Paths
;
29 import java
.nio
.file
.SimpleFileVisitor
;
30 import java
.nio
.file
.StandardOpenOption
;
31 import java
.nio
.file
.attribute
.BasicFileAttributes
;
32 import java
.util
.ArrayList
;
33 import java
.util
.HashMap
;
34 import java
.util
.Iterator
;
35 import java
.util
.List
;
37 import java
.util
.Objects
;
38 import java
.util
.Properties
;
39 import java
.util
.TreeMap
;
40 import java
.util
.concurrent
.CompletableFuture
;
41 import java
.util
.jar
.Attributes
;
42 import java
.util
.jar
.JarEntry
;
43 import java
.util
.jar
.JarInputStream
;
44 import java
.util
.jar
.JarOutputStream
;
45 import java
.util
.jar
.Manifest
;
46 import java
.util
.zip
.Deflater
;
48 import aQute
.bnd
.osgi
.Analyzer
;
49 import aQute
.bnd
.osgi
.Jar
;
51 /** The central class for A2 packaging. */
52 public class Repackage
{
53 private final static Logger logger
= System
.getLogger(Repackage
.class.getName());
55 private final static String ENV_BUILD_SOURCE_BUNDLES
= "BUILD_SOURCE_BUNDLES";
57 private final static boolean parallel
= true;
59 /** Main entry point. */
60 public static void main(String
[] args
) {
61 if (args
.length
< 2) {
62 System
.err
.println("Usage: <path to a2 output dir> <category1> <category2> ...");
65 Path a2Base
= Paths
.get(args
[0]).toAbsolutePath().normalize();
66 Path descriptorsBase
= Paths
.get(".").toAbsolutePath().normalize();
67 Repackage factory
= new Repackage(a2Base
, descriptorsBase
);
69 List
<CompletableFuture
<Void
>> toDos
= new ArrayList
<>();
70 for (int i
= 1; i
< args
.length
; i
++) {
71 Path p
= Paths
.get(args
[i
]);
73 toDos
.add(CompletableFuture
.runAsync(() -> factory
.processCategory(p
)));
75 factory
.processCategory(p
);
77 CompletableFuture
.allOf(toDos
.toArray(new CompletableFuture
[toDos
.size()])).join();
80 private final static String COMMON_BND
= "common.bnd";
81 private final static String MERGE_BND
= "merge.bnd";
83 private Path originBase
;
85 private Path a2LibBase
;
86 private Path descriptorsBase
;
88 private Properties uris
= new Properties();
90 /** key is URI prefix, value list of base URLs */
91 private Map
<String
, List
<String
>> mirrors
= new HashMap
<String
, List
<String
>>();
93 private final boolean sourceBundles
;
95 public Repackage(Path a2Base
, Path descriptorsBase
) {
96 sourceBundles
= Boolean
.parseBoolean(System
.getenv(ENV_BUILD_SOURCE_BUNDLES
));
98 logger
.log(Level
.INFO
, "Sources will be packaged separately");
100 Objects
.requireNonNull(a2Base
);
101 Objects
.requireNonNull(descriptorsBase
);
102 this.originBase
= Paths
.get(System
.getProperty("user.home"), ".cache", "argeo/build/origin");
103 // TODO define and use a build base
104 this.a2Base
= a2Base
;
105 this.a2LibBase
= a2Base
.resolve("lib");
106 this.descriptorsBase
= descriptorsBase
;
107 if (!Files
.exists(this.descriptorsBase
))
108 throw new IllegalArgumentException(this.descriptorsBase
+ " does not exist");
111 Path urisPath
= this.descriptorsBase
.resolve("uris.properties");
112 if (Files
.exists(urisPath
)) {
113 try (InputStream in
= Files
.newInputStream(urisPath
)) {
115 } catch (IOException e
) {
116 throw new IllegalStateException("Cannot load " + urisPath
, e
);
121 Path eclipseMirrorsPath
= this.descriptorsBase
.resolve("eclipse.mirrors.txt");
122 List
<String
> eclipseMirrors
= new ArrayList
<>();
123 if (Files
.exists(eclipseMirrorsPath
)) {
125 eclipseMirrors
= Files
.readAllLines(eclipseMirrorsPath
, StandardCharsets
.UTF_8
);
126 } catch (IOException e
) {
127 throw new IllegalStateException("Cannot load " + eclipseMirrorsPath
, e
);
129 for (Iterator
<String
> it
= eclipseMirrors
.iterator(); it
.hasNext();) {
130 String value
= it
.next();
131 if (value
.strip().equals(""))
136 mirrors
.put("http://www.eclipse.org/downloads", eclipseMirrors
);
143 /** Process a whole category/group id. */
144 public void processCategory(Path categoryRelativePath
) {
146 Path targetCategoryBase
= descriptorsBase
.resolve(categoryRelativePath
);
147 DirectoryStream
<Path
> bnds
= Files
.newDirectoryStream(targetCategoryBase
,
148 (p
) -> p
.getFileName().toString().endsWith(".bnd") && !p
.getFileName().toString().equals(COMMON_BND
)
149 && !p
.getFileName().toString().equals(MERGE_BND
));
150 for (Path p
: bnds
) {
151 processSingleM2ArtifactDistributionUnit(p
);
154 DirectoryStream
<Path
> dus
= Files
.newDirectoryStream(targetCategoryBase
, (p
) -> Files
.isDirectory(p
));
155 for (Path duDir
: dus
) {
156 if (duDir
.getFileName().toString().startsWith("eclipse-")) {
157 processEclipseArchive(duDir
);
159 processM2BasedDistributionUnit(duDir
);
162 } catch (IOException e
) {
163 throw new RuntimeException("Cannot process category " + categoryRelativePath
, e
);
167 /** Process a standalone Maven artifact. */
168 public void processSingleM2ArtifactDistributionUnit(Path bndFile
) {
170 // String category = bndFile.getParent().getFileName().toString();
171 Path categoryRelativePath
= descriptorsBase
.relativize(bndFile
.getParent());
172 Path targetCategoryBase
= a2Base
.resolve(categoryRelativePath
);
174 Properties fileProps
= new Properties();
175 try (InputStream in
= Files
.newInputStream(bndFile
)) {
178 String repoStr
= fileProps
.containsKey(SLC_ORIGIN_M2_REPO
.toString())
179 ? fileProps
.getProperty(SLC_ORIGIN_M2_REPO
.toString())
182 if (!fileProps
.containsKey(BUNDLE_SYMBOLICNAME
.toString())) {
183 // use file name as symbolic name
184 String symbolicName
= bndFile
.getFileName().toString();
185 symbolicName
= symbolicName
.substring(0, symbolicName
.length() - ".bnd".length());
186 fileProps
.put(BUNDLE_SYMBOLICNAME
.toString(), symbolicName
);
189 String m2Coordinates
= fileProps
.getProperty(SLC_ORIGIN_M2
.toString());
190 if (m2Coordinates
== null)
191 throw new IllegalArgumentException("No M2 coordinates available for " + bndFile
);
192 M2Artifact artifact
= new M2Artifact(m2Coordinates
);
193 URL url
= M2ConventionsUtils
.mavenRepoUrl(repoStr
, artifact
);
194 Path downloaded
= downloadMaven(url
, originBase
, artifact
);
196 Path targetBundleDir
= processBndJar(downloaded
, targetCategoryBase
, fileProps
, artifact
);
198 downloadAndProcessM2Sources(repoStr
, artifact
, targetBundleDir
);
200 createJar(targetBundleDir
);
201 } catch (Exception e
) {
202 throw new RuntimeException("Cannot process " + bndFile
, e
);
206 /** Process multiple Maven artifacts. */
207 public void processM2BasedDistributionUnit(Path duDir
) {
209 // String category = duDir.getParent().getFileName().toString();
210 Path categoryRelativePath
= descriptorsBase
.relativize(duDir
.getParent());
211 Path targetCategoryBase
= a2Base
.resolve(categoryRelativePath
);
214 Path mergeBnd
= duDir
.resolve(MERGE_BND
);
215 if (Files
.exists(mergeBnd
)) {
216 mergeM2Artifacts(mergeBnd
);
220 Path commonBnd
= duDir
.resolve(COMMON_BND
);
221 if (!Files
.exists(commonBnd
)) {
224 Properties commonProps
= new Properties();
225 try (InputStream in
= Files
.newInputStream(commonBnd
)) {
226 commonProps
.load(in
);
229 String m2Version
= commonProps
.getProperty(SLC_ORIGIN_M2
.toString());
230 if (m2Version
== null) {
231 logger
.log(Level
.WARNING
, "Ignoring " + duDir
+ " as it is not an M2-based distribution unit");
232 return;// ignore, this is probably an Eclipse archive
234 if (!m2Version
.startsWith(":")) {
235 throw new IllegalStateException("Only the M2 version can be specified: " + m2Version
);
237 m2Version
= m2Version
.substring(1);
239 DirectoryStream
<Path
> ds
= Files
.newDirectoryStream(duDir
,
240 (p
) -> p
.getFileName().toString().endsWith(".bnd") && !p
.getFileName().toString().equals(COMMON_BND
)
241 && !p
.getFileName().toString().equals(MERGE_BND
));
243 Properties fileProps
= new Properties();
244 try (InputStream in
= Files
.newInputStream(p
)) {
247 String m2Coordinates
= fileProps
.getProperty(SLC_ORIGIN_M2
.toString());
248 M2Artifact artifact
= new M2Artifact(m2Coordinates
);
250 artifact
.setVersion(m2Version
);
252 // prepare manifest entries
253 Properties mergeProps
= new Properties();
254 mergeProps
.putAll(commonProps
);
256 fileEntries
: for (Object key
: fileProps
.keySet()) {
257 if (ManifestConstants
.SLC_ORIGIN_M2
.toString().equals(key
))
258 continue fileEntries
;
259 String value
= fileProps
.getProperty(key
.toString());
260 Object previousValue
= mergeProps
.put(key
.toString(), value
);
261 if (previousValue
!= null) {
262 logger
.log(Level
.WARNING
,
263 commonBnd
+ ": " + key
+ " was " + previousValue
+ ", overridden with " + value
);
266 mergeProps
.put(ManifestConstants
.SLC_ORIGIN_M2
.toString(), artifact
.toM2Coordinates());
267 if (!mergeProps
.containsKey(BUNDLE_SYMBOLICNAME
.toString())) {
268 // use file name as symbolic name
269 String symbolicName
= p
.getFileName().toString();
270 symbolicName
= symbolicName
.substring(0, symbolicName
.length() - ".bnd".length());
271 mergeProps
.put(BUNDLE_SYMBOLICNAME
.toString(), symbolicName
);
274 String repoStr
= mergeProps
.containsKey(SLC_ORIGIN_M2_REPO
.toString())
275 ? mergeProps
.getProperty(SLC_ORIGIN_M2_REPO
.toString())
279 URL url
= M2ConventionsUtils
.mavenRepoUrl(repoStr
, artifact
);
280 Path downloaded
= downloadMaven(url
, originBase
, artifact
);
282 Path targetBundleDir
= processBndJar(downloaded
, targetCategoryBase
, mergeProps
, artifact
);
283 // logger.log(Level.DEBUG, () -> "Processed " + downloaded);
286 downloadAndProcessM2Sources(repoStr
, artifact
, targetBundleDir
);
288 createJar(targetBundleDir
);
290 } catch (IOException e
) {
291 throw new RuntimeException("Cannot process " + duDir
, e
);
296 /** Merge multiple Maven artifacts. */
297 protected void mergeM2Artifacts(Path mergeBnd
) throws IOException
{
298 Path duDir
= mergeBnd
.getParent();
299 String category
= duDir
.getParent().getFileName().toString();
300 Path targetCategoryBase
= a2Base
.resolve(category
);
302 Properties mergeProps
= new Properties();
303 try (InputStream in
= Files
.newInputStream(mergeBnd
)) {
308 String m2Version
= mergeProps
.getProperty(SLC_ORIGIN_M2
.toString());
309 if (m2Version
== null) {
310 logger
.log(Level
.WARNING
, "Ignoring " + duDir
+ " as it is not an M2-based distribution unit");
311 return;// ignore, this is probably an Eclipse archive
313 if (!m2Version
.startsWith(":")) {
314 throw new IllegalStateException("Only the M2 version can be specified: " + m2Version
);
316 m2Version
= m2Version
.substring(1);
317 mergeProps
.put(ManifestConstants
.BUNDLE_VERSION
.toString(), m2Version
);
319 String artifactsStr
= mergeProps
.getProperty(ManifestConstants
.SLC_ORIGIN_M2_MERGE
.toString());
320 if (artifactsStr
== null)
321 throw new IllegalArgumentException(
322 mergeBnd
+ ": " + ManifestConstants
.SLC_ORIGIN_M2_MERGE
+ " must be set");
324 String repoStr
= mergeProps
.containsKey(SLC_ORIGIN_M2_REPO
.toString())
325 ? mergeProps
.getProperty(SLC_ORIGIN_M2_REPO
.toString())
328 String bundleSymbolicName
= mergeProps
.getProperty(ManifestConstants
.BUNDLE_SYMBOLICNAME
.toString());
329 if (bundleSymbolicName
== null)
330 throw new IllegalArgumentException("Bundle-SymbolicName must be set in " + mergeBnd
);
331 CategoryNameVersion nameVersion
= new M2Artifact(category
+ ":" + bundleSymbolicName
+ ":" + m2Version
);
332 Path targetBundleDir
= targetCategoryBase
.resolve(bundleSymbolicName
+ "." + nameVersion
.getBranch());
334 String
[] artifacts
= artifactsStr
.split(",");
335 artifacts
: for (String str
: artifacts
) {
336 String m2Coordinates
= str
.trim();
337 if ("".equals(m2Coordinates
))
339 M2Artifact artifact
= new M2Artifact(m2Coordinates
.trim());
340 if (artifact
.getVersion() == null)
341 artifact
.setVersion(m2Version
);
342 URL url
= M2ConventionsUtils
.mavenRepoUrl(repoStr
, artifact
);
343 Path downloaded
= downloadMaven(url
, originBase
, artifact
);
345 try (JarInputStream jarIn
= new JarInputStream(Files
.newInputStream(downloaded
), false)) {
346 entries
: while ((entry
= jarIn
.getNextJarEntry()) != null) {
347 if (entry
.isDirectory())
349 else if (entry
.getName().endsWith(".RSA") || entry
.getName().endsWith(".SF"))
351 else if (entry
.getName().startsWith("META-INF/versions/"))
353 else if (entry
.getName().startsWith("META-INF/maven/"))
355 else if (entry
.getName().equals("module-info.class"))
357 else if (entry
.getName().equals("META-INF/NOTICE"))
359 else if (entry
.getName().equals("META-INF/NOTICE.txt"))
361 else if (entry
.getName().equals("META-INF/LICENSE"))
363 else if (entry
.getName().equals("META-INF/LICENSE.md"))
365 else if (entry
.getName().equals("META-INF/LICENSE-notice.md"))
367 else if (entry
.getName().equals("META-INF/DEPENDENCIES"))
369 if (entry
.getName().startsWith(".cache/")) // Apache SSHD
371 Path target
= targetBundleDir
.resolve(entry
.getName());
372 Files
.createDirectories(target
.getParent());
373 if (!Files
.exists(target
)) {
374 Files
.copy(jarIn
, target
);
376 if (entry
.getName().startsWith("META-INF/services/")) {
377 try (OutputStream out
= Files
.newOutputStream(target
, StandardOpenOption
.APPEND
)) {
378 out
.write("\n".getBytes());
379 jarIn
.transferTo(out
);
380 logger
.log(Level
.WARNING
, artifact
.getArtifactId() + " - Appended " + entry
.getName());
382 } else if (entry
.getName().startsWith("org/apache/batik/")) {
383 logger
.log(Level
.WARNING
, "Skip " + entry
.getName());
386 throw new IllegalStateException("File " + target
+ " from " + artifact
+ " already exists");
389 logger
.log(Level
.TRACE
, () -> "Copied " + target
);
393 downloadAndProcessM2Sources(repoStr
, artifact
, targetBundleDir
);
396 // additional service files
397 Path servicesDir
= duDir
.resolve("services");
398 if (Files
.exists(servicesDir
)) {
399 for (Path p
: Files
.newDirectoryStream(servicesDir
)) {
400 Path target
= targetBundleDir
.resolve("META-INF/services/").resolve(p
.getFileName());
401 try (InputStream in
= Files
.newInputStream(p
);
402 OutputStream out
= Files
.newOutputStream(target
, StandardOpenOption
.APPEND
);) {
403 out
.write("\n".getBytes());
405 logger
.log(Level
.WARNING
, "Appended " + p
);
410 Map
<String
, String
> entries
= new TreeMap
<>();
411 try (Analyzer bndAnalyzer
= new Analyzer()) {
412 bndAnalyzer
.setProperties(mergeProps
);
413 Jar jar
= new Jar(targetBundleDir
.toFile());
414 bndAnalyzer
.setJar(jar
);
415 Manifest manifest
= bndAnalyzer
.calcManifest();
417 keys
: for (Object key
: manifest
.getMainAttributes().keySet()) {
418 Object value
= manifest
.getMainAttributes().get(key
);
420 switch (key
.toString()) {
422 case "Bnd-LastModified":
426 if ("Require-Capability".equals(key
.toString())
427 && value
.toString().equals("osgi.ee;filter:=\"(&(osgi.ee=JavaSE)(version=1.1))\""))
428 continue keys
;// hack for very old classes
429 entries
.put(key
.toString(), value
.toString());
430 // logger.log(DEBUG, () -> key + "=" + value);
433 } catch (Exception e
) {
434 throw new RuntimeException("Cannot process " + mergeBnd
, e
);
437 Manifest manifest
= new Manifest();
438 Path manifestPath
= targetBundleDir
.resolve("META-INF/MANIFEST.MF");
439 Files
.createDirectories(manifestPath
.getParent());
440 for (String key
: entries
.keySet()) {
441 String value
= entries
.get(key
);
442 manifest
.getMainAttributes().putValue(key
, value
);
445 try (OutputStream out
= Files
.newOutputStream(manifestPath
)) {
448 createJar(targetBundleDir
);
451 /** Generate MANIFEST using BND. */
452 protected Path
processBndJar(Path downloaded
, Path targetCategoryBase
, Properties fileProps
, M2Artifact artifact
) {
455 Map
<String
, String
> additionalEntries
= new TreeMap
<>();
456 boolean doNotModify
= Boolean
.parseBoolean(fileProps
457 .getOrDefault(ManifestConstants
.SLC_ORIGIN_MANIFEST_NOT_MODIFIED
.toString(), "false").toString());
459 // we always force the symbolic name
462 fileEntries
: for (Object key
: fileProps
.keySet()) {
463 if (ManifestConstants
.SLC_ORIGIN_M2
.toString().equals(key
))
464 continue fileEntries
;
465 String value
= fileProps
.getProperty(key
.toString());
466 additionalEntries
.put(key
.toString(), value
);
469 if (artifact
!= null) {
470 if (!fileProps
.containsKey(BUNDLE_SYMBOLICNAME
.toString())) {
471 fileProps
.put(BUNDLE_SYMBOLICNAME
.toString(), artifact
.getName());
473 if (!fileProps
.containsKey(BUNDLE_VERSION
.toString())) {
474 fileProps
.put(BUNDLE_VERSION
.toString(), artifact
.getVersion());
478 if (!fileProps
.containsKey(EXPORT_PACKAGE
.toString())) {
479 fileProps
.put(EXPORT_PACKAGE
.toString(),
480 "*;version=\"" + fileProps
.getProperty(BUNDLE_VERSION
.toString()) + "\"");
483 try (Analyzer bndAnalyzer
= new Analyzer()) {
484 bndAnalyzer
.setProperties(fileProps
);
485 Jar jar
= new Jar(downloaded
.toFile());
486 bndAnalyzer
.setJar(jar
);
487 Manifest manifest
= bndAnalyzer
.calcManifest();
489 keys
: for (Object key
: manifest
.getMainAttributes().keySet()) {
490 Object value
= manifest
.getMainAttributes().get(key
);
492 switch (key
.toString()) {
494 case "Bnd-LastModified":
498 if ("Require-Capability".equals(key
.toString())
499 && value
.toString().equals("osgi.ee;filter:=\"(&(osgi.ee=JavaSE)(version=1.1))\""))
500 continue keys
;// hack for very old classes
501 additionalEntries
.put(key
.toString(), value
.toString());
502 // logger.log(DEBUG, () -> key + "=" + value);
507 Path targetBundleDir
= processBundleJar(downloaded
, targetCategoryBase
, additionalEntries
);
508 logger
.log(Level
.DEBUG
, () -> "Processed " + downloaded
);
509 return targetBundleDir
;
510 } catch (Exception e
) {
511 throw new RuntimeException("Cannot BND process " + downloaded
, e
);
516 /** Download and integrates sources for a single Maven artifact. */
517 protected void downloadAndProcessM2Sources(String repoStr
, M2Artifact artifact
, Path targetBundleDir
)
519 // if (sourceBundles)
522 M2Artifact sourcesArtifact
= new M2Artifact(artifact
.toM2Coordinates(), "sources");
523 URL sourcesUrl
= M2ConventionsUtils
.mavenRepoUrl(repoStr
, sourcesArtifact
);
524 Path sourcesDownloaded
= downloadMaven(sourcesUrl
, originBase
, artifact
, true);
525 processM2SourceJar(sourcesDownloaded
, targetBundleDir
);
526 logger
.log(Level
.TRACE
, () -> "Processed source " + sourcesDownloaded
);
527 } catch (Exception e
) {
528 logger
.log(Level
.ERROR
, () -> "Cannot download source for " + artifact
);
533 /** Integrate sources from a downloaded jar file. */
534 protected void processM2SourceJar(Path file
, Path targetBundleDir
) throws IOException
{
535 try (JarInputStream jarIn
= new JarInputStream(Files
.newInputStream(file
), false)) {
536 Path targetSourceDir
= sourceBundles
537 ? targetBundleDir
.getParent().resolve(targetBundleDir
.toString() + ".src")
538 : targetBundleDir
.resolve("OSGI-OPT/src");
540 // TODO make it less dangerous?
541 if (Files
.exists(targetSourceDir
)) {
542 // deleteDirectory(targetSourceDir);
544 Files
.createDirectories(targetSourceDir
);
549 entries
: while ((entry
= jarIn
.getNextJarEntry()) != null) {
550 if (entry
.isDirectory())
552 if (entry
.getName().startsWith("META-INF"))// skip META-INF entries
554 if (entry
.getName().startsWith("module-info.java"))// skip META-INF entries
556 if (entry
.getName().startsWith("/")) // absolute paths
558 Path target
= targetSourceDir
.resolve(entry
.getName());
559 Files
.createDirectories(target
.getParent());
560 if (!Files
.exists(target
)) {
561 Files
.copy(jarIn
, target
);
562 logger
.log(Level
.TRACE
, () -> "Copied source " + target
);
564 logger
.log(Level
.WARNING
, () -> target
+ " already exists, skipping...");
571 /** Download a Maven artifact. */
572 protected Path
downloadMaven(URL url
, Path dir
, M2Artifact artifact
) throws IOException
{
573 return downloadMaven(url
, dir
, artifact
, false);
576 /** Download a Maven artifact. */
577 protected Path
downloadMaven(URL url
, Path dir
, M2Artifact artifact
, boolean sources
) throws IOException
{
578 return download(url
, dir
, artifact
.getGroupId() + '/' + artifact
.getArtifactId() + "-" + artifact
.getVersion()
579 + (sources ?
"-sources" : "") + ".jar");
586 /** Process an archive in Eclipse format. */
587 public void processEclipseArchive(Path duDir
) {
589 Path categoryRelativePath
= descriptorsBase
.relativize(duDir
.getParent());
590 Path targetCategoryBase
= a2Base
.resolve(categoryRelativePath
);
591 Files
.createDirectories(targetCategoryBase
);
592 // first delete all directories from previous builds
593 for (Path dir
: Files
.newDirectoryStream(targetCategoryBase
, (p
) -> Files
.isDirectory(p
))) {
594 deleteDirectory(dir
);
597 Files
.createDirectories(originBase
);
599 Path commonBnd
= duDir
.resolve(COMMON_BND
);
600 Properties commonProps
= new Properties();
601 try (InputStream in
= Files
.newInputStream(commonBnd
)) {
602 commonProps
.load(in
);
604 String url
= commonProps
.getProperty(ManifestConstants
.SLC_ORIGIN_URI
.toString());
606 url
= uris
.getProperty(duDir
.getFileName().toString());
608 throw new IllegalStateException("No url available for " + duDir
);
609 commonProps
.put(ManifestConstants
.SLC_ORIGIN_URI
.toString(), url
);
611 Path downloaded
= tryDownloadArchive(url
, originBase
);
613 FileSystem zipFs
= FileSystems
.newFileSystem(downloaded
, (ClassLoader
) null);
616 List
<PathMatcher
> includeMatchers
= new ArrayList
<>();
617 Properties includes
= new Properties();
618 try (InputStream in
= Files
.newInputStream(duDir
.resolve("includes.properties"))) {
621 for (Object pattern
: includes
.keySet()) {
622 PathMatcher pathMatcher
= zipFs
.getPathMatcher("glob:/" + pattern
);
623 includeMatchers
.add(pathMatcher
);
626 List
<PathMatcher
> excludeMatchers
= new ArrayList
<>();
627 Path excludeFile
= duDir
.resolve("excludes.properties");
628 if (Files
.exists(excludeFile
)) {
629 Properties excludes
= new Properties();
630 try (InputStream in
= Files
.newInputStream(excludeFile
)) {
633 for (Object pattern
: excludes
.keySet()) {
634 PathMatcher pathMatcher
= zipFs
.getPathMatcher("glob:/" + pattern
);
635 excludeMatchers
.add(pathMatcher
);
639 Files
.walkFileTree(zipFs
.getRootDirectories().iterator().next(), new SimpleFileVisitor
<Path
>() {
642 public FileVisitResult
visitFile(Path file
, BasicFileAttributes attrs
) throws IOException
{
643 includeMatchers
: for (PathMatcher includeMatcher
: includeMatchers
) {
644 if (includeMatcher
.matches(file
)) {
645 for (PathMatcher excludeMatcher
: excludeMatchers
) {
646 if (excludeMatcher
.matches(file
)) {
647 logger
.log(Level
.TRACE
, "Skipping excluded " + file
);
648 return FileVisitResult
.CONTINUE
;
651 if (file
.getFileName().toString().contains(".source_")) {
652 // if (!sourceBundles) {
653 processEclipseSourceJar(file
, targetCategoryBase
);
654 logger
.log(Level
.DEBUG
, () -> "Processed source " + file
);
658 Map
<String
, String
> map
= new HashMap
<>();
659 for (Object key
: commonProps
.keySet())
660 map
.put(key
.toString(), commonProps
.getProperty(key
.toString()));
661 processBundleJar(file
, targetCategoryBase
, map
);
662 logger
.log(Level
.DEBUG
, () -> "Processed " + file
);
664 break includeMatchers
;
667 return FileVisitResult
.CONTINUE
;
671 DirectoryStream
<Path
> dirs
= Files
.newDirectoryStream(targetCategoryBase
, (p
) -> Files
.isDirectory(p
)
672 && p
.getFileName().toString().indexOf('.') >= 0 && !p
.getFileName().toString().endsWith(".src"));
673 for (Path dir
: dirs
) {
676 } catch (IOException e
) {
677 throw new RuntimeException("Cannot process " + duDir
, e
);
682 /** Process sources in Eclipse format. */
683 protected void processEclipseSourceJar(Path file
, Path targetBase
) throws IOException
{
685 Path targetBundleDir
;
686 try (JarInputStream jarIn
= new JarInputStream(Files
.newInputStream(file
), false)) {
687 Manifest manifest
= jarIn
.getManifest();
689 String
[] relatedBundle
= manifest
.getMainAttributes().getValue("Eclipse-SourceBundle").split(";");
690 String version
= relatedBundle
[1].substring("version=\"".length());
691 version
= version
.substring(0, version
.length() - 1);
692 NameVersion nameVersion
= new NameVersion(relatedBundle
[0], version
);
693 targetBundleDir
= targetBase
.resolve(nameVersion
.getName() + "." + nameVersion
.getBranch());
695 Path targetSourceDir
= sourceBundles
696 ? targetBundleDir
.getParent().resolve(targetBundleDir
.toString() + ".src")
697 : targetBundleDir
.resolve("OSGI-OPT/src");
699 // TODO make it less dangerous?
700 if (Files
.exists(targetSourceDir
)) {
701 // deleteDirectory(targetSourceDir);
703 Files
.createDirectories(targetSourceDir
);
708 entries
: while ((entry
= jarIn
.getNextJarEntry()) != null) {
709 if (entry
.isDirectory())
711 if (entry
.getName().startsWith("META-INF"))// skip META-INF entries
713 Path target
= targetSourceDir
.resolve(entry
.getName());
714 Files
.createDirectories(target
.getParent());
715 Files
.copy(jarIn
, target
);
716 logger
.log(Level
.TRACE
, () -> "Copied source " + target
);
721 } catch (IOException e
) {
722 throw new IllegalStateException("Cannot process " + file
, e
);
730 /** Normalise a bundle. */
731 protected Path
processBundleJar(Path file
, Path targetBase
, Map
<String
, String
> entries
) throws IOException
{
732 NameVersion nameVersion
;
733 Path targetBundleDir
;
734 try (JarInputStream jarIn
= new JarInputStream(Files
.newInputStream(file
), false)) {
735 Manifest sourceManifest
= jarIn
.getManifest();
736 Manifest manifest
= sourceManifest
!= null ?
new Manifest(sourceManifest
) : new Manifest();
739 boolean isSingleton
= false;
740 String rawSourceSymbolicName
= manifest
.getMainAttributes()
741 .getValue(ManifestConstants
.BUNDLE_SYMBOLICNAME
.toString());
742 if (rawSourceSymbolicName
!= null) {
744 // make sure there is no directive
745 String
[] arr
= rawSourceSymbolicName
.split(";");
746 for (int i
= 1; i
< arr
.length
; i
++) {
747 if (arr
[i
].trim().equals("singleton:=true"))
749 logger
.log(DEBUG
, file
.getFileName() + " is a singleton");
753 // remove problematic entries in MANIFEST
754 manifest
.getEntries().clear();
756 String ourSymbolicName
= entries
.get(BUNDLE_SYMBOLICNAME
.toString());
757 String ourVersion
= entries
.get(BUNDLE_VERSION
.toString());
759 if (ourSymbolicName
!= null && ourVersion
!= null) {
760 nameVersion
= new NameVersion(ourSymbolicName
, ourVersion
);
762 nameVersion
= nameVersionFromManifest(manifest
);
763 if (ourVersion
!= null && !nameVersion
.getVersion().equals(ourVersion
)) {
764 logger
.log(Level
.WARNING
,
765 "Original version is " + nameVersion
.getVersion() + " while new version is " + ourVersion
);
766 entries
.put(BUNDLE_VERSION
.toString(), ourVersion
);
768 if (ourSymbolicName
!= null) {
769 // we always force our symbolic name
770 nameVersion
.setName(ourSymbolicName
);
773 targetBundleDir
= targetBase
.resolve(nameVersion
.getName() + "." + nameVersion
.getBranch());
775 // force Java 9 module name
776 entries
.put(ManifestConstants
.AUTOMATIC_MODULE_NAME
.toString(), nameVersion
.getName());
778 boolean isNative
= false;
781 if (targetBundleDir
.startsWith(a2LibBase
)) {
783 Path libRelativePath
= a2LibBase
.relativize(targetBundleDir
);
784 os
= libRelativePath
.getName(0).toString();
785 arch
= libRelativePath
.getName(1).toString();
790 entries
: while ((entry
= jarIn
.getNextJarEntry()) != null) {
791 if (entry
.isDirectory())
793 if (entry
.getName().endsWith(".RSA") || entry
.getName().endsWith(".SF"))
795 if (entry
.getName().endsWith("module-info.class")) // skip Java 9 module info
797 if (entry
.getName().startsWith("META-INF/versions/")) // skip multi-version
799 // skip file system providers as they cause issues with native image
800 if (entry
.getName().startsWith("META-INF/services/java.nio.file.spi.FileSystemProvider"))
802 if (entry
.getName().startsWith("OSGI-OPT/src/")) // skip embedded sources
804 Path target
= targetBundleDir
.resolve(entry
.getName());
805 Files
.createDirectories(target
.getParent());
806 Files
.copy(jarIn
, target
);
809 if (isNative
&& (entry
.getName().endsWith(".so") || entry
.getName().endsWith(".dll")
810 || entry
.getName().endsWith(".jnilib"))) {
811 Path categoryDir
= targetBundleDir
.getParent();
812 // String[] segments = categoryDir.getFileName().toString().split("\\.");
813 // String arch = segments[segments.length - 1];
814 // String os = segments[segments.length - 2];
815 boolean copyDll
= false;
816 Path targetDll
= categoryDir
.resolve(targetBundleDir
.relativize(target
));
817 if (nameVersion
.getName().equals("com.sun.jna")) {
818 if (arch
.equals("x86_64"))
820 if (os
.equals("macosx"))
822 if (target
.getParent().getFileName().toString().equals(os
+ "-" + arch
)) {
825 targetDll
= categoryDir
.resolve(target
.getFileName());
830 Files
.createDirectories(targetDll
.getParent());
831 if (Files
.exists(targetDll
))
832 Files
.delete(targetDll
);
833 Files
.copy(target
, targetDll
);
835 Files
.delete(target
);
837 logger
.log(Level
.TRACE
, () -> "Copied " + target
);
841 Path manifestPath
= targetBundleDir
.resolve("META-INF/MANIFEST.MF");
842 Files
.createDirectories(manifestPath
.getParent());
844 if (isSingleton
&& entries
.containsKey(BUNDLE_SYMBOLICNAME
.toString())) {
845 entries
.put(BUNDLE_SYMBOLICNAME
.toString(),
846 entries
.get(BUNDLE_SYMBOLICNAME
.toString()) + ";singleton:=true");
849 for (String key
: entries
.keySet()) {
850 String value
= entries
.get(key
);
851 Object previousValue
= manifest
.getMainAttributes().putValue(key
, value
);
852 if (previousValue
!= null && !previousValue
.equals(value
)) {
853 if (ManifestConstants
.IMPORT_PACKAGE
.toString().equals(key
)
854 || ManifestConstants
.EXPORT_PACKAGE
.toString().equals(key
)
855 || ManifestConstants
.BUNDLE_LICENSE
.toString().equals(key
))
856 logger
.log(Level
.TRACE
, file
.getFileName() + ": " + key
+ " was modified");
858 logger
.log(Level
.WARNING
, file
.getFileName() + ": " + key
+ " was " + previousValue
859 + ", overridden with " + value
);
862 // hack to remove unresolvable
863 if (key
.equals("Provide-Capability") || key
.equals("Require-Capability"))
864 if (nameVersion
.getName().equals("osgi.core") || nameVersion
.getName().equals("osgi.cmpn")) {
865 manifest
.getMainAttributes().remove(key
);
868 try (OutputStream out
= Files
.newOutputStream(manifestPath
)) {
872 return targetBundleDir
;
879 /** Recursively deletes a directory. */
880 private static void deleteDirectory(Path path
) throws IOException
{
881 if (!Files
.exists(path
))
883 Files
.walkFileTree(path
, new SimpleFileVisitor
<Path
>() {
885 public FileVisitResult
postVisitDirectory(Path directory
, IOException e
) throws IOException
{
888 Files
.delete(directory
);
889 return FileVisitResult
.CONTINUE
;
893 public FileVisitResult
visitFile(Path file
, BasicFileAttributes attrs
) throws IOException
{
895 return FileVisitResult
.CONTINUE
;
900 /** Extract name/version from a MANIFEST. */
901 protected NameVersion
nameVersionFromManifest(Manifest manifest
) {
902 Attributes attrs
= manifest
.getMainAttributes();
904 String symbolicName
= attrs
.getValue(ManifestConstants
.BUNDLE_SYMBOLICNAME
.toString());
905 if (symbolicName
== null)
907 // make sure there is no directive
908 symbolicName
= symbolicName
.split(";")[0];
910 String version
= attrs
.getValue(ManifestConstants
.BUNDLE_VERSION
.toString());
911 return new NameVersion(symbolicName
, version
);
914 /** Try to download from an URI. */
915 protected Path
tryDownloadArchive(String uri
, Path dir
) throws IOException
{
917 List
<String
> urlBases
= null;
918 String uriPrefix
= null;
919 uriPrefixes
: for (String uriPref
: mirrors
.keySet()) {
920 if (uri
.startsWith(uriPref
)) {
921 if (mirrors
.get(uriPref
).size() > 0) {
922 urlBases
= mirrors
.get(uriPref
);
928 if (urlBases
== null)
930 return downloadArchive(new URL(uri
), dir
);
931 } catch (FileNotFoundException e
) {
932 throw new FileNotFoundException("Cannot find " + uri
);
936 for (String urlBase
: urlBases
) {
937 String relativePath
= uri
.substring(uriPrefix
.length());
938 URL url
= new URL(urlBase
+ relativePath
);
940 return downloadArchive(url
, dir
);
941 } catch (FileNotFoundException e
) {
942 logger
.log(Level
.WARNING
, "Cannot download " + url
+ ", trying another mirror");
945 throw new FileNotFoundException("Cannot find " + uri
);
949 * Effectively download. Synchronised in order to avoid downloading twice in
952 protected synchronized Path
downloadArchive(URL url
, Path dir
) throws IOException
{
953 return download(url
, dir
, (String
) null);
956 /** Effectively download. */
957 protected Path
download(URL url
, Path dir
, String name
) throws IOException
{
961 // We use also use parent directory in case the archive itself has a fixed name
962 String
[] segments
= url
.getPath().split("/");
963 name
= segments
.length
> 1 ? segments
[segments
.length
- 2] + '-' + segments
[segments
.length
- 1]
964 : segments
[segments
.length
- 1];
967 dest
= dir
.resolve(name
);
968 if (Files
.exists(dest
)) {
969 logger
.log(Level
.TRACE
, () -> "File " + dest
+ " already exists for " + url
+ ", not downloading again");
972 Files
.createDirectories(dest
.getParent());
975 try (InputStream in
= url
.openStream()) {
976 Files
.copy(in
, dest
);
977 logger
.log(Level
.DEBUG
, () -> "Downloaded " + dest
+ " from " + url
);
982 /** Create a JAR file from a directory. */
983 protected Path
createJar(Path bundleDir
) throws IOException
{
985 Path jarPath
= bundleDir
.getParent().resolve(bundleDir
.getFileName() + ".jar");
986 Path manifestPath
= bundleDir
.resolve("META-INF/MANIFEST.MF");
988 try (InputStream in
= Files
.newInputStream(manifestPath
)) {
989 manifest
= new Manifest(in
);
991 try (JarOutputStream jarOut
= new JarOutputStream(Files
.newOutputStream(jarPath
), manifest
)) {
992 jarOut
.setLevel(Deflater
.DEFAULT_COMPRESSION
);
993 Files
.walkFileTree(bundleDir
, new SimpleFileVisitor
<Path
>() {
996 public FileVisitResult
visitFile(Path file
, BasicFileAttributes attrs
) throws IOException
{
997 if (file
.getFileName().toString().equals("MANIFEST.MF"))
998 return super.visitFile(file
, attrs
);
999 JarEntry entry
= new JarEntry(
1000 bundleDir
.relativize(file
).toString().replace(File
.separatorChar
, '/'));
1001 jarOut
.putNextEntry(entry
);
1002 Files
.copy(file
, jarOut
);
1003 return super.visitFile(file
, attrs
);
1008 deleteDirectory(bundleDir
);
1010 if (sourceBundles
) {
1011 Path bundleCategoryDir
= bundleDir
.getParent();
1012 Path sourceDir
= bundleCategoryDir
.resolve(bundleDir
.toString() + ".src");
1013 if (!Files
.exists(sourceDir
)) {
1014 logger
.log(WARNING
, sourceDir
+ " does not exist, skipping...");
1018 Path guessedA2Base
= bundleCategoryDir
.getParent();
1019 Path srcA2Base
= guessedA2Base
.getParent().resolve(guessedA2Base
.getFileName() + ".src");
1020 Path srcJarP
= srcA2Base
.resolve(bundleCategoryDir
.getFileName()).resolve(sourceDir
.getFileName() + ".jar");
1022 String bundleSymbolicName
= manifest
.getMainAttributes().getValue("Bundle-SymbolicName").toString();
1023 // in case there are additional directives
1024 bundleSymbolicName
= bundleSymbolicName
.split(";")[0];
1025 Manifest srcManifest
= new Manifest();
1026 srcManifest
.getMainAttributes().put(Attributes
.Name
.MANIFEST_VERSION
, "1.0");
1027 srcManifest
.getMainAttributes().putValue("Bundle-SymbolicName", bundleSymbolicName
+ ".src");
1028 srcManifest
.getMainAttributes().putValue("Bundle-Version",
1029 manifest
.getMainAttributes().getValue("Bundle-Version").toString());
1030 srcManifest
.getMainAttributes().putValue("Eclipse-SourceBundle",
1031 bundleSymbolicName
+ ";version=\"" + manifest
.getMainAttributes().getValue("Bundle-Version"));
1033 try (JarOutputStream srcJarOut
= new JarOutputStream(Files
.newOutputStream(srcJarP
), srcManifest
)) {
1034 srcJarOut
.setLevel(Deflater
.BEST_COMPRESSION
);
1035 Files
.walkFileTree(sourceDir
, new SimpleFileVisitor
<Path
>() {
1038 public FileVisitResult
visitFile(Path file
, BasicFileAttributes attrs
) throws IOException
{
1039 if (file
.getFileName().toString().equals("MANIFEST.MF"))
1040 return super.visitFile(file
, attrs
);
1041 JarEntry entry
= new JarEntry(
1042 sourceDir
.relativize(file
).toString().replace(File
.separatorChar
, '/'));
1043 srcJarOut
.putNextEntry(entry
);
1044 Files
.copy(file
, srcJarOut
);
1045 return super.visitFile(file
, attrs
);
1050 deleteDirectory(sourceDir
);
1056 enum ManifestConstants
{
1058 BUNDLE_SYMBOLICNAME("Bundle-SymbolicName"), //
1059 BUNDLE_VERSION("Bundle-Version"), //
1060 BUNDLE_LICENSE("Bundle-License"), //
1061 EXPORT_PACKAGE("Export-Package"), //
1062 IMPORT_PACKAGE("Import-Package"), //
1064 AUTOMATIC_MODULE_NAME("Automatic-Module-Name"), //
1066 SLC_CATEGORY("SLC-Category"), //
1067 SLC_ORIGIN_M2("SLC-Origin-M2"), //
1068 SLC_ORIGIN_M2_MERGE("SLC-Origin-M2-Merge"), //
1069 SLC_ORIGIN_M2_REPO("SLC-Origin-M2-Repo"), //
1070 SLC_ORIGIN_MANIFEST_NOT_MODIFIED("SLC-Origin-ManifestNotModified"), //
1071 SLC_ORIGIN_URI("SLC-Origin-URI"),//
1076 private ManifestConstants(String value
) {
1081 public String
toString() {
1089 /** Simple representation of an M2 artifact. */
1090 class M2Artifact
extends CategoryNameVersion
{
1091 private String classifier
;
1093 M2Artifact(String m2coordinates
) {
1094 this(m2coordinates
, null);
1097 M2Artifact(String m2coordinates
, String classifier
) {
1098 String
[] parts
= m2coordinates
.split(":");
1099 setCategory(parts
[0]);
1101 if (parts
.length
> 2) {
1102 setVersion(parts
[2]);
1104 this.classifier
= classifier
;
1107 String
getGroupId() {
1108 return super.getCategory();
1111 String
getArtifactId() {
1112 return super.getName();
1115 String
toM2Coordinates() {
1116 return getCategory() + ":" + getName() + (getVersion() != null ?
":" + getVersion() : "");
1119 String
getClassifier() {
1120 return classifier
!= null ? classifier
: "";
1123 String
getExtension() {
1128 /** Utilities around Maven (conventions based). */
1129 class M2ConventionsUtils
{
1130 final static String MAVEN_CENTRAL_BASE_URL
= "https://repo1.maven.org/maven2/";
1132 /** The file name of this artifact when stored */
1133 static String
artifactFileName(M2Artifact artifact
) {
1134 return artifact
.getArtifactId() + '-' + artifact
.getVersion()
1135 + (artifact
.getClassifier().equals("") ?
"" : '-' + artifact
.getClassifier()) + '.'
1136 + artifact
.getExtension();
1139 /** Absolute path to the file */
1140 static String
artifactPath(String artifactBasePath
, M2Artifact artifact
) {
1141 return artifactParentPath(artifactBasePath
, artifact
) + '/' + artifactFileName(artifact
);
1144 /** Absolute path to the file */
1145 static String
artifactUrl(String repoUrl
, M2Artifact artifact
) {
1146 if (repoUrl
.endsWith("/"))
1147 return repoUrl
+ artifactPath("/", artifact
).substring(1);
1149 return repoUrl
+ artifactPath("/", artifact
);
1152 /** Absolute path to the file */
1153 static URL
mavenRepoUrl(String repoBase
, M2Artifact artifact
) {
1154 String url
= artifactUrl(repoBase
== null ? MAVEN_CENTRAL_BASE_URL
: repoBase
, artifact
);
1156 return new URL(url
);
1157 } catch (MalformedURLException e
) {
1158 // it should not happen
1159 throw new IllegalStateException(e
);
1163 /** Absolute path to the directories where the files will be stored */
1164 static String
artifactParentPath(String artifactBasePath
, M2Artifact artifact
) {
1165 return artifactBasePath
+ (artifactBasePath
.endsWith("/") ?
"" : "/") + artifactParentPath(artifact
);
1168 /** Relative path to the directories where the files will be stored */
1169 static String
artifactParentPath(M2Artifact artifact
) {
1170 return artifact
.getGroupId().replace('.', '/') + '/' + artifact
.getArtifactId() + '/' + artifact
.getVersion();
1174 private M2ConventionsUtils() {
1178 class CategoryNameVersion
extends NameVersion
{
1179 private String category
;
1181 CategoryNameVersion() {
1184 CategoryNameVersion(String category
, String name
, String version
) {
1185 super(name
, version
);
1186 this.category
= category
;
1189 CategoryNameVersion(String category
, NameVersion nameVersion
) {
1191 this.category
= category
;
1194 String
getCategory() {
1198 void setCategory(String category
) {
1199 this.category
= category
;
1203 public String
toString() {
1204 return category
+ ":" + super.toString();
1209 class NameVersion
implements Comparable
<NameVersion
> {
1210 private String name
;
1211 private String version
;
1216 /** Interprets string in OSGi-like format my.module.name;version=0.0.0 */
1217 NameVersion(String nameVersion
) {
1218 int index
= nameVersion
.indexOf(";version=");
1220 setName(nameVersion
);
1223 setName(nameVersion
.substring(0, index
));
1224 setVersion(nameVersion
.substring(index
+ ";version=".length()));
1228 NameVersion(String name
, String version
) {
1230 this.version
= version
;
1233 NameVersion(NameVersion nameVersion
) {
1234 this.name
= nameVersion
.getName();
1235 this.version
= nameVersion
.getVersion();
1242 void setName(String name
) {
1246 String
getVersion() {
1250 void setVersion(String version
) {
1251 this.version
= version
;
1254 String
getBranch() {
1255 String
[] parts
= getVersion().split("\\.");
1256 if (parts
.length
< 2)
1257 throw new IllegalStateException("Version " + getVersion() + " cannot be interpreted as branch.");
1258 return parts
[0] + "." + parts
[1];
1262 public boolean equals(Object obj
) {
1263 if (obj
instanceof NameVersion
) {
1264 NameVersion nameVersion
= (NameVersion
) obj
;
1265 return name
.equals(nameVersion
.getName()) && version
.equals(nameVersion
.getVersion());
1271 public int hashCode() {
1272 return name
.hashCode();
1276 public String
toString() {
1277 return name
+ ":" + version
;
1280 public int compareTo(NameVersion o
) {
1281 if (o
.getName().equals(name
))
1282 return version
.compareTo(o
.getVersion());
1284 return name
.compareTo(o
.getName());