@Test public void nonEmptyAdditionalDependenciesFromPlugin() throws IOException { Pair<Model, Xpp3Dom> pair = createModelWithConfiguration(); Xpp3Dom additionalPluginDependencies = new Xpp3Dom(ADDITIONAL_PLUGIN_DEPENDENCIES_ELEMENT); pair.getRight().addChild(additionalPluginDependencies); Xpp3Dom pluginChildren = new Xpp3Dom(PLUGIN_ELEMENT); additionalPluginDependencies.addChild(pluginChildren); Xpp3Dom artifactId = new Xpp3Dom(ARTIFACT_ID_ELEMENT); pluginChildren.addChild(artifactId); artifactId.setValue(RESOLVED_BUNDLE_PLUGIN.getDescriptor().getArtifactId()); Xpp3Dom groupId = new Xpp3Dom(GROUP_ID_ELEMENT); pluginChildren.addChild(groupId); groupId.setValue(RESOLVED_BUNDLE_PLUGIN.getDescriptor().getGroupId()); Xpp3Dom additionalDependencies = new Xpp3Dom(ADDITIONAL_DEPENDENCIES_ELEMENT); pluginChildren.addChild(additionalDependencies); addDependency(additionalDependencies, "1"); addDependency(additionalDependencies, "2"); reset(mockedMavenClient); when(mockedMavenClient.getEffectiveModel(any(), any())).thenReturn(pair.getLeft()); when(mockedMavenClient.getMavenConfiguration()).thenReturn(mockedMavenConfiguration); BundleDependency mockedBundleDependency1 = mock(BundleDependency.class, RETURNS_DEEP_STUBS); when(mockedBundleDependency1.getDescriptor().getArtifactId()).thenReturn(ARTIFACT_ID_ELEMENT + "1"); when(mockedBundleDependency1.getDescriptor().getGroupId()).thenReturn(GROUP_ID_ELEMENT + "1"); when(mockedBundleDependency1.getDescriptor().getVersion()).thenReturn("1.0.0"); BundleDependency mockedBundleDependency2 = mock(BundleDependency.class, RETURNS_DEEP_STUBS); when(mockedBundleDependency2.getDescriptor().getArtifactId()).thenReturn(ARTIFACT_ID_ELEMENT + "2"); when(mockedBundleDependency2.getDescriptor().getGroupId()).thenReturn(GROUP_ID_ELEMENT + "2"); when(mockedBundleDependency2.getDescriptor().getVersion()).thenReturn("1.0.0"); doAnswer(invocationOnMock -> { List<BundleDescriptor> dependencies = invocationOnMock.getArgument(0); return dependencies.stream() .map(dep -> { String artifactId1 = dep.getArtifactId(); if (artifactId1.equals(ARTIFACT_ID_ELEMENT + "1")) { return mockedBundleDependency1; } else { return mockedBundleDependency2; } }) .collect(toList()); }).when(mockedMavenClient).resolveArtifactDependencies(any(), any(), any()); when(mockedMavenClient.resolveBundleDescriptorDependencies(eq(false), eq(false), any())).thenReturn(emptyList()); Map<BundleDependency, List<BundleDependency>> resolvedAdditionalDependencies = createAdditionalPluginDependenciesResolver(emptyList()) .resolveDependencies(of(RESOLVED_BUNDLE_PLUGIN), of(resolvedPluginClassLoaderModel)); assertThat(resolvedAdditionalDependencies.size(), is(1)); List<BundleDependency> dependencies = resolvedAdditionalDependencies.values().iterator().next(); assertThat(dependencies.size(), is(2)); }
public Map<BundleDependency, List<BundleDependency>> resolveDependencies(List<BundleDependency> applicationDependencies, Collection<ClassLoaderModel> mulePluginsClassLoaderModels) { addPluginDependenciesAdditionalLibraries(applicationDependencies); Map<BundleDependency, List<BundleDependency>> pluginsWithAdditionalDeps = new LinkedHashMap<>(); for (Plugin pluginWithAdditionalDependencies : pluginsWithAdditionalDependencies) { BundleDependency pluginBundleDependency = getPluginBundleDependency(pluginWithAdditionalDependencies, applicationDependencies); ClassLoaderModel pluginClassLoaderModel = getPluginClassLoaderModel(pluginWithAdditionalDependencies, mulePluginsClassLoaderModels); List<BundleDependency> additionalDependencies = resolveDependencies(pluginWithAdditionalDependencies.getAdditionalDependencies().stream() .filter(additionalDep -> !isPresentInClassLoaderModel(pluginClassLoaderModel, additionalDep)) .collect(toList())); if (!additionalDependencies.isEmpty()) { pluginsWithAdditionalDeps.put(pluginBundleDependency, additionalDependencies); } } return pluginsWithAdditionalDeps; }
AdditionalPluginDependenciesResolver { public Map<BundleDependency, List<BundleDependency>> resolveDependencies(List<BundleDependency> applicationDependencies, Collection<ClassLoaderModel> mulePluginsClassLoaderModels) { addPluginDependenciesAdditionalLibraries(applicationDependencies); Map<BundleDependency, List<BundleDependency>> pluginsWithAdditionalDeps = new LinkedHashMap<>(); for (Plugin pluginWithAdditionalDependencies : pluginsWithAdditionalDependencies) { BundleDependency pluginBundleDependency = getPluginBundleDependency(pluginWithAdditionalDependencies, applicationDependencies); ClassLoaderModel pluginClassLoaderModel = getPluginClassLoaderModel(pluginWithAdditionalDependencies, mulePluginsClassLoaderModels); List<BundleDependency> additionalDependencies = resolveDependencies(pluginWithAdditionalDependencies.getAdditionalDependencies().stream() .filter(additionalDep -> !isPresentInClassLoaderModel(pluginClassLoaderModel, additionalDep)) .collect(toList())); if (!additionalDependencies.isEmpty()) { pluginsWithAdditionalDeps.put(pluginBundleDependency, additionalDependencies); } } return pluginsWithAdditionalDeps; } }
AdditionalPluginDependenciesResolver { public Map<BundleDependency, List<BundleDependency>> resolveDependencies(List<BundleDependency> applicationDependencies, Collection<ClassLoaderModel> mulePluginsClassLoaderModels) { addPluginDependenciesAdditionalLibraries(applicationDependencies); Map<BundleDependency, List<BundleDependency>> pluginsWithAdditionalDeps = new LinkedHashMap<>(); for (Plugin pluginWithAdditionalDependencies : pluginsWithAdditionalDependencies) { BundleDependency pluginBundleDependency = getPluginBundleDependency(pluginWithAdditionalDependencies, applicationDependencies); ClassLoaderModel pluginClassLoaderModel = getPluginClassLoaderModel(pluginWithAdditionalDependencies, mulePluginsClassLoaderModels); List<BundleDependency> additionalDependencies = resolveDependencies(pluginWithAdditionalDependencies.getAdditionalDependencies().stream() .filter(additionalDep -> !isPresentInClassLoaderModel(pluginClassLoaderModel, additionalDep)) .collect(toList())); if (!additionalDependencies.isEmpty()) { pluginsWithAdditionalDeps.put(pluginBundleDependency, additionalDependencies); } } return pluginsWithAdditionalDeps; } AdditionalPluginDependenciesResolver(AetherMavenClient muleMavenPluginClient,
                                              List<Plugin> additionalPluginDependencies,
                                              File temporaryFolder); }
AdditionalPluginDependenciesResolver { public Map<BundleDependency, List<BundleDependency>> resolveDependencies(List<BundleDependency> applicationDependencies, Collection<ClassLoaderModel> mulePluginsClassLoaderModels) { addPluginDependenciesAdditionalLibraries(applicationDependencies); Map<BundleDependency, List<BundleDependency>> pluginsWithAdditionalDeps = new LinkedHashMap<>(); for (Plugin pluginWithAdditionalDependencies : pluginsWithAdditionalDependencies) { BundleDependency pluginBundleDependency = getPluginBundleDependency(pluginWithAdditionalDependencies, applicationDependencies); ClassLoaderModel pluginClassLoaderModel = getPluginClassLoaderModel(pluginWithAdditionalDependencies, mulePluginsClassLoaderModels); List<BundleDependency> additionalDependencies = resolveDependencies(pluginWithAdditionalDependencies.getAdditionalDependencies().stream() .filter(additionalDep -> !isPresentInClassLoaderModel(pluginClassLoaderModel, additionalDep)) .collect(toList())); if (!additionalDependencies.isEmpty()) { pluginsWithAdditionalDeps.put(pluginBundleDependency, additionalDependencies); } } return pluginsWithAdditionalDeps; } AdditionalPluginDependenciesResolver(AetherMavenClient muleMavenPluginClient,
                                              List<Plugin> additionalPluginDependencies,
                                              File temporaryFolder); Map<BundleDependency, List<BundleDependency>> resolveDependencies(List<BundleDependency> applicationDependencies,
                                                                           Collection<ClassLoaderModel> mulePluginsClassLoaderModels); }
AdditionalPluginDependenciesResolver { public Map<BundleDependency, List<BundleDependency>> resolveDependencies(List<BundleDependency> applicationDependencies, Collection<ClassLoaderModel> mulePluginsClassLoaderModels) { addPluginDependenciesAdditionalLibraries(applicationDependencies); Map<BundleDependency, List<BundleDependency>> pluginsWithAdditionalDeps = new LinkedHashMap<>(); for (Plugin pluginWithAdditionalDependencies : pluginsWithAdditionalDependencies) { BundleDependency pluginBundleDependency = getPluginBundleDependency(pluginWithAdditionalDependencies, applicationDependencies); ClassLoaderModel pluginClassLoaderModel = getPluginClassLoaderModel(pluginWithAdditionalDependencies, mulePluginsClassLoaderModels); List<BundleDependency> additionalDependencies = resolveDependencies(pluginWithAdditionalDependencies.getAdditionalDependencies().stream() .filter(additionalDep -> !isPresentInClassLoaderModel(pluginClassLoaderModel, additionalDep)) .collect(toList())); if (!additionalDependencies.isEmpty()) { pluginsWithAdditionalDeps.put(pluginBundleDependency, additionalDependencies); } } return pluginsWithAdditionalDeps; } AdditionalPluginDependenciesResolver(AetherMavenClient muleMavenPluginClient,
                                              List<Plugin> additionalPluginDependencies,
                                              File temporaryFolder); Map<BundleDependency, List<BundleDependency>> resolveDependencies(List<BundleDependency> applicationDependencies,
                                                                           Collection<ClassLoaderModel> mulePluginsClassLoaderModels);  }