Search in sources :

Example 1 with ClassPathEntry

use of com.kyj.fx.voeditor.visual.main.model.vo.ClassPathEntry in project Gargoyle by callakrsos.

the class DynamicClassLoaderTest method loadTest3.

/**
	 * classpath를 찾고 classpath의 컴파일 폴더를 기준으로 컴파일을 처리한뒤 정상적으로 특정클래스가 로딩되는지를
	 * 테스트한다.
	 * 
	 * @작성자 : KYJ
	 * @작성일 : 2015. 10. 26.
	 * @throws Exception
	 */
@Test
public void loadTest3() throws Exception {
    ClassPath parsingClassPath = DynamicClassLoader.parsingClassPath("C:/Users/KYJ/JAVA_FX/webWorkspace");
    List<ClassPathEntry> entryFilter = parsingClassPath.entryFilter(entry -> ValueUtil.isNotEmpty(entry.getOutput()));
    entryFilter.forEach(entry -> {
        try {
            String filePathName = parsingClassPath.getFilePathName();
            System.out.println(filePathName);
            String replaceFirst = filePathName.replaceFirst(".classPath", "");
            String output = entry.getOutput();
            System.out.println(output);
            System.out.println("output");
            String classesLocation = replaceFirst + output;
            System.out.println(classesLocation);
            List<ProjectInfo> listClases = DynamicClassLoader.listClases(classesLocation);
            if (listClases.isEmpty())
                return;
            ProjectInfo projectInfo = listClases.get(0);
            List<String> classes = projectInfo.getClasses();
            for (String clzz : classes) {
                DynamicClassLoader.load(classesLocation, clzz);
            }
            System.out.println("load ok.");
        } catch (Exception e) {
            e.printStackTrace();
        }
    });
}
Also used : ClassPath(com.kyj.fx.voeditor.visual.main.model.vo.ClassPath) ProjectInfo(com.kyj.fx.voeditor.visual.loder.ProjectInfo) ClassPathEntry(com.kyj.fx.voeditor.visual.main.model.vo.ClassPathEntry) Test(org.junit.Test)

Example 2 with ClassPathEntry

use of com.kyj.fx.voeditor.visual.main.model.vo.ClassPathEntry in project Gargoyle by callakrsos.

the class FileSearcher method parsingClassPath.

// static class RuntimeJarLoader {
//
// public static void loadJarIndDir(String dir) {
// final URLClassLoader loader = (URLClassLoader)
// ClassLoader.getSystemClassLoader();
// loadJarIndDir(loader, dir);
// }
//
// public static void loadJarIndDir(ClassLoader loader, String dir) {
// try {
// final Method method = URLClassLoader.class.getDeclaredMethod("addURL",
// new Class[] { URL.class });
// method.setAccessible(true);
//
// new File(dir).listFiles(new FileFilter() {
// public boolean accept(File jar) {
// // jar 파일인 경우만 로딩
// if (jar.toString().toLowerCase().contains(".jar")) {
// try {
// // URLClassLoader.addURL(URL url) 메소드 호출
// method.invoke(loader, new Object[] { jar.toURI().toURL() });
// System.out.println(jar.getName() + " is loaded.");
// } catch (Exception e) {
// System.out.println(jar.getName() + " can't load.");
// }
// }
// return false;
// }
// });
// } catch (Exception e) {
// throw new RuntimeException(e);
// }
// }
// }
/**
	 * classPath의 정보를 파싱하여 데이터셋으로 반환
	 *
	 * @작성자 : KYJ
	 * @작성일 : 2015. 10. 26.
	 * @param filePathName
	 * @return
	 * @throws Exception
	 */
