本文整理匯總了Java中org.apache.tools.ant.AntClassLoader類的典型用法代碼示例。如果您正苦於以下問題:Java AntClassLoader類的具體用法?Java AntClassLoader怎麽用?Java AntClassLoader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
AntClassLoader類屬於org.apache.tools.ant包,在下文中一共展示了AntClassLoader類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: validateAgainstAUDTDs
import org.apache.tools.ant.AntClassLoader; //導入依賴的package包/類
static void validateAgainstAUDTDs(InputSource input, final Path updaterJar, final Task task) throws IOException, SAXException {
XMLUtil.parse(input, true, false, XMLUtil.rethrowHandler(), new EntityResolver() {
ClassLoader loader = new AntClassLoader(task.getProject(), updaterJar);
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
String remote = "http://www.netbeans.org/dtds/";
if (systemId.startsWith(remote)) {
String rsrc = "org/netbeans/updater/resources/" + systemId.substring(remote.length());
URL u = loader.getResource(rsrc);
if (u != null) {
return new InputSource(u.toString());
} else {
task.log(rsrc + " not found in " + updaterJar, Project.MSG_WARN);
}
}
return null;
}
});
}
示例2: testClassloaderInRootModule
import org.apache.tools.ant.AntClassLoader; //導入依賴的package包/類
@Test
public void testClassloaderInRootModule() throws IOException {
TestRootModuleChecker.reset();
CheckerStub.reset();
final CheckstyleAntTask antTask =
getCheckstyleAntTask(
"InputCheckstyleAntTaskConfigCustomCheckerRootModule.xml");
antTask.setFile(new File(getPath(VIOLATED_INPUT)));
antTask.execute();
final ClassLoader classLoader = CheckerStub.getClassLoader();
assertTrue("Classloader is not set or has invalid type",
classLoader instanceof AntClassLoader);
}
示例3: resolveClassName
import org.apache.tools.ant.AntClassLoader; //導入依賴的package包/類
/**
* Tries to resolve the given classname into a compiler adapter.
* Throws a fit if it can't.
*
* @param className The fully qualified classname to be created.
* @param classloader Classloader with which to load the class
* @throws BuildException This is the fit that is thrown if className
* isn't an instance of JspCompilerAdapter.
*/
private static JspCompilerAdapter resolveClassName(String className,
AntClassLoader classloader)
throws BuildException {
try {
Class<? extends JspCompilerAdapter> c = classloader.findClass(className).asSubclass(JspCompilerAdapter.class);
return c.newInstance();
} catch (ClassNotFoundException cnfe) {
throw new BuildException(className + " can\'t be found.", cnfe);
} catch (ClassCastException cce) {
throw new BuildException(className + " isn\'t the classname of "
+ "a compiler adapter.", cce);
} catch (Throwable t) {
// for all other possibilities
throw new BuildException(className + " caused an interesting "
+ "exception.", t);
}
}
示例4: loadClass
import org.apache.tools.ant.AntClassLoader; //導入依賴的package包/類
Class loadClass(String className) throws ClassNotFoundException
{
if (_classpath != null)
{
log("Loading " + className + " using AntClassLoader with classpath " + _classpath,
Project.MSG_VERBOSE);
AntClassLoader loader = new AntClassLoader(getProject(), _classpath);
return loader.loadClass(className);
}
else
{
log("Loading " + className + " using system loader.",
Project.MSG_VERBOSE);
return Class.forName(className);
}
}
示例5: execute
import org.apache.tools.ant.AntClassLoader; //導入依賴的package包/類
public void execute() throws BuildException {
try {
/*
* This needs the ClassLoader we use to load the task
* have all the dependancies set, hope that
* is ok for now
*/
AntClassLoader cl = new AntClassLoader(
getClass().getClassLoader(),
getProject(),
classpath == null ? createClasspath() : classpath,
false);
Thread.currentThread().setContextClassLoader(cl);
Map commandLineOptions = this.fillOptionMap();
CommandLineOptionParser parser =
new CommandLineOptionParser(commandLineOptions);
new CodeGenerationEngine(parser).generate();
} catch (Throwable e) {
throw new BuildException(e);
}
}
示例6: execute
import org.apache.tools.ant.AntClassLoader; //導入依賴的package包/類
public void execute() throws BuildException {
try {
Map commandLineOptions = this.fillOptionMap();
ClassLoader conextClassLoader = Thread.currentThread().getContextClassLoader();
AntClassLoader cl = new AntClassLoader(getClass().getClassLoader(),
getProject(),
classpath == null ? createClasspath() : classpath,
false);
commandLineOptions.put(Java2WSDLConstants.CLASSPATH_OPTION, new Java2WSDLCommandLineOption(Java2WSDLConstants.CLASSPATH_OPTION, classpath.list()));
Thread.currentThread().setContextClassLoader(cl);
if (outputLocation != null) cl.addPathElement(outputLocation);
new Java2WSDLCodegenEngine(commandLineOptions).generate();
Thread.currentThread().setContextClassLoader(conextClassLoader);
} catch (Throwable e) {
throw new BuildException(e);
}
}
示例7: doXJC
import org.apache.tools.ant.AntClassLoader; //導入依賴的package包/類
private void doXJC() throws BuildException {
ClassLoader old = Thread.currentThread().getContextClassLoader();
try {
if (classpath != null) {
for (String pathElement : classpath.list()) {
try {
options.classpaths.add(new File(pathElement).toURI().toURL());
} catch (MalformedURLException ex) {
log("Classpath for XJC task not setup properly: " + pathElement);
}
}
}
// set the user-specified class loader so that XJC will use it.
Thread.currentThread().setContextClassLoader(new AntClassLoader(getProject(),classpath));
_doXJC();
} finally {
// restore the context class loader
Thread.currentThread().setContextClassLoader(old);
}
}
示例8: setConf
import org.apache.tools.ant.AntClassLoader; //導入依賴的package包/類
/**
* Sets the path for the parent-last ClassLoader, intended to be used for
* {@link org.apache.hadoop.conf.Configuration Configuration}.
* @param confpath The path to search for resources, classes, etc. before
* parent ClassLoaders.
*/
public void setConf(String confpath) {
confloader = AccessController.doPrivileged(
new PrivilegedAction<AntClassLoader>() {
@Override
public AntClassLoader run() {
return new AntClassLoader(getClass().getClassLoader(), false);
}
});
confloader.setProject(getProject());
if (null != confpath)
confloader.addPathElement(confpath);
}
示例9: setConf
import org.apache.tools.ant.AntClassLoader; //導入依賴的package包/類
/**
* Sets the path for the parent-last ClassLoader, intended to be used for
* {@link org.apache.hadoop.conf.Configuration Configuration}.
* @param confpath The path to search for resources, classes, etc. before
* parent ClassLoaders.
*/
public void setConf(String confpath) {
confloader = new AntClassLoader(getClass().getClassLoader(), false);
confloader.setProject(getProject());
if (null != confpath)
confloader.addPathElement(confpath);
}
示例10: doRun
import org.apache.tools.ant.AntClassLoader; //導入依賴的package包/類
private void doRun(List<String> args)
throws Exception
{
AntClassLoader classLoader = new AntClassLoader( null, createRuntimeClasspath(), false );
try
{
classLoader.setThreadContextLoader();
log(classLoader.toString(), Project.MSG_DEBUG);
AntTaskRunnerMonitor recorderMonitor = new AntTaskRunnerMonitor();
Object runnerInstance = createRunner( classLoader , new AntTaskRunnerLogger(this), recorderMonitor );
CommandLineRunnerMirror runner = DuckType.implement( CommandLineRunnerMirror.class, runnerInstance );
String[] arguments = new String[args.size()];
args.toArray(arguments);
runner.run(arguments);
log(String.format("Results: %s for %s specification(s)",
recorderMonitor.getStatistics().toString(),
recorderMonitor.getLocationCount()), Project.MSG_INFO);
checkResults(recorderMonitor.hasException(), "Some greenpepper tests did not run");
checkResults(recorderMonitor.hasTestFailures(), "There were greenpepper tests failures");
}
finally
{
classLoader.resetThreadContextLoader();
}
}
示例11: getCookCCPath
import org.apache.tools.ant.AntClassLoader; //導入依賴的package包/類
protected String getCookCCPath ()
{
ClassLoader cl = Task.class.getClassLoader ();
if (cl instanceof AntClassLoader)
{
return ((AntClassLoader)cl).getClasspath ();
}
throw new RuntimeException ("Unable to determine the runtime path of CookCC.");
}
示例12: execute
import org.apache.tools.ant.AntClassLoader; //導入依賴的package包/類
public void execute() throws BuildException {
if (taskClasspath==null || taskClasspath.size()==0) {
throw new BuildException("no classpath given");
}
Project project = getProject();
AntClassLoader loader = new AntClassLoader(makeRoot(),true);
project.addReference(name,loader);
}
示例13: getClassLoader
import org.apache.tools.ant.AntClassLoader; //導入依賴的package包/類
/**
* combines the various ways that could specify a ClassLoader and
* potentially creates one that needs to be cleaned up when it is
* no longer needed so that classes can get garbage collected.
*
* @return ClassLoaderWithFlag
*/
protected ClassLoaderWithFlag getClassLoader() {
ClassLoader cl = null;
if (loader != null) {
cl = (ClassLoader) loader.getReferencedObject();
}
boolean clNeedsCleanup = false;
if (cl == null) {
if (getClasspath() != null) {
Path p = getClasspath().concatSystemClasspath("ignore");
if (parentFirst) {
cl = getProject().createClassLoader(p);
} else {
cl = AntClassLoader.newAntClassLoader(getProject()
.getCoreLoader(),
getProject(),
p, false);
}
clNeedsCleanup = loader == null;
} else {
cl = JavaResource.class.getClassLoader();
}
if (loader != null && cl != null) {
getProject().addReference(loader.getRefId(), cl);
}
}
return new ClassLoaderWithFlag(cl, clNeedsCleanup);
}
示例14: selectorCreate
import org.apache.tools.ant.AntClassLoader; //導入依賴的package包/類
/**
* Instantiates the identified custom selector class.
*/
public void selectorCreate() {
if (classname != null && classname.length() > 0) {
try {
Class<?> c;
if (classpath == null) {
c = Class.forName(classname);
} else {
// Memory-Leak in line below
AntClassLoader al
= getProject().createClassLoader(classpath);
c = Class.forName(classname, true, al);
}
dynselector = c.asSubclass(FileSelector.class).newInstance();
final Project p = getProject();
if (p != null) {
p.setProjectReference(dynselector);
}
} catch (ClassNotFoundException cnfexcept) {
setError("Selector " + classname
+ " not initialized, no such class");
} catch (InstantiationException iexcept) {
setError("Selector " + classname
+ " not initialized, could not create class");
} catch (IllegalAccessException iaexcept) {
setError("Selector " + classname
+ " not initialized, class not accessible");
}
} else {
setError("There is no classname specified");
}
}
示例15: classpathLookup
import org.apache.tools.ant.AntClassLoader; //導入依賴的package包/類
/**
* Utility method to lookup a ResourceLocation in the classpath.
*
* @return An InputSource for reading the resource, or <code>null</code>
* if the resource does not exist in the classpath or is not readable.
*/
private InputSource classpathLookup(ResourceLocation matchingEntry) {
InputSource source = null;
Path cp = classpath;
if (cp != null) {
cp = classpath.concatSystemClasspath("ignore");
} else {
cp = (new Path(getProject())).concatSystemClasspath("last");
}
AntClassLoader loader = getProject().createClassLoader(cp);
//
// for classpath lookup we ignore the base directory
//
InputStream is
= loader.getResourceAsStream(matchingEntry.getLocation());
if (is != null) {
source = new InputSource(is);
URL entryURL = loader.getResource(matchingEntry.getLocation());
String sysid = entryURL.toExternalForm();
source.setSystemId(sysid);
log("catalog entry matched a resource in the classpath: '"
+ sysid + "'", Project.MSG_DEBUG);
}
return source;
}