Search in sources :

Example 11 with ZipResource

use of org.mule.tck.ZipUtils.ZipResource in project mule by mulesoft.

the class FileJarExplorerTestCase method readsPackagesFromJar.

@Test
public void readsPackagesFromJar() throws Exception {
    final ZipResource fooClass = new ZipResource("EchoTest.clazz", "org/foo/Foo.class");
    final ZipResource barClass = new ZipResource("EchoTest.clazz", "org/bar/Bar.class");
    final ZipResource[] zipResources = { fooClass, barClass };
    final File jarFile = File.createTempFile("test", ".jar");
    jarFile.delete();
    ZipUtils.compress(jarFile, zipResources);
    final Set<String> packages = packageExplorer.explore(jarFile.toURI()).getPackages();
    assertThat(packages.size(), equalTo(2));
    assertThat(packages, hasItem("org.foo"));
    assertThat(packages, hasItem("org.bar"));
}
Also used : ZipResource(org.mule.tck.ZipUtils.ZipResource) FileUtils.writeStringToFile(org.apache.commons.io.FileUtils.writeStringToFile) File(java.io.File) Test(org.junit.Test)

Example 12 with ZipResource

use of org.mule.tck.ZipUtils.ZipResource in project mule by mulesoft.

the class ApplicationFileBuilder method doGetCustomResources.

@Override
protected List<ZipResource> doGetCustomResources() {
    final List<ZipResource> customResources = new LinkedList<>();
    Object redeploymentEnabled = deployProperties.get(PROPERTY_REDEPLOYMENT_ENABLED);
    Object configResources = deployProperties.get(PROPERTY_CONFIG_RESOURCES);
    File applicationDescriptor = createApplicationJsonDescriptorFile(redeploymentEnabled == null ? empty() : ofNullable(Boolean.valueOf((String) redeploymentEnabled)), Optional.ofNullable((String) configResources), ofNullable((String) properties.get(EXPORTED_PACKAGES)), ofNullable((String) properties.get(EXPORTED_RESOURCES)));
    customResources.add(new ZipResource(applicationDescriptor.getAbsolutePath(), MULE_ARTIFACT_JSON_DESCRIPTOR_LOCATION));
    return customResources;
}
Also used : ZipResource(org.mule.tck.ZipUtils.ZipResource) File(java.io.File) LinkedList(java.util.LinkedList)

Example 13 with ZipResource

use of org.mule.tck.ZipUtils.ZipResource 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 14 with ZipResource

use of org.mule.tck.ZipUtils.ZipResource in project mule by mulesoft.

the class DomainFileBuilder method doGetCustomResources.

@Override
protected List<ZipResource> doGetCustomResources() {
    final List<ZipResource> customResources = new LinkedList<>();
    final ZipResource domainProperties = createPropertiesFile(this.deployProperties, DEFAULT_DEPLOY_PROPERTIES_RESOURCE, DEFAULT_DEPLOY_PROPERTIES_RESOURCE);
    if (domainProperties != null) {
        customResources.add(domainProperties);
    }
    Object redeploymentEnabled = deployProperties.get(PROPERTY_REDEPLOYMENT_ENABLED);
    Object configResources = deployProperties.get(PROPERTY_CONFIG_RESOURCES);
    File domainDescriptor = createDomainJsonDescriptorFile(redeploymentEnabled == null ? empty() : ofNullable(Boolean.valueOf((String) redeploymentEnabled)), Optional.ofNullable((String) configResources), empty());
    customResources.add(new ZipResource(domainDescriptor.getAbsolutePath(), MULE_ARTIFACT_JSON_DESCRIPTOR_LOCATION));
    return customResources;
}
Also used : ZipResource(org.mule.tck.ZipUtils.ZipResource) File(java.io.File) LinkedList(java.util.LinkedList)

Example 15 with ZipResource

use of org.mule.tck.ZipUtils.ZipResource in project mule by mulesoft.

the class PolicyFileBuilder method doGetCustomResources.

@Override
protected List<ZipResource> doGetCustomResources() {
    final List<ZipResource> customResources = new LinkedList<>();
    if (mulePolicyModel != null) {
        final File jsonDescriptorFile = new File(getTempFolder(), META_INF + separator + MULE_ARTIFACT + separator + MULE_ARTIFACT_JSON_DESCRIPTOR);
        jsonDescriptorFile.deleteOnExit();
        String jsonDescriber = new MulePolicyModelJsonSerializer().serialize(mulePolicyModel);
        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(), META_INF + "/" + MULE_ARTIFACT + "/" + MULE_ARTIFACT_JSON_DESCRIPTOR));
    }
    return customResources;
}
Also used : ZipResource(org.mule.tck.ZipUtils.ZipResource) MulePolicyModelJsonSerializer(org.mule.runtime.api.deployment.persistence.MulePolicyModelJsonSerializer) IOException(java.io.IOException) File(java.io.File) FileUtils.writeStringToFile(org.apache.commons.io.FileUtils.writeStringToFile) LinkedList(java.util.LinkedList)

Aggregations

ZipResource (org.mule.tck.ZipUtils.ZipResource)17 File (java.io.File)10 LinkedList (java.util.LinkedList)5 Test (org.junit.Test)4 FileUtils.readFileToString (org.apache.commons.io.FileUtils.readFileToString)3 FileUtils.writeStringToFile (org.apache.commons.io.FileUtils.writeStringToFile)3 IOException (java.io.IOException)2 MuleArtifactLoaderDescriptor (org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor)1 MuleArtifactLoaderDescriptorBuilder (org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptorBuilder)1 MulePluginModel (org.mule.runtime.api.deployment.meta.MulePluginModel)1 MulePluginModelJsonSerializer (org.mule.runtime.api.deployment.persistence.MulePluginModelJsonSerializer)1 MulePolicyModelJsonSerializer (org.mule.runtime.api.deployment.persistence.MulePolicyModelJsonSerializer)1