org.codehaus.mojo.apt.EmbeddedURLClassLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of apt-maven-plugin Show documentation
Show all versions of apt-maven-plugin Show documentation
Maven Plugin for Annotation Processing Tool (apt).
package org.codehaus.mojo.apt;
/*
* The MIT License
*
* Copyright 2006-2008 The Codehaus.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLStreamHandlerFactory;
/**
* Provides a more embedder friendly {@link URLClassLoader} for APT. The constructor that takes no parent will delegate
* to the APT class loader instead of the system class loader.
*
* @author Benjamin Bentmann
*/
public class EmbeddedURLClassLoader
extends URLClassLoader
{
/**
* Fixes the class loading in APT to be embeddable. To load a factory, APT is doing something like
*
*
* ClassLoader classLoader = new URLClassLoader( classPath );
* AnnotationProcessorFactory factory = (AnnotationProcessorFactory) classLoader.loadClass( name );
*
*
* i.e. it's assumed that {@code AnnotationProcessorFactory} is present in the system class loader. This is
* generally wrong so we derive the factory class loader from the APT class loader.
*/
public EmbeddedURLClassLoader( URL[] urls )
{
this( urls, AptClassLoader.INSTANCE );
}
public EmbeddedURLClassLoader( URL[] urls, ClassLoader parent )
{
super( urls, parent );
}
public EmbeddedURLClassLoader( URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory )
{
super( urls, parent, factory );
}
}