Search in sources :

Example 6 with MuleArtifactLoaderDescriptor

use of org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor in project mule by mulesoft.

the class PolicyTemplateDescriptorFactoryTestCase method readsRuntimeLibs.

@Test
public void readsRuntimeLibs() throws Exception {
    MulePolicyModelBuilder mulePolicyModelBuilder = new MulePolicyModelBuilder().setName(POLICY_NAME).setMinMuleVersion("4.0.0").setRequiredProduct(MULE).withBundleDescriptorLoader(createPolicyBundleDescriptorLoader(PROPERTIES_BUNDLE_DESCRIPTOR_LOADER_ID));
    mulePolicyModelBuilder.withClassLoaderModelDescriptorLoader(new MuleArtifactLoaderDescriptor(FILE_SYSTEM_POLICY_MODEL_LOADER_ID, emptyMap()));
    PolicyFileBuilder policyFileBuilder = new PolicyFileBuilder(POLICY_NAME).usingLibrary(echoTestJarFile.getAbsolutePath()).describedBy(mulePolicyModelBuilder.build());
    File tempFolder = createTempFolder();
    unzip(policyFileBuilder.getArtifactFile(), tempFolder);
    PolicyTemplateDescriptorFactory descriptorFactory = new PolicyTemplateDescriptorFactory(artifactPluginDescriptorLoader, descriptorLoaderRepository, ArtifactDescriptorValidatorBuilder.builder());
    PolicyTemplateDescriptor desc = descriptorFactory.create(tempFolder, empty());
    assertThat(desc.getClassLoaderModel().getUrls().length, equalTo(2));
    assertThat(toFile(desc.getClassLoaderModel().getUrls()[0]).getPath(), equalTo(tempFolder.toString()));
    assertThat(toFile(desc.getClassLoaderModel().getUrls()[1]).getPath(), equalTo(new File(tempFolder, LIB_DIR + separator + JAR_FILE_NAME).toString()));
}
Also used : MuleArtifactLoaderDescriptor(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor) PolicyFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.PolicyFileBuilder) MulePolicyModelBuilder(org.mule.runtime.api.deployment.meta.MulePolicyModel.MulePolicyModelBuilder) PolicyTemplateDescriptor(org.mule.runtime.deployment.model.api.policy.PolicyTemplateDescriptor) File.createTempFile(java.io.File.createTempFile) FileUtils.toFile(org.apache.commons.io.FileUtils.toFile) File(java.io.File) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 7 with MuleArtifactLoaderDescriptor

use of org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor in project mule by mulesoft.

the class PolicyTemplateDescriptorFactoryTestCase method readsPlugin.

