本文整理汇总了Java中org.apache.tools.ant.util.LoaderUtils.getResourceSource方法的典型用法代码示例。如果您正苦于以下问题:Java LoaderUtils.getResourceSource方法的具体用法?Java LoaderUtils.getResourceSource怎么用?Java LoaderUtils.getResourceSource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tools.ant.util.LoaderUtils
的用法示例。
在下文中一共展示了LoaderUtils.getResourceSource方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addClasspathResource
import org.apache.tools.ant.util.LoaderUtils; //导入方法依赖的package包/类
/**
* Implementation of addClasspathEntry.
*
* @param resource resource that one wants to lookup
* @return true if something was in fact added
* @since Ant 1.7.1
*/
private boolean addClasspathResource(String resource) {
/*
* pre Ant 1.6 this method used to call getClass().getResource
* while Ant 1.6 will call ClassLoader.getResource().
*
* The difference is that Class.getResource expects a leading
* slash for "absolute" resources and will strip it before
* delegating to ClassLoader.getResource - so we now have to
* emulate Class's behavior.
*/
if (resource.startsWith("/")) {
resource = resource.substring(1);
} else {
resource = "org/apache/tools/ant/taskdefs/optional/junit/"
+ resource;
}
final File f = LoaderUtils.getResourceSource(JUnitTask.class.getClassLoader(),
resource);
if (f != null) {
log("Found " + f.getAbsolutePath(), Project.MSG_DEBUG);
antRuntimeClasses.createPath().setLocation(f);
return true;
} else {
log("Couldn\'t find " + resource, Project.MSG_DEBUG);
return false;
}
}
示例2: addClasspathEntry
import org.apache.tools.ant.util.LoaderUtils; //导入方法依赖的package包/类
/**
* Search for the given resource and add the directory or archive
* that contains it to the classpath.
*
* <p>Doesn't work for archives in JDK 1.1 as the URL returned by
* getResource doesn't contain the name of the archive.</p>
* @param resource the resource name to search for
*/
protected void addClasspathEntry(String resource) {
/*
* pre Ant 1.6 this method used to call getClass().getResource
* while Ant 1.6 will call ClassLoader.getResource().
*
* The difference is that Class.getResource expects a leading
* slash for "absolute" resources and will strip it before
* delegating to ClassLoader.getResource - so we now have to
* emulate Class's behavior.
*/
if (resource.startsWith("/")) {
resource = resource.substring(1);
} else {
resource = "org/apache/tools/ant/taskdefs/optional/"
+ resource;
}
File f = LoaderUtils.getResourceSource(getClass().getClassLoader(),
resource);
if (f != null) {
log("Found " + f.getAbsolutePath(), Project.MSG_DEBUG);
createClasspath().setLocation(f);
} else {
log("Couldn\'t find " + resource, Project.MSG_VERBOSE);
}
}
示例3: addClasspathEntry
import org.apache.tools.ant.util.LoaderUtils; //导入方法依赖的package包/类
/**
* Search for the given resource and add the directory or archive
* that contains it to the classpath.
*
* <p>Doesn't work for archives in JDK 1.1 as the URL returned by
* getResource doesn't contain the name of the archive.</p>
*
* @param resource resource that one wants to lookup
* @since Ant 1.6
*/
private void addClasspathEntry(String resource) {
/*
* pre Ant 1.6 this method used to call getClass().getResource
* while Ant 1.6 will call ClassLoader.getResource().
*
* The difference is that Class.getResource expects a leading
* slash for "absolute" resources and will strip it before
* delegating to ClassLoader.getResource - so we now have to
* emulate Class's behavior.
*/
if (resource.startsWith("/")) {
resource = resource.substring(1);
} else {
resource = "org/apache/tools/ant/taskdefs/optional/jdepend/"
+ resource;
}
File f = LoaderUtils.getResourceSource(getClass().getClassLoader(),
resource);
if (f == null) {
log("Couldn\'t find " + resource, Project.MSG_DEBUG);
} else {
log("Found " + f.getAbsolutePath(), Project.MSG_DEBUG);
runtimeClasses.createPath().setLocation(f);
}
}
示例4: addResourceSource
import org.apache.tools.ant.util.LoaderUtils; //导入方法依赖的package包/类
private void addResourceSource(Path classpath, String resource) {
final File f =
LoaderUtils.getResourceSource(
ErrorProneExternalCompilerAdapter.class.getClassLoader(), resource);
if (f != null) {
attributes.log("Found " + f.getAbsolutePath(), Project.MSG_DEBUG);
classpath.createPath().setLocation(f);
} else {
attributes.log("Couldn't find " + resource, Project.MSG_DEBUG);
}
}
示例5: mustSplit
import org.apache.tools.ant.util.LoaderUtils; //导入方法依赖的package包/类
private static boolean mustSplit() {
return LoaderUtils.getResourceSource(FTPTask.class.getClassLoader(),
"/org/apache/commons/net/"
+ "ftp/FTP.class")
== null;
}
示例6: testJunitOnCpArguments
import org.apache.tools.ant.util.LoaderUtils; //导入方法依赖的package包/类
@Test
public void testJunitOnCpArguments() throws Exception {
final File tmp = new File(System.getProperty("java.io.tmpdir")); //NOI18N
final File workDir = new File(tmp, String.format("%s_testJCP%d", //NOI18N
getClass().getName(),
System.currentTimeMillis() / 1000));
workDir.mkdirs();
try {
final File modulesDir = new File(workDir, "modules"); //NOI18N
modulesDir.mkdirs();
final Project project = new Project();
project.init();
project.setBaseDir(workDir);
final MockCommandLauncher mockProcLauncher = new MockCommandLauncher();
project.addReference(
MagicNames.ANT_VM_LAUNCHER_REF_ID,
mockProcLauncher);
JUnitTask task = new JUnitTask();
task.setDir(workDir);
task.setFork(true);
task.setProject(project);
final File junit = LoaderUtils.getResourceSource(
JUnitTask.class.getClassLoader(),
"junit/framework/Test.class"); //NOI18N
final Path cp = new Path(project);
cp.setPath(junit.getAbsolutePath());
task.createClasspath().add(cp);
final Path mp = new Path(project);
mp.setPath(modulesDir.getName());
task.createModulepath().add(mp);
task.addTest(new JUnitTest("org.apache.tools.ant.taskdefs.optional.junit.TestTest"));
task.execute();
assertNotNull(mockProcLauncher.cmd);
String resCp = null;
String resMp = null;
Set<String> resExports = new TreeSet<>();
for (int i = 1; i < mockProcLauncher.cmd.length; i++) {
if ("-classpath".equals(mockProcLauncher.cmd[i])) { //NOI18N
resCp = mockProcLauncher.cmd[++i];
} else if ("--module-path".equals(mockProcLauncher.cmd[i])) { //NOI18N
resMp = mockProcLauncher.cmd[++i];
} else if (mockProcLauncher.cmd[i].equals("--add-exports")) { //NOI18N
resExports.add(mockProcLauncher.cmd[++i]);
} else if (JUnitTestRunner.class.getName().equals(mockProcLauncher.cmd[i])) {
break;
}
}
assertTrue("No exports", resExports.isEmpty());
if (project.getProperty(MagicNames.BUILD_SYSCLASSPATH) == null
&& System.getProperty(MagicNames.BUILD_SYSCLASSPATH) == null) {
assertEquals("Expected classpath", cp.toString(), resCp);
}
assertEquals("Expected modulepath", mp.toString(), resMp);
} finally {
delete(workDir);
}
}
示例7: testJunitOnMpArguments
import org.apache.tools.ant.util.LoaderUtils; //导入方法依赖的package包/类
@Test
public void testJunitOnMpArguments() throws Exception {
final File tmp = new File(System.getProperty("java.io.tmpdir")); //NOI18N
final File workDir = new File(tmp, String.format("%s_testJMP%d", //NOI18N
getClass().getName(),
System.currentTimeMillis() / 1000));
workDir.mkdirs();
try {
final File modulesDir = new File(workDir, "modules"); //NOI18N
modulesDir.mkdirs();
final Project project = new Project();
project.init();
project.setBaseDir(workDir);
final MockCommandLauncher mockProcLauncher = new MockCommandLauncher();
project.addReference(
MagicNames.ANT_VM_LAUNCHER_REF_ID,
mockProcLauncher);
JUnitTask task = new JUnitTask();
task.setDir(workDir);
task.setFork(true);
task.setProject(project);
final File junit = LoaderUtils.getResourceSource(
JUnitTask.class.getClassLoader(),
"junit/framework/Test.class"); //NOI18N
final Path mp = new Path(project);
mp.add(new Path(project, junit.getAbsolutePath()));
mp.add(new Path(project, modulesDir.getName()));
task.createModulepath().add(mp);
task.addTest(new JUnitTest("org.apache.tools.ant.taskdefs.optional.junit.TestTest")); //NOI18N
task.execute();
assertNotNull(mockProcLauncher.cmd);
String resCp = null;
String resMp = null;
Set<String> resExports = new TreeSet<>();
for (int i = 1; i < mockProcLauncher.cmd.length; i++) {
if ("-classpath".equals(mockProcLauncher.cmd[i])) { //NOI18N
resCp = mockProcLauncher.cmd[++i];
} else if ("--module-path".equals(mockProcLauncher.cmd[i])) { //NOI18N
resMp = mockProcLauncher.cmd[++i];
} else if (mockProcLauncher.cmd[i].equals("--add-exports")) { //NOI18N
resExports.add(mockProcLauncher.cmd[++i]);
} else if (JUnitTestRunner.class.getName().equals(mockProcLauncher.cmd[i])) {
break;
}
}
assertTrue("No exports", resExports.isEmpty());
if (project.getProperty(MagicNames.BUILD_SYSCLASSPATH) == null
&& System.getProperty(MagicNames.BUILD_SYSCLASSPATH) == null) {
assertNull("No classpath", resCp);
}
assertEquals("Expected modulepath", mp.toString(), resMp);
} finally {
delete(workDir);
}
}