rempl-maven-plugin-1.1.3.src.main.java.com.rempl.maven.MavenClassLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rempl-maven-plugin Show documentation
Show all versions of rempl-maven-plugin Show documentation
Reverse Engineering Meta Programming Library (REMPL) that
enables manipulations with source code meta constructs,
like classes, methods, files, packages, etc. in runtime.
/**
* Copyright (c) 2011, REMPL.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1) Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* 3) Neither the name of the REMPL.com nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.rempl.maven;
// REMPL API from com.rempl:rempl-api
import com.ymock.util.Logger;
// base classes
import java.net.URL;
import java.net.URLClassLoader;
// for manipulations with arrays
import org.apache.commons.lang.ArrayUtils;
/**
* Wrapper around {@link URLClassLoader}.
*
* @author Yegor Bugayenko ([email protected])
* @version $Id: MavenClassLoader.java 1614 2011-07-10 19:05:43Z guard $
* @see MavenLoader
*/
final class MavenClassLoader extends URLClassLoader {
/**
* Public ctor.
* @param parent Parent class loader
* @see MavenLoader#MavenLoader(MavenResolver)
*/
public MavenClassLoader(final ClassLoader parent) {
super(new URL[] {}, parent);
}
/**
* Appends the specified URLs to the list of URLs to search for
* classes and resources.
* @param urls URLs to add to search path
*/
public void addURLs(final URL[] urls) {
for (URL url : urls) {
this.addURL(url);
}
}
/**
* {@inheritDoc}
*/
@Override
public void addURL(final URL url) {
final URL[] urls = this.getURLs();
if (ArrayUtils.contains(urls, url)) {
Logger.debug(
this,
"#addURL(%s): duplicate",
url.toString()
);
} else {
super.addURL(url);
Logger.debug(
this,
"#addURL(%s): added #%d",
url.toString(),
urls.length + 1
);
}
}
/**
* {@inheritDoc}
*/
@Override
protected Class> findClass(final String name)
throws ClassNotFoundException {
Logger.debug(
this,
"#findClass(%s)",
name
);
return super.findClass(name);
}
}