use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class MuleProductArtifactDescriptorValidator method validate.
@Override
public void validate(ArtifactDescriptor descriptor) {
Product requiredProduct = descriptor.getRequiredProduct();
Product runtimeProduct = getProductByName(getProductName());
if (!runtimeProduct.supports(requiredProduct)) {
throw new MuleRuntimeException(createStaticMessage("The artifact %s requires a different runtime. The artifact required runtime is %s and the runtime is %s", descriptor.getName(), descriptor.getRequiredProduct().name(), runtimeProduct.name()));
}
}
use of org.mule.runtime.api.exception.MuleRuntimeException 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.api.exception.MuleRuntimeException in project mule by mulesoft.
the class MuleExtensionModelLoaderManager method start.
/**
* Will look through SPI every class that implements the {@code providerClass} and if there are repeated IDs, it will
* collect them all to throw an exception with the detailed message.
* <p/>
* The exception, if thrown, will have the following message:
* <pre>
* There are several loaders that return the same ID when looking up providers for 'org.mule.runtime.module.artifact.ExtensionModelLoader'. Full error list:
* ID [some-id] is being returned by the following classes [org.foo.FooLoader, org.bar.BarLoader]
* ID [another-id] is being returned by the following classes [org.foo2.FooLoader2, org.bar2.BarLoader2]
* </pre>
*
* @throws IllegalStateException if there are loaders with repeated IDs.
*/
@Override
public void start() throws MuleException {
final Class<ExtensionModelLoader> providerClass = ExtensionModelLoader.class;
final SpiServiceRegistry spiServiceRegistry = new SpiServiceRegistry();
final ClassLoader classLoader = containerClassLoader.getClassLoader();
final Collection<ExtensionModelLoader> extensionModelLoaders = spiServiceRegistry.lookupProviders(providerClass, classLoader);
final StringBuilder sb = new StringBuilder();
extensionModelLoaders.stream().collect(groupingBy(ExtensionModelLoader::getId)).entrySet().stream().filter(entry -> entry.getValue().size() > 1).forEach(entry -> {
// At this point we are sure there are at least 2 classes that return the same ID, we will append it to the builder
final String classes = entry.getValue().stream().map(extensionModelLoader -> extensionModelLoader.getClass().getName()).collect(Collectors.joining(", "));
sb.append(lineSeparator()).append("ID [").append(entry.getKey()).append("] is being returned by the following classes [").append(classes).append("]");
});
if (isNotBlank(sb.toString())) {
throw new MuleRuntimeException(createStaticMessage(format("There are several loaders that return the same identifier when looking up providers for '%s'. Full error list: %s", providerClass.getName(), sb.toString())));
}
extensionModelLoaders.stream().forEach(extensionModelLoader -> this.extensionModelLoaders.put(extensionModelLoader.getId(), extensionModelLoader));
if (logger.isDebugEnabled()) {
logger.debug("ExtensionModelLoader registered identifiers: {}", printExtensionModelLoaderIDs());
}
}
use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class ApplicationFileBuilder method createApplicationJsonDescriptorFile.
private File createApplicationJsonDescriptorFile(Optional<Boolean> redeploymentEnabled, Optional<String> configResources, Optional<String> exportedPackages, Optional<String> exportedResources) {
File applicationDescriptor = new File(getTempFolder(), getArtifactId() + "application.json");
applicationDescriptor.deleteOnExit();
MuleApplicationModel.MuleApplicationModelBuilder muleApplicationModelBuilder = new MuleApplicationModel.MuleApplicationModelBuilder();
muleApplicationModelBuilder.setName(getArtifactId()).setMinMuleVersion("4.0.0").setRequiredProduct(MULE);
redeploymentEnabled.ifPresent(muleApplicationModelBuilder::setRedeploymentEnabled);
configResources.ifPresent(configs -> {
String[] configFiles = configs.split(",");
muleApplicationModelBuilder.setConfigs(new HashSet<>(asList(configFiles)));
});
MuleArtifactLoaderDescriptorBuilder muleArtifactLoaderDescriptorBuilder = new MuleArtifactLoaderDescriptorBuilder().setId(MULE_LOADER_ID);
exportedPackages.ifPresent(packages -> {
muleArtifactLoaderDescriptorBuilder.addProperty(EXPORTED_PACKAGES, packages.split(","));
});
exportedResources.ifPresent(resources -> {
muleArtifactLoaderDescriptorBuilder.addProperty(EXPORTED_RESOURCES, resources.split(","));
});
muleApplicationModelBuilder.withClassLoaderModelDescriptorLoader(muleArtifactLoaderDescriptorBuilder.build());
muleApplicationModelBuilder.withBundleDescriptorLoader(muleArtifactLoaderDescriptorBuilder.build());
String applicationDescriptorContent = new MuleApplicationModelJsonSerializer().serialize(muleApplicationModelBuilder.build());
try (FileWriter fileWriter = new FileWriter(applicationDescriptor)) {
fileWriter.write(applicationDescriptorContent);
} catch (IOException e) {
throw new MuleRuntimeException(e);
}
return applicationDescriptor;
}
use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class DomainFileBuilder method createDomainJsonDescriptorFile.
private File createDomainJsonDescriptorFile(Optional<Boolean> redeploymentEnabled, Optional<String> configResources, Optional<String> exportedResources) {
File domainDescriptor = new File(getTempFolder(), getArtifactId() + "domain.json");
domainDescriptor.deleteOnExit();
MuleDomainModel.MuleDomainModelBuilder muleDomainModelBuilder = new MuleDomainModel.MuleDomainModelBuilder();
muleDomainModelBuilder.setName(getArtifactId()).setMinMuleVersion("4.0.0").setRequiredProduct(MULE);
redeploymentEnabled.ifPresent(muleDomainModelBuilder::setRedeploymentEnabled);
configResources.ifPresent(configs -> {
String[] configFiles = configs.split(",");
muleDomainModelBuilder.setConfigs(new HashSet<>(asList(configFiles)));
});
MuleArtifactLoaderDescriptorBuilder muleArtifactClassLoaderDescriptorBuilder = new MuleArtifactLoaderDescriptorBuilder().setId(MULE_LOADER_ID);
exportedResources.ifPresent(resources -> {
muleArtifactClassLoaderDescriptorBuilder.addProperty(EXPORTED_RESOURCES, resources.split(","));
});
muleDomainModelBuilder.withClassLoaderModelDescriptorLoader(muleArtifactClassLoaderDescriptorBuilder.build());
muleDomainModelBuilder.withBundleDescriptorLoader(new MuleArtifactLoaderDescriptor(MULE_LOADER_ID, emptyMap()));
String applicationDescriptorContent = new MuleDomainModelJsonSerializer().serialize(muleDomainModelBuilder.build());
try (FileWriter fileWriter = new FileWriter(domainDescriptor)) {
fileWriter.write(applicationDescriptorContent);
} catch (IOException e) {
throw new MuleRuntimeException(e);
}
return domainDescriptor;
}
Aggregations