in atomos.substrate.config/src/main/java/org/apache/felix/atomos/substrate/config/SubstrateService.java [51:142]
public void substrateBundles(File output) throws IOException
{
if (!output.isDirectory())
{
throw new IllegalArgumentException("Output file must be a directory.");
}
File atomosDir = new File(output, ATOMOS_BUNDLES);
atomosDir.mkdir();
List<String> resources = new ArrayList<String>();
for (Bundle b : context.getBundles())
{
File bundleDir = new File(atomosDir, Long.toString(b.getBundleId()));
resources.add(ATOMOS_BUNDLE);
resources.add(Long.toString(b.getBundleId()));
resources.add(b.getSymbolicName());
resources.add(b.getVersion().toString());
Enumeration<URL> entries = b.findEntries("/", "*", false);
while (entries.hasMoreElements())
{
URL rootResource = entries.nextElement();
String rootPath = rootResource.getPath();
if (rootPath.startsWith("/"))
{
rootPath = rootPath.substring(1);
}
// make sure this is not from a fragment
if (!rootResource.equals(b.getEntry(rootPath)))
{
continue;
}
if (!rootPath.endsWith("/"))
{
// skip default package classes
if (!rootPath.endsWith(".class"))
{
resources.add(rootPath);
File resourceFile = new File(bundleDir, rootPath);
resourceFile.getParentFile().mkdirs();
try (InputStream in = rootResource.openStream())
{
Files.copy(rootResource.openStream(), resourceFile.toPath(),
StandardCopyOption.REPLACE_EXISTING);
}
}
}
else if (rootPath.contains("-"))
{
Enumeration<URL> nonPackageEntry = b.findEntries(rootPath, "*", true);
while (nonPackageEntry.hasMoreElements())
{
URL resource = nonPackageEntry.nextElement();
String path = resource.getPath();
if (path.startsWith("/"))
{
path = path.substring(1);
}
// make sure this is not from a fragment
if (resource.equals(b.getEntry(path)))
{
resources.add(path);
if (!path.endsWith("/") && !isExcluded(path))
{
File resourceFile = new File(bundleDir, path);
resourceFile.getParentFile().mkdirs();
try (InputStream in = resource.openStream())
{
Files.copy(resource.openStream(),
resourceFile.toPath(),
StandardCopyOption.REPLACE_EXISTING);
}
}
}
}
}
}
}
File bundlesIndex = new File(output, ATOMOS_BUNDLES_INDEX);
try (BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(new FileOutputStream(bundlesIndex))))
{
resources.forEach((l) -> {
try
{
writer.append(l).append('\n');
}
catch (IOException e)
{
throw new UncheckedIOException(e);
}
});
}
}