use of org.mule.runtime.module.extension.internal.resources.manifest.ExportedArtifactsCollector 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.module.extension.internal.resources.manifest.ExportedArtifactsCollector in project mule by mulesoft.
the class ExportedPackagesValidator method validate.
@Override
public void validate(ExtensionModel model, ProblemsReporter problemsReporter) {
if (shouldValidate()) {
ExportedArtifactsCollector exportedArtifactsCollector = getExportedArtifactsCollector(model);
Map<String, Collection<String>> exportedPackages = exportedArtifactsCollector.getDetailedExportedPackages();
Map<String, Collection<String>> internalPackages = new HashMap<>();
Map<String, Collection<String>> noVisibilityDeclaredPackages = new HashMap<>();
exportedPackages.forEach((packageName, classes) -> {
if (packageName.contains(".api.") || packageName.endsWith(".api")) {
// valid package
} else if (packageName.contains(".internal.") || packageName.endsWith(".internal")) {
internalPackages.put(packageName, classes);
} else {
noVisibilityDeclaredPackages.put(packageName, classes);
}
});
if (!internalPackages.isEmpty()) {
Problem problem = new Problem(model, getErrorMessage(model, internalPackages, "exports the following internal packages"));
if (strictValidation()) {
problemsReporter.addError(problem);
} else {
problemsReporter.addWarning(problem);
}
}
if (!noVisibilityDeclaredPackages.isEmpty()) {
problemsReporter.addWarning(new Problem(model, getErrorMessage(model, noVisibilityDeclaredPackages, "exports packages which doesn't have a defined visibility, 'api' or 'internal'")));
}
}
}
Aggregations