1 package org.apache.maven.project;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.List;
23
24 import org.apache.maven.artifact.repository.ArtifactRepository;
25 import org.apache.maven.model.Model;
26 import org.apache.maven.model.building.AbstractModelBuildingListener;
27 import org.apache.maven.model.building.ModelBuildingEvent;
28 import org.apache.maven.model.building.ModelProblem.Severity;
29 import org.apache.maven.model.building.ModelProblem.Version;
30 import org.apache.maven.model.building.ModelProblemCollectorRequest;
31 import org.apache.maven.plugin.PluginResolutionException;
32 import org.apache.maven.plugin.version.PluginVersionResolutionException;
33
34
35
36
37
38
39 class DefaultModelBuildingListener
40 extends AbstractModelBuildingListener
41 {
42
43 private MavenProject project;
44
45 private ProjectBuildingHelper projectBuildingHelper;
46
47 private ProjectBuildingRequest projectBuildingRequest;
48
49 private List<ArtifactRepository> remoteRepositories;
50
51 private List<ArtifactRepository> pluginRepositories;
52
53 public DefaultModelBuildingListener( MavenProject project, ProjectBuildingHelper projectBuildingHelper,
54 ProjectBuildingRequest projectBuildingRequest )
55 {
56 if ( project == null )
57 {
58 throw new IllegalArgumentException( "project missing" );
59 }
60 this.project = project;
61
62 if ( projectBuildingHelper == null )
63 {
64 throw new IllegalArgumentException( "project building helper missing" );
65 }
66 this.projectBuildingHelper = projectBuildingHelper;
67
68 if ( projectBuildingRequest == null )
69 {
70 throw new IllegalArgumentException( "project building request missing" );
71 }
72 this.projectBuildingRequest = projectBuildingRequest;
73 this.remoteRepositories = projectBuildingRequest.getRemoteRepositories();
74 this.pluginRepositories = projectBuildingRequest.getPluginArtifactRepositories();
75 }
76
77
78
79
80
81
82 public MavenProject getProject()
83 {
84 return project;
85 }
86
87 @Override
88 public void buildExtensionsAssembled( ModelBuildingEvent event )
89 {
90 Model model = event.getModel();
91
92 try
93 {
94 pluginRepositories =
95 projectBuildingHelper.createArtifactRepositories( model.getPluginRepositories(), pluginRepositories,
96 projectBuildingRequest );
97 }
98 catch ( Exception e )
99 {
100 event.getProblems().add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE )
101 .setMessage( "Invalid plugin repository: " + e.getMessage() )
102 .setException( e ) );
103 }
104 project.setPluginArtifactRepositories( pluginRepositories );
105
106 if ( event.getRequest().isProcessPlugins() )
107 {
108 try
109 {
110 ProjectRealmCache.CacheRecord record =
111 projectBuildingHelper.createProjectRealm( project, model, projectBuildingRequest );
112
113 project.setClassRealm( record.realm );
114 project.setExtensionDependencyFilter( record.extensionArtifactFilter );
115 }
116 catch ( PluginResolutionException e )
117 {
118 event.getProblems().add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE )
119 .setMessage( "Unresolveable build extension: " + e.getMessage() )
120 .setException( e ) );
121 }
122 catch ( PluginVersionResolutionException e )
123 {
124 event.getProblems().add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE )
125 .setMessage( "Unresolveable build extension: " + e.getMessage() )
126 .setException( e ) );
127 }
128
129 projectBuildingHelper.selectProjectRealm( project );
130 }
131
132
133 try
134 {
135 remoteRepositories =
136 projectBuildingHelper.createArtifactRepositories( model.getRepositories(), remoteRepositories,
137 projectBuildingRequest );
138 }
139 catch ( Exception e )
140 {
141 event.getProblems().add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE )
142 .setMessage( "Invalid artifact repository: " + e.getMessage() )
143 .setException( e ) );
144 }
145 project.setRemoteArtifactRepositories( remoteRepositories );
146 }
147
148 }