Search in sources :

Example 1 with InvalidDescriptorLoaderException

use of org.mule.runtime.module.artifact.api.descriptor.InvalidDescriptorLoaderException in project mule by mulesoft.

the class DeployableMavenClassLoaderModelLoaderTestCase method testPatchedDependency.

private void testPatchedDependency(String application, int totalExpectedDependencies, String patchedArtifactId, String patchedArtifactVersion) throws InvalidDescriptorLoaderException {
    DeployableMavenClassLoaderModelLoader deployableMavenClassLoaderModelLoader = new DeployableMavenClassLoaderModelLoader(mockMavenClient, mockLocalRepository);
    URL patchedAppUrl = getClass().getClassLoader().getResource(Paths.get(APPS_FOLDER, application).toString());
    ClassLoaderModel classLoaderModel = deployableMavenClassLoaderModelLoader.load(FileUtils.toFile(patchedAppUrl), emptyMap(), APP);
    Set<BundleDependency> dependencies = classLoaderModel.getDependencies();
    assertThat(dependencies, hasSize(totalExpectedDependencies));
    List<BundleDependency> connectorsFound = dependencies.stream().filter(bundleDependency -> bundleDependency.getDescriptor().getArtifactId().equals(patchedArtifactId)).collect(Collectors.toList());
    assertThat(connectorsFound, hasSize(1));
    assertThat(connectorsFound.get(0).getDescriptor().getVersion(), is(patchedArtifactVersion));
}
Also used : Collections.emptyMap(java.util.Collections.emptyMap) MavenClient(org.mule.maven.client.api.MavenClient) URL(java.net.URL) BundleDependency(org.mule.runtime.module.artifact.api.descriptor.BundleDependency) Set(java.util.Set) LocalRepositorySupplierFactory(org.mule.maven.client.api.LocalRepositorySupplierFactory) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Assert.assertThat(org.junit.Assert.assertThat) List(java.util.List) Rule(org.junit.Rule) ClassLoaderModel(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel) Paths(java.nio.file.Paths) APP(org.mule.runtime.core.api.config.bootstrap.ArtifactType.APP) Is.is(org.hamcrest.core.Is.is) Matchers.hasSize(org.hamcrest.Matchers.hasSize) InvalidDescriptorLoaderException(org.mule.runtime.module.artifact.api.descriptor.InvalidDescriptorLoaderException) TemporaryFolder(org.junit.rules.TemporaryFolder) Mockito.mock(org.mockito.Mockito.mock) BundleDependency(org.mule.runtime.module.artifact.api.descriptor.BundleDependency) URL(java.net.URL) ClassLoaderModel(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel)

Example 2 with InvalidDescriptorLoaderException

use of org.mule.runtime.module.artifact.api.descriptor.InvalidDescriptorLoaderException in project mule by mulesoft.

the class FileSystemPolicyClassLoaderModelLoader method loadUrls.

private void loadUrls(ClassLoaderModel.ClassLoaderModelBuilder classLoaderModelBuilder, File artifactFolder) throws InvalidDescriptorLoaderException {
    try {
        classLoaderModelBuilder.containing(artifactFolder.toURI().toURL());
        final File libDir = new File(artifactFolder, LIB_DIR);
        if (libDir.exists()) {
            final File[] jars = libDir.listFiles((FilenameFilter) new SuffixFileFilter(JAR_FILE));
            for (int i = 0; i < jars.length; i++) {
                classLoaderModelBuilder.containing(jars[i].toURI().toURL());
            }
        }
    } catch (MalformedURLException e) {
        throw new InvalidDescriptorLoaderException("Failed to create plugin descriptor " + artifactFolder);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) InvalidDescriptorLoaderException(org.mule.runtime.module.artifact.api.descriptor.InvalidDescriptorLoaderException) SuffixFileFilter(org.apache.commons.io.filefilter.SuffixFileFilter) File(java.io.File)

Example 3 with InvalidDescriptorLoaderException

use of org.mule.runtime.module.artifact.api.descriptor.InvalidDescriptorLoaderException in project mule by mulesoft.

the class PropertiesBundleDescriptorLoader method load.

/**
 * Loads a bundle descriptor from the provided properties
 *
 * @param artifactFolder {@link File} where the current artifact to work with. Non null
 * @param attributes attributes defined in the loader.
 * @param artifactType the type of the artifact of the descriptor to be loaded.
 * @return a locator of the coordinates of the current artifact
 * @throws ArtifactDescriptorCreateException if any bundle descriptor required property is missing on the given attributes.
 */
@Override
public BundleDescriptor load(File artifactFolder, Map<String, Object> attributes, ArtifactType artifactType) throws InvalidDescriptorLoaderException {
    String version = (String) attributes.get(VERSION);
    String groupId = (String) attributes.get(GROUP_ID);
    String artifactId = (String) attributes.get(ARTIFACT_ID);
    String classifier = (String) attributes.get(CLASSIFIER);
    String type = (String) attributes.get(TYPE);
    try {
        return new BundleDescriptor.Builder().setVersion(version).setGroupId(groupId).setArtifactId(artifactId).setClassifier(classifier).setType(type).build();
    } catch (IllegalArgumentException e) {
        throw new InvalidDescriptorLoaderException("Bundle descriptor attributes are not complete", e);
    }
}
Also used : InvalidDescriptorLoaderException(org.mule.runtime.module.artifact.api.descriptor.InvalidDescriptorLoaderException)

Aggregations

InvalidDescriptorLoaderException (org.mule.runtime.module.artifact.api.descriptor.InvalidDescriptorLoaderException)3 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Paths (java.nio.file.Paths)1 Collections.emptyMap (java.util.Collections.emptyMap)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 FileUtils (org.apache.commons.io.FileUtils)1 SuffixFileFilter (org.apache.commons.io.filefilter.SuffixFileFilter)1 Matchers.hasSize (org.hamcrest.Matchers.hasSize)1 Is.is (org.hamcrest.core.Is.is)1 Assert.assertThat (org.junit.Assert.assertThat)1 Rule (org.junit.Rule)1 Test (org.junit.Test)1 TemporaryFolder (org.junit.rules.TemporaryFolder)1 Mockito.mock (org.mockito.Mockito.mock)1 LocalRepositorySupplierFactory (org.mule.maven.client.api.LocalRepositorySupplierFactory)1 MavenClient (org.mule.maven.client.api.MavenClient)1