X-Git-Url: http://git.argeo.org/?p=lgpl%2Fargeo-commons.git;a=blobdiff_plain;f=org.argeo.init%2Fsrc%2Forg%2Fargeo%2Fapi%2Fa2%2FClasspathSource.java;fp=org.argeo.init%2Fsrc%2Forg%2Fargeo%2Fapi%2Fa2%2FClasspathSource.java;h=b702d35a0f89495e6b8851618db3300522044231;hp=0000000000000000000000000000000000000000;hb=b95462873703848193e56fcbe997693630db6121;hpb=55d88fba80cec198a0f11ba7545e19878c51fc5e diff --git a/org.argeo.init/src/org/argeo/api/a2/ClasspathSource.java b/org.argeo.init/src/org/argeo/api/a2/ClasspathSource.java new file mode 100644 index 000000000..b702d35a0 --- /dev/null +++ b/org.argeo.init/src/org/argeo/api/a2/ClasspathSource.java @@ -0,0 +1,44 @@ +package org.argeo.api.a2; + +import java.io.File; +import java.io.IOException; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.List; + +import org.osgi.framework.Version; + +/** + * A provisioning source based on the linear classpath with which the JVM has + * been started. + */ +public class ClasspathSource extends AbstractProvisioningSource { + private final static Logger logger = System.getLogger(ClasspathSource.class.getName()); + + public ClasspathSource() { + super(true); + } + + void load() throws IOException { + A2Contribution classpathContribution = getOrAddContribution(A2Contribution.CLASSPATH); + List classpath = Arrays.asList(System.getProperty("java.class.path").split(File.pathSeparator)); + parts: for (String part : classpath) { + Path file = Paths.get(part); + Version version; + try { + version = new Version(readVersionFromModule(file)); + } catch (Exception e) { + // ignore non OSGi + continue parts; + } + String moduleName = readSymbolicNameFromModule(file); + A2Component component = classpathContribution.getOrAddComponent(moduleName); + A2Module module = component.getOrAddModule(version, file); + logger.log(Level.TRACE, () -> "Registered " + module); + } + + } +}