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;
}
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;
}
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);
}
}
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);
}
}
Aggregations