Search in sources :

Example 11 with MuleArtifactLoaderDescriptorBuilder

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

the class ArtifactPluginFileBuilder method getCustomResources.

@Override
protected List<ZipResource> getCustomResources() {
    final List<ZipResource> customResources = new LinkedList<>();
    if (!properties.isEmpty()) {
        final MulePluginModel.MulePluginModelBuilder builder = new MulePluginModel.MulePluginModelBuilder();
        builder.setName(getArtifactId()).setMinMuleVersion("4.0.0").setRequiredProduct(MULE);
        MuleArtifactLoaderDescriptorBuilder classLoaderModelDescriptorBuilder = new MuleArtifactLoaderDescriptorBuilder().setId(MULE_LOADER_ID);
        if (properties.containsKey(EXPORTED_CLASS_PACKAGES_PROPERTY)) {
            classLoaderModelDescriptorBuilder.addProperty(EXPORTED_PACKAGES, ((String) properties.get(EXPORTED_CLASS_PACKAGES_PROPERTY)).split(","));
        }
        if (properties.containsKey(PRIVILEGED_EXPORTED_CLASS_PACKAGES_PROPERTY)) {
            classLoaderModelDescriptorBuilder.addProperty(PRIVILEGED_EXPORTED_PACKAGES, ((String) properties.get(PRIVILEGED_EXPORTED_CLASS_PACKAGES_PROPERTY)).split(","));
        }
        if (properties.containsKey(PRIVILEGED_ARTIFACTS_PROPERTY)) {
            classLoaderModelDescriptorBuilder.addProperty(PRIVILEGED_ARTIFACTS_IDS, ((String) properties.get(PRIVILEGED_ARTIFACTS_PROPERTY)).split(","));
        }
        if (properties.containsKey(EXPORTED_RESOURCE_PROPERTY)) {
            classLoaderModelDescriptorBuilder.addProperty(EXPORTED_RESOURCES, ((String) properties.get(EXPORTED_RESOURCE_PROPERTY)).split(","));
        }
        builder.withClassLoaderModelDescriptorLoader(classLoaderModelDescriptorBuilder.build());
        builder.withBundleDescriptorLoader(new MuleArtifactLoaderDescriptor(MULE_LOADER_ID, emptyMap()));
        mulePluginModel = builder.build();
    }
    if (mulePluginModel != null) {
        final File jsonDescriptorFile = new File(getTempFolder(), MULE_ARTIFACT_FOLDER + separator + MULE_ARTIFACT_JSON_DESCRIPTOR);
        jsonDescriptorFile.deleteOnExit();
        String jsonDescriber = new MulePluginModelJsonSerializer().serialize(mulePluginModel);
        try {
            writeStringToFile(jsonDescriptorFile, jsonDescriber);
        } catch (IOException e) {
            throw new IllegalStateException("There was an issue generating the JSON file for " + this.getId(), e);
        }
        customResources.add(new ZipResource(jsonDescriptorFile.getAbsolutePath(), MULE_ARTIFACT_PATH_INSIDE_JAR + "/" + MULE_ARTIFACT_JSON_DESCRIPTOR));
    }
    return customResources;
}
Also used : MuleArtifactLoaderDescriptor(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor) MuleArtifactLoaderDescriptorBuilder(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptorBuilder) MulePluginModelJsonSerializer(org.mule.runtime.api.deployment.persistence.MulePluginModelJsonSerializer) IOException(java.io.IOException) LinkedList(java.util.LinkedList) ZipResource(org.mule.tck.ZipUtils.ZipResource) MulePluginModel(org.mule.runtime.api.deployment.meta.MulePluginModel) FileUtils.writeStringToFile(org.apache.commons.io.FileUtils.writeStringToFile) File(java.io.File)

Example 12 with MuleArtifactLoaderDescriptorBuilder

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

the class AbstractDeploymentTestCase method createModuleUsingByeXmlPluginFileBuilder.

