1 package org
.argeo
.osgi
.boot
.a2
;
3 import java
.io
.IOException
;
4 import java
.nio
.file
.DirectoryStream
;
5 import java
.nio
.file
.Files
;
6 import java
.nio
.file
.Path
;
7 import java
.nio
.file
.Paths
;
8 import java
.util
.SortedSet
;
9 import java
.util
.TreeSet
;
11 import org
.argeo
.osgi
.boot
.OsgiBootUtils
;
12 import org
.osgi
.framework
.Version
;
14 public class FsA2Source
extends ProvisioningSource
{
15 private final Path base
;
17 public FsA2Source(Path base
) {
22 void load() throws IOException
{
23 DirectoryStream
<Path
> contributionPaths
= Files
.newDirectoryStream(base
);
24 SortedSet
<A2Contribution
> contributions
= new TreeSet
<>();
25 contributions
: for (Path contributionPath
: contributionPaths
) {
26 if (Files
.isDirectory(contributionPath
)) {
27 String contributionId
= contributionPath
.getFileName().toString();
28 if (A2Contribution
.BOOT
.equals(contributionId
))// skip boot
29 continue contributions
;
30 A2Contribution contribution
= new A2Contribution(this, contributionId
);
31 contributions
.add(contribution
);
35 for (A2Contribution contribution
: contributions
) {
36 DirectoryStream
<Path
> modulePaths
= Files
.newDirectoryStream(base
.resolve(contribution
.getId()));
37 modules
: for (Path modulePath
: modulePaths
) {
38 if (!Files
.isDirectory(modulePath
)) {
39 // OsgiBootUtils.debug("Registering " + modulePath);
40 String moduleFileName
= modulePath
.getFileName().toString();
41 int lastDot
= moduleFileName
.lastIndexOf('.');
42 String ext
= moduleFileName
.substring(lastDot
+ 1);
43 if (!"jar".equals(ext
))
45 String moduleName
= moduleFileName
.substring(0, lastDot
);
46 int firstDash
= moduleName
.indexOf('-');
47 String versionStr
= moduleName
.substring(firstDash
+ 1);
48 String componentName
= moduleName
.substring(0, firstDash
);
49 // if(versionStr.endsWith("-SNAPSHOT")) {
50 // versionStr = readVersionFromModule(modulePath);
54 version
= new Version(versionStr
);
55 } catch (Exception e
) {
56 versionStr
= readVersionFromModule(modulePath
);
57 if (versionStr
!= null) {
58 version
= new Version(versionStr
);
60 OsgiBootUtils
.debug("Ignore " + modulePath
+ " (" + e
.getMessage() + ")");
64 A2Component component
= contribution
.getOrAddComponent(componentName
);
65 A2Module module
= component
.getOrAddModule(version
, modulePath
);
66 if (OsgiBootUtils
.isDebug())
67 OsgiBootUtils
.debug("Registered " + module
);
74 public static void main(String
[] args
) {
76 FsA2Source context
= new FsA2Source(Paths
.get(
77 "/home/mbaudier/dev/git/apache2/argeo-commons/dist/argeo-node/target/argeo-node-2.1.77-SNAPSHOT/share/osgi"));
80 } catch (Exception e
) {