@Test public void getClassloaderFromAllDependencies() { Optional<ClassLoader> classLoader = CompilerClassloaderUtils.getClassloaderFromAllDependencies(tmpRoot.toString() + "/dummy", mavenRepoPath, TestUtilMaven.getSettingsFile()); assertThat(classLoader).isPresent(); }
public static Optional<ClassLoader> getClassloaderFromAllDependencies(String prjPath, String localRepo, String settingsXmlPath) { AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.STORE_BUILD_CLASSPATH)); WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(Paths.get(URI.create(CommonConstants.FILE_URI + prjPath))); CompilationRequest req; if (settingsXmlPath != null) { req = new DefaultCompilationRequest(localRepo, info, new String[]{MavenConfig.DEPS_IN_MEMORY_BUILD_CLASSPATH, MavenCLIArgs.ALTERNATE_USER_SETTINGS + settingsXmlPath}, Boolean.FALSE); } else { req = new DefaultCompilationRequest(localRepo, info, new String[]{MavenConfig.DEPS_IN_MEMORY_BUILD_CLASSPATH}, Boolean.FALSE); } CompilationResponse res = compiler.compile(req); if (res.isSuccessful()) { if (!res.getDependencies().isEmpty()) { Optional<ClassLoader> urlClassLoader = CompilerClassloaderUtils.createClassloaderFromStringDeps(res.getDependencies()); if (urlClassLoader.isPresent()) { return urlClassLoader; } } } return Optional.empty(); }
CompilerClassloaderUtils { public static Optional<ClassLoader> getClassloaderFromAllDependencies(String prjPath, String localRepo, String settingsXmlPath) { AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.STORE_BUILD_CLASSPATH)); WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(Paths.get(URI.create(CommonConstants.FILE_URI + prjPath))); CompilationRequest req; if (settingsXmlPath != null) { req = new DefaultCompilationRequest(localRepo, info, new String[]{MavenConfig.DEPS_IN_MEMORY_BUILD_CLASSPATH, MavenCLIArgs.ALTERNATE_USER_SETTINGS + settingsXmlPath}, Boolean.FALSE); } else { req = new DefaultCompilationRequest(localRepo, info, new String[]{MavenConfig.DEPS_IN_MEMORY_BUILD_CLASSPATH}, Boolean.FALSE); } CompilationResponse res = compiler.compile(req); if (res.isSuccessful()) { if (!res.getDependencies().isEmpty()) { Optional<ClassLoader> urlClassLoader = CompilerClassloaderUtils.createClassloaderFromStringDeps(res.getDependencies()); if (urlClassLoader.isPresent()) { return urlClassLoader; } } } return Optional.empty(); } }
CompilerClassloaderUtils { public static Optional<ClassLoader> getClassloaderFromAllDependencies(String prjPath, String localRepo, String settingsXmlPath) { AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.STORE_BUILD_CLASSPATH)); WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(Paths.get(URI.create(CommonConstants.FILE_URI + prjPath))); CompilationRequest req; if (settingsXmlPath != null) { req = new DefaultCompilationRequest(localRepo, info, new String[]{MavenConfig.DEPS_IN_MEMORY_BUILD_CLASSPATH, MavenCLIArgs.ALTERNATE_USER_SETTINGS + settingsXmlPath}, Boolean.FALSE); } else { req = new DefaultCompilationRequest(localRepo, info, new String[]{MavenConfig.DEPS_IN_MEMORY_BUILD_CLASSPATH}, Boolean.FALSE); } CompilationResponse res = compiler.compile(req); if (res.isSuccessful()) { if (!res.getDependencies().isEmpty()) { Optional<ClassLoader> urlClassLoader = CompilerClassloaderUtils.createClassloaderFromStringDeps(res.getDependencies()); if (urlClassLoader.isPresent()) { return urlClassLoader; } } } return Optional.empty(); } private  CompilerClassloaderUtils(); }
CompilerClassloaderUtils { public static Optional<ClassLoader> getClassloaderFromAllDependencies(String prjPath, String localRepo, String settingsXmlPath) { AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.STORE_BUILD_CLASSPATH)); WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(Paths.get(URI.create(CommonConstants.FILE_URI + prjPath))); CompilationRequest req; if (settingsXmlPath != null) { req = new DefaultCompilationRequest(localRepo, info, new String[]{MavenConfig.DEPS_IN_MEMORY_BUILD_CLASSPATH, MavenCLIArgs.ALTERNATE_USER_SETTINGS + settingsXmlPath}, Boolean.FALSE); } else { req = new DefaultCompilationRequest(localRepo, info, new String[]{MavenConfig.DEPS_IN_MEMORY_BUILD_CLASSPATH}, Boolean.FALSE); } CompilationResponse res = compiler.compile(req); if (res.isSuccessful()) { if (!res.getDependencies().isEmpty()) { Optional<ClassLoader> urlClassLoader = CompilerClassloaderUtils.createClassloaderFromStringDeps(res.getDependencies()); if (urlClassLoader.isPresent()) { return urlClassLoader; } } } return Optional.empty(); } private  CompilerClassloaderUtils(); static Optional<ClassLoader> getClassloaderFromAllDependencies(String prjPath,
                                                                          String localRepo,
                                                                          String settingsXmlPath); static Map<String, byte[]> getMapClasses(String path,
                                                    Map<String, byte[]> store); static Predicate<File> filterClasses(); static Optional<ClassLoader> loadDependenciesClassloaderFromProject(String prjPath,
                                                                               String localRepo); static Optional<ClassLoader> loadDependenciesClassloaderFromProject(List<String> poms,
                                                                               String localRepo); static Optional<ClassLoader> getClassloaderFromProjectTargets(List<String> pomsPaths); static List<URL> buildUrlsFromArtifacts(String localRepo,
                                                   List<Artifact> artifacts); static List<URL> getDependenciesURL(List<String> poms,
                                               String localRepo); static List<URL> getTargetModulesURL(List<String> pomsPaths); static Optional<ClassLoader> createClassloaderFromStringDeps(List<String> depsProject); static List<URL> readAllDepsAsUrls(List<String> prjDeps); static List<URI> readAllDepsAsUris(List<String> prjDeps); static List<String> readItemsFromClasspathString(Set<String> depsModules); static List<String> getStringFromTargets(Path prjPath); static List<String> getStringFromTargetWithStream(Path pathIn,
                                                             String... extensions); static List<URI> processScannedFilesAsURIs(List<String> classPathFiles); static List<URL> processScannedFilesAsURLs(List<String> classPathFiles); static Set<String> filterPathClasses(Collection<String> paths,
                                                String mavenRepoPath); static List<String> filterClassesByPackage(Collection<String> items,
                                                      String packageName); static Class<?> getClass(String pkgName,
                                    String className,
                                    ClassLoader classloader); }
