/**
* Create a ClassLoader, which includes the artifacts in <code>artifacts</code>, but excludes the artifacts in <code>previousArtifacts</code>. The intention is, that we let BCEL inspect the artifacts in the latter set, using a {@link ClassLoader}, which contains the dependencies. However, the {@link ClassLoader} must not contain the jar files, which are being inspected.
* @param artifacts The artifacts, from which to build a {@link ClassLoader}.
* @param previousArtifacts The artifacts being inspected, or null, if tereturned {@link ClassLoader} should contain all the elements of<code>artifacts</code>.
* @return A {@link ClassLoader} which may be used to inspect the classes inpreviousArtifacts.
* @throws MalformedURLException Failed to convert a file to an URL.
*/
protected static ClassLoader createClassLoader(Collection<Artifact> artifacts,Set<Artifact> previousArtifacts) throws MalformedURLException {
URLClassLoader cl=null;
if (!artifacts.isEmpty()) {
List<URL> urls=new ArrayList<URL>(artifacts.size());
for (Iterator<Artifact> i=artifacts.iterator(); i.hasNext(); ) {
Artifact artifact=i.next();
if (previousArtifacts == null || !previousArtifacts.contains(artifact)) {
urls.add(artifact.getFile().toURI().toURL());
}
}
if (!urls.isEmpty()) {
cl=new URLClassLoader(urls.toArray(new URL[urls.size()]));
}
}
return cl;
}

Example 35

From project clustermeister, under directory /integration-tests/src/main/java/com/github/nethad/clustermeister/integration/sc07/.