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();
}
});
}
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;
}
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);
}
Aggregations