Created
January 18, 2017 22:50
-
-
Save gastaldi/74b0d1d51219b12c16f18a6136fe441f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright 2017 Red Hat, Inc. and/or its affiliates. | |
* | |
* Licensed under the Eclipse Public License version 1.0, available at | |
* http://www.eclipse.org/legal/epl-v10.html | |
*/ | |
package org.jboss.forge.addon.swarm.config; | |
import java.io.IOException; | |
import java.net.URL; | |
import java.net.URLClassLoader; | |
import java.util.Collection; | |
import java.util.Map; | |
import org.jboss.forge.furnace.proxy.ClassLoaderAdapterBuilder; | |
import org.wildfly.swarm.tools.FractionDescriptor; | |
import org.wildfly.swarm.tools.FractionList; | |
/** | |
* | |
* @author <a href="mailto:[email protected]">George Gastaldi</a> | |
*/ | |
public class DynamicFractionList implements FractionList | |
{ | |
private URLClassLoader urlClassLoader; | |
private FractionList fractionList; | |
public DynamicFractionList(URL jar) throws Exception | |
{ | |
this.urlClassLoader = URLClassLoader.newInstance(new URL[] { jar }); | |
Class<?> targetFractionListClass = this.urlClassLoader.loadClass("org.wildfly.swarm.fractionlist.FractionList"); | |
Object targetFractionList = targetFractionListClass.getMethod("get").invoke(null); | |
this.fractionList = (FractionList) ClassLoaderAdapterBuilder | |
.callingLoader(getClass().getClassLoader()) | |
.delegateLoader(this.urlClassLoader) | |
.enhance(targetFractionList, FractionList.class); | |
} | |
@Override | |
public Collection<FractionDescriptor> getFractionDescriptors() | |
{ | |
return fractionList.getFractionDescriptors(); | |
} | |
@Override | |
public FractionDescriptor getFractionDescriptor(String groupId, String artifactId) | |
{ | |
return fractionList.getFractionDescriptor(groupId, artifactId); | |
} | |
@Override | |
public Map<String, FractionDescriptor> getPackageSpecs() | |
{ | |
return fractionList.getPackageSpecs(); | |
} | |
public void close() throws IOException | |
{ | |
if (this.urlClassLoader != null) | |
{ | |
this.urlClassLoader.close(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment