Search in sources :

Example 1 with ArtifactDescriptorCreateException

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

the class MavenUtils method lookupPomFromMavenLocation.

public static File lookupPomFromMavenLocation(File artifactFolder) {
    File mulePluginPom = null;
    File lookupFolder = new File(artifactFolder, "META-INF" + separator + "maven");
    while (lookupFolder != null && lookupFolder.exists()) {
        File possiblePomLocation = new File(lookupFolder, MULE_PLUGIN_POM);
        if (possiblePomLocation.exists()) {
            mulePluginPom = possiblePomLocation;
            break;
        }
        File[] directories = lookupFolder.listFiles((FileFilter) DIRECTORY);
        checkState(directories != null || directories.length == 0, format("No directories under %s so pom.xml file for artifact in folder %s could not be found", lookupFolder.getAbsolutePath(), artifactFolder.getAbsolutePath()));
        checkState(directories.length == 1, format("More than one directory under %s so pom.xml file for artifact in folder %s could not be found", lookupFolder.getAbsolutePath(), artifactFolder.getAbsolutePath()));
        lookupFolder = directories[0];
    }
    // final File mulePluginPom = new File(artifactFolder, MULE_ARTIFACT_FOLDER + separator + MULE_PLUGIN_POM);
    if (mulePluginPom == null || !mulePluginPom.exists()) {
        throw new ArtifactDescriptorCreateException(format("The maven bundle loader requires the file pom.xml (error found while reading plugin '%s')", artifactFolder.getName()));
    }
    return mulePluginPom;
}
Also used : ArtifactDescriptorCreateException(org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptorCreateException) FileUtils.createFile(org.mule.runtime.core.api.util.FileUtils.createFile) File(java.io.File)

Example 2 with ArtifactDescriptorCreateException

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

the class MavenUtils method getPomModelFolder.

/**
 * Returns the {@link Model} from a given artifact folder
 *
 * @param artifactFolder folder containing the exploded artifact file.
 * @return the {@link Model} from the {@value ArtifactPluginDescriptor#MULE_PLUGIN_POM} file if available
 * @throws ArtifactDescriptorCreateException if the folder does not contain a {@value ArtifactPluginDescriptor#MULE_PLUGIN_POM}
 *         file or the file can' be loaded
 */
public static Model getPomModelFolder(File artifactFolder) {
    final File mulePluginPom = lookupPomFromMavenLocation(artifactFolder);
    MavenXpp3Reader reader = new MavenXpp3Reader();
    Model model;
    try (FileReader mulePluginPomFileReader = new FileReader(mulePluginPom)) {
        model = reader.read(mulePluginPomFileReader);
    } catch (IOException | XmlPullParserException e) {
        throw new ArtifactDescriptorCreateException(format("There was an issue reading '%s' for the plugin '%s'", mulePluginPom.getName(), artifactFolder.getAbsolutePath()), e);
    }
    return model;
}
Also used : Model(org.apache.maven.model.Model) ArtifactDescriptorCreateException(org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptorCreateException) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) FileReader(java.io.FileReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) FileUtils.createFile(org.mule.runtime.core.api.util.FileUtils.createFile) File(java.io.File)

Example 3 with ArtifactDescriptorCreateException

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

the class MavenUtils method getPomUrlFromJar.

/**
 * Finds the URL of the pom file within the artifact file.
 *
 * @param artifactFile the artifact file to search for the pom file.
 * @return the URL to the pom file.
 */
public static URL getPomUrlFromJar(File artifactFile) {
    String pomFilePath = MULE_ARTIFACT_PATH_INSIDE_JAR + "/" + MULE_PLUGIN_POM;
    URL possibleUrl;
    try {
        possibleUrl = getUrlWithinJar(artifactFile, pomFilePath);
        try (InputStream ignored = possibleUrl.openStream()) {
            return possibleUrl;
        } catch (Exception e) {
            List<URL> jarMavenUrls = getUrlsWithinJar(artifactFile, META_INF + "/" + "maven");
            Optional<URL> pomUrl = jarMavenUrls.stream().filter(url -> url.toString().endsWith("pom.xml")).findAny();
            if (!pomUrl.isPresent()) {
                throw new ArtifactDescriptorCreateException(format("The identifier '%s' requires the file '%s' within the artifact(error found while reading plugin '%s')", artifactFile.getName(), "pom.xml", artifactFile.getAbsolutePath()));
            }
            return pomUrl.get();
        }
    } catch (IOException e) {
        throw new MuleRuntimeException(e);
    }
}
Also used : Optional(java.util.Optional) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ArtifactDescriptorCreateException(org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptorCreateException) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) URL(java.net.URL) ArtifactDescriptorCreateException(org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptorCreateException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) IOException(java.io.IOException)

