Search in sources :

Example 1 with ExportedArtifactsCollector

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()));
}
Also used : MuleArtifactLoaderDescriptor(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor) ExportedArtifactsCollector(org.mule.runtime.module.extension.internal.resources.manifest.ExportedArtifactsCollector) MuleArtifactLoaderDescriptorBuilder(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptorBuilder) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) MulePluginModelJsonSerializer(org.mule.runtime.api.deployment.persistence.MulePluginModelJsonSerializer) DefaultClassPackageFinder(org.mule.runtime.module.extension.internal.resources.manifest.DefaultClassPackageFinder) GeneratedResource(org.mule.runtime.extension.api.resources.GeneratedResource) MulePluginModelBuilder(org.mule.runtime.api.deployment.meta.MulePluginModel.MulePluginModelBuilder) LicenseModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.LicenseModelProperty)

Example 2 with ExportedArtifactsCollector

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'")));
        }
    }
}
Also used : ExportedArtifactsCollector(org.mule.runtime.module.extension.internal.resources.manifest.ExportedArtifactsCollector) HashMap(java.util.HashMap) Collection(java.util.Collection) Problem(org.mule.runtime.extension.api.loader.Problem)

Aggregations

ExportedArtifactsCollector (org.mule.runtime.module.extension.internal.resources.manifest.ExportedArtifactsCollector)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 MuleArtifactLoaderDescriptor (org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor)1 MuleArtifactLoaderDescriptorBuilder (org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptorBuilder)1 MulePluginModelBuilder (org.mule.runtime.api.deployment.meta.MulePluginModel.MulePluginModelBuilder)1 MulePluginModelJsonSerializer (org.mule.runtime.api.deployment.persistence.MulePluginModelJsonSerializer)1 Problem (org.mule.runtime.extension.api.loader.Problem)1 GeneratedResource (org.mule.runtime.extension.api.resources.GeneratedResource)1 LicenseModelProperty (org.mule.runtime.module.extension.internal.loader.java.property.LicenseModelProperty)1 ExtensionTypeDescriptorModelProperty (org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty)1 DefaultClassPackageFinder (org.mule.runtime.module.extension.internal.resources.manifest.DefaultClassPackageFinder)1