use of org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel in project mule by mulesoft.
the class PolicyTemplateDescriptorTestCase method verifiesPolicyTemplateDoesNotExportResources.
@Test
public void verifiesPolicyTemplateDoesNotExportResources() throws Exception {
PolicyTemplateDescriptor policyTemplateDescriptor = new PolicyTemplateDescriptor(POLICY_NAME);
ClassLoaderModel classLoaderModel = new ClassLoaderModel.ClassLoaderModelBuilder().exportingResources(Collections.singleton("META-INF/foo.xml")).build();
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage(POLICY_EXPORTED_RESOURCE_ERROR);
policyTemplateDescriptor.setClassLoaderModel(classLoaderModel);
}
use of org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel in project mule by mulesoft.
the class PolicyTemplateDescriptorTestCase method verifiesPolicyTemplateDoesNotExportPackages.
@Test
public void verifiesPolicyTemplateDoesNotExportPackages() throws Exception {
PolicyTemplateDescriptor policyTemplateDescriptor = new PolicyTemplateDescriptor(POLICY_NAME);
ClassLoaderModel classLoaderModel = new ClassLoaderModel.ClassLoaderModelBuilder().exportingPackages(Collections.singleton("org.foo")).build();
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage(POLICY_EXPORTED_PACKAGES_ERROR);
policyTemplateDescriptor.setClassLoaderModel(classLoaderModel);
}
use of org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel in project mule by mulesoft.
the class AbstractMavenClassLoaderModelLoader method createHeavyPackageClassLoaderModel.
private ClassLoaderModel createHeavyPackageClassLoaderModel(File artifactFile, Map<String, Object> attributes) {
File classLoaderModelDescriptor = getClassLoaderModelDescriptor(artifactFile);
org.mule.tools.api.classloader.model.ClassLoaderModel packagerClassLoaderModel = deserialize(classLoaderModelDescriptor);
File deployableArtifactRepositoryFolder = getDeployableArtifactRepositoryFolder(artifactFile);
final ClassLoaderModel.ClassLoaderModelBuilder classLoaderModelBuilder = new ClassLoaderModel.ClassLoaderModelBuilder();
classLoaderModelBuilder.exportingPackages(new HashSet<>(getAttribute(attributes, EXPORTED_PACKAGES))).exportingPrivilegedPackages(new HashSet<>(getAttribute(attributes, PRIVILEGED_EXPORTED_PACKAGES)), new HashSet<>(getAttribute(attributes, PRIVILEGED_ARTIFACTS_IDS))).exportingResources(new HashSet<>(getAttribute(attributes, EXPORTED_RESOURCES)));
Set<BundleDependency> patchBundleDependencies = getPatchedBundledDependencies(artifactFile, deployableArtifactRepositoryFolder);
Set<BundleDependency> bundleDependencies = packagerClassLoaderModel.getDependencies().stream().map(artifact -> {
Optional<BundleDependency> patchedBundledDependency = patchBundleDependencies.stream().filter(bundleDependency -> bundleDependency.getDescriptor().getGroupId().equals(artifact.getArtifactCoordinates().getGroupId()) && bundleDependency.getDescriptor().getArtifactId().equals(artifact.getArtifactCoordinates().getArtifactId())).findAny();
return patchedBundledDependency.orElse(createBundleDependencyFromPackagerDependency(deployableArtifactRepositoryFolder).apply(artifact));
}).collect(toSet());
loadUrls(artifactFile, classLoaderModelBuilder, bundleDependencies);
classLoaderModelBuilder.dependingOn(bundleDependencies);
return classLoaderModelBuilder.build();
}
use of org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel in project mule by mulesoft.
the class DeployableMavenClassLoaderModelLoaderTestCase method testPatchedDependency.
private void testPatchedDependency(String application, int totalExpectedDependencies, String patchedArtifactId, String patchedArtifactVersion) throws InvalidDescriptorLoaderException {
DeployableMavenClassLoaderModelLoader deployableMavenClassLoaderModelLoader = new DeployableMavenClassLoaderModelLoader(mockMavenClient, mockLocalRepository);
URL patchedAppUrl = getClass().getClassLoader().getResource(Paths.get(APPS_FOLDER, application).toString());
ClassLoaderModel classLoaderModel = deployableMavenClassLoaderModelLoader.load(FileUtils.toFile(patchedAppUrl), emptyMap(), APP);
Set<BundleDependency> dependencies = classLoaderModel.getDependencies();
assertThat(dependencies, hasSize(totalExpectedDependencies));
List<BundleDependency> connectorsFound = dependencies.stream().filter(bundleDependency -> bundleDependency.getDescriptor().getArtifactId().equals(patchedArtifactId)).collect(Collectors.toList());
assertThat(connectorsFound, hasSize(1));
assertThat(connectorsFound.get(0).getDescriptor().getVersion(), is(patchedArtifactVersion));
}
use of org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel in project mule by mulesoft.
the class DeployableArtifactDescriptorFactoryTestCase method classLoaderModelWithSingleDependency.
@Test
public void classLoaderModelWithSingleDependency() throws Exception {
D desc = createArtifactDescriptor(getArtifactRootFolder() + "single-dependency");
ClassLoaderModel classLoaderModel = desc.getClassLoaderModel();
assertThat(classLoaderModel.getDependencies(), hasSize(1));
BundleDependency commonsCollectionDependency = classLoaderModel.getDependencies().iterator().next();
assertThat(commonsCollectionDependency, commonsCollectionDependencyMatcher());
assertThat(classLoaderModel.getUrls().length, is(2));
assertThat(asList(classLoaderModel.getUrls()), hasItem(commonsCollectionDependency.getBundleUri().toURL()));
}
Aggregations