use of org.mule.runtime.extension.api.resources.GeneratedResource in project mule by mulesoft.
the class MulePluginDescriptorGenerator method generateResource.
/**
* {@inheritDoc}
*/
@Override
public Optional<GeneratedResource> generateResource(ExtensionModel extensionModel) {
final Optional<ExtensionTypeDescriptorModelProperty> typeProperty = extensionModel.getModelProperty(ExtensionTypeDescriptorModelProperty.class);
if (!typeProperty.isPresent()) {
return empty();
}
final ExportedArtifactsCollector exportCollector = new ExportedArtifactsCollector(extensionModel, new DefaultClassPackageFinder(processingEnvironment));
final MulePluginModelBuilder builder = new MulePluginModelBuilder();
// Set only for testing purposes, the value will be reset by the plugin packager.
builder.setName(extensionModel.getName());
builder.withClassLoaderModelDescriptorLoader(new MuleArtifactLoaderDescriptorBuilder().setId(MULE_LOADER_ID).addProperty(EXPORTED_PACKAGES, exportCollector.getExportedPackages()).addProperty(EXPORTED_RESOURCES, exportCollector.getExportedResources()).addProperty(PRIVILEGED_EXPORTED_PACKAGES, exportCollector.getPrivilegedExportedPackages()).addProperty(PRIVILEGED_ARTIFACTS_IDS, exportCollector.getPrivilegedArtifacts()).build());
builder.withExtensionModelDescriber().setId(getLoaderId(extensionModel)).addProperty(TYPE_PROPERTY_NAME, typeProperty.get().getType().getTypeName()).addProperty("version", extensionModel.getVersion());
builder.withBundleDescriptorLoader(new MuleArtifactLoaderDescriptor(MULE_LOADER_ID, emptyMap()));
final Optional<LicenseModelProperty> licenseModelPropertyOptional = extensionModel.getModelProperty(LicenseModelProperty.class);
builder.setRequiredProduct(extensionModel.getCategory().equals(COMMUNITY) ? MULE : MULE_EE);
licenseModelPropertyOptional.ifPresent(licenseModelProperty -> {
builder.setRequiredProduct(licenseModelProperty.requiresEeLicense() ? MULE_EE : MULE);
if (licenseModelProperty.requiresEeLicense()) {
builder.withLicenseModel().setAllowsEvaluationLicense(licenseModelProperty.isAllowsEvaluationLicense());
licenseModelProperty.getRequiredEntitlement().ifPresent(requiredEntitlement -> builder.withLicenseModel().setProvider(extensionModel.getVendor()).setRequiredEntitlement(requiredEntitlement));
}
});
final String descriptorJson = new MulePluginModelJsonSerializer().serialize(builder.build());
return of(new GeneratedResource(AUTO_GENERATED_MULE_ARTIFACT_DESCRIPTOR, descriptorJson.getBytes()));
}
use of org.mule.runtime.extension.api.resources.GeneratedResource in project mule by mulesoft.
the class MulePluginDescriptorGeneratorTestCase method generate.
@Test
public void generate() throws Exception {
InputStream in = getClass().getResourceAsStream("/heisenberg-test-mule-artifact.json");
assertThat(in, is(notNullValue()));
String expectedDescriptor = IOUtils.toString(in);
Optional<GeneratedResource> resource = generator.generateResource(extensionModel);
assertThat(resource.isPresent(), is(true));
String actualDescriptor = new String(resource.get().getContent());
JSONAssert.assertEquals(expectedDescriptor, actualDescriptor, true);
}
use of org.mule.runtime.extension.api.resources.GeneratedResource in project mule by mulesoft.
the class ExtensionModelResourceFactoryTestCase method generate.
@Test
public void generate() throws Exception {
GeneratedResource resource = resourceFactory.generateResource(extensionModel).get();
assertThat(resource.getPath(), equalTo(RESOURCE_NAME));
XMLUnit.setIgnoreWhitespace(true);
String expected = IOUtils.toString(currentThread().getContextClassLoader().getResource(RESOURCE_NAME).openStream());
XMLUnit.compareXML(expected, new String(resource.getContent()));
}
use of org.mule.runtime.extension.api.resources.GeneratedResource in project mule by mulesoft.
the class ExtensionFunctionalTestCase method generateResourcesAndAddToClasspath.
private void generateResourcesAndAddToClasspath(File generatedResourcesDirectory, List<GeneratedResource> resources) throws Exception {
ClassLoader cl = getClass().getClassLoader();
Method method = findMethod(cl.getClass(), "addURL", URL.class);
method.setAccessible(true);
for (GeneratedResource resource : resources) {
URL generatedResourceURL = new File(generatedResourcesDirectory, resource.getPath()).toURI().toURL();
method.invoke(cl, generatedResourceURL);
}
}
use of org.mule.runtime.extension.api.resources.GeneratedResource in project mule by mulesoft.
the class ExtensionsTestInfrastructureDiscoverer method generateDslResources.
public List<GeneratedResource> generateDslResources(File generatedResourcesDirectory, ExtensionModel forExtensionModel) {
DslResolvingContext context;
if (extensionManager.getExtensions().stream().anyMatch(e -> !e.getImportedTypes().isEmpty())) {
HashSet<ExtensionModel> models = new HashSet<>(extensionManager.getExtensions());
models.add(MuleExtensionModelProvider.getExtensionModel());
context = DslResolvingContext.getDefault(models);
} else {
context = new NullDslResolvingContext();
}
ExtensionsTestDslResourcesGenerator dslResourceGenerator = new ExtensionsTestDslResourcesGenerator(getDslResourceFactories(), generatedResourcesDirectory, context);
extensionManager.getExtensions().stream().filter(runtimeExtensionModel -> forExtensionModel != null ? runtimeExtensionModel.equals(forExtensionModel) : true).forEach(dslResourceGenerator::generateFor);
return dslResourceGenerator.dumpAll();
}
Aggregations