1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.render.groovy

File XWikiPageClassLoader.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

8
18
5
1
85
56
10
0.56
3.6
5
2

Classes

Class Line # Actions
XWikiPageClassLoader 35 18 0% 10 31
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package com.xpn.xwiki.render.groovy;
21   
22    import java.net.URL;
23    import java.net.URLClassLoader;
24    import java.net.URLStreamHandlerFactory;
25    import java.util.List;
26   
27    import org.slf4j.Logger;
28    import org.slf4j.LoggerFactory;
29   
30    import com.xpn.xwiki.XWikiContext;
31    import com.xpn.xwiki.XWikiException;
32    import com.xpn.xwiki.doc.XWikiAttachment;
33    import com.xpn.xwiki.doc.XWikiDocument;
34   
 
35    public class XWikiPageClassLoader extends URLClassLoader
36    {
37    private static final Logger LOGGER = LoggerFactory.getLogger(XWikiPageClassLoader.class);
38   
 
39  0 toggle public XWikiPageClassLoader(URL[] urls, ClassLoader parent)
40    {
41  0 super(urls, parent);
42    }
43   
 
44  0 toggle public XWikiPageClassLoader(URL[] urls)
45    {
46  0 super(urls);
47    }
48   
 
49  0 toggle public XWikiPageClassLoader(URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory)
50    {
51  0 super(urls, parent, factory);
52    }
53   
 
54  0 toggle public XWikiPageClassLoader(String jarWikiPage, XWikiContext context) throws XWikiException
55    {
56  0 this(jarWikiPage, Thread.currentThread().getContextClassLoader(), context);
57    }
58   
 
59  0 toggle public XWikiPageClassLoader(String jarWikiPage, ClassLoader parent, XWikiContext context) throws XWikiException
60    {
61  0 super(new URL[0], parent);
62   
63  0 XWikiDocument doc = context.getWiki().getDocument(jarWikiPage, context);
64  0 if (!doc.isNew()) {
65  0 List attachList = doc.getAttachmentList();
66  0 for (int i = 0; i < attachList.size(); i++) {
67  0 XWikiAttachment attach = (XWikiAttachment) attachList.get(i);
68  0 String filename = attach.getFilename();
69  0 if (filename.endsWith(".jar")) {
70  0 String downloadURL = doc.getExternalAttachmentURL(filename, "download", context);
71  0 try {
72  0 addURL(new URL(downloadURL));
73  0 if (LOGGER.isDebugEnabled()) {
74  0 LOGGER.debug("Adding [" + downloadURL + "] JAR from page [" + jarWikiPage
75    + "] to Groovy classloader");
76    }
77    } catch (Exception e) {
78  0 LOGGER.warn("Failed to add [" + downloadURL + "] JAR from page [" + jarWikiPage
79    + "], ignoring it.");
80    }
81    }
82    }
83    }
84    }
85    }