Initializes the classloader as/if needed for the given compilation context. @return the classloader that will be used @throws IOException If an error occurs
()
| 1800 | * @throws IOException If an error occurs |
| 1801 | */ |
| 1802 | protected ClassLoader initClassLoader() throws IOException { |
| 1803 | |
| 1804 | classPath = getClassPath(); |
| 1805 | |
| 1806 | ClassLoader jspcLoader = getClass().getClassLoader(); |
| 1807 | if (jspcLoader instanceof AntClassLoader) { |
| 1808 | classPath += File.pathSeparator + ((AntClassLoader) jspcLoader).getClasspath(); |
| 1809 | } |
| 1810 | |
| 1811 | // Turn the classPath into URLs |
| 1812 | List<URL> urls = new ArrayList<>(); |
| 1813 | StringTokenizer tokenizer = new StringTokenizer(classPath, File.pathSeparator); |
| 1814 | while (tokenizer.hasMoreTokens()) { |
| 1815 | String path = tokenizer.nextToken(); |
| 1816 | try { |
| 1817 | File libFile = new File(path); |
| 1818 | urls.add(libFile.toURI().toURL()); |
| 1819 | } catch (IOException ioe) { |
| 1820 | // Failing a toCanonicalPath on a file that |
| 1821 | // exists() should be a JVM regression test, |
| 1822 | // therefore we have permission to freak uot |
| 1823 | throw new RuntimeException(ioe.toString()); |
| 1824 | } |
| 1825 | } |
| 1826 | |
| 1827 | File webappBase = new File(uriRoot); |
| 1828 | if (webappBase.exists()) { |
| 1829 | File classes = new File(webappBase, "/WEB-INF/classes"); |
| 1830 | try { |
| 1831 | if (classes.exists()) { |
| 1832 | classPath = classPath + File.pathSeparator + classes.getCanonicalPath(); |
| 1833 | urls.add(classes.getCanonicalFile().toURI().toURL()); |
| 1834 | } |
| 1835 | } catch (IOException ioe) { |
| 1836 | // failing a toCanonicalPath on a file that |
| 1837 | // exists() should be a JVM regression test, |
| 1838 | // therefore we have permission to freak out |
| 1839 | throw new RuntimeException(ioe.toString()); |
| 1840 | } |
| 1841 | File webinfLib = new File(webappBase, "/WEB-INF/lib"); |
| 1842 | if (webinfLib.exists() && webinfLib.isDirectory()) { |
| 1843 | String[] libs = webinfLib.list(); |
| 1844 | if (libs != null) { |
| 1845 | for (String lib : libs) { |
| 1846 | if (lib.length() < 5) { |
| 1847 | continue; |
| 1848 | } |
| 1849 | String ext = lib.substring(lib.length() - 4); |
| 1850 | if (!".jar".equalsIgnoreCase(ext)) { |
| 1851 | if (".tld".equalsIgnoreCase(ext)) { |
| 1852 | log.warn(Localizer.getMessage("jspc.warning.tldInWebInfLib")); |
| 1853 | } |
| 1854 | continue; |
| 1855 | } |
| 1856 | try { |
| 1857 | File libFile = new File(webinfLib, lib); |
| 1858 | classPath = classPath + File.pathSeparator + libFile.getAbsolutePath(); |
| 1859 | urls.add(libFile.getAbsoluteFile().toURI().toURL()); |
no test coverage detected