Search in sources :

Example 11 with MuleArtifactLoaderDescriptor

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

the class PluginResourcesResolverTestCase method resolvePluginResourcesForMulePlugin.

@Test
public void resolvePluginResourcesForMulePlugin() throws Exception {
    MulePluginModelBuilder builder = new MulePluginModelBuilder();
    builder.withClassLoaderModelDescriptorLoader(new MuleArtifactLoaderDescriptorBuilder().setId("mule").addProperty(EXPORTED_PACKAGES, newArrayList(ORG_MULE_TEST_RUNNER, ORG_MULE_TEST_RUNNER_API)).addProperty(EXPORTED_RESOURCES, newArrayList(META_INF_RESOURCE_PROPERTIES, META_INF_ANOTHER_RESOURCE_PROPERTIES)).build());
    builder.withBundleDescriptorLoader(new MuleArtifactLoaderDescriptor(MULE_LOADER_ID, emptyMap()));
    MulePluginModel mulePluginModel = builder.setName("samplePlugin").setMinMuleVersion("4.0.0").build();
    String mulePluginModelJson = new MulePluginModelJsonSerializer().serialize(mulePluginModel);
    File pluginPropertiesFile = new File(new File(new File(temporaryFolder.getRoot(), "META-INF"), "mule-artifact"), MULE_ARTIFACT_JSON_DESCRIPTOR);
    writeStringToFile(pluginPropertiesFile, mulePluginModelJson);
    URL classPathUrl = temporaryFolder.getRoot().toURI().toURL();
    List<URL> urls = newArrayList(classPathUrl);
    PluginUrlClassification mulePluginClassification = newPluginUrlClassification(urls);
    PluginResourcesResolver resolver = new PluginResourcesResolver();
    PluginUrlClassification result = resolver.resolvePluginResourcesFor(mulePluginClassification);
    assertResolvedResources(mulePluginClassification, result);
}
Also used : MuleArtifactLoaderDescriptor(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor) MuleArtifactLoaderDescriptorBuilder(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptorBuilder) MulePluginModel(org.mule.runtime.api.deployment.meta.MulePluginModel) MulePluginModelJsonSerializer(org.mule.runtime.api.deployment.persistence.MulePluginModelJsonSerializer) MulePluginModelBuilder(org.mule.runtime.api.deployment.meta.MulePluginModel.MulePluginModelBuilder) FileUtils.writeStringToFile(org.apache.commons.io.FileUtils.writeStringToFile) File(java.io.File) URL(java.net.URL) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 12 with MuleArtifactLoaderDescriptor

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

the class ArtifactPluginDescriptorFactoryTestCase method createPluginDescriptor.

@Test
public void createPluginDescriptor() throws Exception {
    String pluginName = "samplePlugin";
    MulePluginModel.MulePluginModelBuilder builder = new MulePluginModel.MulePluginModelBuilder();
    builder.withClassLoaderModelDescriptorLoader(new MuleArtifactLoaderDescriptorBuilder().setId("mule").build());
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(GROUP_ID, "org.mule.test");
    attributes.put(ARTIFACT_ID, pluginName);
    attributes.put(VERSION, "1.0.0");
    attributes.put(CLASSIFIER, MULE_PLUGIN_CLASSIFIER);
    attributes.put(TYPE, "jar");
    builder.withBundleDescriptorLoader(new MuleArtifactLoaderDescriptor(PROPERTIES_BUNDLE_DESCRIPTOR_LOADER_ID, attributes));
    builder.withClassLoaderModelDescriptorLoader(new MuleArtifactLoaderDescriptor(MULE_LOADER_ID, emptyMap()));
    MulePluginModel mulePluginModel = builder.setName(pluginName).setMinMuleVersion("4.0.0").setRequiredProduct(MULE).build();
    ArtifactPluginFileBuilder pluginFileBuilder = new ArtifactPluginFileBuilder(PLUGIN_NAME).tempFolder(pluginsTempFolder.newFolder()).describedBy(mulePluginModel);
    final ArtifactPluginDescriptor artifactPluginDescriptor = descriptorFactory.create(pluginFileBuilder.getArtifactFile(), empty());
    assertThat(artifactPluginDescriptor.getName(), equalTo(pluginName));
    assertThat(artifactPluginDescriptor.getBundleDescriptor().getArtifactId(), equalTo(pluginName));
}
Also used : MuleArtifactLoaderDescriptor(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor) ArtifactPluginFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.ArtifactPluginFileBuilder) MuleArtifactLoaderDescriptorBuilder(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptorBuilder) MulePluginModel(org.mule.runtime.api.deployment.meta.MulePluginModel) HashMap(java.util.HashMap) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 13 with MuleArtifactLoaderDescriptor

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

the class ArtifactPluginDescriptorFactoryTestCase method detectsInvalidClassLoaderModelLoaderId.

@Test
public void detectsInvalidClassLoaderModelLoaderId() throws Exception {
    MulePluginModel.MulePluginModelBuilder pluginModelBuilder = new MulePluginModel.MulePluginModelBuilder().setName(PLUGIN_NAME).setMinMuleVersion(MIN_MULE_VERSION).setRequiredProduct(MULE).withBundleDescriptorLoader(createBundleDescriptorLoader(PROPERTIES_BUNDLE_DESCRIPTOR_LOADER_ID));
    pluginModelBuilder.withClassLoaderModelDescriptorLoader(new MuleArtifactLoaderDescriptor(INVALID_LOADER_ID, emptyMap()));
    ArtifactPluginFileBuilder pluginFileBuilder = new ArtifactPluginFileBuilder(PLUGIN_NAME).tempFolder(pluginsTempFolder.newFolder()).describedBy(pluginModelBuilder.build());
    File pluginJarLocation = pluginFileBuilder.getArtifactFile();
    expectedException.expect(ArtifactDescriptorCreateException.class);
    expectedException.expectMessage(invalidClassLoaderModelIdError(pluginJarLocation, pluginModelBuilder.getClassLoaderModelDescriptorLoader()));
    descriptorFactory.create(pluginJarLocation, empty());
}
Also used : MuleArtifactLoaderDescriptor(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor) ArtifactPluginFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.ArtifactPluginFileBuilder) MulePluginModel(org.mule.runtime.api.deployment.meta.MulePluginModel) File(java.io.File) Test(org.junit.Test)

Example 14 with MuleArtifactLoaderDescriptor

use of org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor 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 15 with MuleArtifactLoaderDescriptor

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

the class AbstractDeploymentTestCase method createPolicyIncludingHelloPluginV2FileBuilder.

private PolicyFileBuilder createPolicyIncludingHelloPluginV2FileBuilder() {
    MulePolicyModelBuilder mulePolicyModelBuilder = new MulePolicyModelBuilder().setMinMuleVersion(MIN_MULE_VERSION).setName(BAZ_POLICY_NAME).setRequiredProduct(MULE).withBundleDescriptorLoader(createBundleDescriptorLoader(BAZ_POLICY_NAME, MULE_POLICY_CLASSIFIER, PROPERTIES_BUNDLE_DESCRIPTOR_LOADER_ID));
    mulePolicyModelBuilder.withClassLoaderModelDescriptorLoader(new MuleArtifactLoaderDescriptor(MULE_LOADER_ID, emptyMap()));
    return new PolicyFileBuilder(BAZ_POLICY_NAME).describedBy(mulePolicyModelBuilder.build()).dependingOn(helloExtensionV2Plugin);
}
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)

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