]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.init/src/org/argeo/api/a2/ClasspathSource.java
Improve init launch
[lgpl/argeo-commons.git] / org.argeo.init / src / org / argeo / api / a2 / ClasspathSource.java
1 package org.argeo.api.a2;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.lang.System.Logger;
6 import java.lang.System.Logger.Level;
7 import java.nio.file.Path;
8 import java.nio.file.Paths;
9 import java.util.Arrays;
10 import java.util.List;
11
12 import org.osgi.framework.Version;
13
14 /**
15 * A provisioning source based on the linear classpath with which the JVM has
16 * been started.
17 */
18 public class ClasspathSource extends AbstractProvisioningSource {
19 private final static Logger logger = System.getLogger(ClasspathSource.class.getName());
20
21 public ClasspathSource() {
22 super(true);
23 }
24
25 void load() throws IOException {
26 A2Contribution classpathContribution = getOrAddContribution(A2Contribution.CLASSPATH);
27 List<String> classpath = Arrays.asList(System.getProperty("java.class.path").split(File.pathSeparator));
28 parts: for (String part : classpath) {
29 Path file = Paths.get(part);
30 Version version;
31 try {
32 version = new Version(readVersionFromModule(file));
33 } catch (Exception e) {
34 // ignore non OSGi
35 continue parts;
36 }
37 String moduleName = readSymbolicNameFromModule(file);
38 A2Component component = classpathContribution.getOrAddComponent(moduleName);
39 A2Module module = component.getOrAddModule(version, file);
40 logger.log(Level.TRACE, () -> "Registered " + module);
41 }
42
43 }
44 }