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