CompilerClassloaderUtils { public static Optional<ClassLoader> getClassloaderFromAllDependencies(String prjPath, String localRepo, String settingsXmlPath) { AFCompiler compiler = KieMavenCompilerFactory.getCompiler(EnumSet.of(KieDecorator.STORE_BUILD_CLASSPATH)); WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(Paths.get(URI.create(CommonConstants.FILE_URI + prjPath))); CompilationRequest req; if (settingsXmlPath != null) { req = new DefaultCompilationRequest(localRepo, info, new String[]{MavenConfig.DEPS_IN_MEMORY_BUILD_CLASSPATH, MavenCLIArgs.ALTERNATE_USER_SETTINGS + settingsXmlPath}, Boolean.FALSE); } else { req = new DefaultCompilationRequest(localRepo, info, new String[]{MavenConfig.DEPS_IN_MEMORY_BUILD_CLASSPATH}, Boolean.FALSE); } CompilationResponse res = compiler.compile(req); if (res.isSuccessful()) { if (!res.getDependencies().isEmpty()) { Optional<ClassLoader> urlClassLoader = CompilerClassloaderUtils.createClassloaderFromStringDeps(res.getDependencies()); if (urlClassLoader.isPresent()) { return urlClassLoader; } } } return Optional.empty(); } private  CompilerClassloaderUtils(); static Optional<ClassLoader> getClassloaderFromAllDependencies(String prjPath,
                                                                          String localRepo,
                                                                          String settingsXmlPath); static Map<String, byte[]> getMapClasses(String path,
                                                    Map<String, byte[]> store); static Predicate<File> filterClasses(); static Optional<ClassLoader> loadDependenciesClassloaderFromProject(String prjPath,
                                                                               String localRepo); static Optional<ClassLoader> loadDependenciesClassloaderFromProject(List<String> poms,
                                                                               String localRepo); static Optional<ClassLoader> getClassloaderFromProjectTargets(List<String> pomsPaths); static List<URL> buildUrlsFromArtifacts(String localRepo,
                                                   List<Artifact> artifacts); static List<URL> getDependenciesURL(List<String> poms,
                                               String localRepo); static List<URL> getTargetModulesURL(List<String> pomsPaths); static Optional<ClassLoader> createClassloaderFromStringDeps(List<String> depsProject); static List<URL> readAllDepsAsUrls(List<String> prjDeps); static List<URI> readAllDepsAsUris(List<String> prjDeps); static List<String> readItemsFromClasspathString(Set<String> depsModules); static List<String> getStringFromTargets(Path prjPath); static List<String> getStringFromTargetWithStream(Path pathIn,
                                                             String... extensions); static List<URI> processScannedFilesAsURIs(List<String> classPathFiles); static List<URL> processScannedFilesAsURLs(List<String> classPathFiles); static Set<String> filterPathClasses(Collection<String> paths,
                                                String mavenRepoPath); static List<String> filterClassesByPackage(Collection<String> items,
                                                      String packageName); static Class<?> getClass(String pkgName,
                                    String className,
                                    ClassLoader classloader);  }