wtorek, 17 marca 2015

Maven 3.2.3 internals - how it works

  1. private MavenExecutionResult doExecute(MavenExecutionRequest request)
Executing maven request contains the following steps:
1). Sets starting time to the request object 2). Instantiates result container object 3). Validates local repository 4). Creates new repository session (RepositorySystemSession) 5). Instantiates new maven session object (for future purposes lets call it just "session") 6). Notifies AbstractMavenLifecycleParticipant listeners that session has been started 7). Fires ExecutionEvent.Type.ProjectDiscoveryStarted event with created session to the EventCatapult instance 8). Gathers projects for maven reactor and puts them into session 9). Validate projects (building plugins with extensions cannot be part of reactor) - puts just warns 10). Creates projects dependency graph 11). Quits if any exceptions occurred so far 12). Creates ReactorReader and updates session with sorted projects list and projects map (Map) 13). Enters into session scope (extends com.google.inject.Scope) 14). Seeds scope with session object 15). Looks up for WorkspaceReader instance in DefaultPlexusContainer instance (Workspace reader manages a repository backed by the IDE workspace, a build session or a similar ad-hoc collection of artifacts) 16). Sets workspace reader in the repository session (the order of precedence is: Reactor, Workspace, User Local Respository (M2_REPO)) 17). Marking repository sesssion read-only 18). Notifies AbstractMavenLifecycleParticipant listeners that session project have been read 19). Builds again projects dependency graph, as the participants can potentially change the build order as are free to change the dependencies and as a result topological order of the projects 20). Finally the session is passed to the execute method of LifecycleStarter instance 21). Once done all projects within session are validated against active profiles. 22). All the AbstractMavenLifecycleParticipant listeners are notified that session is about to end 23). Session scope exists

Ad 8. Collecting all projects

private void collectProjects( List projects, List files, MavenExecutionRequest request )
ProjectBuildingRequest projectBuildingRequest = request.getProjectBuildingRequest();
List results = projectBuilder.build( files, request.isRecursive(), projectBuildingRequest );
In project builder build method ReactorModelPool is created which is intended to holding all POM files that are known to the reactor. This allows the project builder to resolve imported POMs from the reactor when building another project's effective model. Next the project builders iterate through all pom files and for each creates MavenProject which is passed to DefaultModelNuildingListener and set on ModelBuildingRequest instance. Now the ModelBuilder object comes into play. ModelBuildingRequest instance is passed into build method. After some initial helper objects instantiations the readModel method is invoked.
private Model readModel(ModelSource modelSource, 
                        File pomFile,
                        ModelBuildingRequest request,
                        DefaultModelProblemCollector problems) throws ModelBuildingException
DefaultModelProcessor instance do the read.
 public Model read( InputStream input, Map options )
        throws IOException
Finally the new instance of MavenXpp3ReaderEx is created and read method invoked. Once model is done it is registered in projectIndex map.
If project is recursive and contains modules it locates pom.xml for each and add it to moduleFiles list. Such prepared list is again passed into the same build method as the initial aggregator pom file. Once all projects are build, next step is populating ReactorModelPool object, created at the beginning. It goes through all interim results and registers all models
  //DefaultProjetBuilder:593
  private void populateReactorModelPool( ReactorModelPool reactorModelPool, List interimResults )
    {
        for ( InterimResult interimResult : interimResults )
        {
            Model model = interimResult.result.getEffectiveModel();
            reactorModelPool.put( model.getGroupId(), model.getArtifactId(), model.getVersion(), model.getPomFile() );

            populateReactorModelPool( reactorModelPool, interimResult.modules );
        }
    }

Brak komentarzy:

Prześlij komentarz