/**
* Will detect pom.xml specified by {@link #getPackageDescriptor()}, and load {@link EntryPoint#getAdditionalClassSources()}.
* It will also load all maven project directories specified by {@link #getProjectDirectory()}.
*/
public void main(EntryPointConfiguration config) throws Throwable {
ClassContext context = null;
ClassSource cs = config.getPoint().getAdditionalClassSources();
// Load project directories
String mp = this.getProjectDirectory();
if (mp == null) mp = "../";
this.resolver = MavenRepositoryUtil.createStandardResolver();
String[] mps = mp.split(";");
for (String mpd : mps) {
((ClassPackageResolverImpl)this.resolver).addLocalRepository(new MavenRepositoryLocalProject( new SystemDirectory(mpd) ));
}
((ClassPackageResolverImpl)this.resolver).addLocalRepository(new MavenRepositoryClassLoader());
context = cs != null ?
new ClassContext(new StandardClassLoaderHeiarchy(), cs) :
new ClassContext(new StandardClassLoaderHeiarchy());
Thread.currentThread().setContextClassLoader(context);
// Check for a specified or default pom.xml file
IVirtualFile pomFile = this.locatePOMDescriptor();
if (pomFile != null && pomFile.isExists()) {
ProjectObjectModel pom = ProjectObjectModel.parse(resolver, pomFile);
ProjectObjectModel resolved = (ProjectObjectModel) resolver.getDescriptor(pom);
if (resolved != null) {
pom = resolved;
} else {
log.info("Unresolvable pom.xml used for bootstrapping: " + pom);
}
MavenRepositoryUtil.addProjectMainTarget(context.getNonPackageSources(), pom, pomFile.getOwner());
context.setPool(pool = MavenRepositoryUtil.createFrom(resolver, pom, pom.getDependencies()));
Thread.currentThread().setContextClassLoader(context);
} else {
log.warn("Could not find: " + pomFile.getPath().toString("/"));
}
new ClassPackageContext(resolver, context.getPool()).setGlobal();
config.getPoint().setupDefaultURLStreamHandlerFactory(context);
if (log.isDebug()) {
log.debug("Non Package Sources");
for (ClassSource src : context.getNonPackageSources().getAllNonCompositeSources()) {
log.debug(" --> " + src);
}
log.debug("Package Sources");
for (IClassPackage pkg : context.getPool().getPackages(true)) {
log.debug(" --> " + pkg.getDescriptor());
}
this.log.debug("BOOTING MAVEN: " + config.getMainClass() + ": " + System.currentTimeMillis());
}
config.registerExecuted(this);
// Load the main class and invoke it
this.settings.refresh();
if (config.getMainClass() != null)
config.getPoint().boot(ClassCache.getFor(context.loadClass(config.getMainClass())), this);
}