本文整理匯總了Java中org.apache.tools.ant.AntClassLoader.newAntClassLoader方法的典型用法代碼示例。如果您正苦於以下問題:Java AntClassLoader.newAntClassLoader方法的具體用法?Java AntClassLoader.newAntClassLoader怎麽用?Java AntClassLoader.newAntClassLoader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.tools.ant.AntClassLoader
的用法示例。
在下文中一共展示了AntClassLoader.newAntClassLoader方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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);
}
示例2: checkForkedPath
import org.apache.tools.ant.AntClassLoader; //導入方法依賴的package包/類
/**
* Check the path for multiple different versions of
* ant.
* @param cmd command to execute
*/
private void checkForkedPath(final CommandlineJava cmd) {
if (forkedPathChecked) {
return;
}
forkedPathChecked = true;
if (!cmd.haveClasspath()) {
return;
}
try (AntClassLoader loader =
AntClassLoader.newAntClassLoader(null, getProject(),
cmd.createClasspath(getProject()),
true)) {
final String projectResourceName =
LoaderUtils.classNameToResource(Project.class.getName());
URL previous = null;
try {
for (final Enumeration<URL> e = loader.getResources(projectResourceName);
e.hasMoreElements();) {
final URL current = e.nextElement();
if (previous != null && !urlEquals(current, previous)) {
log("WARNING: multiple versions of ant detected "
+ "in path for junit "
+ LINE_SEP + " " + previous
+ LINE_SEP + " and " + current,
Project.MSG_WARN);
return;
}
previous = current;
}
} catch (final Exception ex) {
// Ignore exception
}
}
}
示例3: hasJunit
import org.apache.tools.ant.AntClassLoader; //導入方法依賴的package包/類
/**
* Checks is a junit is on given path.
* @param path the {@link Path} to check
* @return true when given {@link Path} contains junit
* @since 1.9.8
*/
private boolean hasJunit(final Path path) {
try (AntClassLoader loader = AntClassLoader.newAntClassLoader(
null,
getProject(),
path,
true)) {
try {
loader.loadClass("junit.framework.Test");
return true;
} catch (final Exception ex) {
return false;
}
}
}
示例4: execute
import org.apache.tools.ant.AntClassLoader; //導入方法依賴的package包/類
/**
* execute it
* @throws BuildException on error
*/
@Override
public void execute() throws BuildException {
validate();
if (classpath != null) {
classpath = classpath.concatSystemClasspath("ignore");
getProject().log("using user supplied classpath: " + classpath,
Project.MSG_DEBUG);
} else {
classpath = new Path(getProject());
classpath = classpath.concatSystemClasspath("only");
getProject().log("using system classpath: " + classpath,
Project.MSG_DEBUG);
}
try (AntClassLoader loader =
AntClassLoader.newAntClassLoader(getProject().getCoreLoader(),
getProject(),
classpath, false)) {
String loc = null;
if (classname != null) {
//convert a class name into a resource
resource = classname.replace('.', '/') + ".class";
}
if (resource == null) {
throw new BuildException("One of class or resource is required");
}
if (resource.startsWith("/")) {
resource = resource.substring(1);
}
log("Searching for " + resource, Project.MSG_VERBOSE);
URL url = loader.getResource(resource);
if (url != null) {
//set the property
loc = url.toExternalForm();
getProject().setNewProperty(property, loc);
}
}
}