Example 4 with ArtifactDescriptorCreateException

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

the class ArtifactPluginDescriptorFactory method create.

@Override
public ArtifactPluginDescriptor create(File pluginJarFile, Optional<Properties> deploymentProperties) throws ArtifactDescriptorCreateException {
    try {
        checkArgument(pluginJarFile.isDirectory() || pluginJarFile.getName().endsWith(".jar"), "provided file is not a plugin: " + pluginJarFile.getAbsolutePath());
        // Use / instead of File.separator as the file is going to be accessed inside the jar as a URL
        String mulePluginJsonPathInsideJarFile = MULE_ARTIFACT_PATH_INSIDE_JAR + "/" + MULE_ARTIFACT_JSON_DESCRIPTOR;
        Optional<byte[]> jsonDescriptorContentOptional = loadFileContentFrom(pluginJarFile, mulePluginJsonPathInsideJarFile);
        return jsonDescriptorContentOptional.map(jsonDescriptorContent -> loadFromJsonDescriptor(pluginJarFile, loadModelFromJson(new String(jsonDescriptorContent)), deploymentProperties)).orElseThrow(() -> new ArtifactDescriptorCreateException(pluginDescriptorNotFound(pluginJarFile, mulePluginJsonPathInsideJarFile)));
    } catch (ArtifactDescriptorCreateException e) {
        throw e;
    } catch (IOException e) {
        throw new ArtifactDescriptorCreateException(e);
    }
}
Also used : Properties(java.util.Properties) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) ServiceRegistryDescriptorLoaderRepository(org.mule.runtime.module.deployment.impl.internal.artifact.ServiceRegistryDescriptorLoaderRepository) ArtifactDescriptorCreateException(org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptorCreateException) Preconditions.checkArgument(org.mule.runtime.api.util.Preconditions.checkArgument) MULE_ARTIFACT_PATH_INSIDE_JAR(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor.MULE_ARTIFACT_PATH_INSIDE_JAR) ArtifactDescriptorValidatorBuilder(org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptorValidatorBuilder) IOException(java.io.IOException) String.format(java.lang.String.format) File(java.io.File) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry) AbstractMuleArtifactModelJsonSerializer(org.mule.runtime.api.deployment.persistence.AbstractMuleArtifactModelJsonSerializer) DescriptorLoaderRepository(org.mule.runtime.module.artifact.api.descriptor.DescriptorLoaderRepository) ArtifactType(org.mule.runtime.core.api.config.bootstrap.ArtifactType) AbstractArtifactDescriptorFactory(org.mule.runtime.module.artifact.api.descriptor.AbstractArtifactDescriptorFactory) MulePluginModelJsonSerializer(org.mule.runtime.api.deployment.persistence.MulePluginModelJsonSerializer) LoaderDescriber(org.mule.runtime.deployment.model.api.plugin.LoaderDescriber) ClassLoaderModelLoader(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModelLoader) JarUtils.loadFileContentFrom(org.mule.runtime.core.internal.util.JarUtils.loadFileContentFrom) MULE_ARTIFACT_JSON_DESCRIPTOR(org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptor.MULE_ARTIFACT_JSON_DESCRIPTOR) Optional(java.util.Optional) PLUGIN(org.mule.runtime.core.api.config.bootstrap.ArtifactType.PLUGIN) MulePluginModel(org.mule.runtime.api.deployment.meta.MulePluginModel) ArtifactDescriptorCreateException(org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptorCreateException) IOException(java.io.IOException)

Aggregations

ArtifactDescriptorCreateException (org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptorCreateException)4 File (java.io.File)3 IOException (java.io.IOException)3 Optional (java.util.Optional)2 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)2 FileUtils.createFile (org.mule.runtime.core.api.util.FileUtils.createFile)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileReader (java.io.FileReader)1 InputStream (java.io.InputStream)1 String.format (java.lang.String.format)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Properties (java.util.Properties)1 Model (org.apache.maven.model.Model)1 MavenXpp3Reader (org.apache.maven.model.io.xpp3.MavenXpp3Reader)1 MulePluginModel (org.mule.runtime.api.deployment.meta.MulePluginModel)1 AbstractMuleArtifactModelJsonSerializer (org.mule.runtime.api.deployment.persistence.AbstractMuleArtifactModelJsonSerializer)1 MulePluginModelJsonSerializer (org.mule.runtime.api.deployment.persistence.MulePluginModelJsonSerializer)1 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1