當前位置: 首頁>>代碼示例>>Java>>正文


Java LoaderUtils.getResourceSource方法代碼示例

本文整理匯總了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;
    }
}
 
開發者ID:apache,項目名稱:ant,代碼行數:36,代碼來源:JUnitTask.java

示例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);
    }
}
 
開發者ID:apache,項目名稱:ant,代碼行數:35,代碼來源:ANTLR.java

示例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);
    }
}
 
開發者ID:apache,項目名稱:ant,代碼行數:37,代碼來源:JDependTask.java

示例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);
  }
}
 
開發者ID:google,項目名稱:error-prone,代碼行數:12,代碼來源:ErrorProneExternalCompilerAdapter.java

示例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;
}
 
開發者ID:apache,項目名稱:ant,代碼行數:7,代碼來源:FTPTask.java

示例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);
    }
}
 
開發者ID:apache,項目名稱:ant,代碼行數:59,代碼來源:JUnitTaskTest.java

示例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);
    }
}
 
開發者ID:apache,項目名稱:ant,代碼行數:57,代碼來源:JUnitTaskTest.java


注:本文中的org.apache.tools.ant.util.LoaderUtils.getResourceSource方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。