@Test
public void readsPlugin() throws Exception {
    MulePolicyModelBuilder policyModelBuilder = new MulePolicyModelBuilder().setName(POLICY_NAME).setMinMuleVersion("4.0.0").setRequiredProduct(MULE).withBundleDescriptorLoader(createPolicyBundleDescriptorLoader(PROPERTIES_BUNDLE_DESCRIPTOR_LOADER_ID)).withClassLoaderModelDescriptorLoader(new MuleArtifactLoaderDescriptor(MULE_LOADER_ID, emptyMap()));
    ArtifactPluginFileBuilder plugin1 = new ArtifactPluginFileBuilder("plugin1");
    ArtifactPluginFileBuilder plugin2 = new ArtifactPluginFileBuilder("plugin2");
    PolicyFileBuilder policyFileBuilder = new PolicyFileBuilder(POLICY_NAME).describedBy(policyModelBuilder.build()).dependingOn(plugin1).dependingOn(plugin2);
    File tempFolder = createTempFolder();
    unzip(policyFileBuilder.getArtifactFile(), tempFolder);
    final ArtifactPluginDescriptorFactory pluginDescriptorFactory = mock(ArtifactPluginDescriptorFactory.class);
    final PolicyTemplateDescriptorFactory policyTemplateDescriptorFactory = new PolicyTemplateDescriptorFactory(new ArtifactPluginDescriptorLoader(pluginDescriptorFactory), descriptorLoaderRepository, ArtifactDescriptorValidatorBuilder.builder());
    final ArtifactPluginDescriptor expectedPluginDescriptor1 = new ArtifactPluginDescriptor("plugin1");
    final ArtifactPluginDescriptor expectedPluginDescriptor2 = new ArtifactPluginDescriptor("plugin2");
    when(pluginDescriptorFactory.create(any(), any())).thenReturn(expectedPluginDescriptor1).thenReturn(expectedPluginDescriptor2);
    PolicyTemplateDescriptor descriptor = policyTemplateDescriptorFactory.create(tempFolder, empty());
    Set<ArtifactPluginDescriptor> plugins = descriptor.getPlugins();
    assertThat(plugins.size(), equalTo(2));
    assertThat(plugins, hasItem(equalTo(expectedPluginDescriptor1)));
    assertThat(plugins, hasItem(equalTo(expectedPluginDescriptor2)));
}
Also used : MuleArtifactLoaderDescriptor(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor) ArtifactPluginFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.ArtifactPluginFileBuilder) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) PolicyFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.PolicyFileBuilder) ArtifactPluginDescriptorLoader(org.mule.runtime.module.deployment.impl.internal.plugin.ArtifactPluginDescriptorLoader) MulePolicyModelBuilder(org.mule.runtime.api.deployment.meta.MulePolicyModel.MulePolicyModelBuilder) ArtifactPluginDescriptorFactory(org.mule.runtime.module.deployment.impl.internal.plugin.ArtifactPluginDescriptorFactory) PolicyTemplateDescriptor(org.mule.runtime.deployment.model.api.policy.PolicyTemplateDescriptor) File.createTempFile(java.io.File.createTempFile) FileUtils.toFile(org.apache.commons.io.FileUtils.toFile) File(java.io.File) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 8 with MuleArtifactLoaderDescriptor

use of org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor in project mule by mulesoft.

the class ServiceFileBuilder method createServiceJsonDescriptorFile.

private File createServiceJsonDescriptorFile() {
    File serviceDescriptor = new File(getTempFolder(), getArtifactId() + "service.json");
    serviceDescriptor.deleteOnExit();
    MuleServiceModelBuilder serviceModelBuilder = new MuleServiceModelBuilder();
    serviceModelBuilder.setName(getArtifactId()).setMinMuleVersion("4.0.0").setRequiredProduct(MULE);
    serviceModelBuilder.withClassLoaderModelDescriptorLoader(new MuleArtifactLoaderDescriptor(MULE_LOADER_ID, emptyMap()));
    serviceModelBuilder.withBundleDescriptorLoader(new MuleArtifactLoaderDescriptor(MULE_LOADER_ID, emptyMap()));
    serviceModelBuilder.withServiceProviderClassName(serviceProviderClassName);
    String serviceDescriptorContent = new MuleServiceModelJsonSerializer().serialize(serviceModelBuilder.build());
    try (FileWriter fileWriter = new FileWriter(serviceDescriptor)) {
        fileWriter.write(serviceDescriptorContent);
    } catch (IOException e) {
        throw new MuleRuntimeException(e);
    }
    return serviceDescriptor;
}
Also used : MuleArtifactLoaderDescriptor(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor) MuleServiceModelBuilder(org.mule.runtime.api.deployment.meta.MuleServiceModel.MuleServiceModelBuilder) FileWriter(java.io.FileWriter) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) IOException(java.io.IOException) MuleServiceModelJsonSerializer(org.mule.runtime.api.deployment.persistence.MuleServiceModelJsonSerializer) File(java.io.File)

Example 9 with MuleArtifactLoaderDescriptor

use of org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor in project mule by mulesoft.

the class DefaultToolingService method doCreateApplication.