public static ClassPath parsingClassPath(String filePathName) throws Exception {
    DocumentBuilderFactory newInstance = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = newInstance.newDocumentBuilder();
    {
        FileTypeMap defaultFileTypeMap = MimetypesFileTypeMap.getDefaultFileTypeMap();
        String contentType = defaultFileTypeMap.getContentType(filePathName);
        LOGGER.debug(String.format("File path Name : %s Content type : %s ", filePathName, contentType));
    }
    Reader reader = new InputStreamReader(new FileInputStream(new File(filePathName)), ENCODING);
    InputSource is = new InputSource(reader);
    Document parse = builder.parse(is);
    ClassPath classPath = new ClassPath();
    classPath.setFilePathName(filePathName);
    classPath.setApplyedEncoding(ENCODING);
    NodeList elementsByTagName2 = parse.getElementsByTagName("classpath");
    int length = elementsByTagName2.getLength();
    for (int i = 0; i < length; i++) {
        Node classPathNode = elementsByTagName2.item(i);
        NodeList childNodes = classPathNode.getChildNodes();
        int classEntrySize = childNodes.getLength();
        for (int e = 0; e < classEntrySize; e++) {
            Node classEntryNode = childNodes.item(e);
            NamedNodeMap attributes = classEntryNode.getAttributes();
            if (attributes == null)
                continue;
            // 코드에서 필요로하는 부분만 XML을 파싱해서 데이터셋에 담는다.
            String kind = emptyThan(attributes.getNamedItem("kind"));
            String output = emptyThan(attributes.getNamedItem("output"));
            String path = emptyThan(attributes.getNamedItem("path"));
            ClassPathEntry classPathEntry = new ClassPathEntry(kind, output, path);
            classPath.addEntry(classPathEntry);
        }
    }
    return classPath;
}
Also used : ClassPath(com.kyj.fx.voeditor.visual.main.model.vo.ClassPath) InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NamedNodeMap(org.w3c.dom.NamedNodeMap) InputStreamReader(java.io.InputStreamReader) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Document(org.w3c.dom.Document) FileInputStream(java.io.FileInputStream) ClassPathEntry(com.kyj.fx.voeditor.visual.main.model.vo.ClassPathEntry) DocumentBuilder(javax.xml.parsers.DocumentBuilder) MimetypesFileTypeMap(javax.activation.MimetypesFileTypeMap) FileTypeMap(javax.activation.FileTypeMap) File(java.io.File)

Example 3 with ClassPathEntry

use of com.kyj.fx.voeditor.visual.main.model.vo.ClassPathEntry in project Gargoyle by callakrsos.

the class DynamicClassLoaderTest method classPathTest.

/**
	 * 
	 * classpath파일을 찾은경우 classpath파일안의 컴파일 폴더를 찾는 테스트코드
	 * 
	 * @작성자 : KYJ
	 * @작성일 : 2015. 10. 26.
	 * @throws Exception
	 */
@Test
public void classPathTest() throws Exception {
    String filePathName = "C:\\G-MES2.0\\workspace\\gmes2-model\\.classPath";
    ClassPath parsingClassPath = DynamicClassLoader.parsingClassPath(filePathName);
    List<ClassPathEntry> entryFilter = parsingClassPath.entryFilter(entry -> ValueUtil.isNotEmpty(entry.getOutput()));
    entryFilter.forEach(System.out::println);
}
Also used : ClassPath(com.kyj.fx.voeditor.visual.main.model.vo.ClassPath) ClassPathEntry(com.kyj.fx.voeditor.visual.main.model.vo.ClassPathEntry) Test(org.junit.Test)

Aggregations

ClassPath (com.kyj.fx.voeditor.visual.main.model.vo.ClassPath)3 ClassPathEntry (com.kyj.fx.voeditor.visual.main.model.vo.ClassPathEntry)3 Test (org.junit.Test)2 ProjectInfo (com.kyj.fx.voeditor.visual.loder.ProjectInfo)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 FileTypeMap (javax.activation.FileTypeMap)1 MimetypesFileTypeMap (javax.activation.MimetypesFileTypeMap)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 Document (org.w3c.dom.Document)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1 InputSource (org.xml.sax.InputSource)1