public RepositorySystemSession getRepositorySession() { MavenSession session = getSession(); return ( session != null ) ? session.getRepositorySession() : null; }
public ProjectBuildingRequest getProjectBuildingRequest() { return request.getProjectBuildingRequest().setRepositorySession( getRepositorySession() ); }
PluginDescriptor getPluginDescriptor(MavenProject project, Plugin plugin) throws InvocationTargetException, IllegalAccessException, MojoFailureException { try { Method loadPlugin = pluginManager.getClass().getMethod("loadPluginDescriptor", plugin.getClass(), project.getClass(), session.getClass()); return (PluginDescriptor) loadPlugin.invoke(pluginManager, plugin, project, session); } catch (NoSuchMethodException exp) { try { // Fallback for older Maven versions RepositorySystemSession repositorySession = session.getRepositorySession(); Method loadPlugin = pluginManager.getClass().getMethod("loadPlugin", plugin.getClass(), project.getRemotePluginRepositories().getClass(), repositorySession.getClass()); return (PluginDescriptor) loadPlugin.invoke(pluginManager, plugin, project.getRemotePluginRepositories(), repositorySession); } catch (NoSuchMethodException exp2) { throw new MojoFailureException("Cannot load plugin descriptor for plugin " + plugin.getGroupId() + ":" + plugin.getArtifactId(),exp2); } } }
public Object getPluginComponent( Plugin plugin, String role, String roleHint ) throws PluginManagerException, ComponentLookupException { MavenSession session = legacySupport.getSession(); PluginDescriptor pluginDescriptor; try { pluginDescriptor = pluginManager.getPluginDescriptor( plugin, session.getCurrentProject().getRemotePluginRepositories(), session.getRepositorySession() ); pluginManager.setupPluginRealm( pluginDescriptor, session, null, null, null ); } catch ( Exception e ) { throw new PluginManagerException( plugin, e.getMessage(), e ); } ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader( pluginDescriptor.getClassRealm() ); return container.lookup( role, roleHint ); } finally { Thread.currentThread().setContextClassLoader( oldClassLoader ); } }
public Map<String, Object> getPluginComponents( Plugin plugin, String role ) throws ComponentLookupException, PluginManagerException { MavenSession session = legacySupport.getSession(); PluginDescriptor pluginDescriptor; try { pluginDescriptor = pluginManager.getPluginDescriptor( plugin, session.getCurrentProject().getRemotePluginRepositories(), session.getRepositorySession() ); pluginManager.setupPluginRealm( pluginDescriptor, session, null, null, null ); } catch ( Exception e ) { throw new PluginManagerException( plugin, e.getMessage(), e ); } ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader( pluginDescriptor.getClassRealm() ); return container.lookupMap( role ); } finally { Thread.currentThread().setContextClassLoader( oldClassLoader ); } }
private void resolvePluginVersion( Plugin plugin, MavenSession session, MavenProject project ) throws PluginVersionResolutionException { PluginVersionRequest versionRequest = new DefaultPluginVersionRequest( plugin, session.getRepositorySession(), project.getRemotePluginRepositories() ); plugin.setVersion( pluginVersionResolver.resolve( versionRequest ).getVersion() ); }
session.getRepositorySession() );
private List<MavenProject> getProjectsForMavenReactor( MavenSession session ) throws ProjectBuildingException { MavenExecutionRequest request = session.getRequest(); request.getProjectBuildingRequest().setRepositorySession( session.getRepositorySession() ); List<MavenProject> projects = new ArrayList<>(); // We have no POM file. // if ( request.getPom() == null ) { ModelSource modelSource = new UrlModelSource( DefaultMaven.class.getResource( "project/standalone.xml" ) ); MavenProject project = projectBuilder.build( modelSource, request.getProjectBuildingRequest() ) .getProject(); project.setExecutionRoot( true ); projects.add( project ); request.setProjectPresent( false ); return projects; } List<File> files = Arrays.asList( request.getPom().getAbsoluteFile() ); collectProjects( projects, files, request ); return projects; }
private ProjectBuildingRequest injectSession( ProjectBuildingRequest request ) { MavenSession session = legacySupport.getSession(); if ( session != null ) { request.setRepositorySession( session.getRepositorySession() ); request.setSystemProperties( session.getSystemProperties() ); if ( request.getUserProperties().isEmpty() ) { request.setUserProperties( session.getUserProperties() ); } MavenExecutionRequest req = session.getRequest(); if ( req != null ) { request.setRemoteRepositories( req.getRemoteRepositories() ); } } else { Properties props = new Properties(); EnvironmentUtils.addEnvVars( props ); props.putAll( System.getProperties() ); request.setSystemProperties( props ); } return request; }
scopesToResolve, aggregating, session.getRepositorySession() ); ProjectArtifactsCache.CacheRecord recordArtifacts; recordArtifacts = projectArtifactsCache.get( cacheKey );
session.getRepositorySession() );
public PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings, ArtifactRepository localRepository ) throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException, InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException, PluginVersionNotFoundException { MavenSession session = legacySupport.getSession(); if ( plugin.getVersion() == null ) { PluginVersionRequest versionRequest = new DefaultPluginVersionRequest( plugin, session.getRepositorySession(), project.getRemotePluginRepositories() ); plugin.setVersion( pluginVersionResolver.resolve( versionRequest ).getVersion() ); } try { return pluginManager.getPluginDescriptor( plugin, project.getRemotePluginRepositories(), session.getRepositorySession() ); } catch ( PluginResolutionException e ) { throw new PluginNotFoundException( plugin, project.getPluginArtifactRepositories() ); } catch ( PluginDescriptorParsingException | InvalidPluginDescriptorException e ) { throw new PluginManagerException( plugin, e.getMessage(), e ); } }
pluginManager.getMojoDescriptor( forkedExecution.getPlugin(), forkedExecution.getGoal(), project.getRemotePluginRepositories(), session.getRepositorySession() );
PluginVersionRequest request = new DefaultPluginVersionRequest( plugin, session.getRepositorySession(), project.getRemotePluginRepositories() ); plugin.setVersion( pluginVersionResolver.resolve( request ).getVersion() ); new DefaultPluginVersionRequest( plugin, session.getRepositorySession(), project.getRemotePluginRepositories() ); plugin.setVersion( pluginVersionResolver.resolve( request ).getVersion() );
new DefaultDependencyResolutionRequest( project, session.getRepositorySession() ); request.setResolutionFilter( resolutionFilter );
/** * Creates a request for the specified plugin by copying settings from the specified build session. If the session * has a current project, its plugin repositories will be used as well. * * @param plugin The plugin for which to resolve a version, must not be {@code null}. * @param session The Maven session to use, must not be {@code null}. */ public DefaultPluginVersionRequest( Plugin plugin, MavenSession session ) { setGroupId( plugin.getGroupId() ); setArtifactId( plugin.getArtifactId() ); setRepositorySession( session.getRepositorySession() ); MavenProject project = session.getCurrentProject(); if ( project != null ) { setRepositories( project.getRemotePluginRepositories() ); } }
@Override public void setupMojoExecution( MavenSession session, MavenProject project, MojoExecution mojoExecution ) throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, MojoNotFoundException, InvalidPluginDescriptorException, NoPluginFoundForPrefixException, LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException { MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); if ( mojoDescriptor == null ) { mojoDescriptor = pluginManager.getMojoDescriptor( mojoExecution.getPlugin(), mojoExecution.getGoal(), project.getRemotePluginRepositories(), session.getRepositorySession() ); mojoExecution.setMojoDescriptor( mojoDescriptor ); } mojoExecutionConfigurator( mojoExecution ).configure( project, mojoExecution, MojoExecution.Source.CLI.equals( mojoExecution.getSource() ) ); finalizeMojoConfiguration( mojoExecution ); calculateForkedExecutions( mojoExecution, session, project, new HashSet<MojoDescriptor>() ); }
/** * Creates a request for the specified plugin prefix and build session. The provided build session will be used to * configure repository settings. If the session has a current project, its plugin repositories and model will be * used as well. * * @param prefix The plugin prefix to resolve, must not be {@code null}. * @param session The build session from which to derive further settings, must not be {@code null}. */ public DefaultPluginPrefixRequest( String prefix, MavenSession session ) { setPrefix( prefix ); setRepositorySession( session.getRepositorySession() ); MavenProject project = session.getCurrentProject(); if ( project != null ) { setRepositories( project.getRemotePluginRepositories() ); setPom( project.getModel() ); } setPluginGroups( session.getPluginGroups() ); }
private void createPluginRealm( PluginDescriptor pluginDescriptor, MavenSession session, ClassLoader parent, Map<String, ClassLoader> foreignImports, DependencyFilter filter ) throws PluginResolutionException, PluginContainerException { Plugin plugin = Objects.requireNonNull( pluginDescriptor.getPlugin(), "pluginDescriptor.plugin cannot be null" ); Artifact pluginArtifact = Objects.requireNonNull( pluginDescriptor.getPluginArtifact(), "pluginDescriptor.pluginArtifact cannot be null" ); MavenProject project = session.getCurrentProject(); final ClassRealm pluginRealm; final List<Artifact> pluginArtifacts; RepositorySystemSession repositorySession = session.getRepositorySession(); DependencyFilter dependencyFilter = project.getExtensionDependencyFilter(); dependencyFilter = AndDependencyFilter.newInstance( dependencyFilter, filter ); DependencyNode root = pluginDependenciesResolver.resolve( plugin, RepositoryUtils.toArtifact( pluginArtifact ), dependencyFilter, project.getRemotePluginRepositories(), repositorySession ); PreorderNodeListGenerator nlg = new PreorderNodeListGenerator(); root.accept( nlg ); pluginArtifacts = toMavenArtifacts( root, nlg ); pluginRealm = classRealmManager.createPluginRealm( plugin, parent, null, foreignImports, toAetherArtifacts( pluginArtifacts ) ); discoverPluginComponents( pluginRealm, plugin, pluginDescriptor ); pluginDescriptor.setClassRealm( pluginRealm ); pluginDescriptor.setArtifacts( pluginArtifacts ); }
try RepositorySystemSession repositorySession = session.getRepositorySession(); extensionRecord = setupExtensionsRealm( project, plugin, repositorySession ); session.getRepositorySession() );