private Application doCreateApplication(File toolingApplicationContent, Optional<Properties> deploymentProperties) throws IOException {
    Optional<Properties> mergedDeploymentProperties = of(createDeploymentProperties(deploymentProperties));
    MuleApplicationModel.MuleApplicationModelBuilder applicationArtifactModelBuilder = applicationDescriptorFactory.createArtifactModelBuilder(toolingApplicationContent);
    String domainName = mergedDeploymentProperties.get().getProperty(DEPLOYMENT_DOMAIN_NAME_REF);
    if (domainName != null) {
        Domain domain = domainRepository.getDomain(domainName);
        if (domain == null) {
            throw new IllegalArgumentException(format("Domain '%s' is expected to be deployed", domainName));
        }
        MuleArtifactLoaderDescriptor classLoaderModelDescriptorLoader = applicationArtifactModelBuilder.getClassLoaderModelDescriptorLoader();
        Map<String, Object> extendedAttributes = new HashMap<>(classLoaderModelDescriptorLoader.getAttributes());
        extendedAttributes.put(CLASSLOADER_MODEL_MAVEN_REACTOR_RESOLVER, new DomainMavenReactorResolver(domain.getLocation(), domain.getDescriptor().getBundleDescriptor()));
        applicationArtifactModelBuilder.withClassLoaderModelDescriptorLoader(new MuleArtifactLoaderDescriptor(classLoaderModelDescriptorLoader.getId(), extendedAttributes));
        ApplicationDescriptor applicationDescriptor = applicationDescriptorFactory.createArtifact(toolingApplicationContent, mergedDeploymentProperties, applicationArtifactModelBuilder.build());
        applicationDescriptor.setDomainName(domain.getArtifactName());
        return new ToolingApplicationWrapper(doCreateApplication(applicationDescriptor));
    }
    return new ToolingApplicationWrapper(doCreateApplication(applicationDescriptorFactory.create(toolingApplicationContent, mergedDeploymentProperties)));
}
Also used : MuleArtifactLoaderDescriptor(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor) HashMap(java.util.HashMap) Properties(java.util.Properties) ApplicationDescriptor(org.mule.runtime.deployment.model.api.application.ApplicationDescriptor) MuleApplicationModel(org.mule.runtime.api.deployment.meta.MuleApplicationModel) Domain(org.mule.runtime.deployment.model.api.domain.Domain)

Example 10 with MuleArtifactLoaderDescriptor

use of org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor in project mule by mulesoft.

the class MulePluginBasedLoaderFinder method getParams.

public Map<String, Object> getParams() {
    Map<String, Object> params = new HashMap<>();
    MuleArtifactLoaderDescriptor muleArtifactLoaderDescriptor = mulePlugin.getExtensionModelLoaderDescriptor().get();
    Map<String, Object> attributes = muleArtifactLoaderDescriptor.getAttributes();
    attributes.entrySet().stream().forEach(entry -> {
        params.put(entry.getKey(), entry.getValue());
    });
    return params;
}
Also used : MuleArtifactLoaderDescriptor(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor) HashMap(java.util.HashMap)

Aggregations

MuleArtifactLoaderDescriptor (org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor)22 File (java.io.File)13 Test (org.junit.Test)12 MulePluginModel (org.mule.runtime.api.deployment.meta.MulePluginModel)8 ArtifactPluginFileBuilder (org.mule.runtime.module.deployment.impl.internal.builder.ArtifactPluginFileBuilder)8 PolicyFileBuilder (org.mule.runtime.module.deployment.impl.internal.builder.PolicyFileBuilder)8 MulePolicyModelBuilder (org.mule.runtime.api.deployment.meta.MulePolicyModel.MulePolicyModelBuilder)7 SmallTest (org.mule.tck.size.SmallTest)7 MuleArtifactLoaderDescriptorBuilder (org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptorBuilder)6 File.createTempFile (java.io.File.createTempFile)5 FileUtils.toFile (org.apache.commons.io.FileUtils.toFile)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)3 MuleServiceModelJsonSerializer (org.mule.runtime.api.deployment.persistence.MuleServiceModelJsonSerializer)3 FileWriter (java.io.FileWriter)2 URISyntaxException (java.net.URISyntaxException)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Collections.emptyList (java.util.Collections.emptyList)2 List (java.util.List)2