ru.circumflex.maven.AbstractCircumflexMojo Maven / Gradle / Ivy
package ru.circumflex.maven;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.project.MavenProject;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
/**
* Author: incarnate
*/
public abstract class AbstractCircumflexMojo extends AbstractMojo {
/**
* @parameter expression="${project}"
* @readonly
*/
protected MavenProject project;
protected URLClassLoader prepareClassLoader()
throws MalformedURLException, DependencyResolutionRequiredException {
List urls = new ArrayList();
for (Object o : project.getRuntimeClasspathElements()) {
File f = new File(o.toString());
String path = f.getAbsolutePath().replace(File.separatorChar, '/');
if (f.isDirectory()) path += "/";
urls.add(new URL("file", "localhost", path));
}
return URLClassLoader.newInstance(urls.toArray(new URL[urls.size()]),
Thread.currentThread().getContextClassLoader());
}
}