use of org.mule.runtime.core.api.config.bootstrap.ArtifactType in project mule by mulesoft.
the class AbstractRegistryBootstrap method createObjectBootstrapProperty.
private ObjectBootstrapProperty createObjectBootstrapProperty(BootstrapService bootstrapService, String propertyKey, String propertyValue) {
boolean optional = false;
String className;
Set<ArtifactType> artifactTypesParameterValue = new HashSet<>(asList(APP, DOMAIN, POLICY));
final String value = propertyValue;
int index = value.indexOf(",");
if (index > -1) {
Properties p = PropertiesUtils.getPropertiesFromString(value.substring(index + 1), ',');
if (p.containsKey(APPLY_TO_ARTIFACT_TYPE_PARAMETER_KEY)) {
artifactTypesParameterValue = stream(((String) p.get(APPLY_TO_ARTIFACT_TYPE_PARAMETER_KEY)).split("\\/")).map(t -> createFromString(t)).collect(toSet());
}
optional = p.containsKey(OPTIONAL_ATTRIBUTE);
className = value.substring(0, index);
} else {
className = value;
}
return new ObjectBootstrapProperty(bootstrapService, artifactTypesParameterValue, optional, propertyKey, className);
}
use of org.mule.runtime.core.api.config.bootstrap.ArtifactType 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.core.api.config.bootstrap.ArtifactType 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);
}
}
Aggregations