MavenEmbedder { public MavenExecutionRequest getMavenExecutionRequest() { return mavenExecutionRequest; } MavenEmbedder( MavenRequest mavenRequest );  MavenEmbedder( ClassLoader mavenClassLoader,
                          ClassLoader parent,
                          MavenRequest mavenRequest ); protected  MavenEmbedder( MavenRequest mavenRequest,
                             ComponentProvider componentProvider ); Settings getSettings(); ArtifactRepository getLocalRepository(); String getLocalRepositoryPath(); MavenProject readProject( final InputStream mavenProjectStream ); MavenProject readProject( File mavenProject ); List<MavenProject> readProjects( File mavenProject,
                                            boolean recursive ); List<ProjectBuildingResult> buildProjects( File mavenProject,
                                                      boolean recursive ); MavenSession getMavenSession(); MavenExecutionRequest getMavenExecutionRequest(); void dispose(); MavenExecutionResult execute( final MavenRequest mavenRequest ); static final File DEFAULT_GLOBAL_SETTINGS_FILE; }
@Test public void testExternalRepositories() { String oldSettingsXmlPath = System.getProperty( CUSTOM_SETTINGS_PROPERTY ); try { if (oldSettingsXmlPath != null) { System.clearProperty( CUSTOM_SETTINGS_PROPERTY ); } MavenSettings.reinitSettingsFromString( EMPTY_SETTINGS ); final MavenRequest mavenRequest = createMavenRequest( null ); final MavenEmbedder embedder = new MavenEmbedderWithRepoMock( mavenRequest ); final MavenExecutionRequest request = embedder.getMavenExecutionRequest(); assertNotNull( request ); final List<ArtifactRepository> remoteRepositories = request.getRemoteRepositories(); assertEquals( 2, remoteRepositories.size() ); for ( ArtifactRepository remoteRepository : remoteRepositories ) { assertTrue( remoteRepository.getId().equals( "central" ) || remoteRepository.getId().equals( "kie-wb-m2-repo" ) ); } } catch ( MavenEmbedderException mee ) { fail( mee.getMessage() ); } finally { if (oldSettingsXmlPath != null) { System.setProperty( CUSTOM_SETTINGS_PROPERTY, oldSettingsXmlPath ); } MavenSettings.reinitSettings(); } }
@Test public void testCustomSettingSource() { try { final MavenRequest mavenRequest = createMavenRequest(new SettingsSourceMock( "<settings/>" ) ); final MavenEmbedder embedder = new MavenEmbedderWithRepoMock( mavenRequest ); final MavenExecutionRequest request = embedder.getMavenExecutionRequest(); assertNotNull( request ); Assert.assertEquals( "<settings/>", readFileAsString( request.getUserSettingsFile() ).trim() ); } catch ( MavenEmbedderException mee ) { fail( mee.getMessage() ); } }
@Test public void testProxies() { String oldSettingsXmlPath = System.getProperty( CUSTOM_SETTINGS_PROPERTY ); try { if (oldSettingsXmlPath != null) { System.clearProperty( CUSTOM_SETTINGS_PROPERTY ); } MavenSettings.reinitSettingsFromString(EMPTY_SETTINGS); final MavenRequest mavenRequest = createMavenRequest(null); final MavenEmbedder embedder = new MavenEmbedderWithProxyMock( mavenRequest ); final MavenExecutionRequest request = embedder.getMavenExecutionRequest(); assertNotNull( request ); final List<Proxy> proxies = request.getProxies(); assertEquals( 1, proxies.size() ); assertEquals( "MyProxy", proxies.get(0).getId() ); } catch ( MavenEmbedderException mee ) { fail( mee.getMessage() ); } finally { if (oldSettingsXmlPath != null) { System.setProperty( CUSTOM_SETTINGS_PROPERTY, oldSettingsXmlPath ); } MavenSettings.reinitSettings(); } }