use of org.mule.maven.client.api.MavenClientProvider in project mule by mulesoft.
the class PolicyTemplateDescriptorFactoryTestCase method setUp.
@Before
public void setUp() throws Exception {
when(descriptorLoaderRepository.get(FILE_SYSTEM_POLICY_MODEL_LOADER_ID, POLICY, ClassLoaderModelLoader.class)).thenReturn(new FileSystemPolicyClassLoaderModelLoader());
when(descriptorLoaderRepository.get(INVALID_LOADER_ID, POLICY, ClassLoaderModelLoader.class)).thenThrow(new LoaderNotFoundException(INVALID_LOADER_ID));
MavenClientProvider mavenClientProvider = MavenClientProvider.discoverProvider(currentThread().getContextClassLoader());
when(descriptorLoaderRepository.get(MULE_LOADER_ID, POLICY, ClassLoaderModelLoader.class)).thenReturn(new DeployableMavenClassLoaderModelLoader(mavenClientProvider.createMavenClient(newMavenConfigurationBuilder().localMavenRepositoryLocation(mavenClientProvider.getLocalRepositorySuppliers().environmentMavenRepositorySupplier().get()).build()), mavenClientProvider.getLocalRepositorySuppliers()));
when(descriptorLoaderRepository.get(PROPERTIES_BUNDLE_DESCRIPTOR_LOADER_ID, POLICY, BundleDescriptorLoader.class)).thenReturn(new PropertiesBundleDescriptorLoader());
when(descriptorLoaderRepository.get(INVALID_LOADER_ID, POLICY, BundleDescriptorLoader.class)).thenThrow(new LoaderNotFoundException(INVALID_LOADER_ID));
}
use of org.mule.maven.client.api.MavenClientProvider in project mule by mulesoft.
the class ArtifactClassLoaderRunner method createClassLoaderTestRunner.
/**
* Creates the {@link ArtifactClassLoaderHolder} with the isolated class loaders.
*
* @param klass the test class being executed
* @param runnerConfiguration {@link RunnerConfiguration} based on annotated test class.
* @return creates a {@link ArtifactClassLoaderHolder} that would be used to run the test. This way the test will be isolated
* and it will behave similar as an application running in a Mule standalone container.
*/
private static synchronized ArtifactClassLoaderHolder createClassLoaderTestRunner(Class<?> klass, RunnerConfiguration runnerConfiguration) {
final File targetTestClassesFolder = new File(klass.getProtectionDomain().getCodeSource().getLocation().getPath());
ArtifactIsolatedClassLoaderBuilder builder = new ArtifactIsolatedClassLoaderBuilder();
final File rootArtifactClassesFolder = new File(targetTestClassesFolder.getParentFile(), "classes");
builder.setRootArtifactClassesFolder(rootArtifactClassesFolder);
builder.setPluginResourcesFolder(targetTestClassesFolder.getParentFile());
builder.setProvidedExclusions(runnerConfiguration.getProvidedExclusions());
builder.setTestExclusions(runnerConfiguration.getTestExclusions());
builder.setTestInclusions(runnerConfiguration.getTestInclusions());
builder.setExportPluginClasses(runnerConfiguration.getExportPluginClasses());
builder.setApplicationSharedLibCoordinates(runnerConfiguration.getSharedApplicationRuntimeLibs());
builder.setApplicationLibCoordinates(runnerConfiguration.getApplicationRuntimeLibs());
builder.setTestRunnerExportedLibCoordinates(runnerConfiguration.getTestRunnerExportedRuntimeLibs());
builder.setExtensionMetadataGeneration(true);
Properties excludedProperties;
try {
excludedProperties = getExcludedProperties();
} catch (IOException e) {
throw new RuntimeException("Error while reading excluded properties", e);
}
Set<String> excludedArtifactsList = getExcludedArtifacts(excludedProperties);
builder.setExcludedArtifacts(excludedArtifactsList);
builder.setExtraBootPackages(getExtraBootPackages(excludedProperties));
builder.setExtraPrivilegedArtifacts(runnerConfiguration.getExtraPrivilegedArtifacts());
final ClassPathUrlProvider classPathUrlProvider = new ClassPathUrlProvider();
List<URL> classPath = classPathUrlProvider.getURLs();
builder.setClassPathUrlProvider(classPathUrlProvider);
WorkspaceLocationResolver workspaceLocationResolver = new AutoDiscoverWorkspaceLocationResolver(classPath, rootArtifactClassesFolder);
final MavenClientProvider mavenClientProvider = discoverProvider(ArtifactClassLoaderRunner.class.getClassLoader());
final Supplier<File> localMavenRepository = mavenClientProvider.getLocalRepositorySuppliers().environmentMavenRepositorySupplier();
final SettingsSupplierFactory settingsSupplierFactory = mavenClientProvider.getSettingsSupplierFactory();
final Optional<File> globalSettings = settingsSupplierFactory.environmentGlobalSettingsSupplier();
final Optional<File> userSettings = settingsSupplierFactory.environmentUserSettingsSupplier();
final MavenConfiguration.MavenConfigurationBuilder mavenConfigurationBuilder = newMavenConfigurationBuilder().forcePolicyUpdateNever(true).localMavenRepositoryLocation(localMavenRepository.get());
if (globalSettings.isPresent()) {
mavenConfigurationBuilder.globalSettingsLocation(globalSettings.get());
} else {
LOGGER.info("Maven global settings couldn't be found, M2_HOME environment variable has to be set in order to use global settings (if needed)");
}
if (userSettings.isPresent()) {
mavenConfigurationBuilder.userSettingsLocation(userSettings.get());
} else {
LOGGER.info("Maven user settings couldn't be found, this could cause a wrong resolution for dependencies");
}
final MavenConfiguration mavenConfiguration = mavenConfigurationBuilder.build();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Using MavenConfiguration: {}", mavenConfiguration);
}
final DependencyResolver dependencyResolver = new DependencyResolver(mavenConfiguration, of(new DefaultWorkspaceReader(classPath, workspaceLocationResolver)));
builder.setClassPathClassifier(new AetherClassPathClassifier(dependencyResolver, new ArtifactClassificationTypeResolver(dependencyResolver)));
return builder.build();
}
use of org.mule.maven.client.api.MavenClientProvider in project mule by mulesoft.
the class DefaultConnectivityTestingServiceBuilder method build.
/**
* {@inheritDoc}
*/
@Override
public ConnectivityTestingService build() {
checkState(artifactDeclaration != null, "artifact configuration cannot be null");
return new TemporaryArtifactConnectivityTestingService(() -> {
String applicationName = UUID.getUUID() + "-connectivity-testing-temp-app";
File applicationFolder = new File(getExecutionFolder(), applicationName);
ApplicationDescriptor applicationDescriptor = new ApplicationDescriptor(applicationName);
applicationDescriptor.setArtifactDeclaration(artifactDeclaration);
applicationDescriptor.setConfigResources(emptySet());
applicationDescriptor.setArtifactLocation(applicationFolder);
createDeployablePomFile(applicationFolder, model);
updateArtifactPom(applicationFolder, model);
MavenClientProvider mavenClientProvider = MavenClientProvider.discoverProvider(DefaultConnectivityTestingServiceBuilder.class.getClassLoader());
applicationDescriptor.setClassLoaderModel(new DeployableMavenClassLoaderModelLoader(mavenClientProvider.createMavenClient(GlobalConfigLoader.getMavenConfig()), mavenClientProvider.getLocalRepositorySuppliers()).load(applicationFolder, emptyMap(), ArtifactType.APP));
return defaultApplicationFactory.createArtifact(applicationDescriptor);
});
}
Aggregations