private ArtifactPluginFileBuilder createModuleUsingByeXmlPluginFileBuilder() {
    String moduleFileName = "module-using-bye.xml";
    String extensionName = "using-bye-extension";
    String moduleDestination = "org/mule/module/" + moduleFileName;
    MulePluginModel.MulePluginModelBuilder builder = new MulePluginModel.MulePluginModelBuilder().setName(extensionName).setMinMuleVersion(MIN_MULE_VERSION).setRequiredProduct(MULE);
    builder.withExtensionModelDescriber().setId(XmlExtensionModelLoader.DESCRIBER_ID).addProperty(RESOURCE_XML, moduleDestination);
    builder.withClassLoaderModelDescriptorLoader(new MuleArtifactLoaderDescriptorBuilder().addProperty(EXPORTED_PACKAGES, asList("org.foo")).setId(MULE_LOADER_ID).build());
    builder.withBundleDescriptorLoader(createBundleDescriptorLoader(extensionName, MULE_EXTENSION_CLASSIFIER, MULE_LOADER_ID));
    return new ArtifactPluginFileBuilder(extensionName).containingResource("module-using-byeSource.xml", moduleDestination).dependingOn(byeXmlExtensionPlugin).describedBy(builder.build());
}
Also used : ArtifactPluginFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.ArtifactPluginFileBuilder) MulePluginModelBuilder(org.mule.runtime.api.deployment.meta.MulePluginModel.MulePluginModelBuilder) MuleArtifactLoaderDescriptorBuilder(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptorBuilder) MulePluginModel(org.mule.runtime.api.deployment.meta.MulePluginModel)

Example 13 with MuleArtifactLoaderDescriptorBuilder

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

the class AbstractDeploymentTestCase method createHelloExtensionV1PluginFileBuilder.

private ArtifactPluginFileBuilder createHelloExtensionV1PluginFileBuilder() {
    MulePluginModelBuilder mulePluginModelBuilder = new MulePluginModelBuilder().setMinMuleVersion(MIN_MULE_VERSION).setName("helloExtensionPlugin").setRequiredProduct(MULE).withBundleDescriptorLoader(createBundleDescriptorLoader("helloExtensionPlugin", MULE_EXTENSION_CLASSIFIER, PROPERTIES_BUNDLE_DESCRIPTOR_LOADER_ID, "1.0.0"));
    mulePluginModelBuilder.withClassLoaderModelDescriptorLoader(new MuleArtifactLoaderDescriptorBuilder().setId(MULE_LOADER_ID).build());
    mulePluginModelBuilder.withExtensionModelDescriber().setId(JAVA_LOADER_ID).addProperty("type", "org.foo.hello.HelloExtension").addProperty("version", "1.0.0");
    return new ArtifactPluginFileBuilder("helloExtensionPlugin-1.0.0").dependingOn(new JarFileBuilder("helloExtensionV1", helloExtensionV1JarFile)).describedBy((mulePluginModelBuilder.build()));
}
Also used : ArtifactPluginFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.ArtifactPluginFileBuilder) MuleArtifactLoaderDescriptorBuilder(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptorBuilder) JarFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.JarFileBuilder) MulePluginModelBuilder(org.mule.runtime.api.deployment.meta.MulePluginModel.MulePluginModelBuilder)

Example 14 with MuleArtifactLoaderDescriptorBuilder

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

the class ApplicationDeploymentTestCase method deploysWithExtensionXmlPluginWithDependencies.

@Test
public void deploysWithExtensionXmlPluginWithDependencies() throws Exception {
    String moduleFileName = "module-using-java.xml";
    String extensionName = "using-java-extension";
    String moduleDestination = "org/mule/module/" + moduleFileName;
    MulePluginModel.MulePluginModelBuilder builder = new MulePluginModel.MulePluginModelBuilder().setName(extensionName).setMinMuleVersion(MIN_MULE_VERSION).setRequiredProduct(MULE);
    builder.withExtensionModelDescriber().setId(XmlExtensionModelLoader.DESCRIBER_ID).addProperty(RESOURCE_XML, moduleDestination);
    builder.withClassLoaderModelDescriptorLoader(new MuleArtifactLoaderDescriptorBuilder().addProperty(EXPORTED_PACKAGES, asList("org.foo")).setId(MULE_LOADER_ID).build());
    builder.withBundleDescriptorLoader(createBundleDescriptorLoader(extensionName, MULE_EXTENSION_CLASSIFIER, MULE_LOADER_ID));
    builder.setRequiredProduct(MULE).setMinMuleVersion(MIN_MULE_VERSION);
    final ArtifactPluginFileBuilder byeXmlExtensionPlugin = new ArtifactPluginFileBuilder(extensionName).describedBy(builder.build()).containingResource("module-using-javaSource.xml", moduleDestination).dependingOn(new JarFileBuilder("echoTestJar", echoTestJarFile)).describedBy(builder.build());
    ApplicationFileBuilder applicationFileBuilder = new ApplicationFileBuilder("appWithExtensionXmlPluginWithDependencies").definedBy("app-with-extension-xml-plugin-module-using-java.xml").dependingOn(byeXmlExtensionPlugin);
    addPackedAppFromBuilder(applicationFileBuilder);
    final DefaultDomainManager domainManager = new DefaultDomainManager();
    domainManager.addDomain(createDefaultDomain());
    TestApplicationFactory appFactory = createTestApplicationFactory(new MuleApplicationClassLoaderFactory(new DefaultNativeLibraryFinderFactory()), domainManager, serviceManager, extensionModelLoaderManager, moduleRepository, createDescriptorLoaderRepository());
    deploymentService.setAppFactory(appFactory);
    startDeployment();
    assertDeploymentSuccess(applicationDeploymentListener, applicationFileBuilder.getId());
}
Also used : ArtifactPluginFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.ArtifactPluginFileBuilder) ApplicationFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.ApplicationFileBuilder) DefaultDomainManager(org.mule.runtime.module.deployment.impl.internal.domain.DefaultDomainManager) MuleArtifactLoaderDescriptorBuilder(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptorBuilder) JarFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.JarFileBuilder) MulePluginModel(org.mule.runtime.api.deployment.meta.MulePluginModel) DefaultNativeLibraryFinderFactory(org.mule.runtime.deployment.model.internal.nativelib.DefaultNativeLibraryFinderFactory) Matchers.containsString(org.hamcrest.Matchers.containsString) TestApplicationFactory.createTestApplicationFactory(org.mule.runtime.module.deployment.internal.TestApplicationFactory.createTestApplicationFactory) MuleApplicationClassLoaderFactory(org.mule.runtime.deployment.model.internal.application.MuleApplicationClassLoaderFactory) Test(org.junit.Test)

