ApplicationClassLoaderModelAssembler { @Deprecated public ApplicationClassloaderModel getApplicationClassLoaderModel(File pomFile, ApplicationGAVModel appGAVModel) throws IllegalStateException { return getApplicationClassLoaderModel(pomFile, null, appGAVModel, false, empty()); } @Deprecated  ApplicationClassLoaderModelAssembler(AetherMavenClient aetherMavenClient, File temporaryFolder);  ApplicationClassLoaderModelAssembler(ApplicationDependencyResolver applicationDependencyResolver,
                                              ClassloaderModelResolver mulePluginClassLoaderModelResolver,
                                              AdditionalPluginDependenciesResolver additionalPluginDependenciesResolver,
                                              JarExplorer jarExplorer); @Deprecated ApplicationClassloaderModel getApplicationClassLoaderModel(File pomFile, ApplicationGAVModel appGAVModel); @Deprecated ApplicationClassloaderModel getApplicationClassLoaderModel(File pomFile, File outputDirectory,
                                                                    ApplicationGAVModel appGAVModel,
                                                                    boolean includeTestDependencies); ApplicationClassloaderModel getApplicationClassLoaderModel(File pomFile, File outputDirectory,
                                                                    ApplicationGAVModel appGAVModel,
                                                                    boolean includeTestDependencies,
                                                                    Optional<MavenReactorResolver> mavenReactorResolver); ArtifactCoordinates getApplicationArtifactCoordinates(Model pomModel, ApplicationGAVModel appGAVModel); static final String CLASS_LOADER_MODEL_VERSION; static final String CLASSES; }
