in atomos.utils/atomos.utils.core/src/main/java/org/apache/felix/atomos/utils/core/LauncherImpl.java [156:273]
public Context execute(Context context)
{
//CollectFiles
orderdPluginsBy(FileCollectorPlugin.class)//
.peek(System.out::println)//
.forEachOrdered(plugin -> plugin.collectFiles(context));//
//Visit all files with type
orderdPluginsBy(FileHandlerPlugin.class)//
.peek(System.out::println)//
.forEachOrdered(plugin -> {
//for each FileType
List.of(FileType.values()).forEach(fileType -> {
context.getFiles(fileType)//
.forEach(path -> plugin.handleFile(context, path, fileType));
});
});//
List<Path> artifacts = context.getFiles(FileType.ARTIFACT).collect(
Collectors.toList());
URL[] urls = artifacts.stream().map(p -> {
try
{
return p.toUri().toURL();
}
catch (MalformedURLException e1)
{
throw new UncheckedIOException(e1);
}
}).toArray(URL[]::new);
List<JarFile> jarFiles = new ArrayList<>();
try (URLClassLoader classLoader = URLClassLoader.newInstance(urls, null))
{
List<Class<?>> classes = loadClasses(artifacts, classLoader);
List<JarPlugin<?>> jarPlugins = new ArrayList<>();//collector had compile issues on ojdk compiler
orderdPluginsBy(JarPlugin.class).forEachOrdered(jarPlugins::add);
jarPlugins.forEach(plugin -> plugin.preJars(context));
for (Path p : artifacts)
{
jarFiles.add(new JarFile(p.toFile()));
}
jarFiles.forEach(
j -> jarPlugins.forEach(p -> p.initJar(j, context, classLoader)));
jarFiles.forEach(j -> {
jarPlugins.forEach(p -> p.doJar(j, context, classLoader));
try
{
processJar(j, context, classLoader);
}
catch (IOException e)
{
e.printStackTrace();
}
});
jarPlugins.forEach(plugin -> plugin.postJars(context));
List<ClassPlugin<?>> classPlugins = new ArrayList<>();
orderdPluginsBy(ClassPlugin.class).forEachOrdered(classPlugins::add);
List<MethodPlugin<?>> methodPlugins = new ArrayList<>();
orderdPluginsBy(MethodPlugin.class).forEachOrdered(methodPlugins::add);
if (!classPlugins.isEmpty() || !methodPlugins.isEmpty())
{
for (Class<?> c : classes)
{
classPlugins.forEach(p -> p.doClass(c, context));
if (!methodPlugins.isEmpty())
{
try
{
Method[] methods = c.getDeclaredMethods();
if (methods != null)
{
for (Method m : methods)
{
methodPlugins.forEach(p -> p.doMethod(m, context));
}
}
}
catch (NoClassDefFoundError e)
{
//e.printStackTrace(); //TODO Log
System.out.println("incomplete classpath: " + c);
}
}
}
}
orderdPluginsBy(FinalPlugin.class).forEachOrdered(p -> p.doFinal(context));
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
jarFiles.forEach(f -> {
try
{
f.close();
}
catch (IOException e)
{
// ignore
}
});
}
return context;
}