log.debug( "Processing dependencies for project " + project.getName() + "; classloader " + projectClassLoader );
// add the dependencies to the classpath
for ( Iterator i = project.getArtifacts().iterator(); i.hasNext(); )
{
Artifact artifact = (Artifact) i.next();
Dependency dependency = artifact.getDependency();
if ( dependency.isPlugin() )
{
// TODO: is this the best place to call this?
installPlugin( artifact.getFile(), project );
}
// get correct classloader
String dependencyClassLoader = dependency.getProperty( "classloader" );
// add to classloader
if ( artifact.exists() )
{
// Only add compile type dependencies to classloader
// what about ejbs etc
if ( dependency.isAddedToClasspath() )
{
if ( dependencyClassLoader != null )
{
log.debug( "DEPRECATION: " + dependency.getId() + " in project " + project.getId()
+ " forces the classloader '" + dependencyClassLoader + "'" );
log.debug( " This behaviour is deprecated. Please refer to the FAQ" );
ForeheadClassLoader loader = Forehead.getInstance().getClassLoader( dependencyClassLoader );
if ( loader == null )
{
log.warn( "classloader '" + dependencyClassLoader
+ "' not found. Adding dependencies to the project classloader instead" );
loader = projectClassLoader;
}
else
{
log.debug( "poking dependency " + artifact.getFile() + " into classloader "
+ dependencyClassLoader );
}
loader.addURL( artifact.getFile().toURL() );
}
else
{
log.debug( "adding dependency " + artifact.getFile() + " into project classloader" );
projectClassLoader.addURL( artifact.getFile().toURL() );
}
}
else
{
log.debug( "Non classpath dependency: '" + artifact.getFile() + "' not added to classpath" );
}
}
else
{
log.info( "Artifact '" + artifact.getFile() + "' not found to add to classpath" );
}
}
// Explicity set the classloader used to find resources. As we just
// poked all the dependencies into the classloader.
project.getContext().setClassLoader( projectClassLoader );