001package org.apache.maven.project; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.util.ArrayList; 023import java.util.Date; 024import java.util.List; 025import java.util.Properties; 026 027import org.apache.maven.artifact.repository.ArtifactRepository; 028import org.apache.maven.model.Profile; 029import org.apache.maven.model.building.ModelBuildingRequest; 030import org.eclipse.aether.RepositorySystemSession; 031 032public class DefaultProjectBuildingRequest 033 implements ProjectBuildingRequest 034{ 035 036 private RepositorySystemSession repositorySession; 037 038 private ArtifactRepository localRepository; 039 040 private List<ArtifactRepository> remoteRepositories; 041 042 private List<ArtifactRepository> pluginArtifactRepositories; 043 044 private MavenProject project; 045 046 private int validationLevel = ModelBuildingRequest.VALIDATION_LEVEL_STRICT; 047 048 private boolean processPlugins; 049 050 private List<Profile> profiles; 051 052 private List<String> activeProfileIds; 053 054 private List<String> inactiveProfileIds; 055 056 private Properties systemProperties; 057 058 private Properties userProperties; 059 060 private Date buildStartTime; 061 062 private boolean resolveDependencies; 063 064 private RepositoryMerging repositoryMerging = RepositoryMerging.POM_DOMINANT; 065 066 public DefaultProjectBuildingRequest() 067 { 068 processPlugins = true; 069 profiles = new ArrayList<Profile>(); 070 activeProfileIds = new ArrayList<String>(); 071 inactiveProfileIds = new ArrayList<String>(); 072 systemProperties = new Properties(); 073 userProperties = new Properties(); 074 remoteRepositories = new ArrayList<ArtifactRepository>(); 075 pluginArtifactRepositories = new ArrayList<ArtifactRepository>(); 076 } 077 078 public DefaultProjectBuildingRequest( ProjectBuildingRequest request ) 079 { 080 this(); 081 setProcessPlugins( request.isProcessPlugins() ); 082 setProfiles( request.getProfiles() ); 083 setActiveProfileIds( request.getActiveProfileIds() ); 084 setInactiveProfileIds( request.getInactiveProfileIds() ); 085 setSystemProperties( request.getSystemProperties() ); 086 setUserProperties( request.getUserProperties() ); 087 setRemoteRepositories( request.getRemoteRepositories() ); 088 setPluginArtifactRepositories( request.getPluginArtifactRepositories() ); 089 setRepositorySession( request.getRepositorySession() ); 090 setLocalRepository( request.getLocalRepository() ); 091 setBuildStartTime( request.getBuildStartTime() ); 092 setProject( request.getProject() ); 093 setResolveDependencies( request.isResolveDependencies() ); 094 setValidationLevel( request.getValidationLevel() ); 095 } 096 097 public MavenProject getProject() 098 { 099 return project; 100 } 101 102 public void setProject( MavenProject mavenProject ) 103 { 104 this.project = mavenProject; 105 } 106 107 public ProjectBuildingRequest setLocalRepository( ArtifactRepository localRepository ) 108 { 109 this.localRepository = localRepository; 110 return this; 111 } 112 113 public ArtifactRepository getLocalRepository() 114 { 115 return localRepository; 116 } 117 118 public List<ArtifactRepository> getRemoteRepositories() 119 { 120 return remoteRepositories; 121 } 122 123 public ProjectBuildingRequest setRemoteRepositories( List<ArtifactRepository> remoteRepositories ) 124 { 125 if ( remoteRepositories != null ) 126 { 127 this.remoteRepositories = new ArrayList<ArtifactRepository>( remoteRepositories ); 128 } 129 else 130 { 131 this.remoteRepositories.clear(); 132 } 133 134 return this; 135 } 136 137 public List<ArtifactRepository> getPluginArtifactRepositories() 138 { 139 return pluginArtifactRepositories; 140 } 141 142 public ProjectBuildingRequest setPluginArtifactRepositories( List<ArtifactRepository> pluginArtifactRepositories ) 143 { 144 if ( pluginArtifactRepositories != null ) 145 { 146 this.pluginArtifactRepositories = new ArrayList<ArtifactRepository>( pluginArtifactRepositories ); 147 } 148 else 149 { 150 this.pluginArtifactRepositories.clear(); 151 } 152 153 return this; 154 } 155 156 public Properties getSystemProperties() 157 { 158 return systemProperties; 159 } 160 161 public ProjectBuildingRequest setSystemProperties( Properties systemProperties ) 162 { 163 if ( systemProperties != null ) 164 { 165 this.systemProperties = new Properties(); 166 this.systemProperties.putAll( systemProperties ); 167 } 168 else 169 { 170 this.systemProperties.clear(); 171 } 172 173 return this; 174 } 175 176 public Properties getUserProperties() 177 { 178 return userProperties; 179 } 180 181 public ProjectBuildingRequest setUserProperties( Properties userProperties ) 182 { 183 if ( userProperties != null ) 184 { 185 this.userProperties = new Properties(); 186 this.userProperties.putAll( userProperties ); 187 } 188 else 189 { 190 this.userProperties.clear(); 191 } 192 193 return this; 194 } 195 196 public boolean isProcessPlugins() 197 { 198 return processPlugins; 199 } 200 201 public ProjectBuildingRequest setProcessPlugins( boolean processPlugins ) 202 { 203 this.processPlugins = processPlugins; 204 return this; 205 } 206 207 public ProjectBuildingRequest setResolveDependencies( boolean resolveDependencies ) 208 { 209 this.resolveDependencies = resolveDependencies; 210 return this; 211 } 212 213 public boolean isResolveDependencies() 214 { 215 return resolveDependencies; 216 } 217 218 public ProjectBuildingRequest setValidationLevel( int validationLevel ) 219 { 220 this.validationLevel = validationLevel; 221 return this; 222 } 223 224 public int getValidationLevel() 225 { 226 return validationLevel; 227 } 228 229 public List<String> getActiveProfileIds() 230 { 231 return activeProfileIds; 232 } 233 234 public void setActiveProfileIds( List<String> activeProfileIds ) 235 { 236 if ( activeProfileIds != null ) 237 { 238 this.activeProfileIds = new ArrayList<String>( activeProfileIds ); 239 } 240 else 241 { 242 this.activeProfileIds.clear(); 243 } 244 } 245 246 public List<String> getInactiveProfileIds() 247 { 248 return inactiveProfileIds; 249 } 250 251 public void setInactiveProfileIds( List<String> inactiveProfileIds ) 252 { 253 if ( inactiveProfileIds != null ) 254 { 255 this.inactiveProfileIds = new ArrayList<String>( inactiveProfileIds ); 256 } 257 else 258 { 259 this.inactiveProfileIds.clear(); 260 } 261 } 262 263 public void setProfiles( List<Profile> profiles ) 264 { 265 if ( profiles != null ) 266 { 267 this.profiles = new ArrayList<Profile>( profiles ); 268 } 269 else 270 { 271 this.profiles.clear(); 272 } 273 } 274 275 public void addProfile( Profile profile ) 276 { 277 profiles.add( profile ); 278 } 279 280 public List<Profile> getProfiles() 281 { 282 return profiles; 283 } 284 285 public Date getBuildStartTime() 286 { 287 return buildStartTime; 288 } 289 290 public void setBuildStartTime( Date buildStartTime ) 291 { 292 this.buildStartTime = buildStartTime; 293 } 294 295 public RepositorySystemSession getRepositorySession() 296 { 297 return repositorySession; 298 } 299 300 public DefaultProjectBuildingRequest setRepositorySession( RepositorySystemSession repositorySession ) 301 { 302 this.repositorySession = repositorySession; 303 return this; 304 } 305 306 public DefaultProjectBuildingRequest setRepositoryMerging( RepositoryMerging repositoryMerging ) 307 { 308 if ( repositoryMerging == null ) 309 { 310 throw new IllegalArgumentException( "repository merge mode not specified" ); 311 } 312 this.repositoryMerging = repositoryMerging; 313 return this; 314 } 315 316 public RepositoryMerging getRepositoryMerging() 317 { 318 return repositoryMerging; 319 } 320 321}