Search in sources :

Example 1 with MavenClientProvider

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));
}
Also used : DeployableMavenClassLoaderModelLoader(org.mule.runtime.module.deployment.impl.internal.application.DeployableMavenClassLoaderModelLoader) LoaderNotFoundException(org.mule.runtime.module.artifact.api.descriptor.LoaderNotFoundException) MavenClientProvider(org.mule.maven.client.api.MavenClientProvider) Before(org.junit.Before)

Example 2 with MavenClientProvider

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();
}
Also used : ArtifactIsolatedClassLoaderBuilder(org.mule.test.runner.api.ArtifactIsolatedClassLoaderBuilder) MavenConfiguration(org.mule.maven.client.api.model.MavenConfiguration) SettingsSupplierFactory(org.mule.maven.client.api.SettingsSupplierFactory) IOException(java.io.IOException) Properties(java.util.Properties) RunnerModuleUtils.getExcludedProperties(org.mule.test.runner.utils.RunnerModuleUtils.getExcludedProperties) URL(java.net.URL) AutoDiscoverWorkspaceLocationResolver(org.mule.test.runner.maven.AutoDiscoverWorkspaceLocationResolver) WorkspaceLocationResolver(org.mule.test.runner.api.WorkspaceLocationResolver) DependencyResolver(org.mule.test.runner.api.DependencyResolver) AetherClassPathClassifier(org.mule.test.runner.api.AetherClassPathClassifier) AutoDiscoverWorkspaceLocationResolver(org.mule.test.runner.maven.AutoDiscoverWorkspaceLocationResolver) MavenClientProvider(org.mule.maven.client.api.MavenClientProvider) DefaultWorkspaceReader(org.mule.test.runner.classification.DefaultWorkspaceReader) File(java.io.File) ClassPathUrlProvider(org.mule.test.runner.api.ClassPathUrlProvider) ArtifactClassificationTypeResolver(org.mule.test.runner.api.ArtifactClassificationTypeResolver)

Example 3 with MavenClientProvider

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);
    });
}
Also used : DeployableMavenClassLoaderModelLoader(org.mule.runtime.module.deployment.impl.internal.application.DeployableMavenClassLoaderModelLoader) MavenClientProvider(org.mule.maven.client.api.MavenClientProvider) File(java.io.File) MavenUtils.createDeployablePomFile(org.mule.runtime.module.deployment.impl.internal.maven.MavenUtils.createDeployablePomFile) ApplicationDescriptor(org.mule.runtime.deployment.model.api.application.ApplicationDescriptor)

Aggregations

MavenClientProvider (org.mule.maven.client.api.MavenClientProvider)3 File (java.io.File)2 DeployableMavenClassLoaderModelLoader (org.mule.runtime.module.deployment.impl.internal.application.DeployableMavenClassLoaderModelLoader)2 IOException (java.io.IOException)1 URL (java.net.URL)1 Properties (java.util.Properties)1 Before (org.junit.Before)1 SettingsSupplierFactory (org.mule.maven.client.api.SettingsSupplierFactory)1 MavenConfiguration (org.mule.maven.client.api.model.MavenConfiguration)1 ApplicationDescriptor (org.mule.runtime.deployment.model.api.application.ApplicationDescriptor)1 LoaderNotFoundException (org.mule.runtime.module.artifact.api.descriptor.LoaderNotFoundException)1 MavenUtils.createDeployablePomFile (org.mule.runtime.module.deployment.impl.internal.maven.MavenUtils.createDeployablePomFile)1 AetherClassPathClassifier (org.mule.test.runner.api.AetherClassPathClassifier)1 ArtifactClassificationTypeResolver (org.mule.test.runner.api.ArtifactClassificationTypeResolver)1 ArtifactIsolatedClassLoaderBuilder (org.mule.test.runner.api.ArtifactIsolatedClassLoaderBuilder)1 ClassPathUrlProvider (org.mule.test.runner.api.ClassPathUrlProvider)1 DependencyResolver (org.mule.test.runner.api.DependencyResolver)1 WorkspaceLocationResolver (org.mule.test.runner.api.WorkspaceLocationResolver)1 DefaultWorkspaceReader (org.mule.test.runner.classification.DefaultWorkspaceReader)1 AutoDiscoverWorkspaceLocationResolver (org.mule.test.runner.maven.AutoDiscoverWorkspaceLocationResolver)1