@Test public void getClassLoaderModelTest() throws IOException { List<BundleDependency> appDependencies = new ArrayList<>(); BundleDependency dependency1 = buildBundleDependency(1, 1, EMPTY); BundleDependency dependency2 = buildBundleDependency(1, 2, EMPTY); BundleDependency dependency3 = buildBundleDependency(1, 3, MULE_DOMAIN_CLASSIFIER); appDependencies.add(dependency1); appDependencies.add(dependency2); appDependencies.add(dependency3); List<BundleDependency> appMulePluginDependencies = new ArrayList<>(); BundleDependency dependency5 = buildBundleDependency(1, 5, EMPTY); BundleDependency dependency6 = buildBundleDependency(1, 6, EMPTY); BundleDependency dependency7 = buildBundleDependency(1, 7, EMPTY); BundleDependency dependency8 = buildBundleDependency(1, 8, EMPTY); List<BundleDependency> secondMulePluginDependencies = new ArrayList<>(); secondMulePluginDependencies.add(dependency6); secondMulePluginDependencies.add(dependency7); BundleDependency secondMulePlugin = buildBundleDependency(2, 4, MULE_PLUGIN_CLASSIFIER, VERSION, secondMulePluginDependencies).build(); List<BundleDependency> firstMulePluginDependencies = new ArrayList<>(); firstMulePluginDependencies.add(secondMulePlugin); firstMulePluginDependencies.add(dependency5); firstMulePluginDependencies.add(dependency8); BundleDependency firstMulePlugin = buildBundleDependency(2, 3, MULE_PLUGIN_CLASSIFIER, VERSION, firstMulePluginDependencies).build(); appMulePluginDependencies.add(firstMulePlugin); appMulePluginDependencies.add(secondMulePlugin); aetherMavenClientMock = getAetherMavenClientMock(appDependencies, appMulePluginDependencies); AdditionalPluginDependenciesResolver additionalPluginDependenciesResolver = mock(AdditionalPluginDependenciesResolver.class); Map<BundleDependency, List<BundleDependency>> additionalPluginDependencies = new HashMap<>(); additionalPluginDependencies.put(firstMulePlugin, Lists.newArrayList(dependency1)); when(additionalPluginDependenciesResolver.resolveDependencies(eq(appDependencies), any(Collection.class))) .thenReturn(additionalPluginDependencies); JarExplorer jarExplorer = mock(JarExplorer.class); ApplicationClassLoaderModelAssembler applicationClassLoaderModelAssemblerSpy = getClassLoaderModelAssemblySpy(aetherMavenClientMock, additionalPluginDependenciesResolver, jarExplorer); File outputDirectory = temporaryFolder.newFolder(); File classesDirectory = new File(outputDirectory, CLASSES); assertThat(classesDirectory.mkdirs(), is(true)); Set<String> packages = new HashSet<>(); packages.add("org.test"); Set<String> resources = new HashSet<>(); resources.add("folder/file.properties"); when(jarExplorer.explore(classesDirectory.toURI())).thenReturn(new JarInfo(packages, resources)); ApplicationClassloaderModel applicationClassloaderModel = applicationClassLoaderModelAssemblerSpy.getApplicationClassLoaderModel(mock(File.class), outputDirectory, mock(ApplicationGAVModel.class), true, empty()); assertThat("Application dependencies are not the expected", applicationClassloaderModel.getClassLoaderModel().getDependencies(), containsInAnyOrder(toArtifact(firstMulePlugin), toArtifact(secondMulePlugin), toArtifact(dependency1), toArtifact(dependency2), toArtifact(dependency3))); assertThat(applicationClassloaderModel.getPackages(), equalTo(packages.toArray())); assertThat(applicationClassloaderModel.getResources(), equalTo(resources.toArray())); }
@Test public void getClassLoaderModelWithOneDependencyThatIsNotMulePluginTest() { List<BundleDependency> appDependencies = new ArrayList<>(); BundleDependency dependency1 = buildBundleDependency(1, 1, EMPTY); appDependencies.add(dependency1); List<BundleDependency> appMulePluginDependencies = new ArrayList<>(); aetherMavenClientMock = getAetherMavenClientMock(appDependencies, appMulePluginDependencies); when(aetherMavenClientMock.resolveBundleDescriptorDependencies(eq(false), eq(false), any())).thenReturn(new ArrayList<>()); ApplicationClassLoaderModelAssembler applicationClassLoaderModelAssemblerSpy = getClassLoaderModelAssemblySpy(aetherMavenClientMock); ApplicationClassloaderModel applicationClassloaderModel = applicationClassLoaderModelAssemblerSpy.getApplicationClassLoaderModel(mock(File.class), mock(ApplicationGAVModel.class)); assertThat("Application dependencies are not the expected", applicationClassloaderModel.getClassLoaderModel().getDependencies(), containsInAnyOrder(toArtifact(dependency1))); assertThat("The application should have no mule plugin dependencies", applicationClassloaderModel.getMulePluginsClassloaderModels().size(), equalTo(0)); }
@Test public void getClassLoaderModelWithOneDependencyThatIsAMulePluginTest() { List<BundleDependency> appDependencies = new ArrayList<>(); BundleDependency mulePluginTransitiveDependency1 = buildBundleDependency(1, 1, EMPTY); BundleDependency firstMulePlugin = buildBundleDependency(2, 3, MULE_PLUGIN_CLASSIFIER, VERSION, singletonList(mulePluginTransitiveDependency1)).build(); aetherMavenClientMock = getAetherMavenClientMock(appDependencies, singletonList(firstMulePlugin)); ApplicationClassLoaderModelAssembler applicationClassLoaderModelAssemblerSpy = getClassLoaderModelAssemblySpy(aetherMavenClientMock); ApplicationClassloaderModel applicationClassloaderModel = applicationClassLoaderModelAssemblerSpy.getApplicationClassLoaderModel(mock(File.class), mock(ApplicationGAVModel.class)); assertThat("The class loader model should have one dependency", applicationClassloaderModel.getClassLoaderModel().getDependencies().size(), equalTo(1)); assertThat("Mule plugins are not the expected", applicationClassloaderModel.getClassLoaderModel().getDependencies(), containsInAnyOrder(toArtifact(firstMulePlugin))); assertThat("First mule plugin dependencies are not the expected", applicationClassloaderModel.getMulePluginsClassloaderModels().get(0).getDependencies(), containsInAnyOrder(toArtifact(mulePluginTransitiveDependency1))); }