Example 15 with MuleArtifactLoaderDescriptorBuilder

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

the class ApplicationDeploymentTestCase method failsToDeployWithExtensionThatHasNonExistingIdForClassLoaderModel.

@Test
public void failsToDeployWithExtensionThatHasNonExistingIdForClassLoaderModel() throws Exception {
    String extensionName = "extension-with-classloader-model-id-non-existing";
    MulePluginModel.MulePluginModelBuilder builder = new MulePluginModel.MulePluginModelBuilder().setName(extensionName).setMinMuleVersion(MIN_MULE_VERSION);
    builder.withClassLoaderModelDescriptorLoader(new MuleArtifactLoaderDescriptorBuilder().setId("a-non-existing-ID-describer").addProperty("aProperty", "aValue").build());
    builder.withBundleDescriptorLoader(createBundleDescriptorLoader(extensionName, MULE_EXTENSION_CLASSIFIER, PROPERTIES_BUNDLE_DESCRIPTOR_LOADER_ID));
    final ArtifactPluginFileBuilder byeXmlExtensionPlugin = new ArtifactPluginFileBuilder(extensionName).describedBy(builder.build());
    ApplicationFileBuilder applicationFileBuilder = new ApplicationFileBuilder("appWithExtensionXmlPluginFails").definedBy("app-with-extension-xml-plugin-module-bye.xml").dependingOn(byeXmlExtensionPlugin);
    addPackedAppFromBuilder(applicationFileBuilder);
    startDeployment();
    assertDeploymentFailure(applicationDeploymentListener, applicationFileBuilder.getId(), times(1));
}
Also used : ArtifactPluginFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.ArtifactPluginFileBuilder) ApplicationFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.ApplicationFileBuilder) MuleArtifactLoaderDescriptorBuilder(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptorBuilder) MulePluginModel(org.mule.runtime.api.deployment.meta.MulePluginModel) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

MuleArtifactLoaderDescriptorBuilder (org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptorBuilder)15 MulePluginModel (org.mule.runtime.api.deployment.meta.MulePluginModel)10 ArtifactPluginFileBuilder (org.mule.runtime.module.deployment.impl.internal.builder.ArtifactPluginFileBuilder)10 File (java.io.File)6 MulePluginModelBuilder (org.mule.runtime.api.deployment.meta.MulePluginModel.MulePluginModelBuilder)6 JarFileBuilder (org.mule.runtime.module.deployment.impl.internal.builder.JarFileBuilder)6 MuleArtifactLoaderDescriptor (org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor)5 Test (org.junit.Test)4 IOException (java.io.IOException)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 MulePluginModelJsonSerializer (org.mule.runtime.api.deployment.persistence.MulePluginModelJsonSerializer)3 FileWriter (java.io.FileWriter)2 FileUtils.writeStringToFile (org.apache.commons.io.FileUtils.writeStringToFile)2 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)2 ApplicationFileBuilder (org.mule.runtime.module.deployment.impl.internal.builder.ApplicationFileBuilder)2 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 FileUtils.copyFile (org.apache.commons.io.FileUtils.copyFile)1