use of org.kie.workbench.common.services.backend.compiler.nio.impl.ClassLoaderProviderImpl in project kie-wb-common by kiegroup.
the class KieClassLoaderProviderTest method getClassloaderFromAllDependenciesTestSimple.
@Test
public void getClassloaderFromAllDependenciesTestSimple() {
AFClassLoaderProvider kieClazzLoaderProvider = new ClassLoaderProviderImpl();
Optional<ClassLoader> classloaderOptional = kieClazzLoaderProvider.getClassloaderFromAllDependencies("src/test/projects/dummy_deps_simple", mavenRepo.toAbsolutePath().toString());
assertTrue(classloaderOptional.isPresent());
ClassLoader classloader = classloaderOptional.get();
URLClassLoader urlsc = (URLClassLoader) classloader;
assertTrue(urlsc.getURLs().length == 4);
}
use of org.kie.workbench.common.services.backend.compiler.nio.impl.ClassLoaderProviderImpl in project kie-wb-common by kiegroup.
the class KieClassLoaderProviderTest method loadProjectClassloaderTest.
@Test
public void loadProjectClassloaderTest() throws Exception {
// we use NIO for this part of the test because Uberfire lack the implementation to copy a tree
Path tmpRoot = Files.createTempDirectory("repo");
Path tmp = Files.createDirectories(Paths.get(tmpRoot.toString(), "dummy"));
TestUtil.copyTree(Paths.get("src/test/projects/dummy_kie_multimodule_classloader"), tmp);
AFCompiler compiler = KieMavenCompilerFactory.getCompiler(KieDecorator.NONE);
Path uberfireTmp = Paths.get(tmp.toAbsolutePath().toString());
WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(uberfireTmp);
CompilationRequest req = new DefaultCompilationRequest(mavenRepo.toAbsolutePath().toString(), info, new String[] { MavenCLIArgs.CLEAN, MavenCLIArgs.COMPILE, MavenCLIArgs.INSTALL }, new HashMap<>(), Boolean.FALSE);
CompilationResponse res = compiler.compileSync(req);
if (res.getMavenOutput().isPresent() && !res.isSuccessful()) {
TestUtil.writeMavenOutputIntoTargetFolder(res.getMavenOutput().get(), "KieClassLoaderProviderTest.loadProjectClassloaderTest");
}
assertTrue(res.isSuccessful());
AFClassLoaderProvider kieClazzLoaderProvider = new ClassLoaderProviderImpl();
List<String> pomList = new ArrayList<>();
MavenUtils.searchPoms(Paths.get("src/test/projects/dummy_kie_multimodule_classloader/"), pomList);
Optional<ClassLoader> clazzLoader = kieClazzLoaderProvider.loadDependenciesClassloaderFromProject(pomList, mavenRepo.toAbsolutePath().toString());
assertNotNull(clazzLoader);
assertTrue(clazzLoader.isPresent());
ClassLoader prjClassloader = clazzLoader.get();
// we try to load the only dep in the prj with a simple call method to see if is loaded or not
Class clazz;
try {
clazz = prjClassloader.loadClass("org.slf4j.LoggerFactory");
assertFalse(clazz.isInterface());
Method m = clazz.getMethod("getLogger", String.class);
Logger logger = (Logger) m.invoke(clazz, "Dummy");
assertTrue(logger.getName().equals("Dummy"));
logger.info("dependency loaded from the prj classpath");
} catch (ClassNotFoundException e) {
fail();
}
TestUtil.rm(tmpRoot.toFile());
}
use of org.kie.workbench.common.services.backend.compiler.nio.impl.ClassLoaderProviderImpl in project kie-wb-common by kiegroup.
the class KieClassLoaderProviderTest method getClassloaderFromAllDependenciesTestComplex.
@Test
public void getClassloaderFromAllDependenciesTestComplex() {
AFClassLoaderProvider kieClazzLoaderProvider = new ClassLoaderProviderImpl();
Optional<ClassLoader> classloaderOptional = kieClazzLoaderProvider.getClassloaderFromAllDependencies("src/test/projects/dummy_deps_complex", mavenRepo.toAbsolutePath().toString());
assertTrue(classloaderOptional.isPresent());
ClassLoader classloader = classloaderOptional.get();
URLClassLoader urlsc = (URLClassLoader) classloader;
assertTrue(urlsc.getURLs().length == 7);
}
use of org.kie.workbench.common.services.backend.compiler.nio.impl.ClassLoaderProviderImpl in project kie-wb-common by kiegroup.
the class KieAfterDecorator method handleKieMavenPlugin.
private KieCompilationResponse handleKieMavenPlugin(CompilationRequest req, CompilationResponse res) {
KieTuple kieModuleMetaInfoTuple = readKieModuleMetaInfo(req);
KieTuple kieModuleTuple = readKieModule(req);
if (kieModuleMetaInfoTuple.getOptionalObject().isPresent() && kieModuleTuple.getOptionalObject().isPresent()) {
AFClassLoaderProvider provider = new ClassLoaderProviderImpl();
Optional<List<URI>> optionalDeps = provider.getURISFromAllDependencies(req.getInfo().getPrjPath().toAbsolutePath().toString());
List<URI> uris = Collections.emptyList();
if (optionalDeps.isPresent()) {
uris = optionalDeps.get();
}
if (req.getKieCliRequest().isLogRequested()) {
return new DefaultKieCompilationResponse(Boolean.TRUE, (KieModuleMetaInfo) kieModuleMetaInfoTuple.getOptionalObject().get(), (KieModule) kieModuleTuple.getOptionalObject().get(), res.getMavenOutput().get(), uris);
} else {
return new DefaultKieCompilationResponse(Boolean.TRUE, (KieModuleMetaInfo) kieModuleMetaInfoTuple.getOptionalObject().get(), (KieModule) kieModuleTuple.getOptionalObject().get(), uris);
}
} else {
StringBuilder sb = new StringBuilder();
if (kieModuleMetaInfoTuple.getErrorMsg().isPresent()) {
sb.append(" Error in the kieModuleMetaInfo from the kieMap:").append(kieModuleMetaInfoTuple.getErrorMsg().get());
}
if (kieModuleTuple.getErrorMsg().isPresent()) {
sb.append(" Error in the kieModule:").append(kieModuleTuple.getErrorMsg().get());
}
if (req.getKieCliRequest().isLogRequested()) {
return new DefaultKieCompilationResponse(Boolean.FALSE, sb.toString(), res.getMavenOutput().get());
} else {
return new DefaultKieCompilationResponse(Boolean.FALSE, sb.toString());
}
}
}
use of org.kie.workbench.common.services.backend.compiler.nio.impl.ClassLoaderProviderImpl in project kie-wb-common by kiegroup.
the class ClassLoaderProviderTest method getClassloaderFromAllDependenciesTestSimple.
@Test
public void getClassloaderFromAllDependenciesTestSimple() {
AFClassLoaderProvider kieClazzLoaderProvider = new ClassLoaderProviderImpl();
Optional<ClassLoader> classloaderOptional = kieClazzLoaderProvider.getClassloaderFromAllDependencies("src/test/projects/dummy_deps_simple", mavenRepo.toAbsolutePath().toString());
assertTrue(classloaderOptional.isPresent());
ClassLoader classloader = classloaderOptional.get();
URLClassLoader urlsc = (URLClassLoader) classloader;
assertTrue(urlsc.getURLs().length == 4);
}
Aggregations