use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class DeployableMavenClassLoaderModelLoader method addArtifactSpecificClassloaderConfiguration.
@Override
protected void addArtifactSpecificClassloaderConfiguration(File artifactFile, ClassLoaderModelBuilder classLoaderModelBuilder, Set<BundleDependency> dependencies) {
try {
classLoaderModelBuilder.containing(artifactFile.toURL());
exportSharedLibrariesResourcesAndPackages(artifactFile, classLoaderModelBuilder, dependencies);
} catch (MalformedURLException e) {
throw new MuleRuntimeException(e);
}
}
use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class ArtifactContextBuilder method build.
/**
* @return the {@code MuleContext} created with the provided configuration
* @throws ConfigurationException when there's a problem creating the {@code MuleContext}
* @throws InitialisationException when a certain configuration component failed during initialisation phase
*/
public ArtifactContext build() throws InitialisationException, ConfigurationException {
checkState(executionClassLoader != null, EXECUTION_CLASSLOADER_WAS_NOT_SET);
checkState(classLoaderRepository != null, CLASS_LOADER_REPOSITORY_WAS_NOT_SET);
checkState(POLICY.equals(artifactType) || APP.equals(artifactType) || parentArtifact == null, ONLY_APPLICATIONS_OR_POLICIES_ARE_ALLOWED_TO_HAVE_A_PARENT_ARTIFACT);
try {
return withContextClassLoader(executionClassLoader, () -> {
List<ConfigurationBuilder> builders = new LinkedList<>();
builders.addAll(additionalBuilders);
builders.add(new ArtifactBootstrapServiceDiscovererConfigurationBuilder(artifactPlugins));
if (extensionManagerFactory == null) {
if (parentArtifact == null) {
extensionManagerFactory = new ArtifactExtensionManagerFactory(artifactPlugins, extensionModelLoaderRepository, new DefaultExtensionManagerFactory());
} else {
extensionManagerFactory = new CompositeArtifactExtensionManagerFactory(parentArtifact, extensionModelLoaderRepository, artifactPlugins, new DefaultExtensionManagerFactory());
}
}
builders.add(new ArtifactExtensionManagerConfigurationBuilder(artifactPlugins, extensionManagerFactory));
builders.add(createConfigurationBuilderFromApplicationProperties());
// TODO MULE-14289 (elrodro83) pass this object to the builder instead of looking it up here
ArtifactConfigurationProcessor artifactConfigurationProcessor = ArtifactConfigurationProcessor.discover();
AtomicReference<ArtifactContext> artifactContext = new AtomicReference<>();
builders.add(new ConfigurationBuilder() {
@Override
public void configure(MuleContext muleContext) throws ConfigurationException {
if (serviceRepository != null) {
serviceConfigurators.add(new ContainerServicesMuleContextConfigurator(serviceRepository));
}
if (classLoaderRepository != null) {
serviceConfigurators.add(customizationService -> customizationService.registerCustomServiceImpl(OBJECT_CLASSLOADER_REPOSITORY, classLoaderRepository));
}
if (policyProvider != null) {
serviceConfigurators.add(customizationService -> customizationService.registerCustomServiceImpl(OBJECT_POLICY_PROVIDER, policyProvider));
}
ArtifactContextConfiguration.ArtifactContextConfigurationBuilder artifactContextConfigurationBuilder = ArtifactContextConfiguration.builder().setMuleContext(muleContext).setConfigResources(configurationFiles).setArtifactDeclaration(artifactDeclaration).setArtifactProperties(merge(artifactProperties, muleContext.getDeploymentProperties())).setArtifactType(artifactType).setEnableLazyInitialization(enableLazyInit).setDisableXmlValidations(disableXmlValidations).setServiceConfigurators(serviceConfigurators);
if (parentArtifact != null) {
artifactContextConfigurationBuilder.setParentContext(parentArtifact.getRegistry().lookupByType(MuleContext.class).get());
}
artifactContext.set(artifactConfigurationProcessor.createArtifactContext(artifactContextConfigurationBuilder.build()));
((DefaultMuleConfiguration) muleContext.getConfiguration()).setDataFolderName(dataFolderName);
}
@Override
public void addServiceConfigurator(ServiceConfigurator serviceConfigurator) {
// Nothing to do
}
});
DefaultMuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
if (muleContextListener != null) {
muleContextFactory.addListener(muleContextListener);
}
if (APP.equals(artifactType)) {
muleContextBuilder = new ApplicationMuleContextBuilder(artifactName, artifactProperties, defaultEncoding);
} else if (POLICY.equals(artifactType)) {
muleContextBuilder = new PolicyMuleContextBuilder(artifactName, artifactProperties, defaultEncoding);
} else {
muleContextBuilder = new DomainMuleContextBuilder(artifactName);
}
muleContextBuilder.setExecutionClassLoader(this.executionClassLoader);
ArtifactObjectSerializer objectSerializer = new ArtifactObjectSerializer(classLoaderRepository);
muleContextBuilder.setObjectSerializer(objectSerializer);
muleContextBuilder.setDeploymentProperties(properties);
if (parentArtifact != null) {
builders.add(new ConnectionManagerConfigurationBuilder(parentArtifact));
muleContextBuilder.setErrorTypeRepository(createCompositeErrorTypeRepository(parentArtifact.getRegistry().lookupByType(MuleContext.class).get().getErrorTypeRepository()));
} else {
builders.add(new ConnectionManagerConfigurationBuilder());
}
try {
muleContextFactory.createMuleContext(builders, muleContextBuilder);
return artifactContext.get();
} catch (InitialisationException e) {
throw new ConfigurationException(e);
}
});
} catch (MuleRuntimeException e) {
// We need this exception to be thrown as they are since the are possible causes of connectivity errors
if (e.getCause() instanceof InitialisationException) {
throw (InitialisationException) e.getCause();
}
if (e.getCause() instanceof ConfigurationException) {
throw (ConfigurationException) e.getCause();
}
throw e;
}
}
use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class AbstractMavenClassLoaderModelLoader method createLightPackageClassLoaderModel.
private ClassLoaderModel createLightPackageClassLoaderModel(File artifactFile, Map<String, Object> attributes, ArtifactType artifactType) {
File containerRepository;
if (isStandalone() && !getBoolean("mule.mode.embedded")) {
containerRepository = new File(getMuleHomeFolder(), "repository");
if (!containerRepository.exists()) {
if (!containerRepository.mkdirs()) {
// check again since it may have been created already.
if (!containerRepository.exists()) {
throw new MuleRuntimeException(I18nMessageFactory.createStaticMessage("Failure creating repository folder in MULE_HOME folder " + containerRepository.getAbsolutePath()));
}
}
}
}
File localMavenRepositoryLocation = mavenClient.getMavenConfiguration().getLocalMavenRepositoryLocation();
Supplier<File> compositeRepoLocationSupplier = localRepositorySupplierFactory.composeSuppliers(localRepositorySupplierFactory.artifactFolderRepositorySupplier(artifactFile, localMavenRepositoryLocation), localRepositorySupplierFactory.fixedFolderSupplier(localMavenRepositoryLocation));
File mavenRepository = compositeRepoLocationSupplier.get();
File temporaryDirectory = createTempDir();
try {
List<org.mule.maven.client.api.model.BundleDependency> dependencies = mavenClient.resolveArtifactDependencies(artifactFile, includeTestDependencies(attributes), includeProvidedDependencies(artifactType), of(mavenRepository), ofNullable((MavenReactorResolver) attributes.get(CLASSLOADER_MODEL_MAVEN_REACTOR_RESOLVER)), of(temporaryDirectory));
final ClassLoaderModel.ClassLoaderModelBuilder classLoaderModelBuilder = new ClassLoaderModel.ClassLoaderModelBuilder();
classLoaderModelBuilder.exportingPackages(new HashSet<>(getAttribute(attributes, EXPORTED_PACKAGES))).exportingPrivilegedPackages(new HashSet<>(getAttribute(attributes, PRIVILEGED_EXPORTED_PACKAGES)), new HashSet<>(getAttribute(attributes, PRIVILEGED_ARTIFACTS_IDS))).exportingResources(new HashSet<>(getAttribute(attributes, EXPORTED_RESOURCES))).includeTestDependencies(valueOf(getSimpleAttribute(attributes, INCLUDE_TEST_DEPENDENCIES, "false")));
Set<BundleDependency> bundleDependencies = dependencies.stream().filter(mavenClientDependency -> !mavenClientDependency.getScope().equals(PROVIDED)).map(mavenClientDependency -> convertBundleDependency(mavenClientDependency)).collect(toSet());
loadUrls(artifactFile, classLoaderModelBuilder, bundleDependencies);
Set<BundleDependency> allBundleDependencies = dependencies.stream().map(mavenClientDependency -> convertBundleDependency(mavenClientDependency)).collect(toSet());
classLoaderModelBuilder.dependingOn(allBundleDependencies);
return classLoaderModelBuilder.build();
} finally {
deleteQuietly(temporaryDirectory);
}
}
use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class MavenUtils method updateArtifactPom.
/**
* Updates the pom file from an artifact.
*
* @param artifactFolder the artifact folder
* @param model the new pom model
*/
public static void updateArtifactPom(File artifactFolder, Model model) {
final File mulePluginPom = lookupPomFromMavenLocation(artifactFolder);
MavenXpp3Writer writer = new MavenXpp3Writer();
try (FileOutputStream outputStream = new FileOutputStream(mulePluginPom)) {
writer.write(outputStream, model);
} catch (IOException e) {
throw new MuleRuntimeException(e);
}
}
use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class DefaultMuleApplicationStatusTestCase method deploymentFailedOnStart.
@Test
public void deploymentFailedOnStart() throws Exception {
MuleContext mockedMuleContext = mock(MuleContext.class);
when(mockArtifactContext.getMuleContext()).thenReturn(mockedMuleContext);
mockedMuleContext.start();
doThrow(new MuleRuntimeException(createStaticMessage("error")));
try {
application.start();
fail("Was expecting start to fail");
} catch (Exception e) {
assertStatus(ApplicationStatus.DEPLOYMENT_FAILED);
}
}
Aggregations